Package dev.getelements.elements.sdk
Interface Element
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
GuiceSdkElement
,SharedElement
Represents an instance of an SDK Element, similar to a java
Element
but with more flexibility at the expense
of the rigid encapsulation rules. An Element
has the following properties:
- A unique name, which can be inherited from the package name.
- A set of exposed or provided services, which may or may not explicitly be defined in the Element itself
- Its own
ClassLoader
which isolates it from the rest of the classpath (with some exceptions) - A set of properties, defined by
Attributes
- A
ServiceLocator
which exposes its internally managed services and manages their lifecycle
Element
may be implemented using those. In fact, the default implementation
uses Guice to manage the lifecycle. However, those details are kept completely abstract from the author of the
particular Element as it is possible to use any library inside of the Element itself.
Supported features of Elements:
- Unlike Java Modules, they may span multiple Jar files or sources so long as there is a single
ClassLoader
which aggregates all code - Parent-child relationships, where children may inherit from the parent and parents may request resources from children.
- Weak "honor system" encapsulation. There are no restrictions on reflection, so no need to worry about IoC containers needing special consideration.
- Isolation of dependencies of the core Elements product. You can use whatever third party libraries you wish and it will not break the system.
- Greater flexibility in structure. Existing applications do not need to reorganize as Modules if they weren't build that way originally.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes the element and releases any resources associated with the element.Gets theElementDefinitionRecord
which providesGets theElementRegistry
which manages thisElement
.Gets theServiceLocator
associated with this element.void
-
Method Details
-
getElementRecord
ElementRecord getElementRecord()Gets theElementDefinitionRecord
which provides- Returns:
- the name of the element.
-
getServiceLocator
ServiceLocator getServiceLocator()Gets theServiceLocator
associated with this element.- Returns:
- the
ServiceLocator
-
getElementRegistry
ElementRegistry getElementRegistry()Gets theElementRegistry
which manages thisElement
.- Returns:
- the
ElementRegistry
-
publish
Publishes anEvent
to theElement
. All publicElement
instances will receive the event provided that the arguments match the method, or that the method {}- Parameters:
event
-
-
close
void close()Closes the element and releases any resources associated with the element. Future calls to this instance will be undefined and may result in exceptions. The specific behavior is up to the element implementation.- Specified by:
close
in interfaceAutoCloseable
-