akka.actor.PoisonPill Java Examples
The following examples show how to use
akka.actor.PoisonPill.
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: QueueActorRouterProducer.java From usergrid with Apache License 2.0 | 8 votes |
@Override public void produceRouter(ActorSystem system, String role) { ClusterSingletonManagerSettings settings = ClusterSingletonManagerSettings.create( system ).withRole( "io" ); system.actorOf( ClusterSingletonManager.props( Props.create( GuiceActorProducer.class, QueueActorRouter.class ), PoisonPill.getInstance(), settings ), "queueActorRouter" ); ClusterSingletonProxySettings proxySettings = ClusterSingletonProxySettings.create( system ).withRole( role ); system.actorOf( ClusterSingletonProxy.props( "/user/queueActorRouter", proxySettings ), "queueActorRouterProxy" ); }
Example #2
Source File: UniqueValuesServiceImpl.java From usergrid with Apache License 2.0 | 6 votes |
@Override public void produceRouter( ActorSystem system, String role ) { ClusterSingletonManagerSettings settings = ClusterSingletonManagerSettings.create( system ).withRole("io"); system.actorOf( ClusterSingletonManager.props( Props.create( GuiceActorProducer.class, UniqueValuesRouter.class ), PoisonPill.getInstance(), settings ), "uvRouter" ); ClusterSingletonProxySettings proxySettings = ClusterSingletonProxySettings.create( system ).withRole( role ); system.actorOf( ClusterSingletonProxy.props( "/user/uvRouter", proxySettings ), "uvProxy" ); subscribeToReservations( system ); }
Example #3
Source File: QueueSenderRouterProducer.java From usergrid with Apache License 2.0 | 6 votes |
@Override public void produceRouter(ActorSystem system, String role) { ClusterSingletonManagerSettings settings = ClusterSingletonManagerSettings.create( system ).withRole( "io" ); system.actorOf( ClusterSingletonManager.props( Props.create( GuiceActorProducer.class, QueueSenderRouter.class ), PoisonPill.getInstance(), settings ), "queueSenderRouter" ); ClusterSingletonProxySettings proxySettings = ClusterSingletonProxySettings.create( system ).withRole( role ); system.actorOf( ClusterSingletonProxy.props( "/user/queueSenderRouter", proxySettings ), "queueSenderRouterProxy" ); }
Example #4
Source File: QueueWriterRouterProducer.java From usergrid with Apache License 2.0 | 6 votes |
@Override public void produceRouter(ActorSystem system, String role) { ClusterSingletonManagerSettings settings = ClusterSingletonManagerSettings.create( system ).withRole( "io" ); system.actorOf( ClusterSingletonManager.props( Props.create( GuiceActorProducer.class, QueueWriterRouter.class ), PoisonPill.getInstance(), settings ), "queueWriterRouter" ); ClusterSingletonProxySettings proxySettings = ClusterSingletonProxySettings.create( system ).withRole( role ); system.actorOf( ClusterSingletonProxy.props( "/user/queueWriterRouter", proxySettings ), "queueWriterRouterProxy" ); }
Example #5
Source File: SshClientActor.java From java-11-examples with Apache License 2.0 | 6 votes |
@Override public void onReceive(Object message) throws Throwable { if (message instanceof ReceiveTimeout) { sshClientService.onSessionCreateTimeout(clientId); self().tell(PoisonPill.getInstance(), self()); } else if (message instanceof SessionCreateResponse) { SessionCreateResponse sessionCreateResponse = (SessionCreateResponse)message; LOG.info("looking for session actor: {}", sessionCreateResponse.getSessionActorAddress()); Future<ActorRef> actorRefFuture = context().system() .actorSelection(sessionCreateResponse.getSessionActorAddress()).resolveOne(Timeout.apply(2, TimeUnit.SECONDS)); sshSessionActor = Await.result(actorRefFuture, Duration.apply(2, TimeUnit.SECONDS)); sshClientService.onSessionCreateReply(sessionCreateResponse.getClientId(), sessionCreateResponse.getSessionId(), sshSessionActor, sessionCreateResponse.getSessionActorAddress()); } else if (message instanceof SessionDataResponse) { SessionDataResponse sessionDataResponse = (SessionDataResponse)message; sshClientService.onSessionDataReceived(clientId, sessionDataResponse); } else if (message instanceof SessionCloseResponse) { SessionCloseResponse sessionCloseResponse = (SessionCloseResponse)message; sshClientService.onCloseSessionResponse(clientId, sessionCloseResponse); self().tell(PoisonPill.getInstance(), self()); } else { LOG.info("onReceive: {}", message.getClass().getName()); } }
Example #6
Source File: ClusterUtil.java From ditto with Eclipse Public License 2.0 | 6 votes |
/** * Start a cluster singleton actor. * * @param system the actor system. * @param actorRefFactory where the cluster singleton should be created. * @param role role of this cluster member. * @param actorName name of the singleton actor. * @param props Props of the singleton actor. * @param supervisorStrategy the {@link SupervisorStrategy} for the singleton actor. * @return reference of the singleton actor. */ public static ActorRef startSingleton(final ActorSystem system, final ActorRefFactory actorRefFactory, final String role, final String actorName, final Props props, final SupervisorStrategy supervisorStrategy) { final ClusterSingletonManagerSettings settings = ClusterSingletonManagerSettings.create(system).withRole(role); final Props supervisorProps = ClusterSingletonSupervisorActor.props(props, supervisorStrategy); final Props singletonManagerProps = ClusterSingletonManager.props(supervisorProps, PoisonPill.getInstance(), settings); return actorRefFactory.actorOf(singletonManagerProps, actorName); }
Example #7
Source File: ClusterSingleton.java From ts-reaktive with MIT License | 6 votes |
/** * Starts and returns the an {@link ActorRef} to the {@link ClusterSingletonManager} (and backoff supervisor) * that manage this actor singleton. * * Note that you can't send this ActorRef messages that should go to your actor: use {@link StartProxy} for that. * * @param constructor Constructor to pass to Props in order to actually create the actor */ public ActorRef start(ActorSystem system, Supplier<T> constructor) { Config config = system.settings().config().getConfig("ts-reaktive.actors.singleton"); Props backoffSupervisorProps = BackoffSupervisor.props( Backoff.onStop( Props.create(type, () -> constructor.get()), "actor", FiniteDuration.create(config.getDuration("min-backoff", SECONDS), SECONDS), FiniteDuration.create(config.getDuration("max-backoff", SECONDS), SECONDS), 0.2 ).withSupervisorStrategy(new OneForOneStrategy( DeciderBuilder .matchAny(e -> { log.info("{}: Stopping and awaiting restart.", name, e); return stop(); }) .build() )) ); return system.actorOf( ClusterSingletonManager.props(backoffSupervisorProps, PoisonPill.getInstance(), ClusterSingletonManagerSettings.create(system) ), name); }
Example #8
Source File: Master.java From akka-tutorial with Apache License 2.0 | 5 votes |
protected void handle(RegistrationMessage message) { if (this.isEnded) { this.sender().tell(PoisonPill.getInstance(), this.self()); return; } this.context().watch(this.sender()); this.workers.add(this.sender()); this.log().info("Registered {}", this.sender()); this.largeMessageProxy.tell(new LargeMessageProxy.LargeMessage<>(this.data, this.sender()), this.self()); }
Example #9
Source File: ClusterUtil.java From ditto with Eclipse Public License 2.0 | 5 votes |
/** * Start a cluster singleton actor. * * @param system the actor system. * @param actorRefFactory where the cluster singleton should be created. * @param role role of this cluster member. * @param actorName name of the singleton actor. * @param props Props of the singleton actor. * @return reference of the singleton actor. */ public static ActorRef startSingleton(final ActorSystem system, final ActorRefFactory actorRefFactory, final String role, final String actorName, final Props props) { final ClusterSingletonManagerSettings settings = ClusterSingletonManagerSettings.create(system).withRole(role); final Props supervisorProps = ClusterSingletonSupervisorActor.props(props); final Props singletonManagerProps = ClusterSingletonManager.props(supervisorProps, PoisonPill.getInstance(), settings); return actorRefFactory.actorOf(singletonManagerProps, actorName); }
Example #10
Source File: Master.java From akka-tutorial with Apache License 2.0 | 5 votes |
protected void handle(Terminated message) { this.context().unwatch(message.getActor()); this.workers.remove(message.getActor()); if (this.workers.isEmpty()) this.self().tell(PoisonPill.getInstance(), this.self()); }
Example #11
Source File: ThingPersistenceActorTest.java From ditto with Eclipse Public License 2.0 | 5 votes |
@Test public void recoverThingCreated() { new TestKit(actorSystem) { { final Thing thing = createThingV2WithRandomId(); final ThingId thingId = getIdOrThrow(thing); final ActorRef underTest = createPersistenceActorFor(thing); final CreateThing createThing = CreateThing.of(thing, null, dittoHeadersV2); underTest.tell(createThing, getRef()); final CreateThingResponse createThingResponse = expectMsgClass(CreateThingResponse.class); assertThingInResponse(createThingResponse.getThingCreated().orElse(null), thing); // restart actor to recover thing state watch(underTest); underTest.tell(PoisonPill.getInstance(), getRef()); expectTerminated(underTest); final ActorRef underTestAfterRestart = Retry.untilSuccess(() -> createPersistenceActorFor(thing)); final RetrieveThing retrieveThing = RetrieveThing.of(thingId, dittoHeadersV2); Awaitility.await().atMost(10L, TimeUnit.SECONDS).untilAsserted(() -> { underTestAfterRestart.tell(retrieveThing, getRef()); final RetrieveThingResponse retrieveThingResponse = expectMsgClass(RetrieveThingResponse.class); final Thing thingAsPersisted = retrieveThingResponse.getThing(); assertThat(thingAsPersisted.getEntityId()).contains(getIdOrThrow(thing)); assertThat(thingAsPersisted.getAttributes()).isEqualTo(thing.getAttributes()); assertThat(thingAsPersisted.getFeatures()).isEqualTo(thing.getFeatures()); }); } }; }
Example #12
Source File: ThingPersistenceActorTest.java From ditto with Eclipse Public License 2.0 | 5 votes |
@Test public void recoverThingDeleted() { new TestKit(actorSystem) { { final Thing thing = createThingV2WithRandomId(); final ThingId thingId = getIdOrThrow(thing); ActorRef underTest = createPersistenceActorFor(thing); final CreateThing createThing = CreateThing.of(thing, null, dittoHeadersV2); underTest.tell(createThing, getRef()); final CreateThingResponse createThingResponse = expectMsgClass(CreateThingResponse.class); assertThingInResponse(createThingResponse.getThingCreated().orElse(null), thing); final DeleteThing deleteThing = DeleteThing.of(thingId, dittoHeadersV2); underTest.tell(deleteThing, getRef()); expectMsgEquals(DeleteThingResponse.of(thingId, dittoHeadersV2)); // restart actor to recover thing state watch(underTest); underTest.tell(PoisonPill.getInstance(), getRef()); expectTerminated(underTest); underTest = Retry.untilSuccess(() -> createPersistenceActorFor(thing)); final RetrieveThing retrieveThing = RetrieveThing.of(thingId, dittoHeadersV2); underTest.tell(retrieveThing, getRef()); // A deleted Thing cannot be retrieved anymore (or is not accessible during initiation on slow systems) expectMsgClass(ThingNotAccessibleException.class); } }; }
Example #13
Source File: ThingPersistenceActorTest.java From ditto with Eclipse Public License 2.0 | 5 votes |
@Test public void recoverAclModified() { new TestKit(actorSystem) { { final Thing thingV1 = createThingV1WithRandomId(); final ActorRef thingPersistenceActor = watch(createPersistenceActorFor(thingV1)); final CreateThing createThing = CreateThing.of(thingV1, null, dittoHeadersV1); thingPersistenceActor.tell(createThing, getRef()); final CreateThingResponse createThingResponse = expectMsgClass(CreateThingResponse.class); assertThingInResponse(createThingResponse.getThingCreated().orElse(null), thingV1); final AccessControlList acl = ThingsModelFactory.newAcl(newAclEntry(AUTHORIZED_SUBJECT, PERMISSIONS), newAclEntry(AUTHORIZATION_SUBJECT, PERMISSIONS)); final ModifyAcl modifyAcl = ModifyAcl.of(thingV1.getEntityId().orElse(null), acl, dittoHeadersV1); thingPersistenceActor.tell(modifyAcl, getRef()); expectMsgEquals(modifyAclResponse(thingV1.getEntityId().get(), acl, dittoHeadersV1, false)); // restart thingPersistenceActor.tell(PoisonPill.getInstance(), getRef()); expectTerminated(thingPersistenceActor); final ActorRef thingPersistenceActorRecovered = Retry.untilSuccess(() -> createPersistenceActorFor(thingV1)); final Thing thingWithUpdatedAcl = incrementThingRevision(thingV1).setAccessControlList(acl); final RetrieveThing retrieveThing = RetrieveThing.of(thingWithUpdatedAcl.getEntityId().orElse(null), dittoHeadersV1); Awaitility.await().atMost(10L, TimeUnit.SECONDS).untilAsserted(() -> { thingPersistenceActorRecovered.tell(retrieveThing, getRef()); expectMsgEquals(retrieveThingResponse(thingWithUpdatedAcl, thingWithUpdatedAcl.toJson(JsonSchemaVersion.V_1), dittoHeadersV1)); assertThat(getLastSender()).isEqualTo(thingPersistenceActorRecovered); }); } }; }
Example #14
Source File: ThingPersistenceActorTest.java From ditto with Eclipse Public License 2.0 | 5 votes |
@Test public void recoverAclEntryModified() { new TestKit(actorSystem) { { final Thing thingV1 = createThingV1WithRandomId(); final ActorRef thingPersistenceActor = watch(createPersistenceActorFor(thingV1)); final CreateThing createThing = CreateThing.of(thingV1, null, dittoHeadersV1); thingPersistenceActor.tell(createThing, getRef()); final CreateThingResponse createThingResponse = expectMsgClass(CreateThingResponse.class); assertThingInResponse(createThingResponse.getThingCreated().orElse(null), thingV1); final AclEntry aclEntry = newAclEntry(AUTHORIZATION_SUBJECT, PERMISSIONS); final ModifyAclEntry modifyAclEntry = ModifyAclEntry.of(getIdOrThrow(thingV1), aclEntry, dittoHeadersV1); thingPersistenceActor.tell(modifyAclEntry, getRef()); expectMsgEquals(modifyAclEntryResponse(getIdOrThrow(thingV1), aclEntry, dittoHeadersV1, true)); // restart thingPersistenceActor.tell(PoisonPill.getInstance(), getRef()); expectTerminated(thingPersistenceActor); final ActorRef thingPersistenceActorRecovered = Retry.untilSuccess(() -> createPersistenceActorFor(thingV1)); final Thing thingWithUpdatedAclEntry = incrementThingRevision(thingV1).setAclEntry(aclEntry); final RetrieveThing retrieveThing = RetrieveThing.of(getIdOrThrow(thingWithUpdatedAclEntry), dittoHeadersV1); Awaitility.await().atMost(10L, TimeUnit.SECONDS).untilAsserted(() -> { thingPersistenceActorRecovered.tell(retrieveThing, getRef()); expectMsgEquals(retrieveThingResponse(thingWithUpdatedAclEntry, thingWithUpdatedAclEntry.toJson(JsonSchemaVersion.V_1), dittoHeadersV1)); assertThat(getLastSender()).isEqualTo(thingPersistenceActorRecovered); }); } }; }
Example #15
Source File: ThingPersistenceActorTest.java From ditto with Eclipse Public License 2.0 | 5 votes |
@Test public void ensureModifiedCorrectnessAfterRecovery() { new TestKit(actorSystem) { { final Thing thing = createThingV1WithRandomId(); final ActorRef thingPersistenceActor = watch(createPersistenceActorFor(thing)); final JsonFieldSelector fieldSelector = Thing.JsonFields.MODIFIED.getPointer().toFieldSelector(); // create thing final CreateThing createThing = CreateThing.of(thing, null, dittoHeadersV1); thingPersistenceActor.tell(createThing, getRef()); expectMsgClass(CreateThingResponse.class); final Instant createThingResponseTimestamp = Instant.now(); // restart thingPersistenceActor.tell(PoisonPill.getInstance(), getRef()); expectTerminated(thingPersistenceActor); final ActorRef thingPersistenceActorRecovered = Retry.untilSuccess(() -> createPersistenceActorFor(thing)); final RetrieveThing retrieveThing = RetrieveThing.getBuilder(getIdOrThrow(thing), dittoHeadersV1) .withSelectedFields(fieldSelector) .build(); Awaitility.await().atMost(10L, TimeUnit.SECONDS).untilAsserted(() -> { thingPersistenceActorRecovered.tell(retrieveThing, getRef()); final RetrieveThingResponse retrieveThingResponse = expectMsgClass(RetrieveThingResponse.class); assertThat(retrieveThingResponse.getThing()).isNotModifiedAfter(createThingResponseTimestamp); assertThat(getLastSender()).isEqualTo(thingPersistenceActorRecovered); }); } }; }
Example #16
Source File: TestConstants.java From ditto with Eclipse Public License 2.0 | 5 votes |
@Override public Receive createReceive() { return receiveBuilder() .match(ShardRegion.Passivate.class, passivate -> { getSender().tell(PoisonPill.getInstance(), getSelf()); getContext().stop(getSelf()); }) .matchAny(m -> child.forward(m, getContext())) .build(); }
Example #17
Source File: AkkaSource.java From bahir-flink with Apache License 2.0 | 5 votes |
@Override public void close() { LOG.info("Closing source"); if (receiverActorSystem != null) { receiverActor.tell(PoisonPill.getInstance(), ActorRef.noSender()); receiverActorSystem.terminate(); } }
Example #18
Source File: EventSchedulerRegistryImpl.java From flux with Apache License 2.0 | 5 votes |
@Override public void initialize() { ActorSystem actorSystem = actorSystemManager.retrieveActorSystem(); //create cluster singleton actor of {@link AkkaEventSchedulerService} Props actorProps = Props.create(AkkaEventSchedulerService.class, eventSchedulerService); ClusterSingletonManagerSettings settings = ClusterSingletonManagerSettings.create(actorSystem); actorSystem.actorOf(ClusterSingletonManager.props(actorProps, PoisonPill.getInstance(), settings), "eventSchedulerServiceActor"); }
Example #19
Source File: RedriverRegistryImpl.java From flux with Apache License 2.0 | 5 votes |
/** * Initialize the singleton actor wrapping redriverService. * * @see AkkaRedriverService */ @Override public void initialize() { ActorSystem actorSystem = actorSystemManager.retrieveActorSystem(); Props actorProps = Props.create(AkkaRedriverService.class, redriverService); ClusterSingletonManagerSettings settings = ClusterSingletonManagerSettings.create(actorSystem); actorSystem.actorOf(ClusterSingletonManager.props(actorProps, PoisonPill.getInstance(), settings), "redriverServiceActor"); }
Example #20
Source File: Messenger.java From tutorials with MIT License | 5 votes |
private void onSendMessage(JsonNode jsonNode) { RequestDTO requestDTO = MessageConverter.jsonNodeToRequest(jsonNode); String message = requestDTO.getMessage().toLowerCase(); if("stop".equals(message)) { MessageDTO messageDTO = createMessageDTO("1", "1", "Stop", "Stopping actor"); out.tell(MessageConverter.messageToJsonNode(messageDTO), getSelf()); self().tell(PoisonPill.getInstance(), getSelf()); } else { log.info("Actor received. {}", requestDTO); processMessage(requestDTO); } }
Example #21
Source File: AkkaSource.java From flink-learning with Apache License 2.0 | 5 votes |
@Override public void close() { LOG.info("Closing source"); if (receiverActorSystem != null) { receiverActor.tell(PoisonPill.getInstance(), ActorRef.noSender()); receiverActorSystem.terminate(); } }
Example #22
Source File: Master.java From akka-tutorial with Apache License 2.0 | 5 votes |
private void stopSelfAndListener() { // Tell the listener to stop this.listener.tell(new ShutdownMessage(), this.getSelf()); // Stop self and all child actors by sending a poison pill this.getSelf().tell(PoisonPill.getInstance(), this.getSelf()); }
Example #23
Source File: Master.java From akka-tutorial with Apache License 2.0 | 5 votes |
protected void handle(EndMessage message) { this.isEnded = true; for (ActorRef worker : this.workers) worker.tell(PoisonPill.getInstance(), this.self()); if (this.workers.isEmpty()) this.self().tell(PoisonPill.getInstance(), this.self()); }
Example #24
Source File: Master.java From akka-tutorial with Apache License 2.0 | 5 votes |
@Override public void postStop() throws Exception { super.postStop(); // If the master has stopped, it can also stop the listener this.listener.tell(PoisonPill.getInstance(), this.getSelf()); // Log the stop event this.log().info("Stopped {}.", this.getSelf()); }
Example #25
Source File: Shepherd.java From akka-tutorial with Apache License 2.0 | 5 votes |
@Override public void postStop() throws Exception { super.postStop(); // Stop all slaves that connected to this Shepherd for (ActorRef slave : this.slaves) slave.tell(PoisonPill.getInstance(), this.getSelf()); // Log the stop event this.log().info("Stopped {}.", this.getSelf()); }
Example #26
Source File: Shepherd.java From akka-tutorial with Apache License 2.0 | 5 votes |
private void handle(ShutdownMessage message) { // Shutdown all slaves that connected to this Shepherd for (ActorRef slave : this.slaves) slave.tell(new ShutdownMessage(), this.getSelf()); // Stop accepting new slaves (to do so, the actor can simply stop itself) this.getSelf().tell(PoisonPill.getInstance(), this.getSelf()); }
Example #27
Source File: Slave.java From akka-tutorial with Apache License 2.0 | 5 votes |
private void handle(ShutdownMessage message) { // Log remote shutdown message this.log().info("Was asked to stop."); // Stop self by sending a poison pill this.getSelf().tell(PoisonPill.getInstance(), this.getSelf()); }
Example #28
Source File: Calculator.java From akka-tutorial with Apache License 2.0 | 5 votes |
private static void kill(final ActorRef listener, final ActorRef master, final ActorRef shepherd) { // End the listener listener.tell(PoisonPill.getInstance(), ActorRef.noSender()); // End the master master.tell(PoisonPill.getInstance(), ActorRef.noSender()); // End the shepherd shepherd.tell(PoisonPill.getInstance(), ActorRef.noSender()); }
Example #29
Source File: Master.java From akka-tutorial with Apache License 2.0 | 5 votes |
protected void terminate() { this.reader.tell(PoisonPill.getInstance(), ActorRef.noSender()); this.collector.tell(PoisonPill.getInstance(), ActorRef.noSender()); for (ActorRef worker : this.workers) { this.context().unwatch(worker); worker.tell(PoisonPill.getInstance(), ActorRef.noSender()); } this.self().tell(PoisonPill.getInstance(), ActorRef.noSender()); long executionTime = System.currentTimeMillis() - this.startTime; this.log().info("Algorithm finished in {} ms", executionTime); }
Example #30
Source File: SshSessionActor.java From java-11-examples with Apache License 2.0 | 5 votes |
@Override public void onReceive(Object message) throws Throwable { if (message instanceof SessionDataRequest) { SessionDataRequest sessionDataRequest = (SessionDataRequest) message; sshSession.sendData(sessionDataRequest.getData()); String dataOut = sshClientSessionListener.awaitData(); SessionDataResponse sessionDataResponse = new SessionDataResponse(dataOut); sender().tell(sessionDataResponse, self()); } else if (message instanceof SessionPingMessage) { String memberAddress = Cluster.get(context().system()).selfAddress().toString(); context().sender().tell(new SessionPongMessage(memberAddress, sshSession.getId()), self()); } else if (message instanceof SessionCloseRequest) { SessionCloseRequest sessionCloseRequest = (SessionCloseRequest)message; sshSession.close(); SessionCloseResponse sessionCloseResponse = new SessionCloseResponse(sshSession.getId(), sessionCloseRequest.getClientId(), clientActorAddress); sender().tell(sessionCloseResponse, null); self().tell(PoisonPill.getInstance(), self()); } else { LOG.info("onReceive: {}", message.getClass().getName()); context().sender().tell(new SessionError(clientId,"unsupported message"), self()); } }