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


Java Future.onComplete方法代码示例

本文整理汇总了Java中scala.concurrent.Future.onComplete方法的典型用法代码示例。如果您正苦于以下问题:Java Future.onComplete方法的具体用法?Java Future.onComplete怎么用?Java Future.onComplete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scala.concurrent.Future的用法示例。


在下文中一共展示了Future.onComplete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doRegistration

import scala.concurrent.Future; //导入方法依赖的package包/类
private void doRegistration(final ActorRef shard) {

        Future<Object> future = actorContext.executeOperationAsync(shard,
                new RegisterDataTreeChangeListener(registeredPath, dataChangeListenerActor,
                        getInstance() instanceof ClusteredDOMDataTreeChangeListener),
                actorContext.getDatastoreContext().getShardInitializationTimeout());

        future.onComplete(new OnComplete<Object>() {
            @Override
            public void onComplete(final Throwable failure, final Object result) {
                if (failure != null) {
                    LOG.error("{}: Failed to register DataTreeChangeListener {} at path {}", logContext(),
                            getInstance(), registeredPath, failure);
                } else {
                    RegisterDataTreeNotificationListenerReply reply = (RegisterDataTreeNotificationListenerReply)result;
                    setListenerRegistrationActor(actorContext.actorSelection(
                            reply.getListenerRegistrationPath()));
                }
            }
        }, actorContext.getClientDispatcher());
    }
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:22,代码来源:DataTreeChangeListenerProxy.java

示例2: initiateCoordinatedCommit

import scala.concurrent.Future; //导入方法依赖的package包/类
Future<ActorSelection> initiateCoordinatedCommit() {
    final Future<Object> messageFuture = initiateCommit(false);
    final Future<ActorSelection> ret = TransactionReadyReplyMapper.transform(messageFuture, actorContext,
            transaction.getIdentifier());
    ret.onComplete(new OnComplete<ActorSelection>() {
        @Override
        public void onComplete(final Throwable failure, final ActorSelection success) throws Throwable {
            if (failure != null) {
                LOG.info("Failed to prepare transaction {} on backend", transaction.getIdentifier(), failure);
                transactionAborted(transaction);
                return;
            }

            LOG.debug("Transaction {} resolved to actor {}", transaction.getIdentifier(), success);
        }
    }, actorContext.getClientDispatcher());

    return ret;
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:20,代码来源:LocalThreePhaseCommitCohort.java

示例3: transform

import scala.concurrent.Future; //导入方法依赖的package包/类
private <T> Future<T> transform(final Future<Object> future) {
    final Promise<T> promise = new scala.concurrent.impl.Promise.DefaultPromise<>();
    future.onComplete(new OnComplete<Object>() {
        @Override
        public void onComplete(final Throwable failure, final Object success) throws Throwable {
            if (success instanceof Throwable) {
                promise.failure((Throwable) success);
                return;
            }
            if (success == Void.TYPE) {
                promise.success(null);
                return;
            }
            promise.success((T) success);
        }
    }, context().dispatcher());
    return promise.future();
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:19,代码来源:MockedSnapshotStore.java

示例4: run

import scala.concurrent.Future; //导入方法依赖的package包/类
@Override
public void run() {
    final Future<ActorRef> localShardFuture =
            context.findLocalShardAsync(ClusterUtils.getCleanShardName(toLookup.getRootIdentifier()));

    localShardFuture.onComplete(new OnComplete<ActorRef>() {
        @Override
        public void onComplete(Throwable throwable, ActorRef actorRef) throws Throwable {
            if (throwable != null) {
                //TODO Shouldn't we check why findLocalShard failed?
                LOG.debug("Backend shard[{}] removal lookup successful notifying the registration future",
                        toLookup);
                replyTo.tell(new Success(null), noSender());
            } else {
                tryReschedule(null);
            }
        }
    }, system.dispatcher());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:20,代码来源:ShardedDataTreeActor.java

示例5: broadcast

import scala.concurrent.Future; //导入方法依赖的package包/类
/**
 * Send the message to each and every shard.
 */
public void broadcast(final Function<Short, Object> messageSupplier, Class<?> messageClass) {
    for (final String shardName : configuration.getAllShardNames()) {

        Future<PrimaryShardInfo> primaryFuture = findPrimaryShardAsync(shardName);
        primaryFuture.onComplete(new OnComplete<PrimaryShardInfo>() {
            @Override
            public void onComplete(Throwable failure, PrimaryShardInfo primaryShardInfo) {
                if (failure != null) {
                    LOG.warn("broadcast failed to send message {} to shard {}:  {}",
                        messageClass.getSimpleName(), shardName, failure);
                } else {
                    Object message = messageSupplier.apply(primaryShardInfo.getPrimaryShardVersion());
                    primaryShardInfo.getPrimaryShardActor().tell(message, ActorRef.noSender());
                }
            }
        }, getClientDispatcher());
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:22,代码来源:ActorContext.java

示例6: performRegistration

import scala.concurrent.Future; //导入方法依赖的package包/类
private synchronized void performRegistration(ActorRef shard) {
    if (isClosed()) {
        return;
    }
    cohortRegistry = shard;
    Future<Object> future =
            Patterns.ask(shard, new DataTreeCohortActorRegistry.RegisterCohort(subtree, actor), TIMEOUT);
    future.onComplete(new OnComplete<Object>() {

        @Override
        public void onComplete(Throwable failure, Object val) {
            if (failure != null) {
                LOG.error("Unable to register {} as commit cohort", getInstance(), failure);
            }
            if (isClosed()) {
                removeRegistration();
            }
        }

    }, actorContext.getClientDispatcher());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:22,代码来源:DataTreeCohortRegistrationProxy.java

示例7: doRegistration

import scala.concurrent.Future; //导入方法依赖的package包/类
private void doRegistration(ActorRef shard, final YangInstanceIdentifier path,
        DataChangeScope scope) {

    Future<Object> future = actorContext.executeOperationAsync(shard,
            new RegisterChangeListener(path, dataChangeListenerActor, scope,
                listener instanceof ClusteredDOMDataChangeListener),
            actorContext.getDatastoreContext().getShardInitializationTimeout());

    future.onComplete(new OnComplete<Object>() {
        @Override
        public void onComplete(Throwable failure, Object result) {
            if (failure != null) {
                LOG.error("Failed to register DataChangeListener {} at path {}",
                        listener, path.toString(), failure);
            } else {
                RegisterDataTreeNotificationListenerReply reply = (RegisterDataTreeNotificationListenerReply)result;
                setListenerRegistrationActor(actorContext.actorSelection(
                        reply.getListenerRegistrationPath()));
            }
        }
    }, actorContext.getClientDispatcher());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:23,代码来源:DataChangeListenerRegistrationProxy.java

示例8: executeRead

import scala.concurrent.Future; //导入方法依赖的package包/类
@Override
public <T> void executeRead(final AbstractRead<T> readCmd, final SettableFuture<T> returnFuture) {
    LOG.debug("Tx {} executeRead {} called path = {}", getIdentifier(), readCmd.getClass().getSimpleName(),
            readCmd.getPath());

    // Send any batched modifications. This is necessary to honor the read uncommitted semantics of the
    // public API contract.

    acquireOperation();
    sendBatchedModifications();

    OnComplete<Object> onComplete = new OnComplete<Object>() {
        @Override
        public void onComplete(Throwable failure, Object response) throws Throwable {
            if (failure != null) {
                LOG.debug("Tx {} {} operation failed: {}", getIdentifier(), readCmd.getClass().getSimpleName(),
                        failure);

                returnFuture.setException(new ReadFailedException("Error checking "
                    + readCmd.getClass().getSimpleName() + " for path " + readCmd.getPath(), failure));
            } else {
                LOG.debug("Tx {} {} operation succeeded", getIdentifier(), readCmd.getClass().getSimpleName());
                readCmd.processResponse(response, returnFuture);
            }
        }
    };

    Future<Object> future = executeOperationAsync(readCmd.asVersion(getTransactionVersion()),
            actorContext.getOperationTimeout());

    future.onComplete(onComplete, actorContext.getClientDispatcher());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:33,代码来源:RemoteTransactionContext.java

示例9: sendCanCommitTransaction

import scala.concurrent.Future; //导入方法依赖的package包/类
private void sendCanCommitTransaction(final CohortInfo toCohortInfo, final OnComplete<Object> onComplete) {
    CanCommitTransaction message = new CanCommitTransaction(transactionId, toCohortInfo.getActorVersion());

    LOG.debug("Tx {}: sending {} to {}", transactionId, message, toCohortInfo.getResolvedActor());

    Future<Object> future = actorContext.executeOperationAsync(toCohortInfo.getResolvedActor(),
            message.toSerializable(), actorContext.getTransactionCommitOperationTimeout());
    future.onComplete(onComplete, actorContext.getClientDispatcher());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:10,代码来源:ThreePhaseCommitCohortProxy.java

示例10: removePrefixShardReplica

import scala.concurrent.Future; //导入方法依赖的package包/类
private void removePrefixShardReplica(final RemovePrefixShardReplica contextMessage, final String shardName,
                                      final String primaryPath, final ActorRef sender) {
    if (isShardReplicaOperationInProgress(shardName, sender)) {
        return;
    }

    shardReplicaOperationsInProgress.add(shardName);

    final ShardIdentifier shardId = getShardIdentifier(contextMessage.getMemberName(), shardName);

    final DatastoreContext datastoreContext = newShardDatastoreContextBuilder(shardName).build();

    //inform ShardLeader to remove this shard as a replica by sending an RemoveServer message
    LOG.debug("{}: Sending RemoveServer message to peer {} for shard {}", persistenceId(),
            primaryPath, shardId);

    Timeout removeServerTimeout = new Timeout(datastoreContext.getShardLeaderElectionTimeout().duration());
    Future<Object> futureObj = ask(getContext().actorSelection(primaryPath),
            new RemoveServer(shardId.toString()), removeServerTimeout);

    futureObj.onComplete(new OnComplete<Object>() {
        @Override
        public void onComplete(final Throwable failure, final Object response) {
            if (failure != null) {
                shardReplicaOperationsInProgress.remove(shardName);
                String msg = String.format("RemoveServer request to leader %s for shard %s failed",
                        primaryPath, shardName);

                LOG.debug("{}: {}", persistenceId(), msg, failure);

                // FAILURE
                sender.tell(new Status.Failure(new RuntimeException(msg, failure)), self());
            } else {
                // SUCCESS
                self().tell(new WrappedShardResponse(shardId, response, primaryPath), sender);
            }
        }
    }, new Dispatchers(context().system().dispatchers()).getDispatcher(Dispatchers.DispatcherType.Client));
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:40,代码来源:ShardManager.java

示例11: removeShardReplica

import scala.concurrent.Future; //导入方法依赖的package包/类
private void removeShardReplica(final RemoveShardReplica contextMessage, final String shardName,
        final String primaryPath, final ActorRef sender) {
    if (isShardReplicaOperationInProgress(shardName, sender)) {
        return;
    }

    shardReplicaOperationsInProgress.add(shardName);

    final ShardIdentifier shardId = getShardIdentifier(contextMessage.getMemberName(), shardName);

    final DatastoreContext datastoreContext = newShardDatastoreContextBuilder(shardName).build();

    //inform ShardLeader to remove this shard as a replica by sending an RemoveServer message
    LOG.debug("{}: Sending RemoveServer message to peer {} for shard {}", persistenceId(),
            primaryPath, shardId);

    Timeout removeServerTimeout = new Timeout(datastoreContext.getShardLeaderElectionTimeout().duration());
    Future<Object> futureObj = ask(getContext().actorSelection(primaryPath),
            new RemoveServer(shardId.toString()), removeServerTimeout);

    futureObj.onComplete(new OnComplete<Object>() {
        @Override
        public void onComplete(final Throwable failure, final Object response) {
            if (failure != null) {
                shardReplicaOperationsInProgress.remove(shardName);
                String msg = String.format("RemoveServer request to leader %s for shard %s failed",
                        primaryPath, shardName);

                LOG.debug("{}: {}", persistenceId(), msg, failure);

                // FAILURE
                sender.tell(new Status.Failure(new RuntimeException(msg, failure)), self());
            } else {
                // SUCCESS
                self().tell(new WrappedShardResponse(shardId, response, primaryPath), sender);
            }
        }
    }, new Dispatchers(context().system().dispatchers()).getDispatcher(Dispatchers.DispatcherType.Client));
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:40,代码来源:ShardManager.java

示例12: abort

import scala.concurrent.Future; //导入方法依赖的package包/类
@Override
public void abort(final FutureCallback<Void> abortCallback) {
    if (!dataTree.startAbort(this)) {
        abortCallback.onSuccess(null);
        return;
    }

    candidate = null;
    state = State.ABORTED;

    final Optional<List<Future<Object>>> maybeAborts = userCohorts.abort();
    if (!maybeAborts.isPresent()) {
        abortCallback.onSuccess(null);
        return;
    }

    final Future<Iterable<Object>> aborts = Futures.sequence(maybeAborts.get(), ExecutionContexts.global());
    if (aborts.isCompleted()) {
        abortCallback.onSuccess(null);
        return;
    }

    aborts.onComplete(new OnComplete<Iterable<Object>>() {
        @Override
        public void onComplete(final Throwable failure, final Iterable<Object> objs) {
            if (failure != null) {
                abortCallback.onFailure(failure);
            } else {
                abortCallback.onSuccess(null);
            }
        }
    }, ExecutionContexts.global());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:34,代码来源:SimpleShardDataTreeCohort.java

示例13: newTransactionContextWrapper

import scala.concurrent.Future; //导入方法依赖的package包/类
final TransactionContextWrapper newTransactionContextWrapper(final TransactionProxy parent,
        final String shardName) {
    final TransactionContextWrapper transactionContextWrapper =
            new TransactionContextWrapper(parent.getIdentifier(), actorContext);

    Future<PrimaryShardInfo> findPrimaryFuture = findPrimaryShard(shardName, parent.getIdentifier());
    if (findPrimaryFuture.isCompleted()) {
        Try<PrimaryShardInfo> maybe = findPrimaryFuture.value().get();
        if (maybe.isSuccess()) {
            onFindPrimaryShardSuccess(maybe.get(), parent, shardName, transactionContextWrapper);
        } else {
            onFindPrimaryShardFailure(maybe.failed().get(), parent, shardName, transactionContextWrapper);
        }
    } else {
        findPrimaryFuture.onComplete(new OnComplete<PrimaryShardInfo>() {
            @Override
            public void onComplete(final Throwable failure, final PrimaryShardInfo primaryShardInfo) {
                if (failure == null) {
                    onFindPrimaryShardSuccess(primaryShardInfo, parent, shardName, transactionContextWrapper);
                } else {
                    onFindPrimaryShardFailure(failure, parent, shardName, transactionContextWrapper);
                }
            }
        }, actorContext.getClientDispatcher());
    }

    return transactionContextWrapper;
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:29,代码来源:AbstractTransactionContextFactory.java

示例14: tryFindPrimaryShard

import scala.concurrent.Future; //导入方法依赖的package包/类
private void tryFindPrimaryShard() {
    LOG.debug("Tx {} Retrying findPrimaryShardAsync for shard {}", getIdentifier(), shardName);

    this.primaryShardInfo = null;
    Future<PrimaryShardInfo> findPrimaryFuture = getActorContext().findPrimaryShardAsync(shardName);
    findPrimaryFuture.onComplete(new OnComplete<PrimaryShardInfo>() {
        @Override
        public void onComplete(final Throwable failure, final PrimaryShardInfo newPrimaryShardInfo) {
            onFindPrimaryShardComplete(failure, newPrimaryShardInfo);
        }
    }, getActorContext().getClientDispatcher());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:13,代码来源:RemoteTransactionContextSupport.java

示例15: completeWith

import scala.concurrent.Future; //导入方法依赖的package包/类
protected void completeWith(final Future<Object> future) {
    future.onComplete(new FutureUpdater(), ExecutionContext.Implicits$.MODULE$.global());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:4,代码来源:RemoteDOMRpcFuture.java


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