* If the message didn't not come from a remote, we don't handle it.
*/
if (!message.isFlagSet(RoutingFlag.FromRemote))
return;
final LocalContext localContext = LocalContext.get(message);
switch (CDICommands.valueOf(message.getCommandType())) {
case CDIEvent:
if (!isRoutable(localContext, message)) {
return;
}
final Object o = message.get(Object.class, CDIProtocol.BeanReference);
EventConversationContext.activate(o, CDIServerUtil.getSessionId(message));
try {
@SuppressWarnings("unchecked")
final Set<String> qualifierNames = message.get(Set.class, CDIProtocol.Qualifiers);
List<Annotation> qualifiers = null;
if (qualifierNames != null) {
for (String qualifierName : qualifierNames) {
if (qualifiers == null) {
qualifiers = new ArrayList<Annotation>();
}
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:
MessageBuilder.createConversation(message).toSubject(CDI.CLIENT_DISPATCHER_SUBJECT)
.command(BusCommands.RemoteSubscribe)
.with(MessageParts.Value, observedEvents.toArray(new String[observedEvents.size()])).done().reply();
localContext.setAttribute(CDI_EVENT_CHANNEL_OPEN, "1");
break;
default:
throw new IllegalArgumentException("Unknown command type " + message.getCommandType());
}