You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by az...@apache.org on 2007/06/21 12:07:12 UTC

svn commit: r549440 - in /webservices/axis2/trunk/java/modules: clustering/src/org/apache/axis2/clustering/context/ clustering/src/org/apache/axis2/clustering/context/commands/ clustering/src/org/apache/axis2/clustering/tribes/ kernel/src/org/apache/ax...

Author: azeez
Date: Thu Jun 21 03:07:11 2007
New Revision: 549440

URL: http://svn.apache.org/viewvc?view=rev&rev=549440
Log:
Adding back the contextAdded & contextRemoved functionalities


Added:
    webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/context/ClusteringContextListener.java
    webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/context/commands/DeleteServiceContextCommand.java
    webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/context/commands/DeleteServiceGroupContextCommand.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ContextListener.java
    webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/context/ContextListenerTest.java
Modified:
    webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/context/ContextClusteringCommandFactory.java
    webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/context/DefaultContextManager.java
    webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesClusterManager.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/clustering/context/ContextManager.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ConfigurationContext.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ServiceContext.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ServiceGroupContext.java

Added: webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/context/ClusteringContextListener.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/context/ClusteringContextListener.java?view=auto&rev=549440
==============================================================================
--- webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/context/ClusteringContextListener.java (added)
+++ webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/context/ClusteringContextListener.java Thu Jun 21 03:07:11 2007
@@ -0,0 +1,34 @@
+/*                                                                             
+ * Copyright 2004,2005 The Apache Software Foundation.                         
+ *                                                                             
+ * Licensed under the Apache License, Version 2.0 (the "License");             
+ * you may not use this file except in compliance with the License.            
+ * You may obtain a copy of the License at                                     
+ *                                                                             
+ *      http://www.apache.org/licenses/LICENSE-2.0                             
+ *                                                                             
+ * Unless required by applicable law or agreed to in writing, software         
+ * distributed under the License is distributed on an "AS IS" BASIS,           
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.    
+ * See the License for the specific language governing permissions and         
+ * limitations under the License.                                              
+ */
+package org.apache.axis2.clustering.context;
+
+import org.apache.axis2.context.ContextListener;
+import org.apache.axis2.context.AbstractContext;
+
+/**
+ * 
+ */
+public class ClusteringContextListener implements ContextListener {
+    public void contextCreated(AbstractContext context) {
+        //TODO: Method implementation
+        System.err.println("$$$$$$$$$$$$$$ Context created: " + context);
+    }
+
+    public void contextRemoved(AbstractContext context) {
+        //TODO: Method implementation
+        System.err.println("$$$$$$$$$$$$$$ Context removed: " + context);
+    }
+}

Modified: webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/context/ContextClusteringCommandFactory.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/context/ContextClusteringCommandFactory.java?view=diff&rev=549440&r1=549439&r2=549440
==============================================================================
--- webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/context/ContextClusteringCommandFactory.java (original)
+++ webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/context/ContextClusteringCommandFactory.java Thu Jun 21 03:07:11 2007
@@ -21,6 +21,8 @@
 import org.apache.axis2.clustering.context.commands.UpdateContextCommand;
 import org.apache.axis2.clustering.context.commands.UpdateServiceContextCommand;
 import org.apache.axis2.clustering.context.commands.UpdateServiceGroupContextCommand;
+import org.apache.axis2.clustering.context.commands.DeleteServiceGroupContextCommand;
+import org.apache.axis2.clustering.context.commands.DeleteServiceContextCommand;
 import org.apache.axis2.clustering.tribes.AckManager;
 import org.apache.axis2.context.AbstractContext;
 import org.apache.axis2.context.ConfigurationContext;
@@ -154,7 +156,8 @@
                     if (prop instanceof Serializable) { // First check whether it is serializable
 
                         // Next check whether it matches an excluded pattern
-                        if (!isExcluded(key, context.getClass().getName(), excludedPropertyPatterns)) {
+                        if (!isExcluded(key, context.getClass().getName(), excludedPropertyPatterns))
+                        {
                             log.debug("sending property =" + key + "-" + prop);
                             PropertyDifference diff = new PropertyDifference(key, prop, false);
                             updateCmd.addProperty(diff);
@@ -203,5 +206,27 @@
             }
         }
         return false;
+    }
+
+    public static ContextClusteringCommand getRemoveCommand(AbstractContext abstractContext) {
+        if (abstractContext instanceof ServiceGroupContext) {
+            ServiceGroupContext sgCtx = (ServiceGroupContext) abstractContext;
+            DeleteServiceGroupContextCommand cmd = new DeleteServiceGroupContextCommand();
+            cmd.setUniqueId(UUIDGenerator.getUUID());
+            cmd.setServiceGroupName(sgCtx.getDescription().getServiceGroupName());
+            cmd.setServiceGroupContextId(sgCtx.getId());
+            
+            return cmd;
+        } else if (abstractContext instanceof ServiceContext) {
+            ServiceContext serviceCtx = (ServiceContext) abstractContext;
+            DeleteServiceContextCommand cmd = new DeleteServiceContextCommand();
+            cmd.setUniqueId(UUIDGenerator.getUUID());
+            cmd.setServiceGroupName(serviceCtx.getGroupName());
+            cmd.setServiceGroupContextId(serviceCtx.getServiceGroupContext().getId());
+            cmd.setServiceName(serviceCtx.getAxisService().getName());
+
+            return cmd;
+        }
+        return null;
     }
 }

Modified: webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/context/DefaultContextManager.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/context/DefaultContextManager.java?view=diff&rev=549440&r1=549439&r2=549440
==============================================================================
--- webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/context/DefaultContextManager.java (original)
+++ webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/context/DefaultContextManager.java Thu Jun 21 03:07:11 2007
@@ -70,6 +70,12 @@
         return cmd.getUniqueId();
     }
 
+    public String removeContext(AbstractContext context) throws ClusteringFault {
+        ContextClusteringCommand cmd = ContextClusteringCommandFactory.getRemoveCommand(context);
+        processor.process(cmd);
+        return cmd.getUniqueId();
+    }
+
     public boolean isContextClusterable(AbstractContext context) {
         return (context instanceof ConfigurationContext) ||
                (context instanceof ServiceContext) ||

Added: webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/context/commands/DeleteServiceContextCommand.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/context/commands/DeleteServiceContextCommand.java?view=auto&rev=549440
==============================================================================
--- webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/context/commands/DeleteServiceContextCommand.java (added)
+++ webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/context/commands/DeleteServiceContextCommand.java Thu Jun 21 03:07:11 2007
@@ -0,0 +1,45 @@
+/*                                                                             
+ * Copyright 2004,2005 The Apache Software Foundation.                         
+ *                                                                             
+ * Licensed under the Apache License, Version 2.0 (the "License");             
+ * you may not use this file except in compliance with the License.            
+ * You may obtain a copy of the License at                                     
+ *                                                                             
+ *      http://www.apache.org/licenses/LICENSE-2.0                             
+ *                                                                             
+ * Unless required by applicable law or agreed to in writing, software         
+ * distributed under the License is distributed on an "AS IS" BASIS,           
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.    
+ * See the License for the specific language governing permissions and         
+ * limitations under the License.                                              
+ */
+package org.apache.axis2.clustering.context.commands;
+
+import org.apache.axis2.clustering.ClusteringFault;
+import org.apache.axis2.clustering.context.ContextClusteringCommand;
+import org.apache.axis2.context.ConfigurationContext;
+
+/**
+ * 
+ */
+public class DeleteServiceContextCommand extends ContextClusteringCommand {
+    protected String serviceGroupName;
+    protected String serviceGroupContextId;
+    protected String serviceName;
+
+    public void setServiceGroupName(String serviceGroupName) {
+        this.serviceGroupName = serviceGroupName;
+    }
+
+    public void setServiceName(String serviceName) {
+        this.serviceName = serviceName;
+    }
+
+    public void setServiceGroupContextId(String serviceGroupContextId) {
+        this.serviceGroupContextId = serviceGroupContextId;
+    }
+
+    public void execute(ConfigurationContext configurationContext) throws ClusteringFault {
+        // TODO: Implementation
+    }
+}

Added: webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/context/commands/DeleteServiceGroupContextCommand.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/context/commands/DeleteServiceGroupContextCommand.java?view=auto&rev=549440
==============================================================================
--- webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/context/commands/DeleteServiceGroupContextCommand.java (added)
+++ webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/context/commands/DeleteServiceGroupContextCommand.java Thu Jun 21 03:07:11 2007
@@ -0,0 +1,40 @@
+/*                                                                             
+ * Copyright 2004,2005 The Apache Software Foundation.                         
+ *                                                                             
+ * Licensed under the Apache License, Version 2.0 (the "License");             
+ * you may not use this file except in compliance with the License.            
+ * You may obtain a copy of the License at                                     
+ *                                                                             
+ *      http://www.apache.org/licenses/LICENSE-2.0                             
+ *                                                                             
+ * Unless required by applicable law or agreed to in writing, software         
+ * distributed under the License is distributed on an "AS IS" BASIS,           
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.    
+ * See the License for the specific language governing permissions and         
+ * limitations under the License.                                              
+ */
+package org.apache.axis2.clustering.context.commands;
+
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.clustering.ClusteringFault;
+import org.apache.axis2.clustering.context.ContextClusteringCommand;
+
+/**
+ * 
+ */
+public class DeleteServiceGroupContextCommand extends ContextClusteringCommand {
+    private String serviceGroupName;
+    private String serviceGroupContextId;
+
+    public void setServiceGroupName(String serviceGroupName) {
+        this.serviceGroupName = serviceGroupName;
+    }
+
+    public void setServiceGroupContextId(String serviceGroupContextId) {
+        this.serviceGroupContextId = serviceGroupContextId;
+    }
+
+    public void execute(ConfigurationContext configurationContext) throws ClusteringFault {
+        // TODO: Implementation
+    }
+}
\ No newline at end of file

Modified: webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesClusterManager.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesClusterManager.java?view=diff&rev=549440&r1=549439&r2=549440
==============================================================================
--- webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesClusterManager.java (original)
+++ webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesClusterManager.java Thu Jun 21 03:07:11 2007
@@ -25,6 +25,7 @@
 import org.apache.axis2.clustering.configuration.DefaultConfigurationManager;
 import org.apache.axis2.clustering.context.ContextManager;
 import org.apache.axis2.clustering.context.DefaultContextManager;
+import org.apache.axis2.clustering.context.ClusteringContextListener;
 import org.apache.axis2.clustering.control.GetStateCommand;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.description.Parameter;
@@ -162,7 +163,7 @@
                             Thread.sleep(tts + 5);
                         }
                     } catch (Exception e) {
-                        e.printStackTrace();
+                        log.error(e);
                         break;
                     }
                     numberOfTries ++;
@@ -170,6 +171,9 @@
                 configurationContext.
                         setNonReplicableProperty(ClusteringConstants.CLUSTER_INITIALIZED,
                                                  "true");
+                ClusteringContextListener contextListener = new ClusteringContextListener();
+                //TODO: May need to set the context listener somewhere to be useful
+                configurationContext.addContextListener(contextListener);
             }
         } catch (ChannelException e) {
             String message = "Error starting Tribes channel";

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/clustering/context/ContextManager.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/clustering/context/ContextManager.java?view=diff&rev=549440&r1=549439&r2=549440
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/clustering/context/ContextManager.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/clustering/context/ContextManager.java Thu Jun 21 03:07:11 2007
@@ -49,6 +49,15 @@
     String updateContexts(AbstractContext[] contexts) throws ClusteringFault;
 
     /**
+     * This method is called when a new {@link AbstractContext} is removed from the system
+     *
+     * @param context
+     * @return The UUID of the message that was sent to the group communications framework
+     * @throws ClusteringFault
+     */
+    String removeContext(AbstractContext context) throws ClusteringFault;
+
+    /**
      * @param context
      * @return True - if the provided {@link AbstractContext}  is clusterable
      */

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ConfigurationContext.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ConfigurationContext.java?view=diff&rev=549440&r1=549439&r2=549440
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ConfigurationContext.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ConfigurationContext.java Thu Jun 21 03:07:11 2007
@@ -37,21 +37,26 @@
 
 import java.io.File;
 import java.net.URL;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
 
 /**
- * <p>Axis2 states are held in two information models, called description hierarchy 
- * and context hierarchy. Description hierarchy hold deployment configuration 
- * and it's values does not change unless deployment configuration change occurs 
- * where Context hierarchy hold run time information. Both hierarchies consists 
- * four levels, Global, Service Group, Operation and Message. Please look at 
+ * <p>Axis2 states are held in two information models, called description hierarchy
+ * and context hierarchy. Description hierarchy hold deployment configuration
+ * and it's values does not change unless deployment configuration change occurs
+ * where Context hierarchy hold run time information. Both hierarchies consists
+ * four levels, Global, Service Group, Operation and Message. Please look at
  * "Information Model" section  of "Axis2 Architecture Guide" for more information.</p>
- * 
+ * <p/>
  * <p>Configuration Context hold Global level run-time information. This allows
- * same configurations to be used by two Axis2 instances and most Axis2 wide 
- * configurations can changed by setting name value pairs of the configurationContext. 
- * This hold all OperationContexts, ServiceGroups, Sessions, and ListenerManager. 
-
+ * same configurations to be used by two Axis2 instances and most Axis2 wide
+ * configurations can changed by setting name value pairs of the configurationContext.
+ * This hold all OperationContexts, ServiceGroups, Sessions, and ListenerManager.
  */
 public class ConfigurationContext extends AbstractContext {
 
@@ -75,6 +80,7 @@
     private String servicePath;
 
     private String cachedServicePath = null;
+    protected List contextListeners;
 
     public ConfigurationContext(AxisConfiguration axisConfiguration) {
         super(null);
@@ -116,6 +122,61 @@
         return !(param != null && JavaUtils.isTrueExplicitly(param.getValue()));
     }
 
+    /**
+     * Inform any listeners of a new context being created
+     *
+     * @param context the just-created subcontext
+     */
+    void contextCreated(AbstractContext context) {
+        if (contextListeners == null) {
+            return;
+        }
+        for (Iterator iter = contextListeners.iterator(); iter.hasNext();) {
+            ContextListener listener = (ContextListener) iter.next();
+            listener.contextCreated(context);
+        }
+    }
+
+    /**
+     * Inform any listeners of a context being removed
+     *
+     * @param context the just-created subcontext
+     */
+    void contextRemoved(AbstractContext context) {
+        if (contextListeners == null) {
+            return;
+        }
+        for (Iterator iter = contextListeners.iterator(); iter.hasNext();) {
+            ContextListener listener = (ContextListener) iter.next();
+            listener.contextRemoved(context);
+        }
+    }
+
+    /**
+     * Register a {@link ContextListener} to be notified of all sub-context events.
+     *
+     * @param contextListener A ContextListener
+     * @see #removeContextListener
+     */
+    public void addContextListener(ContextListener contextListener) {
+        if (contextListeners == null) {
+            contextListeners = new ArrayList();
+        }
+        contextListeners.add(contextListener);
+    }
+
+    /**
+     * Remove an already registered {@link ContextListener}
+     *
+     * @param contextListener A ContextListener
+     * @see #addContextListener
+     */
+    public void removeContextListener(ContextListener contextListener) {
+        if (contextListeners != null) {
+            contextListeners.remove(contextListener);
+        }
+    }
+
     protected void finalize() throws Throwable {
         super.finalize();
     }
@@ -211,7 +272,7 @@
      * If the given message id already has a registered operation context,
      * no change is made and the methid resturns false.
      *
-     * @param messageID the message-id to register
+     * @param messageID  the message-id to register
      * @param mepContext the OperationContext for the specified message-id
      * @return true if we added a new context, false if the messageID was already there and we did
      *         nothing
@@ -220,7 +281,7 @@
                                             OperationContext mepContext) {
         mepContext.setKey(messageID);  // TODO: Doing this here seems dangerous....
         synchronized (operationContextMap) {
-            if  (!operationContextMap.containsKey(messageID)) {
+            if (!operationContextMap.containsKey(messageID)) {
                 this.operationContextMap.put(messageID, mepContext);
                 return true;
             }
@@ -235,11 +296,14 @@
      */
     public void unregisterOperationContext(String key) {
         synchronized (operationContextMap) {
+            OperationContext opCtx = (OperationContext)operationContextMap.get(key);
             operationContextMap.remove(key);
+            contextRemoved(opCtx);
         }
     }
 
-    public void addServiceGroupContextIntoSoapSessionTable(ServiceGroupContext serviceGroupContext) {
+    public void addServiceGroupContextIntoSoapSessionTable(
+            ServiceGroupContext serviceGroupContext) {
         String id = serviceGroupContext.getId();
         serviceGroupContextMap.put(id, serviceGroupContext);
         serviceGroupContext.touch();
@@ -352,7 +416,9 @@
      * @return a new MessageContext
      */
     public MessageContext createMessageContext() {
-        return new MessageContext(this);
+        MessageContext msgCtx = new MessageContext(this);
+        contextCreated(msgCtx);
+        return msgCtx;
     }
 
     /**
@@ -363,7 +429,9 @@
      * @return a new ServiceGroupContext
      */
     public ServiceGroupContext createServiceGroupContext(AxisServiceGroup serviceGroup) {
-        return new ServiceGroupContext(this, serviceGroup);
+        ServiceGroupContext sgCtx = new ServiceGroupContext(this, serviceGroup);
+        contextCreated(sgCtx);
+        return sgCtx;
     }
 
     /**
@@ -434,24 +502,24 @@
     public String[] getServiceGroupContextIDs() {
         String[] ids = new String[serviceGroupContextMap.size() +
                                   applicationSessionServiceGroupContexts.size()];
-        int index =0;
+        int index = 0;
         for (Iterator iter = serviceGroupContextMap.keySet().iterator(); iter.hasNext();) {
-            ids[index] = (String)iter.next();
+            ids[index] = (String) iter.next();
             index ++;
         }
         for (Iterator iter = applicationSessionServiceGroupContexts.keySet().iterator();
              iter.hasNext();) {
-            ids[index] = (String)iter.next();
+            ids[index] = (String) iter.next();
             index ++;
         }
         return ids;
     }
 
     /**
-     * @deprecated Use {@link #getServiceGroupContextIDs} & {@link #getServiceGroupContext(String)}
      * @return The ServiceGroupContexts
+     * @deprecated Use {@link #getServiceGroupContextIDs} & {@link #getServiceGroupContext(String)}
      */
-    public Hashtable getServiceGroupContexts(){
+    public Hashtable getServiceGroupContexts() {
         return serviceGroupContextMap;
     }
 
@@ -493,8 +561,8 @@
             return;
         }
         long currentTime = new Date().getTime();
-        Iterator sgCtxtMapKeyIter = serviceGroupContextMap.keySet().iterator();
-        while (sgCtxtMapKeyIter.hasNext()) {
+        for (Iterator sgCtxtMapKeyIter = serviceGroupContextMap.keySet().iterator();
+             sgCtxtMapKeyIter.hasNext();) {
             String sgCtxtId = (String) sgCtxtMapKeyIter.next();
             ServiceGroupContext serviceGroupContext =
                     (ServiceGroupContext) serviceGroupContextMap.get(sgCtxtId);
@@ -502,6 +570,7 @@
                 getServiceGroupContextTimoutInterval()) {
                 sgCtxtMapKeyIter.remove();
                 cleanupServiceContexts(serviceGroupContext);
+                contextRemoved(serviceGroupContext);
             }
         }
     }
@@ -518,12 +587,12 @@
         if (serviceGroupContext == null) {
             return;
         }
-        Iterator serviceContecxtes = serviceGroupContext.getServiceContexts();
-        if (serviceContecxtes == null) {
+        Iterator serviceContextIter = serviceGroupContext.getServiceContexts();
+        if (serviceContextIter == null) {
             return;
         }
-        while (serviceContecxtes.hasNext()) {
-            ServiceContext serviceContext = (ServiceContext) serviceContecxtes.next();
+        while (serviceContextIter.hasNext()) {
+            ServiceContext serviceContext = (ServiceContext) serviceContextIter.next();
             DependencyManager.destroyServiceObject(serviceContext);
         }
     }
@@ -531,9 +600,9 @@
     public void cleanupContexts() {
         if ((applicationSessionServiceGroupContexts != null) &&
             (applicationSessionServiceGroupContexts.size() > 0)) {
-            Iterator applicationScopeSgs =
+            for (Iterator applicationScopeSgs =
                     applicationSessionServiceGroupContexts.values().iterator();
-            while (applicationScopeSgs.hasNext()) {
+                 applicationScopeSgs.hasNext();) {
                 ServiceGroupContext serviceGroupContext =
                         (ServiceGroupContext) applicationScopeSgs.next();
                 cleanupServiceContexts(serviceGroupContext);
@@ -541,10 +610,10 @@
             applicationSessionServiceGroupContexts.clear();
         }
         if ((serviceGroupContextMap != null) && (serviceGroupContextMap.size() > 0)) {
-            Iterator sopaSessionSgs = serviceGroupContextMap.values().iterator();
-            while (sopaSessionSgs.hasNext()) {
+            for (Iterator soapSessionSgs = serviceGroupContextMap.values().iterator();
+                 soapSessionSgs.hasNext();) {
                 ServiceGroupContext serviceGroupContext =
-                        (ServiceGroupContext) sopaSessionSgs.next();
+                        (ServiceGroupContext) soapSessionSgs.next();
                 cleanupServiceContexts(serviceGroupContext);
             }
             serviceGroupContextMap.clear();
@@ -564,10 +633,10 @@
      * release to 1.3 release. This will include API changes , class
      * deprecating etc etc.
      */
-    private void cleanupTemp(){
-        File tempFile =  (File)axisConfiguration.getParameterValue(
+    private void cleanupTemp() {
+        File tempFile = (File) axisConfiguration.getParameterValue(
                 Constants.Configuration.ARTIFACTS_TEMP_DIR);
-        if(tempFile==null){
+        if (tempFile == null) {
             tempFile = new File(System.getProperty("java.io.tmpdir"), "_axis2");
         }
         deleteTempFiles(tempFile);
@@ -576,7 +645,7 @@
     private void deleteTempFiles(File dir) {
         if (dir.isDirectory()) {
             String[] children = dir.list();
-            for (int i=0; i<children.length; i++) {
+            for (int i = 0; i < children.length; i++) {
                 deleteTempFiles(new File(dir, children[i]));
             }
         }

Added: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ContextListener.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ContextListener.java?view=auto&rev=549440
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ContextListener.java (added)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ContextListener.java Thu Jun 21 03:07:11 2007
@@ -0,0 +1,38 @@
+/*                                                                             
+ * Copyright 2004,2005 The Apache Software Foundation.                         
+ *                                                                             
+ * Licensed under the Apache License, Version 2.0 (the "License");             
+ * you may not use this file except in compliance with the License.            
+ * You may obtain a copy of the License at                                     
+ *                                                                             
+ *      http://www.apache.org/licenses/LICENSE-2.0                             
+ *                                                                             
+ * Unless required by applicable law or agreed to in writing, software         
+ * distributed under the License is distributed on an "AS IS" BASIS,           
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.    
+ * See the License for the specific language governing permissions and         
+ * limitations under the License.                                              
+ */
+package org.apache.axis2.context;
+
+/**
+ * A ContextListener gets informed about new context creations & removal of existing contexts.
+ * Register one with a ConfigurationContext and you'll get notifications for every
+ * sub-context creation & removal event.
+ */
+public interface ContextListener {
+
+    /**
+     * A context has been added
+     *
+     * @param context
+     */
+    void contextCreated(AbstractContext context);
+
+    /**
+     * A context has been removed
+     *
+     * @param context
+     */
+    void contextRemoved(AbstractContext context);
+}

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ServiceContext.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ServiceContext.java?view=diff&rev=549440&r1=549439&r2=549440
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ServiceContext.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ServiceContext.java Thu Jun 21 03:07:11 2007
@@ -157,6 +157,7 @@
 
     public OperationContext createOperationContext(AxisOperation axisOp) {
         OperationContext ctx = new OperationContext(axisOp, this);
+        configContext.contextCreated(ctx);
         return ctx;
     }
 

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ServiceGroupContext.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ServiceGroupContext.java?view=diff&rev=549440&r1=549439&r2=549440
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ServiceGroupContext.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ServiceGroupContext.java Thu Jun 21 03:07:11 2007
@@ -142,6 +142,7 @@
         ServiceContext serviceContext = (ServiceContext) serviceContextMap.get(service.getName());
         if (serviceContext == null) {
             serviceContext = new ServiceContext(service, this);
+            getRootContext().contextCreated(serviceContext);
             serviceContextMap.put(service.getName(), serviceContext);
         }
         return serviceContext;
@@ -161,7 +162,6 @@
         this.id = id;
     }
 
-
     /**
      * Adds the specified service context object to the
      * lists of service contexts for this service group
@@ -204,7 +204,6 @@
             return null;
         }
 
-        // a map allows a null key
         return (ServiceContext) serviceContextMap.get(name);
     }
 

Added: webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/context/ContextListenerTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/context/ContextListenerTest.java?view=auto&rev=549440
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/context/ContextListenerTest.java (added)
+++ webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/context/ContextListenerTest.java Thu Jun 21 03:07:11 2007
@@ -0,0 +1,94 @@
+/*                                                                             
+ * Copyright 2004,2005 The Apache Software Foundation.                         
+ *                                                                             
+ * Licensed under the Apache License, Version 2.0 (the "License");             
+ * you may not use this file except in compliance with the License.            
+ * You may obtain a copy of the License at                                     
+ *                                                                             
+ *      http://www.apache.org/licenses/LICENSE-2.0                             
+ *                                                                             
+ * Unless required by applicable law or agreed to in writing, software         
+ * distributed under the License is distributed on an "AS IS" BASIS,           
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.    
+ * See the License for the specific language governing permissions and         
+ * limitations under the License.                                              
+ */
+package org.apache.axis2.context;
+
+import junit.framework.TestCase;
+import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.AxisServiceGroup;
+import org.apache.axis2.description.InOutAxisOperation;
+import org.apache.axis2.engine.AxisConfiguration;
+
+import javax.xml.namespace.QName;
+
+/**
+ * 
+ */
+public class ContextListenerTest extends TestCase {
+    static class MyListener implements ContextListener {
+        private AbstractContext lastContext;
+
+        public void contextCreated(AbstractContext context) {
+            lastContext = context;
+        }
+
+        public void contextRemoved(AbstractContext context) {
+            //TODO: Method implementation
+
+        }
+
+        public AbstractContext getLastContext() {
+            return lastContext;
+        }
+    }
+
+    /**
+     * Confirm that creating contexts at various levels correctly causes notifications to
+     * ContextListeners that are registered on a given ConfigurationContext.
+     *
+     * @throws Exception if an error occurs
+     */
+    public void testContextListener() throws Exception {
+        // Set up metadata
+        AxisConfiguration axisConfig = new AxisConfiguration();
+        ConfigurationContext configCtx = new ConfigurationContext(axisConfig);
+        AxisServiceGroup serviceGroup = new AxisServiceGroup(axisConfig);
+        AxisService service = new AxisService("TestService");
+        AxisOperation operation = new InOutAxisOperation(new QName("ns", "op1"));
+        service.addOperation(operation);
+        serviceGroup.addService(service);
+
+        // Register a listener and make sure it starts out clean
+        MyListener listener = new MyListener();
+        configCtx.addContextListener(listener);
+        assertNull(listener.getLastContext());
+
+        MessageContext mc = configCtx.createMessageContext();
+        assertNotNull(mc);
+        assertEquals("MessageContext not stored", mc, listener.getLastContext());
+
+        ServiceGroupContext sgc = configCtx.createServiceGroupContext(serviceGroup);
+        assertNotNull(sgc);
+        assertEquals("ServiceGroupContext not stored", sgc, listener.getLastContext());
+
+        ServiceContext sc = sgc.getServiceContext(service);
+        assertNotNull(sc);
+        assertEquals("ServiceContext not stored", sc, listener.getLastContext());
+
+        OperationContext oc = sc.createOperationContext(operation);
+        assertNotNull(oc);
+        assertEquals("OperationContext not stored", oc, listener.getLastContext());
+
+        // Try a second listener and make sure they both get notified
+        MyListener listener2 = new MyListener();
+        configCtx.addContextListener(listener2);
+
+        mc = configCtx.createMessageContext();
+        assertNotNull(mc);
+        assertEquals("MessageContext not stored", mc, listener.getLastContext());
+        assertEquals("MessageContext not stored in listener 2", mc, listener2.getLastContext());
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org