Java Code Examples for akka.actor.ActorSelection#tell()
The following examples show how to use
akka.actor.ActorSelection#tell() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SshClusterManagerImpl.java From java-11-examples with Apache License 2.0 | 6 votes |
public void onSessionCloseResponse(SessionCloseResponse sessionCloseResponse) { if (isLeader.get()) { LOG.info("session close response: {}", sessionCloseResponse.getSessionId()); SessionCloseRequest sessionCloseRequest = pendingCloseSessionRequests.remove(sessionCloseResponse.getClientId()); if (sessionCloseRequest != null) { for (MemberInfo memberInfo : members.values()) { if (sessionCloseRequest.getSessionActorAddress().startsWith(memberInfo.getMemberAddress())) { memberInfo.removeSessionBySessionId(sessionCloseResponse.getSessionId()); break; } } ActorSelection actorSelection = actorSystem.actorSelection(sessionCloseResponse.getClientActorAddress()); actorSelection.tell(sessionCloseResponse, selfRef); } } }
Example 2
Source File: AkkaTest.java From java-specialagent with Apache License 2.0 | 5 votes |
@Test public void testTell(final MockTracer tracer) { final ActorRef actorRef = system.actorOf(TestActor.props(tracer, false), "tell"); actorRef.tell("tell", ActorRef.noSender()); final ActorSelection actorSelection = system.actorSelection(actorRef.path()); actorSelection.tell("tell-selection", ActorRef.noSender()); await().atMost(15, TimeUnit.SECONDS).until(TestUtil.reportedSpansSize(tracer), equalTo(4)); final List<MockSpan> spans = tracer.finishedSpans(); assertEquals(4, spans.size()); for (final MockSpan span : spans) assertEquals(AkkaAgentIntercept.COMPONENT_NAME, span.tags().get(Tags.COMPONENT.getKey())); }
Example 3
Source File: AkkaActorITest.java From java-specialagent with Apache License 2.0 | 5 votes |
private static void testTell(final ActorSystem system) throws Exception { final ActorRef actorRef = system.actorOf(TestActor.props(false), "tell"); final CountDownLatch latch = TestUtil.initExpectedSpanLatch(4); actorRef.tell("tell", ActorRef.noSender()); final ActorSelection actorSelection = system.actorSelection(actorRef.path()); actorSelection.tell("tell-selection", ActorRef.noSender()); TestUtil.checkSpan(latch, new ComponentSpanCount("java-akka", 4)); }
Example 4
Source File: SshClusterManagerImpl.java From java-11-examples with Apache License 2.0 | 5 votes |
public void onSessionCreateRequest(SessionCreateRequest sessionCreateRequest) { if (isLeader.get()) { String memberAddress = selectClusterMemberForNewSession(); ActorSelection actorSelection = actorSystem.actorSelection(Utils.getSshLocalManagerActorAddress(memberAddress)); actorSelection.tell(sessionCreateRequest, selfRef); //TODO: set timeout (circuit breaker) SessionCreateInfo sessionCreateInfo = new SessionCreateInfo(sessionCreateRequest.getClientId(), memberAddress, sessionCreateRequest.getClientActorAddress()); pendingCreateSessionRequests.put(sessionCreateRequest.getClientId(), sessionCreateInfo); } }
Example 5
Source File: SshClusterManagerImpl.java From java-11-examples with Apache License 2.0 | 5 votes |
public void onSessionCloseRequest(SessionCloseRequest sessionCloseRequest) { if (isLeader.get()) { LOG.info("session close request: {}", sessionCloseRequest.getSessionActorAddress()); pendingCloseSessionRequests.put(sessionCloseRequest.getClientId(), sessionCloseRequest); for (MemberInfo mi: members.values()) { String localManagerAddress = mi.getSshSessionLocalManagerAddress(sessionCloseRequest.getSshSessionId()); if (localManagerAddress != null) { ActorSelection actorSelection = actorSystem.actorSelection(localManagerAddress); actorSelection.tell(sessionCloseRequest, selfRef); break; } } } }
Example 6
Source File: LargeMessageProxy.java From akka-tutorial with Apache License 2.0 | 5 votes |
private void handle(LargeMessage<?> message) { ActorRef receiver = message.getReceiver(); ActorSelection receiverProxy = this.context().actorSelection(receiver.path().child(DEFAULT_NAME)); // This will definitely fail in a distributed setting if the serialized message is large! // Solution options: // 1. Serialize the object and send its bytes batch-wise (make sure to use artery's side channel then). // 2. Serialize the object and send its bytes via Akka streaming. // 3. Send the object via Akka's http client-server component. // 4. Other ideas ... receiverProxy.tell(new BytesMessage<>(message.getMessage(), this.sender(), message.getReceiver()), this.self()); }
Example 7
Source File: SunbirdMWService.java From sunbird-lms-service with MIT License | 5 votes |
public static void tellToRequestRouter(Request request, ActorRef sender) { String operation = request.getOperation(); ActorRef actor = RequestRouter.getActor(operation); if (null == actor) { ActorSelection select = getRemoteRouter(RequestRouter.class.getSimpleName()); select.tell(request, sender); } else { actor.tell(request, sender); } }
Example 8
Source File: SunbirdMWService.java From sunbird-lms-service with MIT License | 5 votes |
public static void tellToBGRouter(Request request, ActorRef sender) { String operation = request.getOperation(); ActorRef actor = BackgroundRequestRouter.getActor(operation); if (null == actor) { ActorSelection select = getRemoteRouter(BackgroundRequestRouter.class.getSimpleName()); select.tell(request, sender); } else { actor.tell(request, sender); } }
Example 9
Source File: AcknowledgementForwarderActorTest.java From ditto with Eclipse Public License 2.0 | 5 votes |
@Test public void createAcknowledgementForwarderAndThreadAcknowledgementThrough() throws ExecutionException, InterruptedException { final AcknowledgementLabel acknowledgementLabel = AcknowledgementLabel.of("my-requested-ack"); final DittoHeaders dittoHeaders = DittoHeaders.newBuilder() .randomCorrelationId() .acknowledgementRequest(AcknowledgementRequest.of(acknowledgementLabel)) .build(); final ThingId entityId = ThingId.generateRandom(); final Acknowledgement acknowledgement = Acknowledgement.of(acknowledgementLabel, entityId, HttpStatusCode.ACCEPTED, dittoHeaders); new TestKit(actorSystem) {{ when(actorContext.sender()).thenReturn(getRef()); final Optional<ActorRef> underTest = AcknowledgementForwarderActor.startAcknowledgementForwarder(actorContext, entityId, dittoHeaders, acknowledgementConfig); softly.assertThat(underTest).isPresent(); final ActorSelection ackForwarderSelection = actorSystem.actorSelection( "/user/" + AcknowledgementForwarderActor.determineActorName(dittoHeaders)); softly.assertThat(underTest.get()).isEqualByComparingTo( ackForwarderSelection.resolveOne(Duration.ofMillis(100)).toCompletableFuture().get()); ackForwarderSelection.tell(acknowledgement, getRef()); expectMsg(acknowledgement); }}; }
Example 10
Source File: Reaper.java From akka-tutorial with Apache License 2.0 | 4 votes |
public static void watchWithDefaultReaper(AbstractActor actor) { ActorSelection defaultReaper = actor.getContext().getSystem().actorSelection("/user/" + DEFAULT_NAME); defaultReaper.tell(new WatchMeMessage(), actor.getSelf()); }
Example 11
Source File: Reaper.java From akka-tutorial with Apache License 2.0 | 4 votes |
public static void watchWithDefaultReaper(AbstractActor actor) { ActorSelection defaultReaper = actor.getContext().getSystem().actorSelection("/user/" + DEFAULT_NAME); defaultReaper.tell(new WatchMeMessage(), actor.getSelf()); }
Example 12
Source File: ClientActor.java From usergrid with Apache License 2.0 | 4 votes |
@Override public void onReceive(Object message) { int startSize = nodes.size(); String routerPath = routersByMessageType.get( message.getClass() ); if ( routerPath != null && ready ) { // just pick any node, the ClusterSingletonRouter will do the consistent hash routing List<Address> nodesList = new ArrayList<>( nodes ); Address address = nodesList.get( ThreadLocalRandom.current().nextInt( nodesList.size() ) ); ActorSelection service = getContext().actorSelection( address + routerPath ); service.tell( message, getSender() ); } else if ( routerPath != null ) { logger.debug("{} responding with status unknown", name); getSender().tell( new ErrorResponse("ClientActor not ready"), getSender() ); } else if ( message instanceof StatusRequest ) { if ( ready ) { getSender().tell( new StatusMessage( name, StatusMessage.Status.READY ), getSender() ); } else { getSender().tell( new StatusMessage( name, StatusMessage.Status.INITIALIZING), getSender() ); } return; } else { processAsClusterEvent( message ); } if ( logger.isDebugEnabled() && startSize != nodes.size() ) { logger.debug( "{} now knows {} nodes", name, nodes.size() ); } if (!nodes.isEmpty() && !ready) { logger.debug( name + " is ready" ); ready = true; } else if (nodes.isEmpty() && ready) { ready = false; } }
Example 13
Source File: Reaper.java From akka-tutorial with Apache License 2.0 | 2 votes |
/** * Find the reaper actor of this actor system and let it watch the given actor. * * @param actor the actor to be watched * @see #DEFAULT_NAME the name of the default reaper */ public static void watchWithDefaultReaper(AbstractActor actor) { ActorSelection defaultReaper = actor.getContext().getSystem().actorSelection("/user/" + DEFAULT_NAME); defaultReaper.tell(new WatchMeMessage(), actor.getSelf()); }