IRecordHelper
Record Helper is a service for easier handling of records and nano services. It provides methods for registering nano services and observers, removing observers, and returns the namespace ID to which a nano service belongs.
Getting the service
The service is available through the local service registry.
final IRecordHelper helper = CServiceRegistry.getInstance() .getService(IRecordHelper.class);
As always, make sure that the service starter of your package has a dependency on the helper service to ensure that the service already exists.
Register nano services and observers
This method registers a service and immediately adds an observer. If the service already existed, the flag aSendLast ensures that the last message received by the nano service before the call is sent to the new observer.
boolean registerServiceAndAddObserver(@NotNull Class<?> aRecordClass, @NotNull ITarget aTarget, @NotNull INamespace aNamespace, boolean aSendLast) throws CException;
Another method simply adds a new observer to an already existing service.
boolean addObserver(@NotNull Class<?> aRecordClass, @NotNull ITarget aTarget, boolean aSendLast) throws CException;
Remove observers
This method removes an observer.
boolean removeObserver(@NotNull Class<?> aClass, @NotNull ITarget aTarget) throws CException;
Fetch the namespace ID
This method fetches the namespace to which the nano service belongs.
If multiple namespaces are listed in a record (rare), the ID of the first namespace is returned.
If the record is not a nano service, null
is returned.
@Nullable IId getNID(@NotNull Class> aRecordClass) throws CException;
This method also fetches the ID of the namespace to which the nano service belongs.
However, if the nano service is registered in multiple namespaces, this method works differently.
If the nano services is installed in all namespaces (NAMESPACES = *
), then the namespace of the target
is returned.
If no target is specified and the service is registered in all namespaces, the SYSTEM
namespace is
returned.
If the record is not a nano service, null
is returned.
@Nullable IId getNID(@NotNull Class<?> aRecordClass, @NotNull ITarget aTarget) throws CException