PMP Demo

The PMP Demo is a bundle that uses the PMP Bundle to establish a connection with an OSGi framework running on the same machine, and retrieves the properties of the framework system.

Demo Components

The components of the demo are in the demo/framework/pmp directory. This includes source and class files, scripts and a readme.txt. The PMP Demo has only one class - PMPDemo, which is a bundle activator calling the PMP Service.

The bundle JAR of the PMP Demo is pmpdemo.jar in demo/bundles.

Starting the Demo

Using an Install Script

The PMP Demo owns an install script for easier and faster installation of its components as well as of the necessary bundles. For more help about starting the demo through the install script, refer to General Rules for Demos.

Activating All Necessary Components Manually

To start the demo:

  1. Start the OSGi framework and make sure the PMP Bundle (bundles/pmp.jar) is running. Otherwise, install and start it.
  2. Install and start the PMP Demo bundle:
    For example using the framework console:
    fw.i -s ../../../demo/bundles/pmpdemo.jar

In return, the properties of the framework are printed in the console.

Inside the Demo

The PMP Demo connects to the OSGi framework by calling the connect method of the PMP Service passing the initial framework account admin/admin.

  import com.prosyst.mbs.services.pmp.PMPService;
import com.prosyst.mbs.services.pmp.PMPConnection;
. . .
ServiceReference sr = bx.getServiceReference(PMPService.class.getName());
if(sr == null) throw new BundleException("Can't get PMPService");
PMPService pmp = (PMPService)bx.getService(sr);
if(pmp == null) throw new BundleException("Can't get PMPService");
Hashtable props = new Hashtable (20);
props.put("username", "admin");
props.put("password", "admin");
PMPConnection con = pmp.connect("socket://127.0.0.1:1449", props);
. . .
Listing 1: Connecting to a framework.

Next, the demo invokes the getProperties method of the System Service specifying that the result should be passed as a serialized object from the executing framework.

  static String SYSTEM = "com.prosyst.util.system.SystemService";
. . .
RemoteObject rObject = con.getReference(SYSTEM, "");
String [] str = {Byte.TYPE.getName()};
RemoteMethod rMethod = rObject.getMethod("getProperties", str);
rMethod.changeReturnType(ExternalizableDictionary.class);
Dictionary obj =
(ExternalizableDictionary)rMethod.invoke(new Object[] { new Byte((byte) 3)},
true);
Enumeration enum = obj.keys();
while(enum.hasMoreElements()) {
Object tmp = enum.nextElement();
System.out.println(tmp + " " + obj.get(tmp));
}
. . .
Listing 2: Retrieving the framework properties.

Finally, the demo prints the result.


Framework Demos