Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Test and Performance Tools Platform (TPTP) » API for sending commands
API for sending commands [message #45802] Fri, 09 December 2005 13:08 Go to next message
Daniel Miles is currently offline Daniel Miles
Messages: 11
Registered: July 2009
Junior Member
I'm exploring TPTP, trying to figure out what it can do and I've run
into a question I'm unable to find documentation or example code for.

I've implemented a very simple agent called SampleAgent, extending
tptp/agents/BaseCollectorImpl which registers with the AgentController.
I wrote another bit of simple code called SampleAgentClient (which
contains an instance of a class that extends tptp/client/Collector) and
with it I am able to connect to SampleAgent and send both data and commands.

tptp/agents/BaseCollectorImpl has functions (which SampleAgent inherits)
like sendCommand and sendErrorCommand that send common base event
formatted strings to a specified destination ID and I want to use them
to send responses back to my client when my agent executes a command.

How can I set up my SampleAgentClient to recieve them? I tried to use
the tptp/client/Collector::addEventListener function but I got hung up
on the (char* InterfaceID) parameter... I don't know what it is and none
of the things I've tried work (the command returns a -1 result).

Can anyone help?
Re: API for sending commands [message #46455 is a reply to message #45802] Tue, 13 December 2005 17:27 Go to previous messageGo to next message
Vishnu is currently offline Vishnu
Messages: 19
Registered: July 2009
Junior Member
Daniel,

There are two ways you can send responses back to the client application
depending on how you want to send them.

1. Synchronous response
2. Asynchronous events/response

Synchronous response - In this case, a client application sends a command
to the agent. While sending the command it registers an object that can
handle the response for the command. On the agent side, it receives the
command sends the response back but the key is - it should use the same
contextID ("ctxt" attribute of the XML command <Cmd> tag) as the command it
received. Having this same context id in the response command, the client
API will forward the response to the handler object registered while sending
actual command. Please take a look at the TimeCollector::sendStopResponse()
method for the implementation details in agent. On the client-side, look at
Collector::stop() method impl on how an object is registered to receive
response while sending the stop command.

Asynchronous response - Here an agent sends events/responses asynchronously
to the client application whenever an event is generated. As an agent may be
sending several events, they can be grouped and is uniquely identified with
the InterfaceID. This InterfaceID is a string defined by agent in the agent
configuration file indicating that it supports the interface just like any
other interface it supports. For a client to be able to receive events from
a specific interface, it must register an event handler with the agent for
that InterfaceID. And the registered event handler object will be called
when an event belonging to this InterfaceID is received. On the agent side,
EventProviderImpl provides the implementation for handling the event
registration and dispatch mechanism. The agent only need to use the API to
send events. I am attaching the modified SampleClient and TimeCollector
samples to demonstrate the asynchronous event mechanism. Look for the sample
code (for sending events from agent) in TimeCollector::sendCurrentTime().
And on the client side, there is a class TimeCollectorEventHandler for
handling the events received. SampleClient.cpp contains calls for event
registration. I will be checking-in this sample to CVS very soon.

Please go through the sample code and let me know if you still have any
issues.

Thanks
Vishnu


"Daniel Miles" <daniel.t.miles@hp.com> wrote in message
news:dnch6o$fhq$1@news.eclipse.org...
> I'm exploring TPTP, trying to figure out what it can do and I've run
> into a question I'm unable to find documentation or example code for.
>
> I've implemented a very simple agent called SampleAgent, extending
> tptp/agents/BaseCollectorImpl which registers with the AgentController.
> I wrote another bit of simple code called SampleAgentClient (which
> contains an instance of a class that extends tptp/client/Collector) and
> with it I am able to connect to SampleAgent and send both data and
> commands.
>
> tptp/agents/BaseCollectorImpl has functions (which SampleAgent inherits)
> like sendCommand and sendErrorCommand that send common base event
> formatted strings to a specified destination ID and I want to use them
> to send responses back to my client when my agent executes a command.
>
> How can I set up my SampleAgentClient to recieve them? I tried to use
> the tptp/client/Collector::addEventListener function but I got hung up
> on the (char* InterfaceID) parameter... I don't know what it is and none
> of the things I've tried work (the command returns a -1 result).
>
> Can anyone help?


  • Attachment: samples.zip
    (Size: 11.15KB, Downloaded 46 times)
Re: API for sending commands [message #49966 is a reply to message #46455] Wed, 11 January 2006 19:37 Go to previous messageGo to next message
David Read is currently offline David Read
Messages: 35
Registered: July 2009
Member
Hi Vishnu,
Do you know if the Java client code works for asynchronous events?
I have a Java client and C++ agent working fine using a data channel, but have been unsuccessful with the event handling.
When I call the Java addEventListener, I get a message back from the agent saying listenerAccepted, but subsequent events from the agent report 'Could not find command handler'
I think this is because the ctxt="0", but from your notes below, it should be using the InterfaceID?
Your thoughts would be appreciated.

Here's a snip of my debug output:

Agent is running
Recvd Message : [B@1377d92
Sending sendMessage command
The message size - 8
The message size - 172
Received a non-acknowledgement message
Processing the Message.
The command read from the buffer - <Cmd ctxt="0" dest="121" src="118"> <log iid="com.davidr.taed.SampleAgentEvents"><aLog>Target on port 2000 Received message msg Hello from workbench
</aLog></log></Cmd>
The AC response 0
The command received is - <Cmd ctxt="0" dest="121" src="118"> <log iid="com.davidr.taed.SampleAgentEvents"><aLog>Target on port 2000 Received message msg Hello from workbench
</aLog></log></Cmd>

Checking for CONNECTION_COMPLETE response
Calling the Command Handler:org.eclipse.tptp.platform.execution.client.core.impl .ConnectionImpl$1@176343e
The context of the returned command:0
Could not find command handler
Recvd Message : [B@1377d92
Received a non-acknowledgement message
Processing the Message.
The command read from the buffer - <Cmd ctxt="0" dest="121" src="118"> <log iid="com.davidr.taed.SampleAgentEvents"><aLog>Connection closed
</aLog></log></Cmd>
The AC response 0
The command received is - <Cmd ctxt="0" dest="121" src="118"> <log iid="com.davidr.taed.SampleAgentEvents"><aLog>Connection closed
</aLog></log></Cmd>

Checking for CONNECTION_COMPLETE response
Calling the Command Handler:org.eclipse.tptp.platform.execution.client.core.impl .ConnectionImpl$1@176343e
The context of the returned command:0
Could not find command handler
Recvd Message : [B@1377d92


Vishnu Naikawadi wrote:
> Daniel,
>
> There are two ways you can send responses back to the client application
> depending on how you want to send them.
>
> 1. Synchronous response
> 2. Asynchronous events/response
>
> Synchronous response - In this case, a client application sends a command
> to the agent. While sending the command it registers an object that can
> handle the response for the command. On the agent side, it receives the
> command sends the response back but the key is - it should use the same
> contextID ("ctxt" attribute of the XML command <Cmd> tag) as the command it
> received. Having this same context id in the response command, the client
> API will forward the response to the handler object registered while sending
> actual command. Please take a look at the TimeCollector::sendStopResponse()
> method for the implementation details in agent. On the client-side, look at
> Collector::stop() method impl on how an object is registered to receive
> response while sending the stop command.
>
> Asynchronous response - Here an agent sends events/responses asynchronously
> to the client application whenever an event is generated. As an agent may be
> sending several events, they can be grouped and is uniquely identified with
> the InterfaceID. This InterfaceID is a string defined by agent in the agent
> configuration file indicating that it supports the interface just like any
> other interface it supports. For a client to be able to receive events from
> a specific interface, it must register an event handler with the agent for
> that InterfaceID. And the registered event handler object will be called
> when an event belonging to this InterfaceID is received. On the agent side,
> EventProviderImpl provides the implementation for handling the event
> registration and dispatch mechanism. The agent only need to use the API to
> send events. I am attaching the modified SampleClient and TimeCollector
> samples to demonstrate the asynchronous event mechanism. Look for the sample
> code (for sending events from agent) in TimeCollector::sendCurrentTime().
> And on the client side, there is a class TimeCollectorEventHandler for
> handling the events received. SampleClient.cpp contains calls for event
> registration. I will be checking-in this sample to CVS very soon.
>
> Please go through the sample code and let me know if you still have any
> issues.
>
> Thanks
> Vishnu
>
>
> "Daniel Miles" <daniel.t.miles@hp.com> wrote in message
> news:dnch6o$fhq$1@news.eclipse.org...
>
>>I'm exploring TPTP, trying to figure out what it can do and I've run
>>into a question I'm unable to find documentation or example code for.
>>
>>I've implemented a very simple agent called SampleAgent, extending
>>tptp/agents/BaseCollectorImpl which registers with the AgentController.
>>I wrote another bit of simple code called SampleAgentClient (which
>>contains an instance of a class that extends tptp/client/Collector) and
>>with it I am able to connect to SampleAgent and send both data and
>>commands.
>>
>>tptp/agents/BaseCollectorImpl has functions (which SampleAgent inherits)
>>like sendCommand and sendErrorCommand that send common base event
>>formatted strings to a specified destination ID and I want to use them
>>to send responses back to my client when my agent executes a command.
>>
>>How can I set up my SampleAgentClient to recieve them? I tried to use
>>the tptp/client/Collector::addEventListener function but I got hung up
>>on the (char* InterfaceID) parameter... I don't know what it is and none
>>of the things I've tried work (the command returns a -1 result).
>>
>>Can anyone help?
>
>
>
Re: API for sending commands [message #50294 is a reply to message #49966] Thu, 12 January 2006 17:10 Go to previous message
Vishnu is currently offline Vishnu
Messages: 19
Registered: July 2009
Junior Member
David,

Can you please verify few things in your program and let me know?
Meanwhile I wll verify the Java Client support for event interface.

1. On the client side, check the interfaceID and listenerID in the
<addEventListener> command. The interfaceID should be
"com.davidr.taed.SampleAgentEvents". The listenerID value should be a
positive integer. This is the ID which represents the object that you are
registering as the event listener so that when an event is received the
client framework calls the listener using this ID. The listenerID is
automatically generated by the client framework. This listenerID becomes the
contextID or "ctxt" value in the event command coming from the agent (which
in your case is coming as zero).

For e.g. The command sequence would be
Client to Agent - Add Event Listener
<Cmd src="121" dest="118" ctxt="111">
<addEventListener iid="org.eclipse.tptp.eventProvider">
<interfaceID>com.davidr.taed.SampleAgentEvents</interfaceID >
<listenerID>1234</listenerID>
</addEventListener>
</Cmd>

Agent to Client - Listener Accepted response
<Cmd src="118" dest="121" ctxt="111">
<listenerAccepted iid="org.eclipse.tptp.eventProvider"></listenerAccepted>
</Cmd>

Agent to Client - Send the Event
<Cmd ctxt="1234" dest="121" src="118">
<log iid="com.davidr.taed.SampleAgentEvents">
<aLog>Target on port 2000 Received message msg Hello from workbench</aLog>
</log>
</Cmd>

2. In the C++ agent, you should call the Event Notification API as below.

CmdBlock* cmd = new CmdBlock();

//Initialize paramList for key value pairs
tptp_list_t* paramList = (tptp_list_t*)tptp_malloc( sizeof(tptp_list_t));
tptp_list_init(paramList);
...
//create and add parameters
....
cmd->setIID("com.davidr.taed.SampleAgentEvents");
cmd->setCommandName("log");
cmd->setParamList(paramList);

// Send the Event Notification to all the listener objects registered to
listen for this event interface
sendEventNotifications(cmd);


Thanks
Vishnu


"David Read" <DavidRead@gmx.net> wrote in message
news:dq48c7$fot$1@utils.eclipse.org...
> Hi Vishnu,
> Do you know if the Java client code works for asynchronous events?
> I have a Java client and C++ agent working fine using a data channel, but
> have been unsuccessful with the event handling.
> When I call the Java addEventListener, I get a message back from the agent
> saying listenerAccepted, but subsequent events from the agent report
> 'Could not find command handler'
> I think this is because the ctxt="0", but from your notes below, it should
> be using the InterfaceID?
> Your thoughts would be appreciated.
>
> Here's a snip of my debug output:
>
> Agent is running
> Recvd Message : [B@1377d92
> Sending sendMessage command
> The message size - 8
> The message size - 172
> Received a non-acknowledgement message
> Processing the Message.
> The command read from the buffer - <Cmd ctxt="0" dest="121" src="118">
> <log iid="com.davidr.taed.SampleAgentEvents"><aLog>Target on port 2000
> Received message msg Hello from workbench
> </aLog></log></Cmd>
> The AC response 0
> The command received is - <Cmd ctxt="0" dest="121" src="118"> <log
> iid="com.davidr.taed.SampleAgentEvents"><aLog>Target on port 2000 Received
> message msg Hello from workbench
> </aLog></log></Cmd>
>
> Checking for CONNECTION_COMPLETE response
> Calling the Command
> Handler:org.eclipse.tptp.platform.execution.client.core.impl .ConnectionImpl$1@176343e
> The context of the returned command:0
> Could not find command handler
> Recvd Message : [B@1377d92
> Received a non-acknowledgement message
> Processing the Message.
> The command read from the buffer - <Cmd ctxt="0" dest="121" src="118">
> <log iid="com.davidr.taed.SampleAgentEvents"><aLog>Connection closed
> </aLog></log></Cmd>
> The AC response 0
> The command received is - <Cmd ctxt="0" dest="121" src="118"> <log
> iid="com.davidr.taed.SampleAgentEvents"><aLog>Connection closed
> </aLog></log></Cmd>
>
> Checking for CONNECTION_COMPLETE response
> Calling the Command
> Handler:org.eclipse.tptp.platform.execution.client.core.impl .ConnectionImpl$1@176343e
> The context of the returned command:0
> Could not find command handler
> Recvd Message : [B@1377d92
>
>
> Vishnu Naikawadi wrote:
>> Daniel,
>>
>> There are two ways you can send responses back to the client application
>> depending on how you want to send them.
>>
>> 1. Synchronous response
>> 2. Asynchronous events/response
>>
>> Synchronous response - In this case, a client application sends a
>> command to the agent. While sending the command it registers an object
>> that can handle the response for the command. On the agent side, it
>> receives the command sends the response back but the key is - it should
>> use the same contextID ("ctxt" attribute of the XML command <Cmd> tag) as
>> the command it received. Having this same context id in the response
>> command, the client API will forward the response to the handler object
>> registered while sending actual command. Please take a look at the
>> TimeCollector::sendStopResponse() method for the implementation details
>> in agent. On the client-side, look at Collector::stop() method impl on
>> how an object is registered to receive response while sending the stop
>> command.
>>
>> Asynchronous response - Here an agent sends events/responses
>> asynchronously to the client application whenever an event is generated.
>> As an agent may be sending several events, they can be grouped and is
>> uniquely identified with the InterfaceID. This InterfaceID is a string
>> defined by agent in the agent configuration file indicating that it
>> supports the interface just like any other interface it supports. For a
>> client to be able to receive events from a specific interface, it must
>> register an event handler with the agent for that InterfaceID. And the
>> registered event handler object will be called when an event belonging to
>> this InterfaceID is received. On the agent side, EventProviderImpl
>> provides the implementation for handling the event registration and
>> dispatch mechanism. The agent only need to use the API to send events. I
>> am attaching the modified SampleClient and TimeCollector samples to
>> demonstrate the asynchronous event mechanism. Look for the sample code
>> (for sending events from agent) in TimeCollector::sendCurrentTime(). And
>> on the client side, there is a class TimeCollectorEventHandler for
>> handling the events received. SampleClient.cpp contains calls for event
>> registration. I will be checking-in this sample to CVS very soon.
>>
>> Please go through the sample code and let me know if you still have any
>> issues.
>>
>> Thanks
>> Vishnu
>>
>>
>> "Daniel Miles" <daniel.t.miles@hp.com> wrote in message
>> news:dnch6o$fhq$1@news.eclipse.org...
>>
>>>I'm exploring TPTP, trying to figure out what it can do and I've run
>>>into a question I'm unable to find documentation or example code for.
>>>
>>>I've implemented a very simple agent called SampleAgent, extending
>>>tptp/agents/BaseCollectorImpl which registers with the AgentController.
>>>I wrote another bit of simple code called SampleAgentClient (which
>>>contains an instance of a class that extends tptp/client/Collector) and
>>>with it I am able to connect to SampleAgent and send both data and
>>>commands.
>>>
>>>tptp/agents/BaseCollectorImpl has functions (which SampleAgent inherits)
>>>like sendCommand and sendErrorCommand that send common base event
>>>formatted strings to a specified destination ID and I want to use them
>>>to send responses back to my client when my agent executes a command.
>>>
>>>How can I set up my SampleAgentClient to recieve them? I tried to use
>>>the tptp/client/Collector::addEventListener function but I got hung up
>>>on the (char* InterfaceID) parameter... I don't know what it is and none
>>>of the things I've tried work (the command returns a -1 result).
>>>
>>>Can anyone help?
>>
>>
Previous Topic:Mixing manuel test methods with automated test methods
Next Topic:Extending the tptp UI
Goto Forum:
  


Current Time: Tue Sep 02 12:53:35 EDT 2014

Powered by FUDForum. Page generated in 0.08641 seconds