net.liftmodules.messagebus

MessageBus

object MessageBus extends LiftActor

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

Linear Supertypes
LiftActor, ForwardableActor[Any, Any], GenericActor[Any], TypedActor[Any, Any], SpecializedLiftActor[Any], SimpleActor[Any], AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. MessageBus
  2. LiftActor
  3. ForwardableActor
  4. GenericActor
  5. TypedActor
  6. SpecializedLiftActor
  7. SimpleActor
  8. AnyRef
  9. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Value Members

  1. def !(msg: Any): Unit

    Definition Classes
    SpecializedLiftActor → SimpleActor
  2. def !!(msg: Any): Box[Any]

    Definition Classes
    LiftActor → TypedActor
  3. def !!(msg: Any, timeout: Long): Box[Any]

    Definition Classes
    LiftActor → TypedActor
  4. def !<(msg: Any): LAFuture[Any]

    Definition Classes
    LiftActor
  5. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  6. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  7. def !?(timeout: Long, message: Any): Box[Any]

    Definition Classes
    LiftActor → TypedActor
  8. def !?(msg: Any): Any

    Definition Classes
    LiftActor → TypedActor
  9. final def ##(): Int

    Definition Classes
    AnyRef → Any
  10. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  11. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  12. def around[R](f: ⇒ R): R

    Attributes
    protected
    Definition Classes
    SpecializedLiftActor
  13. def aroundLoans: List[CommonLoanWrapper]

    Attributes
    protected
    Definition Classes
    SpecializedLiftActor
  14. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  15. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  16. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  17. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  18. def exceptionHandler: PartialFunction[Throwable, Unit]

    Attributes
    protected
    Definition Classes
    SpecializedLiftActor
  19. def execTranslate(f: (Any) ⇒ Unit)(v: Any): Unit

    Attributes
    protected
    Definition Classes
    LiftActor → SpecializedLiftActor
  20. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  21. final def forwardMessageTo(msg: Any, forwardTo: TypedActor[Any, Any]): Unit

    Attributes
    protected
    Definition Classes
    LiftActor → ForwardableActor
  22. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  23. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  24. def highPriorityReceive: Box[PartialFunction[Any, Unit]]

    Attributes
    protected
    Definition Classes
    SpecializedLiftActor
  25. def insertMsgAtHeadOfQueue_!(msg: Any): Unit

    Attributes
    protected
    Definition Classes
    SpecializedLiftActor
  26. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  27. def messageHandler: PartialFunction[Any, Unit]

    Definition Classes
    MessageBus → SpecializedLiftActor
  28. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  29. final def notify(): Unit

    Definition Classes
    AnyRef
  30. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  31. def reply(v: Any): Unit

    Attributes
    protected
    Definition Classes
    LiftActor → ForwardableActor
  32. def send(msg: Any): Unit

    Definition Classes
    SpecializedLiftActor
  33. def sendAndGetFuture(msg: Any): LAFuture[Any]

    Definition Classes
    LiftActor
  34. def sendAndGetReply(timeout: Long, msg: Any): Any

    Definition Classes
    LiftActor
  35. def sendAndGetReply(msg: Any): Any

    Definition Classes
    LiftActor
  36. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  37. def testTranslate(f: (Any) ⇒ Boolean)(v: Any): Boolean

    Attributes
    protected
    Definition Classes
    LiftActor → SpecializedLiftActor
  38. def toString(): String

    Definition Classes
    AnyRef → Any
  39. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  40. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  41. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from LiftActor

Inherited from ForwardableActor[Any, Any]

Inherited from GenericActor[Any]

Inherited from TypedActor[Any, Any]

Inherited from SpecializedLiftActor[Any]

Inherited from SimpleActor[Any]

Inherited from AnyRef

Inherited from Any

Ungrouped