Overview

A service application is a client bundle or a group of client bundles which provide a specific functionality. It is installed, uninstalled and managed as a single entity.

The Service Application Management package provides the Frontend API for operations with Service Applications through the RM Backend. It is possible to install, uninstall, start and stop service applications on specific device.

Accessing the Frontend API

You can access the Application Manager:

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

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
 
import com.prosyst.mprm.admin.application.ApplicationManager;
import org.osgi.framework.ServiceReference;
 
public class Activator implements BundleActivator {
private ServiceReference ref;
private ApplicationManager appManager;
//Method inherited by the Bundle Activator
public void start(BundleContext bc) throws Exception {
// Retrieve the Application Manager as an OSGi service from the framework
ref = bc.getServiceReference(ApplicationManager.class.getName());
if (ref != null) {
appManager = (ApplicationManager)bc.getService(ref);
}
if (appManager != null) {
//Do some work with the obtained Application Manager
...
}
}
  • Through the remote access client from a destination remote to RM backend. The service is accessed by the RemoteAccessClient.getService(String className) method. To access the Frontend API the classpath should include the system-rac.jar , gdm-rac.jar and ssm-rac.jar files. 
import com.prosyst.mprm.admin.application.ApplicationManager;
import com.prosyst.mprm.rac.RemoteAccessClient;
import java.util.Hashtable;
 
public static void main(String[] args) {
 
try { //Open session using valid user account. Hashtable credentials = new Hashtable();
credentials.put(RemoteAccessClient.USER_PASSWORD, <user_password>);
RemoteAccessClient rac = RemoteAccessClient.connect("socket://<mprm_host_address>:11449", <user_name>, credentials, null);
//Now the application can access RM ApplicationManager service
ApplicationManager appManager = (ApplicationManager)rac.getService("com.prosyst.mprm.admin.application.ApplicationManager");
//do something with ApplicationManager
//closing session
rac.close();
} catch (Exception e) { e.printStackTrace(System.err); }
}

Creating and Destroying Service Applications

An existing client bundle in the RM Software Repository can be marked as a service application by using the org.mbs.services.cup.radmin.RemoteCUAdmin. Therefore the software component can be used for satisfying the specific need of the user's device.

Following is an example for creating a service application from an OSGi bundle with client bundle content ID "My OSGi Bundle". The org.mbs.services.cup.radmin.RemoteCUAdmin service is accessed using Remote Access Client.

import java.util.Hashtable;
import com.prosyst.mprm.admin.softrepository.application.ApplicationConstants;
import com.prosyst.mprm.rac.RemoteAccessClient;
import org.mbs.services.cup.radmin.RemoteCUAdmin;
 
 
public static void main(String[] args) {
 
try {
//Open session using valid user account.
Hashtable credentials = new Hashtable();
credentials.put(RemoteAccessClient.USER_PASSWORD, <user_password>);
RemoteAccessClient rac = RemoteAccessClient.connect("socket://<mprm_host_address>:11449", <user_name>, credentials, null);
//Now the application can access RM RemoteCUAdmin service
RemoteCUAdmin cuAdmin = (RemoteCUAdmin)rac.getService("org.mbs.services.cup.radmin.RemoteCUAdmin");
cuAdmin.createControlUnit(ApplicationConstants.SERVICE_APPLICTION_TYPE, ApplicationConstants.SERVICE_APPLICTION_CONSTRUCTOR, "My OSGi Bundle");
//closing session
rac.close();
} catch (Exception e) {
e.printStackTrace(System.err);
}
}

To destroy an existing service application:

import com.prosyst.mprm.admin.softrepository.application.ApplicationConstants;
import org.osgi.framework.ServiceReference;
import org.mbs.services.cup.radmin.RemoteCUAdmin;
 
 
//Method inherited by the Bundle Activator
public void start(BundleContext bc) throws Exception {
//Retreive Remote CU Admin as an OSGi service from the framework
ServiceReference ref = bc.getServiceReference(RemoteCUAdmin.class.getName());
if (ref != null) {
RemoteCUAdmin cuAdmin = (RemoteCUAdmin)bc.getService(ref);
if (cuAdmin != null) {
//destroy 'My OSGi Bundle' service application
cuAdmin.destroyControlUnit(ApplicationConstants.SERVICE_APPLICTION_TYPE, "My OSGi Bundle");
}
}
}

Manage Service Applications through RM Backend

List available Service Applications

//get Application Manager as OSGi framework service or get it through RAC
ApplicationManager appManager = getApplicationManager();
//get service applications filtered by specific property and suitable for all 'mprm.osgi.device' devices
String[] appIDs = appManager.getApplicationsFor("mprm.osgi.device", null, "(public.app=true)");
for (int i = 0; i < appIDs.length; i++) {System.out.println(" application : " + appIDs[i]);

Install/Start/Stop/Uninstall Service Application

//get Application Manager as OSGi framework service or get it through RAC
ApplicationManager appManager = getApplicationManager();
appManager.install("mprm.osgi.device", "test_device", "My OSGi Bundle", null);
appManager.start("mprm.osgi.device", "test_device", "My OSGi Bundle");
appManager.stop("mprm.osgi.device", "test_device", "My OSGi Bundle");
appManager.uninstall("mprm.osgi.device", "test_device", "My OSGi Bundle");