Package org.serviceconnector.service

Examples of org.serviceconnector.service.Subscription


    abortMessage.setHeader(SCMPHeaderAttributeKey.SC_ERROR_TEXT, SCMPError.SESSION_ABORT.getErrorText(reason));
    abortMessage.setServiceName(this.getServiceName());
    abortMessage.setHeader(SCMPHeaderAttributeKey.OPERATION_TIMEOUT, oti);

    if (session.isCascaded() == true) {
      Subscription subscription = ((Subscription) session);
      // XAB procedure for casc subscriptions
      Set<String> subscriptionIds = subscription.getCscSubscriptionIds().keySet();

      for (String id : subscriptionIds) {
        abortMessage.setSessionId(id);
        this.abortSessionAndWaitMech(oti, abortMessage, reason, true);
      }
      subscription.getCscSubscriptionIds().clear();
      // subscription is of type cascaded - do not forward to server
      return;
    }

    abortMessage.setSessionId(session.getId());
View Full Code Here


        // remove non referenced nodes
        publishMessageQueue.removeNonreferencedNodes();
        SubscriptionLogger.logAbortSubscription((Subscription) session, reason);

        if (session.isCascaded() == true) {
          Subscription subscription = ((Subscription) session);
          // XAB procedure for casc subscriptions
          Set<String> subscriptionIds = subscription.getCscSubscriptionIds().keySet();

          for (String id : subscriptionIds) {
            abortMessage.setSessionId(id);
            try {
              this.serverAbortSubscription(abortMessage, new CommandCallback(false), AppContext
                  .getBasicConfiguration().getSrvAbortOTIMillis());
            } catch (ConnectionPoolBusyException e) {
              LOGGER.warn("aborting subscription failed because of busy connection pool. " + e.toString());
            } catch (Exception e) {
              LOGGER.warn("aborting subscription failed. " + e.toString());
            }
          }
          subscription.getCscSubscriptionIds().clear();
          // subscription is of type cascaded - do not forward to server
          continue;
        }
        try {
          this.serverAbortSubscription(abortMessage, new CommandCallback(false), AppContext.getBasicConfiguration()
View Full Code Here

    int simulation = this.getParameterInt(request, "sim", 0);
    if (simulation > 0) {
      Subscription[] sim = new Subscription[simulation + subscriptions.length];
      System.arraycopy(subscriptions, 0, sim, 0, subscriptions.length);
      for (int i = subscriptions.length; i < simulation; i++) {
        sim[i] = new Subscription(null, "sim " + i, null, 0, 0.0, false);
      }
      subscriptions = sim;
    }
    Paging paging = this.writePagingAttributes(writer, request, subscriptions.length, "");
    int nOfRealSubscriptions = 0;
    for (Subscription subscription : subscriptions) {
      if(subscription.isCascaded() == true) {
        // adding casceded subscriptions of current subscription
        nOfRealSubscriptions += subscription.getCscSubscriptionIds().size();       
      } else {
        // adding current subscription because its a real one!
        nOfRealSubscriptions++;
      }
    }
    writer.writeAttribute("nOfRealSubscriptions", nOfRealSubscriptions + "");
    // String showSessionsParameter = request.getParameter("showsessions");
    int startIndex = paging.getStartIndex();
    int endIndex = paging.getEndIndex();
    for (int i = startIndex; i < endIndex; i++) {
      Subscription subscription = subscriptions[i];
      writer.writeStartElement("subscription");
      this.writeBean(writer, subscription);
      writer.writeEndElement();
    }
    writer.writeEndElement(); // close subscriptions tag
View Full Code Here

    SubscriptionMask subscriptionMask = new SubscriptionMask(mask);
    String sessionInfo = reqMessage.getHeader(SCMPHeaderAttributeKey.SESSION_INFO);
    int noiInSecs = reqMessage.getHeaderInt(SCMPHeaderAttributeKey.NO_DATA_INTERVAL);
    int noiInMillis = noiInSecs * Constants.SEC_TO_MILLISEC_FACTOR;
    // create temporary subscription
    Subscription tmpSubscription = new Subscription(subscriptionMask, sessionInfo, ipAddressList, noiInMillis, AppContext
        .getBasicConfiguration().getSubscriptionTimeoutMillis(), false);
    tmpSubscription.setService(abstractService);
    reqMessage.setSessionId(tmpSubscription.getId());

    switch (abstractService.getType()) {
    case CASCADED_PUBLISH_SERVICE:
    case CASCADED_CACHE_GUARDIAN:
      // publish service is cascaded
      CascadedPublishService cascadedPublishService = (CascadedPublishService) abstractService;
      CascadedSC cascadedSC = cascadedPublishService.getCascadedSC();
      // add server to subscription
      tmpSubscription.setServer(cascadedSC);
      // service is cascaded - subscribe is made by a normal client
      SubscribeCommandCallback callback = new SubscribeCommandCallback(request, response, responderCallback, tmpSubscription);
      cascadedSC.cascadedSCSubscribe(cascadedPublishService.getCascClient(), reqMessage, callback, oti);
      return;
    default:
View Full Code Here

    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);
View Full Code Here

  @Override
  public void run(IRequest request, IResponse response, IResponderCallback responderCallback) throws Exception {
    SCMPMessage reqMessage = request.getMessage();
    String subscriptionId = reqMessage.getSessionId();
    SCMPMessage message = null;
    Subscription subscription = this.getSubscriptionById(subscriptionId);
    // looks up subscription queue
    PublishMessageQueue<SCMPMessage> publishMessageQueue = this.getPublishMessageQueueById(subscription);
    synchronized (publishMessageQueue) {
      // reset subscription timeout to NOI+ECI
      this.subscriptionRegistry.resetSubscriptionTimeout(subscription,
          subscription.getNoDataIntervalMillis() + subscription.getSubscriptionTimeoutMillis());
      // tries polling message
      message = publishMessageQueue.getMessageOrListen(subscriptionId, request, response);
      if (message == null) {
        // no message available, switched to listening mode for new message
        return;
      }
    }
    LOGGER.debug("CRP message found in queue subscriptionId " + subscriptionId);
    // message found in subscription queue set up reply
    SCMPMessage reply = null;
    if (message.isPart() == true) {
      // message from queue is of type part - outgoing must be part too, no poll request
      reply = new SCMPPart(message.getSCMPVersion(), false, message.getHeader());
    } else {
      reply = new SCMPMessage(message.getSCMPVersion(), message.getHeader());
    }
    reply.setSessionId(reqMessage.getSessionId());
    reply.setMessageType(reqMessage.getMessageType());
    reply.setIsReply(true);
    reply.setBody(message.getBody());
    response.setSCMP(reply);
    // reset subscription timeout to ECI
    this.subscriptionRegistry.resetSubscriptionTimeout(subscription, subscription.getSubscriptionTimeoutMillis());
    // message already gotten from queue no asynchronous process necessary call callback right away
    responderCallback.responseCallback(request, response);
  }
View Full Code Here

    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:
    case CASCADED_CACHE_GUARDIAN:
      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(reqMessage.getSCMPVersion());
    abortMessage.setHeader(SCMPHeaderAttributeKey.SC_ERROR_CODE, SCMPError.SESSION_ABORT.getErrorCode());
    abortMessage.setHeader(SCMPHeaderAttributeKey.SC_ERROR_TEXT,
View Full Code Here

    String sessionInfo = reqMessage.getHeader(SCMPHeaderAttributeKey.SESSION_INFO);
    int noiSecs = reqMessage.getHeaderInt(SCMPHeaderAttributeKey.NO_DATA_INTERVAL);
    int noiInMillis = noiSecs * Constants.SEC_TO_MILLISEC_FACTOR;
    String cscSCMaskString = reqMessage.getHeader(SCMPHeaderAttributeKey.CASCADED_MASK);
    String cascSubscriptionId = reqMessage.getHeader(SCMPHeaderAttributeKey.CASCADED_SUBSCRIPTION_ID);
    Subscription cscSubscription = this.subscriptionRegistry.getSubscription(cascSubscriptionId);
    SubscriptionMask cscMask = new SubscriptionMask(cscSCMaskString);
    Subscription tmpCascSCSubscription = new Subscription(cscMask, sessionInfo, ipAddressList, noiInMillis, AppContext
        .getBasicConfiguration().getSubscriptionTimeoutMillis(), true);
    tmpCascSCSubscription.setService(abstractService);

    switch (abstractService.getType()) {
    case CASCADED_PUBLISH_SERVICE:
    case CASCADED_CACHE_GUARDIAN:
      // publish service is cascaded
      CascadedPublishService cascadedPublishService = (CascadedPublishService) abstractService;
      CascadedSC cascadedSC = cascadedPublishService.getCascadedSC();
      // add server to subscription
      tmpCascSCSubscription.setServer(cascadedSC);

      ISubscriptionCallback callback = null;
      if (cscSubscription == null) {
        // cascaded SC not subscribed yet
        callback = new SubscribeCommandCallback(request, response, responderCallback, tmpCascSCSubscription);
View Full Code Here

    String serviceName = reqMessage.getServiceName();

    // check service is present
    Service abstractService = this.getService(serviceName);
    String subscriptionId = reqMessage.getSessionId();
    Subscription subscription = this.getSubscriptionById(subscriptionId);

    // enhance ipAddressList
    String ipAddressList = reqMessage.getHeader(SCMPHeaderAttributeKey.IP_ADDRESS_LIST);
    ipAddressList = ipAddressList + Constants.SLASH + request.getRemoteSocketAddress().getAddress().getHostAddress();
    reqMessage.setHeader(SCMPHeaderAttributeKey.IP_ADDRESS_LIST, ipAddressList);
    reqMessage.setHeader(SCMPHeaderAttributeKey.ACTUAL_MASK, subscription.getMask().getValue());

    int oti = reqMessage.getHeaderInt(SCMPHeaderAttributeKey.OPERATION_TIMEOUT);

    switch (abstractService.getType()) {
    case CASCADED_PUBLISH_SERVICE:
    case CASCADED_CACHE_GUARDIAN:
      CascadedPublishService cascadedPublishService = (CascadedPublishService) abstractService;
      // publish service is cascaded
      CascadedSC cascadedSC = cascadedPublishService.getCascadedSC();
      ClnChangeSubscriptionCommandCallback callback = new ClnChangeSubscriptionCommandCallback(request, response,
          responderCallback, subscription);
      cascadedSC.cascadedSCChangeSubscription(cascadedPublishService.getCascClient(), reqMessage, callback, oti);
      return;
    default:
      // code for other types of services is below
      break;
    }

    ClnChangeSubscriptionCommandCallback callback = null;
    StatefulServer server = (StatefulServer) subscription.getServer();
    int otiOnSCMillis = (int) (oti * basicConf.getOperationTimeoutMultiplier());
    int tries = (otiOnSCMillis / Constants.WAIT_FOR_FREE_CONNECTION_INTERVAL_MILLIS);
    // Following loop implements the wait mechanism in case of a busy connection pool
    int i = 0;

View Full Code Here

    Service abstractService = this.getService(serviceName);
    int oti = reqMessage.getHeaderInt(SCMPHeaderAttributeKey.OPERATION_TIMEOUT);
    // service is cascaded - unsubscribe is made by a normal client
    String subscriptionId = reqMessage.getSessionId();
    // lookup session and checks properness
    Subscription subscription = this.getSubscriptionById(subscriptionId);
    // looks up publish message queue and stops publish mechanism
    PublishMessageQueue<SCMPMessage> publishMessageQueue = this.getPublishMessageQueueById(subscription);
    // first remove subscription than unsubscribe
    this.subscriptionRegistry.removeSubscription(subscription);
    publishMessageQueue.unsubscribe(subscriptionId);

    switch (abstractService.getType()) {
    case CASCADED_PUBLISH_SERVICE:
    case CASCADED_CACHE_GUARDIAN:
      CascadedPublishService cascadedPublishService = (CascadedPublishService) abstractService;
      // publish service is cascaded
      CascadedSC cascadedSC = cascadedPublishService.getCascadedSC();
      // free server from subscription
      cascadedSC.removeSession(subscription);
      ClnUnsubscribeCommandCallback callback = new ClnUnsubscribeCommandCallback(request, response, responderCallback,
          subscription);
      cascadedSC.cascadedSCUnsubscribe(cascadedPublishService.getCascClient(), reqMessage, callback, oti);
      return;
    default:
      // code for other types of services is below
      break;
    }
    StatefulServer server = (StatefulServer) subscription.getServer();
    ClnUnsubscribeCommandCallback callback = null;
    int otiOnSCMillis = (int) (oti * basicConf.getOperationTimeoutMultiplier());
    int tries = (otiOnSCMillis / Constants.WAIT_FOR_FREE_CONNECTION_INTERVAL_MILLIS);
    int i = 0;
    // Following loop implements the wait mechanism in case of a busy connection pool
View Full Code Here

TOP

Related Classes of org.serviceconnector.service.Subscription

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.