indexing description: "[ gifaspaces hello-world example Eiffel version This is a heavily documented example that illustrates some very basic characteristics of the Eiffel version of the JavaSpaces bindings. ]" status: "See notice at end of class." legal: "See notice at end of class." date: "$Date$" revision: "$Revision$" class APPLICATION inherit EGS_SPACE_FINDER PERSON_MARSHALING ARGUMENTS create make feature Default_Url: STRING is "/./mySpace?NoWriteLease=true" feature -- Initialization make is -- Connect to the proxy an perfrom basic testing local space_proxy: EGS_SPACE_PROXY url: STRING; do print ("---------- hello-world running................%N") if argument_count >= 1 then url := argument (1) else url := Default_URL end -- retrieving a space proxy space_proxy := find_space_by_string (url) if space_proxy /= Void then print ("Connected to: ") print (url) print (" OK!%N") perform_test_person (space_proxy) perform_test_person_1 (space_proxy) else print ("Failed Connecting to: ") print (url) print ("%N") end end perform_test_person (space_proxy: EGS_SPACE_PROXY) is -- Perform tests using provided spase proxy local person, read_result: PERSON ee, template: EGS_EXTERNAL_ENTRY tmp: EGS_ENTRY tmp_lease: EGS_LEASE do print (" ---------- running test person -------------%N") ---------------------------------------------------------------- -- register our Eiffel type with the space -- we use the second argument set to 'true' to introduce -- the type's metadata to the JavaSpace ---------------------------------------------------------------- create person.make_empty ee := marshal (person, True); tmp := space_proxy.snapshot (ee) print ("Did snapshot for Person class%N") ---------------------------------------------------------------- -- writing an object to the space -- the person instance represents our Eiffel data; 'Person' is a pure Eiffel -- data type and will therefore have to be marshalled into a generic -- entry instance. One way to do that is to write a 'marshal' -- method that can perform this task as a reusable utility. ---------------------------------------------------------------- create person.make ("011-1111111", "Kermit the frog") person.set_age (38) person.set_birth_date ("01/01/1967") person.set_height (6.2) person.set_married (True) person.set_phone (1783698583) person.set_weight (200.5); -- Note that now we do not provide the type information. -- The second argument to marshal is False ee := marshal (person, False) tmp_lease := space_proxy.write (ee, Void, 5000000) print ("Wrote a person to space%N") ---------------------------------------------------------------- -- create the template for entries that we'd like to read -- We set just class name to be able to read any object of such -- class ---------------------------------------------------------------- create template.make_from_classname_values ("Person", Void) ---------------------------------------------------------------- -- Read one object from the space -- after the read operation, we end up with a generic entry instance; -- for easier usability, we then call our unmarshal function to -- put the information into a properly types Eiffel instance ---------------------------------------------------------------- tmp := space_proxy.read (template, Void, 5000000) print ("Read a person from space") create read_result.make_empty ee ?= tmp unmarshal (ee, read_result); print ("%NThis person was found in the space%N") print_person (read_result) end print_person (p: PERSON) is -- do print ("id : ") print (p.id) print ("%N") print ("name : ") print (p.name) print ("%N") print ("age : ") print (p.age) print ("%N") print ("birth_date : ") print (p.birth_date) print ("%N") print ("phone : ") print (p.phone) print ("%N") print ("married : ") print (p.is_married) print ("%N") print ("weight : ") print (p.weight) print ("%N") print ("height : ") print (p.height) print ("%N") end perform_test_person_1 (space_proxy: EGS_SPACE_PROXY) is -- Perform tests using provided spase proxy local person, read_result: PERSON_1 ee, template: EGS_EXTERNAL_ENTRY tmp: EGS_ENTRY tmp_lease: EGS_LEASE do print (" --------- running test person_1 ------------%N") ---------------------------------------------------------------- -- register our Eiffel type with the space -- we use the second argument set to 'true' to introduce -- the type's metadata to the JavaSpace ---------------------------------------------------------------- create person.make ee := person.marshal (True); tmp := space_proxy.snapshot (ee) print ("Did snapshot for Person_1 class%N") ---------------------------------------------------------------- -- writing an object to the space -- the person instance represents our Eiffel data; 'Person_1' is a pure Eiffel -- data type and will therefore have to be marshalled into a generic -- entry instance. One way to do that is to write a 'marshal' -- method that can perform this task as a reusable utility. ---------------------------------------------------------------- create person.make person.set_array_of_int_32 (<<1, 2, 3, 4>>) person.set_array_of_int_64 (<<5, 6, 7, 8>>) person.set_array_of_real_32 (<<9, 10, 11, 12>>) person.set_array_of_real_64 (<<14, 15, 16, 17>>) person.set_array_of_boolean (<>) -- Note that now we do not provide the type information. -- The second argument to marshal is False ee := person.marshal (False) tmp_lease := space_proxy.write (ee, Void, 5000000) print ("Wrote a person to space%N") ---------------------------------------------------------------- -- create the template for entries that we'd like to read -- We set just class name to be able to read any object of such -- class ---------------------------------------------------------------- create template.make_from_classname_values ("Person_1", Void) ---------------------------------------------------------------- -- Read one object from the space -- after the read operation, we end up with a generic entry instance; -- for easier usability, we then call our unmarshal function to -- put the information into a properly types Eiffel instance ---------------------------------------------------------------- tmp := space_proxy.read (template, Void, 5000000) print ("Read a person from space") ee ?= tmp create read_result.make_from_entry (ee) print ("%NThis person was found in the space%N") print_person_1 (read_result) end print_person_1 (p: PERSON_1) is -- do print ("array_of_boolean : ") print_array (p.array_of_boolean) print ("array_of_int_32 : ") print_array (p.array_of_int_32) print ("array_of_int_64 : ") print_array (p.array_of_int_64) print ("array_of_real_32 : ") print_array (p.array_of_real_32) print ("array_of_real_64 : ") print_array (p.array_of_real_64) end print_array (array: ARRAY[ANY]) is -- local i: INTEGER do if array = Void then print ("Void") else from i := array.lower until i > array.upper loop if i > 1 then print (" "); end print (array.item (i)) i := i+1 end end print ("%N") end indexing copyright: "Copyright (c) 2008, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" source: "[ Eiffel Software 356 Storke Road, Goleta, CA 93117 USA Telephone 805-685-1006, Fax 805-685-6869 Website http://www.eiffel.com Customer support http://support.eiffel.com ]" end -- class APPLICATION