THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
How to declare a component type
XML
<component classname="my.Implementation" name="my-type" > </component>
Annotations
@Component(name="my-type") public class Implementation { // ... }
How to declare instances
<instance component="my-type"/> <instance component="my.Implementation"/> <instance component="my-type" name="my-instance"/> <instance component="my-type" name="my-instance"> <property name="property1" value="value1"/> </instance> </component>
- Instances can contains a configuration given under the
key-value
form. Properties can also by complex type (refer to How-to use iPOJO factories)
How to provide a service
XML
<component classname="my.service.implementation" name="my-service-impl"> <provides/> </component> <instance name="my-service-impl"/>
Annotations
@Component @Provides public class Implementation implements FooService { ... }
- Only instances provides really services, so don't forget to declare an instance.
- Published service interfaces must be implemented by your component implementation
Publishing service properties
XML
<component classname="my.service.implementation" name="my-service-impl"> <provides> <property name="foo" field="m_foo" /> <property name="bar" field="m_bar" mandatory="true" /> <property name="baz" type="java.lang.String" /> <!-- Static property (do not change at runtime) --> </provides> </component> <instance name="my-service-impl"> <!-- The configuration has to inject value in unvalued mandatory properties --> <property name="bar" value="5"/> <property name="baz" value="my string"/> <instance/>
Annotations
@Component @Provides(specifications= {FooService.class, BarService.class}) public class ProvidesProperties implements FooService, BarService { @ServiceProperty(name = "foo") public int m_foo = 0; @ServiceProperty(name="bar", mandatory=true) public int m_bar; // ... }
Consuming services
XML
<component classname="my.consumer.Implementation"> <requires field="fs" /> <requires> <callback type="bind" method="bind" /> <callback type="unbind" method="unbind" /> </requires> </component>
Annotations
@Component public class Dependency { @Requires public FooService fs; @Unbind public void unbind(BazService bz) { //... } @Bind public void bind(BazService bz) { // ... } //... }
Reacting to lifecycle state changes
Immediate components
- A POJO object (implementation object) is created as soons as the instance becomes valid
- Instances that don't provide services becomes automatically immediate
XML
<component classname="my.service.implementation" name="my-service-impl" immediate="true"> <provides/> </component>
Annotations@Component(immediate=true) @Provides public class Implementation implements FooService { ... }
Lifecycle callbacks
XML
<component classname="my.implementation" name="my-impl"> <callback transition="validate" method="start" /> <callback transition="invalidate" method="stop" /> </component>
Annotations
@Component public class Implementation { @Validate public void start() { } @Invalidate public void stop() { } }