Beispiel #1
0
  public void registerInterestOps(EventHandler eventHandler) {
    if (orb.transportDebugFlag) {
      dprint(".registerInterestOps:-> " + eventHandler);
    }

    SelectionKey selectionKey = eventHandler.getSelectionKey();
    if (selectionKey.isValid()) {
      int ehOps = eventHandler.getInterestOps();
      SelectionKeyAndOp keyAndOp = new SelectionKeyAndOp(selectionKey, ehOps);
      synchronized (interestOpsList) {
        interestOpsList.add(keyAndOp);
      }
      // tell Selector Thread there's an update to a SelectorKey's Ops
      selector.wakeup();
    } else {
      wrapper.selectionKeyInvalid(eventHandler.toString());
      if (orb.transportDebugFlag) {
        dprint(".registerInterestOps: EventHandler SelectionKey not valid " + eventHandler);
      }
    }

    if (orb.transportDebugFlag) {
      dprint(".registerInterestOps:<- ");
    }
  }
Beispiel #2
0
  public void unregisterForEvent(EventHandler eventHandler) {
    if (orb.transportDebugFlag) {
      dprint(".unregisterForEvent: " + eventHandler);
    }

    if (isClosed()) {
      if (orb.transportDebugFlag) {
        dprint(".unregisterForEvent: closed: " + eventHandler);
      }
      return;
    }

    if (eventHandler.shouldUseSelectThreadToWait()) {
      SelectionKey selectionKey;
      synchronized (deferredRegistrations) {
        selectionKey = eventHandler.getSelectionKey();
      }
      if (selectionKey != null) {
        selectionKey.cancel();
      }
      selector.wakeup();
      return;
    }

    switch (eventHandler.getInterestOps()) {
      case SelectionKey.OP_ACCEPT:
        destroyListenerThread(eventHandler);
        break;
      case SelectionKey.OP_READ:
        destroyReaderThread(eventHandler);
        break;
      default:
        if (orb.transportDebugFlag) {
          dprint(".unregisterForEvent: default: " + eventHandler);
        }
        throw new RuntimeException("SelectorImpl.uregisterForEvent: unknown interest ops");
    }
  }