![]() |
![]() ![]()
Experimental Physics and
| ||||||||||||||||
|
... Hi: I've been wondering myself about that. Here's what I use so far to start/stop CA connections when using JCA/ CAJ. It seems to "work", meaning: I can start/stop CA connections from a running application, but I have no idea if it's the correct way to do this. Maybe somebody has better ideas? Thanks, -Kay
// For each new channel. // ('this' implements the ConnectionListener and MonitorListener interfaces) channel = jca_context.createChannel(name, this); // Then, after all channels were created: jca_context.flushIO(); // One can naively call flushIO() after each createChannel(). // That "works", but at least with the "C" version of the CA client library // that would be a performance hit. // If the channel is found on the network, the ConnectionListener runs. public void connectionChanged(ConnectionEvent ev) { if (ev.isConnected()) { // Subscribe, but only once! if (was_ever_connected == false) { was_ever_connected == true; channel.addMonitor(1, this); // Might be better to tell the application that a "flush" is due, // and run that from a timer, instead of flushing after each addMonitor() jca_context.flushIO(); } } else { // .. notify your application that we're disconnected; schedule GUI update, ... } } // For each subscription update, this one gets invoked: public void monitorChanged(MonitorEvent ev) { if (ev.getStatus().isSuccessful()) { DBR dbr = ev.getDBR(); // decode the value, schedule GUI update, .... } else { // ... } } } // For each channel that we no longer want: channel.dispose(); channel = null; // dispose() seems to "work" for me, but I'm unclear: // There's also a channel.destroy(). // Finally, after the last PV was destroyed: jca_context.destroy(); jca = null;
| ||||||||||||||||
ANJ, 02 Sep 2010 |
![]() · Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing · |