/** * Tests constant future. * * @throws java.lang.Exception so we don't have to catch it */ @Test public void testConstantFuture_Integer() throws Exception { final Integer value = Integer.valueOf(5); final Future<Integer> test = ConcurrentUtils.constantFuture(value); assertTrue(test.isDone()); assertSame(value, test.get()); assertSame(value, test.get(1000, TimeUnit.SECONDS)); assertSame(value, test.get(1000, null)); assertFalse(test.isCancelled()); assertFalse(test.cancel(true)); assertFalse(test.cancel(false)); }
/** * Tests constant future. * * @throws java.lang.Exception so we don't have to catch it */ @Test public void testConstantFuture_null() throws Exception { final Integer value = null; final Future<Integer> test = ConcurrentUtils.constantFuture(value); assertTrue(test.isDone()); assertSame(value, test.get()); assertSame(value, test.get(1000, TimeUnit.SECONDS)); assertSame(value, test.get(1000, null)); assertFalse(test.isCancelled()); assertFalse(test.cancel(true)); assertFalse(test.cancel(false)); }
encoded[16] = constantFuture(encodeElement(value)); try { ret = encodeRlpListFutures(encoded);
public Future<TransferStatus> submit(final TransferCallable runnable) throws BackgroundException { return ConcurrentUtils.constantFuture(runnable.call()); }
/** * 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); }
@Override public <T> FutureObject<T> fetchAsync(IdRef<T> id) { T object = fetch(id); Future<T> futureObject = ConcurrentUtils.constantFuture(object); return new FutureObject<>(r, futureObject); }
@Override public FutureObject<Void> destroyAsync(IdRef<?> id) { destroy(id); Future<Void> future = ConcurrentUtils.constantFuture(null); return new FutureObject<>(r, future); }
@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); } }
/** * Capture arguments to test for expected values. * Since there is no response, the future will hold a null value. * * @param success callback for handling successful requests. * @param error callback for handling http errors. * @param failure callback for handling exception failures. * @param requestBuilder The bound request builder for the request to be sent. * @param timerName The name that distinguishes this request as part of a druid query or segment metadata request * @param outstanding The counter that keeps track of the outstanding (in flight) requests for the top level query * * @return a future with a null response. */ @Override protected Future<Response> sendRequest( final SuccessCallback success, final HttpErrorCallback error, final FailureCallback failure, final BoundRequestBuilder requestBuilder, final String timerName, final AtomicLong outstanding ) { this.request = requestBuilder.build(); return ConcurrentUtils.constantFuture(null); }
/** * Capture arguments to test for expected values. * Since there is no response, the future will hold a null value. * * @param success callback for handling successful requests. * @param error callback for handling http errors. * @param failure callback for handling exception failures. * @param requestBuilder The bound request builder for the request to be sent. * @param timerName The name that distinguishes this request as part of a druid query or segment metadata request * @param outstanding The counter that keeps track of the outstanding (in flight) requests for the top level query * * @return a future with a null response. */ @Override protected Future<Response> sendRequest( final SuccessCallback success, final HttpErrorCallback error, final FailureCallback failure, final BoundRequestBuilder requestBuilder, final String timerName, final AtomicLong outstanding ) { this.request = requestBuilder.build(); return ConcurrentUtils.constantFuture(null); }
@Override public <T> FutureObject<T> fetchAsync(IdRef<T> id) { T object = fetch(id); Future<T> futureObject = ConcurrentUtils.constantFuture(object); return new FutureObject<T>(r, futureObject); }
@Override public FutureObject<Void> destroyAsync(IdRef<?> id) { destroy(id); Future<Void> future = ConcurrentUtils.constantFuture(null); return new FutureObject<>(r, future); }
@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()); }
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(); } }
return ConcurrentUtils.constantFuture(null);
return ConcurrentUtils.constantFuture(null);
@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); }
return ConcurrentUtils.constantFuture(null);
return ConcurrentUtils.constantFuture(null);
encoded[16] = constantFuture(encodeElement(value)); try { ret = encodeRlpListFutures(encoded);