本文整理汇总了Java中com.google.common.util.concurrent.FutureCallback类的典型用法代码示例。如果您正苦于以下问题:Java FutureCallback类的具体用法?Java FutureCallback怎么用?Java FutureCallback使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FutureCallback类属于com.google.common.util.concurrent包,在下文中一共展示了FutureCallback类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: listenForFailure
import com.google.common.util.concurrent.FutureCallback; //导入依赖的package包/类
private CheckedFuture<Void, TransactionCommitFailedException> listenForFailure(
final WriteTransaction tx, final CheckedFuture<Void, TransactionCommitFailedException> future) {
Futures.addCallback(future, new FutureCallback<Void>() {
@Override
public void onFailure(final Throwable t) {
failTransactionChain(tx,t);
}
@Override
public void onSuccess(final Void result) {
// Intentionally NOOP
}
});
return future;
}
示例2: submit
import com.google.common.util.concurrent.FutureCallback; //导入依赖的package包/类
@Override
public CheckedFuture<Void, TransactionCommitFailedException> submit(
final DOMDataWriteTransaction transaction, final Collection<DOMStoreThreePhaseCommitCohort> cohorts) {
checkNotFailed();
checkNotClosed();
final CheckedFuture<Void, TransactionCommitFailedException> ret = broker.submit(transaction, cohorts);
COUNTER_UPDATER.incrementAndGet(this);
Futures.addCallback(ret, new FutureCallback<Void>() {
@Override
public void onSuccess(final Void result) {
transactionCompleted();
}
@Override
public void onFailure(final Throwable t) {
transactionFailed(transaction, t);
}
});
return ret;
}
示例3: testPreCommitWithReportedFailure
import com.google.common.util.concurrent.FutureCallback; //导入依赖的package包/类
@Test
public void testPreCommitWithReportedFailure() throws Exception {
canCommitSuccess();
final Exception cause = new IllegalArgumentException("mock");
cohort.reportFailure(cause);
@SuppressWarnings("unchecked")
final FutureCallback<DataTreeCandidate> callback = mock(FutureCallback.class);
cohort.preCommit(callback);
verify(callback).onFailure(cause);
verifyNoMoreInteractions(callback);
verify(mockShardDataTree, never()).startPreCommit(cohort);
}
示例4: createDocument
import com.google.common.util.concurrent.FutureCallback; //导入依赖的package包/类
@Override
protected void createDocument(Document docToInsert, CallBack<ResourceResponse<Document>> onSuccess,
CallBack<Throwable> onFailure) {
Callable<ResourceResponse<Document>> documentCreateCallable = new Callable<ResourceResponse<Document>>() {
@Override
public ResourceResponse<Document> call() throws Exception {
return documentClient.createDocument(collection.getSelfLink(), docToInsert, null, true);
}
};
ListenableFuture<ResourceResponse<Document>> listenableFuture = this.executor.submit(documentCreateCallable);
Futures.addCallback(listenableFuture, new FutureCallback<ResourceResponse<Document>>() {
@Override
public void onFailure(Throwable t) {
onFailure.invoke(t);
}
@Override
public void onSuccess(ResourceResponse<Document> resourceResponse) {
onSuccess.invoke(resourceResponse);
}
} );
}
示例5: sendRequests
import com.google.common.util.concurrent.FutureCallback; //导入依赖的package包/类
/**
* Notify the {@link ReplicaManager} to send an update the next possible time it can
*
* @return futures with the result of the update
*/
@Nonnull
@VisibleForTesting
List<ListenableFuture<AppendEntriesResponse>> sendRequests(final RaftStateContext ctx) {
List<ListenableFuture<AppendEntriesResponse>> responses = newArrayList();
for (ReplicaManager replicaManager : managers.values()) {
ListenableFuture<AppendEntriesResponse> response = replicaManager.requestUpdate();
responses.add(response);
Futures.addCallback(response, new FutureCallback<AppendEntriesResponse>() {
@Override
public void onSuccess(@Nullable AppendEntriesResponse result) {
updateCommitted();
checkTermOnResponse(ctx, result);
}
@Override
public void onFailure(Throwable t) {
}
});
}
return responses;
}
示例6: validate
import com.google.common.util.concurrent.FutureCallback; //导入依赖的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;
}
示例7: sendRequests
import com.google.common.util.concurrent.FutureCallback; //导入依赖的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;
}
示例8: unwrapUserException
import com.google.common.util.concurrent.FutureCallback; //导入依赖的package包/类
private static ListenableFuture<Object> unwrapUserException(ListenableFuture<Object> future)
{
SettableFuture<Object> result = SettableFuture.create();
Futures.addCallback(future, new FutureCallback<Object>()
{
@Override
public void onSuccess(Object value)
{
result.set(value);
}
@Override
public void onFailure(Throwable t)
{
result.setException(unwrapUserException(t));
}
});
return result;
}
示例9: testPreCommitWithIllegalArgumentEx
import com.google.common.util.concurrent.FutureCallback; //导入依赖的package包/类
@Test
public void testPreCommitWithIllegalArgumentEx() throws Exception {
canCommitSuccess();
final Exception cause = new IllegalArgumentException("mock");
doAnswer(invocation -> {
invocation.getArgumentAt(0, SimpleShardDataTreeCohort.class).failedPreCommit(cause);
return null;
}).when(mockShardDataTree).startPreCommit(cohort);
@SuppressWarnings("unchecked")
final FutureCallback<DataTreeCandidate> callback = mock(FutureCallback.class);
cohort.preCommit(callback);
verify(callback).onFailure(cause);
verifyNoMoreInteractions(callback);
verify(mockUserCohorts).abort();
}
示例10: deleteData
import com.google.common.util.concurrent.FutureCallback; //导入依赖的package包/类
private <T extends DataObject> void deleteData(final LogicalDatastoreType store, final InstanceIdentifier<T> path){
final WriteTransaction tx = getDataBroker().newWriteOnlyTransaction();
tx.delete(OPERATIONAL, path);
Futures.addCallback( tx.submit(), new FutureCallback<Void>(){
@Override
public void onSuccess(final Void result) {
LOG.trace("Data has deleted from datastore {} {}", store, path);
}
@Override
public void onFailure(final Throwable t) {
LOG.error("Can not delete data from datastore [store: {}] [path: {}] [exception: {}]",store,path, t);
}
});
}
示例11: registerBuildStatus
import com.google.common.util.concurrent.FutureCallback; //导入依赖的package包/类
private FutureCallback<Build> registerBuildStatus( final BuildTypeData buildType, final int buildId ) {
return new FutureCallback<Build>( ) {
@Override
public void onSuccess( final Build result ) {
buildType.registerBuild( _buildProvider.get( getApiVersion( ) ).apply( result ) );
_eventBus.post( buildType );
final Optional<ProjectData> project = _projectManager.getProject( buildType.getProjectId( ) );
if ( project.isPresent( ) ) {
_eventBus.post( project.get( ) );
}
}
@Override
public void onFailure( final Throwable t ) {
LOGGER.error( "Error during loading full information for build with id " + buildId + ", build type: " + buildType.getId( ), t );
final Integer errorCount = _buildRequestErrorCounter.getIfPresent( buildId );
final int newErrorCount = errorCount == null ? 1 : errorCount + 1;
_buildRequestErrorCounter.put( buildId, newErrorCount );
if ( newErrorCount >= ERROR_COUNT_BEFORE_IGNORING )
LOGGER.info( "Build {} is now temporary ignored for about {} minutes due to {} failures.", buildId, IGNORING_TIME_IN_MINUTES, ERROR_COUNT_BEFORE_IGNORING );
}
};
}
示例12: findAllAsyncWithLimit
import com.google.common.util.concurrent.FutureCallback; //导入依赖的package包/类
private ListenableFuture<List<TsKvEntry>> findAllAsyncWithLimit(EntityId entityId, TsKvQuery query) {
long minPartition = toPartitionTs(query.getStartTs());
long maxPartition = toPartitionTs(query.getEndTs());
ResultSetFuture partitionsFuture = fetchPartitions(entityId, query.getKey(), minPartition, maxPartition);
final SimpleListenableFuture<List<TsKvEntry>> resultFuture = new SimpleListenableFuture<>();
final ListenableFuture<List<Long>> partitionsListFuture = Futures.transform(partitionsFuture, getPartitionsArrayFunction(), readResultsProcessingExecutor);
Futures.addCallback(partitionsListFuture, new FutureCallback<List<Long>>() {
@Override
public void onSuccess(@Nullable List<Long> partitions) {
TsKvQueryCursor cursor = new TsKvQueryCursor(entityId.getEntityType().name(), entityId.getId(), query, partitions);
findAllAsyncSequentiallyWithLimit(cursor, resultFuture);
}
@Override
public void onFailure(Throwable t) {
log.error("[{}][{}] Failed to fetch partitions for interval {}-{}", entityId.getEntityType().name(), entityId.getId(), minPartition, maxPartition, t);
}
}, readResultsProcessingExecutor);
return resultFuture;
}
示例13: innerStart
import com.google.common.util.concurrent.FutureCallback; //导入依赖的package包/类
@Override
public void innerStart() {
try {
countFuture = countOperation.count(indexShardMap, whereClause);
} catch (IOException | InterruptedException e) {
throw Throwables.propagate(e);
}
Futures.addCallback(countFuture, new FutureCallback<Long>() {
@Override
public void onSuccess(@Nullable Long result) {
rowReceiver.setNextRow(new Row1(result));
close();
}
@Override
public void onFailure(@Nonnull Throwable t) {
close(t);
}
});
}
示例14: start
import com.google.common.util.concurrent.FutureCallback; //导入依赖的package包/类
@Override
public void start() {
if (!this.upstreamResult.isEmpty()) {
Futures.addCallback(Futures.allAsList(this.upstreamResult), new FutureCallback<List<TaskResult>>() {
@Override
public void onSuccess(@Nullable List<TaskResult> result) {
doStart(result);
}
@Override
public void onFailure(@Nonnull Throwable t) {
result.setException(t);
}
});
} else {
doStart(ImmutableList.<TaskResult>of());
}
}
示例15: start
import com.google.common.util.concurrent.FutureCallback; //导入依赖的package包/类
@Override
public void start() {
ListenableFuture<Long> future = ddlStatementDispatcher.dispatch(analyzedStatement, jobId(), this);
Futures.addCallback(future, new FutureCallback<Long>() {
@Override
public void onSuccess(Long rowCount) {
if (rowCount == null) {
result.set(TaskResult.ROW_COUNT_UNKNOWN);
} else {
result.set(new RowCountResult(rowCount));
}
}
@Override
public void onFailure(@Nonnull Throwable t) {
result.setException(t);
}
});
}