
Chapter 3: Java Support Samples
Creating a Java application for data acquisition
/** An acquistion AIM acquires data and makes a distributed function call into a remote application (here an SFM) using the Java DfcSfnmProxy.
* This application implements the AcqAimInterface, which defines the default entry points of the application (initialize, deinitialize, ping). When the SFM references this application as one of its sources, the SFM periodically calls the ping function. Here the ping function sends a transaction back to the SFM
* @see AcqAimInterface
* @see DfcSfmProxy
* @author hlebegue
* @since 1.0
* @version 1.0
*/
public class AcqAimSample implements AcqAimInterface {
/** DfcSfmProxy allows the aim to deliver data to a remote SFM*/
private DfcSfmProxy m_Sfm=null;
/** Remote host when Impact 5.x is running*/
private String m_sRemoteImpactHost="localhost";
/** Remote Tcp port on which Impact 5.x is accepting dfc*/
private int m_sRemoteImpactTcpPort=2255;
/** Creates a new instance
* The aims creates a new Sfm Proxy
*/
public AcqAimSample() { m_Sfm = new DfcSfmProxy(50);
}
/** This function is inherited from the AcqAimInterface
* The aims connects to Impact using the Sfm Proxy
* @see AcqAimInterface
*/
public int initialize() {
System.out.println("-->AcqAimSample::Called on initialize()");
try{
m_Sfm.connect(m_sRemoteImpactHost, m_sRemoteImpactTcpPort); }
catch (Exception e){}return 1;
}
/** This function is inherited from the AcqAimInterface
* The aims disconnect from Impact using the Sfm Proxy
* @see AcqAimInterface
*/
public void deinitialize() {
System.out.println("-->AcqAimSample::Called on deinitialize()");
if (m_Sfm.isConnected()){ try{
m_Sfm.disconnect();
}
catch(Exception e){}
}
}
/** This function is inherited from the AcqAimInterface
* For an acq application, SFM will periodically call this method in order
* to identify the status of the source
* @return negative to indicate that source application is not ready
* @see AcqAimInterface
*/
public int ping(int iAimFlavor, int iCallerFlavor) {
System.out.println("-->AcqAimSample::Called on ping()");
System.out.println(" Flavor:" + iAimFlavor + " CallerFlav:"+ iCallerFlavor);
// Any logic to determine if sending application is ready here,
// eventually reattempt to connect if not. int iRet=-1;
if (!m_Sfm.isConnected()){
try{ m_Sfm.connect(m_sRemoteImpactHost, m_sRemoteImpactTcpPort); } catch (Exception e){} } // Here, for this sample, we will send a transaction to // Sfm every time Sfm pings the source iRet = sendToSfmEngine("Bart|Simpson|M|8|IL".getBytes()); return iRet;}
/** This function is user defined. Consumer application calls it to send data * to Sfm @param bData The transaction data */private int sendToSfmEngine(byte [] bData){ int iRet=-1; if (m_Sfm.isConnected()){ try{ // one way to send a transaction to Sfm iRet = m_Sfm.route_veng("me_myself_and_i", "Eng1", bData); System.out.println("AcqAimSample::Send transaction(1) rc=" + iRet); // another way using an argument wrapper RouteVRecArguments argWrapper = new RouteVRecArguments (); argWrapper.source="AcqAimSample"; argWrapper.route="ENGINE"; argWrapper.data=bData; iRet = m_Sfm.sendDfc("route_veng",50,30,argWrapper); System.out.println("AcqAimSample::Send transaction(2) rc=" + iRet); argWrapper =null; } catch (Exception e){} } return iRet;}
Copyright © 2005. Sybase Inc. All rights reserved.
|
|
View this book as PDF 