Records¶
Records transportieren die ID sowie die Nutzdaten einer Message. Letztere werden in einer Liste von Slots transportiert.
Folgende Konstruktoren existieren:
CRecord(final IId aId);
CRecord(final CRecord aTemplate);
Zudem gibt es eine Factory-Methode:
static CRecord createFromStream(final DataInputStream aStream) throws IOException;
ID¶
Die ID ist vom Typ IId und kann also aus einem Integer, einem String oder einer UUID bestehen:
IId getId();
void setId(final IId aId);
Zugriff auf die Slots¶
Slots werden im Record in einer Map gehalten. Sie können mit folgenden Methoden gesetzt werden:
// Einzelnen Slot hinzufügen. aKey kann SlotKey oder Bestandteil sein.
ISlot addSlot(final Object aKey,
final ISlot aSlot);
// Übernahme aus einem Template; vorhandene Slots werden vorher gelöscht.
void takeSlots(final CRecord aRecord);
Das Entfernen von Slots ist auch möglich:
void removeSlot(final ISlotKey aKey);
Folgende Zugriffsmethoden existieren:
// aKey kann ein SlotKey sein oder eines seiner Bestandteile
ISlot getSlot(final Object aKey);
// inkl. Überprüfung des Typs; falscher Typ --> Exception
ISlot getSlot(final ISlotKey aKey,
final CSlotType aType) throws CException;
// alle Slots holen
Map<ISlotKey, ISlot> getSlots();
// Prüfen, ob Slot existiert
boolean exist(final ISlotKey aKey);
// Anzahl der Slots
int size();
Für den Zugriff auf den Wert eines Slots gibt es eigene Methoden:
Object getValue(final ISlotKey aKey);
// inkl. Default Wert
Object getValue(final ISlotKey aKey,
final Object aDefaultValue);
// inkl. Überprüfung des Typs; falscher Typ --> Exception
Object getValue(final ISlotKey aKey,
final CSlotType aType) throws CException;
// inkl. Überprüfung des Typs; falscher Typ --> Exception
Object getValue(final ISlotKey aKey,
final CSlotType aType,
final Object aDefaultValue) throws CException;
Hier ist deutlich zu Erkennen, dass ein nicht typisiertes Objekt zurückgegeben wird, was man selber casten muss. Das kann man leicht vermeiden, indem man die statischen Zugriffsklassen des Record-Generators verwendet.
Eine Prüfung des Slot-Typs ist natürlich jederzeit möglich:
CSlotType getSlotType(final ISlotKey aKey);
Oder:
ISlot slot = getSlot(aKey);
CSlotType type = slot.getType();
Das Setzen des Wertes ist auch direkt möglich:
void setValue(final ISlotKey aKey,
final CSlotType aType,
final Object aValue) throws CException;
// im Fehlerfall wird nur geloggt
void setValueSafe(final ISlotKey aKey,
final CSlotType aType,
final Object aValue);
Weitere Methoden¶
Folgende Methoden gibt es noch:
// Die Version ist z.Zt. immer 0
getVersion();
// Das Schreiben in einen Stream
void toStream(final DataOutputStream aStream) throws IOException;
// setzt ID zurück, entfernt alle Slots
void clear();
// Entfernt alle Slots
void clearSlots();