Class: MQRPC::Message
Constant Summary
collapse
- @@idseq =
0
- @@idlock =
Mutex.new
- @@knowntypes =
Hash.new
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from BindToHash
argument, header
Constructor Details
Returns a new instance of Message.
77
78
79
80
81
82
83
84
85
|
# File 'lib/mqrpc/message.rb', line 77
def initialize
@data = Hash.new
self.delayable = false
generate_id!
self.message_class = self.class.name
self.args = Hash.new
end
|
Instance Attribute Details
#data=(value) ⇒ Object
44
45
46
|
# File 'lib/mqrpc/message.rb', line 44
def data=(value)
@data = value
end
|
Class Method Details
.inherited(subclass) ⇒ Object
54
55
56
57
58
59
60
61
62
|
# File 'lib/mqrpc/message.rb', line 54
def self.inherited(subclass)
MQRPC::logger.debug "Message '#{subclass.name}' subclasses #{self.name}"
@@knowntypes[subclass.name] = subclass
if subclass.respond_to?(:class_initialize)
subclass.class_initialize
end
end
|
.new_from_data(data) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/mqrpc/message.rb', line 64
def self.new_from_data(data)
obj = nil
name = data["message_class"]
if @@knowntypes.has_key?(name)
obj = @@knowntypes[name].new
else
$stderr.puts "No known message class: #{name}, #{data.inspect}"
obj = Message.new
end
obj.data = data
return obj
end
|
Instance Method Details
#age ⇒ Object
95
96
97
|
# File 'lib/mqrpc/message.rb', line 95
def age
return Time.now.to_f - timestamp
end
|
#generate_id! ⇒ Object
87
88
89
90
91
92
93
|
# File 'lib/mqrpc/message.rb', line 87
def generate_id!
@@idlock.synchronize do
self.id = @@idseq
@@idseq += 1
end
end
|
#to_json(*args) ⇒ Object
99
100
101
|
# File 'lib/mqrpc/message.rb', line 99
def to_json(*args)
return @data.to_json(*args)
end
|