External Communications

One of the reasons for using Ponder2 is to provide a policy framework for other, unrelated applications. This means that Ponder2 has to receive information from other applications in order to make its decisions and to communicate those decisions back to the application.

Sending Information

Receiving Information

Information can come into the Ponder2 SMC as either Events or Commands

Receiving Events

Receiving Commands

There is a useful Managed Object called PonderTalk which accepts PonderTalk statements either as arguments or over an RMI connection that it maintains. Documentation can be found in the Ponder2 release tree at doc/pondertalk/PonderTalk.html.


Simple RMI Example

The PonderTalk managed object can easily be used to send and receive PonderTalk commands from external sources via RMI. First the PonderTalk module must be set up to listen to an RMI port, in this case we are using one called "MyPonder2".

   1 factory := root load: "PonderTalk".
   2 pt := factory create: "MyPonder2".

The RMI connection can be tested internally with the following. You should see "This is a test" written to the console.

   1 pt test: "root print: \"This is a test\"".

Now we can try it from afar, as far as a shell anyway. To a shell prompt enter

$ java -cp lib/ponder2.jar net.ponder2.PonderTalk 'root print: "Hello, World!".'

you should see Hello, World! printed out on the Ponder2 console.

The RMI execute interface used takes a simple string, this is an extract from the PonderTalkInterface class. The proper one from the ponder2.jar file should be used - net.ponder2.PonderTalkInterface.

   1 public interface PonderTalkInterface extends Remote {
   3   /**
   4    * Takes a PonderTalk string, compiles and executes it. Returns the result as
   5    * a string.
   6    *
   7    * @param ponderTalk
   8    *            a string containing one or more PonderTalk statements separated
   9    *            by full-stops (periods).
  10    * @return the result of the operation as a string
  11    * @throws RemoteException
  12    *             if something goes wrong
  13    */
  14   public String execute(String ponderTalk) throws RemoteException;
  15   ...
  16   ...
  17 }

The code used in the PonderTalk main to send the RMI message is copied below and can be incorporated into your external Java code.

   1   public static void main(String args[]) {
   2       String result;
   3       boolean ok = true;
   4       if (args.length < 2)
   5           System.out.println("Too few arguments. Need: RMIname pondertalk statement.");
   6       String rmiName = args[0];
   7       String ponderTalk = "";
   8       for (int i = 1; i < args.length; i++) {
   9           ponderTalk += " " + args[i];
  10       }
  11       try {
  12           PonderTalkInterface pt = (PonderTalkInterface) Naming.lookup(rmiName);
  13           result = pt.execute(ponderTalk);
  14       }
  15       catch (Exception e) {
  16           result = "Remote PonderTalk failure: " + e.getMessage();
  17           ok = false;
  18       }
  19       System.out.println(result);
  20       System.exit(ok ? 0 : 1);
  21   }

For a comprehensive description of using external communications see thexmlBlasterexample.

ExternalCommunications (last edited 2008-09-23 13:03:36 by KevinTwidle)