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.



    
        Register a target asynchronously.
    

    SYSTEM

    
        The namespace ID.
    

    
        The target to register.
    

    
        Optional: The wanted target ID.
    

    
        Optional: A name for the target, which will be registered in the name database.
    

    
        The target address on success.
    


Example of use of the class CRecordRegisterTarget (after generating)

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;
}