本文整理汇总了Java中akka.dispatch.OnComplete类的典型用法代码示例。如果您正苦于以下问题:Java OnComplete类的具体用法?Java OnComplete怎么用?Java OnComplete使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OnComplete类属于akka.dispatch包,在下文中一共展示了OnComplete类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import akka.dispatch.OnComplete; //导入依赖的package包/类
void init(final String shardName) {
Future<ActorRef> findFuture = actorContext.findLocalShardAsync(shardName);
findFuture.onComplete(new OnComplete<ActorRef>() {
@Override
public void onComplete(final Throwable failure, final ActorRef shard) {
if (failure instanceof LocalShardNotFoundException) {
LOG.debug("{}: No local shard found for {} - DataTreeChangeListener {} at path {} "
+ "cannot be registered", logContext(), shardName, getInstance(), registeredPath);
} else if (failure != null) {
LOG.error("{}: Failed to find local shard {} - DataTreeChangeListener {} at path {} "
+ "cannot be registered: {}", logContext(), shardName, getInstance(), registeredPath,
failure);
} else {
doRegistration(shard);
}
}
}, actorContext.getClientDispatcher());
}
示例2: doRegistration
import akka.dispatch.OnComplete; //导入依赖的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());
}
示例3: initiateCoordinatedCommit
import akka.dispatch.OnComplete; //导入依赖的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;
}
示例4: initiateDirectCommit
import akka.dispatch.OnComplete; //导入依赖的package包/类
Future<Object> initiateDirectCommit() {
final Future<Object> messageFuture = initiateCommit(true);
messageFuture.onComplete(new OnComplete<Object>() {
@Override
public void onComplete(final Throwable failure, final Object message) throws Throwable {
if (failure != null) {
LOG.error("Failed to prepare transaction {} on backend", transaction.getIdentifier(), failure);
transactionAborted(transaction);
} else if (CommitTransactionReply.isSerializedType(message)) {
LOG.debug("Transaction {} committed successfully", transaction.getIdentifier());
transactionCommitted(transaction);
} else {
LOG.error("Transaction {} resulted in unhandled message type {}, aborting", message.getClass());
transactionAborted(transaction);
}
}
}, actorContext.getClientDispatcher());
return messageFuture;
}
示例5: start
import akka.dispatch.OnComplete; //导入依赖的package包/类
public static DistributedEntityOwnershipService start(final ActorContext context,
final EntityOwnerSelectionStrategyConfig strategyConfig) {
ActorRef shardManagerActor = context.getShardManager();
Configuration configuration = context.getConfiguration();
Collection<MemberName> entityOwnersMemberNames = configuration.getUniqueMemberNamesForAllShards();
CreateShard createShard = new CreateShard(new ModuleShardConfiguration(EntityOwners.QNAME.getNamespace(),
"entity-owners", ENTITY_OWNERSHIP_SHARD_NAME, ModuleShardStrategy.NAME, entityOwnersMemberNames),
newShardBuilder(context, strategyConfig), null);
Future<Object> createFuture = context.executeOperationAsync(shardManagerActor,
createShard, MESSAGE_TIMEOUT);
createFuture.onComplete(new OnComplete<Object>() {
@Override
public void onComplete(final Throwable failure, final Object response) {
if (failure != null) {
LOG.error("Failed to create {} shard", ENTITY_OWNERSHIP_SHARD_NAME, failure);
} else {
LOG.info("Successfully created {} shard", ENTITY_OWNERSHIP_SHARD_NAME);
}
}
}, context.getClientDispatcher());
return new DistributedEntityOwnershipService(context);
}
示例6: executeLocalEntityOwnershipShardOperation
import akka.dispatch.OnComplete; //导入依赖的package包/类
@VisibleForTesting
void executeLocalEntityOwnershipShardOperation(final Object message) {
if (localEntityOwnershipShard == null) {
Future<ActorRef> future = context.findLocalShardAsync(ENTITY_OWNERSHIP_SHARD_NAME);
future.onComplete(new OnComplete<ActorRef>() {
@Override
public void onComplete(final Throwable failure, final ActorRef shardActor) {
if (failure != null) {
LOG.error("Failed to find local {} shard", ENTITY_OWNERSHIP_SHARD_NAME, failure);
} else {
localEntityOwnershipShard = shardActor;
executeEntityOwnershipShardOperation(localEntityOwnershipShard, message);
}
}
}, context.getClientDispatcher());
} else {
executeEntityOwnershipShardOperation(localEntityOwnershipShard, message);
}
}
示例7: broadcast
import akka.dispatch.OnComplete; //导入依赖的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());
}
}
示例8: tryCreateTransaction
import akka.dispatch.OnComplete; //导入依赖的package包/类
/**
Performs a CreateTransaction try async.
*/
private void tryCreateTransaction() {
LOG.debug("Tx {} Primary shard {} found - trying create transaction", getIdentifier(),
primaryShardInfo.getPrimaryShardActor());
Object serializedCreateMessage = new CreateTransaction(getIdentifier(), getTransactionType().ordinal(),
primaryShardInfo.getPrimaryShardVersion()).toSerializable();
Future<Object> createTxFuture = getActorContext().executeOperationAsync(
primaryShardInfo.getPrimaryShardActor(), serializedCreateMessage, createTxMessageTimeout);
createTxFuture.onComplete(new OnComplete<Object>() {
@Override
public void onComplete(Throwable failure, Object response) {
onCreateTransactionComplete(failure, response);
}
}, getActorContext().getClientDispatcher());
}
示例9: init
import akka.dispatch.OnComplete; //导入依赖的package包/类
public void init(final YangInstanceIdentifier path, final AsyncDataBroker.DataChangeScope scope) {
dataChangeListenerActor = actorContext.getActorSystem().actorOf(
DataChangeListener.props(listener, path).withDispatcher(actorContext.getNotificationDispatcherPath()));
Future<ActorRef> findFuture = actorContext.findLocalShardAsync(shardName);
findFuture.onComplete(new OnComplete<ActorRef>() {
@Override
public void onComplete(Throwable failure, ActorRef shard) {
if (failure instanceof LocalShardNotFoundException) {
LOG.debug("No local shard found for {} - DataChangeListener {} at path {} "
+ "cannot be registered", shardName, listener, path);
} else if (failure != null) {
LOG.error("Failed to find local shard {} - DataChangeListener {} at path {} "
+ "cannot be registered: {}", shardName, listener, path, failure);
} else {
doRegistration(shard, path, scope);
}
}
}, actorContext.getClientDispatcher());
}
示例10: doRegistration
import akka.dispatch.OnComplete; //导入依赖的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());
}
示例11: init
import akka.dispatch.OnComplete; //导入依赖的package包/类
public void init(String shardName) {
// FIXME: Add late binding to shard.
Future<ActorRef> findFuture = actorContext.findLocalShardAsync(shardName);
findFuture.onComplete(new OnComplete<ActorRef>() {
@Override
public void onComplete(final Throwable failure, final ActorRef shard) {
if (failure instanceof LocalShardNotFoundException) {
LOG.debug("No local shard found for {} - DataTreeChangeListener {} at path {} "
+ "cannot be registered", shardName, getInstance(), subtree);
} else if (failure != null) {
LOG.error("Failed to find local shard {} - DataTreeChangeListener {} at path {} "
+ "cannot be registered: {}", shardName, getInstance(), subtree, failure);
} else {
performRegistration(shard);
}
}
}, actorContext.getClientDispatcher());
}
示例12: performRegistration
import akka.dispatch.OnComplete; //导入依赖的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());
}
示例13: isPreviousShardActorStopInProgress
import akka.dispatch.OnComplete; //导入依赖的package包/类
private boolean isPreviousShardActorStopInProgress(final String shardName, final Object messageToDefer) {
final CompositeOnComplete<Boolean> stopOnComplete = shardActorsStopping.get(shardName);
if (stopOnComplete == null) {
return false;
}
LOG.debug("{} : Stop is in progress for shard {} - adding OnComplete callback to defer {}", persistenceId(),
shardName, messageToDefer);
final ActorRef sender = getSender();
stopOnComplete.addOnComplete(new OnComplete<Boolean>() {
@Override
public void onComplete(final Throwable failure, final Boolean result) {
LOG.debug("{} : Stop complete for shard {} - re-queing {}", persistenceId(), shardName, messageToDefer);
self().tell(messageToDefer, sender);
}
});
return true;
}
示例14: findPrimary
import akka.dispatch.OnComplete; //导入依赖的package包/类
private void findPrimary(final String shardName, final FindPrimaryResponseHandler handler) {
Timeout findPrimaryTimeout = new Timeout(datastoreContextFactory.getBaseDatastoreContext()
.getShardInitializationTimeout().duration().$times(2));
Future<Object> futureObj = ask(getSelf(), new FindPrimary(shardName, true), findPrimaryTimeout);
futureObj.onComplete(new OnComplete<Object>() {
@Override
public void onComplete(final Throwable failure, final Object response) {
if (failure != null) {
handler.onFailure(failure);
} else {
if (response instanceof RemotePrimaryShardFound) {
handler.onRemotePrimaryShardFound((RemotePrimaryShardFound) response);
} else if (response instanceof LocalPrimaryShardFound) {
handler.onLocalPrimaryFound((LocalPrimaryShardFound) response);
} else {
handler.onUnknownResponse(response);
}
}
}
}, new Dispatchers(context().system().dispatchers()).getDispatcher(Dispatchers.DispatcherType.Client));
}
示例15: run
import akka.dispatch.OnComplete; //导入依赖的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) {
tryReschedule(throwable);
} else {
LOG.debug("Local backend for shard[{}] lookup successful, starting leader lookup..", toLookup);
system.scheduler().scheduleOnce(
SHARD_LOOKUP_TASK_INTERVAL,
new ShardLeaderLookupTask(system, replyTo, context, clusterWrapper, actorRef,
shardingService, toLookup, lookupMaxRetries),
system.dispatcher());
}
}
}, system.dispatcher());
}