On 2017-07-21T16:57:20 -0400 Raymond Auge <raymond.a...@liferay.com> wrote: > > I hate to say it because I've done exactly this on several occasions...
:) > you get a List of tuples you can iterate over which will hold true to the > natural ordering of the services (via ServiceReference.compareTo) > > Then using a Filter (yes this part pulls in OSGi API, but very little) you > can use the streaming API to find "the best" match in the List (if one > exists): > > Filter filter = FrameworkUtil.createFilter("(format=PNG)"); > > Optional<ImageFormat> bestMatch = _formats.stream().sorted( > Collections.reverseOrder() // not totally sure you need this, I'm not sure about this. The compareTo call would give results in order of service ranking order, tiebreaking by selecting the service with the lowest ID (the oldest service). In the case of multiple versions of the same bundle being available, there's no guarantee that the bundle with the lower service ID is the older version. That's more likely to happen if the framework is running 24/7 (because a user might have installed a newer version of a bundle at some point and not uninstalled the old one), but for short-lived programs it doesn't necessarily hold. -- Mark Raynsford | http://www.io7m.com
pgpcW4qM3ZyA9.pgp
Description: OpenPGP digital signature
_______________________________________________ OSGi Developer Mail List osgi-dev@mail.osgi.org https://mail.osgi.org/mailman/listinfo/osgi-dev