Class: ManqodServer
Overview
this file is part of manqod manqod is distributed under the CDDL licence the author of manqod is Dobai-Pataky Balint([email protected])
Constant Summary
Constants included
from Eprint
Eprint::TERM_COLOUR
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from DBSetup
#check_sql_db, #create_conn, #create_sql_db_and_perms, #load_conns, #populate_manqod_db, #remove_conn, #save_conns, #set_conn_variables
Methods included from HeartBeat
#init_HeartBeat, #stop_HeartBeat
Methods included from Eprint
#ecode, #edebug, #eerror, #eeval, #eexception, #efatal, #einfo, #eprint, #ewarn, #getBinding, #report_mail
Constructor Details
Returns a new instance of ManqodServer.
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/ManqodServer.rb', line 11
def initialize(opts)
@starting_up=true
@uri=opts[:bind]
@logdev=opts[:log]
@log_level=opts[:debug]
@report_address=opts[:report]
@path=opts[:path]
@connections_conf=opts[:connections_conf]
@conns=Hash.new
@dbs=Hash.new
@connected_clients=Hash.new
end
|
Instance Attribute Details
#connected_clients ⇒ Object
Returns the value of attribute connected_clients.
23
24
25
|
# File 'lib/ManqodServer.rb', line 23
def connected_clients
@connected_clients
end
|
#dbs ⇒ Object
Returns the value of attribute dbs.
23
24
25
|
# File 'lib/ManqodServer.rb', line 23
def dbs
@dbs
end
|
#starting_up ⇒ Object
Returns the value of attribute starting_up.
24
25
26
|
# File 'lib/ManqodServer.rb', line 24
def starting_up
@starting_up
end
|
#uri ⇒ Object
Returns the value of attribute uri.
23
24
25
|
# File 'lib/ManqodServer.rb', line 23
def uri
@uri
end
|
Instance Method Details
#alive? ⇒ Boolean
155
156
157
|
# File 'lib/ManqodServer.rb', line 155
def alive?
true
end
|
#conn(conn_name) ⇒ Object
66
67
68
|
# File 'lib/ManqodServer.rb', line 66
def conn(conn_name)
@conns[conn_name]
end
|
#conn_list ⇒ Object
70
71
72
73
74
|
# File 'lib/ManqodServer.rb', line 70
def conn_list
@conns.each_pair{|conn_name,conn|
yield conn_name,conn
}
end
|
#default_connection ⇒ Object
76
77
78
79
80
|
# File 'lib/ManqodServer.rb', line 76
def default_connection
dc=nil
@conns.each_pair{|cn,c| dc=c if c.has_key?("client_default") && c["client_default"]}
dc
end
|
#free_conn(conn_name) ⇒ Object
125
126
127
128
129
130
131
|
# File 'lib/ManqodServer.rb', line 125
def free_conn(conn_name)
if @dbs.has_key?(conn_name)
@dbs[conn_name].exit
@dbs.delete(conn_name)
einfo("#{conn_name} freed.")
end
end
|
#init ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/ManqodServer.rb', line 26
def init
ManqodLogger.instance.set_log(@logdev) if @logdev
einfo("setting log level to #{@log_level}")
ManqodLogger.instance.set_level(@log_level) if @log_level
ManqodLogger.instance.set_report_address(@report_address) if @report_address
load_conns
begin
DRb.start_service(@uri,self)
rescue =>err
eerror("starting main server failed: #{err}")
return false
end
@conns.sort{|a,b| a[1]["auto_load_order"] <=> b[1]["auto_load_order"]}.each{|conn|
load_conn(conn[0]) if conn[1]["auto_load"]
}
setup_clients
init_HeartBeat
@starting_up=false
eprint("serving")
DRb.thread.join
einfo("graceful shutdown")
end
|
#load_conn(conn_name) ⇒ Object
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/ManqodServer.rb', line 90
def load_conn(conn_name)
if @conns.has_key?(conn_name)
begin
@conns[conn_name]["key_name"]=conn_name
@conns[conn_name]['pid']=fork{
th=DrbDb.new(@conns[conn_name],@uri)
th.init
}
Process.detach(@conns[conn_name]['pid'])
edebug("forked \"#{conn_name}\" [#{@conns[conn_name]['uri']}](#{@conns[conn_name]['pid']})")
begin
sleep 1
@dbs[conn_name]=DRb::DRbObject.new_with_uri(@conns[conn_name]['uri'])
@dbs[conn_name].state
@dbs[conn_name].setup_client
rescue => err
begin
Process::kill(0,@conns[conn_name]['pid'])
rescue Errno::ESRCH
raise("Process with pid #{@conns[conn_name]['pid']} is dead")
end
ewarn("waiting for startup of #{conn_name} (#{err})")
retry
end while @dbs[conn_name].state != DrbDb::SERVING
rescue =>err
eerror("error starting connection:#{conn_name} #{err}, retrying")
sleep 1
retry
end
end
end
|
#register_client(client_id, client_object, client_db) ⇒ Object
146
147
148
149
|
# File 'lib/ManqodServer.rb', line 146
def register_client(client_id,client_object,client_db)
@connected_clients[client_id.clone]={:object => client_object, :db => client_db} unless @connected_clients.has_key?(client_id)
einfo("#{client_id} registered to [#{client_db}]")
end
|
#reload_conn(conn_name) ⇒ Object
82
83
84
85
86
87
88
|
# File 'lib/ManqodServer.rb', line 82
def reload_conn(conn_name)
if @conns.has_key?(conn_name)
free_conn(conn_name) if @dbs.has_key?(conn_name)
load_conn(conn_name)
setup_clients
end
end
|
#setup_clients ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/ManqodServer.rb', line 49
def setup_clients
begin
begin
found=false
@dbs.each_value{|drbdb|
unless drbdb.serving?
found = true
sleep 1
end
}
end while found
@dbs.each_pair{|conn_name,drbdb| drbdb.setup_client unless drbdb.client and drbdb.client.alive?}
rescue
end
end
|
#stop ⇒ Object
133
134
135
136
137
138
139
140
141
142
143
144
|
# File 'lib/ManqodServer.rb', line 133
def stop
@dbs.each_key{|dbn|
begin
free_conn(dbn)
rescue =>err
eerror("cannot stop #{dbn}:#{err}")
end
}
current_server.stop_service
einfo("server halted")
exit
end
|
#to_s ⇒ Object
159
160
161
|
# File 'lib/ManqodServer.rb', line 159
def to_s
"ManqodServer"
end
|
#unregister_client(client_id) ⇒ Object
150
151
152
153
|
# File 'lib/ManqodServer.rb', line 150
def unregister_client(client_id)
@connected_clients.delete(client_id)
einfo("#{client_id} unregistered")
end
|