Status Information
Status Information
Firstly, in order to detect that a cluster node has
been created, one has to observer the realm to which
you are connected. When the realm is added to a cluster,
the Observer/Observable mechanism will notify you of
the cluster creation.
As well as impementing the Observer interface to detect
new clusters, there is an interface that can be used
to be notified of specific cluster events when clusters
already exist. This interface is the nClusterEventListener.
The interface defines various methods that enable your
program to receive callbacks for specific cluster events.
When the status changes for a cluster node, this will
trigger an callback on any known listeners of the nClusterNode.
For example, when you have constructed your nRealmNode,
if your class implements the nClusterEventListener interface,
then we can do the following:
realm.addObserver(this);
nClusterNode cluster = realm.getCluster();
if (cluster != null) {
cluster.addListener(this);
}
If the realm is not part of a cluster, then the getCluster()
method will return null. However, by adding an observer
to the realm, if a cluster is created that contains
the realm you are connected to, the update() method
of the Observer implementation will notify you that
a cluster has been created. For example, the following
code demonstrates how to detect if a cluster has been
created with the realm you are connected to as a member:
public void update(Observable o, Object arg)
{
if (arg instanceof nClusterNode) {
System.out.println("New cluster formed,
name = "+( (nClusterNode)arg).getName());
((nClusterNode)arg).addListener(this);
}
}
For more information on how to monitor
cluster nodes programatically please see the example.
For more information on how to monitor
cluster nodes using the enterprise manager please
see the enterprise manager guide.
For more information on Nirvana Administration, please
see the API
documentation, and the administrator
guide. |