You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by xu...@apache.org on 2010/07/28 04:13:47 UTC
svn commit: r979931 - in /geronimo/server/trunk:
framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/FileUtils.java
plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
Author: xuhaihong
Date: Wed Jul 28 02:13:47 2010
New Revision: 979931
URL: http://svn.apache.org/viewvc?rev=979931&view=rev
Log:
GERONIMO-5474 Improve efficiency of embed jar resources handlering (Patch from Han Hong Fang)
Modified:
geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/FileUtils.java
geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/FileUtils.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/FileUtils.java?rev=979931&r1=979930&r2=979931&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/FileUtils.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/FileUtils.java Wed Jul 28 02:13:47 2010
@@ -17,12 +17,17 @@
package org.apache.geronimo.kernel.util;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
+import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.OutputStream;
+import java.io.OutputStreamWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collection;
@@ -287,6 +292,46 @@ public class FileUtils {
}
}
+ public static String readFileAsString(File file, String encoding, String fileSeparator) {
+ if (file == null || !file.exists()) {
+ return null;
+ }
+ BufferedReader reader = null;
+ try {
+ reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), encoding));
+ StringBuilder stringBuilder = new StringBuilder();
+ String currentLine = null;
+ while ((currentLine = reader.readLine()) != null) {
+ stringBuilder.append(currentLine).append(fileSeparator);
+ }
+ return stringBuilder.toString();
+ } catch (IOException e) {
+ logger.error("Fail to read file " + file.getAbsolutePath() + " as a string", e);
+ return null;
+ } finally {
+ IOUtils.close(reader);
+ }
+ }
+
+ public static String readFileAsString(File file) {
+ return readFileAsString(file, "iso-8859-1", File.separator);
+ }
+
+ public static void writeStringToFile(File file, String line) {
+ writeStringToFile(file, line, "iso-8859-1");
+ }
+
+ public static void writeStringToFile(File file, String line, String encoding) {
+ BufferedWriter writer = null;
+ try {
+ writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), encoding));
+ writer.write(line);
+ } catch (IOException e) {
+ } finally {
+ IOUtils.close(writer);
+ }
+ }
+
private static boolean deleteFile(File file) {
boolean fileDeleted = file.delete();
if (fileDeleted) {
@@ -361,7 +406,7 @@ public class FileUtils {
return name;
}
}
-
+
private FileUtils() {
}
}
Modified: geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java?rev=979931&r1=979930&r2=979931&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java (original)
+++ geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java Wed Jul 28 02:13:47 2010
@@ -16,6 +16,10 @@
*/
package org.apache.geronimo.tomcat;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.beans.PropertyChangeListener;
import java.io.ByteArrayInputStream;
import java.io.File;
@@ -601,7 +605,26 @@ public class GeronimoStandardContext ext
File resourceRootDirectory = new File(tomcatHome + File.separator + "resources" + File.separator + serviceName + File.separator + engineName + File.separator + hostName + File.separator
+ (getName().equals("/") ? "_" : getName()));
File completeFlagFile = new File(resourceRootDirectory, "complete.flag");
+
+ boolean extractionRequired = true;
+ if (completeFlagFile.exists()) {
+ String extractedTimeString = FileUtils.readFileAsString(completeFlagFile, "iso-8859-1", "");
+ if (extractedTimeString != null) {
+ try {
+ long extractedTime = Long.parseLong(extractedTimeString);
+ long lastModifiedTime = bundle.getLastModified();
+ if (extractedTime > lastModifiedTime) {
+ extractionRequired = false;
+ }
+ } catch (Exception e) {
+ logger.warn("Unable to compare the timestamp in the file " + completeFlagFile.getAbsolutePath() + ", resources will be re-extracted", e);
+ //ignore
+ }
+ }
+ }
+
//if (!resourceRootDirectory.exists() || FLUSH_STATIC_RESOURCES_ON_STARTUP || !completeFlagFile.exists()) {
+ if (extractionRequired) {
try {
completeFlagFile.delete();
FileUtils.recursiveDelete(resourceRootDirectory);
@@ -640,9 +663,11 @@ public class GeronimoStandardContext ext
}
}
completeFlagFile.createNewFile();
+ FileUtils.writeStringToFile(completeFlagFile, String.valueOf(System.currentTimeMillis()), "iso-8859-1");
} catch (IOException e) {
throw new DeploymentException("Fail to create static resoruce cache for jar files in WEB-INF folder", e);
}
+ }
//}
for (File resourceDirectory : resourceRootDirectory.listFiles()) {
if (resourceDirectory.isDirectory() && resourceDirectory.getName().endsWith(".jar") && resourceDirectory.listFiles().length > 0) {