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.
Class Method Summary collapse
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.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/log-courier/server.rb', line 54 def initialize( = {}) = { logger: nil, transport: 'tls', raw_events: true, }.merge!() @logger = [:logger] case [:transport] when 'tcp', 'tls' require 'log-courier/server_tcp' @server = ServerTcp.new() when 'plainzmq', 'zmq' require 'log-courier/server_zmq' @server = ServerZmq.new() else fail 'input/courier: \'transport\' must be tcp, tls, plainzmq or zmq' end # Grab the port back and update the logger context @port = @server.port end |
Instance Attribute Details
#port ⇒ Object (readonly)
Returns the value of attribute port.
34 35 36 |
# File 'lib/log-courier/server.rb', line 34 def port @port end |
Class Method Details
.get_json_adapter ⇒ Object
41 42 43 44 |
# File 'lib/log-courier/server.rb', line 41 def get_json_adapter @json_adapter = MultiJson.adapter.instance if @json_adapter.nil? @json_adapter end |
.get_json_parseerror ⇒ Object
46 47 48 49 50 51 |
# File 'lib/log-courier/server.rb', line 46 def get_json_parseerror if @json_parseerror.nil? @json_parseerror = get_json_adapter.class::ParseError end @json_parseerror end |
Instance Method Details
#run(&block) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/log-courier/server.rb', line 78 def run(&block) # TODO: Make queue size configurable @event_queue = EventQueue.new 1 server_thread = nil begin 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' unless @logger.nil? else @logger.warn 'Unknown message received', :from => comm.peer unless @logger.nil? 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 loop do event = @event_queue.pop break if event.nil? block.call event end ensure # Signal the server thread to stop unless server_thread.nil? server_thread.raise ShutdownSignal server_thread.join end end return end |
#stop ⇒ Object
120 121 122 |
# File 'lib/log-courier/server.rb', line 120 def stop @event_queue << nil end |