Class: Baykit::BayServer::Docker::BuiltIn::WriteFileTaxi
- Inherits:
-
Taxi::Taxi
- Object
- Common::Vehicle
- Taxi::Taxi
- Baykit::BayServer::Docker::BuiltIn::WriteFileTaxi
- Includes:
- Taxi, Util::Postman, Util::Valve
- Defined in:
- lib/baykit/bayserver/docker/built_in/write_file_taxi.rb
Instance Attribute Summary collapse
-
#agent_id ⇒ Object
readonly
Returns the value of attribute agent_id.
-
#ch_valid ⇒ Object
readonly
Returns the value of attribute ch_valid.
-
#data_listener ⇒ Object
readonly
Returns the value of attribute data_listener.
-
#lock ⇒ Object
readonly
Returns the value of attribute lock.
-
#outfile ⇒ Object
readonly
Returns the value of attribute outfile.
-
#write_queue ⇒ Object
readonly
Returns the value of attribute write_queue.
Attributes inherited from Taxi::Taxi
Attributes inherited from Common::Vehicle
Instance Method Summary collapse
-
#depart ⇒ Object
Implements Taxi.
- #init(agt_id, out, data_listener) ⇒ Object
-
#initialize ⇒ WriteFileTaxi
constructor
A new instance of WriteFileTaxi.
- #next_run ⇒ Object
- #on_timer ⇒ Object
-
#open_valve ⇒ Object
Implements Resumable.
- #post(data, adr, tag) ⇒ Object
- #to_s ⇒ Object
Methods included from Util::Postman
#abort, #flush, #is_zombie, #post_end
Methods inherited from Taxi::Taxi
Methods inherited from Common::Vehicle
Constructor Details
#initialize ⇒ WriteFileTaxi
Returns a new instance of WriteFileTaxi.
24 25 26 27 28 |
# File 'lib/baykit/bayserver/docker/built_in/write_file_taxi.rb', line 24 def initialize() super @write_queue = [] @lock = Mutex.new() end |
Instance Attribute Details
#agent_id ⇒ Object (readonly)
Returns the value of attribute agent_id.
22 23 24 |
# File 'lib/baykit/bayserver/docker/built_in/write_file_taxi.rb', line 22 def agent_id @agent_id end |
#ch_valid ⇒ Object (readonly)
Returns the value of attribute ch_valid.
18 19 20 |
# File 'lib/baykit/bayserver/docker/built_in/write_file_taxi.rb', line 18 def ch_valid @ch_valid end |
#data_listener ⇒ Object (readonly)
Returns the value of attribute data_listener.
19 20 21 |
# File 'lib/baykit/bayserver/docker/built_in/write_file_taxi.rb', line 19 def data_listener @data_listener end |
#lock ⇒ Object (readonly)
Returns the value of attribute lock.
21 22 23 |
# File 'lib/baykit/bayserver/docker/built_in/write_file_taxi.rb', line 21 def lock @lock end |
#outfile ⇒ Object (readonly)
Returns the value of attribute outfile.
17 18 19 |
# File 'lib/baykit/bayserver/docker/built_in/write_file_taxi.rb', line 17 def outfile @outfile end |
#write_queue ⇒ Object (readonly)
Returns the value of attribute write_queue.
20 21 22 |
# File 'lib/baykit/bayserver/docker/built_in/write_file_taxi.rb', line 20 def write_queue @write_queue end |
Instance Method Details
#depart ⇒ Object
Implements Taxi
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/baykit/bayserver/docker/built_in/write_file_taxi.rb', line 52 def depart() begin while true buf = nil empty = nil @lock.synchronize do empty = @write_queue.empty? if !empty buf = @write_queue[0] @write_queue.delete_at(0) end end if empty break end @outfile.syswrite(buf) empty = nil @lock.synchronize do empty = @write_queue.empty? end if !empty next_run() end end rescue StandardError => e BayLog.error_e(e) end end |
#init(agt_id, out, data_listener) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/baykit/bayserver/docker/built_in/write_file_taxi.rb', line 30 def init(agt_id, out, data_listener) @agent_id = agt_id @outfile = out @data_listener = data_listener @ch_valid = true end |
#next_run ⇒ Object
100 101 102 |
# File 'lib/baykit/bayserver/docker/built_in/write_file_taxi.rb', line 100 def next_run() TaxiRunner.post(@agent_id, self) end |
#on_timer ⇒ Object
86 87 88 |
# File 'lib/baykit/bayserver/docker/built_in/write_file_taxi.rb', line 86 def on_timer() end |
#open_valve ⇒ Object
Implements Resumable
44 45 46 |
# File 'lib/baykit/bayserver/docker/built_in/write_file_taxi.rb', line 44 def open_valve() next_run() end |
#post(data, adr, tag) ⇒ Object
90 91 92 93 94 95 96 97 98 |
# File 'lib/baykit/bayserver/docker/built_in/write_file_taxi.rb', line 90 def post(data, adr, tag) @lock.synchronize do empty = @write_queue.empty? @write_queue.append(data) if empty open_valve() end end end |
#to_s ⇒ Object
37 38 39 |
# File 'lib/baykit/bayserver/docker/built_in/write_file_taxi.rb', line 37 def to_s() return super.to_s + " " + @data_listener.to_s end |