Class: ModernTimes::JMS::PublishHandle::WorkerResponse
- Inherits:
-
Object
- Object
- ModernTimes::JMS::PublishHandle::WorkerResponse
- Defined in:
- lib/modern_times/jms/publish_handle.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#start ⇒ Object
readonly
Returns the value of attribute start.
Instance Method Summary collapse
- #done? ⇒ Boolean
-
#initialize(start) ⇒ WorkerResponse
constructor
A new instance of WorkerResponse.
- #make_exception_call(name, e) ⇒ Object
- #make_message_call(name, obj) ⇒ Object
- #make_timeout_calls ⇒ Object
-
#msec_delta ⇒ Object
Msecs since publish.
- #on_message(*names, &block) ⇒ Object
- #on_remote_exception(*names, &block) ⇒ Object
- #on_timeout(*names, &block) ⇒ Object
Constructor Details
#initialize(start) ⇒ WorkerResponse
Returns a new instance of WorkerResponse.
95 96 97 98 99 100 101 102 103 |
# File 'lib/modern_times/jms/publish_handle.rb', line 95 def initialize(start) @start = start @message_hash = {} @timeout_hash = {} @exception_hash = {} @default_timeout_block = nil @default_exception_block = nil @done_array = [] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
93 94 95 |
# File 'lib/modern_times/jms/publish_handle.rb', line 93 def name @name end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
93 94 95 |
# File 'lib/modern_times/jms/publish_handle.rb', line 93 def start @start end |
Instance Method Details
#done? ⇒ Boolean
140 141 142 |
# File 'lib/modern_times/jms/publish_handle.rb', line 140 def done? (@message_hash.keys - @done_array).empty? end |
#make_exception_call(name, e) ⇒ Object
154 155 156 157 158 159 160 161 162 163 |
# File 'lib/modern_times/jms/publish_handle.rb', line 154 def make_exception_call(name, e) @name = name block = @exception_hash[name] || @default_exception_block if block block.call(e) @done_array << name else raise e end end |
#make_message_call(name, obj) ⇒ Object
132 133 134 135 136 137 138 |
# File 'lib/modern_times/jms/publish_handle.rb', line 132 def (name, obj) # Give the client access to the name @name = name block = @message_hash[name] block.call(obj) if block @done_array << name end |
#make_timeout_calls ⇒ Object
144 145 146 147 148 149 150 151 152 |
# File 'lib/modern_times/jms/publish_handle.rb', line 144 def make_timeout_calls @timeouts = @message_hash.keys - @done_array @timeouts.each do |name| # Give the client access to the name @name = name block = @timeout_hash[name] || @default_timeout_block block.call if block end end |
#msec_delta ⇒ Object
Msecs since publish
106 107 108 |
# File 'lib/modern_times/jms/publish_handle.rb', line 106 def msec_delta (Time.now - @start) * 1000 end |
#on_message(*names, &block) ⇒ Object
110 111 112 113 |
# File 'lib/modern_times/jms/publish_handle.rb', line 110 def (*names, &block) raise 'Must explicitly define all message handlers so we know that we\'re done' if names.empty? names.each {|name| @message_hash[name] = block} end |
#on_remote_exception(*names, &block) ⇒ Object
123 124 125 126 127 128 129 130 |
# File 'lib/modern_times/jms/publish_handle.rb', line 123 def on_remote_exception(*names, &block) if names.empty? @default_exception_block = block else names.each {|name| @exception_hash[name] = block} end @remote_exception_block = block end |
#on_timeout(*names, &block) ⇒ Object
115 116 117 118 119 120 121 |
# File 'lib/modern_times/jms/publish_handle.rb', line 115 def on_timeout(*names, &block) if names.empty? @default_timeout_block = block else names.each {|name| @timeout_hash[name] = block} end end |