Esempio n. 1
0
 /** @see com.thinkparity.ophelia.model.util.daemon.DaemonJob#invoke() */
 @Override
 public void run() {
   interruptCount = 0;
   while (true) {
     final long now = System.currentTimeMillis();
     logger.logVariable("sessionModel.isOnline()", sessionModel.isOnline());
     final long latestProcessTime = queueModel.getLatestProcessTimeMillis();
     logger.logVariable("latestProcessTime", format(latestProcessTime));
     logger.logVariable("latestExecutionTime", format(latestExecutionTime));
     logger.logVariable("timeout", formatDuration(timeout));
     if (isQueueTimeout(now, latestProcessTime)
         && isExecutionTimeout(now)
         && sessionModel.isOnline()) {
       logger.logInfo("The session has expired and will be reclaimed.");
       try {
         queueModel.stopNotificationClient();
       } finally {
         try {
           sessionModel.logout();
         } finally {
           latestExecutionTime = System.currentTimeMillis();
         }
       }
     } else {
       logger.logInfo("The session has not expired.");
     }
     try {
       final long sleepMillis = getSleepMillis(now, latestProcessTime);
       if (0 > sleepMillis) {
         /* we break out of the reaper because we have been "offline"
          * longer than we'd like */
         logger.logInfo("Terminating session reaper.");
         break;
       } else {
         logger.logInfo("Session reaper sleeping.");
         Thread.sleep(getSleepMillis(now, latestProcessTime));
       }
     } catch (final InterruptedException ix) {
       interruptCount++;
       logger.logError(
           ix,
           "Session reaper interrupted:  {0}/{1}",
           interruptCount,
           DEFAULT_INTERRUPT_THRESHOLD);
       if (interruptCount + 1 > interruptThreshold) {
         interruptCount = 0;
         /* we break out of the reaper because we have encountered
          * too many interrupts (unlikely) */
         logger.logInfo("Terminating session reaper.");
         break;
       }
     }
   }
 }
Esempio n. 2
0
  /**
   * Create SessionReaper.
   *
   * @param modelFactory An <code>InternalModelFactory</code>.
   */
  public SessionReaper(final InternalModelFactory modelFactory) {
    super();
    this.latestExecutionTime = System.currentTimeMillis();
    this.logger = new Log4JWrapper(getClass());
    this.queueModel = modelFactory.getQueueModel();
    this.sessionModel = modelFactory.getSessionModel();

    setInterruptThreshold(sessionModel.getConfiguration());
    setTimeout(sessionModel.getConfiguration());
    setTimeoutMargin(sessionModel.getConfiguration());
  }