com.alibaba.hologres.client.impl.action.AbstractAction Maven / Gradle / Ivy
/*
* Copyright (c) 2021. Alibaba Group Holding Limited
*/
package com.alibaba.hologres.client.impl.action;
import com.alibaba.hologres.client.exception.ExceptionCode;
import com.alibaba.hologres.client.exception.HoloClientException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Semaphore;
/**
* ca.
*
* @param t
*/
public abstract class AbstractAction {
CompletableFuture future;
Semaphore semaphore;
public AbstractAction() {
this.future = new CompletableFuture<>();
}
public CompletableFuture getFuture() {
return future;
}
public T getResult() throws HoloClientException {
try {
return future.get();
} catch (InterruptedException e) {
throw new HoloClientException(ExceptionCode.INTERNAL_ERROR, "interrupt", e);
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof HoloClientException) {
throw (HoloClientException) cause;
} else {
throw new HoloClientException(ExceptionCode.INTERNAL_ERROR, "", cause);
}
}
}
public Semaphore getSemaphore() {
return semaphore;
}
public void setSemaphore(Semaphore semaphore) {
this.semaphore = semaphore;
}
}