Class: Dizby::ConnectionWorker

Inherits:
Object
  • Object
show all
Defined in:
lib/dizby/worker/connection.rb

Instance Method Summary collapse

Constructor Details

#initialize(server, conn) ⇒ ConnectionWorker


6
7
8
9
10
11
# File 'lib/dizby/worker/connection.rb', line 6

def initialize(server, conn)
  @server = server
  @conn = conn

  @thread = Thread.start { process_requests }
end

Instance Method Details

#close


13
14
15
16
17
18
# File 'lib/dizby/worker/connection.rb', line 13

def close
  @conn.close unless @conn.closed?

  # TODO: @thread gets set to nil for some reason...
  @thread.join if @thread
end

#process_request (private)


30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/dizby/worker/connection.rb', line 30

def process_request
  succ, result = InvokeMethod.new(@server, *@conn.recv_request).perform

  @server.log.backtrace(result) unless succ

  begin
    @conn.send_reply(succ, result)
  rescue
    @server.log.backtrace($!)
  end

  succ
end

#process_requests (private)


22
23
24
25
26
27
28
# File 'lib/dizby/worker/connection.rb', line 22

def process_requests
  loop { break unless process_request }
rescue RemoteServerShutdown
  @server.log.debug("lost connection to server at #{@conn.remote_uri}")
ensure
  @conn.close unless @conn.closed?
end