当前位置: 首页>>代码示例>>Java>>正文


Java FutureCallback类代码示例

本文整理汇总了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;
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:17,代码来源:BindingDOMTransactionChainAdapter.java

示例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;
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:24,代码来源:DOMDataBrokerTransactionChainImpl.java

示例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);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:17,代码来源:SimpleShardDataTreeCohortTest.java

示例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);
        }
    } );
}
 
开发者ID:Azure,项目名称:azure-documentdb-rxjava,代码行数:27,代码来源:SyncBulkInsertBenchmark.java

示例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;
}
 
开发者ID:lemonJun,项目名称:TakinRPC,代码行数:29,代码来源:Leader.java

示例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;
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:24,代码来源:ShardProxyTransaction.java

示例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;
}
 
开发者ID:lemonJun,项目名称:TakinRPC,代码行数:24,代码来源:Candidate.java

示例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;
}
 
开发者ID:airlift,项目名称:drift,代码行数:20,代码来源:DriftInvocationHandler.java

示例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();
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:20,代码来源:SimpleShardDataTreeCohortTest.java

示例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);
        }

    });
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:18,代码来源:EventSourceTopology.java

示例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 );
        }
    };
}
 
开发者ID:u2032,项目名称:wall-t,代码行数:26,代码来源:ApiController.java

示例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;
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:25,代码来源:CassandraBaseTimeseriesDao.java

示例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);
        }
    });
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:21,代码来源:CountContext.java

示例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());
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:19,代码来源:AbstractChainedTask.java

示例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);
        }
    });
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:20,代码来源:DDLTask.java


注:本文中的com.google.common.util.concurrent.FutureCallback类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。