/**
   * @see
   *     com.cosylab.epics.caj.impl.reactor.ReactorHandler#handleEvent(java.nio.channels.SelectionKey)
   */
  public void handleEvent(SelectionKey key) {
    // if not valid, just promote new leader
    if (!key.isValid()) {
      threadPool.promoteLeader(this);
      return;
    }

    reactor.disableSelectionKey(key);
    try {
      // promote a follower thread to become a leader
      threadPool.promoteLeader(this);
      // System.err.println("[processing] " + Thread.currentThread().getName());
      // dispatch application-specific event processing code
      handler.handleEvent(key);
    } finally {
      // enable the handle in the reactor
      reactor.enableSelectionKey(key);
    }
  }
 /** @see java.lang.Runnable#run() */
 public void run() {
   if (!reactor.process()) threadPool.shutdown();
 }