ode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From boisv...@apache.org
Subject svn commit: r545256 - /incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ExternalService.java
Date Thu, 07 Jun 2007 18:23:44 GMT
Author: boisvert
Date: Thu Jun  7 11:23:43 2007
New Revision: 545256

URL: http://svn.apache.org/viewvc?view=rev&rev=545256
Log:
Cache Axis2 ServiceClients, for they are rather heavyweight

Modified:
    incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ExternalService.java

Modified: incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ExternalService.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ExternalService.java?view=diff&rev=545256&r1=545255&r2=545256
==============================================================================
--- incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ExternalService.java (original)
+++ incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ExternalService.java Thu
Jun  7 11:23:43 2007
@@ -62,6 +62,10 @@
 
     private static final Log __log = LogFactory.getLog(ExternalService.class);
 
+    private static final int EXPIRE_SERVICE_CLIENT = 30000;
+
+    private static ThreadLocal<CachedServiceClient> _cachedClients = new ThreadLocal<CachedServiceClient>();
+
     private ExecutorService _executorService;
     private Definition _definition;
     private QName _serviceName;
@@ -108,9 +112,16 @@
             options.setAction(soapAction);
             options.setTimeOutInMilliSeconds(60000);
 
-            ConfigurationContext ctx = new ConfigurationContext(_axisConfig);
-            ServiceClient sclient = new ServiceClient(ctx, null);
-            final OperationClient operationClient = sclient.createClient(isTwoWay ? ServiceClient.ANON_OUT_IN_OP
+            CachedServiceClient cached = _cachedClients.get();
+            long now = System.currentTimeMillis();
+            if (cached == null || cached._expire < now) {
+                cached = new CachedServiceClient();
+                ConfigurationContext ctx = new ConfigurationContext(_axisConfig);
+                cached._client = new ServiceClient(ctx, null);
+                cached._expire = now+EXPIRE_SERVICE_CLIENT;
+                _cachedClients.set(cached);
+            }
+            final OperationClient operationClient = cached._client.createClient(isTwoWay
? ServiceClient.ANON_OUT_IN_OP
                     : ServiceClient.ANON_OUT_ONLY_OP);
             operationClient.setOptions(options);
 
@@ -323,6 +334,12 @@
             String errmsg = "Error executing reply transaction; reply will be lost.";
             __log.error(errmsg, e);
         }
+    }
+
+    // INNER CLASS
+    static class CachedServiceClient {
+        ServiceClient _client;
+        long _expire;
     }
 
 }



Mime
View raw message