Class: Server::EventServer

Inherits:
EM::Connection
  • Object
show all
Includes:
Checker
Defined in:
lib/apprentice/server.rb

Overview

The actual EM::Connection instance referenced by the EventServer class. Notice that we use Mysql2::Client::EM instead of the regular Mysql2::Client class.

Constant Summary

Constants included from Checker

Checker::CODES

Instance Method Summary collapse

Methods included from Checker

#format_text, #generate_response

Constructor Details

#initialize(options) ⇒ EventServer

:nodoc:



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/apprentice/server.rb', line 11

def initialize(options) #:nodoc:
  @ip = options.ip
  @port = options.port
  @sql_port = options.sql_port
  @server = options.server
  @user = options.user
  @password = options.password
  @donor_allowed = options.donor_allowed
  @type = options.type
  @threshold = options.threshold
  @status = {}
end

Instance Method Details

#receive_data(data) ⇒ Object

Take the raw data received on @port and run initiate the checks against the server located at @server

Special conditions

We are sending something to our client with #send_data inside the function, depending on what #run_checks returned to us during the function call.

Attributes

  • data - We receive the actual HTTP request but since we’re not a full blown HTTP server we don’t actually use it to any extent



33
34
35
36
37
# File 'lib/apprentice/server.rb', line 33

def receive_data(data)
  response = run_checks
  response_text = format_text(response[:text])
  send_data generate_response(response[:code], response_text)
end