Sending PonderTalk to the Ponder2 SMC

PonderTalk can be sent to the SMC from a stand-alone application, from a direct Java call, a Java RMI call, a Web Service call or from the Ponder2 Shell.

Stand-Alone Application

PonderTalk can be sent to a Ponder2 SMC from a separate application which can be found in the Ponder2 Jar file. This application uses Web Services to make the call so the receiving Ponder2 instance must have already been set up to use Web Services. The execution takes the format:

java -classpath ponder2.jar:ponder2comms.jar... net.ponder2.comms.RemotePonderTalkClient URL execute [file]

where ... indicates many Jar files, the file argument is optional, don't include the "[: and :and ]" characters. If a file name is given, that files is read and is sent to the SMC. If a file name is not included then the PonderTalk for the command is taken from standard input. See examples below. This example expects that a Ponder2 SMC has been started as detailed in communications with Web Services.

There are two basic commands available, one to send XML to Ponder2 and one to send an Event to Ponder2. First we will send some XML through to create an event and a policy, then we will send an event to trigger the policy.

The library setup is a little complicated so scripts have been included to facilitate the use of this method. On Windows the p2send.bat script can be used and on Unix/Mac OS the shell script p2send is available. So, to setup an Event and a Policy and to send such an event we could execute:

p2send execute p2example/testsetup.p2
p2send execute < p2example/sendevent.p2

The second example uses standard input instead of a file. If something goes wrong then p2send will exit with a return code of 1 and will print a short error message.

NB. The above assumes that you are using a URL of http://localhost:8080/axis/Ponder2.jws, if this is not the case then the file pssend or pssend.bat must be edited.

Java Call

If Ponder2 is running in the same VM as your Java application then you can send a PonderTalk string with the call:

   1 String p2xml = P2Compiler.parse(ponderTalkString);
   2 P2Object value = new XMLParser().execute(SelfManagedCell.RootDomain, p2xml);

This call returns a PonderTalkException if there is an error .

Java RMI

If the Ponder2 SMC is running within another VM on the same or different machine then RMI may be used to send PonderTalk to be executed. This is acheived by starting a PonderTalk managed object inside the SMC and then sending it the PonderTalk text. The PonderTalk managed object can be started within the SMC by:

   1 factory := root load: "PonderTalk".
   2 ptalk := factory create: "P2RMI".

PonderTalk strings may now be sent to rmi://localhost/P2RMI. There are three calls available one to compile the PonderTalk and return the compiled, internal XML as a string, one to execute internal XML and one to compile and execute the PonderTalk in one go. The calls look like:

Compile and Execute a PonderTalk string

   1 PonderTalkInterface pt = (PonderTalkInterface)Naming.lookup("rmi://localhost/P2RMI");
   2 P2Object result = pt.execute(aPonderTalkString);

Compile a PonderTalk string, return anXmlString

   1 PonderTalkInterface pt = (PonderTalkInterface)Naming.lookup("rmi://localhost/P2RMI");
   2 String anXmlString = pt.compile(aPonderTalkString);

Execute a pre-compiled PonderTalk XML string

   1 PonderTalkInterface pt = (PonderTalkInterface)Naming.lookup("rmi://localhost/P2RMI");
   2 P2Object result = pt.executeXML(anXmlString);

Method Definitions

The RMI method definitions are

   1 public String execute(String ponderTalk) throws RemoteException;
   2 public String compile(String ponderTalk) throws RemoteException;
   3 public String executeXML(String xml) throws RemoteException;

Web Service

Ponder2 can have XML commands and events sent to it using Web Service calls via Ponder2.jws. The Java signatures are shown here but if you use a different language you must refer to the Ponder2 WSDL.

To execute XML use the Web Service call execute with the signature:

   1 public String execute(String xmlMessage)


   1 execute("<use name=\"...\"><more xml=\"ok\"/></use>");

To send an event into the SMC use the Web Service call event with the signature:

   1 public String event(String eventName, String[] args)


   1 event("/Event/ReputationChange", "Fred", 55, 25, "Leave Now");

ExecutingPonderTalk (last edited 2008-02-10 10:08:20 by KevinTwidle)