public void process() {
    switch (request.getRequestType()) {
      case START_SESSION:
        log.info("Got a request to create a new session: "
                 + new DesiredCapabilities(request.getDesiredCapabilities()));
        try {
          registry.addNewSessionRequest(this);
          waitForSessionBound();
          beforeSessionEvent();
          forwardNewSessionRequestAndUpdateRegistry(session);
        } catch (Exception e) {
          cleanup();
          log.log(Level.INFO, "Error forwarding the new session " + e.getMessage(), e);
          throw new GridException("Error forwarding the new session " + e.getMessage(), e);
        }
        break;
      case REGULAR:
      case STOP_SESSION:
        session = getSession();
        if (session == null) {
          ExternalSessionKey sessionKey = null;
          try {
            sessionKey = request.extractSession();
          } catch (RuntimeException ignore) {}
          throw new GridException("Session [" + sessionKey + "] not available - "
              + registry.getActiveSessions());
        }
        try {
          forwardRequest(session, this);
        } catch (ClientGoneException e) {
          log.log(Level.WARNING, "The client is gone for session " + session + ", terminating");
          registry.terminate(session, SessionTerminationReason.CLIENT_GONE);
        } catch (SocketTimeoutException e) {
          log.log(Level.SEVERE, "Socket timed out for session " + session + ", " + e.getMessage());
          registry.terminate(session, SessionTerminationReason.SO_TIMEOUT);
        } catch (Throwable t) {
          log.log(Level.SEVERE, "cannot forward the request " + t.getMessage(), t);
          registry.terminate(session, SessionTerminationReason.FORWARDING_TO_NODE_FAILED);
          throw new GridException("cannot forward the request " + t.getMessage(), t);
        }

        if (request.getRequestType() == RequestType.STOP_SESSION) {
          registry.terminate(session, SessionTerminationReason.CLIENT_STOPPED_SESSION);
        }
        break;
      default:
        throw new RuntimeException("NI");
    }
  }
public void process ( ) { switch ( request . getRequestType ( ) ) { case START_SESSION : log . info ( "Got a request to create a new session: " + new DesiredCapabilities ( request . getDesiredCapabilities ( ) ) ) ; try { registry . addNewSessionRequest ( this ) ; waitForSessionBound ( ) ; beforeSessionEvent ( ) ; forwardNewSessionRequestAndUpdateRegistry ( session ) ; } catch ( Exception e ) { cleanup ( ) ; log . log ( Level . INFO , "Error forwarding the new session " + e . getMessage ( ) , e ) ; throw new GridException ( "Error forwarding the new session " + e . getMessage ( ) , e ) ; } break ; case REGULAR : case STOP_SESSION : session = getSession ( ) ; if ( session == null ) { ExternalSessionKey sessionKey = null ; try { sessionKey = request . extractSession ( ) ; } catch ( RuntimeException ignore ) { } throw new GridException ( "Session [" + sessionKey + "] not available - " + registry . getActiveSessions ( ) ) ; } try { forwardRequest ( session , this ) ; } catch ( ClientGoneException e ) { log . log ( Level . WARNING , "The client is gone for session " + session + ", terminating" ) ; registry . terminate ( session , SessionTerminationReason . CLIENT_GONE ) ; } catch ( SocketTimeoutException e ) { log . log ( Level . SEVERE , "Socket timed out for session " + session + ", " + e . getMessage ( ) ) ; registry . terminate ( session , SessionTerminationReason . SO_TIMEOUT ) ; } catch ( Throwable t ) { log . log ( Level . SEVERE , "cannot forward the request " + t . getMessage ( ) , t ) ; registry . terminate ( session , SessionTerminationReason . FORWARDING_TO_NODE_FAILED ) ; throw new GridException ( "cannot forward the request " + t . getMessage ( ) , t ) ; } if ( request . getRequestType ( ) == RequestType . STOP_SESSION ) { registry . terminate ( session , SessionTerminationReason . CLIENT_STOPPED_SESSION ) ; } break ; default : throw new RuntimeException ( "NI" ) ; } }
forwards the request to the remote, allocating / releasing the resources if necessary.