Java Code Examples for org.apache.commons.lang3.concurrent.ConcurrentUtils#constantFuture()
The following examples show how to use
org.apache.commons.lang3.concurrent.ConcurrentUtils#constantFuture() .
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: InitSlaveTaskBody.java From brooklyn-library with Apache License 2.0 | 6 votes |
private Future<ReplicationSnapshot> getValidReplicationInfo() { try { try { lock.acquire(); } catch (InterruptedException e) { throw Exceptions.propagate(e); } ReplicationSnapshot replicationSnapshot = getReplicationInfoMasterConfig(); if (replicationSnapshot == null) { replicationSnapshot = getAttributeBlocking(cluster, MySqlCluster.REPLICATION_LAST_SLAVE_SNAPSHOT); } if (!isReplicationInfoValid(replicationSnapshot)) { final MySqlNode snapshotNode = getSnapshotNode(); final String dumpName = getDumpUniqueId() + ".sql"; if (MySqlClusterUtils.IS_MASTER.apply(snapshotNode)) { return createMasterReplicationSnapshot(snapshotNode, dumpName); } else { return createSlaveReplicationSnapshot(snapshotNode, dumpName); } } return ConcurrentUtils.constantFuture(replicationSnapshot); } finally { lock.release(); } }
Example 2
Source File: DefaultBackgroundExecutor.java From cyberduck with GNU General Public License v3.0 | 6 votes |
@Override public <T> Future<T> execute(final Controller controller, final BackgroundActionRegistry registry, final BackgroundAction<T> action) { if(log.isDebugEnabled()) { log.debug(String.format("Run action %s in background", action)); } // Add action to registry of controller. Will be removed automatically when stopped registry.add(action); action.init(); // Start background task final Callable<T> command = new BackgroundCallable<T>(action, controller); try { final Future<T> task = concurrentExecutor.execute(command); if(log.isInfoEnabled()) { log.info(String.format("Scheduled background runnable %s for execution", action)); } return task; } catch(RejectedExecutionException e) { log.error(String.format("Error scheduling background task %s for execution. %s", action, e.getMessage())); action.cancel(); action.cleanup(); return ConcurrentUtils.constantFuture(null); } }
Example 3
Source File: Lang3UtilsUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void testConstantFuture_Integer() throws Exception { Future<Integer> test = ConcurrentUtils.constantFuture(5); assertTrue(test.isDone()); assertSame(5, test.get()); assertFalse(test.isCancelled()); }
Example 4
Source File: MockPersistenceDriver.java From yawp with MIT License | 5 votes |
@SuppressWarnings("unchecked") @Override public <T> FutureObject<T> saveAsync(Object object) { ObjectHolder objectHolder = new ObjectHolder(object); setIdIfNecessary(objectHolder); MockStore.put(objectHolder.getId(), object, tx()); Future<?> futureId = ConcurrentUtils.constantFuture(objectHolder.getId()); return new FutureObject<T>(r, (Future<IdRef<T>>) futureId, (T) object); }
Example 5
Source File: AbstractController.java From cyberduck with GNU General Public License v3.0 | 5 votes |
/** * Will queue up the <code>BackgroundAction</code> to be run in a background thread * * @param action The runnable to execute in a secondary thread */ @Override public <T> Future<T> background(final BackgroundAction<T> action) { if(registry.contains(action)) { log.warn(String.format("Skip duplicate background action %s found in registry", action)); return ConcurrentUtils.constantFuture(null); } return DefaultBackgroundExecutor.get().execute(this, registry, action); }
Example 6
Source File: OperationExecutor.java From db with GNU Affero General Public License v3.0 | 5 votes |
@Async public Future<OperationStatus> startOperation(final String app, final String table, final String opid, OperationTypes operationType, String... params) { Operable operable = operationFactory.getOperable(operationType, params); try { return operable.start(app, table, opid); } catch (OperationException ex) { LoggerFactory.getLogger(OperationExecutor.class.getName()).error(null, ex); return ConcurrentUtils.constantFuture(OperationStatus.ERROR); } }
Example 7
Source File: MatrixBlock.java From systemds with Apache License 2.0 | 4 votes |
public Future<MatrixBlock> allocateBlockAsync() { ExecutorService pool = LazyWriteBuffer.getUtilThreadPool(); return (pool != null) ? pool.submit(() -> allocateBlock()) : //async ConcurrentUtils.constantFuture(allocateBlock()); //fallback sync }
Example 8
Source File: SingleTransferWorker.java From cyberduck with GNU General Public License v3.0 | 4 votes |
public Future<TransferStatus> submit(final TransferCallable runnable) throws BackgroundException { return ConcurrentUtils.constantFuture(runnable.call()); }
Example 9
Source File: SerialLeastCostPathCalculator.java From amodeus with GNU General Public License v2.0 | 4 votes |
@Override public Future<Path> calcLeastCostPath(Node fromNode, Node toNode, double starttime, Person person, Vehicle vehicle) { return ConcurrentUtils.constantFuture(delegate.calcLeastCostPath(fromNode, toNode, starttime, person, vehicle)); }
Example 10
Source File: MatrixBlock.java From systemds with Apache License 2.0 | 4 votes |
public Future<MatrixBlock> allocateBlockAsync() { ExecutorService pool = LazyWriteBuffer.getUtilThreadPool(); return (pool != null) ? pool.submit(() -> allocateBlock()) : //async ConcurrentUtils.constantFuture(allocateBlock()); //fallback sync }
Example 11
Source File: PGQueryDriver.java From yawp with MIT License | 4 votes |
@Override public <T> FutureObject<T> fetchAsync(IdRef<T> id) { T object = fetch(id); Future<T> futureObject = ConcurrentUtils.constantFuture(object); return new FutureObject<>(r, futureObject); }
Example 12
Source File: PGPersistenceDriver.java From yawp with MIT License | 4 votes |
@Override public FutureObject<Void> destroyAsync(IdRef<?> id) { destroy(id); Future<Void> future = ConcurrentUtils.constantFuture(null); return new FutureObject<>(r, future); }
Example 13
Source File: PGPersistenceDriver.java From yawp with MIT License | 4 votes |
@SuppressWarnings("unchecked") private <T> FutureObject<T> saveEntityAsync(ObjectHolder objectHolder, Entity entity) { Key key = datastore.put(entity); Future<?> futureId = ConcurrentUtils.constantFuture(IdRefToKey.toIdRef(r, key, objectHolder.getModel())); return new FutureObject<>(r, (Future<IdRef<T>>) futureId, (T) objectHolder.getObject()); }
Example 14
Source File: MockQueryDriver.java From yawp with MIT License | 4 votes |
@Override public <T> FutureObject<T> fetchAsync(IdRef<T> id) { T object = fetch(id); Future<T> futureObject = ConcurrentUtils.constantFuture(object); return new FutureObject<>(r, futureObject); }
Example 15
Source File: KsqlResourceTest.java From ksql-fork-with-deep-learning-function with Apache License 2.0 | 4 votes |
@Override public Future<RecordMetadata> send(ProducerRecord record) { // Fake result: only for testing purpose return ConcurrentUtils.constantFuture(new RecordMetadata(null, 0, 0, 0, 0, 0, 0)); }
Example 16
Source File: MockPersistenceDriver.java From yawp with MIT License | 4 votes |
@Override public FutureObject<Void> destroyAsync(IdRef<?> id) { destroy(id); Future<Void> future = ConcurrentUtils.constantFuture(null); return new FutureObject<>(r, future); }
Example 17
Source File: PopupResponsibility.java From arcusandroid with Apache License 2.0 | 2 votes |
/** * Returns a future indicating whether this responsibility is qualified for execution. Subclasses * which require asynchronous processing (like making a network call) to determine if they're * qualified should override this method and throw an IllegalStateException from within * {@link #isQualified()} (which should never be called). * * @return A future boolean indicating whether the responsibility is qualified. */ public Future<Boolean> isAsynchronouslyQualified() { return ConcurrentUtils.constantFuture(isQualified()); }