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:
case CASCADED_CACHE_GUARDIAN:
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(reqMessage.getSCMPVersion());
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();
this.abortCascSubscriptions(cascSubscription, reqMessage);
return;
}
} 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);
}
// use server of cascaded client to unsubscribe
StatefulServer server = (StatefulServer) cascSubscription.getServer();
// unsubscribe on backend server
CscUnsubscribeCommandCallback callback;
int otiOnSCMillis = (int) (oti * basicConf.getOperationTimeoutMultiplier());
int tries = (otiOnSCMillis / Constants.WAIT_FOR_FREE_CONNECTION_INTERVAL_MILLIS);