axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r561482 - in /webservices/axis2/trunk/java/modules/metadata: src/org/apache/axis2/jaxws/description/impl/DescriptionFactoryImpl.java test/org/apache/axis2/jaxws/description/impl/DescriptionFactoryImplTests.java
Date Tue, 31 Jul 2007 20:21:04 GMT
Author: gawor
Date: Tue Jul 31 13:21:04 2007
New Revision: 561482

URL: http://svn.apache.org/viewvc?view=rev&rev=561482
Log:
added two functions to clear the ServiceDescription cache (addresses part of the problem described
in AXIS2-3011)

Modified:
    webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/DescriptionFactoryImpl.java
    webservices/axis2/trunk/java/modules/metadata/test/org/apache/axis2/jaxws/description/impl/DescriptionFactoryImplTests.java

Modified: webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/DescriptionFactoryImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/DescriptionFactoryImpl.java?view=diff&rev=561482&r1=561481&r2=561482
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/DescriptionFactoryImpl.java
(original)
+++ webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/DescriptionFactoryImpl.java
Tue Jul 31 13:21:04 2007
@@ -117,6 +117,47 @@
     }
 
     /**
+     * Clears the entire ServiceDescription cache.
+     * 
+     * <h4>Note</h4>     
+     * This function might cause unpredictable results when configuration contexts are being
reused
+     * and/or there are outstanding requests using the cached ServiceDescription objects.
+     * 
+     */
+    public static void clearServiceDescriptionCache() {
+        cache.clear();
+    }
+    
+    /**
+     * Clears all the ServiceDescription objects in the cache associated with the specified

+     * configuration context.
+     * 
+     * <h4>Note</h4>
+     * This function should only be used to clear the cache when the specified configuration
context
+     * will not be used anymore and there are no outstanding requests using the associated

+     * ServiceDescription objects. Otherwise, it might cause unpredictable results.
+     * 
+     * @param configContext The configuration context associated with the ServiceDescription

+     *                      objects in the cache.
+     */
+    public static void clearServiceDescriptionCache(ConfigurationContext configContext) {
+        if (configContext == null) {
+            return;
+        }
+        synchronized (configContext) {
+            synchronized (cache) {
+                Iterator<DescriptionKey> iter = cache.keySet().iterator();
+                while (iter.hasNext()) {
+                    DescriptionKey key = iter.next();
+                    if (key.getConfigContext() == configContext) {
+                        iter.remove();
+                    }
+                }
+            }
+        }
+    }    
+    
+    /**
      * @see org.apache.axis2.jaxws.description.DescriptionFactory#createServiceDescriptionFromServiceImpl(Class,
      *      AxisService)
      * @deprecated

Modified: webservices/axis2/trunk/java/modules/metadata/test/org/apache/axis2/jaxws/description/impl/DescriptionFactoryImplTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/test/org/apache/axis2/jaxws/description/impl/DescriptionFactoryImplTests.java?view=diff&rev=561482&r1=561481&r2=561482
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/test/org/apache/axis2/jaxws/description/impl/DescriptionFactoryImplTests.java
(original)
+++ webservices/axis2/trunk/java/modules/metadata/test/org/apache/axis2/jaxws/description/impl/DescriptionFactoryImplTests.java
Tue Jul 31 13:21:04 2007
@@ -19,13 +19,17 @@
 
 package org.apache.axis2.jaxws.description.impl;
 
+import java.lang.reflect.Field;
 import java.net.URL;
 
 import javax.xml.namespace.QName;
 
 import junit.framework.TestCase;
 
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.jaxws.ClientConfigurationFactory;
 import org.apache.axis2.jaxws.description.ServiceDescription;
+import org.apache.axis2.metadata.registry.MetadataFactoryRegistry;
 
 public class DescriptionFactoryImplTests extends TestCase {
     
@@ -34,12 +38,13 @@
     private static final String localPart = "EchoService";
     private static final QName serviceQName = new QName(namespaceURI, localPart);
 
+    
     public void testServiceDescriptionCaching() {        
         QName uniqueQName = new QName(namespaceURI, localPart + "_testValidServiceSubclass");
         
         ServiceDescription desc1 = 
             DescriptionFactoryImpl.createServiceDescription(null, uniqueQName, ServiceSubclass.class);
-                    
+                  
         /*
         int size = 5;
         ServiceDescription desc2; 
@@ -48,13 +53,99 @@
                 DescriptionFactoryImpl.createServiceDescription(null, uniqueQName, ServiceSubclass.class);
             assertTrue("service description was not reused", desc1 == desc2);
         } 
-        */     
-    }   
+        */    
+    }      
 
+    public void testClearServiceDescriptionCache() throws Exception {        
+        QName uniqueQName1 = new QName(namespaceURI, localPart + "_testClearCache1");
+        QName uniqueQName2 = new QName(namespaceURI, localPart + "_testClearCache2");
+  
+        // the ClientConfigFactory instance is stored DescriptionFactoryImpl clientConfigFactory

+        // field and for this test we need to clear it, so that a custom version of 
+        // ClientConfigurationFactory can be used.
+        resetClientConfigFactory();
+        
+        // install caching factory        
+        ClientConfigurationFactory oldFactory = 
+            (ClientConfigurationFactory)MetadataFactoryRegistry.getFactory(ClientConfigurationFactory.class);
+        CachingClientContextFactory newFactory = new CachingClientContextFactory();
+        MetadataFactoryRegistry.setFactory(ClientConfigurationFactory.class, newFactory);
+        
+        try {
+            ServiceDescription desc1 = 
+                DescriptionFactoryImpl.createServiceDescription(null, uniqueQName1, ServiceSubclass.class);
+                        
+            ServiceDescription desc2 = 
+                DescriptionFactoryImpl.createServiceDescription(null, uniqueQName1, ServiceSubclass.class);
+            
+            newFactory.reset();
+            
+            ServiceDescription desc3 = 
+                DescriptionFactoryImpl.createServiceDescription(null, uniqueQName2, ServiceSubclass.class);
+            
+            assertTrue(desc1 == desc2);
+            assertTrue(desc1 != desc3);
+                        
+            // should clear one
+            DescriptionFactoryImpl.clearServiceDescriptionCache(desc2.getAxisConfigContext());
+            
+            ServiceDescription desc4 = 
+                DescriptionFactoryImpl.createServiceDescription(null, uniqueQName1, ServiceSubclass.class);
+                        
+            ServiceDescription desc5 = 
+                DescriptionFactoryImpl.createServiceDescription(null, uniqueQName2, ServiceSubclass.class);
+            
+            assertTrue(desc1 != desc4);
+            assertTrue(desc3 == desc5);
+                       
+            // should clear both
+            DescriptionFactoryImpl.clearServiceDescriptionCache();
+            
+            ServiceDescription desc6 = 
+                DescriptionFactoryImpl.createServiceDescription(null, uniqueQName1, ServiceSubclass.class);
+            
+            ServiceDescription desc7 = 
+                DescriptionFactoryImpl.createServiceDescription(null, uniqueQName2, ServiceSubclass.class);
+            
+            assertTrue(desc4 != desc6);
+            assertTrue(desc3 != desc7);
+            
+            // this should do nothing
+            DescriptionFactoryImpl.clearServiceDescriptionCache(null);
+            
+        } finally {
+            // restore old factory
+            MetadataFactoryRegistry.setFactory(ClientConfigurationFactory.class, oldFactory);
+        }                          
+    }
+    
+    private void resetClientConfigFactory() throws Exception {
+        Field field = DescriptionFactoryImpl.class.getDeclaredField("clientConfigFactory");
+        field.setAccessible(true);
+        field.set(null, null);
+    }
+    
     private static class ServiceSubclass extends javax.xml.ws.Service {
 
         protected ServiceSubclass(URL wsdlDocumentLocation, QName serviceName) {
             super(wsdlDocumentLocation, serviceName);
         }
+    }
+    
+    private static class CachingClientContextFactory extends ClientConfigurationFactory {
+        ConfigurationContext context;
+        
+        public ConfigurationContext getClientConfigurationContext() {
+            if (context == null) {
+                context = super.getClientConfigurationContext();
+            }
+            System.out.println(context);
+            return context;
+        }
+        
+        public void reset() {
+            context = null;
+        }
+        
     }
 }



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


Mime
View raw message