Java Reference
In-Depth Information
Listing 3.20 Bundle refresh command
package org.foo.shell;
import java.io.PrintStream;
import java.util.*;
import org.osgi.framework.Bundle;
import org.osgi.service.packageadmin.PackageAdmin;
public class RefreshCommand extends BasicCommand {
public void exec(String args, PrintStream out, PrintStream err)
throws Exception {
if (args == null) {
getPackageAdminService().refreshPackages(null);
} else {
List<Bundle> bundles = new ArrayList<Bundle>();
StringTokenizer tok = new StringTokenizer(args);
while (tok.hasMoreTokens()) {
bundles.add(getBundle(tok.nextToken()));
}
getPackageAdminService().refreshPackages(
bundles.toArray(new Bundle[bundles.size()]));
}
}
B
Lists bundles to
be refreshed
Passes array of
bundles to Package
Admin Service
C
private PackageAdmin getPackageAdminService() {...}
}
Just as in the resolve command, you rely on the magic method to get the Package
Admin Service. You use the PackageAdmin.refreshPackages() method to refresh
bundles. If no arguments are given to the command, you pass in null to the Package
Admin Service. This results in the framework refreshing all previously updated and
uninstalled bundles since the last refresh. This captures the update and uninstall cases
presented earlier, but it doesn't help with the rewiring case. You achieve that by pass-
ing in the specific bundles you want refreshed. For this case, the refresh command
accepts an argument of whitespace-separated bundle identifiers. You parse their iden-
tifiers out of the supplied argument, retrieve their associated Bundle object, and add
them to a list to be refreshed B . You then pass in the array of bundles to refresh to
the Package Admin Service C .
The PackageAdmin.refreshPackages() method updates or removes packages
exported by the bundles being refreshed. The method returns to the caller immedi-
ately and performs the following steps on a separate thread:
It computes the graph of affected dependent bundles, starting from the speci-
fied bundles (or from all updated or uninstalled bundles if null is specified).
Any bundle wired to a package currently exported by a bundle in the graph is
added to the graph. The graph is fully constructed when there is no bundle out-
side the graph wired to a bundle in the graph.
1
Each bundle in the graph in the ACTIVE state is stopped, moving it to the
RESOLVED state.
2
 
Search WWH ::




Custom Search