@Override
protected void onSharedObject(RTMPConnection conn, Channel channel, Header source, SharedObjectMessage message) {
if (log.isDebugEnabled()) {
log.debug("onSharedObject - conn: {} channel: {} so message: {}", new Object[] { conn.getSessionId(), channel.getId(), message });
}
final IScope scope = conn.getScope();
if (scope != null) {
// so name
String name = message.getName();
// whether or not the incoming so is persistent
boolean persistent = message.isPersistent();
// shared object service
ISharedObjectService sharedObjectService = (ISharedObjectService) ScopeUtils.getScopeService(scope, ISharedObjectService.class, SharedObjectService.class, false);
if (!sharedObjectService.hasSharedObject(scope, name)) {
log.debug("Shared object service doesnt have requested object, creation will be attempted");
ISharedObjectSecurityService security = (ISharedObjectSecurityService) ScopeUtils.getScopeService(scope, ISharedObjectSecurityService.class);
if (security != null) {
// Check handlers to see if creation is allowed
for (ISharedObjectSecurity handler : security.getSharedObjectSecurity()) {
if (!handler.isCreationAllowed(scope, name, persistent)) {
log.debug("Shared object create failed, creation is not allowed");
sendSOCreationFailed(conn, message);
return;
}
}
}
if (!sharedObjectService.createSharedObject(scope, name, persistent)) {
log.debug("Shared object create failed");
sendSOCreationFailed(conn, message);
return;
}
}
ISharedObject so = sharedObjectService.getSharedObject(scope, name);
if (so != null) {
if (so.isPersistent() == persistent) {
log.debug("Dispatch persistent shared object");
so.dispatchEvent(message);
} else {
log.warn("Shared object persistence mismatch - current: {} incoming: {}", so.isPersistent(), persistent);
// reset the object so we can re-use it
message.reset();
// add the error event
message.addEvent(new SharedObjectEvent(ISharedObjectEvent.Type.CLIENT_STATUS, "error", SO_PERSISTENCE_MISMATCH));
conn.getChannel(3).write(message);
}
} else {
log.warn("Shared object lookup returned null for {} in {}", name, scope.getName());
// reset the object so we can re-use it
message.reset();
// add the error event
message.addEvent(new SharedObjectEvent(ISharedObjectEvent.Type.CLIENT_STATUS, "error", NC_CALL_FAILED));
conn.getChannel(3).write(message);