Search in sources :

Example 1 with RegistryShutdownHub

use of org.apache.tapestry5.ioc.services.RegistryShutdownHub in project tapestry-5 by apache.

the class SpringModuleDef method constructObjectCreatorForApplicationContext.

private ObjectCreator constructObjectCreatorForApplicationContext(final ServiceBuilderResources resources, @Primary ApplicationContextCustomizer customizer) {
    final CustomizingContextLoader loader = new CustomizingContextLoader(customizer);
    final Runnable shutdownListener = new Runnable() {

        @Override
        public void run() {
            loader.closeWebApplicationContext(servletContext);
        }
    };
    final RegistryShutdownHub shutdownHub = resources.getService(RegistryShutdownHub.class);
    return new ObjectCreator() {

        @Override
        public Object createObject() {
            return resources.getTracker().invoke("Creating Spring ApplicationContext via ContextLoader", new Invokable<Object>() {

                @Override
                public Object invoke() {
                    resources.getLogger().info(String.format("Starting Spring (version %s)", SpringVersion.getVersion()));
                    WebApplicationContext context = loader.initWebApplicationContext(servletContext);
                    shutdownHub.addRegistryShutdownListener(shutdownListener);
                    applicationContextCreated.set(true);
                    return context;
                }
            });
        }

        @Override
        public String toString() {
            return "ObjectCreator for Spring ApplicationContext";
        }
    };
}
Also used : RegistryShutdownHub(org.apache.tapestry5.ioc.services.RegistryShutdownHub) WebApplicationContext(org.springframework.web.context.WebApplicationContext) ConfigurableWebApplicationContext(org.springframework.web.context.ConfigurableWebApplicationContext)

Example 2 with RegistryShutdownHub

use of org.apache.tapestry5.ioc.services.RegistryShutdownHub in project tapestry-5 by apache.

the class TapestryIOCModule method buildDeferredExecution.

public static ParallelExecutor buildDeferredExecution(@Symbol(IOCSymbols.THREAD_POOL_CORE_SIZE) int coreSize, @Symbol(IOCSymbols.THREAD_POOL_MAX_SIZE) int maxSize, @Symbol(IOCSymbols.THREAD_POOL_KEEP_ALIVE) @IntermediateType(TimeInterval.class) int keepAliveMillis, @Symbol(IOCSymbols.THREAD_POOL_ENABLED) boolean threadPoolEnabled, @Symbol(IOCSymbols.THREAD_POOL_QUEUE_SIZE) int queueSize, PerthreadManager perthreadManager, RegistryShutdownHub shutdownHub, ThunkCreator thunkCreator) {
    if (!threadPoolEnabled)
        return new NonParallelExecutor();
    LinkedBlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<Runnable>(queueSize);
    final ThreadPoolExecutor executorService = new ThreadPoolExecutor(coreSize, maxSize, keepAliveMillis, TimeUnit.MILLISECONDS, workQueue);
    shutdownHub.addRegistryShutdownListener(new Runnable() {

        @Override
        public void run() {
            executorService.shutdown();
        }
    });
    return new ParallelExecutorImpl(executorService, thunkCreator, perthreadManager);
}
Also used : NonParallelExecutor(org.apache.tapestry5.ioc.internal.services.NonParallelExecutor) ParallelExecutorImpl(org.apache.tapestry5.ioc.internal.services.ParallelExecutorImpl) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) ServiceOverride(org.apache.tapestry5.ioc.services.ServiceOverride)

Aggregations

LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 NonParallelExecutor (org.apache.tapestry5.ioc.internal.services.NonParallelExecutor)1 ParallelExecutorImpl (org.apache.tapestry5.ioc.internal.services.ParallelExecutorImpl)1 RegistryShutdownHub (org.apache.tapestry5.ioc.services.RegistryShutdownHub)1 ServiceOverride (org.apache.tapestry5.ioc.services.ServiceOverride)1 ConfigurableWebApplicationContext (org.springframework.web.context.ConfigurableWebApplicationContext)1 WebApplicationContext (org.springframework.web.context.WebApplicationContext)1