final ITargetRegistry tr = namespace.getTargetRegistry();
final ITargetRegistry tr = CServiceRegistry.getInstance() .getService(ITargetRegistry.class, "nid=SYSTEM");
Inside an already registered target there is also a simple getter:
final ITargetRegistry tr = getTargetRegistry();
Register a target
When a target is registered, it receives an address that is unique in the nyssr.net. Then it can receive messages.
void registerTarget(@NotNull ITarget aTarget) throws CException;
It is also possible to specify any target ID:
void registerTarget(@NotNull ITarget aTarget, @NotNull IId aTID) throws CException;
If multiple threads exist in the namespace, the queue ID of the thread can also be supplied:
void registerTarget(@NotNull ITarget aTarget, @NotNull IId aTID, @NotNull IId aQID) throws CException;
During the registration the following actions are performed:
Call the target method
notifyTargetRegistered. This method is used by CTarget to store the various parameters.
- The target monitor is triggered. Interested targets can register Observer for this, to receive information about newly registered targets.
The nano service CRecordNotifyTargetRegistered is triggered in the namespace
SYSTEM. Interested targets can register Observer for this, to receive information about newly registered targets.
- The message CRecordStartTarget is sent to the target (asynchronously). It is the first message that the target gets. The delivery of the message is always in the thread of the namespace that was specified during registration.
- A LOG debug message is printed with the logger of the TargetRegistry.
Deregistration of a target
Targets can be deregistered at any time, even while a message is being processed.
void deregisterTarget(@NotNull IId aTID); void deregisterTarget(@NotNull ITarget aTarget); void deregisterTarget(@NotNull CTargetAddress aAddress);
Information on targets
Fetching a target can be done via the ID.
Checking whether a target is registered is done with another method:
boolean isTargetRegistered(@NotNull IId aTID);
Even more information about registered targets can be determined. This can be useful if, for example, a list of registered targets is to be displayed in a dialog. The records are of type CRecordDataTargetInfo.
CRecord @NotNull  getTargetInfo(boolean all, @NotNull Collection<IId> requestList) throws CException;
The number of targets registered in the registry can be determined via
Message queues (Threads)
The queue ID to which a target is assigned can easily be found out by using the target ID:
Likewise, the message queue can be fetched:
IMessageQueue getQueue(@NotNull IId aTID);
The following method returns a list of all target IDs assigned to a given queue: