Package

net.liftmodules

messagebus

Permalink

package messagebus

Visibility
  1. Public
  2. All

Type Members

  1. case class AddListener(listener: LiftActor) extends Product with Serializable

    Permalink
  2. case class For(topic: Topic, payload: Any) extends MessageBusMessage with Product with Serializable

    Permalink

    The payload of For message will be delivered by MessageBus to all LiftActors that subscribed to the given Topic.

    The payload of For message will be delivered by MessageBus to all LiftActors that subscribed to the given Topic. For example:

    case object WombatPhotosTopic extends Topic {
      val name = "wombat-photos"
    }
    
    MessageBus ! For(WombatPhotosTopic, WombatPhoto('wombat.jpg'))

    The WombatPhoto('wombat.jpg') message will be delivered to all LiftActors that previously subscribed to WombatPhotosTopic sending Subscribe to MessageBus.

    Actors should listen for messages delivered from MessageBus as an effect of For sent by sender in the same way as for any other message types (e.g. implementing messageHandler method or low/medium/highPriority method).

    topic

    reference to Topic to which the message should be sent

    payload

    message that should be sent to Topic

  3. case class ForAll[T <: Topic](payload: Any)(implicit manifest: Manifest[T]) extends MessageBusMessage with Product with Serializable

    Permalink

    The payload of ForAll message will be delivered by MessageBus to all LiftActors that subscribed to the given Topic type.

    The payload of ForAll message will be delivered by MessageBus to all LiftActors that subscribed to the given Topic type. For example:

    case class WombatPhotosTopic(wombatId: String) extends Topic {
      val name = "wombat-topic-" + wombatId
    }
    
    case class BeaverPhotosTopic(beaverId: String) extends Topic {
      val name = "beaver-topic-" + beaverId
    }
    
    MessageBus ! Subscribe(listener1, WombatPhotosTopic("1"))
    MessageBus ! Subscribe(listener2, WombatPhotosTopic("2"))
    MessageBus ! Subscribe(listener3, BeaverPhotosTopic("1"))
    
    MessageBus ! ForAll[WombatPhotosTopic](WombatPhoto('wombat.jpg'))

    the WombatPhoto('wombat.jpg') message will be sent to listener1 and listener2 because they are both subscribed to topic of type WombatPhotosTopic. listener3 will not receive this message because it's not subscribed to topic of type WombatPhotosTopic'.

    T

    the type of Topic. Message will be sent to all Topics of this type.

    payload

    message that should be sent to Topic

  4. sealed trait MessageBusMessage extends AnyRef

    Permalink
  5. class PublisherActor extends LiftActor

    Permalink

    PublisherActor is the component that is responsible for sending messages to subscribed listeners.

    PublisherActor is the component that is responsible for sending messages to subscribed listeners. It is an internal actor used by MessageBus and created automatically when a new Topic instance is registered in MessageBus.

  6. case class RemoveListener(listener: LiftActor) extends Product with Serializable

    Permalink
  7. case class Subscribe(actor: LiftActor, topic: Topic) extends MessageBusMessage with Product with Serializable

    Permalink

    Subscribe is a message that should be sent to MessageBus when LiftActor wants to subscribe to the given Topic.

    Subscribe is a message that should be sent to MessageBus when LiftActor wants to subscribe to the given Topic. For example:

    MessageBus ! Subscribe(this, topic)

    For CometActors this will usually take place in the localSetup method.

    actor

    reference to LiftActor that wants to subscribe to topic

    topic

    reference to Topic to which the actor should be subscribed

  8. trait Topic extends AnyRef

    Permalink

    Topic instances can be perceived as a street advertising columns.

    Topic instances can be perceived as a street advertising columns. Components interested in some sort of messages will subscribe to appropriate Topic instance in MessageBus that controls message flow between message publishers and listeners.

    For example, we might have some components interested in receiving beaver photo updates and components interested in receiving wombat photo updates. For this situation, we would create two Topics:

    case object BeaverPhotosTopic extends Topic {
      val name = "beaver-photos"
    }
    
    case object WombatPhotosTopic extends Topic {
      val name = "wombat-photos"
    }

    All messages sent to BeaverPhotosTopic would be received only by components subscribed to BeaverPhotosTopic. All messages sent to WombatPhotosTopic would be received only by components subscribed to WombatPhotosTopic.

  9. case class Unsubscribe(actor: LiftActor, topic: Topic) extends MessageBusMessage with Product with Serializable

    Permalink

    Unsubscribe is a message that should be sent to MessageBus when LiftActor wants to unsubscribe from the given Topic.

    Unsubscribe is a message that should be sent to MessageBus when LiftActor wants to unsubscribe from the given Topic. For example:

    MessageBus ! Unsubscribe(this, topic)

    For CometActors this will usually take place in the localShutdown method.

    actor

    reference to LiftActor that wants to unsubscribe from topic

    topic

    reference to Topic from which the actor should be unsubscribed

Value Members

  1. object MessageBus extends LiftActor

    Permalink

    MessageBus allows to send messages between LiftActors even if they live in separate user sessions.

    MessageBus allows to send messages between LiftActors even if they live in separate user sessions. All LiftActors that subscribed to the given Topic will receive messages sent to this Topic.

    If you want your actor to subscribe to the given Topic, you need to send the Subscribe message:

    case class BeaverPhotosTopic(beaverId: String) extends Topic {
      val name = "beaver-photos-" + beaverId
    }
    
    val topic = BeaverPhotosTopic("1")
    MessageBus ! Subscribe(this, topic)

    from this point, all messages sent to this topic will be received by the actor.

    There are two ways to send a message to Topic: For and ForAll. The For class takes a Topic instance and sends a payload only to actors subscribed to this particular Topic. The ForAll class takes a Topic type and sends a payload to all actors subscribed to all Topics of the given type.

    Let's consider two listeners:

    MessageBus ! Subscribe(listener1, BeaverTopic("1"))
    MessageBus ! Subscribe(listener2, BeaverTopic("2"))

    If we send a message in the following way:

    MessageBus ! For(BeaverTopic("1"), message)

    only listener1 will receive it.

    However, if we send a message in the following way:

    MessageBus ! ForAll[BeaverTopic](message)

    Both listener1 and listener2 will receive it.

    LiftActor can unsubscribe from the given Topic by sending Unsubscribe message:

    MessageBus ! Unsubscribe(this, BeaverTopic("1"))

    In case of CometActors, the Subscribe/Unsubscribe actions should usually take place in localSetup and localShutdown methods.

    There are no limitations in a number of Topics to which a given LiftActor can be subscribed.

    Actors subscribed to Topics should listen for messages in the same way as they listen for any other message types (e.g. implementing messageHandler method or low/medium/highPriority method).

Ungrouped