Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Test and Performance Tools Platform (TPTP) » Data transfer between Client and Agent performance issue
Data transfer between Client and Agent performance issue [message #94310] Wed, 28 March 2007 12:19 Go to next message
Eclipse UserFriend
Originally posted by: cvkmurthy.hotmail.com

This is a multi-part message in MIME format.
--------------060504020405070408000209
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hi Experts,

I have a use case where the client connects to the Agent Controller
and sends a query string to the Agent. The Agent has the logic to
connect to the database, execute the query and return the results back
to the client.

I am using senddata () to send the query string from client to Agent. I
have a class variable on the Agent which stores the query string. Then I
am calling run () method in the client side which will send command to
Agent to execute the query. If I donot put sleep of 1500 milli seconds
between senddata () and run () methods on the client side, I get a Null
pointer exception in the Agent, as the query gets executed before the
data is received by the Agent.

I have a sleep of 2000 milli seconds on the client to receive the data
from the Agent. If I do not have sleep the stop command gets execute
even before the data is received.

Is sleep necessary or is there a workaround for this problem? Is there a
better way to do this? In total it takes around 4 seconds to get the
result. This could be a performance issue for my project. Please find
the client and agent files attached.

Regards,
Krishna

--------------060504020405070408000209
Content-Type: text/plain;
name="TCEngLogClient.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="TCEngLogClient.java"

/*********************************************************** ********************
* Copyright (c) 2005, 2006 Intel Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Vishnu K Naikawadi,Intel - Initial API and implementation
*
* $Id: SampleClientAC.java,v 1.20 2006/02/10 22:12:31 vnaikawadi Exp $
************************************************************ *******************/


package logParser.teamcenter;

import org.eclipse.tptp.platform.execution.client.agent.IAgent;
import org.eclipse.tptp.platform.execution.client.agent.ICollector;
import org.eclipse.tptp.platform.execution.client.core.ConnectionIn fo;
import org.eclipse.tptp.platform.execution.client.core.IAgentContro ller;
import org.eclipse.tptp.platform.execution.client.core.IDataProcess or;
import org.eclipse.tptp.platform.execution.client.core.INode;
import org.eclipse.tptp.platform.execution.client.core.NodeFactory;
import org.eclipse.tptp.platform.execution.util.ICommandElement;
import org.eclipse.tptp.platform.execution.util.ICommandHandler;
import org.eclipse.tptp.platform.execution.util.TPTPDataPath;

/**
* This sample connects to an Agent Controller running on the local host
* and creates a type of agent called collector.
* The client sends commands to the collector to start and stop execution.
* During the period when the collector is running, data is collected by the collector.
* The data collected by the collector is then recieved by the client.
* @author gnagaraj
*
*/

public class TCEngLogClient
{
String fileList = null;
String queryString = null;

public String getFileList (){
return fileList;
}

public TCEngLogClient(){

}

//public static void main(String[] args)
public TCEngLogClient(String pQueryString)
{
queryString = pQueryString;
//Connect to the host where the Agent Controller is running
//See the Getting started guide for TPTP 4.0
String localhost = "localhost";
//This port number corresponds to the port where the Agent Controller
//listens/accepts connections. This is defined in the Agent Controller
//serviceconfig.xml file in the <AgentController_INSTALL_HOME>/config
int port = 10006;
System.out.println("Connecting to Host "+ localhost);

//Create a Node that represents the target agent controller
INode SampleNode = null;
//Create the client Agent Controller representation object
IAgentController ac = null;
//Pass the connection info the client
ConnectionInfo connInfo = new ConnectionInfo();

try
{
//Create a Node that represents the target machine and agent controller
SampleNode = (INode) NodeFactory.createNode(localhost);

//Set the connection parameters required
connInfo.setHostName(localhost);
connInfo.setPort(port);
//connInfo.setAgentControllerNew(true);

if (SampleNode != null)
{
// Connect to the Agent Controller, a successful connection returns
//a client side Agent Controller object that provides various
//methods to perform TPTP tasks.
System.out.println("Connecting to AC..");
ac = SampleNode.connect(connInfo);

System.out.println("Connected to " + localhost + " at port number " + port);

//Create an Agent representation on the client to hold Agent information
//In this case a Collector object is created. A collector is a type of an Agent
//The Agent Controller creates an instance of the Collector
//and returns an agent reference that allows the client to perform operations on the collector.
ICollector TCollector = (ICollector)ac.getAgent("com.teamcenter.tptp.TcengLogAgent", "org.eclipse.tptp.platform.execution.client.agent.ICollector ");

if(TCollector == null){System.out.println("Agent not available, configure the agent and retry"); return;}

//Create the Data Connection required to recieve response from the collector;
//The input to startMonitoring is the to establish the data connection between the client and
//the agent controller for the direction of data flow.
//See constants for additional values.
((IAgent)TCollector).startMonitoring(TPTPDataPath.DATA_PATH_ TWO_WAY);

((IAgent)TCollector).addDataListener( new IDataProcessor()
{
public void incomingData(byte[] buffer, int length, java.net.InetAddress peer)
{
String data = new String(buffer);
char a[] = data.toCharArray();
StringBuffer strBuffer = new StringBuffer ();
for (int i=0; i < a.length; i++){
if (a[i] == '$'){
break;
}
if (a[i] != a[1]){
strBuffer.append(a[i]);
}
}
System.out.println("The Data received from TimeCollector - " + strBuffer.toString());
fileList = strBuffer.toString();
}

public void incomingData(char[] buffer, int length, java.net.InetAddress peer)
{
String data = new String (buffer);
System.out.println("Char Data Processor Called" + data);
}

public void invalidDataType(byte[] data, int length, java.net.InetAddress peer)
{
System.out.println("Data Processor Invalid Data Type Called");
}

public void waitingForData()
{
System.out.println("Data Processor Waiting for Data Called");
}
});

TCollector.sendData(queryString.getBytes());
Thread.sleep(1500);
//Send a message to Agent
TCollector.run();

//Wait for the response to arrive
Thread.sleep(2000);

TCollector.stop();
Thread.sleep(100);
// Disconnect from AC
ac.disconnect();
System.out.println("Disconnected");
}
else
{
System.out.println("Error occurred while creating the Node for " + localhost);
}

}
catch(Exception exp)
{
System.out.println("Error occurred while connecting to " + localhost + ":" + exp);
}
}
}
--------------060504020405070408000209
Content-Type: text/plain;
name="TcengLogAgent.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="TcengLogAgent.java"

/*********************************************************** ********************
* Copyright (c) 2005, 2006 Intel Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Guru Nagarajan,Intel - Initial API and implementation
*
* $Id: TPTPJavaAgent.java,v 1.16 2006/02/10 21:53:14 vnaikawadi Exp $
************************************************************ *******************/
package teamcenter.TPTP;

import org.eclipse.tptp.platform.execution.datacollection.BaseAgent ;
import org.eclipse.tptp.platform.execution.util.ICommandFragment;
import org.eclipse.tptp.platform.execution.util.internal.CommandFra gment;


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;


/**
* @author gnagaraj
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class TcengLogAgent extends BaseAgent implements Runnable{

public static final String TIMECOLLECTOR_INTERFACE = "com.teamcenter.tptp.TcengLogCollector";
protected boolean running = true;
protected Date startTime;
protected Date endTime;
protected long elapsedTime = 0;

/* Element Command Names used to communicate with the client */
protected String agentRunningTag = "agentRunning";
protected String agentStoppedTag = "agentStopped";
protected String elapsedTimeTag = "elapsedTime";
private String queryString = null;

/**
* @param name
* @param type
*/
public TcengLogAgent(String name, String type)
{
super(name);
try
{
super.init();
}
catch (Exception e){e.printStackTrace();}
// TODO Auto-generated constructor stub
}

public static void main(String[] args)
{
/* Create a TimeCollector Agent */
TcengLogAgent jAgent = new TcengLogAgent("com.teamcenter.tptp.TcengLogAgent", "Collector");

/* Register agent */
try
{
jAgent.register();
}
catch(Exception e){e.printStackTrace();}

Thread thread = new Thread(jAgent);
thread.start();
}




public void processCommand(ICommandFragment cmd)
{
super.processCommand(cmd);
System.out.println("Incoming command "+((CommandFragment)cmd).getCommandName() + System.currentTimeMillis());

if(((CommandFragment)cmd).getCommandName().equals("run"))
{
this.sendRunResponse((CommandFragment)cmd);
}
}

public void run()
{
while(running)
{
try {
Thread.sleep(10);
}
catch (InterruptedException e) {}
}
/* Deregister agent */
this.deregister();
}


public int receiveData(int sourceId, String buffer, int bufferLength)
{
queryString = buffer;
//TO DO: At this point printing the data
System.out.println("Data Recvd. on the data channel" + System.currentTimeMillis());
System.out.println("+++++++++++++++++++++++++++++++++");
System.out.println(buffer);
System.out.println("++++++++++++++++++++++++++++++++++");
return 0;
}


private int sendRunResponse(CommandFragment cmd)
{
int ret = -1;

int destID = new Long(cmd.getSource()).intValue();
try
{
super.sendData(destID, (char[])getFileList().toCharArray());
ret = 0;
}
catch(Exception e){e.printStackTrace();}

return ret;
}


public String getFileList (){
// Connect to database and get the results.
// Execute Query using querString
// Return semicolon seperated file list
}

}

--------------060504020405070408000209--
Re: Data transfer between Client and Agent performance issue [message #94361 is a reply to message #94310] Wed, 28 March 2007 14:49 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 404
Registered: July 2009
Senior Member
I'm not an expert in this topic but I'll make an attempt to answer your
questions. First off, you should never need to do any sleeps in your code.

There appears to be a racing condition between senddata() and run(). From
what I understand, senddata() will send a query string from the client to
the agent and run() will indicate that the agent should execute the query.
You'll need to have an acknowledgement sent from the agent to the client to
indicate that the agent has received the query string before you can execute
the run method. Here's the flow:

1. client sends query via senddata()
2. client wait for acknowledgement
3. agent receives the query and acknowledges it
4. client wakes up after acknowledgement or times out
5. client executes the run() method if acknowledgement is received or
repeats number 1.

You can use a slightly different mechanism for avoiding the sleep you have
in place before stopping the agent. The query result will need to be
enclosed in a tag to indicate the beginning and end of the query result.
You can either enclose the query result in an xml tag or have a header
included to indicate the length of the result. For example:

<query-result>
result goes here...
</query-result>

or

#query-result;length=<x>
result goes here...

The client will read in the result and will only stop an agent if the entire
result has been received.

Hope that helps,
Ali Mehregani


"Krishna" <cvkmurthy@hotmail.com> wrote in message
news:eudmfs$tm2$1@utils.eclipse.org...
> Hi Experts,
>
> I have a use case where the client connects to the Agent Controller
> and sends a query string to the Agent. The Agent has the logic to
> connect to the database, execute the query and return the results back
> to the client.
>
> I am using senddata () to send the query string from client to Agent. I
> have a class variable on the Agent which stores the query string. Then I
> am calling run () method in the client side which will send command to
> Agent to execute the query. If I donot put sleep of 1500 milli seconds
> between senddata () and run () methods on the client side, I get a Null
> pointer exception in the Agent, as the query gets executed before the
> data is received by the Agent.
>
> I have a sleep of 2000 milli seconds on the client to receive the data
> from the Agent. If I do not have sleep the stop command gets execute
> even before the data is received.
>
> Is sleep necessary or is there a workaround for this problem? Is there a
> better way to do this? In total it takes around 4 seconds to get the
> result. This could be a performance issue for my project. Please find
> the client and agent files attached.
>
> Regards,
> Krishna
>


------------------------------------------------------------ --------------------


> /*********************************************************** ********************
> * Copyright (c) 2005, 2006 Intel Corporation.
> * All rights reserved. This program and the accompanying materials
> * are made available under the terms of the Eclipse Public License v1.0
> * which accompanies this distribution, and is available at
> * http://www.eclipse.org/legal/epl-v10.html
> *
> * Contributors:
> * Vishnu K Naikawadi,Intel - Initial API and implementation
> *
> * $Id: SampleClientAC.java,v 1.20 2006/02/10 22:12:31 vnaikawadi Exp $
> ************************************************************ *******************/
>
>
> package logParser.teamcenter;
>
> import org.eclipse.tptp.platform.execution.client.agent.IAgent;
> import org.eclipse.tptp.platform.execution.client.agent.ICollector;
> import org.eclipse.tptp.platform.execution.client.core.ConnectionIn fo;
> import org.eclipse.tptp.platform.execution.client.core.IAgentContro ller;
> import org.eclipse.tptp.platform.execution.client.core.IDataProcess or;
> import org.eclipse.tptp.platform.execution.client.core.INode;
> import org.eclipse.tptp.platform.execution.client.core.NodeFactory;
> import org.eclipse.tptp.platform.execution.util.ICommandElement;
> import org.eclipse.tptp.platform.execution.util.ICommandHandler;
> import org.eclipse.tptp.platform.execution.util.TPTPDataPath;
>
> /**
> * This sample connects to an Agent Controller running on the local host
> * and creates a type of agent called collector.
> * The client sends commands to the collector to start and stop execution.
> * During the period when the collector is running, data is collected by
> the collector.
> * The data collected by the collector is then recieved by the client.
> * @author gnagaraj
> *
> */
>
> public class TCEngLogClient
> {
> String fileList = null;
> String queryString = null;
>
> public String getFileList (){
> return fileList;
> }
>
> public TCEngLogClient(){
>
> }
>
> //public static void main(String[] args)
> public TCEngLogClient(String pQueryString)
> {
> queryString = pQueryString;
> //Connect to the host where the Agent Controller is running
> //See the Getting started guide for TPTP 4.0
> String localhost = "localhost";
> //This port number corresponds to the port where the Agent Controller
> //listens/accepts connections. This is defined in the Agent Controller
> //serviceconfig.xml file in the <AgentController_INSTALL_HOME>/config
> int port = 10006;
> System.out.println("Connecting to Host "+ localhost);
>
> //Create a Node that represents the target agent controller
> INode SampleNode = null;
> //Create the client Agent Controller representation object
> IAgentController ac = null;
> //Pass the connection info the client
> ConnectionInfo connInfo = new ConnectionInfo();
>
> try
> {
> //Create a Node that represents the target machine and agent controller
> SampleNode = (INode) NodeFactory.createNode(localhost);
>
> //Set the connection parameters required
> connInfo.setHostName(localhost);
> connInfo.setPort(port);
> //connInfo.setAgentControllerNew(true);
>
> if (SampleNode != null)
> {
> // Connect to the Agent Controller, a successful connection returns
> //a client side Agent Controller object that provides various
> //methods to perform TPTP tasks.
> System.out.println("Connecting to AC..");
> ac = SampleNode.connect(connInfo);
>
> System.out.println("Connected to " + localhost + " at port number " +
> port);
>
> //Create an Agent representation on the client to hold Agent information
> //In this case a Collector object is created. A collector is a type of an
> Agent
> //The Agent Controller creates an instance of the Collector
> //and returns an agent reference that allows the client to perform
> operations on the collector.
> ICollector TCollector =
> (ICollector)ac.getAgent("com.teamcenter.tptp.TcengLogAgent",
> "org.eclipse.tptp.platform.execution.client.agent.ICollector ");
>
> if(TCollector == null){System.out.println("Agent not available, configure
> the agent and retry"); return;}
>
> //Create the Data Connection required to recieve response from the
> collector;
> //The input to startMonitoring is the to establish the data connection
> between the client and
> //the agent controller for the direction of data flow.
> //See constants for additional values.
> ((IAgent)TCollector).startMonitoring(TPTPDataPath.DATA_PATH_ TWO_WAY);
>
> ((IAgent)TCollector).addDataListener( new IDataProcessor()
> {
> public void incomingData(byte[] buffer, int length, java.net.InetAddress
> peer)
> {
> String data = new String(buffer);
> char a[] = data.toCharArray();
> StringBuffer strBuffer = new StringBuffer ();
> for (int i=0; i < a.length; i++){
> if (a[i] == '$'){
> break;
> }
> if (a[i] != a[1]){
> strBuffer.append(a[i]);
> }
> }
> System.out.println("The Data received from TimeCollector - " +
> strBuffer.toString());
> fileList = strBuffer.toString();
> }
>
> public void incomingData(char[] buffer, int length, java.net.InetAddress
> peer)
> {
> String data = new String (buffer);
> System.out.println("Char Data Processor Called" + data);
> }
>
> public void invalidDataType(byte[] data, int length, java.net.InetAddress
> peer)
> {
> System.out.println("Data Processor Invalid Data Type Called");
> }
>
> public void waitingForData()
> {
> System.out.println("Data Processor Waiting for Data Called");
> }
> });
>
> TCollector.sendData(queryString.getBytes());
> Thread.sleep(1500);
> //Send a message to Agent
> TCollector.run();
>
> //Wait for the response to arrive
> Thread.sleep(2000);
>
> TCollector.stop();
> Thread.sleep(100);
> // Disconnect from AC
> ac.disconnect();
> System.out.println("Disconnected");
> }
> else
> {
> System.out.println("Error occurred while creating the Node for " +
> localhost);
> }
>
> }
> catch(Exception exp)
> {
> System.out.println("Error occurred while connecting to " + localhost + ":"
> + exp);
> }
> }
> }


------------------------------------------------------------ --------------------


> /*********************************************************** ********************
> * Copyright (c) 2005, 2006 Intel Corporation.
> * All rights reserved. This program and the accompanying materials
> * are made available under the terms of the Eclipse Public License v1.0
> * which accompanies this distribution, and is available at
> * http://www.eclipse.org/legal/epl-v10.html
> *
> * Contributors:
> * Guru Nagarajan,Intel - Initial API and implementation
> *
> * $Id: TPTPJavaAgent.java,v 1.16 2006/02/10 21:53:14 vnaikawadi Exp $
> ************************************************************ *******************/
> package teamcenter.TPTP;
>
> import org.eclipse.tptp.platform.execution.datacollection.BaseAgent ;
> import org.eclipse.tptp.platform.execution.util.ICommandFragment;
> import org.eclipse.tptp.platform.execution.util.internal.CommandFra gment;
>
>
> import java.io.FileInputStream;
> import java.io.FileNotFoundException;
> import java.io.IOException;
> import java.rmi.NotBoundException;
> import java.rmi.RemoteException;
> import java.util.ArrayList;
> import java.util.Date;
> import java.util.Iterator;
> import java.util.List;
> import java.util.Properties;
>
>
> /**
> * @author gnagaraj
> *
> * TODO To change the template for this generated type comment go to
> * Window - Preferences - Java - Code Style - Code Templates
> */
> public class TcengLogAgent extends BaseAgent implements Runnable{
>
> public static final String TIMECOLLECTOR_INTERFACE =
> "com.teamcenter.tptp.TcengLogCollector";
> protected boolean running = true;
> protected Date startTime;
> protected Date endTime;
> protected long elapsedTime = 0;
>
> /* Element Command Names used to communicate with the client */
> protected String agentRunningTag = "agentRunning";
> protected String agentStoppedTag = "agentStopped";
> protected String elapsedTimeTag = "elapsedTime";
> private String queryString = null;
>
> /**
> * @param name
> * @param type
> */
> public TcengLogAgent(String name, String type)
> {
> super(name);
> try
> {
> super.init();
> }
> catch (Exception e){e.printStackTrace();}
> // TODO Auto-generated constructor stub
> }
>
> public static void main(String[] args)
> {
> /* Create a TimeCollector Agent */
> TcengLogAgent jAgent = new
> TcengLogAgent("com.teamcenter.tptp.TcengLogAgent", "Collector");
>
> /* Register agent */
> try
> {
> jAgent.register();
> }
> catch(Exception e){e.printStackTrace();}
>
> Thread thread = new Thread(jAgent);
> thread.start();
> }
>
>
>
>
> public void processCommand(ICommandFragment cmd)
> {
> super.processCommand(cmd);
> System.out.println("Incoming command
> "+((CommandFragment)cmd).getCommandName() + System.currentTimeMillis());
>
> if(((CommandFragment)cmd).getCommandName().equals("run"))
> {
> this.sendRunResponse((CommandFragment)cmd);
> }
> }
>
> public void run()
> {
> while(running)
> {
> try {
> Thread.sleep(10);
> }
> catch (InterruptedException e) {}
> }
> /* Deregister agent */
> this.deregister();
> }
>
>
> public int receiveData(int sourceId, String buffer, int bufferLength)
> {
> queryString = buffer;
> //TO DO: At this point printing the data
> System.out.println("Data Recvd. on the data channel" +
> System.currentTimeMillis());
> System.out.println("+++++++++++++++++++++++++++++++++");
> System.out.println(buffer);
> System.out.println("++++++++++++++++++++++++++++++++++");
> return 0;
> }
>
>
> private int sendRunResponse(CommandFragment cmd)
> {
> int ret = -1;
>
> int destID = new Long(cmd.getSource()).intValue();
> try
> {
> super.sendData(destID, (char[])getFileList().toCharArray());
> ret = 0;
> }
> catch(Exception e){e.printStackTrace();}
>
> return ret;
> }
>
>
> public String getFileList (){
> // Connect to database and get the results.
> // Execute Query using querString
> // Return semicolon seperated file list
> }
>
> }
>
Re: Data transfer between Client and Agent performance issue [message #94922 is a reply to message #94361] Wed, 04 April 2007 13:10 Go to previous message
Eclipse UserFriend
Originally posted by: cvkmurthy.hotmail.com

Hi Ali,

The solution looks good. I would like to implement it. But how can I
make the client/Agent wait for acknowledgments? How does client and
agent communication occurs in TPTP core? Are there any examples which I
can refer which has a similar use case as mine?

One more question I have is, I created the agent by extending BaseAgent
class. But this class is not present in the Agent Controller plug-ins. I
have to put the tptpcore.jar from Eclipse plug-in directory in the class
path to make it work? If I am not wrong the Agent Controller should have
all classes which helps in creating the Agent. Am I doing something
wrong here?

Thanks and Regards,
Krishna


Ali Mehregani wrote:
> I'm not an expert in this topic but I'll make an attempt to answer your
> questions. First off, you should never need to do any sleeps in your code.
>
> There appears to be a racing condition between senddata() and run(). From
> what I understand, senddata() will send a query string from the client to
> the agent and run() will indicate that the agent should execute the query.
> You'll need to have an acknowledgement sent from the agent to the client to
> indicate that the agent has received the query string before you can execute
> the run method. Here's the flow:
>
> 1. client sends query via senddata()
> 2. client wait for acknowledgement
> 3. agent receives the query and acknowledges it
> 4. client wakes up after acknowledgement or times out
> 5. client executes the run() method if acknowledgement is received or
> repeats number 1.
>
> You can use a slightly different mechanism for avoiding the sleep you have
> in place before stopping the agent. The query result will need to be
> enclosed in a tag to indicate the beginning and end of the query result.
> You can either enclose the query result in an xml tag or have a header
> included to indicate the length of the result. For example:
>
> <query-result>
> result goes here...
> </query-result>
>
> or
>
> #query-result;length=<x>
> result goes here...
>
> The client will read in the result and will only stop an agent if the entire
> result has been received.
>
> Hope that helps,
> Ali Mehregani
>
>
> "Krishna" <cvkmurthy@hotmail.com> wrote in message
> news:eudmfs$tm2$1@utils.eclipse.org...
>> Hi Experts,
>>
>> I have a use case where the client connects to the Agent Controller
>> and sends a query string to the Agent. The Agent has the logic to
>> connect to the database, execute the query and return the results back
>> to the client.
>>
>> I am using senddata () to send the query string from client to Agent. I
>> have a class variable on the Agent which stores the query string. Then I
>> am calling run () method in the client side which will send command to
>> Agent to execute the query. If I donot put sleep of 1500 milli seconds
>> between senddata () and run () methods on the client side, I get a Null
>> pointer exception in the Agent, as the query gets executed before the
>> data is received by the Agent.
>>
>> I have a sleep of 2000 milli seconds on the client to receive the data
>> from the Agent. If I do not have sleep the stop command gets execute
>> even before the data is received.
>>
>> Is sleep necessary or is there a workaround for this problem? Is there a
>> better way to do this? In total it takes around 4 seconds to get the
>> result. This could be a performance issue for my project. Please find
>> the client and agent files attached.
>>
>> Regards,
>> Krishna
>>
>
>
> ------------------------------------------------------------ --------------------
>
>
>> /*********************************************************** ********************
>> * Copyright (c) 2005, 2006 Intel Corporation.
>> * All rights reserved. This program and the accompanying materials
>> * are made available under the terms of the Eclipse Public License v1.0
>> * which accompanies this distribution, and is available at
>> * http://www.eclipse.org/legal/epl-v10.html
>> *
>> * Contributors:
>> * Vishnu K Naikawadi,Intel - Initial API and implementation
>> *
>> * $Id: SampleClientAC.java,v 1.20 2006/02/10 22:12:31 vnaikawadi Exp $
>> ************************************************************ *******************/
>>
>>
>> package logParser.teamcenter;
>>
>> import org.eclipse.tptp.platform.execution.client.agent.IAgent;
>> import org.eclipse.tptp.platform.execution.client.agent.ICollector;
>> import org.eclipse.tptp.platform.execution.client.core.ConnectionIn fo;
>> import org.eclipse.tptp.platform.execution.client.core.IAgentContro ller;
>> import org.eclipse.tptp.platform.execution.client.core.IDataProcess or;
>> import org.eclipse.tptp.platform.execution.client.core.INode;
>> import org.eclipse.tptp.platform.execution.client.core.NodeFactory;
>> import org.eclipse.tptp.platform.execution.util.ICommandElement;
>> import org.eclipse.tptp.platform.execution.util.ICommandHandler;
>> import org.eclipse.tptp.platform.execution.util.TPTPDataPath;
>>
>> /**
>> * This sample connects to an Agent Controller running on the local host
>> * and creates a type of agent called collector.
>> * The client sends commands to the collector to start and stop execution.
>> * During the period when the collector is running, data is collected by
>> the collector.
>> * The data collected by the collector is then recieved by the client.
>> * @author gnagaraj
>> *
>> */
>>
>> public class TCEngLogClient
>> {
>> String fileList = null;
>> String queryString = null;
>>
>> public String getFileList (){
>> return fileList;
>> }
>>
>> public TCEngLogClient(){
>>
>> }
>>
>> //public static void main(String[] args)
>> public TCEngLogClient(String pQueryString)
>> {
>> queryString = pQueryString;
>> //Connect to the host where the Agent Controller is running
>> //See the Getting started guide for TPTP 4.0
>> String localhost = "localhost";
>> //This port number corresponds to the port where the Agent Controller
>> //listens/accepts connections. This is defined in the Agent Controller
>> //serviceconfig.xml file in the <AgentController_INSTALL_HOME>/config
>> int port = 10006;
>> System.out.println("Connecting to Host "+ localhost);
>>
>> //Create a Node that represents the target agent controller
>> INode SampleNode = null;
>> //Create the client Agent Controller representation object
>> IAgentController ac = null;
>> //Pass the connection info the client
>> ConnectionInfo connInfo = new ConnectionInfo();
>>
>> try
>> {
>> //Create a Node that represents the target machine and agent controller
>> SampleNode = (INode) NodeFactory.createNode(localhost);
>>
>> //Set the connection parameters required
>> connInfo.setHostName(localhost);
>> connInfo.setPort(port);
>> //connInfo.setAgentControllerNew(true);
>>
>> if (SampleNode != null)
>> {
>> // Connect to the Agent Controller, a successful connection returns
>> //a client side Agent Controller object that provides various
>> //methods to perform TPTP tasks.
>> System.out.println("Connecting to AC..");
>> ac = SampleNode.connect(connInfo);
>>
>> System.out.println("Connected to " + localhost + " at port number " +
>> port);
>>
>> //Create an Agent representation on the client to hold Agent information
>> //In this case a Collector object is created. A collector is a type of an
>> Agent
>> //The Agent Controller creates an instance of the Collector
>> //and returns an agent reference that allows the client to perform
>> operations on the collector.
>> ICollector TCollector =
>> (ICollector)ac.getAgent("com.teamcenter.tptp.TcengLogAgent",
>> "org.eclipse.tptp.platform.execution.client.agent.ICollector ");
>>
>> if(TCollector == null){System.out.println("Agent not available, configure
>> the agent and retry"); return;}
>>
>> //Create the Data Connection required to recieve response from the
>> collector;
>> //The input to startMonitoring is the to establish the data connection
>> between the client and
>> //the agent controller for the direction of data flow.
>> //See constants for additional values.
>> ((IAgent)TCollector).startMonitoring(TPTPDataPath.DATA_PATH_ TWO_WAY);
>>
>> ((IAgent)TCollector).addDataListener( new IDataProcessor()
>> {
>> public void incomingData(byte[] buffer, int length, java.net.InetAddress
>> peer)
>> {
>> String data = new String(buffer);
>> char a[] = data.toCharArray();
>> StringBuffer strBuffer = new StringBuffer ();
>> for (int i=0; i < a.length; i++){
>> if (a[i] == '$'){
>> break;
>> }
>> if (a[i] != a[1]){
>> strBuffer.append(a[i]);
>> }
>> }
>> System.out.println("The Data received from TimeCollector - " +
>> strBuffer.toString());
>> fileList = strBuffer.toString();
>> }
>>
>> public void incomingData(char[] buffer, int length, java.net.InetAddress
>> peer)
>> {
>> String data = new String (buffer);
>> System.out.println("Char Data Processor Called" + data);
>> }
>>
>> public void invalidDataType(byte[] data, int length, java.net.InetAddress
>> peer)
>> {
>> System.out.println("Data Processor Invalid Data Type Called");
>> }
>>
>> public void waitingForData()
>> {
>> System.out.println("Data Processor Waiting for Data Called");
>> }
>> });
>>
>> TCollector.sendData(queryString.getBytes());
>> Thread.sleep(1500);
>> //Send a message to Agent
>> TCollector.run();
>>
>> //Wait for the response to arrive
>> Thread.sleep(2000);
>>
>> TCollector.stop();
>> Thread.sleep(100);
>> // Disconnect from AC
>> ac.disconnect();
>> System.out.println("Disconnected");
>> }
>> else
>> {
>> System.out.println("Error occurred while creating the Node for " +
>> localhost);
>> }
>>
>> }
>> catch(Exception exp)
>> {
>> System.out.println("Error occurred while connecting to " + localhost + ":"
>> + exp);
>> }
>> }
>> }
>
>
> ------------------------------------------------------------ --------------------
>
>
>> /*********************************************************** ********************
>> * Copyright (c) 2005, 2006 Intel Corporation.
>> * All rights reserved. This program and the accompanying materials
>> * are made available under the terms of the Eclipse Public License v1.0
>> * which accompanies this distribution, and is available at
>> * http://www.eclipse.org/legal/epl-v10.html
>> *
>> * Contributors:
>> * Guru Nagarajan,Intel - Initial API and implementation
>> *
>> * $Id: TPTPJavaAgent.java,v 1.16 2006/02/10 21:53:14 vnaikawadi Exp $
>> ************************************************************ *******************/
>> package teamcenter.TPTP;
>>
>> import org.eclipse.tptp.platform.execution.datacollection.BaseAgent ;
>> import org.eclipse.tptp.platform.execution.util.ICommandFragment;
>> import org.eclipse.tptp.platform.execution.util.internal.CommandFra gment;
>>
>>
>> import java.io.FileInputStream;
>> import java.io.FileNotFoundException;
>> import java.io.IOException;
>> import java.rmi.NotBoundException;
>> import java.rmi.RemoteException;
>> import java.util.ArrayList;
>> import java.util.Date;
>> import java.util.Iterator;
>> import java.util.List;
>> import java.util.Properties;
>>
>>
>> /**
>> * @author gnagaraj
>> *
>> * TODO To change the template for this generated type comment go to
>> * Window - Preferences - Java - Code Style - Code Templates
>> */
>> public class TcengLogAgent extends BaseAgent implements Runnable{
>>
>> public static final String TIMECOLLECTOR_INTERFACE =
>> "com.teamcenter.tptp.TcengLogCollector";
>> protected boolean running = true;
>> protected Date startTime;
>> protected Date endTime;
>> protected long elapsedTime = 0;
>>
>> /* Element Command Names used to communicate with the client */
>> protected String agentRunningTag = "agentRunning";
>> protected String agentStoppedTag = "agentStopped";
>> protected String elapsedTimeTag = "elapsedTime";
>> private String queryString = null;
>>
>> /**
>> * @param name
>> * @param type
>> */
>> public TcengLogAgent(String name, String type)
>> {
>> super(name);
>> try
>> {
>> super.init();
>> }
>> catch (Exception e){e.printStackTrace();}
>> // TODO Auto-generated constructor stub
>> }
>>
>> public static void main(String[] args)
>> {
>> /* Create a TimeCollector Agent */
>> TcengLogAgent jAgent = new
>> TcengLogAgent("com.teamcenter.tptp.TcengLogAgent", "Collector");
>>
>> /* Register agent */
>> try
>> {
>> jAgent.register();
>> }
>> catch(Exception e){e.printStackTrace();}
>>
>> Thread thread = new Thread(jAgent);
>> thread.start();
>> }
>>
>>
>>
>>
>> public void processCommand(ICommandFragment cmd)
>> {
>> super.processCommand(cmd);
>> System.out.println("Incoming command
>> "+((CommandFragment)cmd).getCommandName() + System.currentTimeMillis());
>>
>> if(((CommandFragment)cmd).getCommandName().equals("run"))
>> {
>> this.sendRunResponse((CommandFragment)cmd);
>> }
>> }
>>
>> public void run()
>> {
>> while(running)
>> {
>> try {
>> Thread.sleep(10);
>> }
>> catch (InterruptedException e) {}
>> }
>> /* Deregister agent */
>> this.deregister();
>> }
>>
>>
>> public int receiveData(int sourceId, String buffer, int bufferLength)
>> {
>> queryString = buffer;
>> //TO DO: At this point printing the data
>> System.out.println("Data Recvd. on the data channel" +
>> System.currentTimeMillis());
>> System.out.println("+++++++++++++++++++++++++++++++++");
>> System.out.println(buffer);
>> System.out.println("++++++++++++++++++++++++++++++++++");
>> return 0;
>> }
>>
>>
>> private int sendRunResponse(CommandFragment cmd)
>> {
>> int ret = -1;
>>
>> int destID = new Long(cmd.getSource()).intValue();
>> try
>> {
>> super.sendData(destID, (char[])getFileList().toCharArray());
>> ret = 0;
>> }
>> catch(Exception e){e.printStackTrace();}
>>
>> return ret;
>> }
>>
>>
>> public String getFileList (){
>> // Connect to database and get the results.
>> // Execute Query using querString
>> // Return semicolon seperated file list
>> }
>>
>> }
>>
>
>
Previous Topic:Is seperate port required by each Agent?
Next Topic:No output when Profiling
Goto Forum:
  


Current Time: Fri Apr 26 02:27:11 GMT 2024

Powered by FUDForum. Page generated in 0.02682 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top