Client management on events with Callbacks.
/**
* This class check the events on Callback
* @author verdier
*/
import fr.esrf.Tango.DevFailed;
import fr.esrf.TangoDs.TangoConst;
import fr.esrf.TangoDs.Except;
import fr.esrf.TangoApi.DeviceProxy;
import fr.esrf.TangoApi.CallBack;
import fr.esrf.TangoApi.DeviceAttribute;
import fr.esrf.TangoApi.events.EventData;
import java.util.Date;
public class CallbackTest extends DeviceProxy {
private EventCallBack callback;
/**
* Constructor
* @param devname The device name.
* @param attname The attribute name.
*/
public CallbackTest(String devname, String attname) throws DevFailed {
super(devname);
callback = new EventCallBack();
subscribe_event(attname, TangoConst.CHANGE_EVENT,
callback, new String[] {}, true);
}
/**
* An inner class extending fr.esrf.TangoApi.CallBack
*/
class EventCallBack extends CallBack {
public void push_event(EventData event) {
System.out.print("Event at " + new Date(event.date) + ": ");
if (event.err)
Except.print_exception(event.errors);
else {
DeviceAttribute value = event.attr_value;
if (value.hasFailed())
Except.print_exception(value.getErrStack());
else
try {
if (value.getType()==TangoConst.Tango_DEV_DOUBLE)
System.out.println(value.extractDouble());
}
catch(DevFailed e) {
Except.print_exception(e);
}
}
}
}
public static void main (String[] args) {
String devname = "my/device/test";
String attribute = "value";
try {
CallbackTest client = new CallbackTest(devname, attribute);
}
catch(DevFailed e) {
Except.print_exception(e);
}
}
}