@Override public void createComplete(int rc, LedgerHandle lh, Object ctx) { if (BKException.Code.OK == rc) { promise.updateIfEmpty(new Return<LedgerHandle>(lh)); } else { promise.updateIfEmpty(new Throw<LedgerHandle>(BKException.create(rc))); } } }, null);
void setException(Throwable throwable) { Stopwatch stopwatch = Stopwatch.createStarted(); if (promise.updateIfEmpty(new Throw<List<LogRecordWithDLSN>>(throwable))) { futureSetLatency.registerFailedEvent(stopwatch.stop().elapsed(TimeUnit.MICROSECONDS)); delayUntilPromiseSatisfied.registerFailedEvent(enqueueTime.elapsed(TimeUnit.MICROSECONDS)); } }
@Override public void deleteComplete(int rc, Object ctx) { if (BKException.Code.OK == rc) { promise.updateIfEmpty(new Return<Void>(null)); } else if (BKException.Code.NoSuchLedgerExistsException == rc) { if (ignoreNonExistentLedger) { promise.updateIfEmpty(new Return<Void>(null)); } else { promise.updateIfEmpty(new Throw<Void>(BKException.create(rc))); } } else { promise.updateIfEmpty(new Throw<Void>(BKException.create(rc))); } } }, null);
protected void setResponse(Response response) { Return<Response> responseTry = new Return(response); boolean isEmpty = result.updateIfEmpty(responseTry); if (!isEmpty) { Option<Try<Response>> resultTry = result.poll(); logger.error("Result set multiple times. Value='{}', New='{}'", resultTry, responseTry); } }
/** * Satisfy the <i>promise</i> with provided <i>cause</i>. * * @param promise promise to satisfy * @param cause cause to satisfy * @return true if successfully satisfy the future. false if the promise has been satisfied. */ public static <T> boolean setException(Promise<T> promise, Throwable cause) { boolean success = promise.updateIfEmpty(new Throw<T>(cause)); if (!success) { logger.info("Result set multiple times. Value = '{}', New = 'Throw({})'", promise.poll(), cause); } return success; }
/** * Satisfy the <i>promise</i> with provide value. * <p>If the promise was already satisfied, nothing will be changed. * * @param promise promise to satisfy * @param value value to satisfy * @return true if successfully satisfy the future. false if the promise has been satisfied. */ public static <T> boolean setValue(Promise<T> promise, T value) { boolean success = promise.updateIfEmpty(new Return<T>(value)); if (!success) { logger.info("Result set multiple times. Value = '{}', New = 'Return({})'", promise.poll(), value); } return success; }
private void claimOwnership(int lockEpoch) { lockState.transition(State.CLAIMED); // clear previous lock ids lockContext.clearLockIds(); // add current lock id lockContext.addLockId(lockId); if (LOG.isDebugEnabled()) { LOG.debug("Notify lock waiters on {} at {} : watcher epoch {}, lock epoch {}", new Object[] { lockPath, System.currentTimeMillis(), lockEpoch, ZKSessionLock.this.epoch.get() }); } acquireFuture.updateIfEmpty(new Return<Boolean>(true)); }
@Override public void processResult(int rc, String path, Object ctx) { if (KeeperException.Code.OK.intValue() == rc) { promise.updateIfEmpty(new Return<Void>(null)); return; } promise.updateIfEmpty(new Throw<Void>( KeeperException.create(KeeperException.Code.get(rc)))); return; } }, null);
@Override public void processResult(int rc, String path, Object ctx, Stat stat) { if (KeeperException.Code.OK.intValue() == rc) { promise.updateIfEmpty(new Return<ZkVersion>(new ZkVersion(stat.getVersion()))); return; } promise.updateIfEmpty(new Throw<ZkVersion>( KeeperException.create(KeeperException.Code.get(rc)))); return; } }, null);
@Override public void onFailure(Throwable cause) { getOwnerPromise.updateIfEmpty(new Throw<SocketAddress>(cause)); }
protected void setResponse(Response response) { Return<Response> responseTry = new Return(response); boolean isEmpty = result.updateIfEmpty(responseTry); if (!isEmpty) { Option<Try<Response>> resultTry = result.poll(); logger.error("Result set multiple times. Value='{}', New='{}'", resultTry, responseTry); } }
@Override public void onSuccess(WriteResponse value) { if (StatusCode.FOUND == value.getHeader().getCode() && null != value.getHeader().getLocation()) { try { InetSocketAddress addr = DLSocketAddress.deserialize( value.getHeader().getLocation() ).getSocketAddress(); getOwnerPromise.updateIfEmpty(new Return<SocketAddress>(addr)); } catch (IOException e) { // retry from the routing server again logger.error("ERROR in getOwner", e); retryGetOwnerFromResourcePlacementServer(op, getOwnerPromise, e); return; } } else { // retry from the routing server again retryGetOwnerFromResourcePlacementServer(op, getOwnerPromise, new StreamUnavailableException("Stream " + op.stream + "'s owner is unknown")); } } });