Java 类io.vertx.core.Closeable 实例源码

项目:vertx-kafka-client    文件:CloseHandler.java   
private synchronized void registerCloseHook(Consumer<Closeable> addCloseHook, Consumer<Closeable> removeCloseHook) {
  if (closeable == null) {
    closeable = ar -> {
      synchronized (CloseHandler.this) {
        if (closeable == null) {
          ar.handle(Future.succeededFuture());
          return;
        }
        closeable = null;
      }
      close.accept(0L, ar);
    };
    closeableHookCleanup = () -> {
      synchronized (CloseHandler.this) {
        if (closeable != null) {
          removeCloseHook.accept(closeable);
          closeable = null;
        }
      }
    };
    addCloseHook.accept(closeable);
  }
}