You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2004/07/15 16:42:39 UTC
cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/session StandardSession.java
remm 2004/07/15 07:42:39
Modified: catalina/src/share/org/apache/catalina/session
StandardSession.java
Log:
- I looked in the spec, and I don't think the notifications should be sent when "replacing" an attribute with the
same instance.
- Also add some (small) syncs on set and remove so that the HashMap structure doesn't become corrupted.
We'll see if that's really needed, but I don't think this has any noticeable performance impact.
Revision Changes Path
1.46 +21 -21 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/session/StandardSession.java
Index: StandardSession.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/session/StandardSession.java,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -r1.45 -r1.46
--- StandardSession.java 23 Jun 2004 16:59:42 -0000 1.45
+++ StandardSession.java 15 Jul 2004 14:42:38 -0000 1.46
@@ -715,7 +715,7 @@
HttpSessionEvent event = null;
String keys[] = keys();
for (int i = 0; i < keys.length; i++) {
- Object attribute = getAttributeInternal(keys[i]);
+ Object attribute = attributes.get(keys[i]);
if (attribute instanceof HttpSessionActivationListener) {
if (event == null)
event = new HttpSessionEvent(getSession());
@@ -742,7 +742,7 @@
HttpSessionEvent event = null;
String keys[] = keys();
for (int i = 0; i < keys.length; i++) {
- Object attribute = getAttributeInternal(keys[i]);
+ Object attribute = attributes.get(keys[i]);
if (attribute instanceof HttpSessionActivationListener) {
if (event == null)
event = new HttpSessionEvent(getSession());
@@ -1212,20 +1212,27 @@
// Call the valueBound() method if necessary
if (value instanceof HttpSessionBindingListener) {
- event = new HttpSessionBindingEvent(getSession(), name, value);
- try {
- ((HttpSessionBindingListener) value).valueBound(event);
- } catch (Throwable t){
- manager.getContainer().getLogger().error
+ // Don't call any notification if replacing with the same value
+ Object oldValue = attributes.get(name);
+ if (value != oldValue) {
+ event = new HttpSessionBindingEvent(getSession(), name, value);
+ try {
+ ((HttpSessionBindingListener) value).valueBound(event);
+ } catch (Throwable t){
+ manager.getContainer().getLogger().error
(sm.getString("standardSession.bindingEvent"), t);
+ }
}
}
// Replace or add this attribute
- Object unbound = attributes.put(name, value);
+ Object unbound = null;
+ synchronized (attributes) {
+ unbound = attributes.put(name, value);
+ }
// Call the valueUnbound() method if necessary
- if ((unbound != null) &&
+ if ((unbound != null) && (unbound != value) &&
(unbound instanceof HttpSessionBindingListener)) {
try {
((HttpSessionBindingListener) unbound).valueUnbound
@@ -1530,16 +1537,6 @@
/**
- * Return the value of an attribute without a check for validity.
- */
- protected Object getAttributeInternal(String name) {
-
- return (attributes.get(name));
-
- }
-
-
- /**
* Remove the object bound with the specified name from this session. If
* the session does not have an object bound with this name, this method
* does nothing.
@@ -1555,7 +1552,10 @@
protected void removeAttributeInternal(String name, boolean notify) {
// Remove this attribute from our collection
- Object value = attributes.remove(name);
+ Object value = null;
+ synchronized (attributes) {
+ value = attributes.remove(name);
+ }
// Do we need to do valueUnbound() and attributeRemoved() notification?
if (!notify || (value == null)) {
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org