note description : "A simple node that receives messages from the partnernode `generator'." date : "$Date$" revision : "$Revision$" class RECEIVER inherit A_NODE redefine register_message_handlers end A_GENERAL_CONSTANTS A_EXAMPLE_CONSTANTS create make feature -- Access Peer_description: STRING = "A simple node that echoes received messages." -- Node's peer description name: STRING = "Echo simple client" version: STRING = "$Revision$" feature {NONE} -- Callbacks display_simple_message (a_msg: A_MESSAGE) require a_msg_set: a_msg /= Void do print ("--------------------%N") if attached {A_EXAMPLE_SIMPLE_MESSAGE} a_msg as simple_msg then print ("Received A_EXAMPLE_SIMPLE_MESSAGE%N%N") print("field_boolean: " + simple_msg.field_boolean.value.out + "%N") print("field_double: " + simple_msg.field_double.value.out + "%N") print("field_integer: " + simple_msg.field_integer.value.out + "%N") print("field_string: " + simple_msg.field_string + "%N") else -- error print("*** ERROR in display_simple_message - wrong message type ***%N"); end end display_extended_message (a_msg: A_MESSAGE) require a_msg_set: a_msg /= Void local l_string: STRING do print ("--------------------%N") if attached {A_EXAMPLE_SIMPLE_EXTENDED_MESSAGE} a_msg as extended_msg then print ("Receicved A_EXAMPLE_SIMPLE_EXTENDED_MESSAGE%N%N") print("field_boolean: " + extended_msg.field_boolean.value.out + "%N") print("field_double: " + extended_msg.field_double.value.out + "%N") print("field_integer: " + extended_msg.field_integer.value.out + "%N") print("field_string: " + extended_msg.field_string.value + "%N") create l_string.make_empty l_string.from_c_substring (extended_msg.field_binary.value.item, 1, extended_msg.field_binary.value.count) print("field_binary: " + l_string + "%N") else -- error print("*** ERROR in display_simple_message - wrong message type ***%N"); end end display_special_message (a_msg: A_MESSAGE) require a_msg_set: a_msg /= Void do print ("--------------------%N") if attached {A_EXAMPLE_SPECIAL_MESSAGE} a_msg as special_msg then print ("Received A_EXAMPLE_SPECIAL_MESSAGE%N%N") print("field_double_one: " + special_msg.field_double_one.value.out + "%N") print("field_double_two: " + special_msg.field_double_two.value.out + "%N") print("field_unicode: " + special_msg.field_unicode.value.out + "%N") else -- error print("*** ERROR in display_simple_message - wrong message type ***%N"); end end display_complex_message (a_msg: A_MESSAGE) require a_msg_set: a_msg /= Void local l_string: STRING l_array_integer: DS_ARRAYED_LIST[A_INTEGER_VALUE] l_array_boolean: DS_ARRAYED_LIST[A_BOOLEAN_VALUE] l_map_double: DS_HASH_TABLE[A_DOUBLE_VALUE, A_STRING_VALUE] l_map_string: DS_HASH_TABLE[A_STRING_VALUE, A_STRING_VALUE] l_array_array: DS_ARRAYED_LIST[A_SEQUENCE_VALUE[A_INTEGER_VALUE]] l_inner_array: DS_ARRAYED_LIST[A_INTEGER_VALUE] l_map_map: DS_HASH_TABLE[A_MAP_VALUE[A_DOUBLE_VALUE], A_STRING_VALUE] l_inner_map: DS_HASH_TABLE[A_DOUBLE_VALUE, A_STRING_VALUE] l_array_map: DS_ARRAYED_LIST[A_MAP_VALUE[A_STRING_VALUE]] l_inner_string_map: DS_HASH_TABLE[A_STRING_VALUE, A_STRING_VALUE] l_map_array: DS_HASH_TABLE[A_SEQUENCE_VALUE[A_BOOLEAN_VALUE], A_STRING_VALUE] l_inner_boolean_array: DS_ARRAYED_LIST[A_BOOLEAN_VALUE] l_nested_map: DS_HASH_TABLE[A_EXAMPLE_NESTED_MESSAGE_MESSAGE, A_STRING_VALUE] l_nested: A_EXAMPLE_NESTED_MESSAGE_MESSAGE do print ("--------------------%N") if attached {A_EXAMPLE_COMPLEX_MESSAGE} a_msg as complex_msg then print ("Received A_EXAMPLE_COMPLEX_MESSAGE%N%N") print("field_integer: " + complex_msg.field_integer.value.out + "%N") print("field_boolean: " + complex_msg.field_boolean.value.out + "%N") print("field_string: " + complex_msg.field_string.value + "%N") print("field_double: " + complex_msg.field_double.value.out + "%N") create l_string.make_empty l_string.from_c_substring (complex_msg.field_binary.value.item, 1, complex_msg.field_binary.value.count) print("field_binary: " + l_string + "%N") print("field_array_integer: ") l_array_integer := complex_msg.field_array_integer.sequence from l_array_integer.start until l_array_integer.after loop print("[" + l_array_integer.item_for_iteration.out + "]") -- Increment l_array_integer.forth end print("%N") print("field_array_boolean: ") l_array_boolean := complex_msg.field_array_boolean.sequence from l_array_boolean.start until l_array_boolean.after loop print("[" + l_array_boolean.item_for_iteration.out + "]") -- Increment l_array_boolean.forth end print("%N") print("field_map_double: ") l_map_double := complex_msg.field_map_double.map from l_map_double.start until l_map_double.after loop print("[" + l_map_double.key_for_iteration.out + " => " + l_map_double.item_for_iteration.out + "]") -- Increment l_map_double.forth end print("%N") print("field_map_string: ") l_map_string := complex_msg.field_map_string.map from l_map_string.start until l_map_string.after loop print("[" + l_map_string.key_for_iteration.out + " => " + l_map_string.item_for_iteration.out + "]") -- Increment l_map_string.forth end print("%N") print("field_array_array:%N") l_array_array := complex_msg.field_array_array.sequence from l_array_array.start until l_array_array.after loop l_inner_array := l_array_array.item_for_iteration.sequence print("%T") from l_inner_array.start until l_inner_array.after loop print("[" + l_inner_array.item_for_iteration.out + "]") -- increment l_inner_array.forth end print("%N") -- Increment l_array_array.forth end print("%N") print("field_map_map:%N") l_map_map := complex_msg.field_map_map.map from l_map_map.start until l_map_map.after loop print("%T" + l_map_map.key_for_iteration.out + " => ") l_inner_map := l_map_map.item_for_iteration.map from l_inner_map.start until l_inner_map.after loop print("[" + l_inner_map.key_for_iteration.out + " => " + l_inner_map.item_for_iteration.out + "]") -- increment l_inner_map.forth end print("%N") -- Increment l_map_map.forth end print("%N") print("field_array_map:%N") l_array_map := complex_msg.field_array_map.sequence from l_array_map.start until l_array_map.after loop l_inner_string_map := l_array_map.item_for_iteration.map print("%T") from l_inner_string_map.start until l_inner_string_map.after loop print("[" + l_inner_string_map.item_for_iteration.out + "]") -- increment l_inner_string_map.forth end print("%N") -- Increment l_array_map.forth end print("%N") print("field_map_array:%N") l_map_array := complex_msg.field_map_array.map from l_map_array.start until l_map_array.after loop l_inner_boolean_array := l_map_array.item_for_iteration.sequence print("%T") from l_inner_boolean_array.start until l_inner_boolean_array.after loop print("[" + l_inner_boolean_array.item_for_iteration.out + "]") -- increment l_inner_boolean_array.forth end print("%N") -- Increment l_map_array.forth end print("%N") print("field_nested:%N") l_nested_map := complex_msg.field_nested.map from l_nested_map.start until l_nested_map.after loop l_nested := l_nested_map.item_for_iteration print("%Topen: " + l_nested.open.out + "%Tclosed: " + l_nested.closed.out + "%N") -- Increment l_nested_map.forth end print("%N") else -- error print("*** ERROR in display_simple_message - wrong message type ***%N"); end end feature {NONE} -- Implementation register_message_handlers -- Register message handlers. do Precursor register_message_handler (example_namespace, example_simple_type, agent display_simple_message) register_message_handler (example_namespace, example_simple_extended_type, agent display_extended_message) register_message_handler (example_namespace, example_special_type, agent display_special_message) register_message_handler (example_namespace, example_complex_type, agent display_complex_message) -- DOES NOT WORK: -- Check with Jann. I suspect it only works when a reply-handler is set in the message. -- register_message_handler (general_namespace, "e2", agent handle_update_reply) end create_msg_factory : A_MESSAGE_FACTORY -- create a new message factory once create Result.make end end