KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ha > jndi > HANamingService


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.ha.jndi;
23
24 import java.rmi.server.RMIServerSocketFactory JavaDoc;
25 import java.rmi.server.RMIClientSocketFactory JavaDoc;
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 /** Management Bean for HA-JNDI service for the legacy version that is coupled
33  * to the RMI/JRMP protocol. The DetachedHANamingService should be used with
34  * the appropriate detached invoker service.
35  *
36  * @author <a HREF="mailto:bill@burkecentral.com">Bill Burke</a>
37  * @author <a HREF="mailto:sacha.labourey@cogito-info.ch">Sacha Labourey</a>
38  * @author Scott.Stark@jboss.org
39  * @version $Revision: 38794 $
40  */

41 public class HANamingService
42    extends DetachedHANamingService
43    implements HANamingServiceMBean
44 {
45    // Constants -----------------------------------------------------
46

47    // Attributes ----------------------------------------------------
48
/** An optional custom client socket factory */
49    protected RMIClientSocketFactory JavaDoc clientSocketFactory;
50    /** An optional custom server socket factory */
51    protected RMIServerSocketFactory JavaDoc serverSocketFactory;
52    /** The class name of the optional custom client socket factory */
53    protected String JavaDoc clientSocketFactoryName;
54    /** The class name of the optional custom server socket factory */
55    protected String JavaDoc serverSocketFactoryName;
56    /** The class name of the load balancing policy */
57    protected String JavaDoc loadBalancePolicy = RoundRobin.class.getName();
58    /** The RMI port on which the Naming implementation will be exported. The
59     default is 0 which means use any available port. */

60    protected int rmiPort = 0;
61    HARMIServerImpl rmiserver;
62
63    // Public --------------------------------------------------------
64

65    public HANamingService()
66    {
67       // for JMX
68
}
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 JavaDoc getClientSocketFactory()
80    {
81       return serverSocketFactoryName;
82    }
83    public void setClientSocketFactory(String JavaDoc factoryClassName)
84       throws ClassNotFoundException JavaDoc, InstantiationException JavaDoc, IllegalAccessException JavaDoc
85    {
86       this.clientSocketFactoryName = factoryClassName;
87       ClassLoader JavaDoc loader = Thread.currentThread().getContextClassLoader();
88       Class JavaDoc clazz = loader.loadClass(clientSocketFactoryName);
89       clientSocketFactory = (RMIClientSocketFactory JavaDoc) clazz.newInstance();
90    }
91    
92    public String JavaDoc getServerSocketFactory()
93    {
94       return serverSocketFactoryName;
95    }
96    public void setServerSocketFactory(String JavaDoc factoryClassName)
97       throws ClassNotFoundException JavaDoc, InstantiationException JavaDoc, IllegalAccessException JavaDoc
98    {
99       this.serverSocketFactoryName = factoryClassName;
100       ClassLoader JavaDoc loader = Thread.currentThread().getContextClassLoader();
101       Class JavaDoc clazz = loader.loadClass(serverSocketFactoryName);
102       serverSocketFactory = (RMIServerSocketFactory JavaDoc) clazz.newInstance();
103    }
104
105    public String JavaDoc getLoadBalancePolicy()
106    {
107       return loadBalancePolicy;
108    }
109    public void setLoadBalancePolicy(String JavaDoc policyClassName)
110    {
111       loadBalancePolicy = policyClassName;
112    }
113    
114    protected void stopService() throws Exception JavaDoc
115    {
116       super.stopService();
117       // Unexport server
118
log.debug("destroy ha rmiserver");
119       this.rmiserver.destroy ();
120    }
121
122    protected Naming getNamingProxy() throws Exception JavaDoc
123    {
124       Class JavaDoc clazz;
125       LoadBalancePolicy policy;
126       
127       rmiserver = new HARMIServerImpl(partition, "HAJNDI", Naming.class,
128          theServer, rmiPort, clientSocketFactory, serverSocketFactory, bindAddress);
129
130       ClassLoader JavaDoc 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