Inspirel banner

Programming Distributed Systems with YAMI4

3.5.3 Java

Simple values (boolean, integer, long and double) can be set with a single operation:

params.setInteger("age", 25);

Above, a new entry named ``age'' is created (or replaces the existing one with the same name) and an integer value 25 is set as its content.

String values are also handled directly:

params.setString("first_name", "John");

The binary values are handled with byte[] array type to describe the data buffer:

byte[] songBuffer = getSongFromSomewhere();

params.setBinary("favorite_song", songBuffer);

In both string and binary cases, the arrays are not copied into the internal storage of the parameters object - in the case of String it is not a problem, since Strings are immutable, but binary buffers are shared and care should be taken to ensure that the buffer contains the intended value at the time when it is used for serialization.

Arrays are handled similarly to binary buffers - that is, array objects of relevant type are used as buffers:

int[] myNumbers = ...;

params.setIntegerArray("favorite_numbers", myNumbers);

Arrays of strings are also handled this way:

String[] friends = {"Alice", "Bob", "Nicole"};

params.setStringArray("friends", friends);

Arrays of binary values are passed as byte[][] buffers.

Nested parameters allow to build some form of hierarchic data structures. Nested parameters objects are just inserted into existing objects as any other type:

Parameters nested = new Parameters();
// ...
params.setNestedParameters("address", nested);

The nested object declared above is a stand-alone object, but after setting it in another object its state is shared (aliased) as with array objects of any type.

The nested object declared above can be used just as any regular parameters object, for example:

nested.setString("street", "Flowery");
nested.setInteger("house_number", 17);

Similar rules apply for nested parameters arrays.

All the example statements in this section filled a single parameters object with six entries (``age'', ``first_name'', ``favorite_song'', ``favorite_numbers'' ``friends'' and ``address''), one them being an array with 3 elements and one being a nested parameters with 2 entries.