RAD Event Handling in Java
This example shows how to subscribe and handle events. The ZoneManager instance defines a stateChange event, which clients can subscribe for information about changes in the runtime state of a zone.
Example 2-28 Java Language – Subscribing to and Handling RAD Events
import com.oracle.solaris.rad.client.ADRName;
import com.oracle.solaris.rad.client.RadEvent;
import com.oracle.solaris.rad.client.RadEventHandler;
import com.oracle.solaris.rad.connect.Connection;
import com.oracle.solaris.rad.zonemgr.*;
ZoneManager zmgr = con.getObject(new ZoneManager());
con.subscribe(zmgr, "statechange", new StateChangeHandler());
Thread.currentThread().sleep(100000000);
class StateChangeHandler extends RadEventHandler {
public void handleEvent(RadEvent event, Object payload) {
StateChange obj = (StateChange) payload;
System.out.printf("Event: %s", event.toString());
System.out.printf("\tcode: %s\n", obj.getZone());
System.out.printf("\told: %s\n", obj.getOldstate());
System.out.printf("\tnew: %s\n", obj.getNewstate());
}
}
To handle an event, implement the RadEventInterface class. The com.oracle.solaris.rad.client package provides a default implementation (RadEventHandler) with limited functions. This class can be extended to provide additional event handling logic as in the example above.
In this example, you have subscribed to a single event by passing a handler and a reference to the ZoneManager object. The handler is invoked asynchronously by the framework with various event details and provided the user data.