package jsat.utils;

import java.util.Collection;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

/**
 *
 * Provides a fake {@link ExecutorService} that immediatly runs any 
 * given runnable on the main thread. This will not use any given 
 * threads and will never create a thread. 
 * 
 * @author Edward Raff
 */
public class FakeExecutor implements ExecutorService
{

    public void shutdown()
    {
        
    }

    public List shutdownNow()
    {
       return null;
    }

    public boolean isShutdown()
    {
        return false;
    }

    public boolean isTerminated()
    {
        return false;
    }

    public boolean awaitTermination(long l, TimeUnit tu) throws InterruptedException
    {
        return true;
    }

    public  Future submit(final Callable clbl)
    {
        return new Future() {

            public boolean cancel(boolean bln)
            {
                return false;
            }

            public boolean isCancelled()
            {
                return false;
            }

            public boolean isDone()
            {
                return false;
            }

            public T get() throws InterruptedException, ExecutionException
            {
                try
                {
                    return clbl.call();
                }
                catch (Exception ex)
                {
                    return null;
                }
            }

            public T get(long l, TimeUnit tu) throws InterruptedException, ExecutionException, TimeoutException
            {
                return get();
            }
        };
    }

    public  Future submit(Runnable r, T t)
    {
        r.run();
        return null;
    }

    public Future submit(Runnable r)
    {
        r.run();
        return null;
    }

    public  List> invokeAll(Collection> clctn) throws InterruptedException
    {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public  List> invokeAll(Collection> clctn, long l, TimeUnit tu) throws InterruptedException
    {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public  T invokeAny(Collection> clctn) throws InterruptedException, ExecutionException
    {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public  T invokeAny(Collection> clctn, long l, TimeUnit tu) throws InterruptedException, ExecutionException, TimeoutException
    {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void execute(Runnable r)
    {
        r.run();
    }
    
}

 

Ads help maintain this website.