Handling Delegate Events

Delegate events allow you to keep track of which delegates (presenters and representatives) are currently connected to and available in the environment. Each delegate is represented by its address card as well as an HTML script for an iconographic display in the environment's interface.

a. Initialization This example suggest the use of a vector to store and maintain the delegates information. Upon requesting the current delegates (AllAgents) from the mediator service, the resulting vector can be used for initialization:
    this.delegates = (Vector) request.result(); See here for more information on how to handle requests and their results, and on the mediator service requests in particular.

b. Delegate events The source of a delegate event is always the delegate. In the case of an ENTERS event, the object of the event is the delegate's script. The following method handles all delegate events and updates the vector accordingly:

public void handleAgentEvent(Event event) {
    // make sure the delegates vector has been
    //   initialized
    if (this.delegates == null) return;

    switch (event.type) {
    case Event.ENTERS:
	Object[] tuple = new Object[2];
        // the tuple's first element contains the
        //   delegate's address card
	tuple[0] = event.source;
        // the tuple's second element contains the
        //   delegate's script
	tuple[1] = event.object;

	this.delegates.addElement(tuple);
	break;
    case Event.LEAVES:
        // find and remove the delegate's information
        //   from the vector
        for (int i = 0; i < this.delegates.size(); i++)
            if (event.source.equals(((Object[])
                   this.delegates.elementAt(i))[0])) {
               this.delegates.removeElementAt(i);
               break;
            }
	break;
    }
}


Last modified on 5 May 1999 by Rudi Stouffs

This website has been archived and is no longer maintained.