public interface ActorSubscriber extends Actor
Actor
to make it a
stream subscriber with full control of stream back pressure. It will receive
ActorSubscriberMessage.OnNext
, ActorSubscriberMessage.OnComplete
and ActorSubscriberMessage.OnError
messages from the stream. It can also receive other, non-stream messages, in
the same way as any actor.
Attach the actor as a Subscriber
to the stream with
Scala API ActorSubscriber#apply
, or Java API UntypedActorSubscriber.create(akka.actor.ActorRef)
or
Java API compatible with lambda expressions AbstractActorSubscriber.create(akka.actor.ActorRef)
.
Subclass must define the RequestStrategy
to control stream back pressure.
After each incoming message the ActorSubscriber
will automatically invoke
the RequestStrategy.requestDemand(int)
and propagate the returned demand to the stream.
The provided WatermarkRequestStrategy
is a good strategy if the actor
performs work itself.
The provided MaxInFlightRequestStrategy
is useful if messages are
queued internally or delegated to other actors.
You can also implement a custom RequestStrategy
or call request(long)
manually
together with ZeroRequestStrategy
or some other strategy. In that case
you must also call request(long)
when the actor is started or when it is ready, otherwise
it will not receive any elements.
Modifier and Type | Interface and Description |
---|---|
static class |
ActorSubscriber.OnSubscribe
INTERNAL API
|
static class |
ActorSubscriber.OnSubscribe$ |
Actor.emptyBehavior$, Actor.ignoringBehavior$
Modifier and Type | Method and Description |
---|---|
void |
aroundPostRestart(java.lang.Throwable reason)
INTERNAL API
|
void |
aroundPostStop()
INTERNAL API
|
void |
aroundPreRestart(java.lang.Throwable reason,
scala.Option<java.lang.Object> message)
INTERNAL API
|
void |
aroundPreStart()
INTERNAL API
|
void |
aroundReceive(scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> receive,
java.lang.Object msg)
INTERNAL API
|
void |
cancel()
Cancel upstream subscription.
|
boolean |
canceled() |
int |
longToIntMax(long n) |
int |
remainingRequested()
The number of stream elements that have already been requested from upstream
but not yet received.
|
void |
request(long elements)
Request a number of elements from upstream.
|
RequestStrategy |
requestStrategy() |
context, postRestart, postStop, preRestart, preStart, receive, self, sender, supervisorStrategy, unhandled
RequestStrategy requestStrategy()
boolean canceled()
void aroundReceive(scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> receive, java.lang.Object msg)
aroundReceive
in interface Actor
receive
- (undocumented)msg
- (undocumented)void aroundPreStart()
aroundPreStart
in interface Actor
void aroundPostRestart(java.lang.Throwable reason)
aroundPostRestart
in interface Actor
reason
- (undocumented)void aroundPreRestart(java.lang.Throwable reason, scala.Option<java.lang.Object> message)
aroundPreRestart
in interface Actor
reason
- (undocumented)message
- (undocumented)void aroundPostStop()
aroundPostStop
in interface Actor
void request(long elements)
elements
- (undocumented)void cancel()
The ActorSubscriber
will be stopped immediately after signaling cancellation.
In case the upstream subscription has not yet arrived the Actor will stay alive
until a subscription arrives, cancel it and then stop itself.
int remainingRequested()
int longToIntMax(long n)