CRecordNotifyTargetRegistered

This nano service is triggered by the TargetRegistry when a new Target is registered.

<record id="42686f64-56d9-40d8-9efc-e4f42e9902fd" name="NOTIFY_TARGET_DEREGISTERED"
        isService="true">

    <description>
        SYSTEM nano service that will be triggered if a target in a namespace (any namespace) has been deregistered.
    </description>

    <namespaces>SYSTEM</namespaces>

    <slot key="1" name="ADDRESS" answer="false" mandatory="true" type="TARGET_ADDRESS">
        <description>Address of the deregistered target.</description>
    </slot>

    <slot key="2" name="NAME" answer="false" mandatory="true" type="STRING">
        <description>Name of the target, if available via name database.</description>
    </slot>

</record>

Example of use of the class CRecordNotifyTargetRegistered (after generating)

This record is a notification nanoservice in the SYSTEM namespace. To get the message when targets are registered, we need to stick an observer to the nanoservice. We do this best in the handler of CRecordStartTarget, which is called when our target is registered:

// constructor:
addMessageHandler(CRecordStartTarget.ID,
                  this::asyncStartTarget);
private boolean asyncStartTarget(@NotNull final CEnvelope aEnvelope,
                                 @NotNull final CRecord aRecord) throws CException
{
    // fetch namespace
    final INamespace namespace = mDependencies.getNamespaceRegistry()
                                              .getNamespace(CWellKnownNID.SYSTEM);
    assert namespace != null;

    // fetch nanoservice registry
    final INanoServiceRegistry nsr = namespace.getNanoServiceRegistry();

    // add observer
    nsr.addObserver(CRecordNotifyTargetRegistered.class,
                    getAddress(),
                    false);

    aEnvelope.setResultSuccess();
    return true;
}

Okay, now we need the handler for the CRecordNotifyTargetRegistered message:

// constructor:
addMessageHandler(CRecordNotifyTargetRegistered.ID,
                  this::asyncNotifyTargetRegistered);
private boolean asyncNotifyTargetRegistered(@NotNull final CEnvelope aEnvelope,
                                            @NotNull final CRecord aRecord)
{
    if (!aEnvelope.isAnswer())
    {
        final CTargetAddress address = CRecordNotifyTargetRegistered.getAddress(aRecord,
                                                                                null);
        final String name = CRecordNotifyTargetRegistered.getName(aRecord,
                                                                  "");
        final String simpleClassName = CRecordNotifyTargetRegistered.getSimpleClassName(aRecord,
                                                                                        "");
        final String className = CRecordNotifyTargetRegistered.getClassName(aRecord,
                                                                            "");
        final IId queueId = CRecordNotifyTargetRegistered.getQueueId(aRecord,
                                                                     null);

        aEnvelope.setResultSuccess();

        return true;
    }
    return false;
}

Well, every time a target is registered in our node, we get this message.