CRecordRegisterTarget
With this message a target can be registered.
Notice
If you have direct access to the target registry, it is easier to call the ITargetRegistry.registerTarget() method.
<record id="1685ebe1-b0e4-4560-a3ec-98e8b3968f3f" name="REGISTER_TARGET" isNanoService="true" type="REQUEST">
<description>
Register a target asynchronously.
</description>
<namespaces>SYSTEM</namespaces>
<slot key="nid" name="NAMESPACE_ID" direction="REQUEST" presenceConstraint="MANDATORY" type="ID">
<description>The namespace ID.</description>
</slot>
<slot key="tgt" name="TARGET" direction="REQUEST" presenceConstraint="MANDATORY" type="OBJECT">
<description>The target to register.</description>
</slot>
<slot key="tid" name="TID_WANTED" direction="REQUEST" presenceConstraint="OPTIONAL" type="ID">
<description>Optional: The wanted target ID.</description>
</slot>
<slot key="name" name="NAME" direction="REQUEST" presenceConstraint="OPTIONAL" type="STRING">
<description>Optional: A name for the target, which will be registered in the name database.</description>
</slot>
<slot key="adr" name="ADDRESS" direction="RESPONSE" presenceConstraint="OPTIONAL" type="TARGET_ADDRESS">
<description>The target address on success.</description>
</slot>
</record>
Example of use of the class CRecordRegisterTarget (after
private void registerTarget(@NotNull final ITarget aTarget,
@NotNull final IId aNID,
@NotNull final String aName,
@NotNull final IId aTargetId) throws CException
{
final CEnvelope env = CEnvelope.forLocalNanoService(CWellKnownNID.SYSTEM);
final CRecord record = CRecordRegisterTarget.create();
CRecordRegisterTarget.setNamespaceId(record,
aNID);
CRecordRegisterTarget.setName(record,
aName);
CRecordRegisterTarget.setTarget(record,
aTarget);
// optional:
CRecordRegisterTarget.setTidWanted(record,
aTargetId);
sendRequest(env,
record);
}
To catch the reply, we need a message handler. We add it in the constructor of the message handler registry.
// constructor:
addMessageHandler(CRecordRegisterTarget.ID,
this::asyncRegisterTarget);
The message is handled in the local method asyncRegisterTarget:
private boolean asyncRegisterTarget(@NotNull final CEnvelope aEnvelope,
@NotNull final CRecord aRecord)
{
if (aEnvelope.isAnswer())
{
final int rc = aEnvelope.getResultCode();
if (rc == CResultCode.SUCCESS)
{
final CTargetAddress address = CRecordRegisterTarget.getAddress(aRecord,
null);
// ...
}
return true;
}
return false;
}