FileDocCategorySizeDatePackage
TopologyMonitorService.javaAPI DocJBoss 4.2.19480Fri Jul 13 20:52:38 BST 2007org.jboss.ha.framework.server.util

TopologyMonitorService

public class TopologyMonitorService extends org.jboss.system.ServiceMBeanSupport implements TopologyMonitorServiceMBean, org.jboss.ha.framework.interfaces.HAPartition.AsynchHAMembershipListener
A cluster parition membership monitor. It can be used to view how the nodes in a cluster are seeing the topology change using either email or a centralized log server. To use this to send email on change notifications use the following log4j.xml fragments: You can also have this service notify another MBean of the change to perform arbitrary checks by specifying the MBean name as the TriggerServiceName attribute value. This MBean must have an operation with the following signature:
param: removed ArrayList of nodes that were removed
param: added ArrayList of nodes that were added
param: members ArrayList of nodes currently in the cluster
param: logCategoryName the log4j category name used by the
TopologyMonitorService. This should be used for logging to integrate with
the TopologyMonitorService output.
public void membershipChanged(ArrayList deadMembers, ArrayList newMembers,
ArrayList allMembers, String logCategoryName)
author
Scott.Stark@jboss.org
version
$Revision: 57188 $

Fields Summary
private static final String
CHANGE_NAME
private static Logger
changeLog
private String
partitionName
private org.jboss.ha.framework.interfaces.HAPartition
partition
private String
hostname
private ObjectName
triggerServiceName
Constructors Summary
public TopologyMonitorService()


    
   
   
Methods Summary
public java.util.VectorgetClusterNodes()

      Vector view = null;
      try
      {
         InitialContext ctx = new InitialContext();
         String jndiName = "/HAPartition/" + partitionName;
         HAPartition partition = (HAPartition) ctx.lookup(jndiName);
         view = partition.getCurrentView();
      }
      catch(Exception e)
      {
         log.error("Failed to access HAPartition state", e);
      }
      return view;
   
private org.jboss.ha.framework.server.util.TopologyMonitorService$AddressPortgetMemberAddress(java.lang.Object addr)
Use reflection to access the address InetAddress and port if they exist in the Address implementation

      AddressPort info = null;
      try
      {
         org.jboss.ha.framework.interfaces.ClusterNode node =
               (org.jboss.ha.framework.interfaces.ClusterNode)addr;

         InetAddress inetAddr = node.getOriginalJGAddress().getIpAddress();
         Integer port = new Integer(node.getOriginalJGAddress().getPort());
         info = new AddressPort(inetAddr, port);
      }
      catch(Exception e)
      {
         log.warn("Failed to obtain InetAddress/port from addr: "+addr, e);
      }
      return info;
   
public java.lang.StringgetPartitionName()

      return partitionName;
   
public javax.management.ObjectNamegetTriggerServiceName()

      return triggerServiceName;
   
public voidmembershipChanged(java.util.Vector deadMembers, java.util.Vector newMembers, java.util.Vector allMembers)
Called when a new partition topology occurs.

param
deadMembers A list of nodes that have died since the previous view
param
newMembers A list of nodes that have joined the partition since the previous view
param
allMembers A list of nodes that built the current view

      MDC.put("RegexEventEvaluator", "End membershipChange.*");
      ArrayList removed = new ArrayList();
      ArrayList added = new ArrayList();
      ArrayList members = new ArrayList();
      changeLog.info("Begin membershipChanged info, hostname="+hostname);
      changeLog.info("DeadMembers: size="+deadMembers.size());
      for(int m = 0; m < deadMembers.size(); m ++)
      {
         AddressPort addrInfo = getMemberAddress(deadMembers.get(m));
         removed.add(addrInfo);
         changeLog.info(addrInfo);
      }
      changeLog.info("NewMembers: size="+newMembers.size());
      for(int m = 0; m < newMembers.size(); m ++)
      {
         AddressPort addrInfo = getMemberAddress(newMembers.get(m));
         added.add(addrInfo);
         changeLog.info(addrInfo);
      }
      changeLog.info("AllMembers: size="+allMembers.size());
      for(int m = 0; m < allMembers.size(); m ++)
      {
         AddressPort addrInfo = getMemberAddress(allMembers.get(m));
         members.add(addrInfo);
         changeLog.info(addrInfo);
      }
      // Notify the trigger MBean
      if( triggerServiceName != null )
      {
         changeLog.info("Invoking trigger service: "+triggerServiceName);
         try
         {
            Object[] params = {removed, added, members, CHANGE_NAME};
            String[] sig = {"java.util.ArrayList", "java.util.ArrayList",
               "java.util.ArrayList", "java.lang.String"};
            server.invoke(triggerServiceName, "membershipChanged", params, sig);
         }
         catch(Throwable t)
         {
            changeLog.error("Failed to notify trigger service: "+triggerServiceName, t);
            log.debug("Failed to notify trigger service: "+triggerServiceName, t);
         }
      }
      changeLog.info("End membershipChanged info, hostname="+hostname);
      MDC.remove("RegexEventEvaluator");
   
public voidsetPartitionName(java.lang.String name)

      this.partitionName = name;
   
public voidsetTriggerServiceName(javax.management.ObjectName triggerServiceName)

      this.triggerServiceName = triggerServiceName;
   
protected voidstartService()

      InitialContext ctx = new InitialContext();
      String partitionJndiName = "/HAPartition/" + partitionName;
      partition = (HAPartition) ctx.lookup(partitionJndiName);
      // Register as a listener of cluster membership changes
      partition.registerMembershipListener(this);
      log.info("Registered as MembershipListener");
      try
      {
         hostname = InetAddress.getLocalHost().getHostName();
      }
      catch(IOException e)
      {
         log.warn("Failed to lookup local hostname", e);
         hostname = "<unknown>";
      }
   
protected voidstopService()

      partition.unregisterMembershipListener(this);