You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Bulu <bu...@romandie.com> on 2014/10/15 14:12:06 UTC
DependencyManager: notify third party object of changed adaptee properties
Hello All
Using Dependency Manager, I declare adapters like this:
mgr.add(createAdapterService(Device.class,null)
.setImplementation(DeviceAdapter.class)
.setCallbacks(deviceManager, "init", "start", "stop", "destroy"));
So deviceManager gets notified when the adapters appear. Now I also want
deviceManager to be notified when the properties of any of the adaptees
(Device.class) change (need to update the UI).
For normal ServiceDependency I can specify callbacks to be called on a
third party object with
ServiceDependency.setCallbacks(Object instance, String added, String
changed, String removed);
For adapters and I can specify the callbacks, but only calling the
adapter itself:
createAdapterService(Device.class.name, null, "add", "change", "remove")
How can I tell the adapter to use callbacks on a third party object
(deviceManager) when the adaptee's properties change?
Thanks & regards
Philipp
Re: DependencyManager: notify third party object of changed adaptee properties
Posted by Marcel Offermans <ma...@luminis.eu>.
Hello Pierre, Philipp,
On 16 Oct 2014, at 8:50 am, Pierre De Rop <pi...@gmail.com> wrote:
> Now, if you really need to be able to specify a callback instance to be
> called when the adaptee service properties are changed (Device), then can
> you please create a Jira issue for it, and I will add a
> createAdapterService signature allowing to specify a callbackObject,
> similar to what is currently done int the createResourceAdapterService
> methods.
> (Marcel, would you be OK for this new feature ?)
Definitely, I can't think of a valid reason not to add this. We simply did not create this signature yet (mainly because nobody asked). I would propose we only implement new features in our upcoming DM4 release though.
Greetings, Marcel
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org
Re: Felix DependencyManager on OSGi 3
Posted by Bulu <bu...@romandie.com>.
Yes, don't tell me... I'm working with the ZB4O project which insists on
using OSGi 3 (presumably, because it uses less resources on constraint
devices).
Regards Philipp
On 20.01.2015 13:21, Neil Bartlett wrote:
> Fascinated to hear why you need this, by the way! OSGi R3 was superseded by R4 more than ten years ago…
>
> Neil
>
>
>> On 20 Jan 2015, at 10:05, Bulu <bu...@romandie.com> wrote:
>>
>> Dear Felix DM users
>>
>> Is it possible to use Felix DM on OSGi 3?
>>
>> I hope it is :-)
>>
>> Regards Philipp
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org
Re: Felix DependencyManager on OSGi 3
Posted by Neil Bartlett <nj...@gmail.com>.
Fascinated to hear why you need this, by the way! OSGi R3 was superseded by R4 more than ten years ago…
Neil
> On 20 Jan 2015, at 10:05, Bulu <bu...@romandie.com> wrote:
>
> Dear Felix DM users
>
> Is it possible to use Felix DM on OSGi 3?
>
> I hope it is :-)
>
> Regards Philipp
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org
Re: Felix DependencyManager on OSGi 3
Posted by Marcel Offermans <ma...@luminis.nl>.
Good question. The first release at Felix was already using R4 (2.0.1 that is). I must say that I have a hard time finding any “older” code. After a lot of digging in personal archives, I did manage to find a very old R3 version. It probably makes sense to contact me off-list if you want a copy. :)
Greetings, Marcel
On 20 Jan 2015 at 15:36:02 , Bulu (bulu@romandie.com) wrote:
OK thanks. Do you know of another dependency manager which might work on
OSGi 3?
Regards Philipp
On 20.01.2015 13:01, Marcel Offermans wrote:
> Hello Philipp,
>
> When the DM project was started, a long time ago, it was compatible with an OSGi R3 framework. However, we currently build against R4 classes, so out of the box that won’t work. I do think that, with a few patches, you could make it work.
>
> Greetings, Marcel
>
> On 20 Jan 2015 at 11:11:02, Bulu (bulu@romandie.com) wrote:
>
> Dear Felix DM users
>
> Is it possible to use Felix DM on OSGi 3?
>
> I hope it is :-)
>
> Regards Philipp
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org
Re: Felix DependencyManager on OSGi 3
Posted by Bulu <bu...@romandie.com>.
OK thanks. Do you know of another dependency manager which might work on
OSGi 3?
Regards Philipp
On 20.01.2015 13:01, Marcel Offermans wrote:
> Hello Philipp,
>
> When the DM project was started, a long time ago, it was compatible with an OSGi R3 framework. However, we currently build against R4 classes, so out of the box that won’t work. I do think that, with a few patches, you could make it work.
>
> Greetings, Marcel
>
> On 20 Jan 2015 at 11:11:02, Bulu (bulu@romandie.com) wrote:
>
> Dear Felix DM users
>
> Is it possible to use Felix DM on OSGi 3?
>
> I hope it is :-)
>
> Regards Philipp
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org
Re: Felix DependencyManager on OSGi 3
Posted by Marcel Offermans <ma...@luminis.nl>.
Hello Philipp,
When the DM project was started, a long time ago, it was compatible with an OSGi R3 framework. However, we currently build against R4 classes, so out of the box that won’t work. I do think that, with a few patches, you could make it work.
Greetings, Marcel
On 20 Jan 2015 at 11:11:02, Bulu (bulu@romandie.com) wrote:
Dear Felix DM users
Is it possible to use Felix DM on OSGi 3?
I hope it is :-)
Regards Philipp
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org
Felix DependencyManager on OSGi 3
Posted by Bulu <bu...@romandie.com>.
Dear Felix DM users
Is it possible to use Felix DM on OSGi 3?
I hope it is :-)
Regards Philipp
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org
Re: DependencyManager: publish object as several interfaces and change their properties in init()
Posted by Marcel Offermans <ma...@luminis.eu>.
Hello Philipp,
On 10 Dec 2014, at 14:43 pm, Bulu <bu...@romandie.com> wrote:
> On 09.12.2014 10:18, Marcel Offermans wrote:
>> Hello Philipp,
>>
>>> On 09 Dec 2014, at 10:03 am, Bulu <bu...@romandie.com> wrote:
>>>
>>> In Felix DM, can I publish a certain object as several services / interfaces, but each with different properties?
>>> Calling setInterface() multiple times does not seem to do the trick. Calling setInterface(String[],Dictionary) will assign the same properties to each.
>>>
>>> If I use several interface (with that last call), can I change the properties in init(). I see I can do the following, but that changes the one set of properties for all interfaces
>>>
>>> public void init(Component c){
>>> ...
>>> Dictionary<String, Object> props = c.getServiceProperties();
>>> props.put(someKey, someValue);
>>> c.setServiceProperties(props);
>>> }
>> OSGi allows you to publish a service with multiple interfaces, but the properties then apply to all of them. DM follows that model, so what you’re seeing makes sense from that point of view. If you want different properties, you have to define multiple DM “components” (which can all use the same instance if that’s what you want).
>
> If the component is instantiated only when the dependencies are met, can this approach also be used?
>
> Component c1 = Component compo = createAdapterService(Device.class, null)
> .setImplementation(DeviceAdapterImpl.class)
> .setInterface(DeviceAdapter.class.getName(), null);
> mgr.add(compo);
>
> // here also publish all instances of the component (ie. for each adapted Device) as an EventHandler with properties topic & filter.
If you have an adapter, it will create an instance of DeviceAdapterImpl for every Device it finds. That makes it a bit harder to create a second component based on that same implementation, because only after the adapter instance has been created can you try to use it in a second component. I would take this approach:
in your activator:
mgr.add(createAdapterService(…)…); // basically with the same interface and implementation you had
in DeviceAdapterImpl create an init / destroy method as follows:
private Component c2;
void init(Component c) {
dm = c.getDependencyManager();
c2 = dm.createComponent()
.setInterface(EventHandler.class.getName(), propsForTopicAndFilter)
.setImplementation(this);
dm.add(c2);
}
void destroy(Component c) {
dm = c.getDependencyManager();
dm.remove(c2);
}
So as soon as you have an instance created by the adapter, in its init method create another component, with the right service interface and properties, and in the destroy clean up again.
However, in your example, if you need the adapter to publish both as DeviceAdapter and as EventHandler, why not just register it as both and have the properties for topic/filter available on both interfaces. They are not used for DeviceAdapter, but that is not really a problem. Service properties that have no special meaning for a service can in general be ignored.
>>> Unrelated: can I use component as a dependency without publishing it as a service? Like so:
>> You might have hit “send” too soon… You cannot depend on something that is not a service. You can have a component that does not publish a service but does have dependencies on other services.
>>
>> Well, the only thing you could do is implement some custom form of dependency, but that would then have to lookup components in a registry. Which almost sounds like another service registry. :)
>>
>>
> OK too bad. My tendency was to use DM as a more general dependency injection framework. But I'm reluctant to publish a service just to acquire it again in the same bundle, because it then becomes public API.
Well, that is not necessarily true:
If you publish a service, as an interface or class, that is private to your bundle, then it will be in the service registry, but since nobody else outside your bundle will be able to access that class or interface so effectively it will be invisible. The only way to “see” it is to getAllServiceReferences() instead.
Another option is to use a component that consists of a composition, instead of a single instance. A composition is a fixed collection of instances associated with a component. All dependencies that are declared on that component will be injected into all instances in the collection. This is probably not the best way to “privately” publish a service and consume it in the same bundle, but it might be something that comes in handy in similar situations.
Greetings, Marcel
Re: DependencyManager: publish object as several interfaces and change
their properties in init()
Posted by Bulu <bu...@romandie.com>.
Hello Marcel
Thanks for you answer and the clarification.
On 09.12.2014 10:18, Marcel Offermans wrote:
> Hello Philipp,
>
>> On 09 Dec 2014, at 10:03 am, Bulu <bu...@romandie.com> wrote:
>>
>> In Felix DM, can I publish a certain object as several services / interfaces, but each with different properties?
>> Calling setInterface() multiple times does not seem to do the trick. Calling setInterface(String[],Dictionary) will assign the same properties to each.
>>
>> If I use several interface (with that last call), can I change the properties in init(). I see I can do the following, but that changes the one set of properties for all interfaces
>>
>> public void init(Component c){
>> ...
>> Dictionary<String, Object> props = c.getServiceProperties();
>> props.put(someKey, someValue);
>> c.setServiceProperties(props);
>> }
> OSGi allows you to publish a service with multiple interfaces, but the properties then apply to all of them. DM follows that model, so what you’re seeing makes sense from that point of view. If you want different properties, you have to define multiple DM “components” (which can all use the same instance if that’s what you want).
If the component is instantiated only when the dependencies are met, can
this approach also be used?
Component c1 = Component compo = createAdapterService(Device.class, null)
.setImplementation(DeviceAdapterImpl.class)
.setInterface(DeviceAdapter.class.getName(), null);
mgr.add(compo);
// here also publish all instances of the component (ie. for each
adapted Device) as an EventHandler with properties topic & filter.
>> Unrelated: can I use component as a dependency without publishing it as a service? Like so:
> You might have hit “send” too soon… You cannot depend on something that is not a service. You can have a component that does not publish a service but does have dependencies on other services.
>
> Well, the only thing you could do is implement some custom form of dependency, but that would then have to lookup components in a registry. Which almost sounds like another service registry. :)
>
>
OK too bad. My tendency was to use DM as a more general dependency
injection framework. But I'm reluctant to publish a service just to
acquire it again in the same bundle, because it then becomes public API.
Regards Philipp
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org
Re: DependencyManager: publish object as several interfaces and change their properties in init()
Posted by Marcel Offermans <ma...@luminis.eu>.
Hello Philipp,
> On 09 Dec 2014, at 10:03 am, Bulu <bu...@romandie.com> wrote:
>
> In Felix DM, can I publish a certain object as several services / interfaces, but each with different properties?
> Calling setInterface() multiple times does not seem to do the trick. Calling setInterface(String[],Dictionary) will assign the same properties to each.
>
> If I use several interface (with that last call), can I change the properties in init(). I see I can do the following, but that changes the one set of properties for all interfaces
>
> public void init(Component c){
> ...
> Dictionary<String, Object> props = c.getServiceProperties();
> props.put(someKey, someValue);
> c.setServiceProperties(props);
> }
OSGi allows you to publish a service with multiple interfaces, but the properties then apply to all of them. DM follows that model, so what you’re seeing makes sense from that point of view. If you want different properties, you have to define multiple DM “components” (which can all use the same instance if that’s what you want).
> Unrelated: can I use component as a dependency without publishing it as a service? Like so:
You might have hit “send” too soon… You cannot depend on something that is not a service. You can have a component that does not publish a service but does have dependencies on other services.
Well, the only thing you could do is implement some custom form of dependency, but that would then have to lookup components in a registry. Which almost sounds like another service registry. :)
Greetings, Marcel
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org
DependencyManager: publish object as several interfaces and change
their properties in init()
Posted by Bulu <bu...@romandie.com>.
Hello All
In Felix DM, can I publish a certain object as several services /
interfaces, but each with different properties?
Calling setInterface() multiple times does not seem to do the trick.
Calling setInterface(String[],Dictionary) will assign the same
properties to each.
If I use several interface (with that last call), can I change the
properties in init(). I see I can do the following, but that changes the
one set of properties for all interfaces
public void init(Component c){
...
Dictionary<String, Object> props = c.getServiceProperties();
props.put(someKey, someValue);
c.setServiceProperties(props);
}
Unrelated: can I use component as a dependency without publishing it as
a service? Like so:
Thanks & Regards Philipp
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org
Re: DependencyManager: notify third party object of changed adaptee
properties
Posted by Bulu <bu...@romandie.com>.
Hello Pierre
Thanks for coming up with this solution. I will try it out. The only
downside I see, is that bundle-internal objects (the adapters) are
published on the framework, so we lose a bit of encapsulation, but I can
live with that.
About the usage of the DeviceManager:
I want to show devices with their properties in a Vaadin GUI, for this,
they must be collected in a Container which is linked to the Widget (a
Tree). So two things need to happen:
1. for each Device appearing, create a DeviceAdapter which is of a
convenient form (a Bean) for the Vaadin framework to use, and which
forwards calls to the actual Device
2. for each DeviceAdapter created, add it to the Container (and remove
when disappearing...). The DeviceManager holds the Container and
adds/removes the adapters in it.
For separation of concerns, I didn't want the DeviceAdapters to directly
hold a reference to the deviceManager/container (ie. they should not
add/remove themselves).
Now I also want to track changes in the properties (which do not destroy
the adapter, its filter is still met), so that I can update the
container (a typical property which might change is the "parent" node in
the tree widget). So it is also the DeviceManager which needs to get
these property change notifications.
I will file a Jira request. I guess the difficulty might lie in the fact
that you will have to distinguish two case:
1. adaptee property change which make the adapter disappear (filter no
longer met)
2. adaptee property change but adapter is kept - so call callbacks on
itself or third party object
Regards Philipp
On 16.10.2014 08:50, Pierre De Rop wrote:
> Hello Philipp,
>
> I think that currently, it is not possible to specify a third party
> callback object to be notified when the adaptee services properties are
> changed, and only your adapter will be notified.
>
> One possible alternative could consist in letting the adapter impl provide
> an adapted interface and you could then track the adapted interface itself,
> because when the adaptee (Device) service properties are changed, the
> Device changed properties are then also propagated to the service
> properties provided by the adapter (if the adapter provides an adapted
> service).
>
> For example, when you create your adapter, you can manage to let it provide
> a service (like 'DeviceAdapter' service):
>
> mgr.add(createAdapterService(Device.class,null)
> .setImplementation(DeviceAdapter.class)
> .setInterface(DeviceAdapter.class, null)
> .setCallbacks("init", "start", "stop", "destroy"));
>
> Then you could manage to define your "DeviceManager" as a DM component, and
> that component could listen to all DeviceAdapter services, including
> propagated service properties change events:
>
> mgr.add(createComponent()
> .setImplementation(DeviceManager.class)
> .add(createServiceDependency(DeviceAdapter.class).setRequired(true)
> .setCallbacks("added", "changed", "removed)));
>
> then your DeviceManager could be called back it its changed method when a
> DeviceAdapter propagates its adapted Device service properties change
> events.
>
> This should work, but I don't know if this would be compatible with your
> current application design ?
> (maybe you could describe a but what is doing your DeviceManager ?)
>
> Now unfortunately, regarding your last question, I think that the work
> around won't work, because when the adaptee services comes up, the first
> dependency (the one that your work around has modified) is removed and
> replaced by another dependency (see the AdapterServiceImpl.
> AdapterImpl.createService() method()).
>
> Now, if you really need to be able to specify a callback instance to be
> called when the adaptee service properties are changed (Device), then can
> you please create a Jira issue for it, and I will add a
> createAdapterService signature allowing to specify a callbackObject,
> similar to what is currently done int the createResourceAdapterService
> methods.
> (Marcel, would you be OK for this new feature ?)
>
> kind regards;
> /Pierre
>
> On Wed, Oct 15, 2014 at 2:52 PM, Bulu <bu...@romandie.com> wrote:
>
>> Addition to my own question:
>> I came up with the following, but the callbacks seem not to get called on
>> the deviceManager...
>>
>> Component adapter = createAdapterService(Device.class,null)
>> .setImplementation(DeviceAdapter.class)
>> .setCallbacks(deviceManager, INIT_METHOD, START_METHOD, STOP_METHOD,
>> DESTROY_METHOD);
>>
>> // Ugly: supposing the adapter has always the adaptee as first service
>> dependency
>> ServiceDependency dep = (ServiceDependency) adapter.getDependencies().get(
>> 0);
>> logger.debug("Dependency is {}", dep); // OK, in my tests it's the right
>> dependency
>> dep.setCallbacks(deviceManager, BIND_METHOD, CHANGED_METHOD,
>> UNBIND_METHOD);
>> mgr.add(adapter);
>>
>> Is this the right way?
>>
>> Regards Philipp
>>
>>
>> On 15.10.2014 14:12, Bulu wrote:
>>
>>> Hello All
>>>
>>> Using Dependency Manager, I declare adapters like this:
>>> mgr.add(createAdapterService(Device.class,null)
>>> .setImplementation(DeviceAdapter.class)
>>> .setCallbacks(deviceManager, "init", "start", "stop", "destroy"));
>>>
>>> So deviceManager gets notified when the adapters appear. Now I also want
>>> deviceManager to be notified when the properties of any of the adaptees
>>> (Device.class) change (need to update the UI).
>>>
>>> For normal ServiceDependency I can specify callbacks to be called on a
>>> third party object with
>>> ServiceDependency.setCallbacks(Object instance, String added, String
>>> changed, String removed);
>>>
>>> For adapters and I can specify the callbacks, but only calling the
>>> adapter itself:
>>> createAdapterService(Device.class.name, null, "add", "change",
>>> "remove")
>>>
>>> How can I tell the adapter to use callbacks on a third party object
>>> (deviceManager) when the adaptee's properties change?
>>>
>>> Thanks & regards
>>> Philipp
>>>
>>>
>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>>
>>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org
Re: DependencyManager: notify third party object of changed adaptee properties
Posted by Pierre De Rop <pi...@gmail.com>.
Hello Philipp,
I think that currently, it is not possible to specify a third party
callback object to be notified when the adaptee services properties are
changed, and only your adapter will be notified.
One possible alternative could consist in letting the adapter impl provide
an adapted interface and you could then track the adapted interface itself,
because when the adaptee (Device) service properties are changed, the
Device changed properties are then also propagated to the service
properties provided by the adapter (if the adapter provides an adapted
service).
For example, when you create your adapter, you can manage to let it provide
a service (like 'DeviceAdapter' service):
mgr.add(createAdapterService(Device.class,null)
.setImplementation(DeviceAdapter.class)
.setInterface(DeviceAdapter.class, null)
.setCallbacks("init", "start", "stop", "destroy"));
Then you could manage to define your "DeviceManager" as a DM component, and
that component could listen to all DeviceAdapter services, including
propagated service properties change events:
mgr.add(createComponent()
.setImplementation(DeviceManager.class)
.add(createServiceDependency(DeviceAdapter.class).setRequired(true)
.setCallbacks("added", "changed", "removed)));
then your DeviceManager could be called back it its changed method when a
DeviceAdapter propagates its adapted Device service properties change
events.
This should work, but I don't know if this would be compatible with your
current application design ?
(maybe you could describe a but what is doing your DeviceManager ?)
Now unfortunately, regarding your last question, I think that the work
around won't work, because when the adaptee services comes up, the first
dependency (the one that your work around has modified) is removed and
replaced by another dependency (see the AdapterServiceImpl.
AdapterImpl.createService() method()).
Now, if you really need to be able to specify a callback instance to be
called when the adaptee service properties are changed (Device), then can
you please create a Jira issue for it, and I will add a
createAdapterService signature allowing to specify a callbackObject,
similar to what is currently done int the createResourceAdapterService
methods.
(Marcel, would you be OK for this new feature ?)
kind regards;
/Pierre
On Wed, Oct 15, 2014 at 2:52 PM, Bulu <bu...@romandie.com> wrote:
> Addition to my own question:
> I came up with the following, but the callbacks seem not to get called on
> the deviceManager...
>
> Component adapter = createAdapterService(Device.class,null)
> .setImplementation(DeviceAdapter.class)
> .setCallbacks(deviceManager, INIT_METHOD, START_METHOD, STOP_METHOD,
> DESTROY_METHOD);
>
> // Ugly: supposing the adapter has always the adaptee as first service
> dependency
> ServiceDependency dep = (ServiceDependency) adapter.getDependencies().get(
> 0);
> logger.debug("Dependency is {}", dep); // OK, in my tests it's the right
> dependency
> dep.setCallbacks(deviceManager, BIND_METHOD, CHANGED_METHOD,
> UNBIND_METHOD);
> mgr.add(adapter);
>
> Is this the right way?
>
> Regards Philipp
>
>
> On 15.10.2014 14:12, Bulu wrote:
>
>> Hello All
>>
>> Using Dependency Manager, I declare adapters like this:
>> mgr.add(createAdapterService(Device.class,null)
>> .setImplementation(DeviceAdapter.class)
>> .setCallbacks(deviceManager, "init", "start", "stop", "destroy"));
>>
>> So deviceManager gets notified when the adapters appear. Now I also want
>> deviceManager to be notified when the properties of any of the adaptees
>> (Device.class) change (need to update the UI).
>>
>> For normal ServiceDependency I can specify callbacks to be called on a
>> third party object with
>> ServiceDependency.setCallbacks(Object instance, String added, String
>> changed, String removed);
>>
>> For adapters and I can specify the callbacks, but only calling the
>> adapter itself:
>> createAdapterService(Device.class.name, null, "add", "change",
>> "remove")
>>
>> How can I tell the adapter to use callbacks on a third party object
>> (deviceManager) when the adaptee's properties change?
>>
>> Thanks & regards
>> Philipp
>>
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>
Re: DependencyManager: notify third party object of changed adaptee
properties
Posted by Bulu <bu...@romandie.com>.
Addition to my own question:
I came up with the following, but the callbacks seem not to get called
on the deviceManager...
Component adapter = createAdapterService(Device.class,null)
.setImplementation(DeviceAdapter.class)
.setCallbacks(deviceManager, INIT_METHOD, START_METHOD, STOP_METHOD,
DESTROY_METHOD);
// Ugly: supposing the adapter has always the adaptee as first service
dependency
ServiceDependency dep = (ServiceDependency)
adapter.getDependencies().get(0);
logger.debug("Dependency is {}", dep); // OK, in my tests it's the right
dependency
dep.setCallbacks(deviceManager, BIND_METHOD, CHANGED_METHOD, UNBIND_METHOD);
mgr.add(adapter);
Is this the right way?
Regards Philipp
On 15.10.2014 14:12, Bulu wrote:
> Hello All
>
> Using Dependency Manager, I declare adapters like this:
> mgr.add(createAdapterService(Device.class,null)
> .setImplementation(DeviceAdapter.class)
> .setCallbacks(deviceManager, "init", "start", "stop", "destroy"));
>
> So deviceManager gets notified when the adapters appear. Now I also
> want deviceManager to be notified when the properties of any of the
> adaptees (Device.class) change (need to update the UI).
>
> For normal ServiceDependency I can specify callbacks to be called on a
> third party object with
> ServiceDependency.setCallbacks(Object instance, String added, String
> changed, String removed);
>
> For adapters and I can specify the callbacks, but only calling the
> adapter itself:
> createAdapterService(Device.class.name, null, "add", "change",
> "remove")
>
> How can I tell the adapter to use callbacks on a third party object
> (deviceManager) when the adaptee's properties change?
>
> Thanks & regards
> Philipp
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org