io.prestosql.jdbc.$internal.airlift.concurrent.ExecutorServiceAdapter Maven / Gradle / Ivy
package io.prestosql.jdbc.$internal.airlift.concurrent;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import static java.util.Objects.requireNonNull;
/**
* Converts an Executor into a minimalistic ExecutorService
*/
public class ExecutorServiceAdapter
implements ExecutorService
{
private final Executor executor;
public ExecutorServiceAdapter(Executor executor)
{
this.executor = requireNonNull(executor, "executor is null");
}
public static ExecutorService from(Executor executor)
{
return new ExecutorServiceAdapter(executor);
}
@Override
public void execute(Runnable command)
{
executor.execute(command);
}
@Override
public Future submit(Callable task)
{
FutureTask futureTask = new FutureTask<>(task);
execute(futureTask);
return futureTask;
}
@Override
public Future submit(Runnable task, T result)
{
return submit(Executors.callable(task, result));
}
@Override
public Future> submit(Runnable task)
{
return submit(Executors.callable(task));
}
@Override
public List> invokeAll(Collection extends Callable> tasks)
throws InterruptedException
{
throw new UnsupportedOperationException();
}
@Override
public List> invokeAll(Collection extends Callable> tasks, long timeout, TimeUnit unit)
throws InterruptedException
{
throw new UnsupportedOperationException();
}
@Override
public T invokeAny(Collection extends Callable> tasks)
throws InterruptedException, ExecutionException
{
throw new UnsupportedOperationException();
}
@Override
public T invokeAny(Collection extends Callable> tasks, long timeout, TimeUnit unit)
throws InterruptedException, ExecutionException, TimeoutException
{
throw new UnsupportedOperationException();
}
@Override
public void shutdown()
{
throw new UnsupportedOperationException();
}
@Override
public List shutdownNow()
{
throw new UnsupportedOperationException();
}
@Override
public boolean isShutdown()
{
throw new UnsupportedOperationException();
}
@Override
public boolean isTerminated()
{
throw new UnsupportedOperationException();
}
@Override
public boolean awaitTermination(long timeout, TimeUnit unit)
throws InterruptedException
{
throw new UnsupportedOperationException();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy