Overview

RM offers support for matching the execution environment, required by a bundle, against the runtime environment of an OSGi device. The term "execution environment" (abbreviated as "EE") is defined by the OSGi Alliance in the OSGi Service Platform Service Compendium Specification, Release 4 . You can find more information on EE management in RM in Execution Environment Management Conceptual Guide.
The EE Management API is placed in the com.prosyst.admin.ee package and its main interface is EEManager. The API represents an execution environment as an EE instance, which can contain classes and interfaces with methods and fields described by FieldOrMethod objects.
The EEManager interface is implemented and registered as a service by the Execution Environment Manager bundle (packages/genericosgi/genericosgi.ee.be.jar) on a backend (CC, RAS and MS) OSGi framework.
Developer can also use the lib/api/genericosgi-api.jar archive for development and compilation of applications based on the EE Management API.

Accessing the EE Management API

The EE Management API can be accessed as a front-end API:

  • On the RM backend as a service on the backend framework by other bundles. You use the methods defined by the OSGi Framework specification.

Retrieving the EEManager service object in the context of a backend OSGi framework:


import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import com.prosyst.mprm.admin.ee.EEManager;
public class EETesterBundle implements BundleActivator {
 
private ServiceReference eeMngrRef = null;
 
public void start(BundleContext bc) throws Exception {
eeMngrRef = bc.getServiceReference(EEManager.class.getName());
EEManager eeMngr = (EEManager) bc.getService(eeMngrRef);
// Perform some operations with EEManager
. . .
}
 
public void stop(BundleContext bc) throws Exception {
if (eeMngrRef != null) {
bc.ungetService(eeMngrRef);
}
}
}
  • Through the remote access client (RAC) from a destination remote to the RM backend. The RAC class libraries to use are lib/rac/system-rac.jar and lib/rac/genericosgi-rac.jar. See Remote Access to RM for more information about using a remote access client.

Retrieving the EEManager service object through RAC:

import java.util.Hashtable;
import com.prosyst.mprm.admin.ee.EEManager;
import com.prosyst.mprm.rac.RemoteAccessClient;
 
public class EETester() {
public static void main(String[] args) throws Exception {
Hashtable connProps = new Hashtable();
connProps.put(RemoteAccessClient.CONNECT_TO_CC, "true");
Hashtable credentials = new Hashtable();
credentials.put(RemoteAccessClient.USER_PASSWORD, "system");
RemoteAccessClient rac = RemoteAccessClient.connect(
"socket://localhost:11449",
"system",
credentials,
connProps);
EEManager eeMngr = (EEManager) rac.getService(EEManager.class.getName());
// Perform some operations with EEManager
. . .
}
}


Adding an Execution Environment

To add a new execution environment to RM, call the addEE(String name, String description, InputStream is) method of EEManager with EE name, description and input stream to the EE JAR file. The addEE method does not accept null or empty string as EE name, as well as tabulation, new line, white space or comma contained in the name.
Adding new EE:

import java.io.FileInputStream;
import com.prosyst.mprm.admin.ee.EE;
import com.prosyst.mprm.admin.ee.EEManager;
. . .
private static void addEE(EEManager eeMngr) throws Exception {
String eePath = "D:\\jvm\\jeode\\win32\\x86\\lib\\i18n.jar";
String eeName = "Jeode/i18n";
FileInputStream in = new FileInputStream(eePath);
if (eeMngr != null && in != null) {
if (eeMngr.getEE(eeName) == null) {
EEee = eeMngr.addEE(eeName, "Jeode class library for i18n", in);
. . .
}
}
}

Retrieving Stored Execution Environments

Getting an EE

Basically, there are two ways to retrieve one or more execution environment:

  • Getting a single EE by using the EEManager's getEE method for an EE with a known name.
  • Getting a list of all EEs, of JVM EEs or of library EEs by using the EEManager's listEE method with filter EEManager.ALL_EE, EEManager.JVM_EE or EEManager.LIB_EE respectively. The listEE method returns a com.prosyst.mprm.data.Enumerator of the matching EE objects.


Getting an EE instance:

import com.prosyst.mprm.admin.ee.EE;
import com.prosyst.mprm.admin.ee.EEManager;
import com.prosyst.mprm.data.Enumerator;
. . .
 
private static void listEE(EEManager eeMngr) throws Exception {
Enumerator eeJvmIndex = eeMngr.listEE(EEManager.JVM_EE);
while (eeJvmIndex.hasMoreElements()) {
EE tmpJvmEE = (EE) eeJvmIndex.nextElement();
System.out.println("[EETester] jvm ee " + tmpJvmEE);
}
eeJvmIndex.close();
Enumerator eeLibIndex = eeMngr.listEE(EEManager.LIB_EE);
while (eeLibIndex.hasMoreElements()) {
EE tmpLibEE = (EE) eeLibIndex.nextElement();
System.out.println("[EETester] lib ee " + tmpLibEE);
}
eeLibIndex.close();
}


Getting the Names of Stored EEs

You can get the names of all stored EE by using the getEENames method of EEManager passing as an argument one of the following constants: EEManager.ALL_EE, EEManager.JVM_EE or EEManager.LIB_EE. The method returns an Enumerator of String objects, representing EE names.

Retrieving the Content of an EE


The EE Management API allows you to analyze the classes and interfaces of an EE as well as their methods and fields.

To list the classes (as Strings) of an EE instance, use the getClasses method. Next, for a particular class call the EE's getClassContent method, which returns an array of FieldOrMethod objects which represent the methods or fields of the corresponding class. The FieldOrMethod methods allow you to further study the properties of the method or field.

Exploring the content of an EE:

import com.prosyst.mprm.admin.ee.EE;
import com.prosyst.mprm.admin.ee.EEManager;
import com.prosyst.mprm.admin.ee.FieldOrMethod;
import com.prosyst.mprm.data.Enumerator;
. . .
 
private static void getEEContent(EEManager eeMngr, String eeName) throws Exception {
EE ee = eeMngr.getEE(eeName);
Enumerator classIndex = ee.getClasses();
while (classIndex.hasMoreElements()) {
String clazz = (String) classIndex.nextElement();
FieldOrMethod[] members = ee.getClassContent(clazz);
System.out.println(clazz);
for (int i = 0; i < members.length; i++) {
System.out.println("\t" + members[i].getName());
}
}
classIndex.close();
}


Converting an EE JAR File

Besides operations on the RM execution environment storage, the EE Management API supports reducing the size of an EE JAR file by removing the CODE attribute from its class files. To convert an EE JAR, call the convert method of EEManager specifying the input stream to the original JAR and the output stream to the reduced JAR.
Converting the JAR file of an EE:

import java.io.InputStream;
import java.io.OutputStream;
import com.prosyst.mprm.admin.ee.EEManager;
. . .
private static void convertEEJar(EEManager eeMngr) throws Exception {
InputStream in = new FileInputStream("D:\\jvm\\jeode\\win32\\x86\\lib\\i18n.jar");
OutputStream out = new FileOutputStream("D:\\jvm\\jeode\\win32\\x86\\lib\\i18n_reduced.jar");
eeMngr.convert(in, out);
. . .
}

Removing an Execution Environment

To remove an execution environment from RM, use the removeEE method of EEManager. To remove all execution environments with a single call, invoke the removeAllEE method.