Search in sources :

Example 1 with Contextual

use of javax.enterprise.context.spi.Contextual in project deltaspike by apache.

the class GroupedConversationContext method tryToDestroySubGroup.

private void tryToDestroySubGroup(Set<Class<?>> subGroups, Map.Entry<ConversationKey, ContextualStorage> entry) {
    ContextualStorage storage = entry.getValue();
    for (Map.Entry<Object, ContextualInstanceInfo<?>> storageEntry : storage.getStorage().entrySet()) {
        for (Class<?> subGroup : subGroups) {
            Class classOfEntry = storageEntry.getValue().getContextualInstance().getClass();
            if (subGroup.equals(classOfEntry) || (subGroup.isInterface() && subGroup.isAssignableFrom(classOfEntry))) {
                Contextual bean = storage.getBean(storageEntry.getKey());
                AbstractContext.destroyBean(bean, storageEntry.getValue());
                //ok due to ConcurrentHashMap
                storage.getStorage().remove(storageEntry.getKey());
                break;
            }
        }
    }
}
Also used : Contextual(javax.enterprise.context.spi.Contextual) ContextualStorage(org.apache.deltaspike.core.util.context.ContextualStorage) ContextualInstanceInfo(org.apache.deltaspike.core.util.context.ContextualInstanceInfo) Map(java.util.Map)

Example 2 with Contextual

use of javax.enterprise.context.spi.Contextual in project deltaspike by apache.

the class ViewAccessContext method destroyExpiredBeans.

private void destroyExpiredBeans(boolean force) {
    ContextualStorage storage = viewAccessBeanHolder.getContextualStorage(beanManager, KEY, false);
    if (storage != null) {
        for (Map.Entry<Object, ContextualInstanceInfo<?>> storageEntry : storage.getStorage().entrySet()) {
            if (force || !viewAccessBeanAccessHistory.getAccessedBeans().contains((String) storageEntry.getKey())) {
                Contextual bean = storage.getBean(storageEntry.getKey());
                AbstractContext.destroyBean(bean, storageEntry.getValue());
                //ok due to ConcurrentHashMap
                storage.getStorage().remove(storageEntry.getKey());
            }
        }
    }
}
Also used : Contextual(javax.enterprise.context.spi.Contextual) ContextualStorage(org.apache.deltaspike.core.util.context.ContextualStorage) ContextualInstanceInfo(org.apache.deltaspike.core.util.context.ContextualInstanceInfo) Map(java.util.Map)

Example 3 with Contextual

use of javax.enterprise.context.spi.Contextual in project Payara by payara.

the class TransactionScopedBeanTest method testAllMethods.

@Test
@SuppressWarnings("unchecked")
public void testAllMethods() {
    LocalBean localBean = new LocalBean();
    EasyMockSupport mockSupport = new EasyMockSupport();
    Contextual<LocalBean> contextual = (Contextual<LocalBean>) mockSupport.createMock(Contextual.class);
    CreationalContext<LocalBean> creationalContext = (CreationalContext<LocalBean>) mockSupport.createMock(CreationalContext.class);
    TransactionScopedContextImpl transactionScopedContext = mockSupport.createMock(TransactionScopedContextImpl.class);
    transactionScopedContext.beansPerTransaction = new ConcurrentHashMap<>();
    // test getContextualInstance
    TransactionScopedBean<LocalBean> transactionScopedBean = getTransactionScopedBean(mockSupport, localBean, contextual, creationalContext, transactionScopedContext);
    assertSame(localBean, transactionScopedBean.getContextualInstance());
    // test afterCompletion
    contextual.destroy(localBean, creationalContext);
    mockSupport.replayAll();
    transactionScopedBean.afterCompletion(0);
    mockSupport.verifyAll();
    mockSupport.resetAll();
}
Also used : CreationalContext(javax.enterprise.context.spi.CreationalContext) EasyMockSupport(org.easymock.EasyMockSupport) Contextual(javax.enterprise.context.spi.Contextual) Test(org.junit.Test)

Example 4 with Contextual

use of javax.enterprise.context.spi.Contextual in project deltaspike by apache.

the class AbstractContext method destroyAllActive.

/**
     * Destroys all the Contextual Instances in the specified ContextualStorage.
     * This is a static method to allow various holder objects to cleanup
     * properly in &#064;PreDestroy.
     */
public static Map<Object, ContextualInstanceInfo<?>> destroyAllActive(ContextualStorage storage) {
    //drop all entries in the storage before starting with destroying the original entries
    Map<Object, ContextualInstanceInfo<?>> contextMap = new HashMap<Object, ContextualInstanceInfo<?>>(storage.getStorage());
    storage.getStorage().clear();
    for (Map.Entry<Object, ContextualInstanceInfo<?>> entry : contextMap.entrySet()) {
        Contextual bean = storage.getBean(entry.getKey());
        ContextualInstanceInfo<?> contextualInstanceInfo = entry.getValue();
        destroyBean(bean, contextualInstanceInfo);
    }
    return contextMap;
}
Also used : Contextual(javax.enterprise.context.spi.Contextual) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

Contextual (javax.enterprise.context.spi.Contextual)4 Map (java.util.Map)3 ContextualInstanceInfo (org.apache.deltaspike.core.util.context.ContextualInstanceInfo)2 ContextualStorage (org.apache.deltaspike.core.util.context.ContextualStorage)2 HashMap (java.util.HashMap)1 CreationalContext (javax.enterprise.context.spi.CreationalContext)1 EasyMockSupport (org.easymock.EasyMockSupport)1 Test (org.junit.Test)1