Class: Isono::NodeModules::RpcChannel::RequestContext
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Isono::NodeModules::RpcChannel::RequestContext
show all
- Defined in:
- lib/isono/node_modules/rpc_channel.rb
Defined Under Namespace
Modules: RequestSynchronize
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(endpoint, command, args) ⇒ RequestContext
Returns a new instance of RequestContext.
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
|
# File 'lib/isono/node_modules/rpc_channel.rb', line 345
def initialize(endpoint, command, args)
super({:request=>{
:endpoint=> endpoint,
:command => command,
:args => args
},
: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
@state = :init
end
|
Instance Attribute Details
#error_cb ⇒ Object
They are not to be appeared in @table so that won’t be inspect().
342
343
344
|
# File 'lib/isono/node_modules/rpc_channel.rb', line 342
def error_cb
@error_cb
end
|
#progress_cb ⇒ Object
They are not to be appeared in @table so that won’t be inspect().
342
343
344
|
# File 'lib/isono/node_modules/rpc_channel.rb', line 342
def progress_cb
@progress_cb
end
|
#state ⇒ Object
Returns the value of attribute state.
343
344
345
|
# File 'lib/isono/node_modules/rpc_channel.rb', line 343
def state
@state
end
|
#success_cb ⇒ Object
They are not to be appeared in @table so that won’t be inspect().
342
343
344
|
# File 'lib/isono/node_modules/rpc_channel.rb', line 342
def success_cb
@success_cb
end
|
Instance Method Details
#command ⇒ Object
370
371
372
|
# File 'lib/isono/node_modules/rpc_channel.rb', line 370
def command
self.request[:command]
end
|
#elapsed_time ⇒ Object
398
399
400
|
# File 'lib/isono/node_modules/rpc_channel.rb', line 398
def elapsed_time
self.completed_at.nil? ? nil : (self.completed_at - self.sent_at)
end
|
#endpoint ⇒ Object
366
367
368
|
# File 'lib/isono/node_modules/rpc_channel.rb', line 366
def endpoint
self.request[:endpoint]
end
|
#hash ⇒ Object
402
403
404
405
406
|
# File 'lib/isono/node_modules/rpc_channel.rb', line 402
def hash
@table.dup.merge({:state=>self.state})
end
|
#on_error(&blk) ⇒ Object
422
423
424
425
|
# File 'lib/isono/node_modules/rpc_channel.rb', line 422
def on_error(&blk)
raise ArgumentError unless blk
@error_cb = blk
end
|
#on_progress(&blk) ⇒ Object
417
418
419
420
|
# File 'lib/isono/node_modules/rpc_channel.rb', line 417
def on_progress(&blk)
raise ArgumentError unless blk
@progress_cb = blk
end
|
#on_success(&blk) ⇒ Object
412
413
414
415
|
# File 'lib/isono/node_modules/rpc_channel.rb', line 412
def on_success(&blk)
raise ArgumentError unless blk
@success_cb = blk
end
|
#process_event(ev, *args) ⇒ Object
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
|
# File 'lib/isono/node_modules/rpc_channel.rb', line 374
def process_event(ev, *args)
case [ev, @state]
when [:on_ready, :init]
@state = :ready
when [:on_sent, :ready]
@state = :waiting
self.sent_at=Time.now
self.request.freeze
when [:on_received, :waiting]
@state = :waiting
when [:on_success, :waiting]
@state = :done
self.completed_at=Time.now
self.complete_status = :success
when [:on_error, :waiting]
@state = :done
self.completed_at=Time.now
self.complete_status = :fail
else
raise "Unknown state transition: #{ev}, #{@state}"
end
end
|
#request_hash ⇒ Object
408
409
410
|
# File 'lib/isono/node_modules/rpc_channel.rb', line 408
def request_hash
request.merge({:oneshot=>oneshot})
end
|
#synchronize ⇒ Object
427
428
429
430
|
# File 'lib/isono/node_modules/rpc_channel.rb', line 427
def synchronize
self.extend RequestSynchronize
self
end
|