001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.ha.jndi;
023:
024: import java.rmi.server.RMIServerSocketFactory;
025: import java.rmi.server.RMIClientSocketFactory;
026:
027: import org.jboss.ha.framework.server.HARMIServerImpl;
028: import org.jboss.ha.framework.interfaces.LoadBalancePolicy;
029: import org.jboss.ha.framework.interfaces.RoundRobin;
030: import org.jnp.interfaces.Naming;
031:
032: /** Management Bean for HA-JNDI service for the legacy version that is coupled
033: * to the RMI/JRMP protocol. The DetachedHANamingService should be used with
034: * the approriate detached invoker service.
035: *
036: * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
037: * @author <a href="mailto:sacha.labourey@cogito-info.ch">Sacha Labourey</a>
038: * @author Scott.Stark@jboss.org
039: * @version $Revision: 57188 $
040: */
041: public class HANamingService extends DetachedHANamingService implements
042: HANamingServiceMBean {
043: // Constants -----------------------------------------------------
044:
045: // Attributes ----------------------------------------------------
046: /** An optional custom client socket factory */
047: protected RMIClientSocketFactory clientSocketFactory;
048: /** An optional custom server socket factory */
049: protected RMIServerSocketFactory serverSocketFactory;
050: /** The class name of the optional custom client socket factory */
051: protected String clientSocketFactoryName;
052: /** The class name of the optional custom server socket factory */
053: protected String serverSocketFactoryName;
054: /** The class name of the load balancing policy */
055: protected String loadBalancePolicy = RoundRobin.class.getName();
056: /** The RMI port on which the Naming implementation will be exported. The
057: default is 0 which means use any available port. */
058: protected int rmiPort = 0;
059: HARMIServerImpl rmiserver;
060:
061: // Public --------------------------------------------------------
062:
063: public HANamingService() {
064: // for JMX
065: }
066:
067: public void setRmiPort(int p) {
068: rmiPort = p;
069: }
070:
071: public int getRmiPort() {
072: return rmiPort;
073: }
074:
075: public String getClientSocketFactory() {
076: return serverSocketFactoryName;
077: }
078:
079: public void setClientSocketFactory(String factoryClassName)
080: throws ClassNotFoundException, InstantiationException,
081: IllegalAccessException {
082: this .clientSocketFactoryName = factoryClassName;
083: ClassLoader loader = Thread.currentThread()
084: .getContextClassLoader();
085: Class clazz = loader.loadClass(clientSocketFactoryName);
086: clientSocketFactory = (RMIClientSocketFactory) clazz
087: .newInstance();
088: }
089:
090: public String getServerSocketFactory() {
091: return serverSocketFactoryName;
092: }
093:
094: public void setServerSocketFactory(String factoryClassName)
095: throws ClassNotFoundException, InstantiationException,
096: IllegalAccessException {
097: this .serverSocketFactoryName = factoryClassName;
098: ClassLoader loader = Thread.currentThread()
099: .getContextClassLoader();
100: Class clazz = loader.loadClass(serverSocketFactoryName);
101: serverSocketFactory = (RMIServerSocketFactory) clazz
102: .newInstance();
103: }
104:
105: public String getLoadBalancePolicy() {
106: return loadBalancePolicy;
107: }
108:
109: public void setLoadBalancePolicy(String policyClassName) {
110: loadBalancePolicy = policyClassName;
111: }
112:
113: protected void stopService() throws Exception {
114: super .stopService();
115: // Unexport server
116: log.debug("destroy ha rmiserver");
117: this .rmiserver.destroy();
118: }
119:
120: protected Naming getNamingProxy() throws Exception {
121: Class clazz;
122: LoadBalancePolicy policy;
123:
124: rmiserver = new HARMIServerImpl(partition, "HAJNDI",
125: Naming.class, theServer, rmiPort, clientSocketFactory,
126: serverSocketFactory, bindAddress);
127:
128: ClassLoader cl = Thread.currentThread().getContextClassLoader();
129: clazz = cl.loadClass(loadBalancePolicy);
130: policy = (LoadBalancePolicy) clazz.newInstance();
131:
132: Naming proxy = (Naming) rmiserver.createHAStub(policy);
133: return proxy;
134: }
135: }
|