Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » PackageAdmin deprecated?
PackageAdmin deprecated? [message #658414] Tue, 08 March 2011 07:23 Go to next message
Thomas Hallgren is currently offline Thomas Hallgren
Messages: 3214
Registered: July 2009
Senior Member
In some of my JUnit tests, I use the PackageAdmin method:

public Bundle[] getBundles(String symbolicName, String versionRange);

to find a bundle that I know contains some of the data that I need for the test. In 3.7, where OSGi 4.3 is used, I see
that PackageAdmin is deprecated and that I'm supposed to use org.osgi.framework.wiring instead. Problem is, I don't find
any similar method in that package.

What is the preferred way of finding a bundle by it's symbolic id in 4.3?

Regards,
Thomas Hallgren
Re: PackageAdmin deprecated? [message #658433 is a reply to message #658414] Tue, 08 March 2011 08:57 Go to previous messageGo to next message
Thomas Watson is currently offline Thomas Watson
Messages: 420
Registered: July 2009
Senior Member
Note that PackageAdmin is deprecated, but will not be removed any time soon in Equinox. There is no replacement method in wiring because this method is a convenience method and it was decided that it should not be moved to wiring.

OSGi has recommended that you iterate over the bundles to find the ones you need. I'm not a big fan of that approach because I know the Equinox implementation of PackageAdmin.getBundles will perform better when dealing with large sets of bundles. So in the mean time I would stick with PackageAdmin for only the getBundles(String symbolicName, String versionRange) method.

HTH

Tom.
Re: PackageAdmin deprecated? [message #658460 is a reply to message #658433] Tue, 08 March 2011 10:30 Go to previous messageGo to next message
Thomas Hallgren is currently offline Thomas Hallgren
Messages: 3214
Registered: July 2009
Senior Member
Hi Tom,

Thanks a lot for the clarification. It was very helpful.

- thomas

On 2011-03-08 14:57, Thomas Watson wrote:
> Note that PackageAdmin is deprecated, but will not be removed any time soon in Equinox. There is no replacement method
> in wiring because this method is a convenience method and it was decided that it should not be moved to wiring.
>
> OSGi has recommended that you iterate over the bundles to find the ones you need. I'm not a big fan of that approach
> because I know the Equinox implementation of PackageAdmin.getBundles will perform better when dealing with large sets of
> bundles. So in the mean time I would stick with PackageAdmin for only the getBundles(String symbolicName, String
> versionRange) method.
>
> HTH
>
> Tom.
>
Re: PackageAdmin deprecated? [message #1074688 is a reply to message #658433] Sat, 27 July 2013 09:22 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan Herrmann
Messages: 984
Registered: July 2009
Senior Member
Thomas Watson wrote on Tue, 08 March 2011 14:57
Note that PackageAdmin is deprecated, but will not be removed any time soon in Equinox.


Does this answer still hold for Luna and beyond?

Quote:
OSGi has recommended that you iterate over the bundles to find the ones you need.


Assuming I would want to do s.t. like that, what would be the entry point for this?

Quote:
So in the mean time I would stick with PackageAdmin for only the getBundles(String symbolicName, String versionRange) method.


Is this your recommendation also when I don't have a versionRange at hand and therefore pass null instead?

thanks,
Stephan
Re: PackageAdmin deprecated? [message #1075453 is a reply to message #1074688] Mon, 29 July 2013 09:04 Go to previous messageGo to next message
Thomas Watson is currently offline Thomas Watson
Messages: 420
Registered: July 2009
Senior Member
Stephan Herrmann wrote on Sat, 27 July 2013 08:22
Thomas Watson wrote on Tue, 08 March 2011 14:57
Note that PackageAdmin is deprecated, but will not be removed any time soon in Equinox.


Does this answer still hold for Luna and beyond?


Yes, no plans to remove PackageAdmin implementation for the foreseeable future.

Quote:

Quote:
OSGi has recommended that you iterate over the bundles to find the ones you need.


Assuming I would want to do s.t. like that, what would be the entry point for this?


For OSGi R6 there is new API. FrameworkAdmin.findProviders(Requirement). If you wanted to find all bundles with symbolic name "com.foo". Then it would look something like this:


FrameworkWiring fwkWiring = systemBundle.adapt(FrameworkWiring.class);
Collection<BundleCapability> comFooIdentities = fwkWiring.findProviders(
    new Requirement(){
        public String getNamespace() { return IdentityNamespace.IDENTITY_NAMESPACE; }
        public Map<String, String> getDirectives() {
            Collections.singletonMap(Namespace.REQUIREMENT_FILTER_DIRECTIVE,
                "(osgi.identity=com.foo)");
        }
        public Map<String, Object> getAttributes() {
            return Collections.EMPTY_MAP
        }
        public Resource getResource() {
            return null;
        }
    }
);


After this you will have a Collection<BundleCapability> that contain osgi.identity capabilities all with the symbolic name "com.foo". You can then get to the bundle object behind each capability by calling BundleCapability.getRevision().getBundle().

See the PackageAdmin implementation for more:

http://git.eclipse.org/c/equinox/rt.equinox.framework.git/tree/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/legacy/PackageAdminImpl.java#n148

Quote:

Quote:
So in the mean time I would stick with PackageAdmin for only the getBundles(String symbolicName, String versionRange) method.


Is this your recommendation also when I don't have a versionRange at hand and therefore pass null instead?



Yes, a null versionRange means any version. At this point moving away from PackageAdmin is not really a high priority in my mind. If it works for you then feel free to continue using it. I certainly do not plan to remove it from equinox any time soon.

Tom
Re: PackageAdmin deprecated? [message #1075646 is a reply to message #1075453] Mon, 29 July 2013 16:15 Go to previous message
Stephan Herrmann is currently offline Stephan Herrmann
Messages: 984
Registered: July 2009
Senior Member
Thanks for confirming. The new generic approach is sure more powerful, but for the normal case it looks pretty bloated Smile

Stephan
Previous Topic:Where's the bundle pool?
Next Topic:Redeploy RAP-Application on WebSphere and JBoss fails
Goto Forum:
  


Current Time: Tue Jul 29 18:55:41 EDT 2014

Powered by FUDForum. Page generated in 0.02638 seconds