akka.persistence
Class Channel

java.lang.Object
  extended by akka.persistence.Channel
All Implemented Interfaces:
Actor

public final class Channel
extends java.lang.Object
implements Actor

A channel is used by Processors (and Views) 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.

See Also:
Deliver

Nested Class Summary
 
Nested classes/interfaces inherited from interface akka.actor.Actor
Actor.emptyBehavior$
 
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, noSender, postRestart, postStop, preRestart, preStart, self, sender, supervisorStrategy, unhandled
 

Method Detail

props

public static Props props()
Returns a channel actor configuration object for creating a Channel with a generated id and default ChannelSettings.


props

public static Props props(ChannelSettings channelSettings)
Returns a channel actor configuration object for creating a Channel with a generated id and specified channelSettings.

Parameters:
channelSettings - channel configuration object.

props

public static Props props(java.lang.String channelId)
Returns a channel actor configuration object for creating a Channel with the specified id and default ChannelSettings.

Parameters:
channelId - channel id.

props

public 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.

Parameters:
channelId - channel id.
channelSettings - channel configuration object.

receive

public scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> receive()
Description copied from interface: Actor
This defines the initial actor behavior, it must return a partial function with the actor logic.

Specified by:
receive in interface Actor