System Service

The System Service delivers information about essential system attributes of the host computer, such as OS, VM, and OSGi framework. In addition, you can retrieve information about the runtime status of the framework.

Calling the System Service

The interface of the System Service is com.prosyst.util.system.SystemService and you can call it using the conventional techniques defined by the OSGi Framework Specification.

  import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.ServiceReference;
import com.prosyst.util.system.SystemService;
public class TestActivator implements BundleActivator {
 
ServiceReference sysRef;
SystemService sysServ;

public void start(BundleContext bc) { // Retrieving the System Service from the server framework
sysRef = bc.getServiceReference(SystemService.class.getName()); sysServ = (SystemService) bc.getService(sysRef);
}

public void stop(BundleContext bc) { bc.ungetService(sysRef); }  }
Listing 1: Calling the System Service.

Getting General Properties

General properties involve the framework system properties, the attributes of the operating system (OS) and virtual machine (VM) currently running the framework. To retrieve such data, call the getProperties method of the System Service for the preferred type of information:

For example to request the attributes of the VM, call getProperties(SystemService.JVM).

The getProperties method returns a java.util.Dictionary with the following string key/value pairs:

Listing 2 uses the System Service from Listing 1 to read framework properties.

                     . . .
import java.util.Dictionary;
import java.util.Enumeration;
. . .
Dictionary fwProps = sysServ.getProperties(SystemService.FRAMEWORK);
Enumeration fwPropsEnum = fwProps.keys();
while(fwPropsEnum.hasMoreElements()) {
String key = (String)fwPropsEnum.nextElement();
String property = (String)fwProps.get(key);
}
. . .
Listing 2: Using the System Service.

Getting Runtime Information

Runtime information, provided by the System Service, includes active threads, active classpath, consumed memory and current gateway platform. These parameters are wrapped by a com.prosyst.util.system.RuntimeInfo object. You can apply a filter on a RuntimeInfo to retrieve runtime information only of a particular type. In case you are interested only in one runtime parameter, you can save memory and CPU time. The method to invoke is getRuntimeInfo(byte) with one of the following constants as argument:

Then, you can read only that field of the RuntimeInfo instance, which you are interested in. For example, if you created a RuntimeInfo object about used memory, then you only get the value of the memoryUsage field.

Viewing the Thread Groups Allocated for Active Bundles

The threads of each bundle running in the framework operate in a separate thread group (see the "Framework Architecture" document for more details about bundles and threads). By calling the activeThreads variable of RuntimeInfo, you inspect active threads by thread group, that is, by bundle. Bundles' thread groups are ThreadGroupInfo objects. For each ThreadGroupInfo you can list active threads (use activeThreads) and obtain information about sub groups of the current one (use subGroupsInfo).

Providing a Native Platform Informer

You can implement a class, which contacts the operating system for getting the used and free space on the hard disk or on another storage. This information will be provided on checking the runtime information about the platform (when calling getRuntimeInfo(SystemService.PLATFORM)) or about the entire system (when calling getRuntimeInfo(SystemService.ALL)).

Such a class is called Native Platform Informer.

A Native Platform Informer must implement the following methods:

Finally, to make the System Service use your Native Platform Informer, add the informer class to the system classpath or export it in a bundle, and set the mbs.platform.informer system property to the class name.

Remote Usage of the System Service

Remote PMP-enabled frameworks can refer to and invoke the methods of the System Service interface because the service also implements com.prosyst.util.io.Remote which enables this access. For example, the mConsole uses PMP to show the information available through the System Service to the framework administrator.

Console Commands

The System Service plugs commands as a group called info into the command set of the Parser Service.

The commands of the info group offer information about essential runtime parameters of the OSGi framework, such as current OS and VM.

Info Group Command Shortcut Description
classpath cp Prints the classpath of the framework including the value of the system CLASSPATH variable.
fw - Prints the system properties of the OSGi framework.
jvm - Prints information about the attributes of the current VM.
memory [j9_options] [<ID> [<ID>]] mem

Gives information about the memory consumed.

When the framework is running on J9 jclRM with enabled resource management, this command shows information about the memory space of the bundle with the specified ID (pass 0 for the framework memory space) and has additional options related to this feature.

-a, -A Shows all memory spaces.
-o, -O Shows information about all objects in the bundle memory space.
-r, -R Shows information about all objects in the bundle memory space as well as the objects which hold reference to them.
os - Shows the essential features of the current OS.
packages pkg Lists mBS packages currently installed. This command works in case all packages are in the same home directory.
resman [options]
{<ID>[ <ID>]|<URL>[ <URL>]}
res Prints information about the resources required by or allocated for the bundle(s) with the specified bundleID(s) or URL(s). See the "Resource Management" document.
The command supports the following options:

-r, -R Shows information about the resources that the bundle requests in its resource XML file.
-a, -A Shows information about the actual consumption of the resources, requested in the resource XML file.

On the J9 JVM, the command includes J9-specific resources only if the jclRM class library is used and the J9 Resource Manager is enabled.

threads [options] th Prints information about the active threads in the framework.
The command offers the -b, -B option, which shows threads classified by the IDs of the bundles that created them.


Parser Service