log.debug("Poll: {}", clientId);
//send back stored updates for this client
if (registrations.containsKey(clientId)) {
ServiceAdapter adapter = registrations.get(clientId);
if (adapter != null) {
CommandMessage result = new CommandMessage();
result.setOperation(Constants.CLIENT_SYNC_OPERATION);
//result.setCorrelationId(msg.getMessageId());
//this will be the body of the responding command message
AsyncMessageExt ext = new AsyncMessageExt();
ext.setClientId(clientId);
ext.setCorrelationId(msg.getMessageId());
ext.setDestination("Red5Chat");
ext.setBody(adapter.manage(msg));
//add as a child (body) of the command message
result.setBody(new Object[]{ext});
return result;
} else {
log.debug("Adapter was not available");
}
}
break;
case Constants.SUBSCRIBE_OPERATION: //0
log.debug("Subscribe: {}", clientId);
//if there is a destination check for an adapter
if (StringUtils.isNotBlank(destination)) {
//look-up end-point and register
if (endpoints.containsKey(destination)) {
Object endpoint = endpoints.get(destination);
//if the endpoint is an adapter, try to subscribe
if (endpoint instanceof ServiceAdapter) {
ServiceAdapter adapter = (ServiceAdapter) endpoint;
boolean subscribed = ((Boolean) adapter.manage(msg));
if (subscribed) {
log.debug("Client was subscribed");
registerClientToAdapter(clientId, adapter);
} else {
log.debug("Client was not subscribed");
}
}
}
}
// Send back registration ok
break;
case Constants.UNSUBSCRIBE_OPERATION: //1
log.trace("Unsubscribe: {}", clientId);
if (registrations.containsKey(clientId)) {
ServiceAdapter adapter = registrations.get(clientId);
boolean unsubscribed = ((Boolean) adapter.manage(msg));
if (unsubscribed) {
log.debug("Client was unsubscribed");
unregisterClientFromAdapter(clientId);
} else {
log.debug("Client was not unsubscribed");
}
} else {
log.debug("Client was not subscribed");
}
// Send back unregistration ok
break;
default:
log.error("Unknown CommandMessage request: {}", msg);
String errMsg = String.format("Don't know how to handle %s", msg);
return returnError(msg, "notImplemented", errMsg, errMsg);
}
AcknowledgeMessage result = new AcknowledgeMessage();
result.setBody(msg.getBody());
result.setClientId(clientId);
result.setCorrelationId(msg.getMessageId());
result.setHeaders(headers);
// put destination in ack if it exists
if (StringUtils.isNotBlank(destination)) {
result.setDestination(destination);
}
return result;
}