Client management on events with EventQueue.
/**
* This class check the event queue mechanism.
*
* @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 QueueTest {
private DeviceProxy dev;
/**
* Constructor
* @param devname The device name.
* @param attname The attribute name.
*/
public QueueTest(String devname, String attname) throws DevFailed {
dev = new DeviceProxy(devname);
dev.subscribe_event(attname, TangoConst.CHANGE_EVENT, 0, new String[] {}, true);
}
/**
* Event management.
* Wait a bit to have enough events, get them and push them to callback
*/
public void manageEvents() {
// nb events to wait.
int nb = 10;
while(dev.get_event_queue_size() < nb) {
try { Thread.sleep(1000); } catch(Exception e) { /* */ }
}
EventData[] events = dev.get_events(TangoConst.CHANGE_EVENT);
for (EventData event : events) {
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);
}
}
}
}
/**
* main method.
*/
public static void main (String[] args) {
String devname = "my/device/test";
String attribute = "value";
try {
QueueTest client = new QueueTest(devname, attribute);
client.manageEvents();
}
catch(DevFailed e) {
Except.print_exception(e);
}
}
}