You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hivemind.apache.org by ah...@apache.org on 2007/03/04 15:31:16 UTC
svn commit: r514403 - in /hivemind/hivemind2/trunk:
framework/src/java/org/apache/hivemind/impl/
framework/src/java/org/apache/hivemind/util/
xml/src/java/org/apache/hivemind/parse/
Author: ahuegen
Date: Sun Mar 4 06:31:15 2007
New Revision: 514403
URL: http://svn.apache.org/viewvc?view=rev&rev=514403
Log:
Caching for URL connections disable to prevent jar file locking in web applications
Modified:
hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/impl/MessageFinderImpl.java
hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/impl/RegistryProviderAutoDetector.java
hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/util/IOUtils.java
hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/util/URLResource.java
hivemind/hivemind2/trunk/xml/src/java/org/apache/hivemind/parse/XmlResourceProcessor.java
Modified: hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/impl/MessageFinderImpl.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/impl/MessageFinderImpl.java?view=diff&rev=514403&r1=514402&r2=514403
==============================================================================
--- hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/impl/MessageFinderImpl.java (original)
+++ hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/impl/MessageFinderImpl.java Sun Mar 4 06:31:15 2007
@@ -160,7 +160,7 @@
try
{
- stream = new BufferedInputStream(url.openStream());
+ stream = new BufferedInputStream(IOUtils.openStreamWithoutCaching(url));
result.load(stream);
Modified: hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/impl/RegistryProviderAutoDetector.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/impl/RegistryProviderAutoDetector.java?view=diff&rev=514403&r1=514402&r2=514403
==============================================================================
--- hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/impl/RegistryProviderAutoDetector.java (original)
+++ hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/impl/RegistryProviderAutoDetector.java Sun Mar 4 06:31:15 2007
@@ -15,6 +15,7 @@
package org.apache.hivemind.impl;
import java.io.IOException;
+import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.util.ArrayList;
@@ -28,6 +29,7 @@
import org.apache.commons.logging.LogFactory;
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.ClassResolver;
+import org.apache.hivemind.util.IOUtils;
import org.apache.hivemind.util.URLResource;
/**
@@ -100,15 +102,21 @@
private void processManifestFile(ClassResolver resolver, URLResource resource)
{
URL url = resource.getResourceURL();
+ InputStream manifestStream = null;
Manifest manifest;
try
{
- manifest = new Manifest(url.openStream());
+ manifestStream = IOUtils.openStreamWithoutCaching(url);
+ manifest = new Manifest(manifestStream);
}
catch (IOException e)
{
throw new ApplicationRuntimeException(ImplMessages.unableToReadManifest(url, e),
e);
+ }
+ finally
+ {
+ IOUtils.close(manifestStream);
}
// Search for an entry that defines a provider class
Attributes attributes = manifest.getMainAttributes();
Modified: hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/util/IOUtils.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/util/IOUtils.java?view=diff&rev=514403&r1=514402&r2=514403
==============================================================================
--- hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/util/IOUtils.java (original)
+++ hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/util/IOUtils.java Sun Mar 4 06:31:15 2007
@@ -16,6 +16,8 @@
import java.io.IOException;
import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
/**
* Tiny utilities used with InputStream and friends.
@@ -41,4 +43,21 @@
// Ignored.
}
}
+
+ /**
+ * Opens the input stream of an URL. To prevent jar locking the cache
+ * is disabled before. Jar locking is experiencied under servlet containers on Windows.
+ * (http://tomcat.apache.org/faq/windows.html#lock).
+ * @param url the url
+ * @return the input stream
+ * @throws IOException
+ */
+ public static InputStream openStreamWithoutCaching(URL url) throws IOException
+ {
+ // These call should are equivalent to URL#openStream()
+ URLConnection conn = url.openConnection();
+ conn.setUseCaches(false);
+ return conn.getInputStream();
+ }
+
}
Modified: hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/util/URLResource.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/util/URLResource.java?view=diff&rev=514403&r1=514402&r2=514403
==============================================================================
--- hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/util/URLResource.java (original)
+++ hivemind/hivemind2/trunk/framework/src/java/org/apache/hivemind/util/URLResource.java Sun Mar 4 06:31:15 2007
@@ -61,7 +61,7 @@
try
{
URL test = new URL( getPath() );
- InputStream stream = test.openStream();
+ InputStream stream = IOUtils.openStreamWithoutCaching(test);
if( stream != null )
{
stream.close();
Modified: hivemind/hivemind2/trunk/xml/src/java/org/apache/hivemind/parse/XmlResourceProcessor.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/xml/src/java/org/apache/hivemind/parse/XmlResourceProcessor.java?view=diff&rev=514403&r1=514402&r2=514403
==============================================================================
--- hivemind/hivemind2/trunk/xml/src/java/org/apache/hivemind/parse/XmlResourceProcessor.java (original)
+++ hivemind/hivemind2/trunk/xml/src/java/org/apache/hivemind/parse/XmlResourceProcessor.java Sun Mar 4 06:31:15 2007
@@ -28,6 +28,7 @@
import org.apache.hivemind.ClassResolver;
import org.apache.hivemind.ErrorHandler;
import org.apache.hivemind.Resource;
+import org.apache.hivemind.util.IOUtils;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -115,7 +116,11 @@
{
InputSource source = getInputSource(resource);
- parser.parse(source, contentHandler);
+ try {
+ parser.parse(source, contentHandler);
+ } finally {
+ IOUtils.close(source.getByteStream());
+ }
return contentHandler.getModuleDescriptor();
}
@@ -126,7 +131,7 @@
{
URL url = resource.getResourceURL();
- return new InputSource(url.openStream());
+ return new InputSource(IOUtils.openStreamWithoutCaching(url));
}
catch (Exception e)
{