Class: DRbQS::Server::Message
- Inherits:
-
Object
- Object
- DRbQS::Server::Message
show all
- Includes:
- Misc
- Defined in:
- lib/drbqs/server/message.rb
Constant Summary
Constants included
from Misc
Misc::STRINGS_FOR_KEY
Instance Method Summary
collapse
Methods included from Misc
create_logger, create_uri, output_error, process_running_normally?, random_key, time_to_history_string, time_to_history_string2, uri_drbunix
Constructor Details
#initialize(message, logger = DRbQS::Misc::LoggerDummy.new) ⇒ Message
Returns a new instance of Message.
Instance Method Details
#check_connection ⇒ Object
77
78
79
80
81
82
83
84
85
|
# File 'lib/drbqs/server/message.rb', line 77
def check_connection
deleted = @node_list.delete_not_alive
@logger.info("IDs of deleted nodes") { deleted } if deleted.size > 0 && @logger
@node_list.each do |id, str|
@message.write([id, :alive_p])
end
@node_list.set_check_connection
deleted
end
|
#each_node_history(&block) ⇒ Object
124
125
126
|
# File 'lib/drbqs/server/message.rb', line 124
def each_node_history(&block)
@node_list.history.each(&block)
end
|
#get_all_nodes ⇒ Object
152
153
154
|
# File 'lib/drbqs/server/message.rb', line 152
def get_all_nodes
@node_list.list.dup
end
|
#get_message ⇒ Array
One of the following messages is returned.
- [:exit_server, nil]
- [:request_status, nil]
- [:request_history, nil]
- [:exit_after_task, node_id]
- [:wake_node, node_id]
- [:sleep_node, node_id]
- [:node_error, [node_id, error_message]]
- [:initialize, Array]
- [:finalize, Array]
27
28
29
30
31
32
33
34
|
# File 'lib/drbqs/server/message.rb', line 27
def get_message
begin
mes = @message.take([:server, Symbol, nil], 0)
manage_message(*mes[1..2])
rescue Rinda::RequestExpiredError
nil
end
end
|
#node_exist?(node_id) ⇒ Boolean
160
161
162
|
# File 'lib/drbqs/server/message.rb', line 160
def node_exist?(node_id)
@node_list.exist?(node_id)
end
|
#node_not_exist? ⇒ Boolean
156
157
158
|
# File 'lib/drbqs/server/message.rb', line 156
def node_not_exist?
@node_list.empty?
end
|
#send_exit ⇒ Object
Send all nodes a message to exit.
102
103
104
|
# File 'lib/drbqs/server/message.rb', line 102
def send_exit
send_signal_to_all_nodes(:exit)
end
|
#send_exit_after_task(node_id) ⇒ Object
119
120
121
122
|
# File 'lib/drbqs/server/message.rb', line 119
def send_exit_after_task(node_id)
@node_list.add_to_preparation_to_exit(node_id)
send_signal(node_id, :exit_after_task)
end
|
#send_finalization ⇒ Object
Send all nodes a message to finalize and exit.
115
116
117
|
# File 'lib/drbqs/server/message.rb', line 115
def send_finalization
send_signal_to_all_nodes(:finalize)
end
|
#send_history(history_string) ⇒ Object
144
145
146
147
148
149
150
|
# File 'lib/drbqs/server/message.rb', line 144
def send_history(history_string)
begin
@message.take([:history, nil], 0)
rescue Rinda::RequestExpiredError
end
@message.write([:history, history_string])
end
|
#send_only_response(sender_id, request_time) ⇒ Object
136
137
138
139
140
141
142
|
# File 'lib/drbqs/server/message.rb', line 136
def send_only_response(sender_id, request_time)
begin
@message.take([:response, sender_id, nil], 0)
rescue Rinda::RequestExpiredError
end
@message.write([:response, sender_id, request_time])
end
|
#send_sleep(node_id) ⇒ Object
106
107
108
|
# File 'lib/drbqs/server/message.rb', line 106
def send_sleep(node_id)
send_signal(node_id, :sleep)
end
|
#send_status(server_status_string) ⇒ Object
128
129
130
131
132
133
134
|
# File 'lib/drbqs/server/message.rb', line 128
def send_status(server_status_string)
begin
@message.take([:status, nil], 0)
rescue Rinda::RequestExpiredError
end
@message.write([:status, server_status_string])
end
|
#send_wake(node_id) ⇒ Object
110
111
112
|
# File 'lib/drbqs/server/message.rb', line 110
def send_wake(node_id)
send_signal(node_id, :wake)
end
|
#set_finalization_tasks(task_ary) ⇒ Object
183
184
185
|
# File 'lib/drbqs/server/message.rb', line 183
def set_finalization_tasks(task_ary)
set_special_task(:finalize, *task_ary)
end
|
#set_initialization_tasks(task_ary) ⇒ Object
If the task has already set,
the method overwrite old task of initialization by new task.
179
180
181
|
# File 'lib/drbqs/server/message.rb', line 179
def set_initialization_tasks(task_ary)
set_special_task(:initialize, *task_ary)
end
|
#shutdown_unused_nodes(calculating_nodes) ⇒ Object
187
188
189
190
191
192
193
194
195
196
|
# File 'lib/drbqs/server/message.rb', line 187
def shutdown_unused_nodes(calculating_nodes)
shutdown_nodes = []
@node_list.each do |node_id, id_str|
if !@node_list.prepare_to_exit?(node_id) && !calculating_nodes.include?(node_id)
send_exit_after_task(node_id)
shutdown_nodes << node_id
end
end
shutdown_nodes
end
|