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

PingJndi

public class PingJndi extends org.jboss.system.ServiceMBeanSupport implements PingJndiMBean
A utility MBean that can be used as the trigger target of the TopologyMonitorService to probe the state of JNDI on the cluster nodes.
author
Scott.Stark@jboss.org
version
$Revision: 57188 $

Fields Summary
private String
urlPrefix
private String
urlSuffix
private String
urlPattern
private String[]
lookupNames
Constructors Summary
Methods Summary
private voiddoLookups(java.util.Hashtable localEnv, org.jboss.logging.Logger tmsLog, java.util.ArrayList nodes)

      for(int n = 0; n < nodes.size(); n ++)
      {
         AddressPort addrInfo = (AddressPort) nodes.get(n);
         String providerURL = urlPrefix + addrInfo.getHostName() + urlSuffix;
         Hashtable env = new Hashtable(localEnv);
         env.put(Context.PROVIDER_URL, providerURL);
         tmsLog.info("Checking names on: "+addrInfo);
         try
         {
            InitialContext ctx = new InitialContext(env);
            for(int s = 0; s < lookupNames.length; s ++)
            {
               String name = lookupNames[s];
               Object value = ctx.lookup(name);
               tmsLog.info("lookup("+name+"): "+value);
            }
         }
         catch(Exception e)
         {
            tmsLog.error("Failed lookups on: "+addrInfo, e);
         }
      }
   
public java.lang.String[]getLookupNames()
Get the names of JNDI bindings that should be queried on each host

return
the array of target names to test
jmx:managed-attribute

      return lookupNames;
   
public java.lang.StringgetProviderURLPattern()
Get the Context.PROVIDER_URL regular expression.

return
the regular expression containing the host, for example 'jnp://(host):1099/'
jmx:managed-attribute

      return urlPattern;
   
public voidmembershipChanged(java.util.ArrayList removed, java.util.ArrayList added, java.util.ArrayList members, java.lang.String logCategoryName)
The TopologyMonitorService trigger callback operation.

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 is used for logging to integrate with the TopologyMonitorService output.

      log.debug("membershipChanged");
      Logger tmsLog = Logger.getLogger(logCategoryName);
      Hashtable localEnv = null;
      try
      {
         InitialContext localCtx = new InitialContext();
         localEnv = localCtx.getEnvironment();
      }
      catch(NamingException e)
      {
         tmsLog.error("Failed to obtain InitialContext env", e);
         return;
      }

      tmsLog.info("Checking removed hosts JNDI binding");
      doLookups(localEnv, tmsLog, removed);
      tmsLog.info("Checking added hosts JNDI binding");
      doLookups(localEnv, tmsLog, added);
      tmsLog.info("Checking members hosts JNDI binding");
      doLookups(localEnv, tmsLog, members);
   
public voidsetLookupNames(java.lang.String[] names)
Set the names of JNDI bindings that should be queried on each host

param
names
jmx:managed-attribute

      this.lookupNames = names;
   
public voidsetProviderURLPattern(java.lang.String regex)
Set the regular expression containing the hostname/IP address of the JNDI provider. This expression is used to build the JNDI Context.PROVIDER_URL for each node in the cluster. The expression should contain a "(host)" component that will be replaced with the cluster node hostname.

param
regex the regular expression containing the host, for example 'jnp://(host):1099/'
jmx:managed-attribute

      this.urlPattern = regex;
      this.urlPrefix = regex;
      this.urlSuffix = "";
      String hostExp = "{host}";
      int hostIndex = regex.indexOf(hostExp);
      if( hostIndex >= 0 )
      {
         urlPrefix = regex.substring(0, hostIndex);
         int endIndex = hostIndex + hostExp.length();
         urlSuffix = regex.substring(endIndex);
      }