You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@river.apache.org by gt...@apache.org on 2011/12/08 16:50:47 UTC

svn commit: r1211940 - in /river/jtsk/trunk: ./ src/com/sun/jini/resource/Service.java src/net/jini/config/ConfigurationProvider.java src/net/jini/export/ServerContext.java

Author: gtrasuk
Date: Thu Dec  8 15:50:47 2011
New Revision: 1211940

URL: http://svn.apache.org/viewvc?rev=1211940&view=rev
Log:
Fix RIVER-149.

Modified:
    river/jtsk/trunk/   (props changed)
    river/jtsk/trunk/src/com/sun/jini/resource/Service.java
    river/jtsk/trunk/src/net/jini/config/ConfigurationProvider.java
    river/jtsk/trunk/src/net/jini/export/ServerContext.java

Propchange: river/jtsk/trunk/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Thu Dec  8 15:50:47 2011
@@ -1,14 +1,16 @@
 classes
-lib-ext
-build.properties
-deps
-configentry
-nbproject
+LICENSE.txt
+River-149-patch-final.diff
+River-149-patch.diff
 build
 .*
 lib-dl
+lib-ext
 lib
-dist
+build.properties
 doc
-LICENSE.txt
+deps
+configentry
+nbproject
 NOTICE.txt
+dist

Modified: river/jtsk/trunk/src/com/sun/jini/resource/Service.java
URL: http://svn.apache.org/viewvc/river/jtsk/trunk/src/com/sun/jini/resource/Service.java?rev=1211940&r1=1211939&r2=1211940&view=diff
==============================================================================
--- river/jtsk/trunk/src/com/sun/jini/resource/Service.java (original)
+++ river/jtsk/trunk/src/com/sun/jini/resource/Service.java Thu Dec  8 15:50:47 2011
@@ -30,6 +30,7 @@ import java.util.List;
 import java.util.NoSuchElementException;
 import java.util.Set;
 import java.util.LinkedHashSet;
+import java.util.logging.Logger;
 
 
 /**
@@ -121,6 +122,9 @@ import java.util.LinkedHashSet;
 
 public final class Service {
 
+	private static final Logger log=
+		Logger.getLogger(Service.class.getName());
+
     private static final String prefix = "META-INF/services/";
 
     private Service() { }
@@ -271,6 +275,9 @@ public final class Service {
 	    try {
 		Class c = Class.forName(cn, true, loader);
 		if (!service.isAssignableFrom(c)) {
+			log.severe("service classloader is "
+					  + service.getClass().getClassLoader()
+					  + ", provider loader is " + loader);
 		    fail(service, "Provider " + cn + " is of incorrect type");
 		}
 		return c.newInstance();

Modified: river/jtsk/trunk/src/net/jini/config/ConfigurationProvider.java
URL: http://svn.apache.org/viewvc/river/jtsk/trunk/src/net/jini/config/ConfigurationProvider.java?rev=1211940&r1=1211939&r2=1211940&view=diff
==============================================================================
--- river/jtsk/trunk/src/net/jini/config/ConfigurationProvider.java (original)
+++ river/jtsk/trunk/src/net/jini/config/ConfigurationProvider.java Thu Dec  8 15:50:47 2011
@@ -177,15 +177,30 @@ public class ConfigurationProvider {
     public static Configuration getInstance(String[] options, ClassLoader cl)
 	throws ConfigurationException
     {
-	ClassLoader resourceLoader = (cl != null) ? cl :
-	    (ClassLoader) Security.doPrivileged(
-		new PrivilegedAction() {
-		    public Object run() {
-			return Thread.currentThread().getContextClassLoader();
-		    }
-		});
+		/*
+		  ClassLoader resourceLoader = (cl != null) ? cl :
+		  (ClassLoader) Security.doPrivileged(
+		  new PrivilegedAction() {
+		  public Object run() {
+		  return Thread.currentThread().getContextClassLoader();
+		  }
+		  });
+		*/
+		ClassLoader resourceLoader=cl;
+		if (resourceLoader == null) {
+			logger.fine("Null class loader provided, fetching context class loader...");
+			resourceLoader = (cl != null) ? cl :
+				(ClassLoader) Security.doPrivileged(
+													new PrivilegedAction() {
+														public Object run() {
+															return Thread.currentThread().getContextClassLoader();
+														}
+													});
+			logger.fine("...resource class loader is now: " + resourceLoader);
+		}
 	final ClassLoader finalResourceLoader = (resourceLoader == null)
 	    ? Utilities.bootstrapResourceLoader : resourceLoader;
+	logger.fine("Final resource class loader is: " + finalResourceLoader);
 	String cname = null;
 	ConfigurationException configEx = null;
 	try {

Modified: river/jtsk/trunk/src/net/jini/export/ServerContext.java
URL: http://svn.apache.org/viewvc/river/jtsk/trunk/src/net/jini/export/ServerContext.java?rev=1211940&r1=1211939&r2=1211940&view=diff
==============================================================================
--- river/jtsk/trunk/src/net/jini/export/ServerContext.java (original)
+++ river/jtsk/trunk/src/net/jini/export/ServerContext.java Thu Dec  8 15:50:47 2011
@@ -15,7 +15,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package net.jini.export;
 
 import com.sun.jini.resource.Service;
@@ -47,18 +46,25 @@ import net.jini.security.Security;
 public final class ServerContext {
 
     private static final ThreadLocal state = new ThreadLocal();
-    private static final ServerContext.Spi[] providers = (ServerContext.Spi[]) 
-	Security.doPrivileged(new PrivilegedAction() {
-	    public Object run() {
-		ClassLoader cl = ClassLoader.getSystemClassLoader();
-		ArrayList list = new ArrayList(1);
-		Iterator i = Service.providers(ServerContext.Spi.class, cl);
-		while (i.hasNext()) {
-		    list.add(i.next());
-		}
-		return list.toArray(new ServerContext.Spi[list.size()]);
-	    }
-	});
+    private static ServerContext.Spi[] providers = null;
+
+    private static ServerContext.Spi[] getProviders() {
+        if (providers == null) {
+            providers = (ServerContext.Spi[]) Security.doPrivileged(new PrivilegedAction() {
+
+                public Object run() {
+                    ClassLoader cl = Thread.currentThread().getContextClassLoader();
+                    ArrayList list = new ArrayList(1);
+                    Iterator i = Service.providers(ServerContext.Spi.class, cl);
+                    while (i.hasNext()) {
+                        list.add(i.next());
+                    }
+                    return list.toArray(new ServerContext.Spi[list.size()]);
+                }
+            });
+        }
+        return providers;
+    }
 
     /**
      * Prevents instantiation.
@@ -88,22 +94,21 @@ public final class ServerContext {
      * @see #getServerContextElement
      **/
     public static void doWithServerContext(Runnable runnable,
-					   Collection context)
-    {
-	if (context == null) {
-	    throw new NullPointerException("context cannot be null");
-	}
-	if (state.get() != null) {
-	    throw new IllegalStateException(
-		"context is already set for this thread");
-	}
-
-	state.set(context);
-	try {
-	    runnable.run();
-	} finally {
-	    state.set(null);
-	}
+            Collection context) {
+        if (context == null) {
+            throw new NullPointerException("context cannot be null");
+        }
+        if (state.get() != null) {
+            throw new IllegalStateException(
+                    "context is already set for this thread");
+        }
+
+        state.set(context);
+        try {
+            runnable.run();
+        } finally {
+            state.set(null);
+        }
     }
 
     /**
@@ -153,20 +158,19 @@ public final class ServerContext {
      *		current thread
      **/
     public static Collection getServerContext()
-	throws ServerNotActiveException
-    {
-	Collection context = (Collection) state.get();
-	if (context == null) {
-	    for (int i = 0; i < providers.length; i++) {
-		if ((context = providers[i].getServerContext()) != null) {
-		    break;
-		}
-	    }
-	}
-	if (context == null) {
-	    throw new ServerNotActiveException("not in remote call");
-	}
-	return context;
+            throws ServerNotActiveException {
+        Collection context = (Collection) state.get();
+        if (context == null) {
+            for (int i = 0; i < getProviders().length; i++) {
+                if ((context = getProviders()[i].getServerContext()) != null) {
+                    break;
+                }
+            }
+        }
+        if (context == null) {
+            throw new ServerNotActiveException("not in remote call");
+        }
+        return context;
     }
 
     /**
@@ -176,22 +180,23 @@ public final class ServerContext {
      * call to {@link ServerContext#doWithServerContext}.
      */
     public interface Spi {
-	/**
-	 * Returns a server context collection for the current thread, or
-	 * <code>null</code> if provider does not contain context for the
-	 * current thread.
-	 * 
-	 * <p>The context information available from a given element of
-	 * the collection is determined by that element's type.  The order
-	 * of the elements is insignificant.  The collection may be empty.
-	 *
-	 * <p>The caller of this method cannot assume that the returned
-	 * collection is modifiable.
-	 *
-	 * @return  the server context for the current thread,
-	 *	    or <code>null</code> if none known
-	 */
-	Collection getServerContext();
+
+        /**
+         * Returns a server context collection for the current thread, or
+         * <code>null</code> if provider does not contain context for the
+         * current thread.
+         * 
+         * <p>The context information available from a given element of
+         * the collection is determined by that element's type.  The order
+         * of the elements is insignificant.  The collection may be empty.
+         *
+         * <p>The caller of this method cannot assume that the returned
+         * collection is modifiable.
+         *
+         * @return  the server context for the current thread,
+         *	    or <code>null</code> if none known
+         */
+        Collection getServerContext();
     }
 
     /**
@@ -209,16 +214,15 @@ public final class ServerContext {
      *		the current thread
      **/
     public static Object getServerContextElement(Class type)
-	throws ServerNotActiveException
-    {
-	Collection context = getServerContext();
-	Iterator iter = context.iterator();
-	while (iter.hasNext()) {
-	    Object elem = iter.next();
-	    if (elem != null && type.isAssignableFrom(elem.getClass())) {
-		return elem;
-	    }
-	}
-	return null;
-    }	
+            throws ServerNotActiveException {
+        Collection context = getServerContext();
+        Iterator iter = context.iterator();
+        while (iter.hasNext()) {
+            Object elem = iter.next();
+            if (elem != null && type.isAssignableFrom(elem.getClass())) {
+                return elem;
+            }
+        }
+        return null;
+    }
 }