Class: Baykit::BayServer::Common::VehicleRunner::VehicleService

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/baykit/bayserver/common/vehicle_runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(agt, runner) ⇒ VehicleService

Returns a new instance of VehicleService.



45
46
47
48
49
50
51
# File 'lib/baykit/bayserver/common/vehicle_runner.rb', line 45

def initialize(agt, runner)
  @agent = agt
  @agent.add_timer_handler(self)
  @runnings = []
  @runnings_lock = Mutex.new
  @exe = ExecutorService.new("Runner", runner.max_vehicles)
end

Instance Attribute Details

#agentObject (readonly)

Returns the value of attribute agent.



40
41
42
# File 'lib/baykit/bayserver/common/vehicle_runner.rb', line 40

def agent
  @agent
end

#exeObject (readonly)

Returns the value of attribute exe.



41
42
43
# File 'lib/baykit/bayserver/common/vehicle_runner.rb', line 41

def exe
  @exe
end

#runningsObject (readonly)

Returns the value of attribute runnings.



42
43
44
# File 'lib/baykit/bayserver/common/vehicle_runner.rb', line 42

def runnings
  @runnings
end

#runnings_lockObject (readonly)

Returns the value of attribute runnings_lock.



43
44
45
# File 'lib/baykit/bayserver/common/vehicle_runner.rb', line 43

def runnings_lock
  @runnings_lock
end

Instance Method Details

#on_timerObject

Implements TimerHandler



56
57
58
59
60
61
62
# File 'lib/baykit/bayserver/common/vehicle_runner.rb', line 56

def on_timer
  @runnings_lock.synchronize do
    @runnings.each do |vcl|
      vcl.on_timer
    end
  end
end

#submit(vcl) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/baykit/bayserver/common/vehicle_runner.rb', line 74

def submit(vcl)
  @exe.submit() do
    if @agent.aborted
      BayLog.error("%s Agent is aborted", @agent)
      return
    end

    @runnings_lock.synchronize do
      @runnings << vcl
    end

    begin
      vcl.run
    rescue => e
      BayLog.fatal_e(e)
      @agent.req_shutdown
    ensure
      @runnings_lock.synchronize do
        @runnings.delete(vcl)
      end
    end
  end
end

#terminateObject

Private methods



69
70
71
72
# File 'lib/baykit/bayserver/common/vehicle_runner.rb', line 69

def terminate()
  @agent.remove_timer_handler(self)
  @exe.shutdown
end