osgi / bugzilla-archive

Archive of OSGi Alliance Specification Bugzilla bugs. The Specification Bugzilla system was decommissioned with the move to GitHub. The issues in this repository are imported from the Specification Bugzilla system for archival purposes.
0 stars 1 forks source link

Provide a way to get a ServiceReferenceDTO for a Service #2985

Closed bjhargrave closed 4 years ago

bjhargrave commented 5 years ago

Original bug ID: BZ#3117 From: @cziegeler Reported version: R7

bjhargrave commented 5 years ago

Comment author: @cziegeler

There are currently two ways to get a ServiceReferenceDTO: traversing down from a FrameworkDTO and adapting a bundle to an array of ServiceReferenceDTOs. Both approaches are not waisting a lot of resources to get a single reference.

I assume the easiest way would be to add an adapt method to ServiceReference

bjhargrave commented 5 years ago

Comment author: @bjhargrave

CPEG call: Agree to add adapt method to ServiceReference. Target types to include ServiceReferenceDTO, Map(service properties), Bundle (registering bundle).

Also have ServiceReference extends BundleReference.

bjhargrave commented 4 years ago

Comment author: @bjhargrave

Fixed by https://osgi.org/gitweb/build.git/commit/70eec607be7fc06b37f7ff2ffedbc7379621f6ac

This change adds an adapt method to ServiceReference and changes ServiceReference to extend BundleReference.

ServiceReference can only be adapted to ServiceReferenceDTO. I also added a CT method for the adaption.

There is no point in adapting ServiceReference to Bundle since there is already a getBundle method (now via BundleReference).

Also, the change does not support adapting to Map. There is already a getProperties() method which returns Dictionary which can be wrapped to a Map with the new FrameworkUtil.asMap method. Adapting to Map.class would loose any generic information which means the caller would need to suppress warnings.

@ SuppressWarnings("unchecked") Map<String,Object> props = ref.adapt(Map.class);

FrameworkUtil.asMap(ServiceReference.getProperties()) will return a properly generified Map with no warnings.

Map<String,Object> props = FrameworkUtil.asMap(ref.getProperties());

We just need to framework RI updated for adapting ServiceReference to a ServiceReferenceDTO. Assigning to Tom to update the RI.

bjhargrave commented 4 years ago

Comment author: @bjhargrave

RI done. Need CT changes.

bjhargrave commented 4 years ago

Comment author: @bjhargrave

CT was updated!