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

io.prestosql.jdbc.$internal.airlift.concurrent.ExecutorServiceAdapter Maven / Gradle / Ivy

The newest version!
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> tasks)
            throws InterruptedException
    {
        throw new UnsupportedOperationException();
    }

    @Override
    public  List> invokeAll(Collection> tasks, long timeout, TimeUnit unit)
            throws InterruptedException
    {
        throw new UnsupportedOperationException();
    }

    @Override
    public  T invokeAny(Collection> tasks)
            throws InterruptedException, ExecutionException
    {
        throw new UnsupportedOperationException();
    }

    @Override
    public  T invokeAny(Collection> 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 - 2024 Weber Informatics LLC | Privacy Policy