java.util.concurrent.RunnableFuture Java Examples
The following examples show how to use
java.util.concurrent.RunnableFuture.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HeapKeyedStateBackend.java From flink with Apache License 2.0 | 6 votes |
@Nonnull @Override @SuppressWarnings("unchecked") public RunnableFuture<SnapshotResult<KeyedStateHandle>> snapshot( final long checkpointId, final long timestamp, @Nonnull final CheckpointStreamFactory streamFactory, @Nonnull CheckpointOptions checkpointOptions) throws IOException { long startTime = System.currentTimeMillis(); final RunnableFuture<SnapshotResult<KeyedStateHandle>> snapshotRunner = snapshotStrategy.snapshot(checkpointId, timestamp, streamFactory, checkpointOptions); snapshotStrategy.logSyncCompleted(streamFactory, startTime); return snapshotRunner; }
Example #2
Source File: OperatorStateBackendTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testSnapshotEmpty() throws Exception { final AbstractStateBackend abstractStateBackend = new MemoryStateBackend(4096); CloseableRegistry cancelStreamRegistry = new CloseableRegistry(); final OperatorStateBackend operatorStateBackend = abstractStateBackend.createOperatorStateBackend(createMockEnvironment(), "testOperator", emptyStateHandles, cancelStreamRegistry); CheckpointStreamFactory streamFactory = new MemCheckpointStreamFactory(4096); RunnableFuture<SnapshotResult<OperatorStateHandle>> snapshot = operatorStateBackend.snapshot(0L, 0L, streamFactory, CheckpointOptions.forCheckpointWithDefaultLocation()); SnapshotResult<OperatorStateHandle> snapshotResult = FutureUtils.runIfNotDoneAndGet(snapshot); OperatorStateHandle stateHandle = snapshotResult.getJobManagerOwnedSnapshot(); assertNull(stateHandle); }
Example #3
Source File: BlockRejectedExecutionHandler.java From huaweicloud-sdk-java-obs with Apache License 2.0 | 6 votes |
@Override public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { try { executor.getQueue().put(r); } catch (InterruptedException e) { if (r instanceof RunnableFuture) { throw new RejectedExecutionException(e); } ObsException obsException = new ObsException(e.getMessage(), e); if (r instanceof RestoreObjectTask) { RestoreObjectTask task = (RestoreObjectTask) r; task.getProgressStatus().failTaskIncrement(); TaskCallback<RestoreObjectResult, RestoreObjectRequest> callback = task.getCallback(); callback.onException(obsException, task.getTaskRequest()); } } }
Example #4
Source File: RocksDBSnapshotStrategyBase.java From flink with Apache License 2.0 | 6 votes |
@Nonnull @Override public final RunnableFuture<SnapshotResult<KeyedStateHandle>> snapshot( long checkpointId, long timestamp, @Nonnull CheckpointStreamFactory streamFactory, @Nonnull CheckpointOptions checkpointOptions) throws Exception { if (kvStateInformation.isEmpty()) { if (LOG.isDebugEnabled()) { LOG.debug("Asynchronous RocksDB snapshot performed on empty keyed state at {}. Returning null.", timestamp); } return DoneFuture.of(SnapshotResult.empty()); } else { return doSnapshot(checkpointId, timestamp, streamFactory, checkpointOptions); } }
Example #5
Source File: DefaultOperatorStateBackend.java From flink with Apache License 2.0 | 6 votes |
@Nonnull @Override public RunnableFuture<SnapshotResult<OperatorStateHandle>> snapshot( long checkpointId, long timestamp, @Nonnull CheckpointStreamFactory streamFactory, @Nonnull CheckpointOptions checkpointOptions) throws Exception { long syncStartTime = System.currentTimeMillis(); RunnableFuture<SnapshotResult<OperatorStateHandle>> snapshotRunner = snapshotStrategy.snapshot(checkpointId, timestamp, streamFactory, checkpointOptions); snapshotStrategy.logSyncCompleted(streamFactory, syncStartTime); return snapshotRunner; }
Example #6
Source File: FileWriter.java From PackageTemplates with Apache License 2.0 | 6 votes |
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; }
Example #7
Source File: JUnitProjectOpenedHook.java From netbeans with Apache License 2.0 | 6 votes |
@Override public java.util.concurrent.Future<ProjectProblemsProvider.Result> resolve() { ProjectProblemsProvider.Result res; if (action != null) { action.actionPerformed(null); String text = (String) action.getValue(ACT_START_MESSAGE); if (text != null) { res = ProjectProblemsProvider.Result.create(ProjectProblemsProvider.Status.RESOLVED, text); } else { res = ProjectProblemsProvider.Result.create(ProjectProblemsProvider.Status.RESOLVED); } } else { res = ProjectProblemsProvider.Result.create(ProjectProblemsProvider.Status.UNRESOLVED, "No resolution for the problem"); } RunnableFuture<ProjectProblemsProvider.Result> f = new FutureTask<>(new Runnable() { @Override public void run() { } }, res); f.run(); return f; }
Example #8
Source File: TaskExecutorImpl.java From qpid-broker-j with Apache License 2.0 | 6 votes |
@Override public void stopImmediately() { if (_running.compareAndSet(true,false)) { ExecutorService executor = _executor; if (executor != null) { LOGGER.debug("Stopping task executor {} immediately", _name); List<Runnable> cancelledTasks = executor.shutdownNow(); for (Runnable runnable : cancelledTasks) { if (runnable instanceof RunnableFuture<?>) { ((RunnableFuture<?>) runnable).cancel(true); } } _executor = null; _taskThread = null; LOGGER.debug("Task executor was stopped immediately. Number of unfinished tasks: " + cancelledTasks.size()); } } }
Example #9
Source File: RocksDBStateBackendTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testDismissingSnapshotNotRunnable() throws Exception { setupRocksKeyedStateBackend(); try { RunnableFuture<SnapshotResult<KeyedStateHandle>> snapshot = keyedStateBackend.snapshot(0L, 0L, testStreamFactory, CheckpointOptions.forCheckpointWithDefaultLocation()); 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; } }
Example #10
Source File: MergeThreadPool.java From incubator-iotdb with Apache License 2.0 | 5 votes |
@Override protected <T> RunnableFuture<T> newTaskFor(Callable<T> callable) { if (callable instanceof MergeTask) { return (RunnableFuture<T>) new MainMergeFuture((MergeTask) callable); } else { return (RunnableFuture<T>) new SubMergeFuture((MergeChunkHeapTask) callable); } }
Example #11
Source File: XThreadPoolExecutor.java From lite-pool with Apache License 2.0 | 5 votes |
protected final void notifyPrevExecute(RunnableFuture<?> future) { if(this.listeners.size() == 0) return; for(final Listener listener : this.listeners) { try { listener.prevExecute(this, future); } catch(Throwable tx) { LOGGER.error("["+ this.getName() + "]failed to notify prevExecute, listener: " + listener, tx); } } }
Example #12
Source File: RocksDBStateBackendTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testCancelRunningSnapshot() throws Exception { setupRocksKeyedStateBackend(); try { RunnableFuture<SnapshotResult<KeyedStateHandle>> snapshot = keyedStateBackend.snapshot(0L, 0L, testStreamFactory, CheckpointOptions.forCheckpointWithDefaultLocation()); 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 for (BlockingCheckpointOutputStream stream : testStreamFactory.getAllCreatedStreams()) { assertTrue(stream.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; } }
Example #13
Source File: TaskCheckpointingBehaviourTest.java From flink with Apache License 2.0 | 5 votes |
@Override public OperatorStateBackend createOperatorStateBackend( Environment env, String operatorIdentifier, @Nonnull Collection<OperatorStateHandle> stateHandles, CloseableRegistry cancelStreamRegistry) throws Exception { return new DefaultOperatorStateBackendBuilder( env.getUserClassLoader(), env.getExecutionConfig(), true, stateHandles, cancelStreamRegistry) { @Override @SuppressWarnings("unchecked") public DefaultOperatorStateBackend build() { return new DefaultOperatorStateBackend( executionConfig, cancelStreamRegistry, new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<>(), mock(AbstractSnapshotStrategy.class) ) { @Nonnull @Override public RunnableFuture<SnapshotResult<OperatorStateHandle>> snapshot( long checkpointId, long timestamp, @Nonnull CheckpointStreamFactory streamFactory, @Nonnull CheckpointOptions checkpointOptions) throws Exception { return new FutureTask<>(() -> { throw new Exception("Async part snapshot exception."); }); } }; } }.build(); }
Example #14
Source File: RocksDBStateBackendTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testCompletingSnapshot() throws Exception { setupRocksKeyedStateBackend(); try { RunnableFuture<SnapshotResult<KeyedStateHandle>> snapshot = keyedStateBackend.snapshot(0L, 0L, testStreamFactory, CheckpointOptions.forCheckpointWithDefaultLocation()); 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 SnapshotResult<KeyedStateHandle> snapshotResult = snapshot.get(); KeyedStateHandle keyedStateHandle = snapshotResult.getJobManagerOwnedSnapshot(); assertNotNull(keyedStateHandle); assertTrue(keyedStateHandle.getStateSize() > 0); assertEquals(2, keyedStateHandle.getKeyGroupRange().getNumberOfKeyGroups()); for (BlockingCheckpointOutputStream stream : testStreamFactory.getAllCreatedStreams()) { assertTrue(stream.isClosed()); } asyncSnapshotThread.join(); verifyRocksObjectsReleased(); } finally { this.keyedStateBackend.dispose(); this.keyedStateBackend = null; } }
Example #15
Source File: StateSnapshotContextSynchronousImpl.java From flink with Apache License 2.0 | 5 votes |
@Nonnull public RunnableFuture<SnapshotResult<OperatorStateHandle>> getOperatorStateStreamFuture() throws IOException { if (null == operatorStateCheckpointClosingFuture) { StreamCloserCallable<OperatorStateHandle> callable = new StreamCloserCallable<>(closableRegistry, operatorStateCheckpointOutputStream); operatorStateCheckpointClosingFuture = callable.toAsyncSnapshotFutureTask(closableRegistry); } return operatorStateCheckpointClosingFuture; }
Example #16
Source File: StateBackendMigrationTestBase.java From flink with Apache License 2.0 | 5 votes |
private KeyedStateHandle runSnapshot( RunnableFuture<SnapshotResult<KeyedStateHandle>> snapshotRunnableFuture, SharedStateRegistry sharedStateRegistry) throws Exception { if (!snapshotRunnableFuture.isDone()) { snapshotRunnableFuture.run(); } SnapshotResult<KeyedStateHandle> snapshotResult = snapshotRunnableFuture.get(); KeyedStateHandle jobManagerOwnedSnapshot = snapshotResult.getJobManagerOwnedSnapshot(); if (jobManagerOwnedSnapshot != null) { jobManagerOwnedSnapshot.registerSharedStates(sharedStateRegistry); } return jobManagerOwnedSnapshot; }
Example #17
Source File: StateSnapshotTransformerTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
void testNonConcurrentSnapshotTransformerAccess() throws Exception { List<TestState> testStates = Arrays.asList( new TestValueState(), new TestListState(), new TestMapState() ); for (TestState state : testStates) { for (int i = 0; i < 100; i++) { backend.setCurrentKey(i); state.setToRandomValue(); } CheckpointOptions checkpointOptions = CheckpointOptions.forCheckpointWithDefaultLocation(); RunnableFuture<SnapshotResult<KeyedStateHandle>> snapshot1 = backend.snapshot(1L, 0L, streamFactory, checkpointOptions); RunnableFuture<SnapshotResult<KeyedStateHandle>> snapshot2 = backend.snapshot(2L, 0L, streamFactory, checkpointOptions); Thread runner1 = new Thread(snapshot1, "snapshot1"); runner1.start(); Thread runner2 = new Thread(snapshot2, "snapshot2"); runner2.start(); runner1.join(); runner2.join(); snapshot1.get(); snapshot2.get(); } }
Example #18
Source File: PrioritizedEsThreadPoolExecutor.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override protected <T> RunnableFuture<T> newTaskFor(Runnable runnable, T value) { if (!(runnable instanceof PrioritizedRunnable)) { runnable = PrioritizedRunnable.wrap(runnable, Priority.NORMAL); } return new PrioritizedFutureTask<>((PrioritizedRunnable) runnable, value, insertionOrder.incrementAndGet()); }
Example #19
Source File: StateBackendMigrationTestBase.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private KeyedStateHandle runSnapshot( RunnableFuture<SnapshotResult<KeyedStateHandle>> snapshotRunnableFuture, SharedStateRegistry sharedStateRegistry) throws Exception { if (!snapshotRunnableFuture.isDone()) { snapshotRunnableFuture.run(); } SnapshotResult<KeyedStateHandle> snapshotResult = snapshotRunnableFuture.get(); KeyedStateHandle jobManagerOwnedSnapshot = snapshotResult.getJobManagerOwnedSnapshot(); if (jobManagerOwnedSnapshot != null) { jobManagerOwnedSnapshot.registerSharedStates(sharedStateRegistry); } return jobManagerOwnedSnapshot; }
Example #20
Source File: StateBackendMigrationTestBase.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private OperatorStateHandle runSnapshot( RunnableFuture<SnapshotResult<OperatorStateHandle>> snapshotRunnableFuture) throws Exception { if (!snapshotRunnableFuture.isDone()) { snapshotRunnableFuture.run(); } return snapshotRunnableFuture.get().getJobManagerOwnedSnapshot(); }
Example #21
Source File: TaskCheckpointingBehaviourTest.java From flink with Apache License 2.0 | 5 votes |
@Override public OperatorStateBackend createOperatorStateBackend( Environment env, String operatorIdentifier, @Nonnull Collection<OperatorStateHandle> stateHandles, CloseableRegistry cancelStreamRegistry) throws Exception { return new DefaultOperatorStateBackendBuilder( env.getUserClassLoader(), env.getExecutionConfig(), true, stateHandles, cancelStreamRegistry) { @Override @SuppressWarnings("unchecked") public DefaultOperatorStateBackend build() { return new DefaultOperatorStateBackend( executionConfig, cancelStreamRegistry, new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<>(), mock(AbstractSnapshotStrategy.class) ) { @Nonnull @Override public RunnableFuture<SnapshotResult<OperatorStateHandle>> snapshot( long checkpointId, long timestamp, @Nonnull CheckpointStreamFactory streamFactory, @Nonnull CheckpointOptions checkpointOptions) throws Exception { return new FutureTask<>(() -> { throw new Exception("Async part snapshot exception."); }); } }; } }.build(); }
Example #22
Source File: OperatorSnapshotFutures.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
public OperatorSnapshotFutures( @Nonnull RunnableFuture<SnapshotResult<KeyedStateHandle>> keyedStateManagedFuture, @Nonnull RunnableFuture<SnapshotResult<KeyedStateHandle>> keyedStateRawFuture, @Nonnull RunnableFuture<SnapshotResult<OperatorStateHandle>> operatorStateManagedFuture, @Nonnull RunnableFuture<SnapshotResult<OperatorStateHandle>> operatorStateRawFuture) { this.keyedStateManagedFuture = keyedStateManagedFuture; this.keyedStateRawFuture = keyedStateRawFuture; this.operatorStateManagedFuture = operatorStateManagedFuture; this.operatorStateRawFuture = operatorStateRawFuture; }
Example #23
Source File: StateBackendTestBase.java From flink with Apache License 2.0 | 5 votes |
protected KeyedStateHandle runSnapshot( RunnableFuture<SnapshotResult<KeyedStateHandle>> snapshotRunnableFuture, SharedStateRegistry sharedStateRegistry) throws Exception { if (!snapshotRunnableFuture.isDone()) { snapshotRunnableFuture.run(); } SnapshotResult<KeyedStateHandle> snapshotResult = snapshotRunnableFuture.get(); KeyedStateHandle jobManagerOwnedSnapshot = snapshotResult.getJobManagerOwnedSnapshot(); if (jobManagerOwnedSnapshot != null) { jobManagerOwnedSnapshot.registerSharedStates(sharedStateRegistry); } return jobManagerOwnedSnapshot; }
Example #24
Source File: RocksDBStateBackendTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testDismissingSnapshot() throws Exception { setupRocksKeyedStateBackend(); try { RunnableFuture<SnapshotResult<KeyedStateHandle>> snapshot = keyedStateBackend.snapshot(0L, 0L, testStreamFactory, CheckpointOptions.forCheckpointWithDefaultLocation()); snapshot.cancel(true); verifyRocksObjectsReleased(); } finally { this.keyedStateBackend.dispose(); this.keyedStateBackend = null; } }
Example #25
Source File: RocksDBStateBackendTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testCompletingSnapshot() throws Exception { setupRocksKeyedStateBackend(); try { RunnableFuture<SnapshotResult<KeyedStateHandle>> snapshot = keyedStateBackend.snapshot(0L, 0L, testStreamFactory, CheckpointOptions.forCheckpointWithDefaultLocation()); 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 SnapshotResult<KeyedStateHandle> snapshotResult = snapshot.get(); KeyedStateHandle keyedStateHandle = snapshotResult.getJobManagerOwnedSnapshot(); assertNotNull(keyedStateHandle); assertTrue(keyedStateHandle.getStateSize() > 0); assertEquals(2, keyedStateHandle.getKeyGroupRange().getNumberOfKeyGroups()); for (BlockingCheckpointOutputStream stream : testStreamFactory.getAllCreatedStreams()) { assertTrue(stream.isClosed()); } asyncSnapshotThread.join(); verifyRocksObjectsReleased(); } finally { this.keyedStateBackend.dispose(); this.keyedStateBackend = null; } }
Example #26
Source File: StateBackendMigrationTestBase.java From flink with Apache License 2.0 | 5 votes |
private OperatorStateHandle runSnapshot( RunnableFuture<SnapshotResult<OperatorStateHandle>> snapshotRunnableFuture) throws Exception { if (!snapshotRunnableFuture.isDone()) { snapshotRunnableFuture.run(); } return snapshotRunnableFuture.get().getJobManagerOwnedSnapshot(); }
Example #27
Source File: XThreadPoolExecutor.java From lite-pool with Apache License 2.0 | 5 votes |
protected final void notifyPrevEnqueue(RunnableFuture<?> future) { if(this.listeners.size() == 0) return; for(final Listener listener : this.listeners) { try { listener.prevEnqueue(this, future); } catch(Throwable e) { LOGGER.error("["+ this.getName() + "]failed to notify prevEnqueue, listener: " + listener, e); } } }
Example #28
Source File: AsyncExecutor.java From ews-java-api with MIT License | 5 votes |
public <T> Future<T> submit(Callable<T> task, AsyncCallback callback) { if (task == null) { throw new NullPointerException(); } RunnableFuture<T> ftask = newTaskFor(task); execute(ftask); if (callback != null) { callback.setTask(ftask); } new Thread(callback).start(); return ftask; }
Example #29
Source File: XThreadPoolExecutor.java From lite-pool with Apache License 2.0 | 5 votes |
/** * */ @Override public void execute(Runnable command) { // RunnableFuture<?> rf = null; if(command instanceof RunnableFuture) { // Called by submit() rf = (RunnableFuture<?>)command; } else { rf = newTaskFor(command, null); } // try { notifyPrevEnqueue(rf); } finally { super.execute(rf); } }
Example #30
Source File: ListenableRunnableFutureInterfaceTest.java From threadly with Mozilla Public License 2.0 | 5 votes |
@Test public void isDoneTest() { ExecuteOnGetFutureFactory ff = makeFutureFactory(); TestRunnable r = new TestRunnable(); RunnableFuture<?> future = ff.make(r); future.run(); assertTrue(future.isDone()); }