本文整理汇总了Java中java.util.concurrent.RunnableFuture.get方法的典型用法代码示例。如果您正苦于以下问题:Java RunnableFuture.get方法的具体用法?Java RunnableFuture.get怎么用?Java RunnableFuture.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.RunnableFuture
的用法示例。
在下文中一共展示了RunnableFuture.get方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeDirectory
import java.util.concurrent.RunnableFuture; //导入方法依赖的package包/类
public static PsiDirectory writeDirectory(PsiDirectory dir, DirectoryWrapper dirWrapper, Project project) {
if (dir == null) {
//todo print error
return null;
}
RunnableFuture<PsiDirectory> runnableFuture = new FutureTask<>(() ->
ApplicationManager.getApplication().runWriteAction(new Computable<PsiDirectory>() {
@Override
public PsiDirectory compute() {
return writeDirectoryAction(dir, dirWrapper, project);
}
}));
ApplicationManager.getApplication().invokeLater(runnableFuture);
try {
return runnableFuture.get();
} catch (InterruptedException | ExecutionException e) {
Logger.log("runnableFuture " + e.getMessage());
Logger.printStack(e);
}
return null;
}
示例2: testDismissingSnapshotNotRunnable
import java.util.concurrent.RunnableFuture; //导入方法依赖的package包/类
@Test
public void testDismissingSnapshotNotRunnable() throws Exception {
setupRocksKeyedStateBackend();
try {
RunnableFuture<KeyedStateHandle> snapshot =
keyedStateBackend.snapshot(0L, 0L, testStreamFactory, CheckpointOptions.forCheckpoint());
snapshot.cancel(true);
Thread asyncSnapshotThread = new Thread(snapshot);
asyncSnapshotThread.start();
try {
snapshot.get();
fail();
} catch (Exception ignored) {
}
asyncSnapshotThread.join();
verifyRocksObjectsReleased();
} finally {
this.keyedStateBackend.dispose();
this.keyedStateBackend = null;
}
}
示例3: testCompletingSnapshot
import java.util.concurrent.RunnableFuture; //导入方法依赖的package包/类
@Test
public void testCompletingSnapshot() throws Exception {
setupRocksKeyedStateBackend();
try {
RunnableFuture<KeyedStateHandle> snapshot =
keyedStateBackend.snapshot(0L, 0L, testStreamFactory, CheckpointOptions.forCheckpoint());
Thread asyncSnapshotThread = new Thread(snapshot);
asyncSnapshotThread.start();
waiter.await(); // wait for snapshot to run
waiter.reset();
runStateUpdates();
blocker.trigger(); // allow checkpointing to start writing
waiter.await(); // wait for snapshot stream writing to run
KeyedStateHandle keyedStateHandle = snapshot.get();
assertNotNull(keyedStateHandle);
assertTrue(keyedStateHandle.getStateSize() > 0);
assertEquals(2, keyedStateHandle.getKeyGroupRange().getNumberOfKeyGroups());
assertTrue(testStreamFactory.getLastCreatedStream().isClosed());
asyncSnapshotThread.join();
verifyRocksObjectsReleased();
} finally {
this.keyedStateBackend.dispose();
this.keyedStateBackend = null;
}
}
示例4: testCancelRunningSnapshot
import java.util.concurrent.RunnableFuture; //导入方法依赖的package包/类
@Test
public void testCancelRunningSnapshot() throws Exception {
setupRocksKeyedStateBackend();
try {
RunnableFuture<KeyedStateHandle> snapshot = keyedStateBackend.snapshot(0L, 0L, testStreamFactory, CheckpointOptions.forCheckpoint());
Thread asyncSnapshotThread = new Thread(snapshot);
asyncSnapshotThread.start();
waiter.await(); // wait for snapshot to run
waiter.reset();
runStateUpdates();
snapshot.cancel(true);
blocker.trigger(); // allow checkpointing to start writing
assertTrue(testStreamFactory.getLastCreatedStream().isClosed());
waiter.await(); // wait for snapshot stream writing to run
try {
snapshot.get();
fail();
} catch (Exception ignored) {
}
asyncSnapshotThread.join();
verifyRocksObjectsReleased();
} finally {
this.keyedStateBackend.dispose();
this.keyedStateBackend = null;
}
}
示例5: runIfNotDoneAndGet
import java.util.concurrent.RunnableFuture; //导入方法依赖的package包/类
public static <T> T runIfNotDoneAndGet(RunnableFuture<T> future) throws ExecutionException, InterruptedException {
if (null == future) {
return null;
}
if (!future.isDone()) {
future.run();
}
return future.get();
}
示例6: runSnapshot
import java.util.concurrent.RunnableFuture; //导入方法依赖的package包/类
protected KeyedStateHandle runSnapshot(RunnableFuture<KeyedStateHandle> snapshotRunnableFuture) throws Exception {
if(!snapshotRunnableFuture.isDone()) {
Thread runner = new Thread(snapshotRunnableFuture);
runner.start();
}
return snapshotRunnableFuture.get();
}
示例7: testSharedIncrementalStateDeRegistration
import java.util.concurrent.RunnableFuture; //导入方法依赖的package包/类
@Test
public void testSharedIncrementalStateDeRegistration() throws Exception {
if (enableIncrementalCheckpointing) {
AbstractKeyedStateBackend<Integer> backend = createKeyedBackend(IntSerializer.INSTANCE);
try {
ValueStateDescriptor<String> kvId =
new ValueStateDescriptor<>("id", String.class, null);
kvId.initializeSerializerUnlessSet(new ExecutionConfig());
ValueState<String> state =
backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, kvId);
Queue<IncrementalKeyedStateHandle> previousStateHandles = new LinkedList<>();
SharedStateRegistry sharedStateRegistry = spy(new SharedStateRegistry());
for (int checkpointId = 0; checkpointId < 3; ++checkpointId) {
reset(sharedStateRegistry);
backend.setCurrentKey(checkpointId);
state.update("Hello-" + checkpointId);
RunnableFuture<KeyedStateHandle> snapshot = backend.snapshot(
checkpointId,
checkpointId,
createStreamFactory(),
CheckpointOptions.forCheckpoint());
snapshot.run();
IncrementalKeyedStateHandle stateHandle = (IncrementalKeyedStateHandle) snapshot.get();
Map<StateHandleID, StreamStateHandle> sharedState =
new HashMap<>(stateHandle.getSharedState());
stateHandle.registerSharedStates(sharedStateRegistry);
for (Map.Entry<StateHandleID, StreamStateHandle> e : sharedState.entrySet()) {
verify(sharedStateRegistry).registerReference(
stateHandle.createSharedStateRegistryKeyFromFileName(e.getKey()),
e.getValue());
}
previousStateHandles.add(stateHandle);
backend.notifyCheckpointComplete(checkpointId);
//-----------------------------------------------------------------
if (previousStateHandles.size() > 1) {
checkRemove(previousStateHandles.remove(), sharedStateRegistry);
}
}
while (!previousStateHandles.isEmpty()) {
reset(sharedStateRegistry);
checkRemove(previousStateHandles.remove(), sharedStateRegistry);
}
} finally {
IOUtils.closeQuietly(backend);
backend.dispose();
}
}
}
示例8: testSnapshotAsyncCancel
import java.util.concurrent.RunnableFuture; //导入方法依赖的package包/类
@Test
public void testSnapshotAsyncCancel() throws Exception {
DefaultOperatorStateBackend operatorStateBackend =
new DefaultOperatorStateBackend(OperatorStateBackendTest.class.getClassLoader(), new ExecutionConfig(), true);
ListStateDescriptor<MutableType> stateDescriptor1 =
new ListStateDescriptor<>("test1", new JavaSerializer<MutableType>());
ListState<MutableType> listState1 = operatorStateBackend.getOperatorState(stateDescriptor1);
listState1.add(MutableType.of(42));
listState1.add(MutableType.of(4711));
BlockerCheckpointStreamFactory streamFactory = new BlockerCheckpointStreamFactory(1024 * 1024);
OneShotLatch waiterLatch = new OneShotLatch();
OneShotLatch blockerLatch = new OneShotLatch();
streamFactory.setWaiterLatch(waiterLatch);
streamFactory.setBlockerLatch(blockerLatch);
RunnableFuture<OperatorStateHandle> runnableFuture =
operatorStateBackend.snapshot(1, 1, streamFactory, CheckpointOptions.forCheckpoint());
ExecutorService executorService = Executors.newFixedThreadPool(1);
executorService.submit(runnableFuture);
// wait until the async checkpoint is in the stream's write code, then continue
waiterLatch.await();
// cancel the future, which should close the underlying stream
runnableFuture.cancel(true);
Assert.assertTrue(streamFactory.getLastCreatedStream().isClosed());
// we allow the stream under test to proceed
blockerLatch.trigger();
try {
runnableFuture.get(60, TimeUnit.SECONDS);
Assert.fail();
} catch (CancellationException ignore) {
}
}
示例9: testParallelAsyncSnapshots
import java.util.concurrent.RunnableFuture; //导入方法依赖的package包/类
/**
* The purpose of this test is to check that parallel snapshots are possible, and work even if a previous snapshot
* is still running and blocking.
*/
@Test
public void testParallelAsyncSnapshots() throws Exception {
OneShotLatch blocker = new OneShotLatch();
OneShotLatch waiter = new OneShotLatch();
BlockerCheckpointStreamFactory streamFactory = new BlockerCheckpointStreamFactory(1024 * 1024);
streamFactory.setWaiterLatch(waiter);
streamFactory.setBlockerLatch(blocker);
streamFactory.setAfterNumberInvocations(10);
final AbstractKeyedStateBackend<Integer> backend = createKeyedBackend(IntSerializer.INSTANCE);
try {
if (!backend.supportsAsynchronousSnapshots()) {
return;
}
// insert some data to the backend.
InternalValueState<VoidNamespace, Integer> valueState = backend.createValueState(
VoidNamespaceSerializer.INSTANCE,
new ValueStateDescriptor<>("test", IntSerializer.INSTANCE));
valueState.setCurrentNamespace(VoidNamespace.INSTANCE);
for (int i = 0; i < 10; ++i) {
backend.setCurrentKey(i);
valueState.update(i);
}
RunnableFuture<KeyedStateHandle> snapshot1 =
backend.snapshot(0L, 0L, streamFactory, CheckpointOptions.forCheckpoint());
Thread runner1 = new Thread(snapshot1, "snapshot-1-runner");
runner1.start();
// after this call returns, we have a running snapshot-1 that is blocked in IO.
waiter.await();
// do some updates in between the snapshots.
for (int i = 5; i < 15; ++i) {
backend.setCurrentKey(i);
valueState.update(i + 1);
}
// we don't want to block the second snapshot.
streamFactory.setWaiterLatch(null);
streamFactory.setBlockerLatch(null);
RunnableFuture<KeyedStateHandle> snapshot2 =
backend.snapshot(1L, 1L, streamFactory, CheckpointOptions.forCheckpoint());
Thread runner2 = new Thread(snapshot2,"snapshot-2-runner");
runner2.start();
// snapshot-2 should run and succeed, while snapshot-1 is still running and blocked in IO.
snapshot2.get();
// we release the blocking IO so that snapshot-1 can also finish and succeed.
blocker.trigger();
snapshot1.get();
} finally {
backend.dispose();
}
}
示例10: testAsyncSnapshotCancellation
import java.util.concurrent.RunnableFuture; //导入方法依赖的package包/类
@Test
public void testAsyncSnapshotCancellation() throws Exception {
OneShotLatch blocker = new OneShotLatch();
OneShotLatch waiter = new OneShotLatch();
BlockerCheckpointStreamFactory streamFactory = new BlockerCheckpointStreamFactory(1024 * 1024);
streamFactory.setWaiterLatch(waiter);
streamFactory.setBlockerLatch(blocker);
streamFactory.setAfterNumberInvocations(10);
final AbstractKeyedStateBackend<Integer> backend = createKeyedBackend(IntSerializer.INSTANCE);
try {
if (!backend.supportsAsynchronousSnapshots()) {
return;
}
InternalValueState<VoidNamespace, Integer> valueState = backend.createValueState(
VoidNamespaceSerializer.INSTANCE,
new ValueStateDescriptor<>("test", IntSerializer.INSTANCE));
valueState.setCurrentNamespace(VoidNamespace.INSTANCE);
for (int i = 0; i < 10; ++i) {
backend.setCurrentKey(i);
valueState.update(i);
}
RunnableFuture<KeyedStateHandle> snapshot =
backend.snapshot(0L, 0L, streamFactory, CheckpointOptions.forCheckpoint());
Thread runner = new Thread(snapshot);
runner.start();
// wait until the code reached some stream read
waiter.await();
// close the backend to see if the close is propagated to the stream
IOUtils.closeQuietly(backend);
//unblock the stream so that it can run into the IOException
blocker.trigger();
runner.join();
try {
snapshot.get();
fail("Close was not propagated.");
} catch (ExecutionException ex) {
//ignore
}
} finally {
backend.dispose();
}
}
示例11: testSnapshotAsyncClose
import java.util.concurrent.RunnableFuture; //导入方法依赖的package包/类
@Test
public void testSnapshotAsyncClose() throws Exception {
DefaultOperatorStateBackend operatorStateBackend =
new DefaultOperatorStateBackend(OperatorStateBackendTest.class.getClassLoader(), new ExecutionConfig(), true);
ListStateDescriptor<MutableType> stateDescriptor1 =
new ListStateDescriptor<>("test1", new JavaSerializer<MutableType>());
ListState<MutableType> listState1 = operatorStateBackend.getOperatorState(stateDescriptor1);
listState1.add(MutableType.of(42));
listState1.add(MutableType.of(4711));
BlockerCheckpointStreamFactory streamFactory = new BlockerCheckpointStreamFactory(1024 * 1024);
OneShotLatch waiterLatch = new OneShotLatch();
OneShotLatch blockerLatch = new OneShotLatch();
streamFactory.setWaiterLatch(waiterLatch);
streamFactory.setBlockerLatch(blockerLatch);
RunnableFuture<OperatorStateHandle> runnableFuture =
operatorStateBackend.snapshot(1, 1, streamFactory, CheckpointOptions.forCheckpoint());
ExecutorService executorService = Executors.newFixedThreadPool(1);
executorService.submit(runnableFuture);
// wait until the async checkpoint is in the write code, then continue
waiterLatch.await();
operatorStateBackend.close();
blockerLatch.trigger();
try {
runnableFuture.get(60, TimeUnit.SECONDS);
Assert.fail();
} catch (ExecutionException eex) {
Assert.assertTrue(eex.getCause() instanceof IOException);
}
}