當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。