EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  <20062007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  <20062007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: Java CA 101, Re: Misaligned protocol rejected, Java client, restarts
From: Kay-Uwe Kasemir <[email protected]>
To: [email protected]
Cc: [email protected]
Date: Fri, 07 Jul 2006 12:30:18 -0400
On Jul 6, 2006, at 18:37 , Harley N wrote:
...
2. Is there something that needs to be done when shutting down a Java program, so the client disconnects and reconnects cleanly?

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


// Only once, reference-counted, as soon as the first PV is created: jca = JCALibrary.getInstance(); jca_context = jca.createContext(JCALibrary.CHANNEL_ACCESS_JAVA);

// 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;




References:
Misaligned protocol rejected, Java client, restarts Harley N

Navigate by Date:
Prev: ASYN UDP broadcasts Eric Norum
Next: record programming and share oblects Liyu, Andrei
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  <20062007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: RE: Misaligned protocol rejected, Java client, restarts Jeff Hill
Next: Libera EPICS driver update Michael Abbott
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  <20062007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 02 Sep 2010 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·