Slots

In addition to the value, a slot also holds the type of data so that it can be unpacked on a remote system. It is possible to register your own slot classes. However, it is strongly recommended that you do not do this, as compatibility with other clients and tools is avoided. We reserve the option to offer further slot types in later versions of devel. one.

The following slot types are currently available:

  • BYTE: A byte (byte).
  • BYTEARRAY: a byte Array (byte[]).
  • CHAR: A character (char).
  • CHARARRAY: A character Array (char[]).
  • BOOLEAN: A Boolean (boolean).
  • BOOLEANARRAY: A Boolean Array (boolean[]).
  • SHORT: A Short integer (short).
  • SHORTARRAY: A Short Integer Array (short[]).
  • INT: An Integer (int).
  • INTARRAY: An Integer Array (int[]).
  • LONG: A Long Integer (long).
  • LONGARRAY: A Long Integer Array (long[]).
  • FLOAT: A Float (float).
  • FLOATARRAY: A Float Array (float[]).
  • DOUBLE: A Double (double).
  • DOUBLEARRAY: A Double Array (double[]).
  • STRING: A String (String, im Stream UTF-8).
  • STRINGARRAY: A String Array (String[], im Stream UTF-8).
  • ID: An ID (IId).
  • IDARRAY: An ID Array (IId[]).
  • NODEID: A NODE ID (INodeID).
  • NODEIDARRAY: A NODE ID Array (INodeID[]).
  • TARGETADDRESS: A Target Address (ITargetAddress).
  • TARGETADDRESSARRAY: A Target Address Array (ITargetAddress[]).
  • UUID: An UUID (UUID).
  • UUIDARRAY: An UUID Array (UUID[]).
  • RECORD: A Record (CRecord).
  • RECORDARRAY: A Record Array (CRecord[]).
  • MESSAGE: A Message (IMessage).
  • OBJECT: An Object (Object - not routeable, only local use).
  • COLOR: A Color object (Color)
  • BITFILED: A bit field (CBitField)

The slot classes offer methods for storing and retrieving the slot data in streams, strings, lists, etc. This is done as efficiently as possible to speed up message parsing and minimize the space requirement of a message. In addition to the value, the slot type and the data length are also transported in the stream. The latter is necessary to be able to skip unknown types when reading from the stream.

The slot types are listed as CSlotType``objects in the class ``CCommonSlotType.

Most slot classes are immutable. For example, a copy of the array is created for arrays. An exception is again the type OBJECT.

Slots implement the interface ISlot. The following methods are available:

// Make a copy
ISlot getCopy();

CSlotType getType();

Object getValue();

// A comparison method
boolean isContentEqualTo(Object aValue);

// the usual I/O method
void toStream(DataOutputStream aStream) throws IOException;

// An utility method for writing to XML files
void valueToList(List<String> aList);

String valueToString();

Slots are created by the SlotFactory.

When using static access classes, such as those created by the Record-Generator from XML message descriptions, there is no need to handle slots. The use of these classes is type safe and very simple:

final IId nid = CRecordRegisterMessageLogger.getNID();
final CEnvelope env = new CEnvelope(nid);

final CRecord rec = CRecordRegisterMessageLogger.create();
CRecordRegisterMessageLogger.setParamObserver(rec, getAddress());
CRecordRegisterMessageLogger.setParamReceiverFilter(rec, aFilter);

sendNotification(env, rec);

The access methods are then uniquely named (setParam**Observer**()). The methods only accept typed values (and not general objects). The handling of slots and slot keys remains hidden.

Slot Keys

The SlotKeys consist of two IDs:

  • the Key ID
  • the Key type

In principle, one key would be sufficient to access the slots. However, if you use two keys, you can name the same slot types with different IDs or implement a naming scheme à la “PATH/Key=Value”. The key is still space-saving because a single byte in the stream indicates an empty or occupied ID in the key.

The Slot Factory

Since the different types of slots have to be registered with their factories, there is a SlotFactory. The slot factory can be accessed via target, namespace or kernel:

ISlotFactory getSlotFactory();

The SlotFactory has several methods for creating slots:

// Creates a slot of the specified type with default data.
ISlot create(CSlotType aType) throws CException;

// Creates a slot of the specified type using the data provided.
ISlot create(CSlotType aType,
             Object aValue) throws CException;

// Lets the framework decide which SlotType fits to the data.
ISlot create(Object aValue);

// Reads a slot from a stream.
ISlot createFromStream(DataInputStream aStream) throws IOException;

There are also methods for creating SlotKeys there:

// Creates a slot key from two IDs
ISlotKey createSlotKeyById(IId aKeyType,
                           IId aKeyId);

// Creates a slot key from a data object (integer, string, UUID)
ISlotKey createSlotKeyByObject(Object aKeyType);

// Creates a slot key from two data objects (Integer, String, UUID)
ISlotKey createSlotKeyByObject(Object aKeyType,
                               Object aKeyId);

// Reads a slot key from a stream
ISlotKey createSlotKeyByStream(DataInputStream aStream) throws IOException;

// Reads a slot key from a string. The string is structured like this:
// "TTTTT|IIIIII", where T is the key type and I is the key id
ISlotKey createSlotKeyByString(String aValue);

Example:

ISlotKey key = getSlotFactory().create("path", "key");
ISlot slot = getSlotFactory().create(CCommonSlotType.INT, 175);
aRecord.addSlot(key, slot);