[jboss-cvs] JBossAS SVN: r57220 - in branches/Branch_4_0: naming/src/main/org/jnp/server server/src/etc/conf/default/xmdesc server/src/main/org/jboss/naming testsuite/src/main/org/jboss/test/naming/test testsuite/src/resources/naming/services

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Sep 26 19:13:51 EDT 2006


Author: scott.stark at jboss.org
Date: 2006-09-26 19:13:40 -0400 (Tue, 26 Sep 2006)
New Revision: 57220

Added:
   branches/Branch_4_0/naming/src/main/org/jnp/server/NamingServerWrapper.java
Modified:
   branches/Branch_4_0/naming/src/main/org/jnp/server/Main.java
   branches/Branch_4_0/naming/src/main/org/jnp/server/MainMBean.java
   branches/Branch_4_0/server/src/etc/conf/default/xmdesc/NamingService-xmbean.xml
   branches/Branch_4_0/server/src/main/org/jboss/naming/NamingService.java
   branches/Branch_4_0/testsuite/src/main/org/jboss/test/naming/test/PooledInvokerUnitTestCase.java
   branches/Branch_4_0/testsuite/src/resources/naming/services/naming-xmbean.xml
   branches/Branch_4_0/testsuite/src/resources/naming/services/pooled-service.xml
Log:
JBAS-3705, Update NamingService to work correctly in multi-homed environments. 

Modified: branches/Branch_4_0/naming/src/main/org/jnp/server/Main.java
===================================================================
--- branches/Branch_4_0/naming/src/main/org/jnp/server/Main.java	2006-09-26 23:11:37 UTC (rev 57219)
+++ branches/Branch_4_0/naming/src/main/org/jnp/server/Main.java	2006-09-26 23:13:40 UTC (rev 57220)
@@ -59,7 +59,7 @@
    
    // Attributes ----------------------------------------------------
    /** The Naming interface server implementation */
-   protected NamingServer theServer;
+   protected Naming theServer;
    protected MarshalledObject serverStub;
    protected boolean isStubExported;
    /** The jnp server socket through which the NamingServer stub is vended */
@@ -92,6 +92,8 @@
    protected int rmiPort = 0;
    /** A flag indicating if theServer will be set as the NamingContext.setLocal value */
    protected boolean InstallGlobalService = true;
+   /** A flag indicating if theServer will try to use the NamingContext.setLocal value */
+   protected boolean UseGlobalService = true;
    protected Logger log;
    /** The thread pool used to handle jnp stub lookup requests */
    protected ThreadPool lookupPool;
@@ -216,7 +218,15 @@
    {
       this.InstallGlobalService = flag;
    }
-
+   public boolean getUseGlobalService()
+   {
+      return UseGlobalService;
+   }
+   public void setUseGlobalService(boolean flag)
+   {
+      this.UseGlobalService = flag;
+   }
+   
    public String getClientSocketFactory()
    {
       return clientSocketFactoryName;
@@ -258,11 +268,24 @@
       // Create the local naming service instance if it does not exist
       if( theServer == null )
       {
-         theServer = new NamingServer();
+         // See if we should try to reuse the current local server
+         if( UseGlobalService == true )
+            theServer = NamingContext.localServer;
+         // If not, or there is no server create one
+         if( theServer == null )
+            theServer = new NamingServer();
+         else
+         {
+            // We need to wrap the server to allow exporting it
+            NamingServerWrapper wrapper = new NamingServerWrapper(theServer);
+            theServer = wrapper;
+         }
+         log.debug("Using NamingServer: "+theServer);
          if( InstallGlobalService == true )
          {
             // Set local server reference
             NamingContext.setLocal(theServer);
+            log.debug("Installed global NamingServer: "+theServer);
          }
       }
 
@@ -367,7 +390,7 @@
       // Use either the rmiBindAddress or bindAddress for the RMI service
       InetAddress addr = rmiBindAddress != null ? rmiBindAddress : bindAddress;
 
-      if (clientSocketFactory != null)
+      if( clientSocketFactory != null && addr != null )
       {
          // See if the client socket supports setBindAddress(String)
          try

Modified: branches/Branch_4_0/naming/src/main/org/jnp/server/MainMBean.java
===================================================================
--- branches/Branch_4_0/naming/src/main/org/jnp/server/MainMBean.java	2006-09-26 23:11:37 UTC (rev 57219)
+++ branches/Branch_4_0/naming/src/main/org/jnp/server/MainMBean.java	2006-09-26 23:13:40 UTC (rev 57220)
@@ -53,7 +53,23 @@
    void setInstallGlobalService(boolean flag);
    boolean getInstallGlobalService();
 
-   /** The RMIServerSocketFactory implementation class */
+   /** Get the UseGlobalService which defines whether the MainMBean's
+    * Naming server will initialized from the existing NamingContext.setLocal
+    * global value.
+    * 
+    * @return true if this should try to use VM global naming service, false otherwise 
+    */ 
+   public boolean getUseGlobalService();
+   /** Set the UseGlobalService which defines whether the MainMBean's
+    * Naming server will initialized from the existing NamingContext.setLocal global
+    * value. This allows one to export multiple servers via different transports
+    * and still share the same underlying naming service.
+    * 
+    * @return true if this should try to use VM global naming service, false otherwise 
+    */ 
+   public void setUseGlobalService(boolean flag);
+
+   /** The RMIClientSocketFactory implementation class */
    void setClientSocketFactory(String factoryClassName)
       throws ClassNotFoundException, InstantiationException, IllegalAccessException;
    String getClientSocketFactory();

Added: branches/Branch_4_0/naming/src/main/org/jnp/server/NamingServerWrapper.java
===================================================================
--- branches/Branch_4_0/naming/src/main/org/jnp/server/NamingServerWrapper.java	2006-09-26 23:11:37 UTC (rev 57219)
+++ branches/Branch_4_0/naming/src/main/org/jnp/server/NamingServerWrapper.java	2006-09-26 23:13:40 UTC (rev 57220)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jnp.server;
+
+import java.rmi.RemoteException;
+import java.util.Collection;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NamingException;
+
+import org.jnp.interfaces.Naming;
+
+/**
+ * A delegating wrapper that can be used to create a unique rmi server endpoint
+ * that shares the an underlying Naming server implementation.
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class NamingServerWrapper
+   implements Naming
+{
+   Naming delegate;
+   NamingServerWrapper(Naming delegate)
+   {
+      this.delegate = delegate;
+   }
+
+   public void bind(Name name, Object obj, String className)
+      throws NamingException, RemoteException
+   {
+      delegate.bind(name, obj, className);
+   }
+   public Context createSubcontext(Name name)
+      throws NamingException, RemoteException
+   {
+      return delegate.createSubcontext(name);
+   }
+   public Collection list(Name name)
+      throws NamingException, RemoteException
+   {
+      return delegate.list(name);
+   }
+   public Collection listBindings(Name name)
+      throws NamingException, RemoteException
+   {
+      return delegate.listBindings(name);
+   }
+   public Object lookup(Name name)
+      throws NamingException, RemoteException
+   {
+      return delegate.lookup(name);
+   }
+   public void rebind(Name name, Object obj, String className)
+      throws NamingException, RemoteException
+   {
+      delegate.rebind(name, obj, className);
+   }
+   public void unbind(Name name)
+      throws NamingException, RemoteException
+   {
+      delegate.unbind(name);
+   }
+}

Modified: branches/Branch_4_0/server/src/etc/conf/default/xmdesc/NamingService-xmbean.xml
===================================================================
--- branches/Branch_4_0/server/src/etc/conf/default/xmdesc/NamingService-xmbean.xml	2006-09-26 23:11:37 UTC (rev 57219)
+++ branches/Branch_4_0/server/src/etc/conf/default/xmdesc/NamingService-xmbean.xml	2006-09-26 23:13:40 UTC (rev 57220)
@@ -94,9 +94,20 @@
 
    <attribute access="read-write" getMethod="getInstallGlobalService"
       setMethod="setInstallGlobalService">
+      <description>Ghe InstallGlobalService which defines whether the MainMBean's
+         Naming server will be installed as the NamingContext.setLocal global
+         value.</description>
       <name>InstallGlobalService</name>
       <type>boolean</type>
    </attribute>
+   <attribute access="read-write" getMethod="getUseGlobalService"
+      setMethod="setUseGlobalService">
+      <description>The UseGlobalService which defines whether the MainMBean's
+         Naming server will initialized from the existing NamingContext.setLocal global
+         value.</description>
+      <name>UseGlobalService</name>
+      <type>boolean</type>
+   </attribute>
    <attribute access="write-only" setMethod="setLookupPool">
       <description>The thread pool service used to control the bootstrap lookups</description>
       <name>LookupPool</name>

Modified: branches/Branch_4_0/server/src/main/org/jboss/naming/NamingService.java
===================================================================
--- branches/Branch_4_0/server/src/main/org/jboss/naming/NamingService.java	2006-09-26 23:11:37 UTC (rev 57219)
+++ branches/Branch_4_0/server/src/main/org/jboss/naming/NamingService.java	2006-09-26 23:13:40 UTC (rev 57220)
@@ -167,7 +167,14 @@
    {
       naming.setInstallGlobalService(flag);
    }
-
+   public boolean getUseGlobalService()
+   {
+      return naming.getUseGlobalService();
+   }
+   public void setUseGlobalService(boolean flag)
+   {
+      naming.setUseGlobalService(flag);
+   }
    public String getClientSocketFactory()
    {
       return naming.getClientSocketFactory();

Modified: branches/Branch_4_0/testsuite/src/main/org/jboss/test/naming/test/PooledInvokerUnitTestCase.java
===================================================================
--- branches/Branch_4_0/testsuite/src/main/org/jboss/test/naming/test/PooledInvokerUnitTestCase.java	2006-09-26 23:11:37 UTC (rev 57219)
+++ branches/Branch_4_0/testsuite/src/main/org/jboss/test/naming/test/PooledInvokerUnitTestCase.java	2006-09-26 23:13:40 UTC (rev 57220)
@@ -111,6 +111,26 @@
       ctx.close();
    }
 
+   /**
+    * Test lookup of a binding that would be created in the default naming
+    * service to validate that the original naming service content is visible
+    * from the pooled invoker version.
+    * @throws Exception
+    */
+   public void testSharedLookup()
+      throws Exception
+   {
+      getLog().info("+++ testSharedLookup");
+      Properties env = new Properties();
+      env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
+      env.setProperty(Context.PROVIDER_URL, "jnp://" + getServerHost() + ":10999/");
+      env.setProperty("jnp.disableDiscovery", "true");
+      InitialContext ctx = new InitialContext(env);
+      Object obj = ctx.lookup("jmx/rmi/RMIAdaptor");
+      assertNotNull("jmx/rmi/RMIAdaptor", obj);
+      getLog().info("lookup('jmx/rmi/RMIAdaptor') = "+obj);      
+   }
+
    /** Lookup a name to test basic connectivity and lookup of a known name
     *
     * @throws Exception

Modified: branches/Branch_4_0/testsuite/src/resources/naming/services/naming-xmbean.xml
===================================================================
--- branches/Branch_4_0/testsuite/src/resources/naming/services/naming-xmbean.xml	2006-09-26 23:11:37 UTC (rev 57219)
+++ branches/Branch_4_0/testsuite/src/resources/naming/services/naming-xmbean.xml	2006-09-26 23:13:40 UTC (rev 57220)
@@ -93,6 +93,14 @@
       <name>InstallGlobalService</name>
       <type>boolean</type>
    </attribute>
+   <attribute access="read-write" getMethod="getUseGlobalService"
+      setMethod="setUseGlobalService">
+      <description>The UseGlobalService which defines whether the MainMBean's
+         Naming server will initialized from the existing NamingContext.setLocal global
+         value.</description>
+      <name>UseGlobalService</name>
+      <type>boolean</type>
+   </attribute>
    <attribute access="write-only" setMethod="setLookupPool">
       <description>The thread pool service used to control the bootstrap lookups</description>
       <name>LookupPool</name>

Modified: branches/Branch_4_0/testsuite/src/resources/naming/services/pooled-service.xml
===================================================================
--- branches/Branch_4_0/testsuite/src/resources/naming/services/pooled-service.xml	2006-09-26 23:11:37 UTC (rev 57219)
+++ branches/Branch_4_0/testsuite/src/resources/naming/services/pooled-service.xml	2006-09-26 23:13:40 UTC (rev 57220)
@@ -38,8 +38,16 @@
       xmbean-dd="naming-xmbean.xml">
       <!-- The bootstrap port used to lookup the Naming proxy -->
       <attribute name="Port">10999</attribute>
+      <attribute name="RmiPort">10998</attribute>
+      <attribute name="RmiBindAddress">${jboss.bind.address}</attribute>
       <!-- Don't override the default naming service -->
       <attribute name="InstallGlobalService">false</attribute>
+      <!-- Use the default local service -->
+      <attribute name="UseGlobalService">true</attribute>
+      <!-- Validate the default client socket factory -->
+      <attribute name="ClientSocketFactory">org.jboss.net.sockets.DefaultClientSocketFactory</attribute>
+      <!-- Validate the default server socket factory -->
+      <attribute name="ServerSocketFactory">org.jboss.net.sockets.DefaultSocketFactory</attribute>
       <!-- The thread pool service used to control the bootstrap lookups -->
       <depends optional-attribute-name="LookupPool"
          proxy-type="attribute">jboss.system:service=ThreadPool</depends>




More information about the jboss-cvs-commits mailing list