Class: Isono::NodeModules::RpcChannel::RequestContext

Inherits:
OpenStruct
  • Object
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.



341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
# File 'lib/isono/node_modules/rpc_channel.rb', line 341

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_cbObject (readonly)

They are not to be appeared in @table so that won’t be inspect().



338
339
340
# File 'lib/isono/node_modules/rpc_channel.rb', line 338

def error_cb
  @error_cb
end

#progress_cbObject (readonly)

They are not to be appeared in @table so that won’t be inspect().



338
339
340
# File 'lib/isono/node_modules/rpc_channel.rb', line 338

def progress_cb
  @progress_cb
end

#stateObject (readonly)

Returns the value of attribute state.



339
340
341
# File 'lib/isono/node_modules/rpc_channel.rb', line 339

def state
  @state
end

#success_cbObject (readonly)

They are not to be appeared in @table so that won’t be inspect().



338
339
340
# File 'lib/isono/node_modules/rpc_channel.rb', line 338

def success_cb
  @success_cb
end

Instance Method Details

#commandObject



366
367
368
# File 'lib/isono/node_modules/rpc_channel.rb', line 366

def command
  self.request[:command]
end

#elapsed_timeObject



394
395
396
# File 'lib/isono/node_modules/rpc_channel.rb', line 394

def elapsed_time
  self.completed_at.nil? ? nil : (self.completed_at - self.sent_at)
end

#endpointObject



362
363
364
# File 'lib/isono/node_modules/rpc_channel.rb', line 362

def endpoint
  self.request[:endpoint]
end

#hashObject



398
399
400
401
402
# File 'lib/isono/node_modules/rpc_channel.rb', line 398

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

Raises:

  • (ArgumentError)


418
419
420
421
# File 'lib/isono/node_modules/rpc_channel.rb', line 418

def on_error(&blk)
  raise ArgumentError unless blk
  @error_cb = blk
end

#on_progress(&blk) ⇒ Object

Raises:

  • (ArgumentError)


413
414
415
416
# File 'lib/isono/node_modules/rpc_channel.rb', line 413

def on_progress(&blk)
  raise ArgumentError unless blk
  @progress_cb = blk
end

#on_success(&blk) ⇒ Object

Raises:

  • (ArgumentError)


408
409
410
411
# File 'lib/isono/node_modules/rpc_channel.rb', line 408

def on_success(&blk)
  raise ArgumentError unless blk
  @success_cb = blk
end

#process_event(ev, *args) ⇒ Object



370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
# File 'lib/isono/node_modules/rpc_channel.rb', line 370

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
    # freeze request hash not to be modified after sending.
    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_hashObject



404
405
406
# File 'lib/isono/node_modules/rpc_channel.rb', line 404

def request_hash
  request.merge({:oneshot=>oneshot})
end

#synchronizeObject



423
424
425
426
# File 'lib/isono/node_modules/rpc_channel.rb', line 423

def synchronize
  self.extend RequestSynchronize
  self
end