Package org.serviceconnector.cmd

Examples of org.serviceconnector.cmd.SCMPCommandException


   *             the SCMP command exception
   */
  protected PublishService validatePublishService(Service service) throws SCMPCommandException {
    if (service.getType() != ServiceType.PUBLISH_SERVICE && service.getType() != ServiceType.CACHE_GUARDIAN) {
      // service is not publish service
      SCMPCommandException scmpCommandException = new SCMPCommandException(SCMPError.V_WRONG_SERVICE_TYPE, service.getName()
          + " is not publish service");
      scmpCommandException.setMessageType(getKey());
      throw scmpCommandException;
    }
    return (PublishService) service;
  }
View Full Code Here


   */
  protected FileService validateFileService(String serviceName) throws SCMPCommandException {
    Service service = this.getService(serviceName);
    if (service.getType() != ServiceType.FILE_SERVICE) {
      // service is not file service
      SCMPCommandException scmpCommandException = new SCMPCommandException(SCMPError.V_WRONG_SERVICE_TYPE, serviceName
          + " is not file service");
      scmpCommandException.setMessageType(getKey());
      throw scmpCommandException;
    }
    return (FileService) service;
  }
View Full Code Here

    case SESSION_SERVICE:
    case CACHE_GUARDIAN:
      break;
    default:
      // service is not the right type
      SCMPCommandException scmpCommandException = new SCMPCommandException(SCMPError.V_WRONG_SERVICE_TYPE, serviceName
          + " is not session or publish service");
      scmpCommandException.setMessageType(getKey());
      throw scmpCommandException;
    }
    return (StatefulService) service;
  }
View Full Code Here

    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 (cache.isCacheEnabled()) {
      try {
        // try to load response from cache
        SCMPMessage message = cache.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

    IResponder responder = AppContext.getResponderRegistry().getCurrentResponder();
    int listenerPort = responder.getListenerConfig().getPort();
    SrvService srvService = srvServiceRegistry.getSrvService(serviceName + "_" + listenerPort);
    if (srvService == null) {
      LOGGER.warn("service=" + serviceName + " port=" + listenerPort + " not found in registry");
      SCMPCommandException scmpCommandException = new SCMPCommandException(SCMPError.SERVICE_NOT_FOUND, serviceName);
      scmpCommandException.setMessageType(this.getKey());
      throw scmpCommandException;
    }
    return srvService;
  }
View Full Code Here

   */
  protected SrvSessionService getSrvSessionServiceByServiceName(String serviceName) throws SCMPCommandException {
    SrvService srvService = this.getSrvServiceByServiceName(serviceName);
    if (srvService instanceof SrvSessionService == false) {
      LOGGER.warn("service=" + serviceName + " not found in registry");
      SCMPCommandException scmpCommandException = new SCMPCommandException(SCMPError.SERVICE_NOT_FOUND, serviceName);
      scmpCommandException.setMessageType(this.getKey());
      throw scmpCommandException;
    }
    return (SrvSessionService) srvService;
  }
View Full Code Here

   */
  protected SrvPublishService getSrvPublishServiceByServiceName(String serviceName) throws SCMPCommandException {
    SrvService srvService = this.getSrvServiceByServiceName(serviceName);
    if (srvService instanceof SrvPublishService == false) {
      LOGGER.warn("service=" + serviceName + " not found in registry");
      SCMPCommandException scmpCommandException = new SCMPCommandException(SCMPError.SERVICE_NOT_FOUND, serviceName);
      scmpCommandException.setMessageType(this.getKey());
      throw scmpCommandException;
    }
    return (SrvPublishService) srvService;
  }
View Full Code Here

        return cachedMessage;
      }

      if (metaEntry.isLoadingAppendix() == true) {
        // requested message gets an updated by an appendix (loading appendix)
        SCMPCommandException scmpCommandException = new SCMPCommandException(SCMPError.CACHE_LOADING, "service="
            + serviceName + " cacheId=" + metaEntryCid);
        scmpCommandException.setMessageType(reqMessage.getMessageType());
        throw scmpCommandException;
      }

      if (metaEntry.isLoading() == true) {
        // requested message is loading
        if (metaEntry.isLoadingSessionId(sessionId) == true) {
          // requested message is being loaded by current session - continue loading
          int nextPartNrToLoad = metaEntry.getNrOfParts(metaEntryCid + Constants.SLASH + appendixNr + Constants.SLASH
              + "0") + 1;
          int reqPartNrInt = Integer.parseInt(reqPartNr);
          if (reqPartNrInt != nextPartNrToLoad) {
            // requested partNr does not match current loading state - remove message from cache
            LOGGER.warn("Requested partNr=" + reqPartNr + " does not match current loading state (numberOfParts="
                + nextPartNrToLoad + ").");
            this.removeMetaAndDataEntries(metaEntryCid, "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="
                    + metaEntryCid);
            scmpCommandException.setMessageType(reqMessage.getMessageType());
            throw scmpCommandException;
          }
          return null;
        }
        SCMPCommandException scmpCommandException = new SCMPCommandException(SCMPError.CACHE_LOADING, "service="
            + serviceName + " cacheId=" + metaEntryCid);
        scmpCommandException.setMessageType(reqMessage.getMessageType());
        throw scmpCommandException;
      } else {
        LOGGER.error("Cache error, bad state of meta entry cacheKey=" + metaEntryCid);
        return null;
      }
View Full Code Here

        } catch (ConnectionPoolBusyException ex) {
          LOGGER.warn("ConnectionPoolBusyException caught in wait mec of session abort");
          if (i >= (tries - 1)) {
            // only one loop outstanding - don't continue throw current exception
            LOGGER.warn(SCMPError.NO_FREE_CONNECTION.getErrorText("service=" + abortMessage.getServiceName()));
            SCMPCommandException scmpCommandException = new SCMPCommandException(SCMPError.NO_FREE_CONNECTION,
                "service=" + abortMessage.getServiceName());
            throw scmpCommandException;
          }
        }
        // sleep for a while and then try again
        Thread.sleep(Constants.WAIT_FOR_FREE_CONNECTION_INTERVAL_MILLIS);
      } while (++i < tries);

      // validate reply of server
      SCMPMessage reply = callback.getMessageSync(oti);
      if (reply.isFault()) {
        // error in server abort session - destroy server
        this.abortSessionsAndDestroy("Session abort failed, abort reason: " + reason);
      }
    } catch (SCMPCommandException scmpCommandException) {
      LOGGER.warn("ConnectionPoolBusyException in aborting session wait mec " + scmpCommandException.toString());
      // ConnectionPoolBusyException after wait mec - try opening a new connection

      // RemoteNodeConfiguration remoteNodeConfiguration = this.requester.getRemoteNodeConfiguration();
      // set up a new requester to make the SAS - only 1 connection is allowed
      Requester sasRequester = new Requester(this.sasRemoteNodeConfiguration);
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.