groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Francesco Chicchiriccò"<ilgro...@apache.org>
Subject Cache parsed classes
Date Tue, 03 Oct 2017 08:52:34 GMT
Hi there,
at Apache Syncope we are currently working to support dynamically loaded Groovy classes as
standard classes.

Essentially, there are some defined Java interfaces, and we allow users to upload their Groovy
implementations which are stored as strings in our internal database.

When one of available implementations is requested, we do something as follows:

    private static final GroovyClassLoader GROOVY_CLASSLOADER = new GroovyClassLoader();

    @SuppressWarnings("unchecked")
    private static <T> T buildGroovy(final String classBody) throws InstantiationException,
IllegalAccessException {
        Class<?> clazz = GROOVY_CLASSLOADER.parseClass(classBody);
        return (T) ApplicationContextProvider.getBeanFactory().
                createBean(clazz, AbstractBeanDefinition.AUTOWIRE_BY_TYPE, false);
    }

I am happy to say that this works just fine.

Now I was wondering what is the best approach to cache such information, to avoid Groovy parsing
the class source text at every execution request.
Could you provide any pointer? Thanks!

Regards.

Mime
View raw message