Example usage for java.util.concurrent Executor Executor

List of usage examples for java.util.concurrent Executor Executor

Introduction

In this page you can find the example usage for java.util.concurrent Executor Executor.

Prototype

Executor

Source Link

Usage

From source file:Main.java

/**
 * Construct a synchronous executor, which will run tasks directly on the calling thread when submitted.
 *//*from  w  ww  .  j av  a 2 s  . com*/
public static Executor makeSynchronousExecutor() {
    return new Executor() {
        public void execute(Runnable command) {
            command.run();
        }
    };
}

From source file:com.android.volley.utils.ImmediateResponseDelivery.java

public ImmediateResponseDelivery() {
    super(new Executor() {
        @Override//w w w .  ja va 2  s. c  o m
        public void execute(Runnable command) {
            command.run();
        }
    });
}

From source file:com.android.volley.ExecutorDelivery.java

/**
 * Creates a new response delivery interface.
 * @param handler {@link Handler} to post responses on
 *//*from   w  w w  .  ja va  2s. c o m*/
public ExecutorDelivery(final Handler handler) {
    // Make an Executor that just wraps the handler.
    mResponsePoster = new Executor() {
        @Override
        public void execute(Runnable command) {
            handler.post(command);
        }
    };
}

From source file:com.athena.meerkat.controller.web.provisioning.log.LogTailerListenerTest.java

@Test
public void testHandleString() {
    LogTailerListener listener = new LogTailerListener(new WebSocketSessionMock());
    long delay = 2000;
    File file = new File("G:\\project\\AthenaMeerkat\\meerkat.log");
    Tailer tailer = new Tailer(file, listener, delay);

    // stupid executor impl. for demo purposes

    Executor executor = new Executor() {
        public void execute(Runnable command) {
            command.run();//from   w w w .java  2  s . co m
        }
    };

    executor.execute(tailer);

    /*
    Thread thread = new Thread(tailer);
    thread.setDaemon(true);
    thread.start();
            
    try{
      Thread.sleep(10000);
    }catch(Exception e){}
    */
}

From source file:com.contentful.vaultintegration.BaseTest.java

protected void sync(SyncConfig config) throws InterruptedException {
    if (config == null) {
        config = SyncConfig.builder().setClient(client).build();
    }/* w  w w . j av  a  2s  .  c om*/

    final CountDownLatch latch = new CountDownLatch(1);

    Executor executor = new Executor() {
        @Override
        public void execute(Runnable command) {
            command.run();
        }
    };

    final SyncResult[] result = { null };
    SyncCallback callback = new SyncCallback() {
        @Override
        public void onResult(SyncResult r) {
            result[0] = r;
            latch.countDown();
        }
    };

    vault.requestSync(config, callback, executor);
    latch.await();

    assertThat(result[0]).isNotNull();

    if (!result[0].isSuccessful()) {
        throw (RuntimeException) result[0].error();
    }
}

From source file:net.grandcentrix.thirtyinch.internal.TestTiFragment.java

@Override
public Executor getUiThreadExecutor() {
    return new Executor() {
        @Override/*from   ww w.  j  a v  a2  s.c o m*/
        public void execute(@NonNull final Runnable action) {
            action.run();
        }
    };
}

From source file:edu.umn.msi.tropix.common.io.impl.AsyncStreamCopierImplTest.java

private void testSimpleCopy(final boolean close) {
    final AsyncStreamCopierImpl copier = new AsyncStreamCopierImpl();
    final ByteArrayInputStream inputStream = new ByteArrayInputStream("Hello".getBytes());
    final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    final TrackedOutputStream trackedOutputStream = new TrackedOutputStream(outputStream);
    copier.setExecutor(new Executor() {
        public void execute(final Runnable runnable) {
            runnable.run();// w  w  w . j  a va  2 s  .  com
        }
    });
    copier.copy(inputStream, trackedOutputStream, close);
    assert new String(outputStream.toByteArray()).equals("Hello");
    assert trackedOutputStream.closed == close;
}

From source file:edu.umn.msi.tropix.common.io.impl.AsyncStreamCopierImplTest.java

@Test(groups = "unit", timeOut = 1000, invocationCount = 10)
public void close() throws IOException, InterruptedException {
    final AsyncStreamCopierImpl copier = new AsyncStreamCopierImpl();
    final Reference<Thread> threadReference = new Reference<Thread>();
    final Reference<Throwable> throwableReference = new Reference<Throwable>();
    copier.setExecutor(new Executor() {
        public void execute(final Runnable runnable) {
            final Thread thread = new Thread(runnable);
            threadReference.set(thread);
            thread.start();//from www. ja va 2  s .  c  o m
            thread.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
                public void uncaughtException(final Thread arg0, final Throwable throwable) {
                    throwableReference.set(throwable);
                }
            });
        }
    });
    final PipedOutputStream pipedOutputStream = new PipedOutputStream();
    final PipedInputStream pipedInputStream = new PipedInputStream(pipedOutputStream);
    final ByteArrayOutputStream copiedStream = new ByteArrayOutputStream();
    copier.copy(pipedInputStream, copiedStream, true);
    Thread.sleep(3);
    assert new String(copiedStream.toByteArray()).equals("");
    pipedOutputStream.write("Hello ".getBytes());
    pipedOutputStream.flush();
    while (!new String(copiedStream.toByteArray()).equals("Hello ")) {
        Thread.sleep(1);
    }
    pipedOutputStream.write("World!".getBytes());
    pipedOutputStream.flush();
    while (!new String(copiedStream.toByteArray()).equals("Hello World!")) {
        Thread.sleep(1);
    }
    assert threadReference.get().isAlive();
    pipedOutputStream.close();
    while (threadReference.get().isAlive()) {
        Thread.sleep(1);
    }
    assert throwableReference.get() == null;
}

From source file:com.navercorp.pinpoint.collector.receiver.thrift.udp.UDPReceiverTest.java

private Executor mockDispatchWorker(CountDownLatch latch) {

    Executor mockWorker = new Executor() {
        @Override/*from  www.  j a va2  s  .  c om*/
        public void execute(Runnable runnable) {
            logger.info("execute:{}", runnable.getClass());
            try {
                runnable.run();
            } finally {
                latch.countDown();
            }
        }
    };
    return Mockito.spy(mockWorker);
}

From source file:com.offbynull.portmapper.common.UdpCommunicator.java

@Override
protected Executor executor() {
    return new Executor() {
        @Override//  w  w  w.  j  av a 2  s. c o  m
        public void execute(Runnable command) {
            Thread thread = new Thread(command);
            thread.setDaemon(true);
            thread.start();
        }
    };
}