Search in sources :

Example 1 with PerthreadManager

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;
}
Also used : MongoDBImpl(org.apache.tapestry5.internal.mongodb.MongoDBImpl) Scope(org.apache.tapestry5.ioc.annotations.Scope)

Example 2 with PerthreadManager

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();
}
Also used : PageLifecycleListener(org.apache.tapestry5.runtime.PageLifecycleListener) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) Test(org.testng.annotations.Test)

Example 3 with PerthreadManager

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();
}
Also used : PageLifecycleListener(org.apache.tapestry5.runtime.PageLifecycleListener) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) Test(org.testng.annotations.Test)

Example 4 with PerthreadManager

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();
}
Also used : PageLifecycleListener(org.apache.tapestry5.runtime.PageLifecycleListener) Logger(org.slf4j.Logger) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) Test(org.testng.annotations.Test)

Example 5 with PerthreadManager

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);
}
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

MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)6 Test (org.testng.annotations.Test)6 PageLifecycleListener (org.apache.tapestry5.runtime.PageLifecycleListener)4 Scope (org.apache.tapestry5.ioc.annotations.Scope)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 TypeCoercer (org.apache.tapestry5.commons.services.TypeCoercer)1 EntityManagerManagerImpl (org.apache.tapestry5.internal.jpa.EntityManagerManagerImpl)1 MongoDBImpl (org.apache.tapestry5.internal.mongodb.MongoDBImpl)1 NonParallelExecutor (org.apache.tapestry5.ioc.internal.services.NonParallelExecutor)1 ParallelExecutorImpl (org.apache.tapestry5.ioc.internal.services.ParallelExecutorImpl)1 PerthreadManager (org.apache.tapestry5.ioc.services.PerthreadManager)1 ServiceOverride (org.apache.tapestry5.ioc.services.ServiceOverride)1 ComponentResourceSelector (org.apache.tapestry5.services.pageload.ComponentResourceSelector)1 Logger (org.slf4j.Logger)1 BeforeClass (org.testng.annotations.BeforeClass)1