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

Inherits:
OpenStruct
  • Object
show all
Includes:
Logger
Defined in:
lib/isono/node_modules/rpc_channel.rb

Defined Under Namespace

Modules: RequestSynchronize

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logger

included, initialize

Constructor Details

#initialize(endpoint, command, args) ⇒ RequestContext

Returns a new instance of RequestContext.



347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
# File 'lib/isono/node_modules/rpc_channel.rb', line 347

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().



342
343
344
# File 'lib/isono/node_modules/rpc_channel.rb', line 342

def error_cb
  @error_cb
end

#progress_cbObject (readonly)

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

#stateObject (readonly)

Returns the value of attribute state.



343
344
345
# File 'lib/isono/node_modules/rpc_channel.rb', line 343

def state
  @state
end

#success_cbObject (readonly)

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

#commandObject



372
373
374
# File 'lib/isono/node_modules/rpc_channel.rb', line 372

def command
  self.request[:command]
end

#elapsed_timeObject



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

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

#endpointObject



368
369
370
# File 'lib/isono/node_modules/rpc_channel.rb', line 368

def endpoint
  self.request[:endpoint]
end

#hashObject



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

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)


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

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

#on_progress(&blk) ⇒ Object

Raises:

  • (ArgumentError)


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

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

#on_success(&blk) ⇒ Object

Raises:

  • (ArgumentError)


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

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

#process_event(ev, *args) ⇒ Object



376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
# File 'lib/isono/node_modules/rpc_channel.rb', line 376

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



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

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

#synchronizeObject



429
430
431
432
# File 'lib/isono/node_modules/rpc_channel.rb', line 429

def synchronize
  self.extend RequestSynchronize
  self
end