added examples for Stream # actorRef operator. As part of #25468 (#26162)

This commit is contained in:
Seeta Ramayya 2019-01-02 17:08:35 +01:00 committed by Johan Andrén
parent 6cca1a0ee3
commit f8618b24b0
3 changed files with 60 additions and 1 deletions

View file

@ -13,6 +13,13 @@ import akka.stream.Materializer;
import akka.stream.javadsl.Source;
//#range-imports
//#actor-ref-imports
import akka.actor.ActorRef;
import akka.actor.Status.Success;
import akka.stream.OverflowStrategy;
import akka.stream.javadsl.Sink;
//#actor-ref-imports
import java.util.Arrays;
//#imports
@ -59,4 +66,22 @@ public class SourceDocExamples {
//#run-range
}
static void actorRef() {
//#actor-ref
final ActorSystem system = ActorSystem.create();
final Materializer materializer = ActorMaterializer.create(system);
int bufferSize = 100;
Source<Object, ActorRef> source = Source.actorRef(bufferSize, OverflowStrategy.dropHead());
ActorRef actorRef = source.to(Sink.foreach(System.out::println)).run(materializer);
actorRef.tell("hello", ActorRef.noSender());
actorRef.tell("hello", ActorRef.noSender());
// The stream completes successfully with the following message
actorRef.tell(new Success("completes stream"), ActorRef.noSender());
//#actor-ref
}
}