INanoServiceRegistry
The nano service registry is a component of each namespace. They provide a collection point for local nano services. A special feature is the nano service registry of the "SYSTEM" namespace. Here, nano services are registered that are not coupled to a node and affect the entire node.
Get the registry
The nano service registry of a namespace can be fetched via the namespace itself.
final INanoserviceRegistry registry = namespace.getNanoServiceRegistry();
Another option is to fetch it from the service registry. A filter then needs to be specified to specify the namespace:
final INanoServiceRegistry registry = CServiceRegistry.getInstance() .getService(INanoServiceRegistry.class, "nid=SYSTEM");
Register a nano service
A nano service can be registered by specifying the service ID (=record ID) and a name or description.
void addNanoService(@NotNull IId aSID, @NotNull String aName) throws CException;
A simpler method is to specify the record class, since both are already included there.
void addNanoService(Class<? extends IGeneratedRecord> aClass) throws CException;
Example:
final INanoServiceRegistry registry = CServiceRegistry.getInstance() .getService(INanoServiceRegistry.class, "nid=SYSTEM"); registry.addNanoService(CRecordNotifyTargetRegistered.class); // or: registry.addNanoService(CIdFactory.fromObject("MySpecialNotification"), "My special notification");
Remove a nano service
Analogous to registration, a nano service can also be deregistered.
void removeNanoService(@NotNull IId aSID) throws CException; void removeNanoService(@NotNull Class<? extends IGeneratedRecord> aClass) throws CException;
Checking whether a nano service exists
It can be checked whether a nano service exists.
boolean existNanoService(@NotNull IId aSID);
Get details
The name or description of the nano service can be fetched. An empty string is returned if no nano service has been registered with this ID.
@NotNull String getName(@NotNull IId aSID);
The number of observers for a given nano service can be determined in this way:
int getObserverCount(@NotNull IId aSID);
It is possible to get more information about a nano service. The passed record must be of type CRecordNanoServiceGetServiceInfo.
void getServiceInfo(@NotNull IId aSID, @NotNull CRecord aRecord) throws CException;
The number of registered nano services is obtained via:
int size();
Adding observers
Observers can be added by specifying the service ID and a target address.
void addObserver(@NotNull IId aSID, @NotNull CTargetAddress aAddress) throws CException;
Nano service always keep the copy of the message that they got last. If you want to receive this message immediately, you can specify this when registering observers. The message is then delivered asynchronously to the observer. This can be useful when the nano service distributes notifications.
void addObserver(@NotNull IId aSID, @NotNull CTargetAddress aAddress, boolean aSendLast) throws CException; void addObserver(@NotNull Class<? extends IGeneratedRecord> aClass, @NotNull CTargetAddress aAddress, boolean aSendLast) throws CException;
It is possible to register several observers with one call.
void addObservers(@NotNull IId[] aSID, @NotNull CTargetAddress aAddress) throws CException;
Here you can also specify whether a copy of the last message is desired.
void addObservers(@NotNull IId[] aSID, @NotNull CTargetAddress aAddress, boolean aSendLast) throws CException;
Observer removal
Observers can also be removed again.
void removeObserver(@NotNull IId aSID, @NotNull CTargetAddress aObserver) throws CException; void removeObserver(@NotNull Class<? extends IGeneratedRecord> aClass, @NotNull CTargetAddress aAddress) throws CException;
There is another method that can be used to remove all observers of a target in one go.
void removeObservers(@NotNull CTargetAddress aObserver) throws CException;
All observers of a nano service can be removed at once.
void removeAllObserver(@NotNull IId aSID) throws CException;
Simultaneous registration of Nano service and Observer
There are two methods to register nano service and observer at the same time.
void addNanoServiceAndObserver(@NotNull IId aSID, @NotNull String aName, @NotNull CTargetAddress aAddress) throws CException; void addNanoServiceAndObserver(@NotNull Class<? extends IGeneratedRecord> aClass, @NotNull CTargetAddress aAddress, boolean aSendLast) throws CException;
Trigger
You can trigger a nano service without sending a message.
boolean triggerObserver(@NotNull IId aSID, @NotNull CMessage aTemplate) throws CException;
Resending the last message to one or all observers is also possible.
void recallTrigger(@NotNull IId aSID) throws CException; void recallTrigger(@NotNull IId aSID, @Nullable CTargetAddress aAddress) throws CException;
Monitor
There is a monitor support for nano services. You can get the corresponding helper class via the following method:
@NotNull INanoServiceMonitor getNanoServiceMonitor();