Class: Ap4r::Dispatchers::Base
Overview
A base class for dispathcer classes associated with each dispatch_mode
. Responsibilities of subclasses are to implement following methods, only invoke
is mandatory and others are optional (no operations by default).
-
modify_message
to preprocess a message, e.g. rewirte URL or discard message. -
invoke
to execute main logic, e.g. HTTP POST call. mandatory -
validate_response
to judge whetherinvoke
finished successfully. -
response
to return the result ofinvoke
process.
Class Method Summary collapse
-
.dispatch_mode(mode_symbol) ⇒ Object
Difine a constant
DISPATCH_MODE
to value ‘mode_symbol’ and add self to a Converters list.
Instance Method Summary collapse
-
#call ⇒ Object
Entry facade for each message processing.
-
#initialize(message, conf) ⇒ Base
constructor
Takes *
message
: from a queue *conf
: configuration from dispatchers section – TODO: Subclass should haveconf
instead of instance? 2007/06/06 by shino. -
#invoke ⇒ Object
Main logic of message processing.
-
#modify_message ⇒ Object
Modifies message.
-
#response ⇒ Object
Returns response.
- #validate_response ⇒ Object
Constructor Details
#initialize(message, conf) ⇒ Base
Takes
-
message
: from a queue -
conf
: configuration from dispatchers section
– TODO: Subclass should have conf
instead of instance? 2007/06/06 by shino
157 158 159 160 |
# File 'lib/ap4r/dispatcher.rb', line 157 def initialize(, conf) @message = @conf = conf end |
Class Method Details
.dispatch_mode(mode_symbol) ⇒ Object
Difine a constant DISPATCH_MODE
to value ‘mode_symbol’ and add self to a Converters list.
147 148 149 150 |
# File 'lib/ap4r/dispatcher.rb', line 147 def self.dispatch_mode(mode_symbol) self.const_set(:DISPATCH_MODE, mode_symbol) ::Ap4r::Dispatchers.register_dispatcher_class(mode_symbol, self) end |
Instance Method Details
#call ⇒ Object
Entry facade for each message processing. Modifies, invokes (maybe remote), validates, and responds.
164 165 166 167 168 169 170 171 |
# File 'lib/ap4r/dispatcher.rb', line 164 def call # TODO: rename to more appropriate one 2007/05/10 by shino self. logger.debug{"Ap4r::Dispatcher after modification\n#{@message.to_yaml}"} self.invoke self.validate_response self.response end |
#invoke ⇒ Object
Main logic of message processing. Maybe calls remote, e.g. HTTP request.
183 184 185 186 |
# File 'lib/ap4r/dispatcher.rb', line 183 def invoke # TODO: rename to more appropriate one 2007/05/10 by shino raise 'must be implemented in subclasses' end |
#modify_message ⇒ Object
Modifies message. Now only URL modification is implemented.
175 176 177 178 179 |
# File 'lib/ap4r/dispatcher.rb', line 175 def modification_rules = @conf["modify_rules"] return unless modification_rules modify_url(modification_rules) end |
#response ⇒ Object
Returns response. The return value is also the return value of call
method. By default impl, the instance variable @response
is used.
195 196 197 |
# File 'lib/ap4r/dispatcher.rb', line 195 def response @response end |
#validate_response ⇒ Object
188 189 190 |
# File 'lib/ap4r/dispatcher.rb', line 188 def validate_response # nop end |