It seems that I need a ctxt.flushIo()
after creating the monitor (thanks Geoff!). Can we add this to the JavaDocs?
/**
* Adds a monitor to
this Channel. The monitor is guaranteed to start working
* only after the
next call to {@link #flushIo()}.
*
...
Thanks!
Gabriele
Hi all,
I have found something that looks like a bug in CAJ. If
monitors are not registered right after the creation of the Channel, they
don’t get notified at all. Here is a test case:
public class CAJBugTest {
public static void main(String[] args)
throws Exception {
JCALibrary jca =
JCALibrary.getInstance();
Context ctxt =
jca.createContext(JCALibrary.CHANNEL_ACCESS_JAVA);
Channel ch =
ctxt.createChannel("pvk01");
//ctxt.pendIO(1.0);
//Thread.sleep(1000);
ch.addMonitor(DBRType.DOUBLE, 1, Monitor.VALUE, new MonitorListener() {
@Override
public void monitorChanged(MonitorEvent ev) {
System.out.println("1 -> " + ev.getDBR().getValue());
}
});
//Thread.sleep(1000);
Channel ch2 =
ctxt.createChannel("pvk01");
ch2.addMonitor(DBRType.DOUBLE, 1, Monitor.VALUE, new MonitorListener() {
@Override
public void monitorChanged(MonitorEvent ev) {
System.out.println("2 -> " + ev.getDBR().getValue());
}
});
Thread.sleep(5000);
ch.destroy();
ch2.destroy();
ctxt.destroy();
}
}
With the comments, this will work and show updates for the
first and the second monitor. If the Sleep or pendIO calls are uncommented, all
the subsequent monitor are not being notified. So, for example, if you remove
the second sleep, you would see the notifications for the first monitor but not
the second.
The problem is that this more or less defies the purpose of
having CAJ caching and managing the channels and monitors for me… :-/
I am using CAJ 1.1.5b, JCA 2.3.2 on a Windows machine. Any
thoughts?
Gabriele