/** Returns the actors to broadcast trace events to. */ private List<Routee> makeRoutes() { return Registry.policies(settings).stream().map(policy -> { ActorRef actorRef = context().actorOf(Props.create(PolicyActor.class, policy)); context().watch(actorRef); return new ActorRefRoutee(actorRef); }).collect(toList()); }
private ActorRef getOrCreateUserActor(String userId) { String localUserId = toLocal(userId); ActorRef userActor = localUsers.get(localUserId); if (userActor == null && userId != null) { userActor = context().actorOf( Props.create(new LocalUserActor.ActorCreator(context, userId, tenantId)) .withDispatcher(USER_DISPATCHER_NAME), localUserId); LOG.debug("Create local user actor with id {}", userId); localUsers.put(localUserId, userActor); context().watch(userActor); } return userActor; }
private ActorRef getOrCreateGlobalUserActor(String userId) { String globalUserId = toGlobal(userId); ActorRef userActor = globalUsers.get(globalUserId); if (userActor == null && userId != null) { userActor = context().actorOf( Props.create(new GlobalUserActor.ActorCreator(context, userId, tenantId)) .withDispatcher(USER_DISPATCHER_NAME), globalUserId); LOG.debug("Create global user actor with id {}", userId); globalUsers.put(globalUserId, userActor); context().watch(userActor); } return userActor; }
private void processEndpointConnectMessage(EndpointUserConnectMessage message) { messageProcessor.processEndpointConnectMessage(context(), message); context().watch(message.getOriginator()); }
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; }
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; }
/** * 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); } }
/** * Gets the or create topic. * * @param topicId the topic id * @return the or create topic */ private ActorRef getOrCreateTopic(String topicId) { ActorRef topicActor = topicSessions.get(topicId); if (topicActor == null) { topicActor = context().actorOf( Props.create(new TopicActor.ActorCreator(context.getNotificationDeltaService())) .withDispatcher(TOPIC_DISPATCHER_NAME), buildTopicKey(topicId) ); topicSessions.put(topicId, topicActor); context().watch(topicActor); } return topicActor; }
private void processEndpointRouteMessage(EndpointRouteMessage msg) { EndpointObjectHash endpointKey = msg.getAddress().getEndpointKey(); GlobalEndpointActorMetaData actorMetaData = globalEndpointSessions.get(endpointKey); if (actorMetaData == null) { String endpointActorId = GlobalEndpointActorCreator.generateActorKey(); LOG.debug("[{}] Creating global endpoint actor for endpointKey: {}", appToken, endpointKey); actorMetaData = new GlobalEndpointActorMetaData( context().actorOf(Props.create( new GlobalEndpointActorCreator(context, endpointActorId, appToken, endpointKey)) .withDispatcher(ENDPOINT_DISPATCHER_NAME), endpointActorId), endpointActorId); globalEndpointSessions.put(endpointKey, actorMetaData); context().watch(actorMetaData.actorRef); } actorMetaData.actorRef.tell(msg, self()); }
/** * Process session endpoint request. * * @param message the message */ private void processEndpointRequest(EndpointAwareMessage message) { LocalEndpointActorMetaData actorMetaData = localEndpointSessions.get(message.getKey()); if (actorMetaData == null) { EndpointObjectHash endpointKey = message.getKey(); String endpointActorId = LocalEndpointActorCreator.generateActorKey(); LOG.debug("[{}] Creating actor with endpointKey: {}", appToken, endpointActorId); String globalActorNodeId = getGlobalEndpointActorNodeId(endpointKey); actorMetaData = new LocalEndpointActorMetaData(context() .actorOf(Props .create(new LocalEndpointActorCreator( context, endpointActorId, message.getAppToken(), message.getKey() )).withDispatcher(ENDPOINT_DISPATCHER_NAME), endpointActorId), endpointActorId, globalActorNodeId); localEndpointSessions.put(message.getKey(), actorMetaData); endpointActorMap.put(endpointActorId, message.getKey()); context().watch(actorMetaData.actorRef); notifyGlobalEndpointActor(endpointKey, globalActorNodeId); } actorMetaData.actorRef.tell(message, self()); }
/** Returns the actors to broadcast trace events to. */ private List<Routee> makeRoutes() { return Registry.policies(settings).stream().map(policy -> { ActorRef actorRef = context().actorOf(Props.create(PolicyActor.class, policy)); context().watch(actorRef); return new ActorRefRoutee(actorRef); }).collect(toList()); }