Ejemplo n.º 1
0
    /** Clock tick callback from Timer. */
    public void run() {
      long now = Sys.now();
      delta = now - lastRun;
      lastRun = now;
      debug("AgingTimerTask: tick");

      // Use Visitor pattern to loop through Session objects (see visit()
      // below)
      getInstance().apply(this, visitMethod, new Object[1]);
    }
Ejemplo n.º 2
0
  /** Manages Session timeouts. */
  private class AgingTimerTask extends TimerTask {
    private long lastRun = Sys.now();
    private long delta;
    private Method visitMethod;

    public AgingTimerTask() throws PushletException {
      try {
        // Setup Visitor Methods for callback from SessionManager
        Class[] argsClasses = {Session.class};
        visitMethod = this.getClass().getMethod("visit", argsClasses);
      } catch (NoSuchMethodException e) {
        throw new PushletException("Failed to setup AgingTimerTask", e);
      }
    }

    /** Clock tick callback from Timer. */
    public void run() {
      long now = Sys.now();
      delta = now - lastRun;
      lastRun = now;
      debug("AgingTimerTask: tick");

      // Use Visitor pattern to loop through Session objects (see visit()
      // below)
      getInstance().apply(this, visitMethod, new Object[1]);
    }

    /** Callback from SessionManager during apply() */
    public void visit(Session aSession) {
      try {
        // Age the lease
        aSession.age(delta);
        debug("AgingTimerTask: visit: " + aSession);

        // Stop session if lease expired
        if (aSession.isExpired()) {
          info("AgingTimerTask: Session expired: " + aSession);
          aSession.stop();
        }
      } catch (Throwable t) {
        warn("AgingTimerTask: Error in timer task : " + t);
      }
    }
  }