subscribe(BuiltInServices.ServerBus.name(), new MessageCallback() {
@Override
@SuppressWarnings({"unchecked", "SynchronizationOnLocalVariableOrMethodParameter"})
public void callback(final Message message) {
try {
final QueueSession session = getSession(message);
MessageQueueImpl queue = (MessageQueueImpl) messageQueues.get(session);
switch (BusCommands.valueOf(message.getCommandType())) {
case Heartbeat:
if (queue != null) {
queue.heartBeat();
}
break;
case RemoteSubscribe:
if (queue == null) return;
if (message.hasPart(MessageParts.SubjectsList)) {
for (final String subject : (List<String>) message.get(List.class, MessageParts.SubjectsList)) {
remoteSubscribe(session, queue, subject);
}
}
else {
remoteSubscribe(session, messageQueues.get(session),
message.get(String.class, MessageParts.Subject));
}
break;
case RemoteUnsubscribe:
if (queue == null) return;
remoteUnsubscribe(session, queue,
message.get(String.class, MessageParts.Subject));
break;
case FinishStateSync:
if (queue == null) return;
queue.finishInit();
drainDeferredDeliveryQueue(queue);
break;
case Disconnect:
if (queue == null) return;
synchronized (messageQueues) {
queue.stopQueue();
closeQueue(queue);
session.endSession();
}
break;
case Resend:
if (queue == null) return;
case ConnectToQueue: {
List<Message> deferred = null;
synchronized (messageQueues) {
if (messageQueues.containsKey(session)) {
final MessageQueue q = messageQueues.get(session);
synchronized (q) {
if (deferredQueue.containsKey(q)) {
deferred = deferredQueue.remove(q);
}
}
messageQueues.get(session).stopQueue();
}
queue = new MessageQueueImpl(transmissionbuffer, session);
addQueue(session, queue);
if (deferred != null) {
deferredQueue.put(queue, deferred);
}
remoteSubscribe(session, queue, BuiltInServices.ClientBus.name());
}
if (isMonitor()) {
busMonitor.notifyQueueAttached(session.getSessionId(), queue);
}
createConversation(message)
.toSubject(BuiltInServices.ClientBus.name())
.command(BusCommands.RemoteSubscribe)