return;
try {
ScopeUtil.associateRequestContext(message);
final LocalContext localContext = LocalContext.get(message);
switch (CDICommands.valueOf(message.getCommandType())) {
case RemoteSubscribe:
if (afterBeanDiscovery != null) {
final String signature = getSignatureFromMessage(message);
final String typeName = message.get(String.class, CDIProtocol.BeanType);
final Class<?> type = Class.forName(typeName);
final Set<String> annotationTypes = message.get(Set.class, CDIProtocol.Qualifiers);
if (!activeObserverSignatures.contains(signature)) {
if (type == null || !EnvUtil.isPortableType(type)) {
log.warn("client tried to register a non-portable type: " + type);
return;
}
final DynamicEventObserverMethod observerMethod
= new DynamicEventObserverMethod(eventRoutingTable, messagebus, type, annotationTypes);
if (!activeObserverMethods.contains(observerMethod)) {
afterBeanDiscovery.addObserverMethod(observerMethod);
int clearCount = clearBeanManagerObserverCaches(beanManager);
log.debug("Cleared observer resolution caches of " + clearCount + " bean managers");
activeObserverMethods.add(observerMethod);
}
activeObserverSignatures.add(signature);
}
eventRoutingTable.activateRoute(typeName, annotationTypes, message.getResource(QueueSession.class, "Session"));
}
break;
case RemoteUnsubscribe:
final String typeName = message.get(String.class, CDIProtocol.BeanType);
final Set<String> annotationTypes = message.get(Set.class, CDIProtocol.Qualifiers);
eventRoutingTable.deactivateRoute(typeName, annotationTypes, message.getResource(QueueSession.class, "Session"));
break;
case CDIEvent:
if (!isRoutable(localContext, message)) {
return;
}
final Object o = message.get(Object.class, CDIProtocol.BeanReference);
EventConversationContext.activate(o, CDIServerUtil.getSession(message));
try {
@SuppressWarnings("unchecked")
final Set<String> qualifierNames = message.get(Set.class, CDIProtocol.Qualifiers);
List<Annotation> qualifiers = null;
if (qualifierNames != null) {
for (final String qualifierName : qualifierNames) {
if (qualifiers == null) {
qualifiers = new ArrayList<Annotation>();
}
final Annotation qualifier = allQualifiers.get(qualifierName);
if (qualifier != null) {
qualifiers.add(qualifier);
}
}
}
if (qualifiers != null) {
beanManager.fireEvent(o, qualifiers.toArray(new Annotation[qualifiers.size()]));
}
else {
beanManager.fireEvent(o);
}
}
finally {
EventConversationContext.deactivate();
}
break;
case AttachRemote:
if (observedEvents.size() > 0) {
MessageBuilder.createConversation(message).toSubject(CDI.CLIENT_DISPATCHER_SUBJECT)
.command(CDICommands.AttachRemote)
.with(MessageParts.RemoteServices, getEventTypes()).done().reply();
}
else {
MessageBuilder.createConversation(message).toSubject(CDI.CLIENT_DISPATCHER_SUBJECT)
.command(CDICommands.AttachRemote)
.with(MessageParts.RemoteServices, "").done().reply();
}
localContext.setAttribute(CDI_EVENT_CHANNEL_OPEN, "1");
break;
default:
throw new IllegalArgumentException("Unknown command type " + message.getCommandType());
}