|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectakka.persistence.Channel
public final class Channel
A channel is used by Processor
s (and View
s) for sending Persistent
messages to destinations.
The main responsibility of a channel is to prevent redundant delivery of replayed messages to destinations
when a processor is recovered.
A channel is instructed to deliver a persistent message to a destination with the Deliver
command. A
destination is provided as ActorPath
and messages are sent via that path's ActorSelection
.
class ForwardExample extends Processor {
val destination = context.actorOf(Props[MyDestination])
val channel = context.actorOf(Channel.props(), "myChannel")
def receive = {
case m @ Persistent(payload, _) =>
// forward modified message to destination
channel forward Deliver(m.withPayload(s"fw: ${payload}"), destination.path)
}
}
To reply to the sender of a persistent message, the sender
reference should be used as channel
destination.
class ReplyExample extends Processor {
val channel = context.actorOf(Channel.props(), "myChannel")
def receive = {
case m @ Persistent(payload, _) =>
// reply modified message to sender
channel ! Deliver(m.withPayload(s"re: ${payload}"), sender.path)
}
}
Redundant delivery of messages to destinations is only prevented if the receipt of these messages
is explicitly confirmed. Therefore, persistent messages that are delivered via a channel are of type
ConfirmablePersistent
. Their receipt can be confirmed by a destination by calling the confirm()
method on these messages.
class MyDestination extends Actor {
def receive = {
case cp @ ConfirmablePersistent(payload, sequenceNr, redeliveries) => cp.confirm()
}
}
If a destination does not confirm the receipt of a ConfirmablePersistent
message, it will be redelivered
by the channel according to the parameters in ChannelSettings
. Redelivered messages have a redeliveries
value greater than zero.
If the maximum number of redeliveries is reached for certain messages, they are removed from the channel and
a redeliverFailureListener
(if specified, see ChannelSettings
) is notified about these messages with a
RedeliverFailure
message. Besides other application-specific tasks, this listener can restart the sending
processor to enforce a redelivery of these messages or confirm these messages to prevent further redeliveries.
Deliver
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface akka.actor.Actor |
---|
Actor.emptyBehavior$ |
Constructor Summary | |
---|---|
Channel(scala.Option<java.lang.String> _channelId,
ChannelSettings channelSettings)
|
Method Summary | |
---|---|
static Props |
props()
Returns a channel actor configuration object for creating a Channel with a
generated id and default ChannelSettings . |
static Props |
props(ChannelSettings channelSettings)
Returns a channel actor configuration object for creating a Channel with a
generated id and specified channelSettings . |
static Props |
props(java.lang.String channelId)
Returns a channel actor configuration object for creating a Channel with the
specified id and default ChannelSettings . |
static Props |
props(java.lang.String channelId,
ChannelSettings channelSettings)
Returns a channel actor configuration object for creating a Channel with the
specified id and specified channelSettings . |
scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> |
receive()
This defines the initial actor behavior, it must return a partial function with the actor logic. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface akka.actor.Actor |
---|
aroundPostRestart, aroundPostStop, aroundPreRestart, aroundPreStart, aroundReceive, context, postRestart, postStop, preRestart, preStart, self, sender, supervisorStrategy, unhandled |
Constructor Detail |
---|
public Channel(scala.Option<java.lang.String> _channelId, ChannelSettings channelSettings)
Method Detail |
---|
public static Props props()
Channel
with a
generated id and default ChannelSettings
.
public static Props props(ChannelSettings channelSettings)
Channel
with a
generated id and specified channelSettings
.
channelSettings
- channel configuration object.
public static Props props(java.lang.String channelId)
Channel
with the
specified id and default ChannelSettings
.
channelId
- channel id.
public static Props props(java.lang.String channelId, ChannelSettings channelSettings)
Channel
with the
specified id and specified channelSettings
.
channelId
- channel id.channelSettings
- channel configuration object.
public scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> receive()
Actor
receive
in interface Actor
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |