Class: Rapid::Baps::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/ury_rapid/baps/client.rb

Overview

A high-level representation of a client on the legacy BAPS server

The BAPS service connects to the BAPS server as a regular client on TCP sockets. The actual reading and writing is done by objects controlled by the Client, which attaches to an input responder and output queue.

Instance Method Summary collapse

Constructor Details

#initialize(queue, logger, hostname, port) ⇒ Client

Creates a BAPS client

Examples:

Creating a BAPS client.

queue = EventMachine::Queue.new
client = Rapid::Baps::Client.new(queue, 'localhost', 1234)

Parameters:

  • queue (Queue)

    The requests queue that will connect to this client.

  • logger (Logger)

    The logger, for logging error messages.

  • hostname (String)

    The host of the BAPS server to which this Client will connect.

  • port (Fixnum)

    The port of the BAPS server to which this Client will connect.


31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ury_rapid/baps/client.rb', line 31

def initialize(queue, logger, hostname, port)
  @hostname = hostname
  @port = port

  @channel = EventMachine::Channel.new
  @reader = Reader.new
  @parser = Responses::Parser.new(@channel, @reader)
  @queue = queue

  @connection_args = [@reader, @queue, logger]
end

Instance Method Details

#run(responder) ⇒ void

This method returns an undefined value.

Runs the client

Examples:

Running a client with a responder.

responder = Responder.new(model, queue)
EventMachine.run do
  # ...
  client.run(responder)
  # ...
end

Parameters:

  • responder (Responder)

    The controller that should be registered to handle any responses coming from this client.


59
60
61
62
63
# File 'lib/ury_rapid/baps/client.rb', line 59

def run(responder)
  responder.register(@channel)
  @parser.start
  connect
end