Class: Baykit::BayServer::Agent::Transporter::SpinReadTransporter
- Inherits:
-
Object
- Object
- Baykit::BayServer::Agent::Transporter::SpinReadTransporter
- Includes:
- SpinHandler::SpinListener, Util, Util::Valve
- Defined in:
- lib/baykit/bayserver/agent/transporter/spin_read_transporter.rb
Instance Attribute Summary collapse
-
#data_listener ⇒ Object
readonly
Returns the value of attribute data_listener.
-
#eof_checker ⇒ Object
readonly
Returns the value of attribute eof_checker.
-
#file_len ⇒ Object
readonly
Returns the value of attribute file_len.
-
#infile ⇒ Object
readonly
Returns the value of attribute infile.
-
#is_closed ⇒ Object
readonly
Returns the value of attribute is_closed.
-
#read_buf ⇒ Object
readonly
Returns the value of attribute read_buf.
-
#spin_handler ⇒ Object
readonly
Returns the value of attribute spin_handler.
-
#timeout_sec ⇒ Object
readonly
Returns the value of attribute timeout_sec.
-
#total_read ⇒ Object
readonly
Returns the value of attribute total_read.
Instance Method Summary collapse
- #check_timeout(duration_sec) ⇒ Object
- #close ⇒ Object
- #init(spin_hnd, lis, infile, limit, timeout_sec, eof_checker) ⇒ Object
-
#initialize(buf_size) ⇒ SpinReadTransporter
constructor
A new instance of SpinReadTransporter.
-
#lap ⇒ Object
Implements SpinListener.
-
#open_valve ⇒ Object
Implements Valve.
-
#reset ⇒ Object
Implements Reusable.
- #to_s ⇒ Object
Constructor Details
#initialize(buf_size) ⇒ SpinReadTransporter
Returns a new instance of SpinReadTransporter.
24 25 26 |
# File 'lib/baykit/bayserver/agent/transporter/spin_read_transporter.rb', line 24 def initialize(buf_size) @read_buf = StringUtil.alloc(buf_size) end |
Instance Attribute Details
#data_listener ⇒ Object (readonly)
Returns the value of attribute data_listener.
15 16 17 |
# File 'lib/baykit/bayserver/agent/transporter/spin_read_transporter.rb', line 15 def data_listener @data_listener end |
#eof_checker ⇒ Object (readonly)
Returns the value of attribute eof_checker.
21 22 23 |
# File 'lib/baykit/bayserver/agent/transporter/spin_read_transporter.rb', line 21 def eof_checker @eof_checker end |
#file_len ⇒ Object (readonly)
Returns the value of attribute file_len.
19 20 21 |
# File 'lib/baykit/bayserver/agent/transporter/spin_read_transporter.rb', line 19 def file_len @file_len end |
#infile ⇒ Object (readonly)
Returns the value of attribute infile.
16 17 18 |
# File 'lib/baykit/bayserver/agent/transporter/spin_read_transporter.rb', line 16 def infile @infile end |
#is_closed ⇒ Object (readonly)
Returns the value of attribute is_closed.
22 23 24 |
# File 'lib/baykit/bayserver/agent/transporter/spin_read_transporter.rb', line 22 def is_closed @is_closed end |
#read_buf ⇒ Object (readonly)
Returns the value of attribute read_buf.
17 18 19 |
# File 'lib/baykit/bayserver/agent/transporter/spin_read_transporter.rb', line 17 def read_buf @read_buf end |
#spin_handler ⇒ Object (readonly)
Returns the value of attribute spin_handler.
14 15 16 |
# File 'lib/baykit/bayserver/agent/transporter/spin_read_transporter.rb', line 14 def spin_handler @spin_handler end |
#timeout_sec ⇒ Object (readonly)
Returns the value of attribute timeout_sec.
20 21 22 |
# File 'lib/baykit/bayserver/agent/transporter/spin_read_transporter.rb', line 20 def timeout_sec @timeout_sec end |
#total_read ⇒ Object (readonly)
Returns the value of attribute total_read.
18 19 20 |
# File 'lib/baykit/bayserver/agent/transporter/spin_read_transporter.rb', line 18 def total_read @total_read end |
Instance Method Details
#check_timeout(duration_sec) ⇒ Object
81 82 83 |
# File 'lib/baykit/bayserver/agent/transporter/spin_read_transporter.rb', line 81 def check_timeout(duration_sec) return duration_sec > @timeout_sec end |
#close ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/baykit/bayserver/agent/transporter/spin_read_transporter.rb', line 85 def close() if @infile != nil @infile.close() end @data_listener.notify_close() @is_closed = true end |
#init(spin_hnd, lis, infile, limit, timeout_sec, eof_checker) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/baykit/bayserver/agent/transporter/spin_read_transporter.rb', line 28 def init(spin_hnd, lis, infile, limit, timeout_sec, eof_checker) @spin_handler = spin_hnd @data_listener = lis @infile = infile @file_len = limit @total_read = 0 @timeout_sec = timeout_sec @eof_checker = eof_checker @is_closed = false end |
#lap ⇒ Object
Implements SpinListener
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/baykit/bayserver/agent/transporter/spin_read_transporter.rb', line 56 def lap() begin @infile.sysread(@buf_size, @read_buf) if @read_buf.length == 0 return NextSocketAction::CONTINUE, true end @total_read += @read_buf.length next_act = @yacht.notify_read(@read_buf) if @total_read == @file_len @data_listener.notify_eof() close() return NextSocketAction::CLOSE, false end return next_act, false rescue Exception => e BayLog.error_e(e) close() return NextSocketAction::CLOSE, false end end |
#open_valve ⇒ Object
Implements Valve
97 98 99 |
# File 'lib/baykit/bayserver/agent/transporter/spin_read_transporter.rb', line 97 def open_valve() @spin_handler.ask_to_callback(self) end |
#reset ⇒ Object
Implements Reusable
47 48 49 50 |
# File 'lib/baykit/bayserver/agent/transporter/spin_read_transporter.rb', line 47 def reset() @data_listener = nil @infile = nil end |
#to_s ⇒ Object
39 40 41 |
# File 'lib/baykit/bayserver/agent/transporter/spin_read_transporter.rb', line 39 def to_s data_listener.to_s() end |