Class: LogPorter::Server
- Inherits:
-
Object
- Object
- LogPorter::Server
- Defined in:
- lib/logporter/namespace.rb,
lib/logporter/server.rb
Defined Under Namespace
Classes: Connection, DefaultHandler, TLSConfig
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Arbitrary attributes for this server.
-
#logger ⇒ Object
The logger object.
-
#network ⇒ Object
readonly
The network layer, :tcp, :udp, or :tls.
-
#port ⇒ Object
readonly
The port we are listening on.
-
#tls ⇒ Object
readonly
TLS options, only meaningful if @network == :tls.
-
#wire ⇒ Object
readonly
The wire format (syslog, raw, etc).
Instance Method Summary collapse
-
#initialize(options) ⇒ Server
constructor
Create a new server to listen with ‘options’ is a hash of:.
- #receive_event(event, client_addr, client_port) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(options) ⇒ Server
Create a new server to listen with ‘options’ is a hash of:
:net => the network layer to use (:udp, :tcp, :tls)
:port => the port to listen on
:wire => the wire format (:raw, :syslog)
:handler => the handler instance. Must respond to 'receive_event'
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/logporter/server.rb', line 37 def initialize() @logger = Logger.new(STDOUT) @network = [:net] @port = [:port] || 514 @wire = [:wire] || :raw @handler = [:handler] || LogPorter::Server::DefaultHandler.new @attributes = [:attributes] || Hash.new if @network == :tls @tls = TLSConfig.new @tls.private_key_file = [:private_key] @tls.cert_chain_file = [:certificate_chain] @tls.verify_peer = [:verify_peer] || false else @tls = nil end end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Arbitrary attributes for this server. You can store whatever you want here. This is a hash
25 26 27 |
# File 'lib/logporter/server.rb', line 25 def attributes @attributes end |
#logger ⇒ Object
The logger object
28 29 30 |
# File 'lib/logporter/server.rb', line 28 def logger @logger end |
#network ⇒ Object (readonly)
The network layer, :tcp, :udp, or :tls
18 19 20 |
# File 'lib/logporter/server.rb', line 18 def network @network end |
#port ⇒ Object (readonly)
The port we are listening on
12 13 14 |
# File 'lib/logporter/server.rb', line 12 def port @port end |
#tls ⇒ Object (readonly)
TLS options, only meaningful if @network == :tls
15 16 17 |
# File 'lib/logporter/server.rb', line 15 def tls @tls end |
#wire ⇒ Object (readonly)
The wire format (syslog, raw, etc)
21 22 23 |
# File 'lib/logporter/server.rb', line 21 def wire @wire end |
Instance Method Details
#receive_event(event, client_addr, client_port) ⇒ Object
106 107 108 |
# File 'lib/logporter/server.rb', line 106 def receive_event(event, client_addr, client_port) @handler.receive_event(event, self, client_addr, client_port) end |
#start ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/logporter/server.rb', line 57 def start # We use next_tick here in case you are invoking this method from outside # of EventMachine; this allows you to do this: # # s = LogPorter::server.new ... # s.start # # EventMachine.run() if EventMachine.reactor_running? _start else EventMachine.next_tick { _start } end end |
#stop ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/logporter/server.rb', line 111 def stop @logger.info "Stopping #{@network}/#{@port}" case @network when :tcp EventMachine::stop_server(@socket) when :tls EventMachine::stop_server(@socket) when :udp @socket.close_connection(true) end end |