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 TypeMethodDescriptionvoid
close()
Closes allElement
instances within thisElementRegistry
and closes the registry itself.Gets allElement
instances which was registered to thisElementRegistry
specifying the name of theElement
Returns a new subordinate registry.onClose
(Consumer<ElementRegistry> onClose) Adds aConsumer
to thisElementRegistry
which will get called when it is closed.Adds aConsumer
to thisElementRegistry
which will get called when anEvent
is sourced from anElement
within this registry.void
stream()
Streams allElement
isntances in thisElementRegistry
.
-
Field Details
-
ROOT
A name binding for the rootElementRegistry
- See Also:
-
-
Method Details
-
stream
Streams allElement
isntances in thisElementRegistry
. -
find
Gets allElement
instances which was registered to thisElementRegistry
specifying the name of theElement
-
newSubordinateRegistry
MutableElementRegistry newSubordinateRegistry()Returns a new subordinate registry. This registry will be linked to this registry and inherit all currently registeredElement
s contained in. Searching the new subordinate registry will make all registeredElement
s available that are available to this registry. The returnedMutableElementRegistry
will receive events from thisElementRegistry
and forward them along to allElement
s therein. This allows anElement
to 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 aConsumer
to thisElementRegistry
which will get called when anEvent
is sourced from anElement
within this registry.- Parameters:
onEvent
- the event consumer- Returns:
- a
Subscription
to the event
-
onClose
Adds aConsumer
to thisElementRegistry
which will get called when it is closed.- Parameters:
onClose
- the on close consumer- Returns:
- a
Subscription
to the event
-
close
void close()Closes allElement
instances within thisElementRegistry
and closes the registry itself.- Specified by:
close
in interfaceAutoCloseable
-