Address address = nodesList.get( ThreadLocalRandom.current().nextInt( nodesList.size() ) ); ActorSelection service = getContext().actorSelection( address + routerPath ); service.tell( message, getSender() );
@Override public CompletableFuture<MetricQueryServiceGateway> retrieveService(String queryServicePath) { ActorSelection selection = actorSystem.actorSelection(queryServicePath); return FutureUtils.toJava(selection.resolveOne(FutureUtils.toFiniteDuration(lookupTimeout))).thenApply(AkkaQueryServiceGateway::new); } }
private void forwardToSessionActor(final String connectionCorrelationId, final Object object) { if (object instanceof WithDittoHeaders) { LogUtil.enhanceLogWithCorrelationId(logger, (WithDittoHeaders<?>) object); } else { LogUtil.enhanceLogWithCorrelationId(logger, (String) null); } logger.debug("Forwarding to session actor '{}': {}", connectionCorrelationId, object); getContext().actorSelection(connectionCorrelationId).forward(object, getContext()); } }
@Override protected void triggerConnectingToJobManager(String leaderAddress) { ActorSelection jobManagerSel = context().actorSelection(leaderAddress); // check if we are at the leading JobManager. if (jobManagerSel.anchorPath().root().equals(self().path().root())) { super.triggerConnectingToJobManager(leaderAddress); } else { LOG.info("Received leader address but not running in leader ActorSystem. Cancelling registration."); } }
/** * Sets the target primary shard and initiates a CreateTransaction try. */ void setPrimaryShard(PrimaryShardInfo primaryShardInfo) { this.primaryShardInfo = primaryShardInfo; if (getTransactionType() == TransactionType.WRITE_ONLY && getActorContext().getDatastoreContext().isWriteOnlyTransactionOptimizationsEnabled()) { ActorSelection primaryShard = primaryShardInfo.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()), primaryShardInfo.getPrimaryShardVersion())); } else { tryCreateTransaction(); } }
@Override public CompletableFuture<MetricQueryServiceGateway> retrieveService(String queryServicePath) { ActorSelection selection = actorSystem.actorSelection(queryServicePath); return FutureUtils.toJava(selection.resolveOne(FutureUtils.toFiniteDuration(lookupTimeout))).thenApply(AkkaQueryServiceGateway::new); } }
private void handleCanCommitTransaction(final CanCommitTransaction canCommit) { LOG.debug("{}: Can committing transaction {}", persistenceId(), canCommit.getTransactionID()); if (isLeader()) { commitCoordinator.handleCanCommit(canCommit.getTransactionID(), getSender(), this); } else { ActorSelection leader = getLeader(); if (leader == null) { messageRetrySupport.addMessageToRetry(canCommit, getSender(), "Could not canCommit transaction " + canCommit.getTransactionID()); } else { LOG.debug("{}: Forwarding CanCommitTransaction to leader {}", persistenceId(), leader); leader.forward(canCommit, getContext()); } } }
@Override protected void triggerConnectingToJobManager(String leaderAddress) { ActorSelection jobManagerSel = context().actorSelection(leaderAddress); // check if we are at the leading JobManager. if (jobManagerSel.anchorPath().root().equals(self().path().root())) { super.triggerConnectingToJobManager(leaderAddress); } else { LOG.info("Received leader address but not running in leader ActorSystem. Cancelling registration."); } }
private void setListenerRegistrationActor(ActorSelection listenerRegistrationActor) { if(listenerRegistrationActor == null) { return; } boolean sendCloseMessage = false; synchronized(this) { if(closed) { sendCloseMessage = true; } else { this.listenerRegistrationActor = listenerRegistrationActor; } } if(sendCloseMessage) { listenerRegistrationActor.tell(CloseDataChangeListenerRegistration.INSTANCE, null); } }
@Override public CompletableFuture<MetricQueryServiceGateway> retrieveService(String queryServicePath) { ActorSelection selection = actorSystem.actorSelection(queryServicePath); return FutureUtils.toJava(selection.resolveOne(FutureUtils.toFiniteDuration(lookupTimeout))).thenApply(AkkaQueryServiceGateway::new); } }
private void handleCommitTransaction(final CommitTransaction commit) { if (isLeader()) { commitCoordinator.handleCommit(commit.getTransactionID(), getSender(), this); } else { ActorSelection leader = getLeader(); if (leader == null) { messageRetrySupport.addMessageToRetry(commit, getSender(), "Could not commit transaction " + commit.getTransactionID()); } else { LOG.debug("{}: Forwarding CommitTransaction to leader {}", persistenceId(), leader); leader.forward(commit, getContext()); } } }
@Override protected void triggerConnectingToJobManager(String leaderAddress) { ActorSelection jobManagerSel = context().actorSelection(leaderAddress); // check if we are at the leading JobManager. if (jobManagerSel.anchorPath().root().equals(self().path().root())) { super.triggerConnectingToJobManager(leaderAddress); } else { LOG.info("Received leader address but not running in leader ActorSystem. Cancelling registration."); } }
/** * Sends an operation to be executed by a remote actor asynchronously without waiting for a * reply (essentially set and forget). * * @param actor the ActorSelection * @param message the message to send */ public void sendOperationAsync(ActorSelection actor, Object message) { Preconditions.checkArgument(actor != null, "actor must not be null"); Preconditions.checkArgument(message != null, "message must not be null"); LOG.debug("Sending message {} to {}", message.getClass(), actor); actor.tell(message, ActorRef.noSender()); }
private void sendRegistrationRequests() { for (Map.Entry<String, Boolean> entry : notifierRegistrationStatus.entrySet()) { if (!entry.getValue()) { try { LOG.debug("{} registering with {}", getSelf().path().toString(), entry.getKey()); ActorRef notifier = Await.result( getContext().actorSelection(entry.getKey()).resolveOne(duration), duration); notifier.tell(new RegisterRoleChangeListener(), getSelf()); } catch (Exception e) { LOG.error("ERROR!! Unable to send registration request to notifier {}", entry.getKey()); } } } }
persistenceId(), shardName, address, visitedAddresses); getContext().actorSelection(address).forward(new RemoteFindPrimary(shardName, message.isWaitUntilReady(), visitedAddresses), getContext()); return;
@Override protected void triggerConnectingToJobManager(String leaderAddress) { ActorSelection jobManagerSel = context().actorSelection(leaderAddress); // check if we are at the leading JobManager. if (jobManagerSel.anchorPath().root().equals(self().path().root())) { super.triggerConnectingToJobManager(leaderAddress); } else { LOG.info("Received leader address but not running in leader ActorSystem. Cancelling registration."); } }
@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());
@SuppressWarnings("checkstyle:IllegalCatch") private void sendRegistrationRequests() { for (Map.Entry<String, Boolean> entry : notifierRegistrationStatus.entrySet()) { if (!entry.getValue()) { try { LOG.debug("{} registering with {}", getSelf().path().toString(), entry.getKey()); ActorRef notifier = Await.result( getContext().actorSelection(entry.getKey()).resolveOne(DURATION), DURATION); notifier.tell(new RegisterRoleChangeListener(), getSelf()); } catch (Exception e) { LOG.error("ERROR!! Unable to send registration request to notifier {}", entry.getKey()); } } } }
@Override protected void handleNonRaftCommand(Object message) { if (message instanceof KeyValue) { if (isLeader()) { persistData(getSender(), new PayloadIdentifier(persistIdentifier++), (Payload) message, false); } else { if (getLeader() != null) { getLeader().forward(message, getContext()); } } } else if (message instanceof PrintState) { if (LOG.isDebugEnabled()) { LOG.debug("State of the node:{} has entries={}, {}", getId(), state.size(), getReplicatedLogState()); } } else if (message instanceof PrintRole) { if (LOG.isDebugEnabled()) { if (getRaftState() == RaftState.Leader || getRaftState() == RaftState.IsolatedLeader) { final String followers = ((Leader)this.getCurrentBehavior()).printFollowerStates(); LOG.debug("{} = {}, Peers={}, followers={}", getId(), getRaftState(), getRaftActorContext().getPeerIds(), followers); } else { LOG.debug("{} = {}, Peers={}", getId(), getRaftState(), getRaftActorContext().getPeerIds()); } } } else { super.handleNonRaftCommand(message); } }