Commit 15b68e02 by Michael Koch Committed by Michael Koch

2003-08-02 Michael Koch <konqueror@gmx.de>

	* java/net/URL.java
	(URL): Added paragraph about the
	gnu.java.net.nocache_protocol_handlers property.
	(ph_cache): Renamed from handlers to match classpath's implementation.
	Reordered it with factory and serialVersionUID member variables.
	(cache_handlers): New member variable.
	(static): New static initializer to initialize cache_handlers from
	gnu.java.net.nocache_protocol_handlers property.
	(URL): Use ph_cache instead of handlers, reformatted some code to
	match classpath's implementation.

From-SVN: r70098
parent f53b62e1
2003-08-02 Michael Koch <konqueror@gmx.de>
* java/net/URL.java
(URL): Added paragraph about the
gnu.java.net.nocache_protocol_handlers property.
(ph_cache): Renamed from handlers to match classpath's implementation.
Reordered it with factory and serialVersionUID member variables.
(cache_handlers): New member variable.
(static): New static initializer to initialize cache_handlers from
gnu.java.net.nocache_protocol_handlers property.
(URL): Use ph_cache instead of handlers, reformatted some code to
match classpath's implementation.
2003-08-01 Tom Tromey <tromey@redhat.com> 2003-08-01 Tom Tromey <tromey@redhat.com>
Fix for PR libgcj/11241: Fix for PR libgcj/11241:
......
...@@ -98,6 +98,14 @@ import java.util.StringTokenizer; ...@@ -98,6 +98,14 @@ import java.util.StringTokenizer;
* <p> * <p>
* Please note that a protocol handler must be a subclass of * Please note that a protocol handler must be a subclass of
* URLStreamHandler. * URLStreamHandler.
* <p>
* Normally, this class caches protocol handlers. Once it finds a handler
* for a particular protocol, it never tries to look up a new handler
* again. However, if the system property
* gnu.java.net.nocache_protocol_handlers is set, then this
* caching behavior is disabled. This property is specific to this
* implementation. Sun's JDK may or may not do protocol caching, but it
* almost certainly does not examine this property.
* *
* @author Aaron M. Renn <arenn@urbanophile.com> * @author Aaron M. Renn <arenn@urbanophile.com>
* @author Warren Levy <warrenl@cygnus.com> * @author Warren Levy <warrenl@cygnus.com>
...@@ -150,18 +158,32 @@ public final class URL implements Serializable ...@@ -150,18 +158,32 @@ public final class URL implements Serializable
transient URLStreamHandler ph; transient URLStreamHandler ph;
/** /**
* If an application installs its own protocol handler factory, this is
* where we keep track of it.
*/
private static URLStreamHandlerFactory factory;
private static final long serialVersionUID = -7627629688361524110L;
/**
* This a table where we cache protocol handlers to avoid the overhead * This a table where we cache protocol handlers to avoid the overhead
* of looking them up each time. * of looking them up each time.
*/ */
private static Hashtable handlers = new Hashtable(); private static Hashtable ph_cache = new Hashtable();
/** /**
* If an application installs its own protocol handler factory, this is * Whether or not to cache protocol handlers.
* where we keep track of it.
*/ */
private static URLStreamHandlerFactory factory; private static boolean cache_handlers;
private static final long serialVersionUID = -7627629688361524110L; static
{
String s = System.getProperty("gnu.java.net.nocache_protocol_handlers");
if (s == null)
cache_handlers = true;
else
cache_handlers = false;
}
/** /**
* Constructs a URL and loads a protocol handler for the values passed as * Constructs a URL and loads a protocol handler for the values passed as
...@@ -732,12 +754,14 @@ public final class URL implements Serializable ...@@ -732,12 +754,14 @@ public final class URL implements Serializable
URLStreamHandler ph; URLStreamHandler ph;
// See if a handler has been cached for this protocol. // See if a handler has been cached for this protocol.
if ((ph = (URLStreamHandler) handlers.get(protocol)) != null) if ((ph = (URLStreamHandler) ph_cache.get(protocol)) != null)
return ph; return ph;
// If a non-default factory has been set, use it to find the protocol. // If a non-default factory has been set, use it to find the protocol.
if (factory != null) if (factory != null)
ph = factory.createURLStreamHandler(protocol); {
ph = factory.createURLStreamHandler(protocol);
}
else if (protocol.equals ("core")) else if (protocol.equals ("core"))
{ {
ph = new gnu.gcj.protocol.core.Handler (); ph = new gnu.gcj.protocol.core.Handler ();
...@@ -788,9 +812,10 @@ public final class URL implements Serializable ...@@ -788,9 +812,10 @@ public final class URL implements Serializable
} }
// Update the hashtable with the new protocol handler. // Update the hashtable with the new protocol handler.
if (ph != null) if (ph != null
&& cache_handlers)
if (ph instanceof URLStreamHandler) if (ph instanceof URLStreamHandler)
handlers.put(protocol, ph); ph_cache.put(protocol, ph);
else else
ph = null; ph = null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment