note description : "A simple node that send messages to the partnernode `receiver'." author : "B. Herlig" date : "$Date$" revision : "$Revision$" class GENERATOR inherit A_NODE redefine main end A_GENERAL_CONSTANTS create make feature main -- Main routine after peer platform is successfully started (main event loop) do main_jobs.force (agent send_simple_message) main_jobs.force (agent send_extended_message) main_jobs.force (agent send_special_message) main_jobs.force (agent send_complex_message) main_jobs.force (agent do is_quit := True end) precursor end send_simple_message local l_simple_message: A_EXAMPLE_SIMPLE_MESSAGE do create l_simple_message.make ( "This is a text-string", 42, True, 2.71828) send_message (l_simple_message, message_receiver) end send_big_message local l_simple_message: A_EXAMPLE_SIMPLE_MESSAGE l_str: STRING do -- send 1 MB of text l_str := "01234567" -- 8 Bytes -- 1 MB = 1024 kb -- = 1'048'576 bytes -- => repeat (1048576 / 8) = 131'072 times l_str.multiply (131072) -- re-use A_SIMPLE_MESSAGE, although we're only interested in the string- and integer-field (64bit INTEGER) of it. create l_simple_message.make ( l_str, 5114113112, True, 2.71828) send_message (l_simple_message, message_receiver) end send_extended_message local l_extended_message: A_EXAMPLE_SIMPLE_EXTENDED_MESSAGE l_string: STRING l_ptr: MANAGED_POINTER do create l_string.make_from_string ("This string is held in binary form") create l_ptr.make_from_pointer (l_string.area.base_address, l_string.count) create l_extended_message.make ( "This is a simple message.", 42, True, 2.71828, l_ptr ) send_message (l_extended_message, message_receiver) end send_special_message local l_special_message: A_EXAMPLE_SPECIAL_MESSAGE l_utf8: UC_UTF8_STRING l_string: STRING l_double_1, l_double_2: DOUBLE do l_double_1 := 1337 l_double_2 := -123.456789e+36 create l_utf8.make_filled_unicode (create {UC_CHARACTER}.make_from_code (0x00AE), 3) l_string := "T%%h%%i%%s is a%N%Ttwo line message with unicode characters here -> " + l_utf8.to_utf8 + " <-" create l_special_message.make ( l_double_1, l_double_2, l_string) send_message (l_special_message, message_receiver) end send_complex_message local l_complex_message: A_EXAMPLE_COMPLEX_MESSAGE -- the arguments l_field_integer: A_INTEGER_VALUE l_field_boolean: A_BOOLEAN_VALUE l_field_string: A_STRING_VALUE l_field_double: A_DOUBLE_VALUE l_field_blob: A_BINARY_VALUE l_field_array_integer: A_SEQUENCE_VALUE[A_INTEGER_VALUE] l_field_array_boolean: A_SEQUENCE_VALUE[A_BOOLEAN_VALUE] l_field_map_double: A_MAP_VALUE[A_DOUBLE_VALUE] l_field_map_string: A_MAP_VALUE[A_STRING_VALUE] l_field_array_array: A_SEQUENCE_VALUE[A_SEQUENCE_VALUE[A_INTEGER_VALUE]] l_field_map_map: A_MAP_VALUE[A_MAP_VALUE[A_DOUBLE_VALUE]] l_field_array_map: A_SEQUENCE_VALUE[A_MAP_VALUE[A_STRING_VALUE]] l_field_map_array: A_MAP_VALUE[A_SEQUENCE_VALUE[A_BOOLEAN_VALUE]] l_field_nested: A_MAP_VALUE[A_EXAMPLE_NESTED_MESSAGE_MESSAGE] -- temporary objects for creating the arguments l_integer_list: DS_ARRAYED_LIST [A_INTEGER_VALUE] l_boolean_list: DS_ARRAYED_LIST [A_BOOLEAN_VALUE] l_double_map: DS_HASH_TABLE[A_DOUBLE_VALUE, A_STRING_VALUE] l_string_map: DS_HASH_TABLE[A_STRING_VALUE, A_STRING_VALUE] l_list_list: DS_ARRAYED_LIST[A_SEQUENCE_VALUE [A_INTEGER_VALUE]] l_map_map: DS_HASH_TABLE[A_MAP_VALUE [A_DOUBLE_VALUE], A_STRING_VALUE] l_utf8: UC_UTF8_STRING str: STRING dbl: DOUBLE bin_str: STRING ptr: MANAGED_POINTER i: INTEGER l_nested_message: A_EXAMPLE_NESTED_MESSAGE_MESSAGE l_ht: DS_HASH_TABLE[A_EXAMPLE_NESTED_MESSAGE_MESSAGE, A_STRING_VALUE] l_ht_boolean: DS_HASH_TABLE[A_STRING_VALUE, A_STRING_VALUE] l_outer_list: DS_ARRAYED_LIST[A_MAP_VALUE[A_STRING_VALUE]] l_inner_ht: A_MAP_VALUE[A_STRING_VALUE] l_outer_ht: DS_HASH_TABLE[A_SEQUENCE_VALUE[A_BOOLEAN_VALUE], A_STRING_VALUE] do create l_field_integer.make (42) create l_field_boolean.make (true) create l_utf8.make_filled_unicode (create {UC_CHARACTER}.make_from_code (0x00AE), 3) str := "T%%h%%i%%s is a%N%Ttwo line message with unicode characters here -> " + l_utf8.to_utf8 + " <-" dbl := -123.456789e+46 create l_field_string.make (str) create l_field_double.make (dbl) -- create some data for the binary bin_str := "This is a string held in binary form!!" create ptr.make_from_pointer (bin_str.area.base_address, bin_str.count) create l_field_blob.make (ptr) create l_integer_list.make_from_array (<< l_field_integer, l_field_integer, l_field_integer >>) create l_field_array_integer.make (l_integer_list) -- l_field_integer := 23 -- l_field_array_integer := << l_field_integer, l_field_integer, l_field_integer >> -- l_field_array_integer := << {A_INTEGER_VALUE}[11] >> -- l_field_integer := {A_INTEGER_VALUE}.adapt(l_field_integer) -- create l_pure_int_list.make (3) -- l_pure_int_list.put_last (23) -- l_pure_int_list.put_last (42) -- l_pure_int_list.put_last (81) -- l_field_array_integer := l_pure_int_list create l_boolean_list.make_from_array (<< l_field_boolean, l_field_boolean, l_field_boolean >>) create l_field_array_boolean.make (l_boolean_list) create l_double_map.make (2) l_double_map.put (l_field_double, l_field_string) create l_field_map_double.make (l_double_map) create l_string_map.make (2) l_string_map.put (l_field_string, l_field_string) create l_field_map_string.make (l_string_map) -- list-list / map-map stuff create l_list_list.make_from_array (<< l_field_array_integer, l_field_array_integer >>) create l_field_array_array.make (l_list_list) create l_map_map.make (2) l_map_map.put (l_field_map_double, create {A_STRING_VALUE}.make("key_string")) l_map_map.put (l_field_map_double, create {A_STRING_VALUE}.make("key_string_2")) create l_field_map_map.make (l_map_map) -- build the nested message from i := 1 create l_ht.make(4) until i > 4 loop create l_nested_message.make (create {A_INTEGER_VALUE}.make (i), create {A_INTEGER_VALUE}.make (2 *i)) l_ht.put (l_nested_message, create {A_STRING_VALUE}.make(i.out)) -- inc i := i + 1 end create l_field_nested.make (l_ht) -- array-map -- create inner map from i := 1 create l_ht_boolean.make(4) create l_outer_ht.make (4) until i > 4 loop l_ht_boolean.put (create {A_STRING_VALUE}.make (i.out), create {A_STRING_VALUE}.make(i.out)) l_outer_ht.put (create {A_SEQUENCE_VALUE[A_BOOLEAN_VALUE]}.make_from_array (<>), create {A_STRING_VALUE}.make(i.out)) -- inc i := i + 1 end create l_inner_ht.make (l_ht_boolean) create l_outer_list.make_from_array (<< create {A_MAP_VALUE[A_STRING_VALUE]}.make (l_ht_boolean), create {A_MAP_VALUE[A_STRING_VALUE]}.make (l_ht_boolean) >>) create l_field_array_map.make (l_outer_list) -- map-array create l_field_map_array.make (l_outer_ht) -- create & send create l_complex_message.make( l_field_integer, l_field_boolean, l_field_string, l_field_double, l_field_blob, l_field_array_integer, l_field_array_boolean, l_field_map_double, l_field_map_string, l_field_array_array, l_field_map_map, l_field_array_map, l_field_map_array, l_field_nested ) send_message (l_complex_message, message_receiver) end feature -- Access name: STRING = "JSON_MESSAGE generator" version: STRING = "$Revision$" message_receiver: STRING = "ARANEA.RECEIVER" feature {NONE} -- Implementation create_msg_factory: A_MESSAGE_FACTORY -- create a new message factory once create Result.make end end