This commit is contained in:
parent
6cca1a0ee3
commit
f8618b24b0
3 changed files with 60 additions and 1 deletions
|
|
@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue