1 9 package org.jboss.mx.remoting; 10 11 import java.util.StringTokenizer ; 12 import javax.management.MBeanServer ; 13 import org.jboss.logging.Logger; 14 import org.jboss.remoting.ConnectionFailedException; 15 import org.jboss.remoting.InvokerLocator; 16 import org.jboss.remoting.ident.Identity; 17 18 29 public class MBeanTransportPreference 30 { 31 private static final transient Logger log = Logger.getLogger(MBeanTransportPreference.class.getName()); 32 33 private static String _preferences = System.getProperty("jboss.transport.preferences", "socket,rmi,soap"); 35 private static String preferences[] = initialize(_preferences); 36 private static MBeanServer ourServer; 37 private static Identity ourIdentity; 38 39 public static void setLocalServer(MBeanServer server, Identity identity) 40 { 41 if(log.isTraceEnabled()) 42 { 43 log.trace("setLocalServer called - server=" + server + ",identity=" + identity); 44 } 45 ourServer = server; 46 ourIdentity = identity; 47 } 48 49 private static String [] initialize(String list) 50 { 51 if(list == null) 52 { 53 return new String [1]; 54 } 55 StringTokenizer tok = new StringTokenizer (list, ","); 56 String pref [] = new String [tok.countTokens()]; 57 int c = 0; 58 while(tok.hasMoreTokens()) 59 { 60 String token = tok.nextToken(); 61 pref[c++] = token.trim(); 62 } 63 return pref; 64 } 65 66 71 public static void setTransportPreferences(String order[]) 72 { 73 preferences = (order == null || order.length <= 0) ? initialize(_preferences) : order; 74 } 75 76 81 public static String [] getTransportPreferences() 82 { 83 return preferences; 84 } 85 86 95 public static MBeanServer getServerByTransport(Identity identity, InvokerLocator locators[]) 96 throws ConnectionFailedException 97 { 98 if(log.isTraceEnabled()) 99 { 100 log.trace("getServerByTransport for identity=" + identity + ", ours is=" + ourIdentity); 101 } 102 if(ourIdentity == null) 103 { 104 if(ourServer == null) 105 { 106 ourServer = JMXUtil.getMBeanServer(); 107 } 108 ourIdentity = Identity.get(ourServer); 109 } 110 if(identity.isSameJVM(ourIdentity)) 111 { 112 return ourServer; 113 } 114 for(int c = 0; c < preferences.length; c++) 115 { 116 String transport = preferences[c]; 117 118 if(transport != null) 119 { 120 for(int x = 0; x < locators.length; x++) 121 { 122 if(locators[x].getProtocol().equals(transport)) 123 { 124 try 126 { 127 MBeanServer svr = MBeanServerRegistry.getMBeanServerFor(locators[x]); 128 if(svr != null) 129 { 130 return svr; 131 } 132 svr = MBeanServerClientInvokerProxy.create(locators[x], ourIdentity.getJMXId(), identity.getJMXId()); 133 if(svr != null) 134 { 135 return svr; 136 } 137 } 138 catch(Throwable ex) 139 { 140 } 141 } 142 } 143 } 144 } 145 for(int x = 0; x < locators.length; x++) 146 { 147 try 149 { 150 if(log.isTraceEnabled()) 151 { 152 log.trace("attempting to connect via locator[" + x + "] (" + locators[x] + ") to: " + identity); 153 } 154 MBeanServer svr = MBeanServerRegistry.getMBeanServerFor(locators[x]); 155 if(svr != null) 156 { 157 return svr; 158 } 159 svr = MBeanServerClientInvokerProxy.create(locators[x], ourIdentity.getJMXId(), identity.getJMXId()); 160 if(svr != null) 161 { 162 return svr; 163 } 164 } 165 catch(Throwable ex) 166 { 167 log.debug("Error connecting ... ", ex); 168 } 169 } 170 throw new ConnectionFailedException("No transport/connection available to connect to: " + identity); 171 } 172 } 173 | Popular Tags |