Class: Baykit::BayServer::Tours::ReadFileTaxi
- Inherits:
-
Baykit::BayServer::Taxi::Taxi
- Object
- Common::Vehicle
- Baykit::BayServer::Taxi::Taxi
- Baykit::BayServer::Tours::ReadFileTaxi
- Includes:
- Agent, Baykit::BayServer::Taxi, Util, Util::Valve
- Defined in:
- lib/baykit/bayserver/tours/read_file_taxi.rb
Instance Attribute Summary collapse
-
#agent_id ⇒ Object
readonly
Returns the value of attribute agent_id.
-
#buf ⇒ Object
readonly
Returns the value of attribute buf.
-
#buf_size ⇒ Object
readonly
Returns the value of attribute buf_size.
-
#ch_valid ⇒ Object
readonly
Returns the value of attribute ch_valid.
-
#data_listener ⇒ Object
readonly
Returns the value of attribute data_listener.
-
#infile ⇒ Object
readonly
Returns the value of attribute infile.
-
#lock ⇒ Object
readonly
Returns the value of attribute lock.
-
#running ⇒ Object
readonly
Returns the value of attribute running.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
Attributes inherited from Baykit::BayServer::Taxi::Taxi
Attributes inherited from Common::Vehicle
Instance Method Summary collapse
- #close ⇒ Object
-
#depart ⇒ Object
implements Taxi.
- #init(infile, data_listener) ⇒ Object
-
#initialize(agt_id, buf_size) ⇒ ReadFileTaxi
constructor
A new instance of ReadFileTaxi.
- #next_run ⇒ Object
- #on_timer ⇒ Object
-
#open_valve ⇒ Object
implements Valve.
- #to_s ⇒ Object
Methods inherited from Baykit::BayServer::Taxi::Taxi
Methods inherited from Common::Vehicle
Constructor Details
#initialize(agt_id, buf_size) ⇒ ReadFileTaxi
Returns a new instance of ReadFileTaxi.
29 30 31 32 33 34 35 |
# File 'lib/baykit/bayserver/tours/read_file_taxi.rb', line 29 def initialize(agt_id, buf_size) super() @buf_size = buf_size @buf = StringUtil.alloc(buf_size) @lock = Monitor.new() @agent_id = agt_id end |
Instance Attribute Details
#agent_id ⇒ Object (readonly)
Returns the value of attribute agent_id.
26 27 28 |
# File 'lib/baykit/bayserver/tours/read_file_taxi.rb', line 26 def agent_id @agent_id end |
#buf ⇒ Object (readonly)
Returns the value of attribute buf.
22 23 24 |
# File 'lib/baykit/bayserver/tours/read_file_taxi.rb', line 22 def buf @buf end |
#buf_size ⇒ Object (readonly)
Returns the value of attribute buf_size.
23 24 25 |
# File 'lib/baykit/bayserver/tours/read_file_taxi.rb', line 23 def buf_size @buf_size end |
#ch_valid ⇒ Object (readonly)
Returns the value of attribute ch_valid.
20 21 22 |
# File 'lib/baykit/bayserver/tours/read_file_taxi.rb', line 20 def ch_valid @ch_valid end |
#data_listener ⇒ Object (readonly)
Returns the value of attribute data_listener.
21 22 23 |
# File 'lib/baykit/bayserver/tours/read_file_taxi.rb', line 21 def data_listener @data_listener end |
#infile ⇒ Object (readonly)
Returns the value of attribute infile.
19 20 21 |
# File 'lib/baykit/bayserver/tours/read_file_taxi.rb', line 19 def infile @infile end |
#lock ⇒ Object (readonly)
Returns the value of attribute lock.
25 26 27 |
# File 'lib/baykit/bayserver/tours/read_file_taxi.rb', line 25 def lock @lock end |
#running ⇒ Object (readonly)
Returns the value of attribute running.
24 25 26 |
# File 'lib/baykit/bayserver/tours/read_file_taxi.rb', line 24 def running @running end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
27 28 29 |
# File 'lib/baykit/bayserver/tours/read_file_taxi.rb', line 27 def start_time @start_time end |
Instance Method Details
#close ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/baykit/bayserver/tours/read_file_taxi.rb', line 105 def close() @lock.synchronize do if !@ch_valid return end @ch_valid = false @data_listener.notify_eof() begin @infile.close() rescue IOError => e end @data_listener.notify_close() end end |
#depart ⇒ Object
implements Taxi
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/baykit/bayserver/tours/read_file_taxi.rb', line 61 def depart() @start_time = Time.now.tv_sec begin @buf.clear() @infile.read(@buf_size, @buf) if @buf.length == 0 close() return end act = @data_listener.notify_read(@buf, nil) @running = false if act == NextSocketAction::CONTINUE next_run() end rescue IOError => e BayLog.debug_e(e) close() rescue Exception => e close() raise e end end |
#init(infile, data_listener) ⇒ Object
41 42 43 44 45 |
# File 'lib/baykit/bayserver/tours/read_file_taxi.rb', line 41 def init(infile, data_listener) @data_listener = data_listener @infile = infile @ch_valid = true end |
#next_run ⇒ Object
96 97 98 99 100 101 102 103 |
# File 'lib/baykit/bayserver/tours/read_file_taxi.rb', line 96 def next_run() if @running # If running, not posted because next run exists return end @running = true TaxiRunner.post(@agent_id, self) end |
#on_timer ⇒ Object
88 89 90 91 92 93 |
# File 'lib/baykit/bayserver/tours/read_file_taxi.rb', line 88 def on_timer() duration_sec = Time.now.tv_sec - @start_time if (@data_listener.check_timeout(duration_sec)) close() end end |
#open_valve ⇒ Object
implements Valve
51 52 53 54 55 |
# File 'lib/baykit/bayserver/tours/read_file_taxi.rb', line 51 def open_valve() @lock.synchronize do next_run() end end |
#to_s ⇒ Object
37 38 39 |
# File 'lib/baykit/bayserver/tours/read_file_taxi.rb', line 37 def to_s() return super.to_s() + " " + @data_listener.to_s() end |