Class: EventAggregator::Message

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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(message_type, data, async = true, consisten_data = true)
	raise "Illegal Message Type" if message_type == nil
	
	@message_type = message_type
	@data = data
	@async = async
	@consisten_data = consisten_data
end

Instance Attribute Details

#asyncObject

Returns the value of attribute async.



18
19
20
# File 'lib/event_aggregator/message.rb', line 18

def async
  @async
end

#consisten_dataObject

Returns the value of attribute consisten_data.



18
19
20
# File 'lib/event_aggregator/message.rb', line 18

def consisten_data
  @consisten_data
end

#dataObject

Returns the value of attribute data.



18
19
20
# File 'lib/event_aggregator/message.rb', line 18

def data
  @data
end

#message_typeObject

Returns the value of attribute message_type.



18
19
20
# File 'lib/event_aggregator/message.rb', line 18

def message_type
  @message_type
end

Instance Method Details

#publishObject

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.message_publish( self )
end

#requestObject

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.message_request( self )
end