Differences between revisions 23 and 24
Deletions are marked like this. Additions are marked like this.
Line 18: Line 18:
root at: "colourEvent" put: template. root at: "colourevent" put: template.
Line 29: Line 29:
root/colourEvent create: #( "red" 35 ). root/colourevent create: #( "red" 35 ).
Line 62: Line 62:
myObj mkEvent: root/colourEvent. myObj mkEvent: root/colourevent.

Ponder2 Events

Events are generated from Event Templates which describe the attribute values that a particular event should carry with it. An Event Template is created from the Event Factory. An Event Template is the specification of a particular event with named arguments. Instances of the Event Template are created and then picked up by Policies that have "subscribed" to that particular Event Template.

The Event Factory is generally located at /factory/event. An Event Template is created by sending the event factory a create command with an array of attribute names that the event will carry.

An event can be generated using PonderTalk by sending the event template a create command with an array of values, one per expected attribute, in the correct order. A Java Managed object can also create events using the operation method on the event template managed object.

Example

To create an Event Template called /event/testevent that has two arguments, colour and intensity, we can use the following PonderTalk:

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

We can now create and send an event of this type. If sending an event using PonderTalk you can do one of the following:

   1 // If the variable "template" is still in context.
   2 template create: #( "red" 35 ).
   3 
   4 // Can be used at any time
   5 root/colourevent create: #( "red" 35 ).

This will create an event and dispatch it into the system where it will be handed to the appropriate policies.

As can be seen in the documentation at http://www.ponder2.net/doc/pondertalk/EventTemplate.html an event can be created from a Hash. The following examples generate the same event as the one above.

   1 template fromHash: #( "intensity" 35 "colour" "red" ) asHash.

   1 hash := #() asHash.
   2 hash at: "colour" put: "red".
   3 hash at: "intensity" put: 35.
   4 template fromHash: hash.

If creating an event from a Managed Object, the create message is sent in the normal way:

   1 @Ponder2op("mkEvent:")
   2 protected void makeEvent(P2Object source, P2Object anEventTemplate) {
   3     anEventTemplate.operation(source, "create:",
   4       P2Object.create(P2Object.create("red"), P2Object.create(35)));
   5 }

If the above object has been instantiated as myObj, the following PonderTalk can be used:

   1 myObj mkEvent: root/colourevent.

This will create an event and dispatch it into the system where it will be handed to the appropriate policies.

Note: For the event to be propagated properly, the managed object (myObj in this case) must be a member of a domain in the domain hierarchy. See Ponder2EventBus for more details.

Other methods of introducing events into the system are described in Ponder2SendingEvents.


Ponder2Events (last edited 2008-08-05 17:05:11 by KevinTwidle)