Sending Ponder2 Events

Once an Event Template has been created, an event can be generated from a stand-alone application, a direct Java call, a Java RMI call, a Web Service call, from directly executed SMC XML or from the command-line shell.

Example Event

The following descriptions of sending events use this event definition. The event contains a colour and an intensity as attributes.

   1 template := root/factory/event create: #( "colour" "intensity" )
   2 root/event at: "colourevent" put: template.

Stand-Alone Application

An event can be generated in the SMC using a simple application embedded within the Ponder2 Jar file. This application uses RMI to make a call to the receiving SMC and it sends an arbitrary PonderTalk string. The execution takes the format:

java -classpath ponder2.jar net.ponder2.PonderTalk RMIname PonderTalk statements.

where ... indicates many Jar files and one or more optional arguments. You must have as many arguments as the event in question was defined with. This example expects that a PonderTalk managed object has been started and added to the domain hierarchy.

java -classpath ponder2.jar net.ponder2.PonderTalk //localhost/MyPonder2 'root/event/colourevent #( "red" 53 ).'

The result will be printed out. If something goes wrong then the command will exit with a return code of 1 and will print a short error message. Remember to escape (\") the quotes if you are using a Unix shell.

Java Call

If the SMC is running in the same VM as your Java application then you can create the above event with a direct method call again using PonderTalk:

   1 String p2xml = P2Compiler.parse("root/event/colourevent create: #( \"red\" 53 ).");
   2 return new XMLParser().execute(SelfManagedCell.RootDomain, p2xml);

The first argument to execute() is the source or creator managed object of the compiled XML i.e. the object that is sending the create message to the colourevent managed object. The source managed object is needed by event creation because the event is actually sent by that object. If you don't have an object that you want to use to send the event then the root domain SelfManagedCell.RootDomain may be specified, as in the example above.

Java RMI

If the SMC is running within another VM on the same or different machine then RMI may be used to send an event. This method uses the PonderTalk managed object which will compile and execute PonderTalk. If there is anything wrong an exception will be thrown.

First the target SMC must create an instance of a PonderTalk managed object with an RMI name to be registered (we assume that rmiregistry is already running):

   1 pondertalk := root load: "PonderTalk".
   2 root/factory at: PonderTalk" put: pondertalk.
   4 // Create an instance waiting on the RMI port MyPonder2
   5 pondertalk := root/factory/PonderTalk create: "MyPonder2".
   6 // The managed object *must* be put into a domain otherwise events will not be sent
   7 root at: "pondertalk" put: pondertalk.

To create the test event described above, the following Java code snippet can be used:

   1 import net.ponder2.Ponder2Interface;
   3 ...
   4 String rmiName = "//localhost/MyPonder2";
   5 String ponderTalk =  "root/event/colourevent create: #( \"red\" 53 ).";
   6 String result;
   7 try {
   8     PonderTalkInterface pt = (PonderTalkInterface)Naming.lookup(rmiName);
   9     result = pt.execute(ponderTalk);
  10 }
  11 catch (Exception e) {
  12     System.out.println("An error has occurred: " + e.getMessage());
  13 }

The RMI method definition is

   1 public String execute(String ponderTalk) throws RemoteException;

Web Service

<This section is out of date >

Ponder2 can have an event sent to it using a Web Service call. The arguments are the port number that the SMC was started at, the event name and a sequence of string arguments. See the WSDL for more information.

   <wsdl:message name="eventRequest">
      <wsdl:part name="port" type="xsd:int"/>
      <wsdl:part name="eventName" type="xsd:string"/>
      <wsdl:part name="args" type="impl:ArrayOf_xsd_string"/>

Command Line Shell

After starting the SMC and observing the port number that it has started at, you can telnet to the SMC and access its shell command module. The following SMC output shows it starting at socket 13571

Shell: trying port 13570
Shell: trying port 13571
Shell port 13571 ready

So, to access this SMC enter the following telnet command in a new terminal window:

$ telnet localhost 13571

The shell may look a little like a Unix shell but it is not as sophisticated. You can now create events by typing (to the SMC shell)

$ event root/event/colourevent red 53

As a shorthand simplification the root/event/ may be omitted, however if the event type is in any other domain, the full path name must be used. You can only send simple arguments without spaces using this method. It is useful for quick testing.

For more complex arguments, PonderTalk can be used:

$ root/event/colourevent create: #( "red" 53 ).

Ponder2SendingEvents (last edited 2009-02-12 17:35:55 by KevinTwidle)