Beispiel #1
0
  @Override
  protected void doClose() throws Exception {
    if (state > 2) {
      // Closed already
      return;
    }

    if (parent() == null) {
      LocalChannelRegistry.unregister(localAddress);
    }
    localAddress = null;
    state = 3;
    if (peer.isActive()) {
      peer.unsafe().close(peer.unsafe().voidFuture());
      peer = null;
    }
  }
Beispiel #2
0
  @Override
  protected void doClose() throws Exception {
    if (state != State.CLOSED) {
      // Update all internal state before the closeFuture is notified.
      if (localAddress != null) {
        if (parent() == null) {
          LocalChannelRegistry.unregister(localAddress);
        }
        localAddress = null;
      }
      state = State.CLOSED;
    }

    final LocalChannel peer = this.peer;
    if (peer != null && peer.isActive()) {
      // Need to execute the close in the correct EventLoop
      // See https://github.com/netty/netty/issues/1777
      EventLoop eventLoop = peer.eventLoop();

      // Also check if the registration was not done yet. In this case we submit the close to the
      // EventLoop
      // to make sure it is run after the registration completes.
      //
      // See https://github.com/netty/netty/issues/2144
      if (eventLoop.inEventLoop() && !registerInProgress) {
        peer.unsafe().close(unsafe().voidPromise());
      } else {
        peer.eventLoop()
            .execute(
                new Runnable() {
                  @Override
                  public void run() {
                    peer.unsafe().close(unsafe().voidPromise());
                  }
                });
      }
      this.peer = null;
    }
  }