@Retention(value=CLASS)
@Target(value=TYPE)
public @interface Component
factoryName
annotation attribute.
If a factoryPid
attribute is set, the component is not started automatically
during bundle startup, and the component can then be instantiated multiple times using
Configuration Admin "Factory Configurations".
Here is a sample showing how a HelloFactory component may dynamically instantiate several Hello component instances, using Configuration Admin "Factory Configurations":/** * This component will be activated once the bundle is started and when all required dependencies * are available. */ @Component class Hello implements HelloService { @ConfigurationDependency(pid="my.pid") void configure(Dictionary conf) { // Configure or reconfigure our component. } @Start void start() { // Our component is starting and is about to be registered in the OSGi registry as a HelloService service. } }
/** * All component instances will be created/updated/removed by the "HelloFactory" component */ @Component(factoryPid="my.factory.pid") class Hello implements HelloService { void updated(Dictionary conf) { // Configure or reconfigure our component. The conf is provided by the factory, } @Start void start() { // Our component is starting and is about to be registered in the OSGi registry as a Hello service. } } /** * This class will instantiate some Hello component instances */ @Component class HelloFactory { @ServiceDependency void bind(ConfigurationAdmin cm) { // instantiate a first instance of Hello component Configuration c1 = cm.createFactoryConfiguration("my.factory.pid", "?"); Hashtable props = new Hashtable(); newprops.put("key", "value1"); c1.update(props); // instantiate another instance of Hello component Configuration c2 = cm.createFactoryConfiguration("my.factory.pid", "?"); props = new Hashtable(); newprops.put("key", "value2"); c2.update(props); // destroy the two instances of X component c1.delete(); c2.delete(); } }
Modifier and Type | Optional Element and Description |
---|---|
java.lang.String |
factoryMethod
Sets the static method used to create the components implementation instance.
|
java.lang.String |
factoryPid
Returns the factory pid whose configurations will instantiate the annotated service class.
|
boolean |
propagate
Returns true if the factory configuration properties must be published to the service properties.
|
Property[] |
properties
Deprecated.
you can apply
Property annotation directly on the component class. |
java.lang.Class<?>[] |
provides
Sets list of provided interfaces.
|
ServiceScope |
scope
The service scope for the service of this Component.
|
java.lang.String |
updated
The Update method to invoke (defaulting to "updated"), when a factory configuration is created or updated.
|
public abstract java.lang.Class<?>[] provides
public abstract java.lang.String factoryMethod
public abstract java.lang.String factoryPid
public abstract java.lang.String updated
public abstract boolean propagate
public abstract ServiceScope scope
If not specified, the singleton
service
scope is used.
public abstract Property[] properties
Property
annotation directly on the component class.