Package org.serviceconnector.service

Examples of org.serviceconnector.service.Session


   * @return the session by id
   * @throws SCMPCommandException
   *             session is not in registry, invalid session id
   */
  protected Session getSessionById(String sessionId) throws SCMPCommandException {
    Session session = sessionRegistry.getSession(sessionId);
    if (session == null) {
      // session not found in registry
      LOGGER.info("session not found sid=" + sessionId);
      SCMPCommandException scmpCommandException = new SCMPCommandException(SCMPError.SESSION_NOT_FOUND, sessionId);
      scmpCommandException.setMessageType(getKey());
View Full Code Here


      break;
    }

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

      Set<Entry<String, Session>> entries = this.registryMap.entrySet();
      Session[] sessions = new Session[entries.size()];
      int index = 0;
      for (Entry<String, Session> entry : entries) {
        // String key = entry.getKey();
        Session session = entry.getValue();
        sessions[index++] = session;
      }
      return sessions;
    } catch (Exception e) {
      LOGGER.error("getSessions", e);
View Full Code Here

    writer.writeAttribute("sessionScheduler_largestPoolSize", this.sessionScheduler.getLargestPoolSize());
    writer.writeAttribute("sessionScheduler_activeCount", this.sessionScheduler.getActiveCount());

    Set<Entry<String, Session>> sessionEntries = this.registryMap.entrySet();
    for (Entry<String, Session> sessionEntry : sessionEntries) {
      Session session = sessionEntry.getValue();
      session.dump(writer);
    }
    writer.writeEndElement(); // end of sessions
  }
View Full Code Here

TOP

Related Classes of org.serviceconnector.service.Session

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.