Search in sources :

Example 1 with ConversationSubGroup

use of org.apache.deltaspike.core.api.scope.ConversationSubGroup in project deltaspike by apache.

the class ConversationUtils method getDeclaredConversationGroup.

public static Class<?> getDeclaredConversationGroup(Class<?> conversationGroup) {
    ConversationSubGroup conversationSubGroup = conversationGroup.getAnnotation(ConversationSubGroup.class);
    if (conversationSubGroup == null) {
        return conversationGroup;
    }
    Class<?> result = conversationSubGroup.of();
    if (!ConversationSubGroup.class.equals(result)) {
        return result;
    }
    result = conversationGroup.getSuperclass();
    if ((result == null || Object.class.getName().equals(result.getName())) && conversationGroup.getInterfaces().length == 1) {
        return conversationGroup.getInterfaces()[0];
    }
    if (result == null) {
        //TODO move validation to the bootstrapping process
        throw new IllegalStateException(conversationGroup.getName() + " hosts an invalid usage of @" + ConversationSubGroup.class.getName());
    }
    return result;
}
Also used : ConversationSubGroup(org.apache.deltaspike.core.api.scope.ConversationSubGroup)

Example 2 with ConversationSubGroup

use of org.apache.deltaspike.core.api.scope.ConversationSubGroup in project deltaspike by apache.

the class GroupedConversationContext method closeConversationGroup.

@Override
public Set<ContextualStorage> closeConversationGroup(Class<?> conversationGroup) {
    Set<ContextualStorage> result = new HashSet<ContextualStorage>();
    ConversationSubGroup conversationSubGroup = conversationGroup.getAnnotation(ConversationSubGroup.class);
    Set<Class<?>> subGroups = null;
    if (conversationSubGroup != null) {
        conversationGroup = ConversationUtils.getDeclaredConversationGroup(conversationGroup);
        subGroups = new HashSet<Class<?>>(conversationSubGroup.subGroup().length);
        Collections.addAll(subGroups, conversationSubGroup.subGroup());
    }
    Map<ConversationKey, ContextualStorage> storageMap = this.conversationBeanHolder.getStorageMap();
    for (Map.Entry<ConversationKey, ContextualStorage> entry : storageMap.entrySet()) {
        if (entry.getKey().getConversationGroup().equals(conversationGroup)) {
            if (subGroups == null) {
                AbstractContext.destroyAllActive(entry.getValue());
                result.add(entry.getValue());
                //ok due to ConcurrentHashMap
                storageMap.remove(entry.getKey());
            } else {
                tryToDestroySubGroup(subGroups, entry);
                if (entry.getValue().getStorage().isEmpty()) {
                    //ok due to ConcurrentHashMap
                    storageMap.remove(entry.getKey());
                }
            }
        }
    }
    return result;
}
Also used : ContextualStorage(org.apache.deltaspike.core.util.context.ContextualStorage) ConversationSubGroup(org.apache.deltaspike.core.api.scope.ConversationSubGroup) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

ConversationSubGroup (org.apache.deltaspike.core.api.scope.ConversationSubGroup)2 HashSet (java.util.HashSet)1 Map (java.util.Map)1 ContextualStorage (org.apache.deltaspike.core.util.context.ContextualStorage)1