[jboss-cvs] JBossAS SVN: r79043 - in projects/naming/trunk/jnpserver/src: main/java/org/jnp/server and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Oct 2 14:50:46 EDT 2008
Author: scott.stark at jboss.org
Date: 2008-10-02 14:50:46 -0400 (Thu, 02 Oct 2008)
New Revision: 79043
Added:
projects/naming/trunk/jnpserver/src/main/java/org/jnp/server/ThreadPoolToExecutor.java
projects/naming/trunk/jnpserver/src/test/resources/org/jnp/test/NamingMCUnitTest#testMainBean.xml
Modified:
projects/naming/trunk/jnpserver/src/main/java/org/jnp/interfaces/NamingContext.java
projects/naming/trunk/jnpserver/src/main/java/org/jnp/interfaces/NamingEvents.java
projects/naming/trunk/jnpserver/src/main/java/org/jnp/server/Main.java
projects/naming/trunk/jnpserver/src/test/java/org/jnp/test/NamingMCUnitTest.java
Log:
JBNAME-16, updates for mc support
Modified: projects/naming/trunk/jnpserver/src/main/java/org/jnp/interfaces/NamingContext.java
===================================================================
--- projects/naming/trunk/jnpserver/src/main/java/org/jnp/interfaces/NamingContext.java 2008-10-02 18:14:53 UTC (rev 79042)
+++ projects/naming/trunk/jnpserver/src/main/java/org/jnp/interfaces/NamingContext.java 2008-10-02 18:50:46 UTC (rev 79043)
@@ -1248,7 +1248,15 @@
throw new UnsupportedOperationException("Naming implementation does not support NamingExt");
}
NamingEvents next = (NamingEvents) naming;
- next.addNamingListener(this, target, scope, l);
+ try
+ {
+ next.addNamingListener(this, target, scope, l);
+ }
+ catch (RemoteException e)
+ {
+ CommunicationException ce = new CommunicationException("addNamingListener failed");
+ ce.initCause(e);
+ }
}
public void addNamingListener(String target, int scope, NamingListener l)
@@ -1266,7 +1274,15 @@
throw new UnsupportedOperationException("Naming implementation does not support NamingExt");
}
NamingEvents next = (NamingEvents) naming;
- next.removeNamingListener(l);
+ try
+ {
+ next.removeNamingListener(l);
+ }
+ catch (RemoteException e)
+ {
+ CommunicationException ce = new CommunicationException("removeNamingListener failed");
+ ce.initCause(e);
+ }
}
public boolean targetMustExist()
@@ -1277,7 +1293,17 @@
throw new UnsupportedOperationException("Naming implementation does not support NamingExt");
}
NamingEvents next = (NamingEvents) naming;
- return next.targetMustExist();
+ boolean targetMustExist = true;
+ try
+ {
+ targetMustExist = next.targetMustExist();
+ }
+ catch (RemoteException e)
+ {
+ CommunicationException ce = new CommunicationException("removeNamingListener failed");
+ ce.initCause(e);
+ }
+ return targetMustExist;
}
// End EventContext methods
Modified: projects/naming/trunk/jnpserver/src/main/java/org/jnp/interfaces/NamingEvents.java
===================================================================
--- projects/naming/trunk/jnpserver/src/main/java/org/jnp/interfaces/NamingEvents.java 2008-10-02 18:14:53 UTC (rev 79042)
+++ projects/naming/trunk/jnpserver/src/main/java/org/jnp/interfaces/NamingEvents.java 2008-10-02 18:50:46 UTC (rev 79043)
@@ -21,6 +21,8 @@
*/
package org.jnp.interfaces;
+import java.rmi.RemoteException;
+
import javax.naming.Name;
import javax.naming.NamingException;
import javax.naming.event.EventContext;
@@ -49,7 +51,7 @@
* @see #removeNamingListener
*/
void addNamingListener(EventContext context, Name target, int scope, NamingListener l)
- throws NamingException;
+ throws NamingException, RemoteException;
/**
* Removes a listener from receiving naming events
@@ -58,7 +60,7 @@
* removing the listener.
* @see #addNamingListener
*/
- void removeNamingListener(NamingListener l) throws NamingException;
+ void removeNamingListener(NamingListener l) throws NamingException, RemoteException;
/**
* Determines whether a listener can register interest in a target
@@ -68,5 +70,5 @@
* @exception NamingException If the context's behavior in this regard cannot
* be determined.
*/
- boolean targetMustExist() throws NamingException;
+ boolean targetMustExist() throws NamingException, RemoteException;
}
Modified: projects/naming/trunk/jnpserver/src/main/java/org/jnp/server/Main.java
===================================================================
--- projects/naming/trunk/jnpserver/src/main/java/org/jnp/server/Main.java 2008-10-02 18:14:53 UTC (rev 79042)
+++ projects/naming/trunk/jnpserver/src/main/java/org/jnp/server/Main.java 2008-10-02 18:50:46 UTC (rev 79043)
@@ -35,13 +35,16 @@
import java.rmi.server.RMIClientSocketFactory;
import java.rmi.server.RMIServerSocketFactory;
import java.rmi.server.UnicastRemoteObject;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
import javax.net.ServerSocketFactory;
import org.jboss.logging.Logger;
import org.jboss.net.sockets.DefaultSocketFactory;
-import org.jboss.util.threadpool.BasicThreadPool;
import org.jboss.util.threadpool.ThreadPool;
+import org.jnp.interfaces.MarshalledValuePair;
import org.jnp.interfaces.Naming;
/**
@@ -95,7 +98,7 @@
protected boolean UseGlobalService = true;
protected Logger log;
/** The thread pool used to handle jnp stub lookup requests */
- protected ThreadPool lookupPool;
+ private Executor lookupExector;
// Static --------------------------------------------------------
public static void main(String[] args)
@@ -134,20 +137,50 @@
{
return theServer;
}
+ /**
+ * Set the NamingBean/Naming implementation
+ * @param info
+ */
public void setNamingInfo(NamingBean info)
{
this.theServer = info;
}
- public ThreadPool getLookupPool()
+ @Deprecated
+ public void setLookupPool(ThreadPool lookupPool)
{
- return lookupPool;
+ this.lookupExector = new ThreadPoolToExecutor(lookupPool);
}
- public void setLookupPool(ThreadPool lookupPool)
+
+ public Executor getLookupExector()
{
- this.lookupPool = lookupPool;
+ return lookupExector;
}
+ public void setLookupExector(Executor lookupExector)
+ {
+ this.lookupExector = lookupExector;
+ }
+ /** Get the call by value flag for jndi lookups.
+ *
+ * @return true if all lookups are unmarshalled using the caller's TCL,
+ * false if in VM lookups return the value by reference.
+ */
+ public boolean getCallByValue()
+ {
+ return MarshalledValuePair.getEnableCallByReference() == false;
+ }
+ /** Set the call by value flag for jndi lookups.
+ *
+ * @param flag - true if all lookups are unmarshalled using the caller's TCL,
+ * false if in VM lookups return the value by reference.
+ */
+ public void setCallByValue(boolean flag)
+ {
+ boolean callByValue = ! flag;
+ MarshalledValuePair.setEnableCallByReference(callByValue);
+ }
+
public void setNamingProxy(Object proxy)
throws IOException
{
@@ -239,7 +272,7 @@
{
this.clientSocketFactoryName = factoryClassName;
ClassLoader loader = Thread.currentThread().getContextClassLoader();
- Class clazz = loader.loadClass(clientSocketFactoryName);
+ Class<?> clazz = loader.loadClass(clientSocketFactoryName);
clientSocketFactory = (RMIClientSocketFactory) clazz.newInstance();
}
@@ -261,7 +294,7 @@
{
this.serverSocketFactoryName = factoryClassName;
ClassLoader loader = Thread.currentThread().getContextClassLoader();
- Class clazz = loader.loadClass(serverSocketFactoryName);
+ Class<?> clazz = loader.loadClass(serverSocketFactoryName);
serverSocketFactory = (RMIServerSocketFactory) clazz.newInstance();
}
@@ -283,7 +316,7 @@
{
this.jnpServerSocketFactoryName = factoryClassName;
ClassLoader loader = Thread.currentThread().getContextClassLoader();
- Class clazz = loader.loadClass(jnpServerSocketFactoryName);
+ Class<?> clazz = loader.loadClass(jnpServerSocketFactoryName);
jnpServerSocketFactory = (ServerSocketFactory) clazz.newInstance();
}
@@ -296,6 +329,9 @@
this.jnpServerSocketFactory = factory;
}
+ /**
+ * Access the
+ */
public Naming getNamingInstance()
{
return theServer.getNamingInstance();
@@ -394,10 +430,19 @@
log.error("Could not start on port " + port, e);
}
- if( lookupPool == null )
- lookupPool = new BasicThreadPool("NamingBootstrap Pool");
+ if( lookupExector == null )
+ {
+ lookupExector = Executors.newSingleThreadExecutor(new ThreadFactory()
+ {
+ public Thread newThread(Runnable r)
+ {
+ return new Thread("Naming Bootstrap");
+ }
+ }
+ );
+ }
AcceptHandler handler = new AcceptHandler();
- lookupPool.run(handler);
+ lookupExector.execute(handler);
}
/**
@@ -413,8 +458,8 @@
// See if the client socket supports setBindAddress(String)
try
{
- Class csfClass = clientSocketFactory.getClass();
- Class[] parameterTypes = {String.class};
+ Class<?> csfClass = clientSocketFactory.getClass();
+ Class<?>[] parameterTypes = {String.class};
Method m = csfClass.getMethod("setBindAddress", parameterTypes);
Object[] args = {addr.getHostAddress()};
m.invoke(clientSocketFactory, args);
@@ -442,8 +487,8 @@
// See if the server socket supports setBindAddress(String)
try
{
- Class ssfClass = serverSocketFactory.getClass();
- Class[] parameterTypes = {String.class};
+ Class<?> ssfClass = serverSocketFactory.getClass();
+ Class<?>[] parameterTypes = {String.class};
Method m = ssfClass.getMethod("setBindAddress", parameterTypes);
Object[] args = {addr.getHostAddress()};
m.invoke(serverSocketFactory, args);
@@ -483,7 +528,7 @@
if( trace )
log.trace("Accepted bootstrap client: "+socket);
BootstrapRequestHandler handler = new BootstrapRequestHandler(socket);
- lookupPool.run(handler);
+ lookupExector.execute(handler);
}
catch (IOException e)
{
Added: projects/naming/trunk/jnpserver/src/main/java/org/jnp/server/ThreadPoolToExecutor.java
===================================================================
--- projects/naming/trunk/jnpserver/src/main/java/org/jnp/server/ThreadPoolToExecutor.java (rev 0)
+++ projects/naming/trunk/jnpserver/src/main/java/org/jnp/server/ThreadPoolToExecutor.java 2008-10-02 18:50:46 UTC (rev 79043)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt 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.util.concurrent.Executor;
+
+import org.jboss.util.threadpool.ThreadPool;
+
+/**
+ * Adapts the legacy ThreadPool to an Executor
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class ThreadPoolToExecutor
+ implements Executor
+{
+ private ThreadPool pool;
+
+ public ThreadPoolToExecutor()
+ {
+ this(null);
+ }
+ public ThreadPoolToExecutor(ThreadPool pool)
+ {
+ this.pool = pool;
+ }
+
+ public ThreadPool getPool()
+ {
+ return pool;
+ }
+ public void setPool(ThreadPool pool)
+ {
+ this.pool = pool;
+ }
+
+ public void execute(Runnable command)
+ {
+ pool.run(command);
+ }
+}
Modified: projects/naming/trunk/jnpserver/src/test/java/org/jnp/test/NamingMCUnitTest.java
===================================================================
--- projects/naming/trunk/jnpserver/src/test/java/org/jnp/test/NamingMCUnitTest.java 2008-10-02 18:14:53 UTC (rev 79042)
+++ projects/naming/trunk/jnpserver/src/test/java/org/jnp/test/NamingMCUnitTest.java 2008-10-02 18:50:46 UTC (rev 79043)
@@ -108,6 +108,17 @@
validateCtx(ctx);
}
+ public void testMainBean()
+ throws Exception
+ {
+ Properties env = new Properties();
+ env.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
+ env.setProperty("java.naming.provider.url", "localhost:1099");
+ env.setProperty("java.naming.factory.url", "org.jboss.naming:org.jnp.interfaces");
+ InitialContext ic = new InitialContext(env);
+ validateCtx(ic);
+ }
+
/**
*
* @param ic
Added: projects/naming/trunk/jnpserver/src/test/resources/org/jnp/test/NamingMCUnitTest#testMainBean.xml
===================================================================
--- projects/naming/trunk/jnpserver/src/test/resources/org/jnp/test/NamingMCUnitTest#testMainBean.xml (rev 0)
+++ projects/naming/trunk/jnpserver/src/test/resources/org/jnp/test/NamingMCUnitTest#testMainBean.xml 2008-10-02 18:50:46 UTC (rev 79043)
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_2_0.xsd"
+ xmlns="urn:jboss:bean-deployer:2.0">
+
+ <bean name="InitialContextFactory" class="org.jboss.naming.InitialContextFactoryBean">
+ <property name="env">
+ <map class="java.util.Properties" keyClass="java.lang.String" valueClass="java.lang.String">
+ <entry>
+ <key>java.naming.factory.initial</key>
+ <value>org.jnp.interfaces.LocalOnlyContextFactory</value>
+ </entry>
+ <entry>
+ <key>java.naming.factory.url</key>
+ <value>org.jboss.naming:org.jnp.interfaces</value>
+ </entry>
+ </map>
+ </property>
+ <depends>testLocaNamingBeanImpl</depends>
+ </bean>
+ <bean name="JndiBindings" class="org.jboss.naming.BindingsInitializer">
+ <property name="ctx">
+ <inject bean="InitialContextFactory" property="ctx"/>
+ </property>
+ <property name="bindings">
+ <map keyClass="java.lang.String">
+ <entry>
+ <key>ints/1</key>
+ <value class="java.lang.Integer">1</value>
+ </entry>
+ <entry>
+ <key>strings/1</key>
+ <value class="java.lang.String">String1</value>
+ </entry>
+ <entry>
+ <key>bigint/1</key>
+ <value class="java.math.BigInteger">123456789</value>
+ </entry>
+ <entry>
+ <key>env-props</key>
+ <value>
+ <map class="java.util.Properties" keyClass="java.lang.String" valueClass="java.lang.String">
+ <entry>
+ <key>java.naming.factory.initial</key>
+ <value>org.jnp.interfaces.LocalOnlyContextFactory</value>
+ </entry>
+ <entry>
+ <key>java.naming.factory.url</key>
+ <value>org.jboss.naming:org.jnp.interfaces</value>
+ </entry>
+ </map>
+ </value>
+ </entry>
+ </map>
+ </property>
+ </bean>
+
+ <bean name="LookupPool">
+ <constructor factoryMethod="newSingleThreadExecutor"
+ factoryClass="java.util.concurrent.Executors"/>
+ </bean>
+ <bean name="testLocaNamingBeanImpl" class="org.jnp.server.NamingBeanImpl">
+ <!-- Install this bean as the global JVM NamingServer -->
+ <property name="installGlobalService">true</property>
+
+ <property name="useGlobalService">false</property>
+ </bean>
+ <bean name="jboss:service=Naming" class="org.jnp.server.Main">
+ <property name="namingInfo"><inject bean="testLocaNamingBeanImpl" /></property>
+ <!-- The call by value mode. true if all lookups are unmarshalled using
+ the caller's TCL, false if in VM lookups return the value by reference.
+ -->
+ <property name="callByValue">false</property>
+
+ <!-- The listening port for the bootstrap JNP service. Set this to -1
+ to run the NamingService without the JNP invoker listening port.
+ -->
+ <property name="port">1099</property>
+
+ <!-- The bootstrap JNP server bind address. This also sets the default
+ RMI service bind address. Empty == all addresses
+ -->
+ <property name="bindAddress">${jboss.bind.address:localhost}</property>
+ <!-- The port of the RMI naming service, 0 == anonymous -->
+ <property name="rmiPort">0</property>
+ <!-- The RMI service bind address. Empty == all addresses
+ -->
+ <property name="rmiBindAddress">${jboss.bind.address:localhost}</property>
+ <!-- The thread pool service used to control the bootstrap lookups -->
+ <property name="lookupExector"><inject bean="LookupPool"/></property>
+ </bean>
+
+</deployment>
More information about the jboss-cvs-commits
mailing list