1 22 package org.jboss.ha.jndi; 23 24 import java.rmi.server.RMIServerSocketFactory ; 25 import java.rmi.server.RMIClientSocketFactory ; 26 27 import org.jboss.ha.framework.server.HARMIServerImpl; 28 import org.jboss.ha.framework.interfaces.LoadBalancePolicy; 29 import org.jboss.ha.framework.interfaces.RoundRobin; 30 import org.jnp.interfaces.Naming; 31 32 41 public class HANamingService 42 extends DetachedHANamingService 43 implements HANamingServiceMBean 44 { 45 47 49 protected RMIClientSocketFactory clientSocketFactory; 50 51 protected RMIServerSocketFactory serverSocketFactory; 52 53 protected String clientSocketFactoryName; 54 55 protected String serverSocketFactoryName; 56 57 protected String loadBalancePolicy = RoundRobin.class.getName(); 58 60 protected int rmiPort = 0; 61 HARMIServerImpl rmiserver; 62 63 65 public HANamingService() 66 { 67 } 69 70 public void setRmiPort(int p) 71 { 72 rmiPort = p; 73 } 74 public int getRmiPort() 75 { 76 return rmiPort; 77 } 78 79 public String getClientSocketFactory() 80 { 81 return serverSocketFactoryName; 82 } 83 public void setClientSocketFactory(String factoryClassName) 84 throws ClassNotFoundException , InstantiationException , IllegalAccessException 85 { 86 this.clientSocketFactoryName = factoryClassName; 87 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 88 Class clazz = loader.loadClass(clientSocketFactoryName); 89 clientSocketFactory = (RMIClientSocketFactory ) clazz.newInstance(); 90 } 91 92 public String getServerSocketFactory() 93 { 94 return serverSocketFactoryName; 95 } 96 public void setServerSocketFactory(String factoryClassName) 97 throws ClassNotFoundException , InstantiationException , IllegalAccessException 98 { 99 this.serverSocketFactoryName = factoryClassName; 100 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 101 Class clazz = loader.loadClass(serverSocketFactoryName); 102 serverSocketFactory = (RMIServerSocketFactory ) clazz.newInstance(); 103 } 104 105 public String getLoadBalancePolicy() 106 { 107 return loadBalancePolicy; 108 } 109 public void setLoadBalancePolicy(String policyClassName) 110 { 111 loadBalancePolicy = policyClassName; 112 } 113 114 protected void stopService() throws Exception 115 { 116 super.stopService(); 117 log.debug("destroy ha rmiserver"); 119 this.rmiserver.destroy (); 120 } 121 122 protected Naming getNamingProxy() throws Exception 123 { 124 Class clazz; 125 LoadBalancePolicy policy; 126 127 rmiserver = new HARMIServerImpl(partition, "HAJNDI", Naming.class, 128 theServer, rmiPort, clientSocketFactory, serverSocketFactory, bindAddress); 129 130 ClassLoader cl = Thread.currentThread().getContextClassLoader(); 131 clazz = cl.loadClass(loadBalancePolicy); 132 policy = (LoadBalancePolicy)clazz.newInstance(); 133 134 Naming proxy = (Naming) rmiserver.createHAStub(policy); 135 return proxy; 136 } 137 } 138 | Popular Tags |