}
/** {@inheritDoc} */
@Override
public void run(IRequest request, IResponse response, IResponderCallback responderCallback) throws Exception {
SCMPMessage reqMessage = request.getMessage();
String serviceName = reqMessage.getServiceName();
// check service is present
Service abstractService = this.getService(serviceName);
String cascSubscriptionId = reqMessage.getHeader(SCMPHeaderAttributeKey.CASCADED_SUBSCRIPTION_ID);
Subscription cascSubscription = this.getSubscriptionById(cascSubscriptionId);
String cascadedSCMask = reqMessage.getHeader(SCMPHeaderAttributeKey.CASCADED_MASK);
int oti = reqMessage.getHeaderInt(SCMPHeaderAttributeKey.OPERATION_TIMEOUT);
PublishMessageQueue<SCMPMessage> publishMessageQueue = ((IPublishService) cascSubscription.getService()).getMessageQueue();
// update csc subscription id list for cascaded subscription
cascSubscription.removeCscSubscriptionId(reqMessage.getSessionId());
switch (abstractService.getType()) {
case CASCADED_PUBLISH_SERVICE:
CascadedPublishService cascadedPublishService = (CascadedPublishService) abstractService;
// publish service is cascaded
CascadedSC cascadedSC = cascadedPublishService.getCascadedSC();
if (cascadedSCMask == null) {
// unsubscribe made by cascaded SC on behalf of his last client
this.subscriptionRegistry.removeSubscription(cascSubscription.getId());
publishMessageQueue.unsubscribe(cascSubscription.getId());
cascSubscription.getServer().removeSession(cascSubscription);
SubscriptionLogger.logUnsubscribe(serviceName, cascSubscription.getId());
} else {
// unsubscribe made by cascaded SC on behalf of his clients
SubscriptionMask cascSCMask = new SubscriptionMask(cascadedSCMask);
publishMessageQueue.changeSubscription(cascSubscription.getId(), cascSCMask);
cascSubscription.setMask(cascSCMask);
SubscriptionLogger.logChangeSubscribe(serviceName, cascSubscription.getId(), cascadedSCMask);
}
CscUnsubscribeCallbackForCasc callback = new CscUnsubscribeCallbackForCasc(request, response, responderCallback,
cascSubscription);
cascadedSC.cascadedSCUnsubscribe(cascadedPublishService.getCascClient(), reqMessage, callback, oti);
// delete unreferenced nodes in queue
publishMessageQueue.removeNonreferencedNodes();
return;
default:
// code for other types of services is below
break;
}
if (cascadedSCMask == null) {
// unsubscribe made by cascaded SC on behalf of his last client
this.subscriptionRegistry.removeSubscription(cascSubscription.getId());
publishMessageQueue.unsubscribe(cascSubscription.getId());
cascSubscription.getServer().removeSession(cascSubscription);
SubscriptionLogger.logUnsubscribe(serviceName, cascSubscription.getId());
if (reqMessage.getSessionId() == null) {
// no session id set, cascadedSC unsubscribe on his own because of an error
SCMPMessage reply = new SCMPMessage();
reply.setIsReply(true);
reply.setServiceName(serviceName);
reply.setMessageType(getKey());
// no need to forward to server
response.setSCMP(reply);
responderCallback.responseCallback(request, response);
// delete unreferenced nodes in queue
publishMessageQueue.removeNonreferencedNodes();