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;
}
}
}
}
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());
}
}
}
}
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();
}
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 @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;
}
Aggregations