Class: LogCourier::Server
- Inherits:
-
Object
- Object
- LogCourier::Server
- Defined in:
- lib/log-courier/server.rb
Overview
Implementation of the server
Instance Attribute Summary collapse
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Server
constructor
A new instance of Server.
- #run(&block) ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Server
Returns a new instance of Server.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 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 |
# File 'lib/log-courier/server.rb', line 35 def initialize( = {}) = { logger: nil, transport: 'tls', disable_handshake: false, }.merge!() @logger = [:logger] case [:transport] when 'tcp', 'tls' require 'log-courier/server_tcp' @server = ServerTcp.new() else raise 'input/courier: \'transport\' must be tcp or tls' end # Grab the port back and update the logger context @port = @server.port # TODO: Make queue size configurable @event_queue = EventQueue.new 1 @server_thread = Thread.new do # Receive messages and process them @server.run do |signature, , comm| case signature when 'PING' process_ping , comm when 'JDAT' process_jdat , comm, @event_queue else if comm.peer.nil? @logger&.warn 'Unknown message received', from: 'unknown' else @logger&.warn 'Unknown message received', from: comm.peer end # Don't kill a client that sends a bad message # Just reject it and let it send it again, potentially to another server comm.send '????', '' end end end end |
Instance Attribute Details
#port ⇒ Object (readonly)
Returns the value of attribute port.
33 34 35 |
# File 'lib/log-courier/server.rb', line 33 def port @port end |
Instance Method Details
#run(&block) ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/log-courier/server.rb', line 80 def run(&block) loop do event = @event_queue.pop break if event.nil? block.call event end nil end |
#stop ⇒ Object
90 91 92 93 94 95 |
# File 'lib/log-courier/server.rb', line 90 def stop @server_thread.raise ShutdownSignal @event_queue << nil @server_thread.join nil end |