Package org.serviceconnector.service

Examples of org.serviceconnector.service.Session


    reply.setIsReply(true);
    reply.setMessageType(this.msgType);
    reply.setServiceName(this.requestServiceName);
    this.response.setSCMP(reply);
    // schedule session timeout
    Session session = this.sessionRegistry.getSession(this.sid);
    if (session != null) {
      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
      }
    }
    this.responderCallback.responseCallback(request, response);
  }
View Full Code Here


    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) {
        // reset session timeout to ECI
        this.sessionRegistry.resetSessionTimeout(session, session.getSessionTimeoutMillis());
        session.setPendingRequest(false); // IMPORTANT - set false after reset - because of parallel echo call
      }
    }
    this.responderCallback.responseCallback(request, response);
  }
View Full Code Here

    int simulation = this.getParameterInt(request, "sim", 0);
    if (simulation > 0) {
      Session[] sim = new Session[simulation + sessions.length];
      System.arraycopy(sessions, 0, sim, 0, sessions.length);
      for (int i = sessions.length; i < simulation; i++) {
        sim[i] = new Session("sim " + i, null);
      }
      sessions = sim;
    }
    Paging paging = this.writePagingAttributes(writer, request, sessions.length, "");
    // String showSessionsParameter = request.getParameter("showsessions");
    int startIndex = paging.getStartIndex();
    int endIndex = paging.getEndIndex();
    for (int i = startIndex; i < endIndex; i++) {
      Session session = sessions[i];
      writer.writeStartElement("session");
      this.writeBean(writer, session);
      writer.writeEndElement();
    }
    writer.writeEndElement(); // close sessions tag
View Full Code Here

    default:
      // code for other types of services is below
      break;
    }
    String sessionId = message.getSessionId();
    Session session = this.getSessionById(sessionId);
    message.setIsReply(true);
    response.setSCMP(message);

    synchronized (session) {
      // needs to be in sync because of setting pending request & reseting timer
      if (session.hasPendingRequest() == false) {
        // reset session timeout to ECI - only if no pending request on session
        this.sessionRegistry.resetSessionTimeout(session, session.getSessionTimeoutMillis());
      }
    }
    responderCallback.responseCallback(request, response);
  }
View Full Code Here

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

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

      // code for other types of services is below
      break;
    }

    // lookup session and checks properness
    Session session = this.getSessionById(sessionId);
    synchronized (session) {
      session.setPendingRequest(true); // IMPORTANT - set true because of parallel echo call
      // delete entry from session registry
      this.sessionRegistry.removeSession(session);
    }
    IServer abstractServer = session.getServer();

    switch (abstractServer.getType()) {
    case STATEFUL_SERVER:
      // code for type session service is below switch statement
      break;
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.