Author: ron.sigal(a)jboss.com
Date: 2008-02-22 04:37:18 -0500 (Fri, 22 Feb 2008)
New Revision: 3472
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/loading/RemotingClassLoader.java
Log:
JBREM-900: Introduced reference counter.
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/loading/RemotingClassLoader.java
===================================================================
---
remoting2/branches/2.x/src/main/org/jboss/remoting/loading/RemotingClassLoader.java 2008-02-22
09:36:22 UTC (rev 3471)
+++
remoting2/branches/2.x/src/main/org/jboss/remoting/loading/RemotingClassLoader.java 2008-02-22
09:37:18 UTC (rev 3472)
@@ -31,6 +31,7 @@
public class RemotingClassLoader extends ClassLoader
{
private ClassLoader userClassLoader = null;
+ private int referenceCounter;
protected static final Logger log = Logger.getLogger(RemotingClassLoader.class);
protected static final boolean isTrace = log.isTraceEnabled();
@@ -39,7 +40,28 @@
{
super(remotingClassLoader);
this.userClassLoader = userClassLoader;
+ referenceCounter = 1;
}
+
+ public synchronized void setUserClassLoader(ClassLoader userClassLoader)
+ throws Exception
+ {
+ if (userClassLoader == null)
+ {
+ this.userClassLoader = userClassLoader;
+ }
+ else if (this.userClassLoader != userClassLoader)
+ {
+ throw new Exception("Attempting to change existing userClassLoader");
+ }
+ referenceCounter++;
+ }
+
+ public synchronized void unsetUserClassLoader()
+ {
+ if (--referenceCounter == 0)
+ userClassLoader = null;
+ }
public Class loadClass(String name) throws ClassNotFoundException
{