示例#1
0
  /**
   * Is this an instance of the default <code>Manager</code> configuration, with all-default
   * properties?
   *
   * @param smanager Manager to be tested
   */
  protected boolean isDefaultManager(StandardManager smanager) {

    if (!"SESSIONS.ser".equals(smanager.getPathname()) || (smanager.getMaxActiveSessions() != -1)) {
      return (false);
    }
    return (true);
  }
示例#2
0
 private void configurePersistSession(Manager manager) {
   Assert.state(
       manager instanceof StandardManager,
       "Unable to persist HTTP session state using manager type " + manager.getClass().getName());
   File dir = getValidSessionStoreDir();
   File file = new File(dir, "SESSIONS.ser");
   ((StandardManager) manager).setPathname(file.getAbsolutePath());
 }
 @Override
 public void start() throws LifecycleException {
   // Use fast, insecure session ID generation for all tests
   Server server = getServer();
   for (Service service : server.findServices()) {
     Container e = service.getContainer();
     for (Container h : e.findChildren()) {
       for (Container c : h.findChildren()) {
         StandardManager m = (StandardManager) c.getManager();
         if (m == null) {
           m = new StandardManager();
           m.setSecureRandomClass("org.apache.catalina.startup.FastNonSecureRandom");
           c.setManager(m);
         }
       }
     }
   }
   super.start();
 }
示例#4
0
 @Override
 public void lifecycleEvent(LifecycleEvent event) {
   if (event.getType().equals(Lifecycle.START_EVENT)) {
     Context context = (Context) event.getLifecycle();
     Manager manager = context.getManager();
     if (manager != null && manager instanceof StandardManager) {
       ((StandardManager) manager).setPathname(null);
     }
   }
 }
 /**
  * Gracefully terminate the active use of the public methods of this component. This method should
  * be the last one called on a given instance of this component.<br>
  * This will disconnect the cluster communication channel and stop the listener thread.
  *
  * @exception IllegalStateException if this component has not been started
  * @exception LifecycleException if this component detects a fatal error that needs to be reported
  */
 public void stop() throws LifecycleException {
   mManagerRunning = false;
   mChannelStarted = false;
   super.stop();
   try {
     this.sessions.clear();
     cluster.removeManager(this);
   } catch (Exception x) {
     log.error("Unable to stop SimpleTcpReplicationManager", x);
   }
 }
  /**
   * Prepare for the beginning of active use of the public methods of this component. This method
   * should be called after <code>configure()</code>, and before any of the public methods of the
   * component are utilized.<br>
   * Starts the cluster communication channel, this will connect with the other nodes in the
   * cluster, and request the current session state to be transferred to this node.
   *
   * @exception IllegalStateException if this component has already been started
   * @exception LifecycleException if this component detects a fatal error that prevents this
   *     component from being used
   */
  public void start() throws LifecycleException {
    mManagerRunning = true;
    super.start();
    try {
      // the channel is already running
      if (mChannelStarted) return;
      if (log.isInfoEnabled()) log.info("Starting clustering manager...:" + getName());
      if (cluster == null) {
        log.error("Starting... no cluster associated with this context:" + getName());
        return;
      }
      cluster.registerManager(this);

      if (cluster.getMembers().length > 0) {
        Member mbr = cluster.getMembers()[0];
        SessionMessage msg =
            new SessionMessageImpl(
                this.getName(),
                SessionMessage.EVT_GET_ALL_SESSIONS,
                null,
                "GET-ALL",
                "GET-ALL-" + this.getName());
        cluster.send(msg, mbr);
        if (log.isWarnEnabled())
          log.warn(
              "Manager["
                  + getName()
                  + "], requesting session state from "
                  + mbr
                  + ". This operation will timeout if no session state has been received within "
                  + "60 seconds");
        long reqStart = System.currentTimeMillis();
        long reqNow = 0;
        boolean isTimeout = false;
        do {
          try {
            Thread.sleep(100);
          } catch (Exception sleep) {
          }
          reqNow = System.currentTimeMillis();
          isTimeout = ((reqNow - reqStart) > (1000 * 60));
        } while ((!isStateTransferred()) && (!isTimeout));
        if (isTimeout || (!isStateTransferred())) {
          log.error("Manager[" + getName() + "], No session state received, timing out.");
        } else {
          if (log.isInfoEnabled())
            log.info(
                "Manager["
                    + getName()
                    + "], session state received in "
                    + (reqNow - reqStart)
                    + " ms.");
        }
      } else {
        if (log.isInfoEnabled())
          log.info(
              "Manager["
                  + getName()
                  + "], skipping state transfer. No members active in cluster group.");
      } // end if
      mChannelStarted = true;
    } catch (Exception x) {
      log.error("Unable to start SimpleTcpReplicationManager", x);
    }
  }
 /** Override persistence since they don't go hand in hand with replication for now. */
 public void unload() throws IOException {
   if (!getDistributable()) {
     super.unload();
   }
 }