Search in sources :

Example 1 with ApplicationInitializerFilter

use of org.apache.tapestry5.http.services.ApplicationInitializerFilter in project tapestry-5 by apache.

the class SpringModule method reportSpringContextDetailsAtStartup.

@Contribute(ApplicationInitializer.class)
@Primary
public void reportSpringContextDetailsAtStartup(OrderedConfiguration<ApplicationInitializerFilter> configuration, final ApplicationContext springContext) {
    ApplicationInitializerFilter filter = new ApplicationInitializerFilter() {

        @Override
        public void initializeApplication(Context context, ApplicationInitializer initializer) {
            logger.info(String.format("Spring version %s with %,d defined beans.", SpringVersion.getVersion(), springContext.getBeanDefinitionCount()));
            initializer.initializeApplication(context);
        }
    };
    configuration.add("SpringContextInitialization", filter);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) ConfigurableWebApplicationContext(org.springframework.web.context.ConfigurableWebApplicationContext) ServletContext(javax.servlet.ServletContext) Context(org.apache.tapestry5.http.services.Context) ApplicationInitializer(org.apache.tapestry5.http.services.ApplicationInitializer) ApplicationInitializerFilter(org.apache.tapestry5.http.services.ApplicationInitializerFilter) Primary(org.apache.tapestry5.ioc.annotations.Primary) Contribute(org.apache.tapestry5.ioc.annotations.Contribute)

Example 2 with ApplicationInitializerFilter

use of org.apache.tapestry5.http.services.ApplicationInitializerFilter in project tapestry-5 by apache.

the class TapestryModule method contributeApplicationInitializer.

/**
 * Adds a listener to the {@link org.apache.tapestry5.internal.services.ComponentInstantiatorSource} that clears the
 * {@link PropertyAccess} and {@link TypeCoercer} caches on
 * a class loader invalidation. In addition, forces the
 * realization of {@link ComponentClassResolver} at startup.
 */
public void contributeApplicationInitializer(OrderedConfiguration<ApplicationInitializerFilter> configuration, final TypeCoercer typeCoercer, final ComponentClassResolver componentClassResolver, @ComponentClasses final InvalidationEventHub invalidationEventHub, @Autobuild final RestoreDirtySessionObjects restoreDirtySessionObjects) {
    final Runnable callback = new Runnable() {

        public void run() {
            propertyAccess.clearCache();
            typeCoercer.clearCache();
        }
    };
    ApplicationInitializerFilter clearCaches = new ApplicationInitializerFilter() {

        public void initializeApplication(Context context, ApplicationInitializer initializer) {
            // Snuck in here is the logic to clear the PropertyAccess
            // service's cache whenever
            // the component class loader is invalidated.
            invalidationEventHub.addInvalidationCallback(callback);
            endOfRequestEventHub.addEndOfRequestListener(restoreDirtySessionObjects);
            // Perform other pending initialization
            initializer.initializeApplication(context);
            // We don't care about the result, but this forces a load of the
            // service
            // at application startup, rather than on first request.
            componentClassResolver.isPageName("ForceLoadAtStartup");
        }
    };
    configuration.add("ClearCachesOnInvalidation", clearCaches);
}
Also used : PageActivationContext(org.apache.tapestry5.annotations.PageActivationContext) EventContext(org.apache.tapestry5.EventContext) Context(org.apache.tapestry5.http.services.Context) ApplicationInitializer(org.apache.tapestry5.http.services.ApplicationInitializer) ApplicationInitializerFilter(org.apache.tapestry5.http.services.ApplicationInitializerFilter)

Aggregations

ApplicationInitializer (org.apache.tapestry5.http.services.ApplicationInitializer)2 ApplicationInitializerFilter (org.apache.tapestry5.http.services.ApplicationInitializerFilter)2 Context (org.apache.tapestry5.http.services.Context)2 ServletContext (javax.servlet.ServletContext)1 EventContext (org.apache.tapestry5.EventContext)1 PageActivationContext (org.apache.tapestry5.annotations.PageActivationContext)1 Contribute (org.apache.tapestry5.ioc.annotations.Contribute)1 Primary (org.apache.tapestry5.ioc.annotations.Primary)1 ApplicationContext (org.springframework.context.ApplicationContext)1 ConfigurableWebApplicationContext (org.springframework.web.context.ConfigurableWebApplicationContext)1