Class: StickyElephant::Connection

Inherits:
Object
  • Object
show all
Includes:
LogInterface
Defined in:
lib/sticky_elephant/connection.rb

Instance Method Summary collapse

Constructor Details

#initialize(socket, logger:) ⇒ Connection

Returns a new instance of Connection.



5
6
7
8
# File 'lib/sticky_elephant/connection.rb', line 5

def initialize(socket, logger: )
  @socket = socket
  @logger = logger
end

Instance Method Details

#processObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/sticky_elephant/connection.rb', line 10

def process
  begin
    loop do
      @payload = Payload.new(socket.readpartial(1024**2).bytes)
      log(msg: "Received #{payload}", level: :debug)
      obj = Handler.for(payload, socket: socket, logger: logger)
      log(msg: "Handling with #{obj.class}", level: :debug)
      obj.process
    end
  rescue => e
    log(msg: e, level: :error) unless e.is_a? EOFError
  ensure
    socket.close
    Thread.exit
  end
end