public Cluster getCluster(String serverName, String hostName, boolean loadMembers) throws Exception {
Cluster cluster = null;
MBeanServer mBeanServer = new Registry().getMBeanServer();
ObjectName membershipOName = new ObjectName(serverName +":type=ClusterMembership,host=" + hostName);
ObjectName receiverOName = new ObjectName(serverName +":type=ClusterReceiver,host=" + hostName);
ObjectName senderOName = new ObjectName(serverName +":type=ClusterSender,host=" + hostName);
//
// should be just one set, this is just to find out if this instance
// is cluster-enabled and the cluster supports JMX
//
Set clusters = mBeanServer.queryMBeans(new ObjectName("*:type=Cluster,host=" + hostName), null);
Set membership = mBeanServer.queryMBeans(membershipOName, null);
if (clusters != null && clusters.size() > 0 && membership != null && membership.size() > 0) {
ObjectName clusterOName = ((ObjectInstance) clusters.iterator().next()).getObjectName();
cluster = new Cluster();
cluster.setName(JmxTools.getStringAttr(mBeanServer, clusterOName, "clusterName"));
cluster.setInfo(JmxTools.getStringAttr(mBeanServer, clusterOName, "info"));
cluster.setManagerClassName(JmxTools.getStringAttr(mBeanServer, clusterOName, "managerClassName"));
cluster.setMcastAddress(JmxTools.getStringAttr(mBeanServer, membershipOName, "mcastAddr"));
cluster.setMcastBindAddress(JmxTools.getStringAttr(mBeanServer, membershipOName, "mcastBindAddress"));
cluster.setMcastClusterDomain(JmxTools.getStringAttr(mBeanServer, membershipOName, "mcastClusterDomain"));
cluster.setMcastDropTime(JmxTools.getLongAttr(mBeanServer, membershipOName, "mcastDropTime"));
cluster.setMcastFrequency(JmxTools.getLongAttr(mBeanServer, membershipOName, "mcastFrequency"));
cluster.setMcastPort(JmxTools.getIntAttr(mBeanServer, membershipOName, "mcastPort"));
cluster.setMcastSoTimeout(JmxTools.getIntAttr(mBeanServer, membershipOName, "mcastSoTimeout"));
cluster.setMcastTTL(JmxTools.getIntAttr(mBeanServer, membershipOName, "mcastTTL"));
cluster.setTcpListenAddress(JmxTools.getStringAttr(mBeanServer, receiverOName, "tcpListenAddress"));
cluster.setTcpListenPort(JmxTools.getIntAttr(mBeanServer, receiverOName, "tcpListenPort"));
cluster.setNrOfMsgsReceived(JmxTools.getLongAttr(mBeanServer, receiverOName, "nrOfMsgsReceived"));
cluster.setTotalReceivedBytes(JmxTools.getLongAttr(mBeanServer, receiverOName, "totalReceivedBytes"));
// cluster.setTcpSelectorTimeout(getLongAttr(mBeanServer, receiverOName, "tcpSelectorTimeout"));
// cluster.setTcpThreadCount(getIntAttr(mBeanServer, receiverOName, "tcpThreadCount"));
cluster.setSenderAckTimeout(JmxTools.getLongAttr(mBeanServer, senderOName, "ackTimeout"));
cluster.setSenderAutoConnect(((Boolean) mBeanServer.getAttribute(senderOName, "autoConnect")).booleanValue());
cluster.setSenderFailureCounter(JmxTools.getLongAttr(mBeanServer, senderOName, "failureCounter"));
cluster.setSenderNrOfRequests(JmxTools.getLongAttr(mBeanServer, senderOName, "nrOfRequests"));
cluster.setSenderReplicationMode(JmxTools.getStringAttr(mBeanServer, senderOName, "replicationMode"));
cluster.setSenderTotalBytes(JmxTools.getLongAttr(mBeanServer, senderOName, "totalBytes"));
if (loadMembers) {
ObjectName senders[] = (ObjectName[]) mBeanServer.getAttribute(senderOName, "senderObjectNames");
for (int i = 0; i < senders.length; i++) {
ClusterSender sender;
if ("pooled".equals(cluster.getSenderReplicationMode())) {
sender = new PooledClusterSender();
} else if ("synchronous".equals(cluster.getSenderReplicationMode())) {
sender = new SyncClusterSender();
} else if ("asynchronous".equals(cluster.getSenderReplicationMode()) ||
"fastasyncqueue".equals(cluster.getSenderReplicationMode())) {
sender = new AsyncClusterSender();
} else {
sender = new ClusterSender();
}
ObjectName localSenderOName = senders[i];
sender.setAddress(JmxTools.getStringAttr(mBeanServer, localSenderOName, "address"));
sender.setPort(JmxTools.getIntAttr(mBeanServer, localSenderOName, "port"));
sender.setAvgMessageSize(JmxTools.getLongAttr(mBeanServer, localSenderOName, "avgMessageSize", -1));