EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

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

Subject: Re: Simultaneous Channel access
From: Marty Kraimer <[email protected]>
To: [email protected]
Date: Tue, 6 Dec 2016 11:37:53 -0500
I have attached a replacement for PVATest.java.
Note that I did not try to compile it.

Can You try it instead of Your original?

I have made the following:changes
1) only one instance of PvaClient is created.
2) org.epics.pvaccess.ClientFactory.start(); is never called since pvaClient does this
3) org.epics.pvaccess.ClientFactory.stop(); is never called. pvaClient calls this when it does out of scope.
4) I did not implement  PvaClientRPCRequesterImpl

Also if You know that the sever is started then You can set timeOut to 0,0 instead of 5.0.

What do You see?

I am not sure what Your requirements are so not sure how much help I am giving.

Marty




On 12/06/2016 04:24 AM, [email protected] wrote:

Hi Marty,

 

Thanks for your reply. In the real application, I don’t have any control over the threads (the calls to Get, RPC are done through a GUI that makes calls to a server which does the request). Though I’ve created simpler test applications that both include threading, and don’t, and the same issue occurs.

 

I’ve created a test application that demonstrates the issue (see attached)

 

There are two files – PVATest.java and EpicsTestServer.java.

 

The EpicsTestServer.java is just a simple server that listens for connections, and has one pv – “state”. When it receives an RPC call, it changes the state and just pauses for 5 seconds. This can be started as a standard Java application using the main() method, and should be started before running the tests.

 

The PVATest.java is a JUnit test file with two tests in. The main test that demonstrates the issue is called TestSimulatenous(). It makes an asynchronous RPC call, and then immediately after does a GET. The test fails because the “Status status2 = pvaChannel2.waitConnect(3);” call in the GET section can’t connect with error ‘channel not connected’

 

The test can be made to pass by uncommenting the “//Thread.sleep(5000);” which gives the server time to finish processing the RPC call and return.

 

The other test in this class is called TestSimulatenousOnlyGet() and is a copy of the GET section of the first test. If it is run at the same time as the first (i.e. whilst the server is still pausing during processing of the RPC request) then it can connect and get the state value, showing that the issue isn’t in the server. To get the timings right on this test, I normally debug the tests and the Test Server, with debug points on the line after “// Do Get” in the first test, and on the “Thread.sleep(5000);” line in the Test Server. This ensures the server is still processing the request when the second test makes its GET request.

 

Thanks again for your help,

 

Matt

 

-- 

This e-mail and any attachments may contain confidential, copyright and or privileged material, and are for the use of the intended addressee only. If you are not the intended addressee or an authorised recipient of the addressee please notify us of receipt by returning the e-mail and do not use, copy, retain, distribute or disclose the information in or attached to the e-mail.
Any opinions expressed within this e-mail are those of the individual and not necessarily of Diamond Light Source Ltd.
Diamond Light Source Ltd. cannot guarantee that this e-mail or any attachments are free from viruses and we cannot accept liability for any damage which you may sustain as a result of software viruses which may be transmitted in or with the message.
Diamond Light Source Limited (company no. 4375679). Registered in England and Wales with its registered office at Diamond House, Harwell Science and Innovation Campus, Didcot, Oxfordshire, OX11 0DE, United Kingdom
 


package org.eclipse.scanning.test.epics;

import org.epics.pvaClient.PvaClient;
import org.epics.pvaClient.PvaClientChannel;
import org.epics.pvaClient.PvaClientGet;
import org.epics.pvaClient.PvaClientGetData;
import org.epics.pvaClient.PvaClientRPC;
import org.epics.pvaClient.PvaClientRPCRequester;
import org.epics.pvdata.factory.FieldFactory;
import org.epics.pvdata.factory.PVDataFactory;
import org.epics.pvdata.pv.PVString;
import org.epics.pvdata.pv.PVStructure;
import org.epics.pvdata.pv.ScalarType;
import org.epics.pvdata.pv.Status;
import org.epics.pvdata.pv.Structure;
import org.junit.Test;

public class PVATest {
   
    PvaClient pvaClient = null;
    String channelName = "mydevice";
    String providerName = "pva";
    double timeOut = 5.0;
    
    // Run this test after starting the EpicsTestServer. It will fail when it attempts to connect to the channel for Get
    @Test
    public void TestSimulataneous() throws Exception {    
        // Create the RPC PVStructure
        Structure methodStructure = FieldFactory.getFieldCreate().createFieldBuilder().
                add("method", ScalarType.pvString).
                createStructure(); 
        Structure parametersStructure = FieldFactory.getFieldCreate().createFieldBuilder().
                add("parameters", ScalarType.pvString).
                createStructure(); 
        PVStructure methodPVS = PVDataFactory.getPVDataCreate().createPVStructure(methodStructure);
        PVStructure paramsPVS = PVDataFactory.getPVDataCreate().createPVStructure(parametersStructure);
        methodPVS.getSubField(PVString.class, "method").put("run");
        
        try {
             if(pvaClient==null) {
                 pvaClient = PvaClient.get(providerName);
             }
             PvaClientChannel pvaChannel = pvaClient.createChannel(channelName,providerName);
	     pvaChannel.issueConnect();
	     Status status = pvaChannel.waitConnect(timeOut);
	     if(!status.isOK()) {
	        	String errMEssage = "Connect failed for (" + status.getType() + ": " + status.getMessage() + ")";
	        	throw new Exception(errMEssage);
	     }
            PvaClientRPC rpc = pvaChannel.createRPC(methodPVS);
            rpc.issueConnect();
            status = rpc.waitConnect();
            if(!status.isOK()) {
            	String errMEssage = "CreateRPC failed for (" + status.getType() + ": " + status.getMessage() + ")";
            	throw new Exception(errMEssage);
            }
            PVStructure pvStructure = rpc.request(paramsPVS);
            System.out.println(pvStructure);
            
            //Thread.sleep(5000); // Uncomment this to get the test to pass

            // Do Get
            
            
            String requestString = "state";
            PvaClientGet pvaGet = pvaChannel.createGet(requestString);
            pvaGet.issueConnect();
            status = pvaGet.waitConnect();
            if(!status.isOK()) {
            	String errMEssage = "CreateGet failed for " + requestString + "(" + status.getType() + ": " + status.getMessage() + ")";
            	throw new Exception(errMEssage);
        	}
            PvaClientGetData pvaData = pvaGet.getData();
            PVStructure pvResult = pvaData.getPVStructure();
            System.out.println(pvResult);
            
                        
        } catch (Exception ex) {
            ex.printStackTrace();
            throw(ex);
        }
    }
    
    // Run this test at the point that the other tests 'Get' fails. (e.g. by pausing the server in the run method to ensure it's still processing the RPC call)
    // It will be able to connect
    @Test
    public void TestSimulataneousOnlyGet() throws Exception {
        if(pvaClient==null) {
             pvaClient = PvaClient.get(providerName);
        }
        PvaClientChannel pvaChannel = pvaClient.createChannel(channelName,providerName);
	pvaChannel.issueConnect();
	Status status = pvaChannel.waitConnect(timeOut);
	if(!status.isOK()) {
	     String errMEssage = "Connect failed for (" + status.getType() + ": " + status.getMessage() + ")";
	     throw new Exception(errMEssage);
	}
        
        String requestString = "state";
        PvaClientGet pvaGet = pvaChannel.createGet(requestString);
        pvaGet.issueConnect();
        status = pvaGet.waitConnect();
        if(!status.isOK()) {
            String errMEssage = "CreateGet failed for " + requestString + "(" + status.getType() + ": " + status.getMessage() + ")";
            throw new Exception(errMEssage);
        }
        PvaClientGetData pvaData = pvaGet.getData();
        PVStructure pvResult = pvaData.getPVStructure();
        System.out.println(pvResult);
    }
}

References:
RE: Simultaneous Channel access matthew.taylor

Navigate by Date:
Prev: TPG-256 driver Peredkov, Sergey
Next: Re: SNL sequencer apparently losing connection to underlying network Benjamin Franksen
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  <20162017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: RE: Simultaneous Channel access matthew.taylor
Next: RE: Simultaneous Channel access matthew.taylor
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  <20162017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 06 Dec 2016 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·