next up previous contents
Next: Connector object Up: Library usage Previous: Message object   Contents

MessageListener interface

Figure 3.2: MessageListener interface
\includegraphics{images/java_listener.eps}

The MessageListener interface is the template of the incoming message handler object that must be implemented by the programmer. An incoming message causes the callback of the processIncomingMessage() method of MessageListener. The message arrived is passed to this method eventually with a reference to a user-define object.

The user-defined object can be used to share informations between the user application and the OPENMAIA connector library. The source of this reference is set by the programmer during the instantiation of the Connector object.

The main reference is set by the programmer using the Connector object.

An example that shows how to use MessageListener is reported here.

public class MyListener implements MessageListener {

  public void processIncomingMessage(Message m, Object o) {
    // put the code to handle message here.
    System.out.println("Command: " + m.getCommand());
    // user-define object must be casted before use, for example
    MyObject myo = (MyObject) o;
    myo.myMethod();
  }
}



2005-07-12