Inspirel banner

Programming Distributed Systems with YAMI4

6.2.3 Java

In Java the message handler has to be an instance of the user-defined class that implements the IncomingMessageCallback interface. This interface is defined to have only a single call() function, where the actual message processing takes place.

An example message handler can be implemented in the following way:

import com.inspirel.yami.IncomingMessage;
import com.inspirel.yami.IncomingMessageCallback;

// ...
class MyObjectImplementation
    implements IncomingMessageCallback {

    @Override
    public void call(IncomingMessage message) throws Exception {
        // code processing the incoming message
        // ...
    }
}

and the registration can look like:

MyObjectImplementation myObject = new MyObjectImplementation();
myAgent.registerObject("my_object", myObject);