JBoss Remoting SVN: r4995 - remoting2/branches/2.x/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-14 06:10:28 -0400 (Tue, 14 Apr 2009)
New Revision: 4995
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java
Log:
JBREM-1116: Eliminated dependence on SecurityUtility.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java 2009-04-14 10:09:59 UTC (rev 4994)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java 2009-04-14 10:10:28 UTC (rev 4995)
@@ -13,6 +13,10 @@
import org.jboss.util.id.GUID;
import java.io.IOException;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -120,7 +124,7 @@
// class loader. This allows to load remoting classes as well as user's
// classes. If possible, will simply reset context classloader on existing
// RemotingClassLoader.
- final ClassLoader contextClassLoader = SecurityUtility.getContextClassLoader(Thread.currentThread());
+ final ClassLoader contextClassLoader = getContextClassLoader(Thread.currentThread());
if (unmarshaller instanceof UpdateableClassloaderUnMarshaller)
{
UpdateableClassloaderUnMarshaller uclum = (UpdateableClassloaderUnMarshaller) unmarshaller;
@@ -132,13 +136,13 @@
}
else
{
- rcl = SecurityUtility.createRemotingClassLoader(getClassLoader(), contextClassLoader, parentFirstClassLoading);
+ rcl = createRemotingClassLoader(getClassLoader(), contextClassLoader, parentFirstClassLoading);
unmarshaller.setClassLoader(rcl);
}
}
else
{
- rcl = SecurityUtility.createRemotingClassLoader(getClassLoader(), contextClassLoader, parentFirstClassLoading);
+ rcl = createRemotingClassLoader(getClassLoader(), contextClassLoader, parentFirstClassLoading);
unmarshaller.setClassLoader(rcl);
}
}
@@ -364,13 +368,13 @@
public void setUnMarshaller(UnMarshaller unmarshaller)
{
- ClassLoader classLoader = SecurityUtility.getContextClassLoader(Thread.currentThread());
+ ClassLoader classLoader = getContextClassLoader(Thread.currentThread());
unmarshallers.put(classLoader, unmarshaller);
}
public UnMarshaller getUnMarshaller()
{
- ClassLoader classLoader = SecurityUtility.getContextClassLoader(Thread.currentThread());
+ ClassLoader classLoader = getContextClassLoader(Thread.currentThread());
return (UnMarshaller)unmarshallers.get(classLoader);
}
@@ -545,7 +549,7 @@
if(flag == null)
{
// Fallback to the system property
- flag = SecurityUtility.getSystemProperty(Remoting.CLASSLOADING_PARENT_FIRST_DELEGATION_PROP);
+ flag = getSystemProperty(Remoting.CLASSLOADING_PARENT_FIRST_DELEGATION_PROP);
}
boolean parentFirst = true;
if (flag != null)
@@ -628,5 +632,61 @@
disconnect();
super.finalize();
}
+
+ static private String getSystemProperty(final String name)
+ {
+ if (SecurityUtility.skipAccessControl())
+ return System.getProperty(name);
+
+ String value = null;
+ try
+ {
+ value = (String)AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return System.getProperty(name);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (RuntimeException) e.getCause();
+ }
+
+ return value;
+ }
+
+ static private RemotingClassLoader createRemotingClassLoader(final ClassLoader remotingClassLoader,
+ final ClassLoader userClassLoader, final boolean parentFirstDelegation)
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return new RemotingClassLoader(remotingClassLoader, userClassLoader, parentFirstDelegation);
+ }
+ return (RemotingClassLoader)AccessController.doPrivileged( new PrivilegedAction()
+ {
+ public Object run()
+ {
+ return new RemotingClassLoader(remotingClassLoader, userClassLoader, parentFirstDelegation);
+ }
+ });
+ }
+
+ static private ClassLoader getContextClassLoader(final Thread thread)
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return thread.getContextClassLoader();
+ }
+
+ return (ClassLoader) AccessController.doPrivileged( new PrivilegedAction()
+ {
+ public Object run()
+ {
+ return thread.getContextClassLoader();
+ }
+ });
+ }
}
15 years, 7 months
JBoss Remoting SVN: r4994 - remoting2/branches/2.x/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-14 06:09:59 -0400 (Tue, 14 Apr 2009)
New Revision: 4994
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/InvokerRegistry.java
Log:
JBREM-1116: Eliminated dependence on SecurityUtility.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/InvokerRegistry.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/InvokerRegistry.java 2009-04-14 10:09:35 UTC (rev 4993)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/InvokerRegistry.java 2009-04-14 10:09:59 UTC (rev 4994)
@@ -33,6 +33,9 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -444,9 +447,9 @@
if(transportFactoryClass != null)
{
ClientFactory transportFactory = (ClientFactory)transportFactoryClass.newInstance();
- Method getClientInvokerMethod = SecurityUtility.getMethod(transportFactoryClass,
- "createClientInvoker",
- new Class[] {InvokerLocator.class, Map.class});
+ Method getClientInvokerMethod = getMethod(transportFactoryClass,
+ "createClientInvoker",
+ new Class[] {InvokerLocator.class, Map.class});
clientInvoker = (ClientInvoker)getClientInvokerMethod.invoke(transportFactory, new Object[] {locator, configuration});
}
else
@@ -465,9 +468,9 @@
if(transportFactoryClass != null)
{
ServerFactory transportFactory = (ServerFactory)transportFactoryClass.newInstance();
- Method getServerInvokerMethod = SecurityUtility.getMethod(transportFactoryClass,
- "createServerInvoker",
- new Class[] {InvokerLocator.class, Map.class});
+ Method getServerInvokerMethod = getMethod(transportFactoryClass,
+ "createServerInvoker",
+ new Class[] {InvokerLocator.class, Map.class});
serverInvoker = (ServerInvoker)getServerInvokerMethod.invoke(transportFactory, new Object[] {locator, configuration});
}
else
@@ -675,7 +678,7 @@
transportFactoryClass = getTransportClientFactory(transport);
}
ClientFactory clientFactory = (ClientFactory)transportFactoryClass.newInstance();
- Method meth = SecurityUtility.getMethod(transportFactoryClass, "supportsSSL", new Class[]{});
+ Method meth = getMethod(transportFactoryClass, "supportsSSL", new Class[]{});
Boolean boolVal = (Boolean)meth.invoke(clientFactory, null);
isSSLSupported = boolVal.booleanValue();
}
@@ -783,4 +786,28 @@
}
}
+
+ static private Method getMethod(final Class c, final String name, final Class[] parameterTypes)
+ throws NoSuchMethodException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return c.getMethod(name, parameterTypes);
+ }
+
+ try
+ {
+ return (Method) AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws NoSuchMethodException
+ {
+ return c.getMethod(name, parameterTypes);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (NoSuchMethodException) e.getCause();
+ }
+ }
}
15 years, 7 months
JBoss Remoting SVN: r4993 - remoting2/branches/2.x/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-14 06:09:35 -0400 (Tue, 14 Apr 2009)
New Revision: 4993
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/InvokerLocator.java
Log:
JBREM-1116: Eliminated dependence on SecurityUtility.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/InvokerLocator.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/InvokerLocator.java 2009-04-14 10:09:05 UTC (rev 4992)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/InvokerLocator.java 2009-04-14 10:09:35 UTC (rev 4993)
@@ -369,7 +369,7 @@
}
else
{
- String s = SecurityUtility.getSystemProperty(LEGACY_PARSING);
+ String s = getSystemProperty(LEGACY_PARSING);
doLegacyParsing = "true".equalsIgnoreCase(s);
}
@@ -511,14 +511,14 @@
}
else if(host.indexOf("0.0.0.0") != -1)
{
- String bindAddress = SecurityUtility.getSystemProperty(SERVER_BIND_ADDRESS, "0.0.0.0");
+ String bindAddress = getSystemProperty(SERVER_BIND_ADDRESS, "0.0.0.0");
if(bindAddress.equals("0.0.0.0"))
{
host = fixRemoteAddress(host);
}
else
{
- host = host.replaceAll("0\\.0\\.0\\.0", SecurityUtility.getSystemProperty(SERVER_BIND_ADDRESS));
+ host = host.replaceAll("0\\.0\\.0\\.0", getSystemProperty(SERVER_BIND_ADDRESS));
}
}
return host;
@@ -941,4 +941,52 @@
sb.append(s.substring(fromIndex));
return sb.toString();
}
+
+ static private String getSystemProperty(final String name, final String defaultValue)
+ {
+ if (SecurityUtility.skipAccessControl())
+ return System.getProperty(name, defaultValue);
+
+ String value = null;
+ try
+ {
+ value = (String)AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return System.getProperty(name, defaultValue);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (RuntimeException) e.getCause();
+ }
+
+ return value;
+ }
+
+ static private String getSystemProperty(final String name)
+ {
+ if (SecurityUtility.skipAccessControl())
+ return System.getProperty(name);
+
+ String value = null;
+ try
+ {
+ value = (String)AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return System.getProperty(name);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (RuntimeException) e.getCause();
+ }
+
+ return value;
+ }
}
15 years, 7 months
JBoss Remoting SVN: r4992 - remoting2/branches/2.x/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-14 06:09:05 -0400 (Tue, 14 Apr 2009)
New Revision: 4992
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/Client.java
Log:
JBREM-1116: Eliminated dependence on SecurityUtility.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/Client.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/Client.java 2009-04-14 06:29:01 UTC (rev 4991)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/Client.java 2009-04-14 10:09:05 UTC (rev 4992)
@@ -54,9 +54,12 @@
import java.lang.ref.WeakReference;
import java.net.InetAddress;
import java.net.SocketTimeoutException;
+import java.net.UnknownHostException;
import java.rmi.MarshalException;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -952,7 +955,7 @@
}
if (host == null)
{
- host = SecurityUtility.getLocalHost().getHostAddress();
+ host = getLocalHost().getHostAddress();
metadata.put(CALLBACK_SERVER_HOST, host);
}
if (port == -1)
@@ -1860,4 +1863,41 @@
ref = null;
}
}
+
+ static private InetAddress getLocalHost() throws UnknownHostException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ try
+ {
+ return InetAddress.getLocalHost();
+ }
+ catch (IOException e)
+ {
+ return InetAddress.getByName("127.0.0.1");
+ }
+ }
+
+ try
+ {
+ return (InetAddress) AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws IOException
+ {
+ try
+ {
+ return InetAddress.getLocalHost();
+ }
+ catch (IOException e)
+ {
+ return InetAddress.getByName("127.0.0.1");
+ }
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (UnknownHostException) e.getCause();
+ }
+ }
}
15 years, 7 months
JBoss Remoting SVN: r4991 - remoting2/branches/2.2/docs/guide/en.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-14 02:29:01 -0400 (Tue, 14 Apr 2009)
New Revision: 4991
Modified:
remoting2/branches/2.2/docs/guide/en/chap10.xml
Log:
JBREM-1103: Updated oneway invocation example.
Modified: remoting2/branches/2.2/docs/guide/en/chap10.xml
===================================================================
--- remoting2/branches/2.2/docs/guide/en/chap10.xml 2009-04-14 06:28:34 UTC (rev 4990)
+++ remoting2/branches/2.2/docs/guide/en/chap10.xml 2009-04-14 06:29:01 UTC (rev 4991)
@@ -289,6 +289,13 @@
worker thread on the client side will make the actual invocation on the
server. This is faster of the two modes, but if there is a problem making
the request on the server, the original caller will be unaware.</para>
+
+ <para><emphasis role="bold">NOTE.</emphasis> In the interest of performance,
+ the behavior of the various transports is not required to conform to the
+ preceding description of the first, "server side", mode, in which the invocation
+ is made on the calling thread. In particular, the socket and bisocket transports
+ return immediately after writing the invocation, without waiting for a
+ response from the server.</para>
<para>The OnewayServer is exactly the same as the SimpleServer from the
previous example, with the exception that invocation handler returns null
15 years, 7 months
JBoss Remoting SVN: r4990 - remoting2/branches/2.x/docs/guide/en.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-14 02:28:34 -0400 (Tue, 14 Apr 2009)
New Revision: 4990
Modified:
remoting2/branches/2.x/docs/guide/en/chap11.xml
Log:
JBREM-1103: Updated oneway invocation example.
Modified: remoting2/branches/2.x/docs/guide/en/chap11.xml
===================================================================
--- remoting2/branches/2.x/docs/guide/en/chap11.xml 2009-04-14 05:59:17 UTC (rev 4989)
+++ remoting2/branches/2.x/docs/guide/en/chap11.xml 2009-04-14 06:28:34 UTC (rev 4990)
@@ -290,6 +290,13 @@
server. This is faster of the two modes, but if there is a problem making
the request on the server, the original caller will be unaware.</para>
+ <para><emphasis role="bold">NOTE.</emphasis> In the interest of performance,
+ the behavior of the various transports is not required to conform to the
+ preceding description of the first, "server side", mode, in which the invocation
+ is made on the calling thread. In particular, the socket and bisocket transports
+ return immediately after writing the invocation, without waiting for a
+ response from the server.</para>
+
<para>The OnewayServer is exactly the same as the SimpleServer from the
previous example, with the exception that invocation handler returns null
(since even if did return a response, would not be delivered to the
15 years, 7 months
JBoss Remoting SVN: r4989 - remoting2/branches/2.x/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-14 01:59:17 -0400 (Tue, 14 Apr 2009)
New Revision: 4989
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/Client.java
Log:
JBREM-1103: Updated javadoc for invokeOneway() methods.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/Client.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/Client.java 2009-04-14 05:58:18 UTC (rev 4988)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/Client.java 2009-04-14 05:59:17 UTC (rev 4989)
@@ -632,7 +632,7 @@
* client will not wait for a return.
* <b>
* This is done one of two ways. The first is to pass true as the clientSide param. This will
- * cause the execution of the remote call to be excuted in a new thread on the client side and
+ * cause the execution of the remote call to be executed in a new thread on the client side and
* will return the calling thread before making call to server side.
* <p/>
* The second, is to pass false as the clientSide param. This will allow the current calling
@@ -640,7 +640,8 @@
* the thread will be executed on the remote server in a new executing thread.
* <p>
* NOTE: The treatment of server side oneway invocations may vary with the transport. The
- * client side transport is not required to wait for a reply from the server.
+ * client side transport is not required to wait for a reply from the server. In particular,
+ * the socket and bisocket transports return immediately after writing the invocation.
*/
public void invokeOneway(final Object param, final Map sendPayload, boolean clientSide)
throws Throwable
@@ -844,8 +845,7 @@
/**
* Same as calling invokeOneway(Object param, Map sendPayload, boolean clientSide) with
- * clientSide param being false and a null sendPayload. Therefore, client thread will not return
- * till it has made remote call.
+ * clientSide param being false and a null sendPayload.
*/
public void invokeOneway(Object param) throws Throwable
{
@@ -854,8 +854,7 @@
/**
* Same as calling invokeOneway(Object param, Map sendPayload, boolean clientSide) with
- * clientSide param being false. Therefore, client thread will not return till it has made
- * remote call.
+ * clientSide param being false.
*/
public void invokeOneway(Object param, Map sendPayload) throws Throwable
{
15 years, 7 months
JBoss Remoting SVN: r4988 - remoting2/branches/2.2/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-14 01:58:18 -0400 (Tue, 14 Apr 2009)
New Revision: 4988
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/Client.java
Log:
JBREM-1103: Updated javadoc for invokeOneway() methods.
Modified: remoting2/branches/2.2/src/main/org/jboss/remoting/Client.java
===================================================================
--- remoting2/branches/2.2/src/main/org/jboss/remoting/Client.java 2009-04-14 05:01:03 UTC (rev 4987)
+++ remoting2/branches/2.2/src/main/org/jboss/remoting/Client.java 2009-04-14 05:58:18 UTC (rev 4988)
@@ -566,17 +566,18 @@
* client will not wait for a return.
* <b>
* This is done one of two ways. The first is to pass true as the clientSide param. This will
- * cause the execution of the remote call to be excuted in a new thread on the client side and
+ * cause the execution of the remote call to be executed in a new thread on the client side and
* will return the calling thread before making call to server side. Although, this is optimal
* for performance, will not know about any problems contacting server.
* <p/>
* The second, is to pass false as the clientSide param. This will allow the current calling
* thread to make the call to the remote server, at which point, the server side processing of
* the thread will be executed on the remote server in a new executing thread and the client
- * thread will return. This is a little slower, but will know that the call made it to the
- * server.
- *
- * NOTE: false case is not accurate.
+ * thread will return.
+ * <p>
+ * NOTE: The treatment of server side oneway invocations may vary with the transport. The
+ * client side transport is not required to wait for a reply from the server. In particular,
+ * the socket and bisocket transports return immediately after writing the invocation.
*/
public void invokeOneway(final Object param, final Map sendPayload, boolean clientSide)
throws Throwable
@@ -780,8 +781,7 @@
/**
* Same as calling invokeOneway(Object param, Map sendPayload, boolean clientSide) with
- * clientSide param being false and a null sendPayload. Therefore, client thread will not return
- * till it has made remote call.
+ * clientSide param being false and a null sendPayload.
*/
public void invokeOneway(Object param) throws Throwable
{
@@ -790,8 +790,7 @@
/**
* Same as calling invokeOneway(Object param, Map sendPayload, boolean clientSide) with
- * clientSide param being false. Therefore, client thread will not return till it has made
- * remote call.
+ * clientSide param being false.
*/
public void invokeOneway(Object param, Map sendPayload) throws Throwable
{
15 years, 7 months
JBoss Remoting SVN: r4986 - in remoting2/branches/2.x/src/tests/org/jboss/test/remoting/callback: leak and 1 other directory.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-13 06:33:46 -0400 (Mon, 13 Apr 2009)
New Revision: 4986
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/callback/leak/
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/callback/leak/ServerInvokerCallbackHandlerLeakTestCase.java
Log:
JBREM-1113: New unit tests.
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/callback/leak/ServerInvokerCallbackHandlerLeakTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/callback/leak/ServerInvokerCallbackHandlerLeakTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/callback/leak/ServerInvokerCallbackHandlerLeakTestCase.java 2009-04-13 10:33:46 UTC (rev 4986)
@@ -0,0 +1,279 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.jboss.test.remoting.callback.leak;
+
+import java.lang.reflect.Field;
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.TimerTask;
+
+import javax.management.MBeanServer;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.ConnectionListener;
+import org.jboss.remoting.ConnectionNotifier;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.LeasePinger;
+import org.jboss.remoting.MicroRemoteClientInvoker;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.Callback;
+import org.jboss.remoting.callback.HandleCallbackException;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.callback.ServerInvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+
+
+/**
+ * Unit tests for JBREM-1113.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Apr 13, 2009
+ * </p>
+ */
+public class ServerInvokerCallbackHandlerLeakTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(ServerInvokerCallbackHandlerLeakTestCase.class);
+
+ private static boolean firstTime = true;
+ private static int COUNT = 10;
+ private static Object lock = new Object();
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(Level.INFO);
+ Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
+ String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+ PatternLayout layout = new PatternLayout(pattern);
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ Logger.getRootLogger().addAppender(consoleAppender);
+ }
+ TestConnectionListener.count = 0;
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testLeakWithCallbackHandlersListening() throws Throwable
+ {
+ doLeakTest(true);
+ }
+
+
+ public void testLeakWithoutCallbackHandlersListening() throws Throwable
+ {
+ doLeakTest(false);
+ }
+
+
+ public void doLeakTest(boolean registerCallbackListener) throws Throwable
+ {
+ log.info("entering " + getName());
+ setupServer(registerCallbackListener);
+
+ // Get fields.
+ ServerInvoker serverInvoker = connector.getServerInvoker();
+ Field field = ServerInvoker.class.getDeclaredField("connectionNotifier");
+ field.setAccessible(true);
+ ConnectionNotifier connectionNotifier = (ConnectionNotifier) field.get(serverInvoker);
+ field = ServerInvoker.class.getDeclaredField("callbackHandlers");
+ field.setAccessible(true);
+ Map callbackHandlers = (Map) field.get(serverInvoker);
+
+ // Create client.
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = null;
+
+ for (int i = 0; i < COUNT; i++)
+ {
+ client = new Client(serverLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ TestCallbackHandler callbackHandler = new TestCallbackHandler();
+ client.addListener(callbackHandler, null, null, true);
+ }
+
+ field = MicroRemoteClientInvoker.class.getDeclaredField("leasePinger");
+ field.setAccessible(true);
+ LeasePinger pinger = (LeasePinger) field.get(client.getInvoker());
+ field = LeasePinger.class.getDeclaredField("timerTask");
+ field.setAccessible(true);
+ TimerTask timerTask = (TimerTask) field.get(pinger);
+ timerTask.cancel();
+
+ synchronized(lock)
+ {
+ lock.wait();
+ }
+ Thread.sleep(2000);
+
+ assertEquals(COUNT, TestConnectionListener.count);
+ assertEquals(1, connectionNotifier.size());
+ assertTrue(callbackHandlers.isEmpty());
+
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer(boolean registerCallbackListener) throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ locatorURI += "/?leasing=true";
+ if (registerCallbackListener)
+ {
+ locatorURI += "&" + ServerInvoker.REGISTER_CALLBACK_LISTENER + "=true";
+ }
+ else
+ {
+ locatorURI += "&" + ServerInvoker.REGISTER_CALLBACK_LISTENER + "=false";
+ }
+ serverLocator = new InvokerLocator(locatorURI);
+ log.info("Starting remoting server with locator uri of: " + locatorURI);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraServerConfig(config);
+ connector = new Connector(serverLocator, config);
+ connector.create();
+ invocationHandler = new TestInvocationHandler();
+ connector.addInvocationHandler("test", invocationHandler);
+ connector.start();
+ connector.setLeasePeriod(2000);
+ TestConnectionListener listener = new TestConnectionListener(!registerCallbackListener);
+ connector.addConnectionListener(listener);
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ connector.stop();
+ }
+
+
+ static class TestInvocationHandler implements ServerInvocationHandler
+ {
+ static public Set callbackHandlers = new HashSet();
+ public void addListener(InvokerCallbackHandler callbackHandler)
+ {
+ callbackHandlers.add(callbackHandler);
+ }
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ return invocation.getParameter();
+ }
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
+
+
+ static class TestCallbackHandler implements InvokerCallbackHandler
+ {
+ public void handleCallback(Callback callback) throws HandleCallbackException
+ {
+ log.info("received callback");
+ }
+ }
+
+
+ static class TestConnectionListener implements ConnectionListener
+ {
+ static public int count;
+ boolean shutdownCallbackHandlers;
+
+ public TestConnectionListener(boolean shutdownCallbackHandlers)
+ {
+ this.shutdownCallbackHandlers = shutdownCallbackHandlers;
+ }
+
+ public synchronized void handleConnectionException(Throwable throwable, Client client)
+ {
+ log.info("got connection exception");
+ if(++count == COUNT)
+ {
+ if (shutdownCallbackHandlers)
+ {
+ Iterator it = TestInvocationHandler.callbackHandlers.iterator();
+ while (it.hasNext())
+ {
+ ServerInvokerCallbackHandler callbackHandler = (ServerInvokerCallbackHandler) it.next();
+ callbackHandler.shutdown();
+ log.info("shut down: " + callbackHandler);
+ }
+ TestInvocationHandler.callbackHandlers.clear();
+ }
+ synchronized(lock)
+ {
+ lock.notify();
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
15 years, 7 months