Package dev.getelements.elements.sdk
Interface ElementRegistry
- All Superinterfaces:
AutoCloseable
- All Known Subinterfaces:
MutableElementRegistry
- All Known Implementing Classes:
ElementScopedElementRegistry,RootElementRegistry
Represents a registry for
Element instances. Inside an Element, there is a shared registry available
by using the ServiceLoader to find an instance of ElementRegistrySupplier. This provides
access to registries in a hierarchy while allowing for visibility into other Element instances.
When searching the hierarchy, by name, the registry searches for all registered at its level, and then up to the
parent level and so forth until the root level. The Stream returned from the find(String) method
will always return the closest first.
Note, instances of ElementRegistry must be thread-safe and may implement thread safety using a locking
strategy.-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes allElementinstances within thisElementRegistryand closes the registry itself.Gets allElementinstances which was registered to thisElementRegistryspecifying the name of theElementReturns a new subordinate registry.onClose(Consumer<ElementRegistry> onClose) Adds aConsumerto thisElementRegistrywhich will get called when it is closed.Adds aConsumerto thisElementRegistrywhich will get called when anEventis sourced from anElementwithin this registry.voidstream()Streams allElementisntances in thisElementRegistry.
-
Field Details
-
ROOT
A name binding for the rootElementRegistry- See Also:
-
-
Method Details
-
stream
Streams allElementisntances in thisElementRegistry. -
find
Gets allElementinstances which was registered to thisElementRegistryspecifying the name of theElement -
newSubordinateRegistry
MutableElementRegistry newSubordinateRegistry()Returns a new subordinate registry. This registry will be linked to this registry and inherit all currently registeredElements contained in. Searching the new subordinate registry will make all registeredElements available that are available to this registry. The returnedMutableElementRegistrywill receive events from thisElementRegistryand forward them along to allElements therein. This allows anElementto load private instances as it sees fit without affecting its parent's hierarchy and thus enforcing encapsulation.- Returns:
- a new subordinate
-
publish
- Parameters:
event- the event
-
onEvent
Adds aConsumerto thisElementRegistrywhich will get called when anEventis sourced from anElementwithin this registry.- Parameters:
onEvent- the event consumer- Returns:
- a
Subscriptionto the event
-
onClose
Adds aConsumerto thisElementRegistrywhich will get called when it is closed.- Parameters:
onClose- the on close consumer- Returns:
- a
Subscriptionto the event
-
close
void close()Closes allElementinstances within thisElementRegistryand closes the registry itself.- Specified by:
closein interfaceAutoCloseable
-