Class: Af::TCPCommand::Client

Inherits:
Object
  • Object
show all
Includes:
Application::Proxy
Defined in:
lib/fiksu-af/tcp_command/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Application::Proxy

#af_logger, #af_name

Constructor Details

#initialize(server_hostname, server_port) ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
# File 'lib/fiksu-af/tcp_command/client.rb', line 7

def initialize(server_hostname, server_port)
  @server_hostname = server_hostname
  @server_port = server_port
  @client = TCPSocket.new(server_hostname, server_port)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/fiksu-af/tcp_command/client.rb', line 5

def client
  @client
end

#server_hostnameObject (readonly)

Returns the value of attribute server_hostname.



5
6
7
# File 'lib/fiksu-af/tcp_command/client.rb', line 5

def server_hostname
  @server_hostname
end

#server_portObject (readonly)

Returns the value of attribute server_port.



5
6
7
# File 'lib/fiksu-af/tcp_command/client.rb', line 5

def server_port
  @server_port
end

Instance Method Details

#command_dispatcher(line) ⇒ Object



21
22
23
# File 'lib/fiksu-af/tcp_command/client.rb', line 21

def command_dispatcher(line)
  logger.debug_fine "process command: #{line}"
end

#command_readerObject



17
18
19
# File 'lib/fiksu-af/tcp_command/client.rb', line 17

def command_reader
  return client.readline.chomp
end

#loggerObject



13
14
15
# File 'lib/fiksu-af/tcp_command/client.rb', line 13

def logger
  return af_logger(self.class.name)
end

#readyObject



29
30
31
# File 'lib/fiksu-af/tcp_command/client.rb', line 29

def ready
  reply_to_server("ready")
end

#reply_to_server(line) ⇒ Object



25
26
27
# File 'lib/fiksu-af/tcp_command/client.rb', line 25

def reply_to_server(line)
  client.write("#{line}\n")
end

#serveObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/fiksu-af/tcp_command/client.rb', line 33

def serve
  while true
    logger.debug_medium "READY!"
    ready
    begin
      line = command_reader
      logger.debug_fine "working on: #{line}"
      command_dispatcher(line)
    rescue EOFError
      logger.warn "master closed connection: #{client.inspect}"
      client.close
      break
    end
  end
end