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);
}
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);
}
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);
}
}
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));
}
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;
}
}
Aggregations