Package org.serviceconnector.scmp

Examples of org.serviceconnector.scmp.SCMPMessage


  }

  /** {@inheritDoc} */
  @Override
  public void run(IRequest request, IResponse response, IResponderCallback responderCallback) throws Exception {
    SCMPMessage message = request.getMessage();
    String serviceName = message.getServiceName();
    // check service is present
    Service abstractService = this.getService(serviceName);
    int oti = message.getHeaderInt(SCMPHeaderAttributeKey.OPERATION_TIMEOUT);

    switch (abstractService.getType()) {
    case CASCADED_FILE_SERVICE:
      CascadedSC cascadedSC = ((CascadedFileService) abstractService).getCascadedSC();
      CommandCascCallback callback = new CommandCascCallback(request, response, responderCallback);
      cascadedSC.serverGetFileList(message, callback, oti);
      return;
    default:
      // code for other types of services is below
      break;
    }

    FileService fileService = this.validateFileService(message.getServiceName());
    if (fileService.isEnabled() == false) {
      SCMPCommandException scmpCommandException = new SCMPCommandException(SCMPError.SERVICE_DISABLED, "service="
          + fileService.getName() + " is disabled");
      scmpCommandException.setMessageType(getKey());
      throw scmpCommandException;
    }
    SCMPMessage reply = null;
    try {
      FileServer fileServer = fileService.getServer();
      reply = fileServer.serverGetFileList(fileService.getPath(), fileService.getGetFileListScriptName(),
          message.getServiceName(), oti);
    } catch (Exception e) {
      SCMPCommandException scmpCommandException = new SCMPCommandException(SCMPError.GET_FILE_LIST_FAILED,
          "Error occured in get file list on SC.");
      scmpCommandException.setMessageType(getKey());
      throw scmpCommandException;
    }
    reply.setIsReply(true);
    reply.setMessageType(getKey());
    response.setSCMP(reply);
    responderCallback.responseCallback(request, response);
  }
View Full Code Here


  /** {@inheritDoc} */
  @Override
  public void validate(IRequest request) throws Exception {
    try {
      SCMPMessage message = request.getMessage();
      // operation timeout mandatory
      String otiValue = message.getHeader(SCMPHeaderAttributeKey.OPERATION_TIMEOUT);
      ValidatorUtility.validateInt(Constants.MIN_OTI_VALUE_CLN, otiValue, Constants.MAX_OTI_VALUE,
          SCMPError.HV_WRONG_OPERATION_TIMEOUT);
      // serviceName mandatory
      String serviceName = message.getServiceName();
      ValidatorUtility.validateStringLengthTrim(1, serviceName, Constants.MAX_LENGTH_SERVICENAME,
          SCMPError.HV_WRONG_SERVICE_NAME);
    } catch (HasFaultResponseException ex) {
      // needs to set message type at this point
      ex.setMessageType(getKey());
View Full Code Here

  /** {@inheritDoc} */
  @Override
  public void receive(Exception ex) {
    LOGGER.warn("receive exception sid=" + sid + " " + ex.toString());
    SCMPMessage fault = null;
    if (ex instanceof IdleTimeoutException) {
      // operation timeout handling
      fault = new SCMPMessageFault(SCMPError.OPERATION_TIMEOUT, "Operation timeout expired on SC sid=" + this.sid);
    } else if (ex instanceof IOException) {
      fault = new SCMPMessageFault(SCMPError.CONNECTION_EXCEPTION, "broken connection to server sid=" + this.sid);
    } else {
      fault = new SCMPMessageFault(SCMPError.SC_ERROR, "error executing " + this.msgType + " sid=" + this.sid);
    }
    // caching
    SCCacheManager cacheManager = AppContext.getCacheManager();
    if (cacheManager.isCacheEnabled() == true) {
      cacheManager.cacheMessage(this.requestMessage, fault);
    }
    // forward server reply to client
    fault.setSessionId(this.sid);
    fault.setIsReply(true);
    fault.setMessageType(this.msgType);
    fault.setServiceName(this.requestServiceName);
    this.response.setSCMP(fault);
    // schedule session timeout
    Session session = this.sessionRegistry.getSession(this.sid);
    if (session != null) {
      synchronized (session) {
View Full Code Here

  }

  /** {@inheritDoc} */
  @Override
  public void receive(SCMPMessage reply) {
    SCMPMessage reqMessage = request.getMessage();
    String serviceName = reqMessage.getServiceName();
    // forward server reply to client
    reply.setIsReply(true);
    reply.setServiceName(serviceName);
    reply.setMessageType(this.msgType);
    this.response.setSCMP(reply);
View Full Code Here

  }

  /** {@inheritDoc} */
  @Override
  public void receive(Exception ex) {
    SCMPMessage reqMessage = this.request.getMessage();
    String sid = reqMessage.getSessionId();
    LOGGER.warn("receive exception sid=" + sid + " " + ex.toString());
    // free server from session
    server.removeSession(session);
    SCMPMessage fault = null;
    String serviceName = reqMessage.getServiceName();
    if (ex instanceof IdleTimeoutException) {
      // operation timeout handling
      fault = new SCMPMessageFault(SCMPError.OPERATION_TIMEOUT, "Operation timeout expired on SC delete session sid=" + sid);
    } else if (ex instanceof IOException) {
      fault = new SCMPMessageFault(SCMPError.CONNECTION_EXCEPTION, "broken connection on SC delete session sid=" + sid);
    } else {
      fault = new SCMPMessageFault(SCMPError.SC_ERROR, "executing delete session failed sid=" + sid);
    }
    // forward server reply to client
    fault.setIsReply(true);
    fault.setServiceName(serviceName);
    fault.setMessageType(this.msgType);
    this.response.setSCMP(fault);
    this.responderCallback.responseCallback(request, response);
    // delete session failed destroy server abort!
    server.abortSession(session, "deleting session failed, exception received in callback");
  }
View Full Code Here

  }

  /** {@inheritDoc} */
  @Override
  public void run(IRequest request, IResponse response, IResponderCallback responderCallback) throws Exception {
    SCMPMessage message = request.getMessage();
    String serviceName = message.getServiceName();
    // lookup service and checks properness
    PublishService service = this.validatePublishService(serviceName);

    // reset server timeout
    this.resetServerTimeout(serviceName, request.getRemoteSocketAddress());

    PublishMessageQueue<SCMPMessage> queue = service.getMessageQueue();
    // throws an exception if failed
    queue.insert(message);

    // reply to server
    SCMPMessage reply = null;
    if (message.isPart()) {
      // incoming message is of type part - outgoing must be part too, poll request
      reply = new SCMPPart(true);

    } else {
      reply = new SCMPMessage();
    }
    reply.setMessageType(this.getKey());
    reply.setIsReply(true);
    reply.setServiceName(serviceName);
    response.setSCMP(reply);
    responderCallback.responseCallback(request, response);
  }
View Full Code Here

  }

  /** {@inheritDoc} */
  @Override
  public void validate(IRequest request) throws Exception {
    SCMPMessage message = request.getMessage();
    try {
      // msgSequenceNr mandatory
      String msgSequenceNr = message.getMessageSequenceNr();
      ValidatorUtility.validateLong(1, msgSequenceNr, SCMPError.HV_WRONG_MESSAGE_SEQUENCE_NR);
      // serviceName mandatory
      String serviceName = message.getServiceName();
      ValidatorUtility.validateStringLengthTrim(1, serviceName, Constants.MAX_LENGTH_SERVICENAME,
          SCMPError.HV_WRONG_SERVICE_NAME);
      // mask mandatory
      String mask = message.getHeader(SCMPHeaderAttributeKey.MASK);
      ValidatorUtility.validateStringLength(1, mask, Constants.MAX_STRING_LENGTH_256, SCMPError.HV_WRONG_MASK);
      // message info optional
      String messageInfo = message.getHeader(SCMPHeaderAttributeKey.MSG_INFO);
      ValidatorUtility.validateStringLengthIgnoreNull(1, messageInfo, Constants.MAX_STRING_LENGTH_256,
          SCMPError.HV_WRONG_MESSAGE_INFO);
    } catch (HasFaultResponseException ex) {
      // needs to set message type at this point
      ex.setMessageType(getKey());
View Full Code Here

  }

  /** {@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();
View Full Code Here

      // XAB procedure for casc subscriptions
      Set<String> subscriptionIds = cascSubscription.getCscSubscriptionIds().keySet();

      int oti = AppContext.getBasicConfiguration().getSrvAbortOTIMillis();
      // 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(cascSubscription.getService().getName());
      abortMessage.setHeader(SCMPHeaderAttributeKey.OPERATION_TIMEOUT, oti);

      StatefulServer server = (StatefulServer) cascSubscription.getServer();

      for (String id : subscriptionIds) {
        abortMessage.setSessionId(id);
        server.abortSessionAndWaitMech(oti, abortMessage, "Cascaded subscription abort in csc unsubscribe command", true);
      }
      cascSubscription.getCscSubscriptionIds().clear();
    }
  }
View Full Code Here

  }

  /** {@inheritDoc} */
  @Override
  public void validate(IRequest request) throws Exception {
    SCMPMessage message = request.getMessage();
    try {
      // msgSequenceNr mandatory
      String msgSequenceNr = message.getMessageSequenceNr();
      ValidatorUtility.validateLong(1, msgSequenceNr, SCMPError.HV_WRONG_MESSAGE_SEQUENCE_NR);
      // serviceName mandatory
      String serviceName = message.getServiceName();
      ValidatorUtility.validateStringLengthTrim(1, serviceName, Constants.MAX_LENGTH_SERVICENAME,
          SCMPError.HV_WRONG_SERVICE_NAME);
      // operation timeout mandatory
      String otiValue = message.getHeader(SCMPHeaderAttributeKey.OPERATION_TIMEOUT);
      ValidatorUtility.validateInt(Constants.MIN_OTI_VALUE_CSC, otiValue, Constants.MAX_OTI_VALUE,
          SCMPError.HV_WRONG_OPERATION_TIMEOUT);
      // cascadedSubscriptionId mandatory
      String cascadedSubscriptionId = message.getHeader(SCMPHeaderAttributeKey.CASCADED_SUBSCRIPTION_ID);
      ValidatorUtility.validateStringLengthTrim(1, cascadedSubscriptionId, Constants.MAX_STRING_LENGTH_256,
          SCMPError.HV_WRONG_SESSION_ID);
      // sessionInfo optional
      ValidatorUtility.validateStringLengthIgnoreNull(1, message.getHeader(SCMPHeaderAttributeKey.SESSION_INFO),
          Constants.MAX_STRING_LENGTH_256, SCMPError.HV_WRONG_SESSION_INFO);
    } catch (HasFaultResponseException ex) {
      // needs to set message type at this point
      ex.setMessageType(getKey());
      throw ex;
View Full Code Here

TOP

Related Classes of org.serviceconnector.scmp.SCMPMessage

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.