2009/3/17 Fredrik Alströmer <[email protected]> > Hi, > > I'm sure this has already been discussed, but I was working with some > stuff that was using annotations, when it hit me that it's rather > inconvenient to publish an OSGi service based on an annotation. You'd > have to publish it using java.lang.Object,
I don't see why you couldn't publish the service instance as normal - ie. if you just want to filter on the annotation then add it to the service properties under a known key also wouldn't you still have an API in mind when using the service? clients would still presumably cast the service to a known type before using it, so use that type perhaps an example would help explain your use-case? and come up with some (not standardized) property to contain the FQ-name of > the annotation. or an array of names if you want to be flexible and filter on more than one annotation at a time, like objectclass does with types > There's also no 'type-safety' involved which checks to see if the > class of the returned service-object does indeed carry the required > annotation. > you could add this check in whatever framework is adding the annotation information to service properties - I don't believe it requires any change to the minimal OSGi core > Considering that it's not possible to 'implement' an annotation actually it is possible to implement annotations, you just have to follow the specification from the javadoc: http://java.sun.com/javase/6/docs/api/java/lang/annotation/Annotation.html Guice does this (it has @Named and NamedImpl.class) (which would produce clashes), would it be a viable addition to the spec to > allow service objects to be registered (extrapolate as needed to > service factories) using an FQ-name of an annotation as > 'interface'-name, where the framework is responsible for checking that > said service object does indeed carry the annotation? This is of > course assuming that annotations are supported in the runtime > environment, but it does not impose such an assumption on any > interfaces, and so the spec is still valid in pre-annotation > environments. As far as I can tell, annotations are used primarily > (only?) in combination with reflection, so there's no real reason to > provide an actual type-check. > personally I'd see this as something optional on top of the core OSGi spec - afaik there's no reason why you couldn't implement this today using existing APIs I can see that there might be concerns in the general direction of > proxy objects, but then again, I believe those have a problem in > general with respect to annotations? > generally yes, but as Neil pointed out most OSGi service instances are not proxied - it's left up to the OSGi framework to decide whether it wants to do any proxying (most don't) however, component models built on top of OSGi do use proxies (but again, not all the time - it depends on the circumstances) > Greetings, > Fredrik. > _______________________________________________ > OSGi Developer Mail List > [email protected] > https://mail.osgi.org/mailman/listinfo/osgi-dev > -- Cheers, Stuart
_______________________________________________ OSGi Developer Mail List [email protected] https://mail.osgi.org/mailman/listinfo/osgi-dev
