}
/** {@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);
// 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();
PublishMessageQueue<SCMPMessage> queue = ((IPublishService) cascSubscription.getService()).getMessageQueue();
if (cascadedSCMask == null) {
// subscription abort made by cascaded SC on behalf of his last client
this.subscriptionRegistry.removeSubscription(cascSubscription.getId());
queue.unsubscribe(cascSubscription.getId());
cascSubscription.getServer().removeSession(cascSubscription);
SubscriptionLogger.logUnsubscribe(serviceName, cascSubscription.getId());
} else {
// unsubscribe made by cascaded SC on behalf of a clients, others are left
SubscriptionMask cascSCMask = new SubscriptionMask(cascadedSCMask);
queue.changeSubscription(cascSubscription.getId(), cascSCMask);
cascSubscription.setMask(cascSCMask);
SubscriptionLogger.logChangeSubscribe(serviceName, cascSubscription.getId(), cascadedSCMask);
}
CscAbortSubscriptionCommandCallback callback = new CscAbortSubscriptionCommandCallback(request, response,
responderCallback, cascSubscription);
cascadedSC.cascadedSCAbortSubscription(cascadedPublishService.getCascClient(), reqMessage, callback, oti);
return;
default:
// code for other types of services is below
break;
}
StatefulServer server = (StatefulServer) cascSubscription.getServer();
PublishMessageQueue<SCMPMessage> publishMessageQueue = ((IPublishService) cascSubscription.getService()).getMessageQueue();
if (cascadedSCMask == null) {
// subscription abort 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 a clients, others are left
SubscriptionMask cascSCMask = new SubscriptionMask(cascadedSCMask);
publishMessageQueue.changeSubscription(cascSubscription.getId(), cascSCMask);
cascSubscription.setMask(cascSCMask);
SubscriptionLogger.logChangeSubscribe(serviceName, cascSubscription.getId(), cascadedSCMask);
}
// set up abort message
SCMPMessage abortMessage = new SCMPMessage();
abortMessage.setHeader(SCMPHeaderAttributeKey.SC_ERROR_CODE, SCMPError.SESSION_ABORT.getErrorCode());
abortMessage.setHeader(SCMPHeaderAttributeKey.SC_ERROR_TEXT,
SCMPError.SESSION_ABORT.getErrorText("Cascaded subscription abort received."));
abortMessage.setServiceName(serviceName);
abortMessage.setSessionId(reqMessage.getSessionId());
abortMessage.setHeader(SCMPHeaderAttributeKey.OPERATION_TIMEOUT, oti);
server.abortSessionAndWaitMech(oti, abortMessage, "Cascaded subscription abort received", true);
// reply to client
reqMessage.setIsReply(true);
response.setSCMP(reqMessage);
responderCallback.responseCallback(request, response);