Package org.serviceconnector.cmd

Examples of org.serviceconnector.cmd.SCMPCommandException


    int otiOnSCMillis = (int) (oti * basicConf.getOperationTimeoutMultiplier());
    String sessionId = reqMessage.getSessionId();
    Session session = this.getSessionById(sessionId);
    if (session.hasPendingRequest() == true) {
      LOGGER.warn("sid=" + sessionId + " has pending request");
      SCMPCommandException scmpCommandException = new SCMPCommandException(SCMPError.PARALLEL_REQUEST, "service="
          + reqMessage.getServiceName() + " sid=" + sessionId);
      scmpCommandException.setMessageType(this.getKey());
      throw scmpCommandException;
    }
    // sets the time of last execution
    session.resetExecuteTime();
    synchronized (session) {
      session.setPendingRequest(true); // IMPORTANT - set true before reset timeout - because of parallel echo call
      // reset session timeout to OTI+ECI - during wait for server reply
      this.sessionRegistry.resetSessionTimeout(session, (otiOnSCMillis + session.getSessionTimeoutMillis()));
    }
    if (cacheManager.isCacheEnabled()) {
      try {
        // try to load response from cache
        SCMPMessage message = cacheManager.tryGetMessageFromCacheOrLoad(reqMessage);
        if (message != null) {
          synchronized (session) {
            // reset session timeout to ECI
            this.sessionRegistry.resetSessionTimeout(session, session.getSessionTimeoutMillis());
            session.setPendingRequest(false); // IMPORTANT - set false after reset timeout - parallel echo call
          }
          // message found in cache - hand it to the client
          response.setSCMP(message);
          responderCallback.responseCallback(request, response);
          return;
        }
      } catch (Exception e) {
        synchronized (session) {
          // reset session timeout to ECI
          this.sessionRegistry.resetSessionTimeout(session, session.getSessionTimeoutMillis());
          session.setPendingRequest(false); // IMPORTANT - set false after reset timeout - because of parallel echo call
        }
        throw e;
      }
    }
    ExecuteCommandCallback callback = null;
    StatefulServer server = session.getStatefulServer();
    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;
    do {
      // reset msgType, might have been modified in below execute try
      reqMessage.setMessageType(this.getKey());
      callback = new ExecuteCommandCallback(request, response, responderCallback, sessionId);
      try {
        server.execute(reqMessage, callback, otiOnSCMillis - (i * Constants.WAIT_FOR_FREE_CONNECTION_INTERVAL_MILLIS));
        // no exception has been thrown - get out of wait loop
        break;
      } catch (ConnectionPoolBusyException ex) {
        LOGGER.debug("ConnectionPoolBusyException caught in wait mec of csc execute, tries left=" + tries);
        if (i >= (tries - 1)) {
          // only one loop outstanding - don't continue throw current exception
          synchronized (session) {
            // reset session timeout to ECI
            this.sessionRegistry.resetSessionTimeout(session, session.getSessionTimeoutMillis());
            session.setPendingRequest(false); // IMPORTANT - set false after reset - because of parallel echo call
          }
          LOGGER.debug(SCMPError.NO_FREE_CONNECTION.getErrorText("service=" + reqMessage.getServiceName()));
          SCMPCommandException scmpCommandException = new SCMPCommandException(SCMPError.NO_FREE_CONNECTION, "service="
              + reqMessage.getServiceName());
          scmpCommandException.setMessageType(this.getKey());
          throw scmpCommandException;
        }
      }
      // sleep for a while and then try again
      Thread.sleep(Constants.WAIT_FOR_FREE_CONNECTION_INTERVAL_MILLIS);
View Full Code Here


      } catch (ConnectionPoolBusyException ex) {
        LOGGER.debug("ConnectionPoolBusyException caught in wait mec of csc change subscription, tries left=" + tries);
        if (i >= (tries - 1)) {
          // only one loop outstanding - don't continue throw current exception
          LOGGER.debug(SCMPError.NO_FREE_CONNECTION.getErrorText("service=" + reqMessage.getServiceName()));
          SCMPCommandException scmpCommandException = new SCMPCommandException(SCMPError.NO_FREE_CONNECTION, "service="
              + reqMessage.getServiceName());
          scmpCommandException.setMessageType(this.getKey());
          throw scmpCommandException;
        }
      } // sleep for a while and then try again
      Thread.sleep(Constants.WAIT_FOR_FREE_CONNECTION_INTERVAL_MILLIS);
    } while (++i < tries);
View Full Code Here

    SCMPMessage reqMessage = request.getMessage();
    String serviceName = reqMessage.getServiceName();
    // check service is present and enabled
    Service abstractService = this.getService(serviceName);
    if (abstractService.isEnabled() == false) {
      SCMPCommandException scmpCommandException = new SCMPCommandException(SCMPError.SERVICE_DISABLED, "service="
          + abstractService.getName() + " is disabled");
      scmpCommandException.setMessageType(getKey());
      throw scmpCommandException;
    }
    // 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);
    String sessionInfo = reqMessage.getHeader(SCMPHeaderAttributeKey.SESSION_INFO);
    int eciInSeconds = reqMessage.getHeaderInt(SCMPHeaderAttributeKey.ECHO_INTERVAL);
    int eciInMillis = eciInSeconds * Constants.SEC_TO_MILLISEC_FACTOR;
    int oti = reqMessage.getHeaderInt(SCMPHeaderAttributeKey.OPERATION_TIMEOUT);

    switch (abstractService.getType()) {
    case CASCADED_SESSION_SERVICE:
      CascadedSC cascadedSC = ((CascadedSessionService) abstractService).getCascadedSC();
      CommandCascCallback callback = new CommandCascCallback(request, response, responderCallback);
      cascadedSC.createSession(reqMessage, callback, oti);
      return;
    case CASCADED_FILE_SERVICE:
      cascadedSC = ((CascadedFileService) abstractService).getCascadedSC();
      callback = new CommandCascCallback(request, response, responderCallback);
      cascadedSC.createSession(reqMessage, callback, oti);
      return;
    case SESSION_SERVICE:
      // code for type session service is below switch statement
      break;
    case FILE_SERVICE:
      FileService fileService = (FileService) abstractService;
      // create file session
      FileSession fileSession = new FileSession(sessionInfo, ipAddressList, fileService.getPath(),
          fileService.getUploadFileScriptName(), fileService.getGetFileListScriptName());
      fileSession.setService(fileService);
      FileServer fileServer = fileService.allocateFileServerAndCreateSession(fileSession);
      // add server to session
      fileSession.setServer(fileServer);
      fileSession.setSessionTimeoutMillis(eciInMillis * basicConf.getEchoIntervalMultiplier());
      // finally add file session to the registry
      this.sessionRegistry.addSession(fileSession.getId(), fileSession);
      // reply to client
      SCMPMessage reply = new SCMPMessage();
      reply.setIsReply(true);
      reply.setMessageType(getKey());
      reply.setSessionId(fileSession.getId());
      response.setSCMP(reply);
      responderCallback.responseCallback(request, response);
      return;
    default:
      // code for other types of services is below
      break;
    }

    // create session
    Session session = new Session(sessionInfo, ipAddressList);
    session.setService(abstractService);
    session.setSessionTimeoutMillis(eciInMillis * basicConf.getEchoIntervalMultiplier());
    reqMessage.setSessionId(session.getId());
    // no need to forward echo attributes
    reqMessage.removeHeader(SCMPHeaderAttributeKey.ECHO_INTERVAL);

    // tries allocating a server for this session
    CreateSessionCommandCallback callback = null;

    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;
    do {
      // reset ipList&msgType, might have been modified in below create session try
      reqMessage.setHeader(SCMPHeaderAttributeKey.IP_ADDRESS_LIST, ipAddressList);
      reqMessage.setMessageType(this.getKey());
      callback = new CreateSessionCommandCallback(request, response, responderCallback, session);
      try {
        ((SessionService) abstractService).allocateServerAndCreateSession(reqMessage, callback, session, otiOnSCMillis
            - (i * Constants.WAIT_FOR_FREE_CONNECTION_INTERVAL_MILLIS));
        // no exception has been thrown - get out of wait loop
        break;
      } catch (NoFreeServerException ex) {
        LOGGER.debug("NoFreeServerException caught in wait mec of csc create session, tries left=" + tries);
        if (i >= (tries - 1)) {
          // only one loop outstanding - don't continue throw current exception
          throw ex;
        }
      } catch (ConnectionPoolBusyException ex) {
        LOGGER.debug("ConnectionPoolBusyException caught in wait mec of csc create session, tries left=" + tries);
        if (i >= (tries - 1)) {
          // only one loop outstanding - don't continue throw current exception
          LOGGER.warn(SCMPError.NO_FREE_CONNECTION.getErrorText("service=" + reqMessage.getServiceName()));
          SCMPCommandException scmpCommandException = new SCMPCommandException(SCMPError.NO_FREE_CONNECTION, "service="
              + reqMessage.getServiceName());
          scmpCommandException.setMessageType(this.getKey());
          throw scmpCommandException;
        }
      }
      // sleep for a while and then try again
      Thread.sleep(Constants.WAIT_FOR_FREE_CONNECTION_INTERVAL_MILLIS);
View Full Code Here

   */
  private Server getServerByKeyAndValidateNotRegistered(String key) throws SCMPCommandException {
    Server server = this.serverRegistry.getServer(key);
    if (server != null) {
      // server registered two times for this service
      SCMPCommandException cmdExc = new SCMPCommandException(SCMPError.SERVER_ALREADY_REGISTERED, "server=" + key);
      cmdExc.setMessageType(getKey());
      throw cmdExc;
    }
    return server;
  }
View Full Code Here

    try {
      String remoteFileName = message.getHeader(SCMPHeaderAttributeKey.REMOTE_FILE_NAME);
      FileServer fileServer = session.getFileServer();
      reply = fileServer.serverUploadFile(session, message, remoteFileName, oti);
    } catch (Exception e) {
      SCMPCommandException scmpCommandException = new SCMPCommandException(SCMPError.FILE_UPLOAD_FAILED,
          "Error occured in file server on SC.");
      scmpCommandException.setMessageType(getKey());
      throw scmpCommandException;
    }
    reply.setIsReply(true);
    reply.setMessageType(getKey());
    response.setSCMP(reply);
View Full Code Here

            LOGGER.warn("Requested partNr=" + reqPartNr + " does not match current loading state (numberOfParts="
                + nextPartNrToLoad + ").");
            this.removeMetaAndDataEntries(sessionId, reqCacheKey, "Requested partNr=" + reqPartNr
                + " does not match current loading state (numberOfParts=" + nextPartNrToLoad + ").");
            // do return an error here to stop current request loading this message and avoid parallel loading problems
            SCMPCommandException scmpCommandException = new SCMPCommandException(SCMPError.CACHE_ERROR,
                "cache cleared message invalid partNr in request service=" + serviceName + " cacheId=" + cacheId);
            scmpCommandException.setMessageType(reqMessage.getMessageType());
            throw scmpCommandException;
          }
          return null;
        }
        SCMPCommandException scmpCommandException = new SCMPCommandException(SCMPError.CACHE_LOADING, "service="
            + serviceName + " cacheId=" + cacheId);
        scmpCommandException.setMessageType(reqMessage.getMessageType());
        throw scmpCommandException;
      } else {
        LOGGER.error("Cache error, bad state of meta entry cacheKey=" + reqCacheKey);
        return null;
      }
View Full Code Here

      responderCallback.responseCallback(request, response);
      return;
    case CASCADED_SC:
    case UNDEFINED:
    default:
      throw new SCMPCommandException(SCMPError.SC_ERROR, "delete session not allowed for service "
          + abstractService.getName());
    }
    StatefulServer statefulServer = (StatefulServer) abstractServer;
    DeleteSessionCommandCallback callback;
    // free server from session
    statefulServer.removeSession(session);

    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;
    do {
      // reset msgType, might have been modified in below delete session try
      reqMessage.setMessageType(this.getKey());
      callback = new DeleteSessionCommandCallback(request, response, responderCallback, session, statefulServer);
      try {
        statefulServer.deleteSession(reqMessage, callback, otiOnSCMillis
            - (i * Constants.WAIT_FOR_FREE_CONNECTION_INTERVAL_MILLIS));
        // no exception has been thrown - get out of wait loop
        break;
      } catch (ConnectionPoolBusyException ex) {
        LOGGER.debug("ConnectionPoolBusyException caught in wait mec of csc delete session, tries left=" + tries);
        if (i >= (tries - 1)) {
          // only one loop outstanding - don't continue throw current exception
          statefulServer.abortSession(session, "deleting session failed, connection pool to server busy");
          LOGGER.debug(SCMPError.NO_FREE_CONNECTION.getErrorText("service=" + reqMessage.getServiceName()));
          SCMPCommandException scmpCommandException = new SCMPCommandException(SCMPError.NO_FREE_CONNECTION, "service="
              + reqMessage.getServiceName());
          scmpCommandException.setMessageType(this.getKey());
          throw scmpCommandException;
        }
      }
      // sleep for a while and then try again
      Thread.sleep(Constants.WAIT_FOR_FREE_CONNECTION_INTERVAL_MILLIS);
View Full Code Here

   */
  private String getCacheInspectString(final String serviceName, final String cacheKey) throws SCMPCommandException,
      UnsupportedEncodingException {
    SCCacheManager cacheManager = AppContext.getCacheManager();
    if (cacheManager == null) {
      SCMPCommandException scmpCommandException = new SCMPCommandException(SCMPError.CACHE_MANAGER_ERROR,
          "no cache manager (null)");
      scmpCommandException.setMessageType(getKey());
      throw scmpCommandException;
    }
    @SuppressWarnings("unchecked")
    ISCCache<SCCacheMetaEntry> scCache = (ISCCache<SCCacheMetaEntry>) AppContext.getCacheRegistry().getCache(
        SC_CACHE_TYPE.META_DATA_CACHE.name());
    if (scCache == null) {
      SCMPCommandException scmpCommandException = new SCMPCommandException(SCMPError.CACHE_ERROR, serviceName);
      scmpCommandException.setMessageType(getKey());
      throw scmpCommandException;
    }
    SCCacheMetaEntry metaEntry = (SCCacheMetaEntry) scCache.get(cacheKey);
    if (metaEntry == null) {
      return URLString.toURLResponseString(Constants.CACHE_ID, cacheKey, "return", "notfound");
View Full Code Here

    String serviceName = reqMessage.getServiceName();

    // check service is present and enabled
    Service abstractService = this.getService(serviceName);
    if (abstractService.isEnabled() == false) {
      SCMPCommandException scmpCommandException = new SCMPCommandException(SCMPError.SERVICE_DISABLED, "service="
          + abstractService.getName() + " is disabled");
      scmpCommandException.setMessageType(getKey());
      throw scmpCommandException;
    }

    // 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);

    int oti = reqMessage.getHeaderInt(SCMPHeaderAttributeKey.OPERATION_TIMEOUT);
    // create temporary Subscription for cascaded SC
    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:
      // 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);
      } else {
        // subscribe is made by an active cascaded SC
        callback = new CscChangeSubscriptionCallbackForCasc(request, response, responderCallback, cscSubscription,
            cscSCMaskString);
      }
      cascadedSC.cascadedSCSubscribe(cascadedPublishService.getCascClient(), reqMessage, callback, oti);
      return;
    default:
      // code for other types of services is below
      break;
    }
    // modify message only if it goes to server
    reqMessage.removeHeader(SCMPHeaderAttributeKey.NO_DATA_INTERVAL);
    reqMessage.removeHeader(SCMPHeaderAttributeKey.CASCADED_MASK);
    reqMessage.removeHeader(SCMPHeaderAttributeKey.CASCADED_SUBSCRIPTION_ID);
    // check service is present
    PublishService service = this.validatePublishService(abstractService);
    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
    do {
      // reset ipList&msgType, might have been modified in below operation try
      reqMessage.setHeader(SCMPHeaderAttributeKey.IP_ADDRESS_LIST, ipAddressList);
      reqMessage.setMessageType(this.getKey());
      try {
        if (cscSubscription != null) {
          // cascaded subscribe made by an active cascaded SC
          CscChangeSubscriptionCallbackForCasc cascCallback = new CscChangeSubscriptionCallbackForCasc(request, response,
              responderCallback, cscSubscription, cscSCMaskString);
          ((StatefulServer) cscSubscription.getServer()).subscribe(reqMessage, cascCallback, otiOnSCMillis);
          break;
        }
        // cascaded subscribe made by an inactive cascaded SC - forward client subscribe to server
        SubscribeCommandCallback callback = new SubscribeCommandCallback(request, response, responderCallback,
            tmpCascSCSubscription);
        service.allocateServerAndSubscribe(reqMessage, callback, tmpCascSCSubscription, otiOnSCMillis
            - (i * Constants.WAIT_FOR_FREE_CONNECTION_INTERVAL_MILLIS));
        // no exception has been thrown - get out of wait loop
        break;
      } catch (NoFreeServerException ex) {
        LOGGER.debug("NoFreeServerException caught in wait mec of subscribe, tries left=" + tries);
        if (i >= (tries - 1)) {
          // only one loop outstanding - don't continue throw current exception
          throw ex;
        }
      } catch (ConnectionPoolBusyException ex) {
        LOGGER.debug("ConnectionPoolBusyException caught in wait mec of subscribe, tries left=" + tries);
        if (i >= (tries - 1)) {
          // only one loop outstanding - don't continue throw current exception
          LOGGER.warn(SCMPError.NO_FREE_CONNECTION.getErrorText("service=" + reqMessage.getServiceName()));
          SCMPCommandException scmpCommandException = new SCMPCommandException(SCMPError.NO_FREE_CONNECTION, "service="
              + reqMessage.getServiceName());
          scmpCommandException.setMessageType(this.getKey());
          throw scmpCommandException;
        }
      }
      // sleep for a while and then try again
      Thread.sleep(Constants.WAIT_FOR_FREE_CONNECTION_INTERVAL_MILLIS);
View Full Code Here

            LOGGER.warn("Requested partNr=" + reqPartNr + " does not match current loading state (numberOfParts="
                + nextPartNrToLoad + ").");
            this.removeMetaAndDataEntries(sessionId, reqCacheKey, "Requested partNr=" + reqPartNr
                + " does not match current loading state (numberOfParts=" + nextPartNrToLoad + ").");
            // do return an error here to stop current request loading this message and avoid parallel loading problems
            SCMPCommandException scmpCommandException = new SCMPCommandException(SCMPError.CACHE_ERROR,
                "cache cleared message invalid partNr in request service=" + serviceName + " cacheId=" + cacheId);
            scmpCommandException.setMessageType(reqMessage.getMessageType());
            throw scmpCommandException;
          }
          return null;
        }
        SCMPCommandException scmpCommandException = new SCMPCommandException(SCMPError.CACHE_LOADING, "service="
            + serviceName + " cacheId=" + cacheId);
        scmpCommandException.setMessageType(reqMessage.getMessageType());
        throw scmpCommandException;
      } else {
        LOGGER.error("Cache error, bad state of meta entry cacheKey=" + reqCacheKey);
        return null;
      }
    } else {
      if (reqMessage.isPollRequest()) {
        // poll large response and no meta entry: Cache got destroyed in meantime, stop operation!
        LOGGER.warn("Poll large response with cacheId=" + cacheId
            + " but no meta entry: Has to be after clearing cache, stop operation!");
        SCMPCommandException scmpCommandException = new SCMPCommandException(SCMPError.CACHE_ERROR,
            "Poll large response with cacheId=" + cacheId
                + " but no meta entry: Has to be after clearing cache, stop operation!");
        scmpCommandException.setMessageType(reqMessage.getMessageType());
        throw scmpCommandException;
      }
      // start loading message to cache
      SCCacheMetaEntry newMetaEntry = new SCCacheMetaEntry(reqCacheKey);
      // take original OTI so transporting message would stop before metaEntry expires!
View Full Code Here

TOP

Related Classes of org.serviceconnector.cmd.SCMPCommandException

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.