Home Contact

 A Generic Framework for Context-Aware Applications.

Abstract

In this tutorial, we introduce the various existing sensors shipped with WildCAT. Then we describe how to easily implements new sensors compatible with the WildCAT framework.

WildCAT team main objective is not to develop sensors, but to provide a generic framework to organize and inspect monitoring sources. Nevertheless, we distribute along with the WildCAT framework a sensors library that we extend as we develop new sensors for our own experiment. Moreover, external contributions are welcome.

The sensors library as of july 2008

As of today, WildCAT proivdes the following sensors (all of which are available in the org.ow2.wildcat.sensors package):

  • Java related sensors
    • JavaRuntimeSensor provides information relative to the current JVM (processor, memory, etc)
    • SystemPropertiesSensor provides a wrapper for Java System Properties
    • MBeanCMDSensor allows for gathering of any JMX related information (defined in synergy with the JASMINe project)
  • System related sensors (Linux-only)
    • KernelVersionSensor provides system kernel version
    • DateTimeSensor provides system current time
    • CPUSensor provides information (model, version, etc) of the CPU
    • CPULoadSensor provides instant CPU load

Extending the sensors library

In WildCAT, every sensor is placed under the org.ow2.wildcat.sensors package. As of today, that package is bundled under the core module in Maven (Note: a separate package for the sensors library should be created in the future).

WildCAT's sensors must all implements the Attribute interface and should be attached to a WildCAT's hierarchy using the "attachAttribute" from the "Context" interface:

Context context = ...
Attribute mySensor = new MySensor();
context.attachAttribute ("self://path/to/my#sensor", mySensor);

Creating a Random Number Generator sensor

To illustrate the design of new sensors, we'll create a simple sensor generating random Integer numbers. To do it, we overload the POJOAttribute class:

package org.ow2.wildcat.sensors;

import org.ow2.wildcat.hierarchy.attribute.*;

import java.util.Random;

public class RNGSensor extends POJOAttribute {
    protected Random rng = new Random (System.currentTimeMillis());

    @Override
    public Object getValue () {
        this.setValue(this.random.nextInt());
        return this.value;
    }
}

The RNGSensor class extends the POJOAttribute class, that is the most common type of attribute. We add the "rng" field to hold a random number generator. To keep it simple, stupid, we only overload the "getValue" method from the POJOAttribute class. When one access the content of our sensor through the "getValue" method from the "Context" interface, the "getValue" method of the "RNGSensor" class is triggered. It change the sensor current value with a newly picked random Integer, and launch a new WAttributeEvent to notify the value change. Then it returns that new value.

Implementing this sensor is a matter of very few lines of code. Nevertheless, that sensors only triggers new values only when one inspect its content. That sensor is said to be passive. To overcome this limitation, one may create a periodical attribute poller, as discussed in the push mode tutorial.

An alternative approach is to make the sensor directly implements the Runnable interface and manually change the sensor value with the "setValue" method whenever one wish to notify of a new value. WildCAT implements such a RunnableAttribute class. Developer being eager for more detail should directly consult that class in the WildCAT org.ow2.wildcat.sensors package.