mapeters
mapeters

Reputation: 1117

How can I run a subprocess in Equinox with dynamic bundle installation?

I have a Java application that runs in OSGi/Equinox. From this application, I need to spawn Java subprocesses (e.g. via ProcessBuilder.start()) that run in OSGi/Equinox as well in order to handle class loading correctly. The subprocess will require multiple bundles, so I would ideally like some fairly dynamic way of installing those bundles in the subprocess' Equinox container, such as by reading feature.xml files.

I have read through program launching here but I don't see how Equinox can fit into it. I also looked into doing something like this, but it wouldn't be very dynamic, especially when the entry-point bundle of the subprocess requires multiple other bundles, which require further bundles, etc.

So, how can I spawn a subprocess to run in OSGi/Equinox with a fairly dynamic way of loading bundles into the container?

Note: I need to use separate processes. The subprocesses will do data processing using a JNA native library that uses global variables (and I can't modify the native library). So, in order to be able to process different data concurrently, the data processing needs to run in separate processes.

Upvotes: 44

Views: 649

Answers (2)

Abhist Dubey
Abhist Dubey

Reputation: 11

Equinox is the OSGi (Open Services Gateway Initiative) framework implementation used in Eclipse. Running a sub process in Equinox with dynamic bundle installation involves interacting with the Equinox OSGi framework to install and start bundles dynamically.

Upvotes: 1

you can use the Equinox Launcher API. Here's an example of how you can use the Equinox Launcher api to launch a new instance of equinox with a set of bundles: `

EquinoxLauncher launcher = new EquinoxLauncher();
String equinoxHome = "/path/to/equinox/home"; 
String[] bundlePaths = { "/path/to/bundle1.jar", "/path/to/bundle2.jar" }; 

EquinoxRunConfiguration runConfig = launcher.newConfiguration();
runConfig.setWorkingDir(new File(equinoxHome));
runConfig.setFramework(new File(equinoxHome, "plugins/org.eclipse.osgi.jar"));
runConfig.addProgramArg("-console");
runConfig.addProgramArg("-noExit");
for (String bundlePath : bundlePaths) {
    runConfig.addBundle(new File(bundlePath).toURI());
}

EquinoxRunMonitor monitor = launcher.launch(runConfig);

`

Upvotes: 0

Related Questions