本文整理匯總了Java中com.google.common.util.concurrent.Futures.addCallback方法的典型用法代碼示例。如果您正苦於以下問題:Java Futures.addCallback方法的具體用法?Java Futures.addCallback怎麽用?Java Futures.addCallback使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.util.concurrent.Futures
的用法示例。
在下文中一共展示了Futures.addCallback方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: validate
import com.google.common.util.concurrent.Futures; //導入方法依賴的package包/類
@Override
public ListenableFuture<Boolean> validate() {
LOG.debug("Validating transaction for shard {}", shardRoot);
checkTransactionReadied();
final List<ListenableFuture<Boolean>> futures =
cohorts.stream().map(DOMStoreThreePhaseCommitCohort::canCommit).collect(Collectors.toList());
final SettableFuture<Boolean> ret = SettableFuture.create();
Futures.addCallback(Futures.allAsList(futures), new FutureCallback<List<Boolean>>() {
@Override
public void onSuccess(final List<Boolean> result) {
ret.set(true);
}
@Override
public void onFailure(final Throwable throwable) {
ret.setException(throwable);
}
}, MoreExecutors.directExecutor());
return ret;
}
示例2: sendRequests
import com.google.common.util.concurrent.Futures; //導入方法依賴的package包/類
@VisibleForTesting
List<ListenableFuture<RequestVoteResponse>> sendRequests(final RaftStateContext ctx) {
RequestVote request = RequestVote.newBuilder().setTerm(log.currentTerm()).setCandidateId(log.self().toString()).setLastLogIndex(log.lastLogIndex()).setLastLogTerm(log.lastLogTerm()).build();
List<ListenableFuture<RequestVoteResponse>> responses = Lists.newArrayList();
for (Replica replica : log.members()) {
ListenableFuture<RequestVoteResponse> response = client.requestVote(replica, request);
Futures.addCallback(response, new FutureCallback<RequestVoteResponse>() {
@Override
public void onSuccess(@Nullable RequestVoteResponse result) {
checkTermOnResponse(ctx, result);
}
@Override
public void onFailure(Throwable t) {
}
});
responses.add(response);
}
return responses;
}
示例3: create
import com.google.common.util.concurrent.Futures; //導入方法依賴的package包/類
static <KEY, RESULT> QuorumCall<KEY, RESULT> create(
Map<KEY, ? extends ListenableFuture<RESULT>> calls) {
final QuorumCall<KEY, RESULT> qr = new QuorumCall<KEY, RESULT>();
for (final Entry<KEY, ? extends ListenableFuture<RESULT>> e : calls.entrySet()) {
Preconditions.checkArgument(e.getValue() != null,
"null future for key: " + e.getKey());
Futures.addCallback(e.getValue(), new FutureCallback<RESULT>() {
@Override
public void onFailure(Throwable t) {
qr.addException(e.getKey(), t);
}
@Override
public void onSuccess(RESULT res) {
qr.addResult(e.getKey(), res);
}
});
}
return qr;
}
示例4: prepare
import com.google.common.util.concurrent.Futures; //導入方法依賴的package包/類
@Override
public ListenableFuture<Void> prepare() {
LOG.debug("Preparing transaction for shard {}", shardRoot);
checkTransactionReadied();
final List<ListenableFuture<Void>> futures =
cohorts.stream().map(DOMStoreThreePhaseCommitCohort::preCommit).collect(Collectors.toList());
final SettableFuture<Void> ret = SettableFuture.create();
Futures.addCallback(Futures.allAsList(futures), new FutureCallback<List<Void>>() {
@Override
public void onSuccess(final List<Void> result) {
ret.set(null);
}
@Override
public void onFailure(final Throwable throwable) {
ret.setException(throwable);
}
}, MoreExecutors.directExecutor());
return ret;
}
示例5: load
import com.google.common.util.concurrent.Futures; //導入方法依賴的package包/類
@Override
public String load(final Object o) throws Exception {
ListenableFuture<String> future = lex.submit(() -> {
String result = toolTipsGenerator.getToolTipText(o);
getCache().invalidate(o);
getCache().put(o, result);
return result;
});
Futures.addCallback(future, this);
return Labels.LOADING;
}
示例6: onLoadKey
import com.google.common.util.concurrent.Futures; //導入方法依賴的package包/類
default void onLoadKey(Runnable runnable) {
Futures.addCallback(getMasterPassword(), new FutureCallback<String>() {
@Override
public void onSuccess(@Nullable String result) {
runnable.run();
}
@Override
public void onFailure(Throwable t) {
LOGGER.error("failed to run callback " + runnable.toString() + " due to unexpected error while waiting for keyfile: ", t);
}
});
}
示例7: put
import com.google.common.util.concurrent.Futures; //導入方法依賴的package包/類
@Override
public void put(Collection<SinkRecord> sinkRecords) {
// If KinesisProducers cannot write to Kinesis Streams (because of
// connectivity issues, access issues
// or misconfigured shards we will pause consumption of messages till
// backlog is cleared
validateOutStandingRecords();
String partitionKey;
for (SinkRecord sinkRecord : sinkRecords) {
ListenableFuture<UserRecordResult> f;
// Kinesis does not allow empty partition key
if (sinkRecord.key() != null && !sinkRecord.key().toString().trim().equals("")) {
partitionKey = sinkRecord.key().toString().trim();
} else {
partitionKey = Integer.toString(sinkRecord.kafkaPartition());
}
if (singleKinesisProducerPerPartition)
f = addUserRecord(producerMap.get(sinkRecord.kafkaPartition() + "@" + sinkRecord.topic()), streamName,
partitionKey, usePartitionAsHashKey, sinkRecord);
else
f = addUserRecord(kinesisProducer, streamName, partitionKey, usePartitionAsHashKey, sinkRecord);
Futures.addCallback(f, callback);
}
}
示例8: JobCollectContext
import com.google.common.util.concurrent.Futures; //導入方法依賴的package包/類
public JobCollectContext(final CollectPhase collectPhase,
MapSideDataCollectOperation collectOperation,
String localNodeId,
RamAccountingContext queryPhaseRamAccountingContext,
final RowReceiver rowReceiver,
SharedShardContexts sharedShardContexts) {
super(collectPhase.executionPhaseId(), LOGGER);
this.collectPhase = collectPhase;
this.collectOperation = collectOperation;
this.queryPhaseRamAccountingContext = queryPhaseRamAccountingContext;
this.sharedShardContexts = sharedShardContexts;
listenableRowReceiver = RowReceivers.listenableRowReceiver(rowReceiver);
Futures.addCallback(listenableRowReceiver.finishFuture(), new FutureCallback<Void>() {
@Override
public void onSuccess(@Nullable Void result) {
close();
}
@Override
public void onFailure(@Nonnull Throwable t) {
closeDueToFailure(t);
}
});
this.rowReceiver = listenableRowReceiver;
this.threadPoolName = threadPoolName(collectPhase, localNodeId);
}
示例9: execute
import com.google.common.util.concurrent.Futures; //導入方法依賴的package包/類
public ListenableFuture<FullHttpResponse> execute() throws URISyntaxException {
Preconditions.checkState(request != null);
final SettableFuture<FullHttpResponse> error = SettableFuture.create();
final SettableFuture<FullHttpResponse> response = SettableFuture.create();
final ListenableFuture<ChannelFuture> connectFuture =
connect(XUrl.getInetSocket(uri), client.getBootstrap(), buildRetryLoop());
Futures.addCallback(
connectFuture,
new FutureCallback<ChannelFuture>() {
@Override
public void onSuccess(ChannelFuture result) {
try {
Channel channel = result.await().channel();
channel.writeAndFlush(request);
HttpResponseHandler responseHandler =
(HttpResponseHandler) channel.pipeline().get("responseHandler");
response.setFuture(responseHandler.getResponse());
} catch (InterruptedException e) {
response.cancel(true);
error.setException(e);
}
}
@Override
public void onFailure(Throwable t) {
response.cancel(true);
error.setException(t);
}
});
if (response.isCancelled()) {
return error;
} else {
return response;
}
}
示例10: onCarBought
import com.google.common.util.concurrent.Futures; //導入方法依賴的package包/類
@Override
public void onCarBought(CarBought notification) {
final CarPersonBuilder carPersonBuilder = new CarPersonBuilder();
carPersonBuilder.setCarId(notification.getCarId());
carPersonBuilder.setPersonId(notification.getPersonId());
CarPersonKey key = new CarPersonKey(notification.getCarId(), notification.getPersonId());
carPersonBuilder.setKey(key);
final CarPerson carPerson = carPersonBuilder.build();
LOG.info("Car bought, adding car-person entry: [{}]", carPerson);
InstanceIdentifier<CarPerson> carPersonIId =
InstanceIdentifier.<CarPeople>builder(CarPeople.class).child(CarPerson.class, carPerson.getKey()).build();
WriteTransaction tx = dataProvider.newWriteOnlyTransaction();
tx.put(LogicalDatastoreType.CONFIGURATION, carPersonIId, carPerson, true);
Futures.addCallback(tx.submit(), new FutureCallback<Void>() {
@Override
public void onSuccess(final Void result) {
LOG.info("Successfully added car-person entry: [{}]", carPerson);
}
@Override
public void onFailure(final Throwable t) {
LOG.error(String.format("Failed to add car-person entry: [%s]", carPerson), t);
}
});
}
示例11: ProjectorChainContext
import com.google.common.util.concurrent.Futures; //導入方法依賴的package包/類
public ProjectorChainContext(int id,
String name,
UUID jobId,
ProjectorFactory projectorFactory,
List<Projection> projections,
RowReceiver rowReceiver,
RamAccountingContext ramAccountingContext) {
super(id, LOGGER);
this.name = name;
ListenableRowReceiver listenableRowReceiver = RowReceivers.listenableRowReceiver(rowReceiver);
Futures.addCallback(listenableRowReceiver.finishFuture(), new FutureCallback<Void>() {
@Override
public void onSuccess(@Nullable Void result) {
ProjectorChainContext.this.close(null);
}
@Override
public void onFailure(@Nonnull Throwable t) {
ProjectorChainContext.this.close(t);
}
});
projectorChain = FlatProjectorChain.withAttachedDownstream(
projectorFactory,
ramAccountingContext,
projections,
listenableRowReceiver,
jobId
);
this.rowReceiver = projectorChain.firstProjector();
}
示例12: addCallback
import com.google.common.util.concurrent.Futures; //導入方法依賴的package包/類
@Override
public FluentFuture<V> addCallback(FutureCallback<V> callback) {
Futures.addCallback(this, callback, executor);
return this;
}
示例13: trackTimestamp
import com.google.common.util.concurrent.Futures; //導入方法依賴的package包/類
/** Track the timestamp of the event for determining watermark values until it has been sent or dropped. */
public void trackTimestamp(ListenableFuture<UserRecordResult> f, TripEvent event) {
Futures.addCallback(f, new RemoveTimestampCallback(event));
}
示例14: getDevice
import com.google.common.util.concurrent.Futures; //導入方法依賴的package包/類
@Override
public void getDevice(DeviceId deviceId, PluginCallback<Device> callback) {
ListenableFuture<Device> deviceFuture = pluginCtx.deviceService.findDeviceByIdAsync(deviceId);
Futures.addCallback(deviceFuture, getCallback(callback, v -> v));
}
示例15: addSuccessCallback
import com.google.common.util.concurrent.Futures; //導入方法依賴的package包/類
@Override
public RedFuture addSuccessCallback(Executor executor, EmptyCallback callback) {
Futures.addCallback(_settableFuture, safeCallback(t -> callback.call(), null), executor);
return this;
}