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

com.clickzetta.platform.flusher.AbstractTask Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
package com.clickzetta.platform.flusher;

import com.clickzetta.platform.common.FlushTaskCallException;
import org.apache.commons.lang3.StringUtils;

import java.util.concurrent.CompletableFuture;

public abstract class AbstractTask implements Task {

  protected CompletableFuture future = new CompletableFuture<>();

  @Override
  public CompletableFuture getFuture() {
    return future;
  }

  public void callPrepare() throws Exception {
    // do nothing.
  }

  public abstract void callInternal() throws Exception;

  @Override
  public CompletableFuture skipCall(Throwable t) {
    if (t == null) {
      future.complete(true);
    } else {
      future.completeExceptionally(t);
    }
    return future;
  }

  @Override
  public CompletableFuture call() {
    try {
      callPrepare();
      callInternal();
    } catch (Throwable t) {
      StackTraceElement[] elements = Thread.currentThread().getStackTrace();
      String errMsg = t + "\n" + StringUtils.join(elements, "\n        ");
      future.completeExceptionally(new FlushTaskCallException(errMsg));
    }
    return future;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy