Java Reference
In-Depth Information
listed. You loop through the discovered resources and print their presentation name,
symbolic name, and version.
You can now use this command to configure repositories and discover bundles.
After you've discovered a bundle you want to use, you need to deploy it. You'll imple-
ment a separate command for that next.
DEPLOYING BUNDLES WITH OBR
Discovering bundles is one half of the
OBR
story; the other half is deploying them and
their dependencies into the framework. The
RepositoryAdmin.getResolver()
method gives you access to a
Resolver
object to select, resolve, and deploy resources.
A
Resolver
has these methods:
public interface Resolver {
void add(Resource resource);
Requirement[] getUnsatisfiedRequirements();
Resource[] getOptionalResources();
Requirement[] getReason(Resource resource);
Resource[] getResources(Requirement requirement);
Resource[] getRequiredResources();
Resource[] getAddedResources();
boolean resolve();
void deploy(boolean start);
}
The process for deploying resources is fairly simple. Follow these steps:
1
Add desired resources using
Resolver.add()
.
2
Resolve the desired resources' dependencies with
Resolver:resolve()
.
3
If the desired resources resolve successfully, deploy them with
Resolver.
deploy()
.
The following listing implements an
obr-resolver
shell command to resolve and
deploy resources.
Listing 10.3 OBR resolver shell command example
public class ResolverCommand extends BasicCommand {
public void exec(String args, PrintStream out, PrintStream err)
throws Exception {
RepositoryAdmin admin = getRepositoryAdmin();
Resolver resolver = admin.resolver();
Resource[] resources = admin.discoverResources(args);
if ((resources != null) && (resources.length > 0)) {
resolver.add(resources[0]);
if (resolver.resolve()) {
for (Resource res : resolver.getRequiredResources()) {
out.println("Deploying dependency: " +
res.getPresentationName() +
" (" + res.getSymbolicName() + ") " + res.getVersion());
}
resolver.deploy(true);
} else {
B
Resolves
resource
Deploys
bundle
C