public interface FactoryComponent extends Component
When a factory configuration is created, an instance of the component is created and the configuration is injected by default in the "updated" callback, which supports the following signatures:
public class Activator extends DependencyActivatorBase { &Override public void init(BundleContext context, DependencyManager dm) throws Exception { FactoryComponent factoryComponent = createFactoryComponent() .setFactoryPid("my.factory.pid") .setInterface(MySevice.class.getName(), null) .setImplementation(MyComponent.class) .setConfigType(MyConfig.class); dm.add(factoryComponent); } } public interface MyConfig { int getPort(); String getAddress(); } public class MyComponent implements MyService { void updated(MyConfig cnf) { int port = cnf.getPort(); String addr = cnf.getAddress(); ... } }
Component.ServiceScope
Modifier and Type | Method and Description |
---|---|
FactoryComponent |
add(ComponentStateListener listener)
Adds a component state listener to this component.
|
FactoryComponent |
add(Dependency... dependencies)
Adds dependency(ies) to this component, atomically.
|
FactoryComponent |
add(PropertyMetaData... metaData)
Sets metatype MetaData regarding configuration properties.
|
FactoryComponent |
remove(ComponentStateListener listener)
Removes a component state listener from this component.
|
FactoryComponent |
remove(Dependency d)
Removes a dependency from the component.
|
FactoryComponent |
setAutoConfig(java.lang.Class<?> clazz,
boolean autoConfig)
Configures auto configuration of injected classes in the component instance.
|
FactoryComponent |
setAutoConfig(java.lang.Class<?> clazz,
java.lang.String instanceName)
Configures auto configuration of injected classes in the component instance.
|
FactoryComponent |
setCallbacks(java.lang.Object instance,
java.lang.String init,
java.lang.String start,
java.lang.String stop,
java.lang.String destroy)
Sets the names of the methods used as callbacks.
|
FactoryComponent |
setCallbacks(java.lang.String init,
java.lang.String start,
java.lang.String stop,
java.lang.String destroy)
Sets the names of the methods used as callbacks.
|
FactoryComponent |
setComposition(java.lang.Object instance,
java.lang.String getMethod)
Sets the instance and method to invoke to get back all instances that
are part of a composition and need dependencies injected.
|
FactoryComponent |
setComposition(java.lang.String getMethod)
Sets the method to invoke on the service implementation to get back all
instances that are part of a composition and need dependencies injected.
|
FactoryComponent |
setConfigType(java.lang.Class<?>... configTypes)
Sets the configuration type to use instead of a dictionary.
|
FactoryComponent |
setDebug(java.lang.String label)
Activate debug for this component.
|
FactoryComponent |
setDesc(java.lang.String desc)
A metatype human readable description of the factory PID this configuration is associated with.
|
FactoryComponent |
setFactory(java.lang.Object factory,
java.lang.String createMethod)
Sets the factory to use to create the implementation.
|
FactoryComponent |
setFactory(java.lang.String createMethod)
Sets the factory to use to create the implementation.
|
FactoryComponent |
setFactoryPid(java.lang.Class<?> clazz)
Sets the pid matching the factory configuration using the specified class.
|
FactoryComponent |
setFactoryPid(java.lang.String factoryPid)
Sets the pid matching the factory configuration
|
FactoryComponent |
setHeading(java.lang.String heading)
Sets the metatype label used to display the tab name (or section) where the properties are displayed.
|
FactoryComponent |
setImplementation(java.lang.Object implementation)
Sets the implementation for this component.
|
FactoryComponent |
setInterface(java.lang.Class<?>[] serviceNames,
java.util.Dictionary<?,?> properties)
Sets the public interfaces under which this component should be registered
in the OSGi service registry.
|
FactoryComponent |
setInterface(java.lang.Class<?> serviceName,
java.util.Dictionary<?,?> properties)
Sets the public interface under which this component should be registered
in the OSGi service registry.
|
FactoryComponent |
setInterface(java.lang.String[] serviceNames,
java.util.Dictionary<?,?> properties)
Sets the public interfaces under which this component should be registered
in the OSGi service registry.
|
FactoryComponent |
setInterface(java.lang.String serviceName,
java.util.Dictionary<?,?> properties)
Sets the public interface under which this component should be registered
in the OSGi service registry.
|
FactoryComponent |
setLocalization(java.lang.String localization)
Points to the metatype basename of the Properties file that can localize the Meta Type informations.
|
FactoryComponent |
setPropagate(boolean propagate)
Sets the propagate flag (true means all public configuration properties are propagated to service properties).
|
FactoryComponent |
setScope(Component.ServiceScope scope)
Sets the component scope.
|
FactoryComponent |
setServiceProperties(java.util.Dictionary<?,?> serviceProperties)
Sets the service properties associated with the component.
|
FactoryComponent |
setUpdated(java.lang.String update)
Sets the method name that will be notified when the factory configuration is created/updated.
|
FactoryComponent |
setUpdateInstance(java.lang.Object updatedCallbackInstance)
Sets the object on which the updated callback will be invoked.
|
getComponentDeclaration, getDependencyManager, getInstance, getInstances, getServiceProperties, getServiceRegistration
FactoryComponent setScope(Component.ServiceScope scope)
FactoryComponent setImplementation(java.lang.Object implementation)
Class
that will be instantiated using its default constructor when the
required dependencies are resolved, effectively giving you a lazy
instantiation mechanism.
There are four special methods that are called when found through
reflection to give you life cycle management options:
init()
is invoked after the instance has been
created and dependencies have been resolved, and can be used to
initialize the internal state of the instance or even to add more
dependencies based on runtime statestart()
is invoked right before the service is
registeredstop()
is invoked right after the service is
unregistereddestroy()
is invoked after all dependencies are
removedsetImplementation
in interface Component
implementation
- the implementationComponentStateListener
FactoryComponent add(Dependency... dependencies)
FactoryComponent remove(Dependency d)
FactoryComponent add(ComponentStateListener listener)
FactoryComponent remove(ComponentStateListener listener)
FactoryComponent setInterface(java.lang.String serviceName, java.util.Dictionary<?,?> properties)
setInterface
in interface Component
serviceName
- the name of the service interfaceproperties
- the properties for this serviceFactoryComponent setInterface(java.lang.String[] serviceNames, java.util.Dictionary<?,?> properties)
setInterface
in interface Component
serviceNames
- the names of the service interfaceproperties
- the properties for these servicesFactoryComponent setInterface(java.lang.Class<?> serviceName, java.util.Dictionary<?,?> properties)
setInterface
in interface Component
serviceName
- the name of the service interfaceproperties
- the properties for this serviceFactoryComponent setInterface(java.lang.Class<?>[] serviceNames, java.util.Dictionary<?,?> properties)
setInterface
in interface Component
serviceNames
- the names of the service interfaceproperties
- the properties for these servicesFactoryComponent setAutoConfig(java.lang.Class<?> clazz, boolean autoConfig)
setAutoConfig
in interface Component
clazz
- the class (from the list above)autoConfig
- false
to turn off auto configurationFactoryComponent setAutoConfig(java.lang.Class<?> clazz, java.lang.String instanceName)
setAutoConfig
in interface Component
clazz
- the class (from the list above)instanceName
- the name of the instance to inject the class intosetAutoConfig(Class, boolean)
FactoryComponent setServiceProperties(java.util.Dictionary<?,?> serviceProperties)
setServiceProperties
in interface Component
serviceProperties
- the propertiesFactoryComponent setCallbacks(java.lang.String init, java.lang.String start, java.lang.String stop, java.lang.String destroy)
setCallbacks
in interface Component
init
- the name of the init methodstart
- the name of the start methodstop
- the name of the stop methoddestroy
- the name of the destroy methodFactoryComponent setCallbacks(java.lang.Object instance, java.lang.String init, java.lang.String start, java.lang.String stop, java.lang.String destroy)
See setCallbacks(String init, String start, String stop, String destroy) for more information on the signatures. Specifying an instance means you can create a manager that will be invoked whenever the life cycle of a component changes and this manager can then decide how to expose this life cycle to the actual component, offering an important indirection when developing your own component models.
setCallbacks
in interface Component
FactoryComponent setFactory(java.lang.Object factory, java.lang.String createMethod)
setComposition
to create a
composition of instances that work together to implement a component. The
factory itself can also be instantiated lazily by not specifying an
instance, but a Class
.setFactory
in interface Component
factory
- the factory instance or classcreateMethod
- the name of the create methodFactoryComponent setFactory(java.lang.String createMethod)
setComposition
to create a composition of instances that
work together to implement a component.
Note that currently, there is no default for the factory, so please use
setFactory(factory, createMethod)
instead.
setFactory
in interface Component
createMethod
- the name of the create methodFactoryComponent setComposition(java.lang.Object instance, java.lang.String getMethod)
Object[]
.setComposition
in interface Component
instance
- the instance that has the methodgetMethod
- the method to invokeFactoryComponent setComposition(java.lang.String getMethod)
Object[]
.setComposition
in interface Component
getMethod
- the method to invokeFactoryComponent setDebug(java.lang.String label)
FactoryComponent setFactoryPid(java.lang.String factoryPid)
factoryPid
- the pid matching the factory configurationFactoryComponent setFactoryPid(java.lang.Class<?> clazz)
clazz
- the class whose FQDN name will be used for the factory pidFactoryComponent setUpdated(java.lang.String update)
updated
TODO describe supported signaturesupdate
- the method name that will be notified when the factory configuration is created/updated.FactoryComponent setUpdateInstance(java.lang.Object updatedCallbackInstance)
updatedCallbackInstance
- the object on which the updated callback will be invoked.FactoryComponent setPropagate(boolean propagate)
propagate
- the propagate flag (false, by default; true means all public configuration properties are propagated to service properties).FactoryComponent setConfigType(java.lang.Class<?>... configTypes)
configTypes
- the configuration type to use instead of a dictionaryConfigurationDependency
FactoryComponent setHeading(java.lang.String heading)
heading
- the label used to display the tab name (or section) where the properties are displayed.FactoryComponent setDesc(java.lang.String desc)
desc
- FactoryComponent setLocalization(java.lang.String localization)
"person"
will match person_du_NL.properties in the root bundle directory).localization
- FactoryComponent add(PropertyMetaData... metaData)
metaData
- the metadata regarding configuration properties