Module: Roma::Client::Proxy::ClientHandler

Defined in:
lib/roma/client/proxy/daemon.rb

Overview

module RomaHandler

Instance Method Summary collapse

Instance Method Details

#get_roma_handler(cmd_line) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/roma/client/proxy/daemon.rb', line 63

def get_roma_handler(cmd_line)
  cmd, key_hname = cmd_line.split(' ')
  key, hname = key_hname.split("\e")
  nid, d = Daemon::rttable.search_node(key)
  Conpool::instance.get_connection(nid, RomaHandler)
rescue =>e
  $log.error("#{e} #{$@}")
end

#post_initObject



34
35
36
37
# File 'lib/roma/client/proxy/daemon.rb', line 34

def post_init
  $log.info("Connected from client")
  @cmd = ''
end

#receive_data(data) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/roma/client/proxy/daemon.rb', line 39

def receive_data(data)
  @cmd << data
  if @cmd.index("\n")
    @roma_h = get_roma_handler(@cmd)
    @roma_h.send_data(@cmd)
    @cmd = ''
    EM::enable_proxy(self, @roma_h)
    EM::enable_proxy(@roma_h, self)
  end
rescue =>e
  $log.error("#{e} #{$@}")
end

#unbindObject



52
53
54
55
56
57
58
59
60
61
# File 'lib/roma/client/proxy/daemon.rb', line 52

def unbind
  $log.info("Disconnected from client")
  EM::disable_proxy(self)
  if @roma_h
    EM::disable_proxy(@roma_h)
    Conpool::instance.return_connection(@roma_h)
  end
rescue =>e
  $log.error("#{e} #{$@}")
end