Author: markt
Date: Wed Mar 30 13:35:12 2011
New Revision: 1086950
URL: http://svn.apache.org/viewvc?rev=1086950&view=rev
Log:
Implment Filip's idea for a configurable close method
Modified:
tomcat/trunk/java/org/apache/catalina/deploy/ContextResource.java
tomcat/trunk/java/org/apache/catalina/deploy/LocalStrings.properties
tomcat/trunk/java/org/apache/catalina/deploy/NamingResources.java
tomcat/trunk/webapps/docs/changelog.xml
tomcat/trunk/webapps/docs/config/context.xml
Modified: tomcat/trunk/java/org/apache/catalina/deploy/ContextResource.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/deploy/ContextResource.java?rev=1086950&r1=1086949&r2=1086950&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/deploy/ContextResource.java (original)
+++ tomcat/trunk/java/org/apache/catalina/deploy/ContextResource.java Wed Mar
30 13:35:12 2011
@@ -80,6 +80,24 @@ public class ContextResource extends Res
this.singleton = singleton;
}
+
+ /**
+ * The name of the zero argument method to be called when the resource is
+ * no longer required to clean-up resources. This method must only speed up
+ * the clean-up of resources that would otherwise happen via garbage
+ * collection.
+ */
+ private String closeMethod = "close";
+
+ public String getCloseMethod() {
+ return closeMethod;
+ }
+
+ public void setCloseMethod(String closeMethod) {
+ this.closeMethod = closeMethod;
+ }
+
+
// --------------------------------------------------------- Public Methods
Modified: tomcat/trunk/java/org/apache/catalina/deploy/LocalStrings.properties
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/deploy/LocalStrings.properties?rev=1086950&r1=1086949&r2=1086950&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/deploy/LocalStrings.properties
(original)
+++ tomcat/trunk/java/org/apache/catalina/deploy/LocalStrings.properties Wed
Mar 30 13:35:12 2011
@@ -43,9 +43,9 @@ webxml.unrecognisedPublicId=The public I
webXml.version.nfe=Unable to parse [{0}] from the version string [{1}]. This
component of the version string will be ignored.
webXml.wrongFragmentName=Used a wrong fragment name {0} at web.xml
absolute-ordering tag!
-namingResources.cleanupCloseFailed=Failed to invoke close method for resource
[{0}] in container [{1}] so no cleanup was performed for that resource
-namingResources.cleanupCloseSecurity=Unable to retrieve close method for
resource [{0}] in container [{1}] so no cleanup was performed for that resource
-namingResources.cleanupNoClose=Resource [{0}] in container [{1}] does not have
a close method so no cleanup was performed for that resource
+namingResources.cleanupCloseFailed=Failed to invoke method [{0}] for resource
[{1}] in container [{2}] so no cleanup was performed for that resource
+namingResources.cleanupCloseSecurity=Unable to retrieve method [{0}] for
resource [{1}] in container [{2}] so no cleanup was performed for that resource
+namingResources.cleanupNoClose=Resource [{0}] in container [{1}] does not have
a [{2}] method so no cleanup was performed for that resource
namingResources.cleanupNoContext=Failed to retrieve JNDI naming context for
container [{0}] so no cleanup was performed for that container
namingResources.cleanupNoResource=Failed to retrieve JNDI resource [{0}] for
container [{1}] so no cleanup was performed for that resource
namingResources.mbeanCreateFail=Failed to create MBean for naming resource
[{0}]
Modified: tomcat/trunk/java/org/apache/catalina/deploy/NamingResources.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/deploy/NamingResources.java?rev=1086950&r1=1086949&r2=1086950&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/deploy/NamingResources.java (original)
+++ tomcat/trunk/java/org/apache/catalina/deploy/NamingResources.java Wed Mar
30 13:35:12 2011
@@ -28,7 +28,6 @@ import java.util.HashMap;
import java.util.Hashtable;
import javax.naming.NamingException;
-import javax.sql.DataSource;
import org.apache.catalina.Container;
import org.apache.catalina.Context;
@@ -981,54 +980,57 @@ public class NamingResources extends Lif
return;
}
for (ContextResource cr: resources.values()) {
- if (DataSource.class.getName().equals(cr.getType())) {
+ String closeMethod = cr.getCloseMethod();
+ if (closeMethod != null && closeMethod.length() > 0) {
String name = cr.getName();
- DataSource ds;
+ Object resource;
try {
- ds = (DataSource) ctxt.lookup(name);
+ resource = ctxt.lookup(name);
} catch (NamingException e) {
log.warn(sm.getString("namingResources.cleanupNoResource",
cr.getName(), container), e);
continue;
}
- cleanUp(ds, name);
+ cleanUp(resource, name, cr.getCloseMethod());
}
}
}
/**
- * Closing a database connection pool will close it's open connections.
This
+ * Clean up a resource by calling the defined close method. For example,
+ * closing a database connection pool will close it's open connections.
This
* will happen on GC but that leaves db connections open that may cause
* issues.
- * @param ds The DataSource to close.
+ *
+ * @param resource The resource to close.
*/
- private void cleanUp(DataSource ds, String name) {
+ private void cleanUp(Object resource, String name, String closeMethod) {
// Look for a zero-arg close() method
Method m = null;
try {
- m = ds.getClass().getMethod("close", (Class<?>[]) null);
+ m = resource.getClass().getMethod(closeMethod, (Class<?>[]) null);
} catch (SecurityException e) {
- log.debug(sm.getString("namingResources.cleanupCloseSecurity",
name,
- container));
+ log.debug(sm.getString("namingResources.cleanupCloseSecurity",
+ closeMethod, name, container));
return;
} catch (NoSuchMethodException e) {
- log.debug(sm.getString("namingResources.cleanupNoClose", name,
- container));
+ log.debug(sm.getString("namingResources.cleanupNoClose",
+ name, container, closeMethod));
return;
}
if (m != null) {
try {
- m.invoke(ds, (Object[]) null);
+ m.invoke(resource, (Object[]) null);
} catch (IllegalArgumentException e) {
log.warn(sm.getString("namingResources.cleanupCloseFailed",
- name, container), e);
+ closeMethod, name, container), e);
} catch (IllegalAccessException e) {
log.warn(sm.getString("namingResources.cleanupCloseFailed",
- name, container), e);
+ closeMethod, name, container), e);
} catch (InvocationTargetException e) {
log.warn(sm.getString("namingResources.cleanupCloseFailed",
- name, container), e);
+ closeMethod, name, container), e);
}
}
}
Modified: tomcat/trunk/webapps/docs/changelog.xml
URL:
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1086950&r1=1086949&r2=1086950&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Wed Mar 30 13:35:12 2011
@@ -115,6 +115,10 @@
close on a JNDI resource while it was still available to the
application. (markt)
</fix>
+ <add>
+ Provide a configuration option that lets the close method to be used
for
+ a JNDI Resource to be defined by the user. (markt)
+ </add>
</changelog>
</subsection>
<subsection name="Coyote">
Modified: tomcat/trunk/webapps/docs/config/context.xml
URL:
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/config/context.xml?rev=1086950&r1=1086949&r2=1086950&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/config/context.xml (original)
+++ tomcat/trunk/webapps/docs/config/context.xml Wed Mar 30 13:35:12 2011
@@ -1013,6 +1013,13 @@
application uses a <code><resource-env-ref></code> instead.</p>
</attribute>
+ <attribute name="closeMethod" required="false">
+ <p>Name of zero-argument method to call on the resource when it is no
+ longer required to spped up clean-up of resources that would otherwise
+ happen as part of garbage collection. If not specificed, the default
+ value of <code>close</code> is used.</p>
+ </attribute>
+
<attribute name="description" required="false">
<p>Optional, human-readable description of this resource.</p>
</attribute>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]