Search in sources :

Example 16 with ActorSelection

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();
    }
}
Also used : ActorSelection(akka.actor.ActorSelection)

Example 17 with ActorSelection

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());
        }
    }
}
Also used : ActorSelection(akka.actor.ActorSelection) RetiredGenerationException(org.opendaylight.controller.cluster.access.concepts.RetiredGenerationException) NotLeaderException(org.opendaylight.controller.cluster.access.commands.NotLeaderException) LeadershipTransferFailedException(org.opendaylight.controller.cluster.raft.LeadershipTransferFailedException) IOException(java.io.IOException) RequestException(org.opendaylight.controller.cluster.access.concepts.RequestException) UnsupportedRequestException(org.opendaylight.controller.cluster.access.concepts.UnsupportedRequestException) RuntimeRequestException(org.opendaylight.controller.cluster.access.concepts.RuntimeRequestException) OutOfSequenceEnvelopeException(org.opendaylight.controller.cluster.access.commands.OutOfSequenceEnvelopeException) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) DataValidationFailedException(org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException) Failure(akka.actor.Status.Failure)

Example 18 with ActorSelection

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;
}
Also used : ActorSelection(akka.actor.ActorSelection) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 19 with ActorSelection

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);
}
Also used : ActorRef(akka.actor.ActorRef) RpcConnectionException(org.apache.flink.runtime.rpc.exceptions.RpcConnectionException) InvocationHandler(java.lang.reflect.InvocationHandler) Identify(akka.actor.Identify) RpcConnectionException(org.apache.flink.runtime.rpc.exceptions.RpcConnectionException) FlinkFuture(org.apache.flink.runtime.concurrent.impl.FlinkFuture) ActorSelection(akka.actor.ActorSelection) Option(scala.Option) ActorIdentity(akka.actor.ActorIdentity)

Example 20 with ActorSelection

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;
}
Also used : ActorSelection(akka.actor.ActorSelection) AkkaException(akka.AkkaException) InvalidActorNameException(akka.actor.InvalidActorNameException) AkkaException(akka.AkkaException)

Aggregations

ActorSelection (akka.actor.ActorSelection)43 ActorRef (akka.actor.ActorRef)9 Test (org.junit.Test)6 PrimaryShardInfo (org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo)5 ActorContext (org.opendaylight.controller.cluster.datastore.utils.ActorContext)4 FollowerLogInformation (org.opendaylight.controller.cluster.raft.FollowerLogInformation)4 InvalidActorNameException (akka.actor.InvalidActorNameException)3 Status (akka.actor.Status)3 TestActorRef (akka.testkit.TestActorRef)3 TestKit (akka.testkit.javadsl.TestKit)3 Timeout (akka.util.Timeout)3 ArrayList (java.util.ArrayList)3 ClientActorContext (org.opendaylight.controller.cluster.access.client.ClientActorContext)3 AkkaException (akka.AkkaException)2 ActorIdentity (akka.actor.ActorIdentity)2 Identify (akka.actor.Identify)2 Failure (akka.actor.Status.Failure)2 Success (akka.actor.Status.Success)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 AbstractActorTest (org.opendaylight.controller.cluster.datastore.AbstractActorTest)2