Class: Baykit::BayServer::Common::VehicleRunner::VehicleService
- Inherits:
-
Object
- Object
- Baykit::BayServer::Common::VehicleRunner::VehicleService
- Includes:
- Util
- Defined in:
- lib/baykit/bayserver/common/vehicle_runner.rb
Instance Attribute Summary collapse
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
-
#exe ⇒ Object
readonly
Returns the value of attribute exe.
-
#runnings ⇒ Object
readonly
Returns the value of attribute runnings.
-
#runnings_lock ⇒ Object
readonly
Returns the value of attribute runnings_lock.
Instance Method Summary collapse
-
#initialize(agt, runner) ⇒ VehicleService
constructor
A new instance of VehicleService.
-
#on_timer ⇒ Object
Implements TimerHandler.
- #submit(vcl) ⇒ Object
-
#terminate ⇒ Object
Private methods.
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
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
40 41 42 |
# File 'lib/baykit/bayserver/common/vehicle_runner.rb', line 40 def agent @agent end |
#exe ⇒ Object (readonly)
Returns the value of attribute exe.
41 42 43 |
# File 'lib/baykit/bayserver/common/vehicle_runner.rb', line 41 def exe @exe end |
#runnings ⇒ Object (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_lock ⇒ Object (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_timer ⇒ Object
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 |
#terminate ⇒ Object
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 |