CRecordDeregisterTarget
With this message a target can be deregistered.
Notice
If you have direct access to the target, it is easier to call the ITargetRegistry.deregisterTarget() method.
<record id="33f72955-04bb-44e1-8da7-ec660de91244" name="DEREGISTER_TARGET" isService="true">
<description>
Deregister a target asynchronously.
</description>
<namespaces>SYSTEM</namespaces>
<slot key="nid" name="NAMESPACE_ID" answer="false" mandatory="true" type="ID">
<description>The namespace ID.</description>
</slot>
<slot key="tid" name="TARGET_ID" answer="false" mandatory="true" type="ID">
<description>The ID of the target to deregister.</description>
</slot>
</record>
Example of use of the class CRecordDeregisterTarget (after
This method is an example of deregistering a target in its own node.
private void deregisterTarget(@NotNull final IId aNamespaceId,
@NotNull final IId aTargetId) throws CException
{
final CEnvelope env = CEnvelope.forLocalNanoService(CWellKnownNID.SYSTEM);
final CRecord record = CRecordDeregisterTarget.create();
CRecordDeregisterTarget.setNamespaceId(record,
aNamespaceId);
CRecordDeregisterTarget.setTargetId(record,
aTargetId);
sendRequest(env,
record);
}
This method is an example of deregistering a target in a remote node. The ID of the node is also required for this.
private void deregisterRemoteTarget(@NotNull final CNodeId aNodeId,
@NotNull final IId aNamespaceId,
@NotNull final IId aTargetId) throws CException
{
final CEnvelope env = CEnvelope.forRemoteNanoService(CWellKnownNID.SYSTEM,
aNodeId);
final CRecord record = CRecordDeregisterTarget.create();
CRecordDeregisterTarget.setNamespaceId(record,
aNamespaceId);
CRecordDeregisterTarget.setTargetId(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(CRecordDeregisterTarget.ID,
this::asyncDeregisterTarget);
private boolean asyncDeregisterTarget(@NotNull final CEnvelope aEnvelope,
@NotNull final CRecord aRecord)
{
if (aEnvelope.isAnswer())
{
final int rc = aEnvelope.getResultCode();
if (rc == CResultCode.SUCCESS)
{
// ...
}
return true;
}
return false;
}