Introduction to Everit Component Registry Model Balázs Zsoldos
Jul 04, 2015
Introduction to Everit Component RegistryModel
Balázs Zsoldos
Blueprint+
JPA+
JSF
DeclarativeServices
+ModularizedPersistence
+JSF
ECM+
ModularizedPersistence
+JSF
ECM+
ModularizedPersistence
+Modularized
Web
DeclarativeServices
+JPA
+JSF
Blueprint
iPojo
Declarative Services
Everit Component Model
Blueprint
iPojo
DS
ECM
Monoholitic + Magic
Christmas tree + Magic
KISS
KISS
Blueprint
iPojo
DS
ECM
~ 630Kb
~ 800 Kb
~ 260 Kb
< 200 Kb
Core with dependencies + Proxy impl, without annotations, without ASM
With dependenciesincluding ASM
DeclarativeServices
EveritComponent
Model
Felix SCR
Capability Collector
ECM Metadata
ECM Component
Annotation Set
Annotation Processor
Annotation Set
Annotation → Metadata
Extender
XML
AnnotationAnnotation processor
Declarative Services
XML
Annotation
Development time
Runtime
Metadata
Annotation
ECMComponentcontainer
Metadata
Annotation
ECMComponentcontainer
Runtime
public class TestActivator implements BundleActivator {
private ComponentContainerInstance<MyComponent> componentContainer;
public TestActivator() { // Initialize component container }
public void start(BundleContext bundleContext) throws Exception { componentContainer.open(); }
public void stop(BundleContext context) throws Exception { componentContainer.close(); }
}
Componentcontainer
ComponentContainer
ComponentContainer + [MetatypeProvider] + ManagedService
ComponentContainer + [MetatypeProvider] + ManagedServiceFactory
Registers OSGi service
OR
OR
public interface ComponentContainer<C> {
ComponentRevision[] getComponentRevisions();
ComponentMetadata getComponentMetadata();
BundleContext getBundleContext();
}
ComponentRevision
ComponentWiring
ComponentWire
ServiceCapability
BundleCapability
Resource Wiring Wire Capability
OSGi R5
ECM
ConfigAdminComponent container
Configuration
Configuration
Configuration
Component
Component
Component
ManagedServiceFactoryManagedService
Component
Configuration References
Service Service
@StringAttributeprivate String stringAttribute; public void setStringAttribute(String stringAttribute) { this.stringAttribute = stringAttribute;}
private String stringAttribute;
@StringAttribute public void setStringAttribute(String stringAttribute) { this.stringAttribute = stringAttribute;}
@StringAttribute(dynamic = true) public void setStringAttribute(String[] stringAttribute) { // Do something with the information}
@Component(configurationPolicy = ConfigurationPolicy.FACTORY)@StringAttributes({ @StringAttribute(attributeId = "name"), @StringAttribute(attributeId = "motherName", setter = "setMotherName") })@IntegerAttributes({ @IntegerAttribute(attributeId = "age", optional = true), @IntegerAttribute(attributeId = "dimensions", multiple = ThreeStateBoolean.TRUE, setter = "setDimensions(int[])")})@AttributeOrder({ "name", "age", "dimensions", "motherName" })@Servicepublic class ServletContextComponent {
...
}
Component
Configuration References
Service Service
BundleCapability
OSGi Service
Reference types
logService.target: (implementation=felix)
servlet.clause: loginServlet;filter:=(service.pid=...)
servlet.clause: ...;init_param1=value1;init_param2=value2
Targeting references
@ServiceRef(configurationType = ReferenceConfigurationType.CLAUSE)private Filter[] filters;
@ServiceRef(configurationType = ReferenceConfigurationType.CLAUSE)public void setServlet(ServiceCapabilityHolder[] servletHolders) {}
@ServiceRef(configurationType = ReferenceConfigurationType.CLAUSE)public void setListeners(EventListener[] listeners) {}
Multiplicity
Mutiplicity
Delayed component
Declarative ServicesEverit Component
Model
The activation of the component is delayed until the service is requested.
No
Optionality
Declarative ServicesEverit Component
Model
Component is satisfied even if there is no OSGi service available for the reference
No configuration must be provided for the reference / attribute.
If there is no configuration for a reference, no OSGi service is picked up.
Optionality
Whiteboard extender ServletContextComponent
Authentication Filter
URL Redirect Filter
User Mgmt Servlet
Login Servlet
Authentication Filter
URL Redirect Filter
User Mgmt Servlet
Login Servlet
Whiteboard ECM
Configuration on Service side Configuration on Container and / or on Service side
Services are extended as soon as they are available
Services are extended as soon as all necessary services are available
Ordering based on service.ranking
Ordering based on the configuration of container
public enum ComponentState {
STOPPED, UNSATISFIED, STARTING, ACTIVE,
STOPPING,
FAILED,
FAILED_PERMANENT}
// activate(), Thread
// deactivate(), Thread
// Throwable, restart on configuration change
// Throwable, never restart
Dynamism
Declarative ServicesEverit Component
Model
If the configuration is updated, the component is not restarted.
If a reference is dynamic, the OSGi services can come and go based on the cardinality of the reference.
If any of the dynamic attributes / references are updated, the component is not restarted automatically.
If an OSGi service is that is wired to a reference is unregistered, but there is another one that can be wired, the component is not restarted.
Component failure and restart
● Failure cause– Issue in the component definition (permanent)
– Exception in activate method (temporary)
– Fail called programmatically
● Restart– A non-dynamic attribute or reference is changed
– Restart called programmatically
public interface ComponentContext<C> {
/** * Causes the component to step into the {@link ComponentState#FAILED} or * {@link ComponentState#FAILED_PERMANENT} state. * * @param e * The cause of the failure. * @param permanent * Whether the failure should be permanent or not. In case of * permanent failure, the component will not be restarted until * the bundle that registered the component is updated. */ void fail(Throwable e, boolean permanent);
/** * Causes the restarting of the component. The old instance will be dropped * and a new one will be instantiated. */ void restart();
// Other methods}
@Activatepublic void activate(ComponentContext<Component> componentContext) {
// A funny StackOverflowError componentContext.restart();}
@Activatepublic void activate(ComponentContext<Component> componentContext) {
// Always failing component Exception e = new Exception("I am an evil failure"); componentContext.fail(e, true);}
Component
Configuration References
Service Service
@Component@Servicepublic class TestComponent {
private ServiceRegistration<String> serviceRegistration;
@Activate public void activate(ComponentContext<TestComponent> context) { Hashtable<String, Object> properties = new Hashtable<String, Object>();
serviceRegistration = context.registerService( String.class, "Hello world", properties); }
@Deactivate public void deactivate() { serviceRegistration.unregister(); }}
Metatype extensions
AttributeDefinition
AttributeDefinitionImpl
AttributeMetadataHolder
Metatype Spec.
ECM
Metatype extensions
● String attribute– multiLine (textArea)
● Service Reference (String type)– service interface
● BundleCapability reference (String type)– namespace
Webconsole plugins
ThreadViewer
Configuration
Components view
● Shows the state of the components● Shows the wirings● Link to the configuration● Link to the ThreadViewer plugin if the component
is in STARTING or STOPPING state● Link to the Component Graph plugin● No enable / disable, restart, etc.
Component Graph
● Visual representation of OSGi services and Components
● Only the selected component and its direct wirings are shown
● Walking via the wirings
Jetty components
● Server Component● ServletContext Component● Connector components (Http, SSL, ...)
No magic, no Christmas tree
public long saveUser(String firstName, String lastName) { Objects.requireNonNull(firstName); Objects.requireNonNull(lastName);
return transactionHelper.required(() -> { // Logic that should be implemented return 0l; }); }
@Transactional public long saveUser(String firstName, String lastName) { Objects.requireNonNull(firstName); Objects.requireNonNull(lastName);
// Logic that should be implemented return 0l; }
Capability-collector: https://github.com/everit-org/osgi-capability-collector
ECM Annotation: https://github.com/everit-org/ecm-annotation
ECM Method util: https://github.com/everit-org/ecm-util-method
ECM Metadata: https://github.com/everit-org/ecm-util-method
ECM Annotation → Metadata: https://github.com/everit-org/ecm-annotation-metadatabuilder
ECM Component: https://github.com/everit-org/ecm-component
Cookbook: http://cookbook.everit.org/
Everit Components: http://www.everit.org/components.html
Twitter: @EveritOrg