All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hubspot.imap.utils.NettyCompletableFuture Maven / Gradle / Ivy

There is a newer version: 0.6.1
Show newest version
package com.hubspot.imap.utils;

import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;
import java.util.concurrent.CompletableFuture;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class NettyCompletableFuture
  extends CompletableFuture
  implements FutureListener {

  private static final Logger LOGGER = LoggerFactory.getLogger(
    NettyCompletableFuture.class
  );

  private NettyCompletableFuture(Future future) {
    future.addListener(this);
  }

  @Override
  public void operationComplete(Future tFuture) throws Exception {
    LOGGER.trace("Completing future from thread: {}", Thread.currentThread().getName());
    if (tFuture.isSuccess()) {
      complete(tFuture.getNow());
    } else if (tFuture.isCancelled()) {
      cancel(true);
    } else {
      completeExceptionally(tFuture.cause());
    }
  }

  public static  CompletableFuture from(Future future) {
    return new NettyCompletableFuture<>(future);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy