You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2013/05/16 15:43:11 UTC
svn commit: r1483360 -
/tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java
Author: markt
Date: Thu May 16 13:43:11 2013
New Revision: 1483360
URL: http://svn.apache.org/r1483360
Log:
Reload rather than redeploy a web application when XML and external WAR are present and the WAR is updated. No need to redeploy since the XML won't change.
Modified:
tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java
Modified: tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java?rev=1483360&r1=1483359&r2=1483360&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java Thu May 16 13:43:11 2013
@@ -1167,7 +1167,22 @@ public class HostConfig
app.redeployResources.get(resources[i]).longValue();
if ((!resource.isDirectory()) &&
resource.lastModified() > lastModified) {
- // Undeploy application
+ // Skip over resources we can't delete such as external WARs
+ while (!isDeletableResource(resource)) {
+ // Update last modified for this resource so this
+ // doesn't trigger again next check
+ app.redeployResources.put(resources[i],
+ Long.valueOf(System.currentTimeMillis()));
+ i++;
+ if (i < resources.length) {
+ resource = new File(resources[i]);
+ } else {
+ // Modified resource - need to reload
+ reload(app);
+ return;
+ }
+ }
+ // This will trigger a redeploy
deleteRedeployResources(app, resources, i, false);
return;
}
@@ -1204,22 +1219,7 @@ public class HostConfig
if ((!resource.exists() && lastModified != 0L)
|| (resource.lastModified() != lastModified)) {
// Reload application
- if(log.isInfoEnabled())
- log.info(sm.getString("hostConfig.reload", app.name));
- Context context = (Context) host.findChild(app.name);
- if (context.getState().isAvailable()) {
- // Reload catches and logs exceptions
- context.reload();
- } else {
- // If the context was not started (for example an error
- // in web.xml) we'll still get to try to start
- try {
- context.start();
- } catch (Exception e) {
- log.warn(sm.getString
- ("hostConfig.context.restart", app.name), e);
- }
- }
+ reload(app);
// Update times
app.reloadResources.put(resources[i],
Long.valueOf(resource.lastModified()));
@@ -1230,6 +1230,26 @@ public class HostConfig
}
+ private void reload(DeployedApplication app) {
+ if(log.isInfoEnabled())
+ log.info(sm.getString("hostConfig.reload", app.name));
+ Context context = (Context) host.findChild(app.name);
+ if (context.getState().isAvailable()) {
+ // Reload catches and logs exceptions
+ context.reload();
+ } else {
+ // If the context was not started (for example an error
+ // in web.xml) we'll still get to try to start
+ try {
+ context.start();
+ } catch (Exception e) {
+ log.warn(sm.getString
+ ("hostConfig.context.restart", app.name), e);
+ }
+ }
+ }
+
+
private void deleteRedeployResources(DeployedApplication app,
String[] resources, int i, boolean deleteReloadResources) {
@@ -1256,11 +1276,7 @@ public class HostConfig
}
// Only delete resources in the appBase or the
// host's configBase
- if ((current.getAbsolutePath().startsWith(
- host.getAppBaseFile().getAbsolutePath() +
- File.separator))
- || (current.getAbsolutePath().startsWith(
- host.getConfigBaseFile().getAbsolutePath()))) {
+ if (isDeletableResource(current)) {
if (log.isDebugEnabled())
log.debug("Delete " + current);
ExpandWar.delete(current);
@@ -1286,11 +1302,7 @@ public class HostConfig
}
// Only delete resources in the appBase or the host's
// configBase
- if ((current.getAbsolutePath().startsWith(
- host.getAppBaseFile().getAbsolutePath() + File.separator))
- || ((current.getAbsolutePath().startsWith(
- host.getConfigBaseFile().getAbsolutePath())
- && (current.getAbsolutePath().endsWith(".xml"))))) {
+ if (isDeletableResource(current)) {
if (log.isDebugEnabled())
log.debug("Delete " + current);
ExpandWar.delete(current);
@@ -1305,6 +1317,19 @@ public class HostConfig
deployed.remove(app.name);
}
+
+ private boolean isDeletableResource(File resource) {
+ if ((resource.getAbsolutePath().startsWith(
+ host.getAppBaseFile().getAbsolutePath() + File.separator))
+ || ((resource.getAbsolutePath().startsWith(
+ host.getConfigBaseFile().getAbsolutePath())
+ && (resource.getAbsolutePath().endsWith(".xml"))))) {
+ return true;
+ }
+ return false;
+ }
+
+
/**
* Process a "start" event for this Host.
*/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org