// Bamboo sample code
// just use a timer event
//
// $ export CLASSPATH=$BAMBOO_DIR/src/:`echo $BAMBOO_DIR/lib/*.jar|sed -e 's/ /:/g'`
// $ javac Timer.java
//
// append the following line to node.cfg:
//
// class my.Timer
//
// intval 3
// msg foobar
//
//
//
// $ ${BAMBOO_DIR}/bin/run-java bamboo.lss.DustDevil node.cfg
package my;
import bamboo.util.StandardStage;
import bamboo.lss.ASyncCore;
import seda.sandStorm.api.ConfigDataIF;
public class Timer extends StandardStage {
// value object as a context passed to callback functions
private class value_obj_t {
public String msg;
public int intval;/* [sec] */
public value_obj_t(String m, int i) {
msg = m;
intval = i;
}
}
// timer callback function
public ASyncCore.TimerCB xt_cb = new ASyncCore.TimerCB() {
public void timer_cb(Object user_ctx) {
value_obj_t val = (value_obj_t)user_ctx;
System.out.println("timer_cb: value is " + val.msg);
acore.register_timer(val.intval * 1000, xt_cb, val);
}
};
public void init(ConfigDataIF config) throws Exception {
super.init(config);
String msg = config_get_string(config, "msg");
int ival = config_get_int(config, "intval");
if (ival > 0) {
value_obj_t val = new value_obj_t(msg, ival);
acore.register_timer(ival * 1000, xt_cb, val);
} else {
System.out.println("intval is required");
}
}
}