protected String getActorPathName(ActorRef actorRef) { return actorRef.path().name(); }
private void processEndpointDeregistration(TopicUnsubscriptionMessage message) { String endpointKey = message.getOriginator().path().name(); if (endpointSessions.remove(endpointKey) != null) { LOG.debug("Removed subsctioption for endpoint {}", endpointKey); } else { LOG.warn("Failed to remove subscription for endpoint {} from topic", endpointKey); } }
/** * Tries to shut down the given actor gracefully. * * @param actorRef specifying the actor to shut down * @param timeout for the graceful shut down * @return A future that finishes with {@code true} iff. the actor could be stopped gracefully * or {@code actorRef} was {@code null}. */ private CompletableFuture<Boolean> stopActor(@Nullable final ActorRef actorRef, FiniteDuration timeout) { if (actorRef == null) { return CompletableFuture.completedFuture(true); } return FutureUtils.toJava(Patterns.gracefulStop(actorRef, timeout)) .exceptionally( (Throwable throwable) -> { // The actor did not stop gracefully in time, try to directly stop it actorSystem.stop(actorRef); log.warn("Could not stop actor {} gracefully.", actorRef.path(), throwable); return false; } ); }
private void waitForClientActor( ActorRef ra ) { logger.info( "Waiting on ClientActor [{}]...", ra.path() ); started = false; int retries = 0; int maxRetries = 60; while (retries < maxRetries) { Timeout t = new Timeout( 10, TimeUnit.SECONDS ); Future<Object> fut = Patterns.ask( ra, new ClientActor.StatusRequest(), t ); try { ClientActor.StatusMessage result = (ClientActor.StatusMessage) Await.result( fut, t.duration() ); if (result.getStatus().equals( ClientActor.StatusMessage.Status.READY )) { started = true; break; } logger.info( "Waiting for ClientActor [{}] region [{}] for [{}s]", ra.path(), currentRegion, retries ); Thread.sleep( 1000 ); } catch (Exception e) { logger.error( "Error: Timeout waiting for ClientActor [{}]", ra.path() ); } retries++; } if (started) { logger.info( "ClientActor [{}] has started", ra.path() ); } else { throw new RuntimeException( "ClientActor ["+ra.path()+"] did not start in time, validate that akka seeds are configured properly" ); } }
private ActorRef getOrCreateLogActor(String name) { ActorRef logActor = logsSessions.get(name); if (logActor == null) { logActor = context().actorOf( Props.create(new ApplicationLogActor.ActorCreator(context, appToken)) .withDispatcher(LOG_DISPATCHER_NAME) ); context().watch(logActor); logsSessions.put(logActor.path().name(), logActor); } return logActor; }
private ActorRef getOrCreateUserVerifierActor(String name) { ActorRef userVerifierActor = userVerifierSessions.get(name); if (userVerifierActor == null) { userVerifierActor = context() .actorOf( Props.create(new ApplicationUserVerifierActor.ActorCreator(context, appToken)) .withDispatcher(VERIFIER_DISPATCHER_NAME) ); context().watch(userVerifierActor); userVerifierSessions.put(userVerifierActor.path().name(), userVerifierActor); } return userVerifierActor; }
/** * Process endpoint registration. * * @param message the message */ private void processEndpointRegistration(TopicSubscriptionMessage message) { ActorRef endpointActor = message.getOriginator(); Integer seqNum = message.getSeqNumber(); SortedMap<Integer, NotificationDto> pendingNotificationMap = notificationCache.tailMap( seqNum, false); Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC")); List<NotificationDto> pendingNotifications = filterMap( pendingNotificationMap, message.getSystemNfSchemaVersion(), message.getUserNfSchemaVersion(), calendar); if (!pendingNotifications.isEmpty()) { LOG.debug("Detected new messages during endpoint subscription!"); NotificationMessage notificationMessage = NotificationMessage.fromNotifications( pendingNotifications); endpointActor.tell(notificationMessage, self()); } else { LOG.debug("No new messages detected. Subscribing endpoint actor to topic actor"); String endpointKey = message.getOriginator().path().name(); ActorInfo actorInfo = new ActorInfo( endpointActor, message.getSystemNfSchemaVersion(), message.getUserNfSchemaVersion()); if (endpointSessions.put(endpointKey, actorInfo) != null) { LOG.warn("Detected duplication of registration message: {}", message); } context().watch(endpointActor); } }
@Override public String toString() { return "ReconnectResourceManager(" + resourceManager.path() + ", " + connectionId + ')'; } }
@Override public String toString() { return "RegisterResourceManager " + resourceManager.path(); } }
@Override public String toString() { return "ReconnectResourceManager(" + resourceManager.path() + ", " + connectionId + ')'; } }
@Override public String toString() { return "RegisterResourceManager " + resourceManager.path(); } }
@Override public String toString() { return "RegisterResourceManager " + resourceManager.path(); } }
@Override public String toString() { return "Greet{" + "name='" + name + '\'' + ", sendTo=" + sendTo.path().name() + '}'; } }
private static void createClusterRoleChangeListener(List<String> memberIds) { System.out.println("memberIds=" + memberIds); for (String memberId : memberIds) { ActorRef listenerActor = listenerActorSystem.actorOf( ExampleRoleChangeListener.getProps(memberId), memberId + "-role-change-listener"); System.out.println("Role Change Listener created:" + listenerActor.path().toString()); } }
void updatePeerAddress(String peerId, String peerAddress, ActorRef sender){ LOG.info("updatePeerAddress for peer {} with address {}", peerId, peerAddress); if(actor != null) { if(LOG.isDebugEnabled()) { LOG.debug("Sending PeerAddressResolved for peer {} with address {} to {}", peerId, peerAddress, actor.path()); } actor.tell(new PeerAddressResolved(peerId, peerAddress), sender); } notifyOnShardInitializedCallbacks(); }
public AkkaJobManagerGateway(ActorGateway jobManagerGateway) { this.jobManagerGateway = Preconditions.checkNotNull(jobManagerGateway); final Option<String> optHostname = jobManagerGateway.actor().path().address().host(); hostname = optHostname.isDefined() ? optHostname.get() : "localhost"; }
/** * * @param actor whose behaviour needs to be metered */ public MeteringBehavior(AbstractUntypedActorWithMetering actor){ Preconditions.checkArgument(actor != null, "actor must not be null"); this.meteredActor = actor; String actorName = actor.getActorNameOverride() != null ? actor.getActorNameOverride() : actor.getSelf().path().name(); init(actorName); }
@Override public void runAsyncWithoutFencing(Runnable runnable) { checkNotNull(runnable, "runnable"); if (isLocal) { getActorRef().tell( new UnfencedMessage<>(new RunAsync(runnable, 0L)), ActorRef.noSender()); } else { throw new RuntimeException("Trying to send a Runnable to a remote actor at " + getActorRef().path() + ". This is not supported."); } }
@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."); } }