public interface ResourceComponent extends Component<ResourceComponent>
public class Activator extends DependencyActivatorBase { &Override public void init(BundleContext context, DependencyManager dm) throws Exception { Component resourceComponent = dm.createResourceComponent() .setResourceFilter("(path=/videos/*.mkv)") .setInterface(VideoPlayer.class, null) .setImplementation(VideoPlayerImpl.class); dm.add(resourceComponent); } } public interface VideoPlayer { void play(); } public class VideoPlayerImpl implements VideoPlayer { volatile URL resource; // injected void play() { ... } }
When you use callbacks to get injected with the resource, the "add", "change" callbacks support the following method signatures:
(Component, URL, Dictionary)
(Component, URL)
(Component)
(URL, Dictionary)
(URL)
(Object)
Component.ServiceScope
Modifier and Type | Method and Description |
---|---|
ResourceComponent |
setBundleCallbackInstance(java.lang.Object callbackInstance)
Sets the instance to invoke the callbacks on (null by default, meaning the callbacks have to be invoked on the resource adapter itself)
|
ResourceComponent |
setBundleCallbacks(java.lang.String add,
java.lang.String change)
Sets the callbacks to invoke when injecting the resource into the adapter component.
|
ResourceComponent |
setPropagate(boolean propagate)
Sets if properties from the resource should be propagated to the resource adapter service.
|
ResourceComponent |
setPropagate(java.lang.Object propagateCbInstance,
java.lang.String propagateCbMethod)
Sets the propagate callback to invoke in order to propagate the resource properties to the adapter service.
|
ResourceComponent |
setResourceFilter(java.lang.String filter)
Sets the resource filter used to match a given resource URL.
|
add, add, getServiceRegistration, remove, remove, setAutoConfig, setAutoConfig, setCallbacks, setCallbacks, setComposition, setComposition, setDebug, setFactory, setFactory, setImplementation, setInterface, setInterface, setInterface, setInterface, setScope, setServiceProperties
getComponentDeclaration, getDependencyManager, getInstance, getInstances, getServiceProperties
ResourceComponent setResourceFilter(java.lang.String filter)
filter
- the filter condition to use with the resourceResourceComponent setPropagate(boolean propagate)
propagate
- true if if properties from the resource should be propagated to the resource adapter service.
true by default.
The provided resource adapter service properties take precedence over the propagated resource service properties.ResourceComponent setPropagate(java.lang.Object propagateCbInstance, java.lang.String propagateCbMethod)
propagateCbInstance
- the object to invoke the propagate callback method onpropagateCbMethod
- the method name to invoke in order to propagate the resource properties to the adapter service.ResourceComponent setBundleCallbacks(java.lang.String add, java.lang.String change)
add
- the method to invoke when injected the resource into the adapter componentchange
- the method to invoke when the resource properties have changedResourceComponent setBundleCallbackInstance(java.lang.Object callbackInstance)
callbackInstance
- the instance to invoke the callbacks on (null by default, meaning the callbacks have to be invoked on the resource adapter itself)