use of org.apache.tapestry5.ioc.services.PerthreadManager in project tapestry-5 by apache.
the class MongodbModule method buildMongoDB.
@Scope(ScopeConstants.PERTHREAD)
public static MongoDB buildMongoDB(Logger logger, final MongoDBSource mongoDBSource, PerthreadManager perthreadManager, @Symbol(MongoDBSymbols.DEFAULT_DB_NAME) String defaultDbName, @Symbol(MongoDBSymbols.CONSISTENT_REQUEST) boolean consistentRequest, @Symbol(MongoDBSymbols.SECURE_MODE) boolean secureMode, @Symbol(MongoDBSymbols.DB_USERNAME) String dbUsername, @Symbol(MongoDBSymbols.DB_PASSWORD) String dbPassword) {
final MongoDBImpl mongoDB = new MongoDBImpl(logger, mongoDBSource, defaultDbName, consistentRequest, secureMode, dbUsername, dbPassword);
perthreadManager.addThreadCleanupListener(mongoDB);
return mongoDB;
}
use of org.apache.tapestry5.ioc.services.PerthreadManager in project tapestry-5 by apache.
the class PageImplTest method detach_notification.
@Test
public void detach_notification() {
PageLifecycleListener listener1 = newPageLifecycle();
PageLifecycleListener listener2 = newPageLifecycle();
listener1.containingPageDidDetach();
listener2.containingPageDidDetach();
MetaDataLocator locator = newMetaDataLocator(LOGICAL_PAGE_NAME, true);
replay();
Page page = new PageImpl(LOGICAL_PAGE_NAME, selector, null, perThreadManager, locator);
page.addLifecycleListener(listener1);
page.addLifecycleListener(listener2);
assertFalse(page.detached());
verify();
}
use of org.apache.tapestry5.ioc.services.PerthreadManager in project tapestry-5 by apache.
the class PageImplTest method attach_notification.
@Test
public void attach_notification() {
MetaDataLocator locator = newMetaDataLocator(LOGICAL_PAGE_NAME, true);
PageLifecycleListener listener1 = newPageLifecycle();
PageLifecycleListener listener2 = newPageLifecycle();
listener1.containingPageDidAttach();
listener2.containingPageDidAttach();
replay();
Page page = new PageImpl(LOGICAL_PAGE_NAME, selector, null, perThreadManager, locator);
page.addLifecycleListener(listener1);
page.addLifecycleListener(listener2);
page.attached();
verify();
}
use of org.apache.tapestry5.ioc.services.PerthreadManager in project tapestry-5 by apache.
the class PageImplTest method detach_dirty_if_listener_throws_exception.
/**
* Also checks that all listeners are invoked, even if one of them throws an exception.
*/
@Test
public void detach_dirty_if_listener_throws_exception() {
ComponentPageElement element = mockComponentPageElement();
Logger logger = mockLogger();
PageLifecycleListener listener1 = newPageLifecycle();
PageLifecycleListener listener2 = newPageLifecycle();
RuntimeException t = new RuntimeException("Listener detach exception.");
MetaDataLocator locator = newMetaDataLocator(LOGICAL_PAGE_NAME, true);
train_getLogger(element, logger);
listener1.containingPageDidDetach();
setThrowable(t);
logger.error(contains("failed during page detach"), same(t));
listener2.containingPageDidDetach();
replay();
Page page = new PageImpl(LOGICAL_PAGE_NAME, selector, null, perThreadManager, locator);
page.setRootElement(element);
page.addLifecycleListener(listener1);
page.addLifecycleListener(listener2);
assertTrue(page.detached());
verify();
}
use of org.apache.tapestry5.ioc.services.PerthreadManager 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);
}
Aggregations