Is it safe to use the same dictionary to register multiple services ?

2013-01-24 Thread Christopher BROWN
Hello,

I am implementing a bit of code with Apache Felix and in a specific code
block, I register multiple services, all with the same non-default service
ranking.

I read the registering services part of the OSGi 4.3 specifications, and
it seems to suggest that implementations will copy the service properties
(changes to the properties object may not be applied, use setProperties()
instead...).  The wording does suggest though that this behavior is
implementation-specific.

Should I create a new Dictionary object for each service registered, or can
I reuse the same instance?  I'd prefer an authoritative answer as opposed
to just observing behavior with a specific implementation.

For example, if the implementation used the supplied properties internally,
it could for example add the object class and service id ; if I reused the
instance, things could get mixed up.

Thanks,
Christopher


Re: Is it safe to use the same dictionary to register multiple services ?

2013-01-24 Thread Richard S. Hall

On 1/24/13 06:42 , Christopher BROWN wrote:

Hello,

I am implementing a bit of code with Apache Felix and in a specific code
block, I register multiple services, all with the same non-default service
ranking.

I read the registering services part of the OSGi 4.3 specifications, and
it seems to suggest that implementations will copy the service properties
(changes to the properties object may not be applied, use setProperties()
instead...).  The wording does suggest though that this behavior is
implementation-specific.

Should I create a new Dictionary object for each service registered, or can
I reuse the same instance?  I'd prefer an authoritative answer as opposed
to just observing behavior with a specific implementation.

For example, if the implementation used the supplied properties internally,
it could for example add the object class and service id ; if I reused the
instance, things could get mixed up.


Well, the JavaDoc says changes should not be made to this object, which 
could imply that the framework now owns the dict after registering a 
service.


And here under registering services the spec says:

   Using the ServiceRegistration object is the only way to reliably
   change the service object’s properties after it has been registered
   (see setProperties(Dictionary)). Modifying a service object’s
   Dictionary object after the service object is registered may not
   have any effect on the service’s properties.

This implies that it is up to the framework as to whether it copies or not.

So, I am thinking you should make copies yourself to be safe, even 
though I think most frameworks do make copies already.

OSGi Core Release 5
- richard



Thanks,
Christopher