1 22 package org.jboss.ha.framework.server.util; 23 24 import java.util.ArrayList ; 25 import java.util.Hashtable ; 26 27 import javax.naming.InitialContext ; 28 import javax.naming.NamingException ; 29 import javax.naming.Context ; 30 31 import org.jboss.system.ServiceMBeanSupport; 32 import org.jboss.logging.Logger; 33 import org.jboss.ha.framework.server.util.TopologyMonitorService.AddressPort; 34 35 41 public class PingJndi extends ServiceMBeanSupport 42 implements PingJndiMBean 43 { 44 private String urlPrefix; 45 private String urlSuffix; 46 private String urlPattern; 47 private String [] lookupNames; 48 49 53 public String [] getLookupNames() 54 { 55 return lookupNames; 56 } 57 61 public void setLookupNames(String [] names) 62 { 63 this.lookupNames = names; 64 } 65 66 71 public String getProviderURLPattern() 72 { 73 return urlPattern; 74 } 75 76 86 public void setProviderURLPattern(String regex) 87 { 88 this.urlPattern = regex; 89 this.urlPrefix = regex; 90 this.urlSuffix = ""; 91 String hostExp = "{host}"; 92 int hostIndex = regex.indexOf(hostExp); 93 if( hostIndex >= 0 ) 94 { 95 urlPrefix = regex.substring(0, hostIndex); 96 int endIndex = hostIndex + hostExp.length(); 97 urlSuffix = regex.substring(endIndex); 98 } 99 } 100 101 110 public void membershipChanged(ArrayList removed, ArrayList added, 111 ArrayList members, String logLoggerName) 112 { 113 log.debug("membershipChanged"); 114 Logger tmsLog = Logger.getLogger(logLoggerName); 115 Hashtable localEnv = null; 116 try 117 { 118 InitialContext localCtx = new InitialContext (); 119 localEnv = localCtx.getEnvironment(); 120 } 121 catch(NamingException e) 122 { 123 tmsLog.error("Failed to obtain InitialContext env", e); 124 return; 125 } 126 127 tmsLog.info("Checking removed hosts JNDI binding"); 128 doLookups(localEnv, tmsLog, removed); 129 tmsLog.info("Checking added hosts JNDI binding"); 130 doLookups(localEnv, tmsLog, added); 131 tmsLog.info("Checking members hosts JNDI binding"); 132 doLookups(localEnv, tmsLog, members); 133 } 134 135 private void doLookups(Hashtable localEnv, Logger tmsLog, ArrayList nodes) 136 { 137 for(int n = 0; n < nodes.size(); n ++) 138 { 139 AddressPort addrInfo = (AddressPort) nodes.get(n); 140 String providerURL = urlPrefix + addrInfo.getHostName() + urlSuffix; 141 Hashtable env = new Hashtable (localEnv); 142 env.put(Context.PROVIDER_URL, providerURL); 143 tmsLog.info("Checking names on: "+addrInfo); 144 try 145 { 146 InitialContext ctx = new InitialContext (env); 147 for(int s = 0; s < lookupNames.length; s ++) 148 { 149 String name = lookupNames[s]; 150 Object value = ctx.lookup(name); 151 tmsLog.info("lookup("+name+"): "+value); 152 } 153 } 154 catch(Exception e) 155 { 156 tmsLog.error("Failed lookups on: "+addrInfo, e); 157 } 158 } 159 } 160 } 161 | Popular Tags |