felix-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher BROWN <br...@reflexe.fr>
Subject Re: Type-safe registration with ServiceFactory and Felix 4.4.1
Date Mon, 11 Aug 2014 08:43:55 GMT
To complete my previous message, this is what I've implemented as a helper
method, but I'm unclear as to whether it's correct or not.

@SuppressWarnings("unchecked")
public static <S> ServiceRegistration<S> register(
BundleContext bundleContext,
 Class<S> serviceType,
ServiceFactory<S> serviceFactory,
 Dictionary<String, ?> serviceRegistrationProperties
)
{
return (ServiceRegistration<S>)bundleContext.registerService(
 serviceType.getName(),
serviceFactory,
 serviceRegistrationProperties)
);
}

I seem to be obliged to use the "String" overload, and not the new "Class"
overload of the "BundleContext.register" method, as <S> is incompatible
with all other approaches I've tried.

With current JVMs (that don't implement reification) it's probably more of
a theoretical problem than anything else, but I'm still unsure about what
is intended by the BundleContext / ServiceRegistration / ServiceFactory
APIs here, and I'd like to get it right.

Thanks,
Christopher


On 11 August 2014 10:26, Christopher BROWN <brown@reflexe.fr> wrote:

> Hello,
>
> I'm upgrading an application that embedded Felix 3.2.2 to Felix 4.4.1 and
> am trying to use generics as intended.  Generally, things are working out
> well, however, it doesn't seem straightforward to use the ServiceFactory<S>
> interface with:
>
> BundleContext.registerService(Class<S> clazz, S service,
> Dictionary<String,?> properties)
>
> If "service" is a ServiceFactory instance, then "clazz" isn't compatible
> with "service" (in terms of generics).  If I specify the
> MyServiceFactory.class (where MyServiceFactory implements
> ServiceFactory<MyType>) then javac expects a service registration with a
> type of ServiceFactory, and not of the service's type, which is not what I
> would have expected compared with the "String" variant.
>
> How is this supposed to be used?  Is the ServiceRegistration supposed to
> be of type MyServiceFactory or of the interface of MyType ?
>
> Thanks,
> Christopher
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message