Exemplo n.º 1
0
  /**
   * Checks the request for any session. If there is a session created we make sure that the server
   * returned is the one the issued the session. If no session is included in the request we will
   * choose the next server in a round-robin fashion.
   *
   * @see net.sf.j2ep.model.ServerContainer#getServer(javax.servlet.http.HttpServletRequest)
   */
  public Server getServer(HttpServletRequest request) {
    String serverId = getServerIdFromCookie(request.getCookies());
    ClusteredServer server = (ClusteredServer) servers.get(serverId);
    if (server == null || !server.online()) {
      server = getNextServer();
    } else {
      log.debug("Server found in session");
    }

    if (server.online()) {
      log.debug("Using id " + server.getServerId() + " for this request");
    } else {
      log.error(
          "All the servers in this cluster are offline. Using id "
              + server.getServerId()
              + ", will probably not work");
    }
    return server;
  }