Return-Path:
Delivered-To: apmail-tomcat-dev-archive@www.apache.org
Received: (qmail 59157 invoked from network); 4 Nov 2010 18:00:09 -0000
Received: from unknown (HELO mail.apache.org) (140.211.11.3)
by 140.211.11.9 with SMTP; 4 Nov 2010 18:00:09 -0000
Received: (qmail 27579 invoked by uid 500); 4 Nov 2010 18:00:40 -0000
Delivered-To: apmail-tomcat-dev-archive@tomcat.apache.org
Received: (qmail 27525 invoked by uid 500); 4 Nov 2010 18:00:39 -0000
Mailing-List: contact dev-help@tomcat.apache.org; run by ezmlm
Precedence: bulk
List-Help:
List-Unsubscribe:
List-Post:
List-Id:
Reply-To: "Tomcat Developers List"
Delivered-To: mailing list dev@tomcat.apache.org
Received: (qmail 27516 invoked by uid 99); 4 Nov 2010 18:00:39 -0000
Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230)
by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 Nov 2010 18:00:39 +0000
X-ASF-Spam-Status: No, hits=-2000.0 required=10.0
tests=ALL_TRUSTED
X-Spam-Check-By: apache.org
Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4)
by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 Nov 2010 18:00:36 +0000
Received: by eris.apache.org (Postfix, from userid 65534)
id 3AC80238890D; Thu, 4 Nov 2010 17:59:21 +0000 (UTC)
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: svn commit: r1031112 - in /tomcat/trunk:
java/org/apache/catalina/core/
java/org/apache/catalina/deploy/ java/org/apache/naming/
test/org/apache/naming/resources/ webapps/docs/ webapps/docs/config/
Date: Thu, 04 Nov 2010 17:59:21 -0000
To: dev@tomcat.apache.org
From: markt@apache.org
X-Mailer: svnmailer-1.0.8
Message-Id: <20101104175921.3AC80238890D@eris.apache.org>
X-Virus-Checked: Checked by ClamAV on apache.org
Author: markt
Date: Thu Nov 4 17:59:20 2010
New Revision: 1031112
URL: http://svn.apache.org/viewvc?rev=1031112&view=rev
Log:
https://issues.apache.org/bugzilla/show_bug.cgi?id=50159
Add a new attribute for elements, singleton that controls whether or not a new object is created every time a JNDI lookup is performed to obtain the resource. The default value is true, which will return the same instance of the resource in every JNDI lookup.
Modified:
tomcat/trunk/java/org/apache/catalina/core/NamingContextListener.java
tomcat/trunk/java/org/apache/catalina/deploy/ContextResource.java
tomcat/trunk/java/org/apache/naming/NamingContext.java
tomcat/trunk/java/org/apache/naming/ResourceRef.java
tomcat/trunk/test/org/apache/naming/resources/TestNamingContext.java
tomcat/trunk/webapps/docs/changelog.xml
tomcat/trunk/webapps/docs/config/context.xml
Modified: tomcat/trunk/java/org/apache/catalina/core/NamingContextListener.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/NamingContextListener.java?rev=1031112&r1=1031111&r2=1031112&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/NamingContextListener.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/NamingContextListener.java Thu Nov 4 17:59:20 2010
@@ -849,7 +849,8 @@ public class NamingContextListener
/**
* Set the specified local EJBs in the naming context.
*/
- public void addLocalEjb(ContextLocalEjb localEjb) {
+ public void addLocalEjb(
+ @SuppressWarnings("unused") ContextLocalEjb localEjb) {
// NO-OP
}
@@ -992,7 +993,8 @@ public class NamingContextListener
// Create a reference to the resource.
Reference ref = new ResourceRef
(resource.getType(), resource.getDescription(),
- resource.getScope(), resource.getAuth());
+ resource.getScope(), resource.getAuth(),
+ resource.getSingleton());
// Adding the additional parameters, if any
Iterator params = resource.listProperties();
while (params.hasNext()) {
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=1031112&r1=1031111&r2=1031112&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/deploy/ContextResource.java (original)
+++ tomcat/trunk/java/org/apache/catalina/deploy/ContextResource.java Thu Nov 4 17:59:20 2010
@@ -65,6 +65,21 @@ public class ContextResource extends Res
}
+ /**
+ * Is this resource known to be a singleton resource. The default value is
+ * true since this is what users expect although the JavaEE spec implies
+ * that the default should be false.
+ */
+ private boolean singleton = true;
+
+ public boolean getSingleton() {
+ return singleton;
+ }
+
+ public void setSingleton(boolean singleton) {
+ this.singleton = singleton;
+ }
+
// --------------------------------------------------------- Public Methods
Modified: tomcat/trunk/java/org/apache/naming/NamingContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/naming/NamingContext.java?rev=1031112&r1=1031111&r2=1031112&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/naming/NamingContext.java (original)
+++ tomcat/trunk/java/org/apache/naming/NamingContext.java Thu Nov 4 17:59:20 2010
@@ -825,6 +825,13 @@ public class NamingContext implements Co
try {
Object obj = NamingManager.getObjectInstance
(entry.value, name, this, env);
+ boolean singleton = Boolean.parseBoolean(
+ (String) ((ResourceRef) entry.value).get(
+ "singleton").getContent());
+ if (singleton) {
+ entry.type = NamingEntry.ENTRY;
+ entry.value = obj;
+ }
return obj;
} catch (NamingException e) {
throw e;
Modified: tomcat/trunk/java/org/apache/naming/ResourceRef.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/naming/ResourceRef.java?rev=1031112&r1=1031111&r2=1031112&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/naming/ResourceRef.java (original)
+++ tomcat/trunk/java/org/apache/naming/ResourceRef.java Thu Nov 4 17:59:20 2010
@@ -32,13 +32,13 @@ import javax.naming.StringRefAddr;
* @version $Id$
*/
-public class ResourceRef
- extends Reference {
+public class ResourceRef extends Reference {
+ private static final long serialVersionUID = 1L;
+
// -------------------------------------------------------------- Constants
-
/**
* Default factory for this reference.
*/
@@ -64,6 +64,11 @@ public class ResourceRef
public static final String AUTH = "auth";
+ /**
+ * Is this resource a singleton
+ */
+ public static final String SINGLETON = "singleton";
+
// ----------------------------------------------------------- Constructors
@@ -75,8 +80,8 @@ public class ResourceRef
* @param auth Resource authentication
*/
public ResourceRef(String resourceClass, String description,
- String scope, String auth) {
- this(resourceClass, description, scope, auth, null, null);
+ String scope, String auth, boolean singleton) {
+ this(resourceClass, description, scope, auth, singleton, null, null);
}
@@ -88,8 +93,8 @@ public class ResourceRef
* @param auth Resource authentication
*/
public ResourceRef(String resourceClass, String description,
- String scope, String auth, String factory,
- String factoryLocation) {
+ String scope, String auth, boolean singleton,
+ String factory, String factoryLocation) {
super(resourceClass, factory, factoryLocation);
StringRefAddr refAddr = null;
if (description != null) {
@@ -104,6 +109,9 @@ public class ResourceRef
refAddr = new StringRefAddr(AUTH, auth);
add(refAddr);
}
+ // singleton is a boolean so slightly different handling
+ refAddr = new StringRefAddr(SINGLETON, Boolean.toString(singleton));
+ add(refAddr);
}
Modified: tomcat/trunk/test/org/apache/naming/resources/TestNamingContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/naming/resources/TestNamingContext.java?rev=1031112&r1=1031111&r2=1031112&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/naming/resources/TestNamingContext.java (original)
+++ tomcat/trunk/test/org/apache/naming/resources/TestNamingContext.java Thu Nov 4 17:59:20 2010
@@ -37,7 +37,15 @@ import org.apache.tomcat.util.buf.ByteCh
public class TestNamingContext extends TomcatBaseTest {
- public void testLookup() throws Exception {
+ public void testLookupSingletonResource() throws Exception {
+ doTestLookup(true);
+ }
+
+ public void testLookupNonSingletonResource() throws Exception {
+ doTestLookup(false);
+ }
+
+ public void doTestLookup(boolean useSingletonResource) throws Exception {
Tomcat tomcat = getTomcatInstance();
tomcat.enableNaming();
@@ -50,6 +58,7 @@ public class TestNamingContext extends T
cr.setName("list/foo");
cr.setType("org.apache.naming.resources.TesterObject");
cr.setProperty("factory", "org.apache.naming.resources.TesterFactory");
+ cr.setSingleton(useSingletonResource);
ctx.getNamingResources().addResource(cr);
// Map the test Servlet
@@ -60,7 +69,14 @@ public class TestNamingContext extends T
tomcat.start();
ByteChunk bc = getUrl("http://localhost:" + getPort() + "/");
- assertEquals("OK", bc.toString());
+
+ String expected;
+ if (useSingletonResource) {
+ expected = "EQUAL";
+ } else {
+ expected = "NOTEQUAL";
+ }
+ assertEquals(expected, bc.toString());
}
@@ -80,9 +96,9 @@ public class TestNamingContext extends T
Object obj1 = ctx.lookup("java:comp/env/list/foo");
Object obj2 = ctx.lookup("java:comp/env/list/foo");
if (obj1 == obj2) {
- out.print("FAIL");
+ out.print("EQUAL");
} else {
- out.print("OK");
+ out.print("NOTEQUAL");
}
} catch (NamingException ne) {
ne.printStackTrace(out);
Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1031112&r1=1031111&r2=1031112&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Thu Nov 4 17:59:20 2010
@@ -73,6 +73,13 @@
50157: Ensure MapperListener is only added to a container
object once. (markt)
+
+ 50159: Add a new attribute for <Resource>
+ elements, singleton
, that controls whether or not a new
+ object is created every time a JNDI lookup is performed to obtain the
+ resource. The default value is true
, which will return the
+ same instance of the resource in every JNDI lookup. (markt)
+
Improve debug logging for MapperListener registration. (markt)
Modified: tomcat/trunk/webapps/docs/config/context.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/config/context.xml?rev=1031112&r1=1031111&r2=1031112&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/config/context.xml (original)
+++ tomcat/trunk/webapps/docs/config/context.xml Thu Nov 4 17:59:20 2010
@@ -878,6 +878,16 @@
connections are assumed to be shareable.
+
+ Specify whether this resource definition is for a singleton resource,
+ i.e. one where there is only a single instance of the resource. If this
+ attribute is true
, multiple JNDI lookups for this resource
+ will return the same object. If this attribute is false
,
+ multiple JNDI lookups for this resource will return different objects.
+ The value of this attribute must be true
or
+ false
. By default, this attribute is true
.
+
+
The fully qualified Java class name expected by the web
application when it performs a lookup for this resource.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org