Home » Archived » Test and Performance Tools Platform (TPTP) » Event handling - New Agent Controller
Event handling - New Agent Controller [message #50171] |
Thu, 12 January 2006 17:47 |
David Read Messages: 35 Registered: July 2009 |
Member |
|
|
I originally posted this as a reply to an old post (13Dec05) so I think it may have been missed.
Here it is again:
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 send
ing 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: Event handling - New Agent Controller [message #50323 is a reply to message #50171] |
Thu, 12 January 2006 22:12 |
Vishnu Messages: 19 Registered: July 2009 |
Junior Member |
|
|
David,
I just responded to your original message. Attaching the same response
below.
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:dq64nn$le1$1@utils.eclipse.org...
>I originally posted this as a reply to an old post (13Dec05) so I think it
>may have been missed.
> Here it is again:
>
> 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 send
> ing 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: Event handling - New Agent Controller [message #50351 is a reply to message #50323] |
Thu, 12 January 2006 23:48 |
David Read Messages: 35 Registered: July 2009 |
Member |
|
|
Hi Vishnu,
Thanks for the pointers. My apologies for the double posting.
It looks like the fault is in AgentImpl.addEventListener() - It does not add the listenerID.
I have used my own method:
private void addEventListener(String interfaceID, ICommandHandler listener) throws InactiveAgentException, NotConnectedException
{
long listenerId = getAgentController().getNextContextId();
getAgentController().getConnection().getContextMapper().addC ontext(listenerId, listener);
StringBuffer cmd = new StringBuffer("");
cmd.append("<addEventListener iid=\"org.eclipse.tptp.eventProvider\">");
cmd.append("<interfaceID>" + interfaceID + "</interfaceID>");
cmd.append("<listenerID>" + listenerId + "</listenerID>");
cmd.append("</addEventListener>");
((IAgent)agent).sendCommand(cmd.toString(), null);
}
and now it is working.
I also had to modify IAgentController.java and IConnection.java to get access to the contextMapper, so it is a bit of a hack.
Do you know a better solution?
David.
Vishnu Naikawadi wrote:
> David,
>
> I just responded to your original message. Attaching the same response
> below.
>
> 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:dq64nn$le1$1@utils.eclipse.org...
>
>>I originally posted this as a reply to an old post (13Dec05) so I think it
>>may have been missed.
>>Here it is again:
>>
>>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 send
>>
>>ing 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: Event handling - New Agent Controller [message #50436 is a reply to message #50351] |
Fri, 13 January 2006 18:01 |
Vishnu Messages: 19 Registered: July 2009 |
Junior Member |
|
|
David,
Good to know that you got it to work. I have verified that the modified API
and implementation for event handling in Java client was not checked-in
during 4.1 release due to time constraints. This implementation will look
similar to C++ implementation. So, you don't need to hack the code. This
code most probably will be checked-in today. I will let you know once it is
available.
Thanks
Vishnu
"David Read" <DavidRead@gmx.net> wrote in message
news:dq6pt9$pn6$1@utils.eclipse.org...
> Hi Vishnu,
> Thanks for the pointers. My apologies for the double posting.
> It looks like the fault is in AgentImpl.addEventListener() - It does not
> add the listenerID.
>
> I have used my own method:
>
> private void addEventListener(String interfaceID, ICommandHandler
> listener) throws InactiveAgentException, NotConnectedException
> {
> long listenerId = getAgentController().getNextContextId();
>
> getAgentController().getConnection().getContextMapper().addC ontext(listenerId,
> listener);
> StringBuffer cmd = new StringBuffer("");
> cmd.append("<addEventListener
> iid=\"org.eclipse.tptp.eventProvider\">");
> cmd.append("<interfaceID>" + interfaceID + "</interfaceID>");
> cmd.append("<listenerID>" + listenerId + "</listenerID>");
> cmd.append("</addEventListener>");
> ((IAgent)agent).sendCommand(cmd.toString(), null);
> }
>
> and now it is working.
> I also had to modify IAgentController.java and IConnection.java to get
> access to the contextMapper, so it is a bit of a hack.
> Do you know a better solution?
>
> David.
>
>
>
> Vishnu Naikawadi wrote:
>> David,
>>
>> I just responded to your original message. Attaching the same response
>> below.
>>
>> 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:dq64nn$le1$1@utils.eclipse.org...
>>
>>>I originally posted this as a reply to an old post (13Dec05) so I think
>>>it may have been missed.
>>>Here it is again:
>>>
>>>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 send
>>>
>>>ing 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: Event handling - New Agent Controller [message #50548 is a reply to message #50436] |
Sat, 14 January 2006 00:43 |
Vishnu Messages: 19 Registered: July 2009 |
Junior Member |
|
|
David,
The code for the modified API and implementation is checked-in today. It
should be available in the next build. The new API is as below.
public long addEventListener(String interfaceID, ICommandHandler listener) ;
public void removeEventListener(String interfaceID, long listenerID) ;
The addEventListener() method now returns the listenerID of the object being
registered (listener passed as second parameter). This listenerID should be
passed to removeEventListener() to remove the listener from getting the
event notifications.
Please try after you get the changes and let us know.
Thanks
Vishnu
"Vishnu Naikawadi" <vishnu.naikawadi@intel.com> wrote in message
news:dq8pt8$v0e$1@utils.eclipse.org...
> David,
>
> Good to know that you got it to work. I have verified that the modified
> API and implementation for event handling in Java client was not
> checked-in during 4.1 release due to time constraints. This implementation
> will look similar to C++ implementation. So, you don't need to hack the
> code. This code most probably will be checked-in today. I will let you
> know once it is available.
>
> Thanks
> Vishnu
>
> "David Read" <DavidRead@gmx.net> wrote in message
> news:dq6pt9$pn6$1@utils.eclipse.org...
>> Hi Vishnu,
>> Thanks for the pointers. My apologies for the double posting.
>> It looks like the fault is in AgentImpl.addEventListener() - It does not
>> add the listenerID.
>>
>> I have used my own method:
>>
>> private void addEventListener(String interfaceID, ICommandHandler
>> listener) throws InactiveAgentException, NotConnectedException
>> {
>> long listenerId = getAgentController().getNextContextId();
>>
>> getAgentController().getConnection().getContextMapper().addC ontext(listenerId,
>> listener);
>> StringBuffer cmd = new StringBuffer("");
>> cmd.append("<addEventListener
>> iid=\"org.eclipse.tptp.eventProvider\">");
>> cmd.append("<interfaceID>" + interfaceID + "</interfaceID>");
>> cmd.append("<listenerID>" + listenerId + "</listenerID>");
>> cmd.append("</addEventListener>");
>> ((IAgent)agent).sendCommand(cmd.toString(), null);
>> }
>>
>> and now it is working.
>> I also had to modify IAgentController.java and IConnection.java to get
>> access to the contextMapper, so it is a bit of a hack.
>> Do you know a better solution?
>>
>> David.
>>
>>
>>
>> Vishnu Naikawadi wrote:
>>> David,
>>>
>>> I just responded to your original message. Attaching the same response
>>> below.
>>>
>>> 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:dq64nn$le1$1@utils.eclipse.org...
>>>
>>>>I originally posted this as a reply to an old post (13Dec05) so I think
>>>>it may have been missed.
>>>>Here it is again:
>>>>
>>>>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 send
>>>>
>>>>ing 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: Event handling - New Agent Controller [message #50891 is a reply to message #50548] |
Wed, 18 January 2006 21:57 |
David Read Messages: 35 Registered: July 2009 |
Member |
|
|
Hi Vishnu,
Thank you - that works.
I'm still on the 4.1 build because my own code is still in development (read flaky) and I didn't want any other unknowns, so I had to pull in some other files to get agentImpl to compile.
Have you noticed any timing/inconsistent behaviour with the Agent Controller?
I have had to introduce a delay before calling addEventListener, otherwise the listenerAccepted message is not always returned.
I'm connecting to an embedded card, running Embedded XP on a Transmeta processor @ 800Mhz, so it's a bit slower than most desktops but no slouch.
After connecting to the Agent Controller, I start a process, which is not processor intensive, then get the agent, send a command to it, which just sets a local variable, then add the event listener.
If I don't sleep - currently 1 second - before addEventListener, then the command is ignored.
I have checked - using Ethereal - that the command is actually being sent out on the wire to the card, and it is a valid packet etc.
The Java client software is running on a 2.6GHz desktop.
Have you seen anything similar?
Here's some of the code:
agent = (ICollector)agentController.getAgent("com.davidr.taed.SampleAgent ",
"org.eclipse.tptp.platform.execution.client.agent.ICollector ");
// Tell the agent which port to use to talk to the target
if (Constants.TPTP_DEBUG)
System.out.println("Sending setTargetPort command from " + hostName);
int port = getExecutable().getListeningPort();
StringBuffer tempbuf = new StringBuffer("");
tempbuf.append("<setTargetPort iid=\"com.davidr.taed.SampleAgent\">" + "<targetPort>"
+ port + "</targetPort></setTargetPort>");
((IAgent)agent).sendCommand(tempbuf.toString(), new ICommandHandler()
{
public void incomingCommand(INode node, ICommandElement command)
{
String commandStr = new String(((CommandFragment)command).getCommandData());
System.out.println(hostName + " response to setTargetPort: " + commandStr);
}
});
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
if (Constants.TPTP_DEBUG)
System.out.println("Sending addEventListener from " + hostName);
((IAgent)agent).addEventListener("com.davidr.taed.SampleAgentEvents ", new ICommandHandler()
{
public void incomingCommand(INode node, ICommandElement command)
{
String commandStr = new String(((CommandFragment)command).getCommandData());
setEventData(commandStr);
if (Constants.TPTP_DEBUG)System.out.println(hostName + " SampleAgentEvents - " + commandStr);
}
});
}
if (Constants.TPTP_DEBUG) System.out.println(hostName + " Start agent running");
agent.run();
//---------------------------------------------------------- --------------------------------
Vishnu Naikawadi wrote:
> David,
>
> The code for the modified API and implementation is checked-in today. It
> should be available in the next build. The new API is as below.
>
> public long addEventListener(String interfaceID, ICommandHandler listener) ;
> public void removeEventListener(String interfaceID, long listenerID) ;
>
> The addEventListener() method now returns the listenerID of the object being
> registered (listener passed as second parameter). This listenerID should be
> passed to removeEventListener() to remove the listener from getting the
> event notifications.
> Please try after you get the changes and let us know.
>
> Thanks
> Vishnu
>
> "Vishnu Naikawadi" <vishnu.naikawadi@intel.com> wrote in message
> news:dq8pt8$v0e$1@utils.eclipse.org...
>
>>David,
>>
>>Good to know that you got it to work. I have verified that the modified
>>API and implementation for event handling in Java client was not
>>checked-in during 4.1 release due to time constraints. This implementation
>>will look similar to C++ implementation. So, you don't need to hack the
>>code. This code most probably will be checked-in today. I will let you
>>know once it is available.
>>
>>Thanks
>>Vishnu
>>
>>"David Read" <DavidRead@gmx.net> wrote in message
>>news:dq6pt9$pn6$1@utils.eclipse.org...
>>
>>>Hi Vishnu,
>>>Thanks for the pointers. My apologies for the double posting.
>>>It looks like the fault is in AgentImpl.addEventListener() - It does not
>>>add the listenerID.
>>>
>>>I have used my own method:
>>>
>>>private void addEventListener(String interfaceID, ICommandHandler
>>>listener) throws InactiveAgentException, NotConnectedException
>>>{
>>> long listenerId = getAgentController().getNextContextId();
>>>
>>> getAgentController().getConnection().getContextMapper().addC ontext(listenerId,
>>>listener);
>>> StringBuffer cmd = new StringBuffer("");
>>> cmd.append("<addEventListener
>>>iid=\"org.eclipse.tptp.eventProvider\">");
>>> cmd.append("<interfaceID>" + interfaceID + "</interfaceID>");
>>> cmd.append("<listenerID>" + listenerId + "</listenerID>");
>>> cmd.append("</addEventListener>");
>>> ((IAgent)agent).sendCommand(cmd.toString(), null);
>>>}
>>>
>>>and now it is working.
>>>I also had to modify IAgentController.java and IConnection.java to get
>>>access to the contextMapper, so it is a bit of a hack.
>>>Do you know a better solution?
>>>
>>>David.
>>>
>>>
>>>
>>>Vishnu Naikawadi wrote:
>>>
>>>>David,
>>>>
>>>>I just responded to your original message. Attaching the same response
>>>>below.
>>>>
>>>>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:dq64nn$le1$1@utils.eclipse.org...
>>>>
>>>>
>>>>>I originally posted this as a reply to an old post (13Dec05) so I think
>>>>>it may have been missed.
>>>>>Here it is again:
>>>>>
>>>>>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 send
>>>>>
>>>>>ing 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: Event handling - New Agent Controller [message #50947 is a reply to message #50891] |
Thu, 19 January 2006 20:32 |
Vishnu Messages: 19 Registered: July 2009 |
Junior Member |
|
|
David,
I have tested one more time doing similar things you are doing - like
getAgent(), addEventListener() and run(), etc. But I didn't have any problem
with getting the listenerAccepted response and I don't have any sleep before
addEventListener call.
Just to get more information, I have modified the AgentImpl.java a little
bit to add a conditional check for listenerAccepted response command.
Attaching the modified file and please run your test again to see what
happens. While doing this test please remove the sleep you added in your
program.
But one thing to be noted is - since the client and AC/agent communication
is asynchronous in nature, whenever there is a need to get the response for
a command before going ahead with the execution and doing other things, we
should wait and check for the expected response until we receive it. The
best way to handle this is using semaphores, which is introduced in Java
1.5. We will probably implement this in future.
Please try and let me know the result.
Thanks
Vishnu
"David Read" <DavidRead@gmx.net> wrote in message
news:dqmdkv$ib6$1@utils.eclipse.org...
> Hi Vishnu,
> Thank you - that works.
> I'm still on the 4.1 build because my own code is still in development
> (read flaky) and I didn't want any other unknowns, so I had to pull in
> some other files to get agentImpl to compile.
>
> Have you noticed any timing/inconsistent behaviour with the Agent
> Controller?
>
> I have had to introduce a delay before calling addEventListener, otherwise
> the listenerAccepted message is not always returned.
> I'm connecting to an embedded card, running Embedded XP on a Transmeta
> processor @ 800Mhz, so it's a bit slower than most desktops but no slouch.
> After connecting to the Agent Controller, I start a process, which is not
> processor intensive, then get the agent, send a command to it, which just
> sets a local variable, then add the event listener.
> If I don't sleep - currently 1 second - before addEventListener, then the
> command is ignored.
> I have checked - using Ethereal - that the command is actually being sent
> out on the wire to the card, and it is a valid packet etc.
> The Java client software is running on a 2.6GHz desktop.
> Have you seen anything similar?
> Here's some of the code:
>
>
> agent =
> (ICollector)agentController.getAgent("com.davidr.taed.SampleAgent ",
>
> "org.eclipse.tptp.platform.execution.client.agent.ICollector ");
>
> // Tell the agent which port to use to talk to the target
> if (Constants.TPTP_DEBUG)
> System.out.println("Sending setTargetPort command from " +
> hostName);
> int port = getExecutable().getListeningPort();
> StringBuffer tempbuf = new StringBuffer("");
> tempbuf.append("<setTargetPort
> iid=\"com.davidr.taed.SampleAgent\">" + "<targetPort>"
> + port + "</targetPort></setTargetPort>");
> ((IAgent)agent).sendCommand(tempbuf.toString(), new
> ICommandHandler()
> {
> public void incomingCommand(INode node, ICommandElement
> command)
> {
> String commandStr = new
> String(((CommandFragment)command).getCommandData());
> System.out.println(hostName + " response to
> setTargetPort: " + commandStr);
> }
> });
>
> try
> {
> Thread.sleep(1000);
> }
> catch (InterruptedException e)
> {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> if (Constants.TPTP_DEBUG)
> System.out.println("Sending addEventListener from " +
> hostName);
>
> ((IAgent)agent).addEventListener("com.davidr.taed.SampleAgentEvents ", new
> ICommandHandler()
> {
> public void incomingCommand(INode node, ICommandElement
> command)
> {
> String commandStr = new
> String(((CommandFragment)command).getCommandData());
> setEventData(commandStr);
> if (Constants.TPTP_DEBUG)System.out.println(hostName +
> " SampleAgentEvents - " + commandStr);
> }
> });
>
> }
> if (Constants.TPTP_DEBUG) System.out.println(hostName + " Start
> agent running");
> agent.run();
> //---------------------------------------------------------- --------------------------------
>
>
> Vishnu Naikawadi wrote:
>> David,
>>
>> The code for the modified API and implementation is checked-in today. It
>> should be available in the next build. The new API is as below.
>>
>> public long addEventListener(String interfaceID, ICommandHandler
>> listener) ;
>> public void removeEventListener(String interfaceID, long listenerID) ;
>>
>> The addEventListener() method now returns the listenerID of the object
>> being
>> registered (listener passed as second parameter). This listenerID should
>> be
>> passed to removeEventListener() to remove the listener from getting the
>> event notifications.
>> Please try after you get the changes and let us know.
>>
>> Thanks
>> Vishnu
>>
>> "Vishnu Naikawadi" <vishnu.naikawadi@intel.com> wrote in message
>> news:dq8pt8$v0e$1@utils.eclipse.org...
>>
>>>David,
>>>
>>>Good to know that you got it to work. I have verified that the modified
>>>API and implementation for event handling in Java client was not
>>>checked-in during 4.1 release due to time constraints. This
>>>implementation
>>>will look similar to C++ implementation. So, you don't need to hack the
>>>code. This code most probably will be checked-in today. I will let you
>>>know once it is available.
>>>
>>>Thanks
>>>Vishnu
>>>
>>>"David Read" <DavidRead@gmx.net> wrote in message
>>>news:dq6pt9$pn6$1@utils.eclipse.org...
>>>
>>>>Hi Vishnu,
>>>>Thanks for the pointers. My apologies for the double posting.
>>>>It looks like the fault is in AgentImpl.addEventListener() - It does not
>>>>add the listenerID.
>>>>
>>>>I have used my own method:
>>>>
>>>>private void addEventListener(String interfaceID, ICommandHandler
>>>>listener) throws InactiveAgentException, NotConnectedException
>>>>{
>>>> long listenerId = getAgentController().getNextContextId();
>>>>
>>>> getAgentController().getConnection().getContextMapper().addC ontext(listenerId,
>>>>listener);
>>>> StringBuffer cmd = new StringBuffer("");
>>>> cmd.append("<addEventListener
>>>>iid=\"org.eclipse.tptp.eventProvider\">");
>>>> cmd.append("<interfaceID>" + interfaceID + "</interfaceID>");
>>>> cmd.append("<listenerID>" + listenerId + "</listenerID>");
>>>> cmd.append("</addEventListener>");
>>>> ((IAgent)agent).sendCommand(cmd.toString(), null);
>>>>}
>>>>
>>>>and now it is working.
>>>>I also had to modify IAgentController.java and IConnection.java to get
>>>>access to the contextMapper, so it is a bit of a hack.
>>>>Do you know a better solution?
>>>>
>>>>David.
>>>>
>>>>
>>>>
>>>>Vishnu Naikawadi wrote:
>>>>
>>>>>David,
>>>>>
>>>>>I just responded to your original message. Attaching the same response
>>>>>below.
>>>>>
>>>>>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:dq64nn$le1$1@utils.eclipse.org...
>>>>>
>>>>>
>>>>>>I originally posted this as a reply to an old post (13Dec05) so I
>>>>>>think
>>>>>>it may have been missed.
>>>>>>Here it is again:
>>>>>>
>>>>>>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 send
>>>>>>
>>>>>>ing 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: Event handling - New Agent Controller [message #50981 is a reply to message #50947] |
Thu, 19 January 2006 20:39 |
Vishnu Messages: 19 Registered: July 2009 |
Junior Member |
|
|
Also, please run the AC with it's log configuration set to "DEBUG" so that
you get more info in the log file. After running the client, open the
tptpAgentCtlr.log file in the bin directory and do a search for
"listenerAccepted" string. If you can locate it in the log file, atleast we
know if the agent/AC is sending the response command.
Thanks
Vishnu
"Vishnu Naikawadi" <vishnu.naikawadi@intel.com> wrote in message
news:dqot27$ume$1@utils.eclipse.org...
> David,
>
> I have tested one more time doing similar things you are doing - like
> getAgent(), addEventListener() and run(), etc. But I didn't have any
> problem with getting the listenerAccepted response and I don't have any
> sleep before addEventListener call.
>
> Just to get more information, I have modified the AgentImpl.java a little
> bit to add a conditional check for listenerAccepted response command.
> Attaching the modified file and please run your test again to see what
> happens. While doing this test please remove the sleep you added in your
> program.
>
> But one thing to be noted is - since the client and AC/agent communication
> is asynchronous in nature, whenever there is a need to get the response
> for a command before going ahead with the execution and doing other
> things, we should wait and check for the expected response until we
> receive it. The best way to handle this is using semaphores, which is
> introduced in Java 1.5. We will probably implement this in future.
>
> Please try and let me know the result.
>
> Thanks
> Vishnu
>
> "David Read" <DavidRead@gmx.net> wrote in message
> news:dqmdkv$ib6$1@utils.eclipse.org...
>> Hi Vishnu,
>> Thank you - that works.
>> I'm still on the 4.1 build because my own code is still in development
>> (read flaky) and I didn't want any other unknowns, so I had to pull in
>> some other files to get agentImpl to compile.
>>
>> Have you noticed any timing/inconsistent behaviour with the Agent
>> Controller?
>>
>> I have had to introduce a delay before calling addEventListener,
>> otherwise the listenerAccepted message is not always returned.
>> I'm connecting to an embedded card, running Embedded XP on a Transmeta
>> processor @ 800Mhz, so it's a bit slower than most desktops but no
>> slouch.
>> After connecting to the Agent Controller, I start a process, which is not
>> processor intensive, then get the agent, send a command to it, which just
>> sets a local variable, then add the event listener.
>> If I don't sleep - currently 1 second - before addEventListener, then the
>> command is ignored.
>> I have checked - using Ethereal - that the command is actually being sent
>> out on the wire to the card, and it is a valid packet etc.
>> The Java client software is running on a 2.6GHz desktop.
>> Have you seen anything similar?
>> Here's some of the code:
>>
>>
>> agent =
>> (ICollector)agentController.getAgent("com.davidr.taed.SampleAgent ",
>>
>> "org.eclipse.tptp.platform.execution.client.agent.ICollector ");
>>
>> // Tell the agent which port to use to talk to the target
>> if (Constants.TPTP_DEBUG)
>> System.out.println("Sending setTargetPort command from " +
>> hostName);
>> int port = getExecutable().getListeningPort();
>> StringBuffer tempbuf = new StringBuffer("");
>> tempbuf.append("<setTargetPort
>> iid=\"com.davidr.taed.SampleAgent\">" + "<targetPort>"
>> + port + "</targetPort></setTargetPort>");
>> ((IAgent)agent).sendCommand(tempbuf.toString(), new
>> ICommandHandler()
>> {
>> public void incomingCommand(INode node, ICommandElement
>> command)
>> {
>> String commandStr = new
>> String(((CommandFragment)command).getCommandData());
>> System.out.println(hostName + " response to
>> setTargetPort: " + commandStr);
>> }
>> });
>>
>> try
>> {
>> Thread.sleep(1000);
>> }
>> catch (InterruptedException e)
>> {
>> // TODO Auto-generated catch block
>> e.printStackTrace();
>> }
>> if (Constants.TPTP_DEBUG)
>> System.out.println("Sending addEventListener from " +
>> hostName);
>>
>> ((IAgent)agent).addEventListener("com.davidr.taed.SampleAgentEvents ", new
>> ICommandHandler()
>> {
>> public void incomingCommand(INode node, ICommandElement
>> command)
>> {
>> String commandStr = new
>> String(((CommandFragment)command).getCommandData());
>> setEventData(commandStr);
>> if (Constants.TPTP_DEBUG)System.out.println(hostName +
>> " SampleAgentEvents - " + commandStr);
>> }
>> });
>>
>> }
>> if (Constants.TPTP_DEBUG) System.out.println(hostName + " Start
>> agent running");
>> agent.run();
>> //---------------------------------------------------------- --------------------------------
>>
>>
>> Vishnu Naikawadi wrote:
>>> David,
>>>
>>> The code for the modified API and implementation is checked-in today. It
>>> should be available in the next build. The new API is as below.
>>>
>>> public long addEventListener(String interfaceID, ICommandHandler
>>> listener) ;
>>> public void removeEventListener(String interfaceID, long listenerID) ;
>>>
>>> The addEventListener() method now returns the listenerID of the object
>>> being
>>> registered (listener passed as second parameter). This listenerID should
>>> be
>>> passed to removeEventListener() to remove the listener from getting the
>>> event notifications.
>>> Please try after you get the changes and let us know.
>>>
>>> Thanks
>>> Vishnu
>>>
>>> "Vishnu Naikawadi" <vishnu.naikawadi@intel.com> wrote in message
>>> news:dq8pt8$v0e$1@utils.eclipse.org...
>>>
>>>>David,
>>>>
>>>>Good to know that you got it to work. I have verified that the modified
>>>>API and implementation for event handling in Java client was not
>>>>checked-in during 4.1 release due to time constraints. This
>>>>implementation
>>>>will look similar to C++ implementation. So, you don't need to hack the
>>>>code. This code most probably will be checked-in today. I will let you
>>>>know once it is available.
>>>>
>>>>Thanks
>>>>Vishnu
>>>>
>>>>"David Read" <DavidRead@gmx.net> wrote in message
>>>>news:dq6pt9$pn6$1@utils.eclipse.org...
>>>>
>>>>>Hi Vishnu,
>>>>>Thanks for the pointers. My apologies for the double posting.
>>>>>It looks like the fault is in AgentImpl.addEventListener() - It does
>>>>>not
>>>>>add the listenerID.
>>>>>
>>>>>I have used my own method:
>>>>>
>>>>>private void addEventListener(String interfaceID, ICommandHandler
>>>>>listener) throws InactiveAgentException, NotConnectedException
>>>>>{
>>>>> long listenerId = getAgentController().getNextContextId();
>>>>>
>>>>> getAgentController().getConnection().getContextMapper().addC ontext(listenerId,
>>>>>listener);
>>>>> StringBuffer cmd = new StringBuffer("");
>>>>> cmd.append("<addEventListener
>>>>>iid=\"org.eclipse.tptp.eventProvider\">");
>>>>> cmd.append("<interfaceID>" + interfaceID + "</interfaceID>");
>>>>> cmd.append("<listenerID>" + listenerId + "</listenerID>");
>>>>> cmd.append("</addEventListener>");
>>>>> ((IAgent)agent).sendCommand(cmd.toString(), null);
>>>>>}
>>>>>
>>>>>and now it is working.
>>>>>I also had to modify IAgentController.java and IConnection.java to get
>>>>>access to the contextMapper, so it is a bit of a hack.
>>>>>Do you know a better solution?
>>>>>
>>>>>David.
>>>>>
>>>>>
>>>>>
>>>>>Vishnu Naikawadi wrote:
>>>>>
>>>>>>David,
>>>>>>
>>>>>>I just responded to your original message. Attaching the same response
>>>>>>below.
>>>>>>
>>>>>>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:dq64nn$le1$1@utils.eclipse.org...
>>>>>>
>>>>>>
>>>>>>>I originally posted this as a reply to an old post (13Dec05) so I
>>>>>>>think
>>>>>>>it may have been missed.
>>>>>>>Here it is again:
>>>>>>>
>>>>>>>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 send
>>>>>>>
>>>>>>>ing 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: Event handling - New Agent Controller [message #51037 is a reply to message #50981] |
Fri, 20 January 2006 00:28 |
David Read Messages: 35 Registered: July 2009 |
Member |
|
|
Hi Vishnu,
The change to AgentImpl works reliably. I have tried it five times and it always succeeded - it's a bit time consuming because I have to shut everything down to re-run - a limitation in my test harness.
I normally run with the AC logging set to DEBUG, because the output is sometimes useful, but previously I had tried setting it to SIMPLE in case it was affecting the processor loading, but this made no difference.
When I had it set to DEBUG, and before your latest change to AgentImpl, I did check that the addEventListener command was being sent to the AC, and it reliably was, but there was, most times, no listenerAccepted response listed in the log file. Perhaps 1 in 10 worked.
I should add that I also run an identical agent and exe on the host machine - the same machine the Java client runs on, and have never had any event listener problems.
So the result of your change is odd - because you have added a delay after sending the command. But no matter, thank you for the fix.
I probably ought to add some checking to my code to ensure the command is accepted anyway - I only do it once at initialisation time at present.
David.
Vishnu Naikawadi wrote:
> Also, please run the AC with it's log configuration set to "DEBUG" so that
> you get more info in the log file. After running the client, open the
> tptpAgentCtlr.log file in the bin directory and do a search for
> "listenerAccepted" string. If you can locate it in the log file, atleast we
> know if the agent/AC is sending the response command.
>
> Thanks
> Vishnu
>
> "Vishnu Naikawadi" <vishnu.naikawadi@intel.com> wrote in message
> news:dqot27$ume$1@utils.eclipse.org...
>
>>David,
>>
>>I have tested one more time doing similar things you are doing - like
>>getAgent(), addEventListener() and run(), etc. But I didn't have any
>>problem with getting the listenerAccepted response and I don't have any
>>sleep before addEventListener call.
>>
>>Just to get more information, I have modified the AgentImpl.java a little
>>bit to add a conditional check for listenerAccepted response command.
>>Attaching the modified file and please run your test again to see what
>>happens. While doing this test please remove the sleep you added in your
>>program.
>>
>>But one thing to be noted is - since the client and AC/agent communication
>>is asynchronous in nature, whenever there is a need to get the response
>>for a command before going ahead with the execution and doing other
>>things, we should wait and check for the expected response until we
>>receive it. The best way to handle this is using semaphores, which is
>>introduced in Java 1.5. We will probably implement this in future.
>>
>>Please try and let me know the result.
>>
>>Thanks
>>Vishnu
>>
>>"David Read" <DavidRead@gmx.net> wrote in message
>>news:dqmdkv$ib6$1@utils.eclipse.org...
>>
>>>Hi Vishnu,
>>>Thank you - that works.
>>>I'm still on the 4.1 build because my own code is still in development
>>>(read flaky) and I didn't want any other unknowns, so I had to pull in
>>>some other files to get agentImpl to compile.
>>>
>>>Have you noticed any timing/inconsistent behaviour with the Agent
>>>Controller?
>>>
>>>I have had to introduce a delay before calling addEventListener,
>>>otherwise the listenerAccepted message is not always returned.
>>>I'm connecting to an embedded card, running Embedded XP on a Transmeta
>>>processor @ 800Mhz, so it's a bit slower than most desktops but no
>>>slouch.
>>>After connecting to the Agent Controller, I start a process, which is not
>>>processor intensive, then get the agent, send a command to it, which just
>>>sets a local variable, then add the event listener.
>>>If I don't sleep - currently 1 second - before addEventListener, then the
>>>command is ignored.
>>>I have checked - using Ethereal - that the command is actually being sent
>>>out on the wire to the card, and it is a valid packet etc.
>>>The Java client software is running on a 2.6GHz desktop.
>>>Have you seen anything similar?
>>>Here's some of the code:
>>>
>>>
>>> agent =
>>>(ICollector)agentController.getAgent("com.davidr.taed.SampleAgent ",
>>>
>>>"org.eclipse.tptp.platform.execution.client.agent.ICollector ");
>>>
>>> // Tell the agent which port to use to talk to the target
>>> if (Constants.TPTP_DEBUG)
>>> System.out.println("Sending setTargetPort command from " +
>>>hostName);
>>> int port = getExecutable().getListeningPort();
>>> StringBuffer tempbuf = new StringBuffer("");
>>> tempbuf.append("<setTargetPort
>>>iid=\"com.davidr.taed.SampleAgent\">" + "<targetPort>"
>>> + port + "</targetPort></setTargetPort>");
>>> ((IAgent)agent).sendCommand(tempbuf.toString(), new
>>>ICommandHandler()
>>> {
>>> public void incomingCommand(INode node, ICommandElement
>>>command)
>>> {
>>> String commandStr = new
>>>String(((CommandFragment)command).getCommandData());
>>> System.out.println(hostName + " response to
>>>setTargetPort: " + commandStr);
>>> }
>>> });
>>>
>>> try
>>> {
>>> Thread.sleep(1000);
>>> }
>>> catch (InterruptedException e)
>>> {
>>> // TODO Auto-generated catch block
>>> e.printStackTrace();
>>> }
>>> if (Constants.TPTP_DEBUG)
>>> System.out.println("Sending addEventListener from " +
>>>hostName);
>>>
>>>((IAgent)agent).addEventListener("com.davidr.taed.SampleAgentEvents ", new
>>>ICommandHandler()
>>> {
>>> public void incomingCommand(INode node, ICommandElement
>>>command)
>>> {
>>> String commandStr = new
>>>String(((CommandFragment)command).getCommandData());
>>> setEventData(commandStr);
>>> if (Constants.TPTP_DEBUG)System.out.println(hostName +
>>>" SampleAgentEvents - " + commandStr);
>>> }
>>> });
>>>
>>> }
>>> if (Constants.TPTP_DEBUG) System.out.println(hostName + " Start
>>>agent running");
>>> agent.run();
>>> //---------------------------------------------------------- --------------------------------
>>>
>>>
>>>Vishnu Naikawadi wrote:
>>>
>>>>David,
>>>>
>>>>The code for the modified API and implementation is checked-in today. It
>>>>should be available in the next build. The new API is as below.
>>>>
>>>>public long addEventListener(String interfaceID, ICommandHandler
>>>>listener) ;
>>>>public void removeEventListener(String interfaceID, long listenerID) ;
>>>>
>>>>The addEventListener() method now returns the listenerID of the object
>>>>being
>>>>registered (listener passed as second parameter). This listenerID should
>>>>be
>>>>passed to removeEventListener() to remove the listener from getting the
>>>>event notifications.
>>>>Please try after you get the changes and let us know.
>>>>
>>>>Thanks
>>>>Vishnu
>>>>
>>>>"Vishnu Naikawadi" <vishnu.naikawadi@intel.com> wrote in message
>>>>news:dq8pt8$v0e$1@utils.eclipse.org...
>>>>
>>>>
>>>>>David,
>>>>>
>>>>>Good to know that you got it to work. I have verified that the modified
>>>>>API and implementation for event handling in Java client was not
>>>>>checked-in during 4.1 release due to time constraints. This
>>>>>implementation
>>>>>will look similar to C++ implementation. So, you don't need to hack the
>>>>>code. This code most probably will be checked-in today. I will let you
>>>>>know once it is available.
>>>>>
>>>>>Thanks
>>>>>Vishnu
>>>>>
>>>>>"David Read" <DavidRead@gmx.net> wrote in message
>>>>>news:dq6pt9$pn6$1@utils.eclipse.org...
>>>>>
>>>>>
>>>>>>Hi Vishnu,
>>>>>>Thanks for the pointers. My apologies for the double posting.
>>>>>>It looks like the fault is in AgentImpl.addEventListener() - It does
>>>>>>not
>>>>>>add the listenerID.
>>>>>>
>>>>>>I have used my own method:
>>>>>>
>>>>>>private void addEventListener(String interfaceID, ICommandHandler
>>>>>>listener) throws InactiveAgentException, NotConnectedException
>>>>>>{
>>>>>> long listenerId = getAgentController().getNextContextId();
>>>>>>
>>>>>> getAgentController().getConnection().getContextMapper().addC ontext(listenerId,
>>>>>>listener);
>>>>>> StringBuffer cmd = new StringBuffer("");
>>>>>> cmd.append("<addEventListener
>>>>>>iid=\"org.eclipse.tptp.eventProvider\">");
>>>>>> cmd.append("<interfaceID>" + interfaceID + "</interfaceID>");
>>>>>> cmd.append("<listenerID>" + listenerId + "</listenerID>");
>>>>>> cmd.append("</addEventListener>");
>>>>>> ((IAgent)agent).sendCommand(cmd.toString(), null);
>>>>>>}
>>>>>>
>>>>>>and now it is working.
>>>>>>I also had to modify IAgentController.java and IConnection.java to get
>>>>>>access to the contextMapper, so it is a bit of a hack.
>>>>>>Do you know a better solution?
>>>>>>
>>>>>>David.
>>>>>>
>>>>>>
>>>>>>
>>>>>>Vishnu Naikawadi wrote:
>>>>>>
>>>>>>
>>>>>>>David,
>>>>>>>
>>>>>>>I just responded to your original message. Attaching the same response
>>>>>>>below.
>>>>>>>
>>>>>>>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:dq64nn$le1$1@utils.eclipse.org...
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>>I originally posted this as a reply to an old post (13Dec05) so I
>>>>>>>>think
>>>>>>>>it may have been missed.
>>>>>>>>Here it is again:
>>>>>>>>
>>>>>>>>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 send
>>>>>>>>
>>>>>>>>ing 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?
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>
>>
>>
>
>
|
|
|
Goto Forum:
Current Time: Sat Nov 09 01:02:33 GMT 2024
Powered by FUDForum. Page generated in 0.03719 seconds
|