Class: Tochtli::BaseClient::SyncMessageHandler
- Inherits:
-
AbstractMessageHandler
- Object
- AbstractMessageHandler
- Tochtli::BaseClient::SyncMessageHandler
- Includes:
- MonitorMixin
- Defined in:
- lib/tochtli/base_client.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#reply ⇒ Object
readonly
Returns the value of attribute reply.
Instance Method Summary collapse
- #call(reply) ⇒ Object
- #handled? ⇒ Boolean
-
#initialize ⇒ SyncMessageHandler
constructor
A new instance of SyncMessageHandler.
- #on_error(error_message) ⇒ Object
- #on_timeout(original_message = nil) ⇒ Object
- #raise_error ⇒ Object
- #wait(timeout) ⇒ Object
- #wait!(timeout) ⇒ Object
Methods inherited from AbstractMessageHandler
Constructor Details
#initialize ⇒ SyncMessageHandler
Returns a new instance of SyncMessageHandler.
84 85 86 87 |
# File 'lib/tochtli/base_client.rb', line 84 def initialize super # initialize monitor @cv = new_cond end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
82 83 84 |
# File 'lib/tochtli/base_client.rb', line 82 def error @error end |
#reply ⇒ Object (readonly)
Returns the value of attribute reply.
82 83 84 |
# File 'lib/tochtli/base_client.rb', line 82 def reply @reply end |
Instance Method Details
#call(reply) ⇒ Object
120 121 122 123 124 125 |
# File 'lib/tochtli/base_client.rb', line 120 def call(reply) synchronize do @reply = reply @cv.signal end end |
#handled? ⇒ Boolean
102 103 104 |
# File 'lib/tochtli/base_client.rb', line 102 def handled? @reply || @error end |
#on_error(error_message) ⇒ Object
113 114 115 116 117 118 |
# File 'lib/tochtli/base_client.rb', line 113 def on_error() synchronize do @error = reconstruct_exception() @cv.signal end end |
#on_timeout(original_message = nil) ⇒ Object
106 107 108 109 110 111 |
# File 'lib/tochtli/base_client.rb', line 106 def on_timeout(=nil) synchronize do @error = Timeout::Error.new( ? "Unable to send message: #{.inspect}" : "Service is not responding") @cv.signal end end |
#raise_error ⇒ Object
127 128 129 130 |
# File 'lib/tochtli/base_client.rb', line 127 def raise_error error = self.error || InternalServiceError.new("Unknwon", "Unknown Error") raise error end |
#wait(timeout) ⇒ Object
89 90 91 92 93 94 |
# File 'lib/tochtli/base_client.rb', line 89 def wait(timeout) synchronize do @cv.wait(timeout) unless handled? end on_timeout unless handled? end |
#wait!(timeout) ⇒ Object
96 97 98 99 100 |
# File 'lib/tochtli/base_client.rb', line 96 def wait!(timeout) wait(timeout) raise_error unless @reply @reply end |