Exemple #1
0
  private void resetClientTimer(Socket socket) {
    if (this.idleClientTimer == null) {
      if (log.logTrace()) {
        log.trace("No idle client timeout configured, skipping timer reset");
      }
      return;
    }

    if (log.logTrace()) {
      log.trace("Resetting idle client timer: " + System.identityHashCode(socket));
    }

    // Store this in a local so we don't have to worry about
    // the value changing underneath us.
    long timeout = this.idleClientTimeout;

    // Cancel the existing task for this socket ...
    TimerTask curTask = (TimerTask) this.socketActivity.get(socket);
    if (curTask != null) {
      curTask.cancel();
    }

    // And schedule a new one.
    TimerTask task = new IdleClientTimerTask(socket);
    this.socketActivity.put(socket, task);
    this.idleClientTimer.schedule(task, timeout);
  }
Exemple #2
0
 public void run() {
   try {
     if (log.logTrace()) {
       log.trace("Idle client timer expired: " + System.identityHashCode(socket));
     }
     SocketChannel socketChannel = (SocketChannel) this.socket.getChannel();
     socketChannel.keyFor(HttpRpcServer.this.getSocketSelector()).cancel();
     // This (shutting down the output stream) seems unnecessary but
     // without it the client never sees a disconnect under Linux.
     // For good measure we shutdown the input stream too.
     socketChannel.socket().shutdownOutput();
     socketChannel.socket().shutdownInput();
     socketChannel.close();
     HttpRpcServer.this.deregisterSocket(socket);
   } catch (Exception e) {
     log.warn("IdleClientTimerTask caught an exception", e);
   }
 }