Class: Baykit::BayServer::Agent::Transporter::SpinWriteTransporter
- Inherits:
-
SpinHandler
- Object
- SpinHandler
- Baykit::BayServer::Agent::Transporter::SpinWriteTransporter
- Includes:
- Util, Util::Postman, Util::Reusable, Util::Valve
- Defined in:
- lib/baykit/bayserver/agent/transporter/spin_write_transporter.rb
Instance Attribute Summary collapse
-
#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.
-
#spin_handler ⇒ Object
readonly
Returns the value of attribute spin_handler.
-
#write_queue ⇒ Object
readonly
Returns the value of attribute write_queue.
Attributes inherited from SpinHandler
#agent, #listeners, #spin_count
Instance Method Summary collapse
- #check_timeout(duration_sec) ⇒ Object
- #close ⇒ Object
- #init(spin_hnd, outfile, lis) ⇒ Object
-
#initialize ⇒ SpinWriteTransporter
constructor
A new instance of SpinWriteTransporter.
-
#lap ⇒ Object
Implements SpinListener.
-
#open_valve ⇒ Object
Implements Valve.
-
#post(bytes, tag) ⇒ Object
Other methods.
-
#reset ⇒ Object
Implements Reusable.
- #to_s ⇒ Object
Methods included from Util::Postman
#abort, #flush, #is_zombie, #post_end
Methods inherited from SpinHandler
#ask_to_callback, #empty?, #on_timer, #process_data, #stop_timeout_spins
Methods included from Baykit::BayServer::Agent::TimerHandler
Constructor Details
#initialize ⇒ SpinWriteTransporter
25 26 27 28 |
# File 'lib/baykit/bayserver/agent/transporter/spin_write_transporter.rb', line 25 def initialize() @write_queue = [] @lock = Mutex.new() end |
Instance Attribute Details
#data_listener ⇒ Object (readonly)
Returns the value of attribute data_listener.
19 20 21 |
# File 'lib/baykit/bayserver/agent/transporter/spin_write_transporter.rb', line 19 def data_listener @data_listener end |
#lock ⇒ Object (readonly)
Returns the value of attribute lock.
22 23 24 |
# File 'lib/baykit/bayserver/agent/transporter/spin_write_transporter.rb', line 22 def lock @lock end |
#outfile ⇒ Object (readonly)
Returns the value of attribute outfile.
20 21 22 |
# File 'lib/baykit/bayserver/agent/transporter/spin_write_transporter.rb', line 20 def outfile @outfile end |
#spin_handler ⇒ Object (readonly)
Returns the value of attribute spin_handler.
18 19 20 |
# File 'lib/baykit/bayserver/agent/transporter/spin_write_transporter.rb', line 18 def spin_handler @spin_handler end |
#write_queue ⇒ Object (readonly)
Returns the value of attribute write_queue.
21 22 23 |
# File 'lib/baykit/bayserver/agent/transporter/spin_write_transporter.rb', line 21 def write_queue @write_queue end |
Instance Method Details
#check_timeout(duration_sec) ⇒ Object
90 91 92 |
# File 'lib/baykit/bayserver/agent/transporter/spin_write_transporter.rb', line 90 def check_timeout(duration_sec) return false end |
#close ⇒ Object
94 95 96 97 98 |
# File 'lib/baykit/bayserver/agent/transporter/spin_write_transporter.rb', line 94 def close() if @outfile != nil @outfile.close() end end |
#init(spin_hnd, outfile, lis) ⇒ Object
30 31 32 33 34 |
# File 'lib/baykit/bayserver/agent/transporter/spin_write_transporter.rb', line 30 def init(spin_hnd, outfile, lis) @spin_handler = spin_hnd @data_listener = lis @outfile = outfile end |
#lap ⇒ Object
Implements SpinListener
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 85 86 87 88 |
# File 'lib/baykit/bayserver/agent/transporter/spin_write_transporter.rb', line 53 def lap() begin buf = nil @lock.synchronize do if @write_queue.empty? BayLog.warn("%s Write queue empty", self) return NextSocketAction::SUSPEND end buf = @write_queue[0] end len = @outfile.syswrite(buf) if len == 0 return NextSocketAction::CONTINUE elsif len < buf.length buf[0 .. len-1] = "" return NextSocketAction::CONTINUE end @lock.synchronize do @write_queue.delete_at(0) if @write_queue.empty? return NextSocketAction::SUSPEND else return NextSocketAction::CONTINUE end end rescue Exception => e BayLog.error_e(e) close() return NextSocketAction::CLOSE end end |
#open_valve ⇒ Object
Implements Valve
104 105 106 |
# File 'lib/baykit/bayserver/agent/transporter/spin_write_transporter.rb', line 104 def open_valve() @spin_handler.ask_to_callback(self) end |
#post(bytes, tag) ⇒ Object
Other methods
111 112 113 114 115 116 117 118 119 |
# File 'lib/baykit/bayserver/agent/transporter/spin_write_transporter.rb', line 111 def post(bytes, tag) @lock.synchronize do empty = @write_queue.empty? @write_queue << bytes if empty open_valve() end end end |
#reset ⇒ Object
Implements Reusable
44 45 46 47 |
# File 'lib/baykit/bayserver/agent/transporter/spin_write_transporter.rb', line 44 def reset() @data_listener = nil @outfile = nil end |
#to_s ⇒ Object
36 37 38 |
# File 'lib/baykit/bayserver/agent/transporter/spin_write_transporter.rb', line 36 def to_s data_listener.to_s() end |