Class: Pants::Readers::UDPReader

Inherits:
BaseReader show all
Includes:
LogSwitch::Mixin
Defined in:
lib/pants/readers/udp_reader.rb

Overview

This is the interface for UDPReaderConnections. It controls what happens when the you want to start it up and stop it.

Instance Attribute Summary

Attributes inherited from BaseReader

#core_stopper_callback, #write_to_channel, #writers

Instance Method Summary collapse

Methods inherited from BaseReader

#add_seam, #add_writer, #read_object, #remove_writer, #running?, #stop!, #write_to

Constructor Details

#initialize(host, port, core_stopper_callback) ⇒ UDPReader

Returns a new instance of UDPReader.

Parameters:

  • host (String)

    The IP address to read on.

  • port (Fixnum)

    The UDP port to read on.

  • core_stopper_callback (EventMachine::Callback)

    The Callback that will get called when #stopper is called. Since there is no clear end to when to stop reading this I/O, #stopper is never called internally; it must be called externally.



60
61
62
63
64
65
66
# File 'lib/pants/readers/udp_reader.rb', line 60

def initialize(host, port, core_stopper_callback)
  @read_object = "udp://#{host}:#{port}"
  @host = host
  @port = port

  super(core_stopper_callback)
end

Instance Method Details

#startObject

Starts reading on the UDP IP and port and pushing packets to the channel.



69
70
71
72
73
74
75
76
77
# File 'lib/pants/readers/udp_reader.rb', line 69

def start
  callback = EM.Callback do
    log "Adding a #{self.class} at #{@host}:#{@port}..."
    EM.open_datagram_socket(@host, @port, UDPReaderConnection,
      @write_to_channel, starter)
  end

  super(callback)
end