Class: Isono::NodeModules::RpcChannel::RequestContext
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Isono::NodeModules::RpcChannel::RequestContext
- Defined in:
- lib/isono/node_modules/rpc_channel.rb
Defined Under Namespace
Modules: RequestSynchronize
Instance Attribute Summary collapse
-
#error_cb ⇒ Object
readonly
They are not to be appeared in @table so that won’t be inspect().
-
#progress_cb ⇒ Object
readonly
They are not to be appeared in @table so that won’t be inspect().
-
#success_cb ⇒ Object
readonly
They are not to be appeared in @table so that won’t be inspect().
-
#timer ⇒ Object
Returns the value of attribute timer.
Instance Method Summary collapse
- #elapsed_time ⇒ Object
- #hash ⇒ Object
-
#initialize(endpoint, command, args) ⇒ RequestContext
constructor
A new instance of RequestContext.
- #on_error(&blk) ⇒ Object
- #on_progress(&blk) ⇒ Object
- #on_success(&blk) ⇒ Object
- #process_event(ev, *args) ⇒ Object
- #request_hash ⇒ Object
- #state ⇒ Object
- #synchronize ⇒ Object
Constructor Details
#initialize(endpoint, command, args) ⇒ RequestContext
Returns a new instance of RequestContext.
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
# File 'lib/isono/node_modules/rpc_channel.rb', line 311 def initialize(endpoint, command, args) super({:request=>{ :endpoint=> endpoint, :command => command, :args => args }, :endpoint=> endpoint, :command => command, :ticket => Util.gen_id, :timeout_sec => -1.0, :oneshot => false, :sent_at => nil, :completed_at => nil, :complete_status => nil, }) @success_cb = nil @progress_cb = nil @error_cb = nil @timer = nil @stm = Statemachine.build { trans :init, :on_ready, :ready trans :ready, :on_sent, :waiting, proc { self.sent_at=Time.now # freeze request hash not to be modified after sending. self.request.freeze } trans :waiting, :on_received, :waiting trans :waiting, :on_error, :done, proc { self.completed_at=Time.now @timer.cancel if @timer self.complete_status = :fail } trans :waiting, :on_success, :done, proc { self.completed_at=Time.now @timer.cancel if @timer self.complete_status = :success } } @stm.context = self end |
Instance Attribute Details
#error_cb ⇒ Object (readonly)
They are not to be appeared in @table so that won’t be inspect().
308 309 310 |
# File 'lib/isono/node_modules/rpc_channel.rb', line 308 def error_cb @error_cb end |
#progress_cb ⇒ Object (readonly)
They are not to be appeared in @table so that won’t be inspect().
308 309 310 |
# File 'lib/isono/node_modules/rpc_channel.rb', line 308 def progress_cb @progress_cb end |
#success_cb ⇒ Object (readonly)
They are not to be appeared in @table so that won’t be inspect().
308 309 310 |
# File 'lib/isono/node_modules/rpc_channel.rb', line 308 def success_cb @success_cb end |
#timer ⇒ Object
Returns the value of attribute timer.
309 310 311 |
# File 'lib/isono/node_modules/rpc_channel.rb', line 309 def timer @timer end |
Instance Method Details
#elapsed_time ⇒ Object
362 363 364 |
# File 'lib/isono/node_modules/rpc_channel.rb', line 362 def elapsed_time self.completed_at.nil? ? nil : (self.completed_at - self.sent_at) end |
#hash ⇒ Object
366 367 368 369 370 |
# File 'lib/isono/node_modules/rpc_channel.rb', line 366 def hash # state, sent_at received_at are readonly values so they are # not pushed in @table. @table.dup.merge({:state=>self.state}) end |
#on_error(&blk) ⇒ Object
386 387 388 389 |
# File 'lib/isono/node_modules/rpc_channel.rb', line 386 def on_error(&blk) raise ArgumentError unless blk @error_cb = blk end |
#on_progress(&blk) ⇒ Object
381 382 383 384 |
# File 'lib/isono/node_modules/rpc_channel.rb', line 381 def on_progress(&blk) raise ArgumentError unless blk @progress_cb = blk end |
#on_success(&blk) ⇒ Object
376 377 378 379 |
# File 'lib/isono/node_modules/rpc_channel.rb', line 376 def on_success(&blk) raise ArgumentError unless blk @success_cb = blk end |
#process_event(ev, *args) ⇒ Object
358 359 360 |
# File 'lib/isono/node_modules/rpc_channel.rb', line 358 def process_event(ev, *args) @stm.process_event(ev, *args) end |
#request_hash ⇒ Object
372 373 374 |
# File 'lib/isono/node_modules/rpc_channel.rb', line 372 def request_hash request.merge({:oneshot=>oneshot}) end |
#state ⇒ Object
354 355 356 |
# File 'lib/isono/node_modules/rpc_channel.rb', line 354 def state @stm.state end |
#synchronize ⇒ Object
391 392 393 394 |
# File 'lib/isono/node_modules/rpc_channel.rb', line 391 def synchronize self.extend RequestSynchronize self end |