use of akka.actor.ActorSelection in project controller by opendaylight.
the class RemoteTransactionContextSupport method setPrimaryShard.
/**
* Sets the target primary shard and initiates a CreateTransaction try.
*/
void setPrimaryShard(final PrimaryShardInfo newPrimaryShardInfo) {
this.primaryShardInfo = newPrimaryShardInfo;
if (getTransactionType() == TransactionType.WRITE_ONLY && getActorContext().getDatastoreContext().isWriteOnlyTransactionOptimizationsEnabled()) {
ActorSelection primaryShard = newPrimaryShardInfo.getPrimaryShardActor();
LOG.debug("Tx {} Primary shard {} found - creating WRITE_ONLY transaction context", getIdentifier(), primaryShard);
// For write-only Tx's we prepare the transaction modifications directly on the shard actor
// to avoid the overhead of creating a separate transaction actor.
transactionContextWrapper.executePriorTransactionOperations(createValidTransactionContext(primaryShard, String.valueOf(primaryShard.path()), newPrimaryShardInfo.getPrimaryShardVersion()));
} else {
tryCreateTransaction();
}
}
use of akka.actor.ActorSelection in project controller by opendaylight.
the class Shard method handleReadyLocalTransaction.
@SuppressWarnings("checkstyle:IllegalCatch")
private void handleReadyLocalTransaction(final ReadyLocalTransaction message) {
LOG.debug("{}: handleReadyLocalTransaction for {}", persistenceId(), message.getTransactionId());
boolean isLeaderActive = isLeaderActive();
if (isLeader() && isLeaderActive) {
try {
commitCoordinator.handleReadyLocalTransaction(message, getSender(), this);
} catch (Exception e) {
LOG.error("{}: Error handling ReadyLocalTransaction for Tx {}", persistenceId(), message.getTransactionId(), e);
getSender().tell(new Failure(e), getSelf());
}
} else {
ActorSelection leader = getLeader();
if (!isLeaderActive || leader == null) {
messageRetrySupport.addMessageToRetry(message, getSender(), "Could not process ready local transaction " + message.getTransactionId());
} else {
LOG.debug("{}: Forwarding ReadyLocalTransaction to leader {}", persistenceId(), leader);
message.setRemoteVersion(getCurrentBehavior().getLeaderPayloadVersion());
leader.forward(message, getContext());
}
}
}
use of akka.actor.ActorSelection in project controller by opendaylight.
the class ThreePhaseCommitCohortProxy method resolveCohorts.
private ListenableFuture<Void> resolveCohorts() {
if (cohortsResolvedFuture.isDone()) {
return cohortsResolvedFuture;
}
final AtomicInteger completed = new AtomicInteger(cohorts.size());
final Object lock = new Object();
for (final CohortInfo info : cohorts) {
info.getActorFuture().onComplete(new OnComplete<ActorSelection>() {
@Override
public void onComplete(final Throwable failure, final ActorSelection actor) {
synchronized (lock) {
boolean done = completed.decrementAndGet() == 0;
if (failure != null) {
LOG.debug("Tx {}: a cohort Future failed", transactionId, failure);
cohortsResolvedFuture.setException(failure);
} else if (!cohortsResolvedFuture.isDone()) {
LOG.debug("Tx {}: cohort actor {} resolved", transactionId, actor);
info.setResolvedActor(actor);
if (done) {
LOG.debug("Tx {}: successfully resolved all cohort actors", transactionId);
cohortsResolvedFuture.set(null);
}
}
}
}
}, actorContext.getClientDispatcher());
}
return cohortsResolvedFuture;
}
use of akka.actor.ActorSelection in project flink by apache.
the class AkkaRpcService method connect.
// this method does not mutate state and is thus thread-safe
@Override
public <C extends RpcGateway> Future<C> connect(final String address, final Class<C> clazz) {
checkState(!stopped, "RpcService is stopped");
LOG.debug("Try to connect to remote RPC endpoint with address {}. Returning a {} gateway.", address, clazz.getName());
final ActorSelection actorSel = actorSystem.actorSelection(address);
final scala.concurrent.Future<Object> identify = Patterns.ask(actorSel, new Identify(42), timeout.toMilliseconds());
final scala.concurrent.Future<C> resultFuture = identify.map(new Mapper<Object, C>() {
@Override
public C checkedApply(Object obj) throws Exception {
ActorIdentity actorIdentity = (ActorIdentity) obj;
if (actorIdentity.getRef() == null) {
throw new RpcConnectionException("Could not connect to rpc endpoint under address " + address + '.');
} else {
ActorRef actorRef = actorIdentity.getRef();
final String address = AkkaUtils.getAkkaURL(actorSystem, actorRef);
final String hostname;
Option<String> host = actorRef.path().address().host();
if (host.isEmpty()) {
hostname = "localhost";
} else {
hostname = host.get();
}
InvocationHandler akkaInvocationHandler = new AkkaInvocationHandler(address, hostname, actorRef, timeout, maximumFramesize, null);
// Rather than using the System ClassLoader directly, we derive the ClassLoader
// from this class . That works better in cases where Flink runs embedded and all Flink
// code is loaded dynamically (for example from an OSGI bundle) through a custom ClassLoader
ClassLoader classLoader = AkkaRpcService.this.getClass().getClassLoader();
@SuppressWarnings("unchecked") C proxy = (C) Proxy.newProxyInstance(classLoader, new Class<?>[] { clazz }, akkaInvocationHandler);
return proxy;
}
}
}, actorSystem.dispatcher());
return new FlinkFuture<>(resultFuture);
}
use of akka.actor.ActorSelection in project transporter by wang4ever.
the class ActorManager method actorTell.
/**
* 通知消息给其他对应actor
*
* @param message
* 当前通知消息对象
* @param actorName
* 目标actor(待通知的用户号码)
* @return 当前被通知的用户bean
*/
public ActorBean actorTell(String actorName, Object message) {
if (StringUtils.isEmpty(actorName))
throw new AkkaException("Failed to send actor '" + actorName + "', because it does not exist or destroyed.");
// 目前推送用户(actor)
ActorBean ab = null;
try {
// 1.1 get actor user.
ab = this.repository.getActorBean(actorName);
if (ab == null)
return null;
// 获取actor用户地址
ActorSelection acti = this._system.actorSelection(ab.getRemoteActorAddr());
acti.tell(message, acti.anchor());
if (logger.isDebugEnabled())
logger.debug("It has been sent to actor: '{}'", ab.getRemoteActorAddr());
} catch (Exception e) {
logger.error("Failed to send to actor '" + ab.getRemoteActorAddr() + "'.", e);
}
return ab;
}
Aggregations