Class: Pants::Writers::UDPWriter
- Inherits:
-
BaseWriter
- Object
- BaseWriter
- Pants::Writers::UDPWriter
- Includes:
- LogSwitch::Mixin
- Defined in:
- lib/pants/writers/udp_writer.rb
Overview
This is the interface to UDPWriterConnections. It defines what happens when you want to start it up and stop it.
Instance Attribute Summary collapse
-
#host ⇒ String
readonly
The IP address that’s being written to.
-
#port ⇒ Fixnum
readonly
The port that’s being written to.
Instance Method Summary collapse
-
#initialize(host, port, read_from_channel) ⇒ UDPWriter
constructor
A new instance of UDPWriter.
-
#start ⇒ Object
Readies the writer for data to write and waits for data to write.
-
#stop ⇒ Object
Closes the connection and notifies the reader that it’s done.
Methods inherited from BaseWriter
#running?, #starter, #stopper, #write_object
Constructor Details
#initialize(host, port, read_from_channel) ⇒ UDPWriter
Returns a new instance of UDPWriter.
95 96 97 98 99 100 101 102 |
# File 'lib/pants/writers/udp_writer.rb', line 95 def initialize(host, port, read_from_channel) @host = host @port = port @connection = nil @write_object = "udp://#{@host}:#{@port}" super(read_from_channel) end |
Instance Attribute Details
#host ⇒ String (readonly)
Returns The IP address that’s being written to.
85 86 87 |
# File 'lib/pants/writers/udp_writer.rb', line 85 def host @host end |
#port ⇒ Fixnum (readonly)
Returns The port that’s being written to.
88 89 90 |
# File 'lib/pants/writers/udp_writer.rb', line 88 def port @port end |
Instance Method Details
#start ⇒ Object
Readies the writer for data to write and waits for data to write.
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/pants/writers/udp_writer.rb', line 105 def start log "#{__id__} Adding a #{self.class} at #{@host}:#{@port}..." EM.defer do @connection = EM.open_datagram_socket('0.0.0.0', 0, UDPWriterConnection, @read_from_channel, @host, @port) start_loop = EM.tick_loop { :stop if @connection } start_loop.on_stop { starter.call } end end |
#stop ⇒ Object
Closes the connection and notifies the reader that it’s done.
118 119 120 121 122 |
# File 'lib/pants/writers/udp_writer.rb', line 118 def stop log "Finishing ID #{__id__}" @connection.close_connection_after_writing stopper.call end |