Class: EventAggregator::Message
- Inherits:
-
Object
- Object
- EventAggregator::Message
- Defined in:
- lib/event_aggregator/message.rb
Overview
Public: The Message class is used as a distribution object for the EventAggregator::Aggregator to send messages to EventAggregator::Listener objects
Examples
EventAggregator::Message.new(“foo”, “data”).publish EventAggregator::Message.new(“foo”, “data”, true, false).publish #equivalent to the first example EventAggregator::Message.new(“foo2”, 7843).publish #Data can be anything #Data can be anything EventAggregator::Message.new(“foo2”, lambda[“”, “bA”, “bw”, “bA”, “IA”, “bg”, “YQ”, “aA”, “cA”, “ZQ”, “dA”, “w”].map{|e| e && e == “w” ?‘U’+e : ‘n’+e.reverse.join(‘==\’).unpack((‘m’+‘x’*4)*11).join}).publish #Non-asynchroneus distribution and consistend data object for all listeners. EventAggregator::Message.new(“foo3”, SomeClass.new(), false, true).publish
Instance Attribute Summary collapse
-
#async ⇒ Object
Returns the value of attribute async.
-
#consisten_data ⇒ Object
Returns the value of attribute consisten_data.
-
#data ⇒ Object
Returns the value of attribute data.
-
#message_type ⇒ Object
Returns the value of attribute message_type.
Instance Method Summary collapse
-
#initialize(message_type, data, async = true, consisten_data = true) ⇒ Message
constructor
Public: Initialize the Message.
-
#publish ⇒ Object
Public: Will publish the message to all instances of EventAggregator::Listener that is registered for message types equal to this.message_type.
-
#request ⇒ Object
Public: Will provide data if a producer of this message_type is present.
Constructor Details
#initialize(message_type, data, async = true, consisten_data = true) ⇒ Message
Public: Initialize the Message
message_type - The type of the message which determine which EventAggregator::Listener objects will recieve the message upon publish data - The data that will be passed to the EventAggregator::Listener objects async = true - Indicates if message should be published async or not consisten_data = true - Indicates if EventAggregator::Listener objects should recieve a consistent object reference or clones.
35 36 37 38 39 40 41 42 |
# File 'lib/event_aggregator/message.rb', line 35 def initialize(, data, async = true, consisten_data = true) raise "Illegal Message Type" if == nil @message_type = @data = data @async = async @consisten_data = consisten_data end |
Instance Attribute Details
#async ⇒ Object
Returns the value of attribute async.
18 19 20 |
# File 'lib/event_aggregator/message.rb', line 18 def async @async end |
#consisten_data ⇒ Object
Returns the value of attribute consisten_data.
18 19 20 |
# File 'lib/event_aggregator/message.rb', line 18 def consisten_data @consisten_data end |
#data ⇒ Object
Returns the value of attribute data.
18 19 20 |
# File 'lib/event_aggregator/message.rb', line 18 def data @data end |
#message_type ⇒ Object
Returns the value of attribute message_type.
18 19 20 |
# File 'lib/event_aggregator/message.rb', line 18 def @message_type end |
Instance Method Details
#publish ⇒ Object
Public: Will publish the message to all instances of EventAggregator::Listener that is registered for message types equal to this.message_type
47 48 49 |
# File 'lib/event_aggregator/message.rb', line 47 def publish Aggregator.( self ) end |
#request ⇒ Object
Public: Will provide data if a producer of this message_type is present.
Returns Requested data if a producer is present. Nil otherwise.
54 55 56 |
# File 'lib/event_aggregator/message.rb', line 54 def request Aggregator.( self ) end |