fixes for
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 27 Mar 2007 04:44:06 +0000 (04:44 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 27 Mar 2007 04:44:06 +0000 (04:44 +0000)
http://issues.apache.org/bugzilla/show_bug.cgi?id=41166
although there is still work to be done, need to separate Tomcat attributes vs. application attributes

git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@522745 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/core/ApplicationContext.java
java/org/apache/catalina/ha/context/ReplicatedContext.java
java/org/apache/catalina/tribes/tipis/AbstractReplicatedMap.java

index d313820..c6999d2 100644 (file)
@@ -804,12 +804,17 @@ public class ApplicationContext
 
 
     // -------------------------------------------------------- Package Methods
-
-
+    protected StandardContext getContext() {
+        return this.context;
+    }
+    
+    protected Map getReadonlyAttributes() {
+        return this.readOnlyAttributes;
+    }
     /**
      * Clear all application-created attributes.
      */
-    void clearAttributes() {
+    protected void clearAttributes() {
 
         // Create list of attributes to be removed
         ArrayList list = new ArrayList();
index ee36b2e..a108e57 100644 (file)
@@ -26,6 +26,11 @@ import org.apache.catalina.core.ApplicationContext;
 import org.apache.catalina.Globals;
 import javax.servlet.ServletContext;
 import java.util.AbstractMap;
+import org.apache.catalina.tribes.tipis.AbstractReplicatedMap;
+import java.util.ArrayList;
+import java.util.Iterator;
+import javax.servlet.ServletContextAttributeListener;
+import javax.servlet.ServletContextAttributeEvent;
 
 /**
  * @author Filip Hanik
@@ -98,6 +103,12 @@ public class ReplicatedContext extends StandardContext {
     }
     
     public ServletContext getServletContext() {
+        if (context == null) {
+            context = new ReplApplContext(getBasePath(), this);
+            if (getAltDDName() != null)
+                context.setAttribute(Globals.ALT_DD_ATTR,getAltDDName());
+        }
+
         return ((ReplApplContext)context).getFacade();
 
     }
@@ -118,8 +129,19 @@ public class ReplicatedContext extends StandardContext {
         public void setAttributeMap(AbstractMap map) {
             this.attributes = map;
         }
-
+        
+        public void removeAttribute(String name) {
+            //do nothing
+            super.removeAttribute(name);
+        }
+        
+        public void setAttribute(String name, Object value) {
+            //do nothing
+            super.setAttribute(name,value);
+        }
+        
     }
 
 
+
 }
\ No newline at end of file
index 6ab41fe..5e25a6b 100644 (file)
@@ -747,10 +747,13 @@ public abstract class AbstractReplicatedMap extends ConcurrentHashMap implements
      * @return Object
      */
     public Object remove(Object key) {
+        return remove(key,true);
+    }
+    public Object remove(Object key, boolean notify) {
         MapEntry entry = (MapEntry)super.remove(key);
 
         try {
-            if (getMapMembers().length > 0 ) {
+            if (getMapMembers().length > 0 && notify) {
                 MapMessage msg = new MapMessage(getMapContextName(), MapMessage.MSG_REMOVE, false, (Serializable) key, null, null, null);
                 getChannel().send(getMapMembers(), msg, getChannelSendOptions());
             }
@@ -885,11 +888,20 @@ public abstract class AbstractReplicatedMap extends ConcurrentHashMap implements
                 put(entry.getKey(),entry.getValue());
             }
         }
-    
+        
         public void clear() {
-            //only delete active keys
-            Iterator keys = keySet().iterator();
-            while ( keys.hasNext() ) remove(keys.next());
+            clear(true);
+        }
+    
+        public void clear(boolean notify) {
+            if ( notify ) {
+                //only delete active keys
+                Iterator keys = keySet().iterator();
+                while (keys.hasNext())
+                    remove(keys.next());
+            } else {
+                super.clear();
+            }
         }
     
         public boolean containsValue(Object value) {
@@ -933,8 +945,9 @@ public abstract class AbstractReplicatedMap extends ConcurrentHashMap implements
             Iterator i = super.entrySet().iterator();
             while ( i.hasNext() ) {
                 Map.Entry e = (Map.Entry)i.next();
-                MapEntry entry = (MapEntry)e.getValue();
-                if ( entry.isPrimary() ) set.add(entry);
+                Object key = e.getKey();
+                MapEntry entry = (MapEntry)super.get(key);
+                if ( entry.isPrimary() ) set.add(entry.getValue());
             }
             return Collections.unmodifiableSet(set);
         }
@@ -946,10 +959,12 @@ public abstract class AbstractReplicatedMap extends ConcurrentHashMap implements
             Iterator i = super.entrySet().iterator();
             while ( i.hasNext() ) {
                 Map.Entry e = (Map.Entry)i.next();
-                MapEntry entry = (MapEntry)e.getValue();
-                if ( entry.isPrimary() ) set.add(entry.getKey());
+                Object key = e.getKey();
+                MapEntry entry = (MapEntry)super.get(key);
+                if ( entry.isPrimary() ) set.add(key);
             }
             return Collections.unmodifiableSet(set);
+
         }
     
     
@@ -1056,7 +1071,7 @@ public abstract class AbstractReplicatedMap extends ConcurrentHashMap implements
 
         public Object setValue(Object value) {
             Object old = this.value;
-            this.value = (Serializable) value;
+            this.value = value;
             return old;
         }
 
@@ -1066,7 +1081,7 @@ public abstract class AbstractReplicatedMap extends ConcurrentHashMap implements
         
         public Object setKey(Object key) {
             Object old = this.key;
-            this.key = (Serializable)key;
+            this.key = key;
             return old;
         }