You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Mohica Jasha <mo...@gmail.com> on 2012/01/27 19:00:41 UTC

multiple configuration dependency

I have two OSGi services: service1 and service2 and each has its own
service PIDs: "service1.pid" and "service2.pid"

service1 only depends on its own configuration, but service2 depends on
both its configuration and service2 configuration and should also get
informed of any updates of service2's configuration.
Is it possible to use dependency manager annotation, i.e.,
@ConfigurationDependency, to specify both of configuration dependencies of
service2?

Thanks in advance,
M

Re: multiple configuration dependency

Posted by Pierre De Rop <pi...@gmail.com>.
Hi Mohica,

After more investigations, there is no bugs, and I forgot to tell you about
the "changed" attribute from the ServiceDependency annotation.

The "changed" attribute allows to define a callback method when the service
properties are updated, so coming back to the second case in the previous
example, where both services are packaged in different bundles, then in
service2, you can define the dependency over service1 using the "changed"
callback attribute, and the service2 "changed" callback will then be
invoked when you update the the service1 configuration:

@Component
public class Service2
{
 // ...

 // Use a ServiceDependency instead of a ConfigurationDependency
 // on Service2, and retrieve service2 configuration using service2
 // osgi service properties.
 // Also define a "changed" callback in order to see service1 service
properties
 // modification

 @ServiceDependency(changed="updateService1")
 void bindService1(Map<String, ?> config, Service1Interfaceservice1)
 {
    System.out.println("Service2 got Service1 properties: " + config);
 }

 void updateService1(Map<String, ?> config, Service1Interfaceservice1)
 {
    System.out.println("Service2 updated with Service1 properties: " +
config);
 }
}

kind regards;
/Pierre



On Tue, Jan 31, 2012 at 10:33 AM, Pierre De Rop <pi...@gmail.com>wrote:

> Hi Mohica,
>
> This sounds like a bug, I will investigate asap.
>
> regards
> /pierre
>
>
> On Mon, Jan 30, 2012 at 9:56 PM, Mohica Jasha <mo...@gmail.com>wrote:
>
>> On Mon, Jan 30, 2012 at 8:11 AM, Pierre De Rop <pierre.derop@gmail.com
>> >wrote:
>>
>> >     // Use a ServiceDependency instead of a ConfigurationDependency on
>> > Service2, and
>> >     // retrieve service2 configuration using service2 osgi service
>> > properties
>> >    @ServiceDependency
>> >    protected void bindService1(Map<String, ?> config, Service1Interface
>> > service1)
>> >    {
>> >        System.out.println("Service2 got Service1 properties: " +
>> config);
>> >    }
>> > }
>> >
>> >
>> Thanks you very much for you elaborate answer.
>> I think the bindService1 is invoked just once, and if service1's
>> configuration is changed then service2 does not get informed. Am I right?
>> Is there any easy workaround solution for getting updates of service1's
>> configuration?
>>
>> Thanks,
>> Mohica
>>
>>
>>
>>
>> > Hope this helps,
>> > /Pierre
>> >
>> > On Fri, Jan 27, 2012 at 7:00 PM, Mohica Jasha <mohica.jasha@gmail.com
>> > >wrote:
>> >
>> > > I have two OSGi services: service1 and service2 and each has its own
>> > > service PIDs: "service1.pid" and "service2.pid"
>> > >
>> > > service1 only depends on its own configuration, but service2 depends
>> on
>> > > both its configuration and service2 configuration and should also get
>> > > informed of any updates of service2's configuration.
>> > > Is it possible to use dependency manager annotation, i.e.,
>> > > @ConfigurationDependency, to specify both of configuration
>> dependencies
>> > of
>> > > service2?
>> > >
>> > > Thanks in advance,
>> > > M
>> > >
>> >
>>
>
>

Re: multiple configuration dependency

Posted by Pierre De Rop <pi...@gmail.com>.
Hi Mohica,

This sounds like a bug, I will investigate asap.

regards
/pierre

On Mon, Jan 30, 2012 at 9:56 PM, Mohica Jasha <mo...@gmail.com>wrote:

> On Mon, Jan 30, 2012 at 8:11 AM, Pierre De Rop <pierre.derop@gmail.com
> >wrote:
>
> >     // Use a ServiceDependency instead of a ConfigurationDependency on
> > Service2, and
> >     // retrieve service2 configuration using service2 osgi service
> > properties
> >    @ServiceDependency
> >    protected void bindService1(Map<String, ?> config, Service1Interface
> > service1)
> >    {
> >        System.out.println("Service2 got Service1 properties: " + config);
> >    }
> > }
> >
> >
> Thanks you very much for you elaborate answer.
> I think the bindService1 is invoked just once, and if service1's
> configuration is changed then service2 does not get informed. Am I right?
> Is there any easy workaround solution for getting updates of service1's
> configuration?
>
> Thanks,
> Mohica
>
>
>
>
> > Hope this helps,
> > /Pierre
> >
> > On Fri, Jan 27, 2012 at 7:00 PM, Mohica Jasha <mohica.jasha@gmail.com
> > >wrote:
> >
> > > I have two OSGi services: service1 and service2 and each has its own
> > > service PIDs: "service1.pid" and "service2.pid"
> > >
> > > service1 only depends on its own configuration, but service2 depends on
> > > both its configuration and service2 configuration and should also get
> > > informed of any updates of service2's configuration.
> > > Is it possible to use dependency manager annotation, i.e.,
> > > @ConfigurationDependency, to specify both of configuration dependencies
> > of
> > > service2?
> > >
> > > Thanks in advance,
> > > M
> > >
> >
>

Re: multiple configuration dependency

Posted by Mohica Jasha <mo...@gmail.com>.
On Mon, Jan 30, 2012 at 8:11 AM, Pierre De Rop <pi...@gmail.com>wrote:

>     // Use a ServiceDependency instead of a ConfigurationDependency on
> Service2, and
>     // retrieve service2 configuration using service2 osgi service
> properties
>    @ServiceDependency
>    protected void bindService1(Map<String, ?> config, Service1Interface
> service1)
>    {
>        System.out.println("Service2 got Service1 properties: " + config);
>    }
> }
>
>
Thanks you very much for you elaborate answer.
I think the bindService1 is invoked just once, and if service1's
configuration is changed then service2 does not get informed. Am I right?
Is there any easy workaround solution for getting updates of service1's
configuration?

Thanks,
Mohica




> Hope this helps,
> /Pierre
>
> On Fri, Jan 27, 2012 at 7:00 PM, Mohica Jasha <mohica.jasha@gmail.com
> >wrote:
>
> > I have two OSGi services: service1 and service2 and each has its own
> > service PIDs: "service1.pid" and "service2.pid"
> >
> > service1 only depends on its own configuration, but service2 depends on
> > both its configuration and service2 configuration and should also get
> > informed of any updates of service2's configuration.
> > Is it possible to use dependency manager annotation, i.e.,
> > @ConfigurationDependency, to specify both of configuration dependencies
> of
> > service2?
> >
> > Thanks in advance,
> > M
> >
>

Re: multiple configuration dependency

Posted by Pierre De Rop <pi...@gmail.com>.
Hi Mohica,

Assuming that service2 needs configuration from service1.pid and
service2.pid, then there are two cases:

1) case 1: if both services (service1/service2) are packaged in the same
bundle, then yes, service2 may define two configuration dependencies on
both pids, for instance like this:

First, let's define the configuration for service1: (we also define the
meta type params, allowing to configure the service1.pid from webconsole):

@Component
public class Service1
{
    @ConfigurationDependency(pid="service1.pid",
            heading = "Service1 configuration",
            description = "Service1 configuration description",
            metadata = {
                @PropertyMetaData(heading = "Service1 property",
                                  description = "Service1 property
description",
                                  defaults = { "def" },
                                  id = "service1.property",
                                  cardinality = 0)
            }
        )
    protected void updated(Dictionary<String, ?> config)
    {
        System.out.println("Service1 got config: " + config);
    }
}

Now, let's define the service2, which depend on both configurations (but
here, when defining the configuration dependency over service1.pid, we only
indicate the pid, not the metatype infos, which already have been defined
in Service1 class):

@Component
public class Service2
{
    @ConfigurationDependency(pid="service2.pid",
                             heading = "Service2 configuration",
                             description = "Service2 configuration
description",
                             metadata = {
                                 @PropertyMetaData(heading = "Service2
property",
                                                   description = "Service2
property description",
                                                   defaults = { "def" },
                                                   id =
"service2.property",
                                                   cardinality = 0)
                             }
                         )
    protected void service2updated(Dictionary<String, ?> config)
    {
        System.out.println("Service2 got config: " + config);
    }

    @ConfigurationDependency(pid="service1.pid")
    protected void service2updatedWithService1Properties(Dictionary<String,
?> config)
    {
        System.out.println("Service2 got Service1 properties: " + config);
    }
}

2) case 2: if the two services (service1 and service2) are packaged in
different bundles, then the service2 won't be able to see the configuration
pid from service1. it is the configadmin spec which specifies this
restriction, but this restriction has been relaxed in osgi 4.3, and I don't
know if it has been implemented in the current configadmin from the trunk).

So, in this case, one option consists in doing the following: you can
manage to let the service1 expose itself as a service, and also propagate
the service1 configuration properties to the service1 osgi service
properties. In this way, service2 may depend on the service1 osgi service,
which will be injected with the service properties (including the service1
configuration).

For instance, let's define the service1 with the "propagage=true" optional
parameter in the configurationdependency: this properties will ensure that
configuration is propagated to the osgi service properties:

@Component
public class Service1 implements Service1Interface /* we provide the
Service1Interface service in service registry */
{
    @ConfigurationDependency(pid="service1.pid",
            propagate = true, // configuration is propagated to our osgi
service properties
            heading = "Service1 configuration",
            description = "Service1 configuration description",
            metadata = {
                @PropertyMetaData(heading = "Service1 property",
                                  description = "Service1 property
description",
                                  defaults = { "def" },
                                  id = "service1.property",
                                  cardinality = 0)
            }
        )
    protected void updated(Dictionary<String, ?> config)
    {
        System.out.println("Service1 got config: " + config);
    }
}

Then if we get back to the service2; we can now depend on the
Service1Interface, and use a Map parameter in order to receive the service1
service properties, like this:

@Component
public class Service2
{
    // ...

     // Use a ServiceDependency instead of a ConfigurationDependency on
Service2, and
     // retrieve service2 configuration using service2 osgi service
properties
    @ServiceDependency
    protected void bindService1(Map<String, ?> config, Service1Interface
service1)
    {
        System.out.println("Service2 got Service1 properties: " + config);
    }
}

Hope this helps,
/Pierre

On Fri, Jan 27, 2012 at 7:00 PM, Mohica Jasha <mo...@gmail.com>wrote:

> I have two OSGi services: service1 and service2 and each has its own
> service PIDs: "service1.pid" and "service2.pid"
>
> service1 only depends on its own configuration, but service2 depends on
> both its configuration and service2 configuration and should also get
> informed of any updates of service2's configuration.
> Is it possible to use dependency manager annotation, i.e.,
> @ConfigurationDependency, to specify both of configuration dependencies of
> service2?
>
> Thanks in advance,
> M
>