<div class="content"> |
<component
classname="my.Implementation"
name="my-type">
</component>
|
@Component(name="my-type")
public class Implementation {
// ...
}
|
|
<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>
|
|
key-value form. Properties can also by complex type.
@Component(name="my-type")
@Instantiate
public class Implementation {
// ...
}
|
<component classname="my.service.implementation" name="my-service-impl"> <provides/> </component> <instance name="my-service-impl"/> |
@Component
@Provides
public class Implementation implements FooService {
...
}
|
|
<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/> |
@Component
@Provides(specifications= {FooService.class, BarService.class},
properties= {
@StaticServiceProperty(name="baz", type="java.lang.String")})
public class ProvidesProperties implements FooService, BarService {
@ServiceProperty(name = "foo")
public int m_foo = 0;
@ServiceProperty(name="bar", mandatory=true)
public int m_bar;
// ...
}
|
|
<component classname="my.consumer.Implementation">
<requires field="fs" />
<requires field="bs" />
</component>
|
@Component
public class Dependency {
@Requires
public FooService fs;
@Requires
public BarService[] bs;
//...
}
|
|
<component classname="my.consumer.Implementation">
<requires>
<callback type="bind" method="bind" />
<callback type="unbind" method="unbind" />
<callback type="modified" method="modified" /> <!-- for filtered service dependencies, to be notified when a service is modified but still match -->
</requires>
</component>
|
@Component
public class Dependency {
@Unbind
public synchronized void unbindBaz(BazService bz) {
//...
}
@Bind
public synchronized void bindBaz(BazService bz) {
// ...
}
@Modified
public synchronized void modifiedBaz() {
// ...
}
//...
}
|
|
from attributerequires.from property, it is possible to override the from attribute value.<component classname="...MyComponent" name="FOO"> <requires field="m_foo" id="id1"> <callback type="bind" method="bind"/> <callback type="unbind" method="unbind"/> </requires> </component> <instance name="FOO1" component="FOO"/> <!-- Use the default 'from' value --> <instance name="FOO2" component="FOO"> <property name="requires.from"> <property name="id1" value="myprovider"/> </property> </instance> |
filter attributerequires.filters property, it is possible to override the filter attribute value.<component classname="org.apache.felix.ipojo.example.FilteredDependency" name="FOO"> <requires field="m_foo" fiter="(foo.property=FOO)" id="id1"> <callback type="bind" method="bind"/> <callback type="unbind" method="unbind"/> </requires> </component> <instance name="FOO1" component="FOO"/> <!-- Use the default 'filter' value --> <instance name="FOO2" component="FOO"> <property name="requires.filters"> <property name="id1" value="(foo.property=BAR)"/> </property> </instance> |
<component classname="my.service.implementation" name="my-service-impl" immediate="true"> <provides/> </component> |
@Component(immediate=true)
@Provides
public class Implementation implements FooService {
...
}
|
|
<component classname="my.implementation" name="my-impl">
<callback transition="validate" method="start" />
<callback transition="invalidate" method="stop" />
</component>
|
@Component
public class Implementation {
@Validate
public void start() {
}
@Invalidate
public void stop() {
}
}
|
<component classname="my.Implementation" name="my-impl">
<properties propagation="true" managedservice="MyPID">
<property name="boo" method="setBoo" />
<property field="m_bar" mandatory="true"/>
<property field="m_foo" value="4"/>
</properties>
</component>
<instance component="my-impl">
<property name="boo" value="..."/>
<property name="m_bar" value="..."/>
</instance>
<instance component="my-impl">
<property name="boo" value="..."/>
<property name="m_bar" value="..."/>
<property name="managed.service.pid" value="AnotherPID"/>
</instance>
|
@Component(managedservice="MyPID", propagation=true)
public class Implementation {
@Property(name="boo")
public void setBoo(int boo) {
//...
}
@Property(mandatory=true)
public int m_bar;
@Property(value="4")
public int m_foo;
}
|
|
ServiceReference as parameter.
<component
classname="...">
<provides
post-unregistration="unregistered" post-registration="registered"/>
</component>
|
@PostRegistration
public void registered(ServiceReference ref) {
System.out.println("Registered");
}
@PostUnregistration
public void unregistered(ServiceReference ref) {
System.out.println("Unregistered");
}
|
<component
classname="...">
<provides>
<controller field="controller" value="false"/>
</provides>
</component>
|
@ServiceController(value="false") private boolean controller |
arch => displays instances name & state (equivalent to arch \-instances) arch -instance $instance_name => displays complete information about the instance $instance_name arch -factories => display the list of available factories arch -factory $factory_name => display complete information about the factory $factory_name arch -handlers => list available handlers |
ipojo:instances => displays instances name & state (equivalent to arch \-instances) ipojo:instance $instance_name => displays complete information about the instance $instance_name ipojo:factories => display the list of available factories ipojo:factory $factory_name => display complete information about the factory $factory_name ipojo:handlers => list available handlers |
proxies and be given to collaborator objects.
<iPOJO xmlns:temporal="org.apache.felix.ipojo.handler.temporal">
<component
className="my.Implementation">
<!-- Temporal dependency configuration -->
<temporal:requires field="mytemporal"/>
<provides/>
</component>
</iPOJO>
|
import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.handler.temporal.Requires;
import org.apache.felix.ipojo.test.scenarios.annotations.service.FooService;
@Component
public class Implementation {
@Requires // org.apache.felix.ipojo.handler.temporal.Requires
private FooService mytemporal;
}
|
|
<ipojo
xmlns:ev="org.apache.felix.ipojo.handlers.event.EventAdminHandler">
<component className="...MyComponent">
<ev:subscriber
name="mySubscriber"
callback="receive"
topics="foo"/>
</component>
</ipojo>
|
@Component
public class MyComponent {
@Subscriber(name="s1", data_key="data")
public void receive1(Object foo) {
// Nothing
}
@Subscriber(name="s2", topics="foo,bar", filter="(foo=true)")
public void receive2(Event foo) {
// Nothing
}
@Subscriber(name="s3", topics="foo", data_key="data", data_type="java.lang.String")
public void receive3(String foo) {
// Nothing
}
|
|
topics attributefilter attribute<instance component="...MyComponent"> <property name="event.topics"> <property name="mySubscriber" value="foo"/> </property> <property name="event.filter"> <property name="mySubscriber" value="|((arg=Minibar)(arg=Coconuts))"/> </property> </instance> |
org.apache.felix.ipojo.handlers.event.publisher.Publisher field.
<ipojo
xmlns:ev="org.apache.felix.ipojo.handlers.event.EventAdminHandler">
<component className="...MyComponent">
<ev:publisher
name="myPublisher"
field="m_publisher"
topics="bar,nuts"/>
</component>
<instance component="...MyComponent"/>
</ipojo>
|
@Component
public class MyComponent {
// We use qualified names to avoid conflict.
@org.apache.felix.ipojo.handlers.event.Publisher(name="p1", synchronous=true)
org.apache.felix.ipojo.handlers.event.publisher.Publisher publisher1;
@org.apache.felix.ipojo.handlers.event.Publisher(name="p2", synchronous=false, topics="foo,bar", data_key="data")
org.apache.felix.ipojo.handlers.event.publisher.Publisher publisher2;
@org.apache.felix.ipojo.handlers.event.Publisher(name="p3", synchronous=true, topics="bar")
org.apache.felix.ipojo.handlers.event.publisher.Publisher publisher3;
// ...
public void doSomething() {
Dictionary e = new Properties();
//...
// Fill out the event
// Send event
publisher1.send(e);
}
}
|
|
topics attribute<instance component="...MyComponent"> <property name="event.topics"> <property name="myPublisher" value="foo"/> </property> </instance> |
Extender pattern without handling obscure details
<ipojo xmlns:extender="org.apache.felix.ipojo.extender">
<component
classname="org.apache.felix.ipojo.extender.Myextender">
<!—Extender Pattern handler configuration -->
<extender:extender
extension="My-Extension"
onArrival="onArrival"
onDeparture="onDeparture"
/>
<callback transition="invalidate" method="stopping" />
<callback transition="validate" method="starting" />
</component>
</ipojo>
|
@Component
@org.apache.felix.ipojo.extender.Extender(extension="My-Extension", onArrival="onArrival", onDeparture="onDeparture")
public class Myextender {
public void onArrival(Bundle bundle, String extension) {
// handle matching bundle arrival
}
public void onDeparture(Bundle bundle) {
// handler matching bundle departure
}
}
|
|
Whiteboard pattern without handling obscure details
<ipojo xmlns:wbp="org.apache.felix.ipojo.whiteboard">
<component
classname="org.apache.felix.ipojo.test.MyWhiteBoardPattern"
>
<wbp:wbp
filter="(my.property=1)"
onArrival="onArrival"
onDeparture="onDeparture"
onModification="onModification"
/>
<provides/>
</component>
|
@Component
@org.apache.felix.ipojo.whiteboard.Wbp(filter="(my.property=1)",
onArrival="onArrival",
onDeparture="onDeparture",
onModification="onModification")
public class WhiteBoardWIModification {
public void onArrival(ServiceReference ref) {
// ...
}
public void onDeparture(ServiceReference ref) {
// ...
}
public void onModification(ServiceReference ref) {
// ...
}
}
|
|