private void subscribeForEvents() { checkConnectionNotNull(); // unsubscribe to previously subscribed topics unsubscribeFromEvents(); uniqueTopics = connection.getTargets().stream() .flatMap(target -> target.getTopics().stream().map(FilteredTopic::getTopic)) .collect(Collectors.toSet()); forEachPubSubTopicDo(pubSubTopic -> { final DistributedPubSubMediator.Subscribe subscribe = new DistributedPubSubMediator.Subscribe(pubSubTopic, PUB_SUB_GROUP_PREFIX + connectionId, getSelf()); log.debug("Subscribing to pub-sub topic <{}> for connection <{}>.", pubSubTopic, connectionId); pubSubMediator.tell(subscribe, getSelf()); }); }
private void subscribeForEvents() { checkConnectionNotNull(); // unsubscribe to previously subscribed topics unsubscribeFromEvents(); uniqueTopics = connection.getTargets().stream() .flatMap(target -> target.getTopics().stream().map(FilteredTopic::getTopic)) .collect(Collectors.toSet()); forEachPubSubTopicDo(pubSubTopic -> { final DistributedPubSubMediator.Subscribe subscribe = new DistributedPubSubMediator.Subscribe(pubSubTopic, PUB_SUB_GROUP_PREFIX + connectionId, getSelf()); log.debug("Subscribing to pub-sub topic <{}> for connection <{}>.", pubSubTopic, connectionId); pubSubMediator.tell(subscribe, getSelf()); }); }
private void retrieveConnection(final RetrieveConnection command) { checkConnectionNotNull(); getSender().tell(RetrieveConnectionResponse.of(connection, command.getDittoHeaders()), getSelf()); }
private void retrieveConnection(final RetrieveConnection command) { checkConnectionNotNull(); getSender().tell(RetrieveConnectionResponse.of(connection, command.getDittoHeaders()), getSelf()); }
private void retrieveConnectionStatus(final RetrieveConnectionStatus command) { checkConnectionNotNull(); getSender().tell(RetrieveConnectionStatusResponse.of(connectionId, connection.getConnectionStatus(), command.getDittoHeaders()), getSelf()); }
private void retrieveConnectionMetrics(final RetrieveConnectionMetrics command) { checkConnectionNotNull(); final ActorRef origin = getSender(); askClientActorIfStarted(command, response -> origin.tell(response, getSelf()), error -> handleException("retrieve-metrics", origin, error), () -> respondWithEmptyMetrics(command, origin)); }
private void retrieveConnectionStatus(final RetrieveConnectionStatus command) { checkConnectionNotNull(); getSender().tell(RetrieveConnectionStatusResponse.of(connectionId, connection.getConnectionStatus(), command.getDittoHeaders()), getSelf()); }
private void retrieveConnectionMetrics(final RetrieveConnectionMetrics command) { checkConnectionNotNull(); final ActorRef origin = getSender(); askClientActorIfStarted(command, response -> origin.tell(response, getSelf()), error -> handleException("retrieve-metrics", origin, error), () -> respondWithEmptyMetrics(command, origin)); }
private void startClientActorIfRequired() { checkNotNull(connectionId, "connectionId"); checkConnectionNotNull(); if (clientActorRouter == null) { final int clientCount = connection.getClientCount(); log.info("Starting ClientActor for connection <{}> with <{}> clients.", connectionId, clientCount); final Props props = propsFactory.getActorPropsForType(connection, conciergeForwarder); final ClusterRouterPoolSettings clusterRouterPoolSettings = new ClusterRouterPoolSettings(clientCount, 1, true, Collections.singleton(CLUSTER_ROLE)); final RoundRobinPool roundRobinPool = new RoundRobinPool(clientCount); final Props clusterRouterPoolProps = new ClusterRouterPool(roundRobinPool, clusterRouterPoolSettings).props(props); // start client actor without name so it does not conflict with its previous incarnation clientActorRouter = getContext().actorOf(clusterRouterPoolProps); } else { log.debug("ClientActor already started."); } }
private void startClientActorIfRequired() { checkNotNull(connectionId, "connectionId"); checkConnectionNotNull(); if (clientActorRouter == null) { final int clientCount = connection.getClientCount(); log.info("Starting ClientActor for connection <{}> with <{}> clients.", connectionId, clientCount); final Props props = propsFactory.getActorPropsForType(connection, conciergeForwarder); final ClusterRouterPoolSettings clusterRouterPoolSettings = new ClusterRouterPoolSettings(clientCount, 1, true, Collections.singleton(CLUSTER_ROLE)); final RoundRobinPool roundRobinPool = new RoundRobinPool(clientCount); final Props clusterRouterPoolProps = new ClusterRouterPool(roundRobinPool, clusterRouterPoolSettings).props(props); // start client actor without name so it does not conflict with its previous incarnation clientActorRouter = getContext().actorOf(clusterRouterPoolProps); } else { log.debug("ClientActor already started."); } }
private void openConnection(final OpenConnection command) { checkConnectionNotNull(); final ConnectionOpened connectionOpened = ConnectionOpened.of(command.getConnectionId(), command.getDittoHeaders()); final ActorRef origin = getSender(); final ActorRef self = getSelf(); persistEvent(connectionOpened, persistedEvent -> { restoreConnection(connection.toBuilder().connectionStatus(ConnectionStatus.OPEN).build()); askClientActor(command, response -> { final ConnectivityCommandResponse commandResponse = OpenConnectionResponse.of(connectionId, command.getDittoHeaders()); final PerformTask performTask = new PerformTask("open connection", subscribeForEventsAndScheduleResponse(commandResponse, origin)); self.tell(performTask, ActorRef.noSender()); }, error -> handleException("open-connection", origin, error) ); }); }
private void openConnection(final OpenConnection command) { checkConnectionNotNull(); final ConnectionOpened connectionOpened = ConnectionOpened.of(command.getConnectionId(), command.getDittoHeaders()); final ActorRef origin = getSender(); final ActorRef self = getSelf(); persistEvent(connectionOpened, persistedEvent -> { restoreConnection(connection.toBuilder().connectionStatus(ConnectionStatus.OPEN).build()); askClientActor(command, response -> { final ConnectivityCommandResponse commandResponse = OpenConnectionResponse.of(connectionId, command.getDittoHeaders()); final PerformTask performTask = new PerformTask("open connection", subscribeForEventsAndScheduleResponse(commandResponse, origin)); self.tell(performTask, ActorRef.noSender()); }, error -> handleException("open-connection", origin, error) ); }); }
private void closeConnection(final CloseConnection command) { checkConnectionNotNull();
private void closeConnection(final CloseConnection command) { checkConnectionNotNull();