Search in sources :

Example 21 with FutureTask

use of java.util.concurrent.FutureTask in project hazelcast by hazelcast.

the class OperationExecutorImpl_IsInvocationAllowedTest method test_whenPartitionOperation_andCallingFromOperationHostileThread_andAsync.

@Test
public void test_whenPartitionOperation_andCallingFromOperationHostileThread_andAsync() {
    initExecutor();
    final Operation operation = new DummyOperation(1);
    FutureTask<Boolean> futureTask = new FutureTask<Boolean>(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            return executor.isInvocationAllowed(operation, true);
        }
    });
    DummyOperationHostileThread thread = new DummyOperationHostileThread(futureTask);
    thread.start();
    assertEqualsEventually(futureTask, FALSE);
}
Also used : FutureTask(java.util.concurrent.FutureTask) Operation(com.hazelcast.spi.Operation) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 22 with FutureTask

use of java.util.concurrent.FutureTask in project hazelcast by hazelcast.

the class OperationExecutorImpl_IsInvocationAllowedTest method test_whenPartitionOperation_andCallingFromOperationHostileThread.

@Test
public void test_whenPartitionOperation_andCallingFromOperationHostileThread() {
    initExecutor();
    final Operation operation = new DummyOperation(1);
    FutureTask<Boolean> futureTask = new FutureTask<Boolean>(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            return executor.isInvocationAllowed(operation, false);
        }
    });
    DummyOperationHostileThread thread = new DummyOperationHostileThread(futureTask);
    thread.start();
    assertEqualsEventually(futureTask, FALSE);
}
Also used : FutureTask(java.util.concurrent.FutureTask) Operation(com.hazelcast.spi.Operation) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 23 with FutureTask

use of java.util.concurrent.FutureTask in project L42 by ElvisResearchGroup.

the class Frame method createNew.

private static Frame createNew(String wName, String html, int x, int y) {
    FutureTask<Frame> future = new FutureTask<>(() -> {
        final Frame frame = new Frame(Frame.extractTitle(html));
        JFXPanel jfxPanel = new JFXPanel();
        frame.createHtmlContent(jfxPanel, html);
        frame.getContentPane().add(jfxPanel);
        frame.setMinimumSize(new Dimension(x, y));
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.addWindowListener(new WindowAdapter() {

            public void windowClosing(WindowEvent e) {
                Frame.close(wName);
            }
        });
        frame.setVisible(true);
        return frame;
    });
    SwingUtilities.invokeLater(future);
    try {
        return future.get();
    } catch (ExecutionException e) {
        throw propagateException(e.getCause());
    } catch (InterruptedException e) {
        throw propagateException(e);
    }
}
Also used : JFrame(javax.swing.JFrame) JFXPanel(javafx.embed.swing.JFXPanel) FutureTask(java.util.concurrent.FutureTask) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter) Dimension(java.awt.Dimension) ExecutionException(java.util.concurrent.ExecutionException)

Example 24 with FutureTask

use of java.util.concurrent.FutureTask in project android_frameworks_base by DirtyUnicorns.

the class MtpManagerTest method testCancelEvent.

public void testCancelEvent() throws Exception {
    final CancellationSignal signal = new CancellationSignal();
    final FutureTask<Boolean> future = new FutureTask<Boolean>(new Callable<Boolean>() {

        @Override
        public Boolean call() throws IOException {
            try {
                while (true) {
                    mManager.readEvent(mUsbDevice.getDeviceId(), signal);
                }
            } catch (OperationCanceledException exception) {
                return true;
            }
        }
    });
    final Thread thread = new Thread(future);
    thread.start();
    SystemClock.sleep(TIMEOUT_MS);
    signal.cancel();
    assertTrue(future.get(TIMEOUT_MS, TimeUnit.MILLISECONDS));
}
Also used : FutureTask(java.util.concurrent.FutureTask) OperationCanceledException(android.os.OperationCanceledException) IOException(java.io.IOException) CancellationSignal(android.os.CancellationSignal)

Example 25 with FutureTask

use of java.util.concurrent.FutureTask in project AutoRefactor by JnRouvignac.

the class DisplayEventLoop method syncExec.

@Override
public <E extends Exception> void syncExec(final Callable<E> call) throws E {
    final FutureTask<E> future = new FutureTask<E>(call);
    Display.getDefault().syncExec(future);
    final E ex;
    try {
        ex = future.get();
    } catch (ExecutionException e) {
        throw new UnhandledException(null, e.getCause());
    } catch (Exception e) {
        throw new UnhandledException(null, e);
    }
    if (ex != null) {
        throw ex;
    }
}
Also used : UnhandledException(org.autorefactor.util.UnhandledException) FutureTask(java.util.concurrent.FutureTask) ExecutionException(java.util.concurrent.ExecutionException) ExecutionException(java.util.concurrent.ExecutionException) UnhandledException(org.autorefactor.util.UnhandledException)

Aggregations

FutureTask (java.util.concurrent.FutureTask)111 ExecutionException (java.util.concurrent.ExecutionException)41 IOException (java.io.IOException)26 Test (org.junit.Test)24 Callable (java.util.concurrent.Callable)18 CountDownLatch (java.util.concurrent.CountDownLatch)18 ExecutorService (java.util.concurrent.ExecutorService)18 TimeoutException (java.util.concurrent.TimeoutException)13 Handler (android.os.Handler)12 ArrayList (java.util.ArrayList)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 CancellationException (java.util.concurrent.CancellationException)8 AccessibleObject (java.lang.reflect.AccessibleObject)6 Future (java.util.concurrent.Future)6 FileNotFoundException (java.io.FileNotFoundException)5 InputStream (java.io.InputStream)5 Iterator (java.util.Iterator)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 CancellationSignal (android.os.CancellationSignal)4 OperationCanceledException (android.os.OperationCanceledException)4