Class: Server::EventServer

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

Constant Summary

Constants included from Checker

Checker::CODES, Checker::STATES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Checker

#format_text, #generate_response

Methods included from Galera

#check_cluster_size, #check_local_state, #check_ready_state, #get_galera_status, #run_checks

Constructor Details

#initialize(options) ⇒ EventServer

Returns a new instance of EventServer.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/apprentice/server.rb', line 9

def initialize(options)
  @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
  @status = {}

  begin
    @client = Mysql2::Client.new(
        host: @server,
        port: @sql_port,
        username: @user,
        password: @password,
        as: :array,
        reconnect: true
    )
  rescue Exception => message
    puts message
    EM.stop_server
  end
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



7
8
9
# File 'lib/apprentice/server.rb', line 7

def client
  @client
end

Instance Method Details

#receive_data(data) ⇒ Object



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

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