indexing description: "Benchmark slave" license: "MIT license (see ../../../license.txt)" author: "Beat Strasser " date: "$Date$" revision: "$Revision$" class P2P_BENCHMARK_SLAVE inherit P2P_BENCHMARK create make feature -- Access is_master: BOOLEAN is False stop_now: BOOLEAN feature {NONE} -- Implementation start_benchmark is -- Sleep until stop do from until stop_now loop sleep (500000000) end logger.fatal ("benchmark slave: gracefully stopped") end benchmark_message_handler (a_msg: P2P_MESSAGE; a_source, a_destination: P2P_ENDPOINT_ADDRESS) is -- Benchmark message handler do handle_control_command (a_msg) send_reply (a_msg) end handle_control_command (a_msg: P2P_MESSAGE) is -- Handle control commands, if any command require Message_valid: a_msg /= Void local control: P2P_MESSAGE_ELEMENT do control := a_msg.element_by_namespace_and_name (benchmark_element_namespace, benchmark_control) if control /= Void then if control.content.is_equal (benchmark_control_stop) then npg.endpoint_service.prune_service (benchmark_service_name, Void) stop_now := True end end end send_reply (a_msg: P2P_MESSAGE) is -- Handle test message require Message_valid: a_msg /= Void local id, data, newel: P2P_MESSAGE_ELEMENT newmsg: P2P_MESSAGE do -- test message number id := a_msg.element_by_namespace_and_name (benchmark_element_namespace, benchmark_message_id) if id /= Void then -- content data := a_msg.element_by_namespace_and_name (benchmark_element_namespace, benchmark_message_data) if data /= Void then if data.type.is_equal (data.type_textplain_utf8) then logger.debugging ("benchmark slave: Received string message: " + id.content) -- send uppercase string back create newel.make_string (benchmark_element_namespace, benchmark_message_data, Void, data.content.as_upper) -- send message back, if any create newmsg.make newmsg.extend (id) newmsg.extend (newel) logger.debugging ("benchmark slave: Sending back a reply: " + id.content) send_message (newmsg) end end end end end