abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r555827 - /incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbderaClient.java
Date Fri, 13 Jul 2007 00:49:24 GMT
Author: jmsnell
Date: Thu Jul 12 17:49:23 2007
New Revision: 555827

URL: http://svn.apache.org/viewvc?view=rev&rev=555827
Log:
Additional improvements to AbderaClient

  * revalidation should send either If-None-Match or If-Unmodified-Since, not both
  * reorganize some code so it's easier to read
  * allow the maximum number of total connections and per host to be set

Modified:
    incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbderaClient.java

Modified: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbderaClient.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbderaClient.java?view=diff&rev=555827&r1=555826&r2=555827
==============================================================================
--- incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbderaClient.java
(original)
+++ incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbderaClient.java
Thu Jul 12 17:49:23 2007
@@ -50,6 +50,7 @@
 import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
 import org.apache.commons.httpclient.methods.RequestEntity;
 import org.apache.commons.httpclient.params.HttpClientParams;
+import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
 import org.apache.commons.httpclient.protocol.Protocol;
 import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
 import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory;
@@ -345,24 +346,34 @@
       return execute(method,uri,re,options);
   }
   
+  private CacheDisposition getCacheDisposition(
+    boolean usecache, 
+    String uri, 
+    RequestOptions options,
+    CachedResponse cached_response) {
+    CacheDisposition disp = 
+      (usecache) ? 
+        cache.getDisposition(uri, options) : 
+        CacheDisposition.TRANSPARENT;
+    disp = (!disp.equals(CacheDisposition.TRANSPARENT) && 
+            mustRevalidate(options, cached_response)) ? 
+              CacheDisposition.STALE : 
+              disp;
+    return disp;
+  }
+  
   public ClientResponse execute(
     String method, 
     String uri, 
     RequestEntity entity,
     RequestOptions options) {
       boolean usecache = useCache(method,options);
+      options = options != null ? options : getDefaultRequestOptions();
       try {
-        if (options == null) options = getDefaultRequestOptions();
         Cache cache = getCache();
-        CacheDisposition disp = 
-          (usecache) ? 
-            cache.getDisposition(uri, options) : 
-            CacheDisposition.TRANSPARENT;
         CachedResponse cached_response = cache.get(uri, options);
-        disp = (!disp.equals(CacheDisposition.TRANSPARENT) && 
-                mustRevalidate(options, cached_response)) ? 
-                  CacheDisposition.STALE : 
-                  disp;
+        CacheDisposition disp = getCacheDisposition(
+          usecache, uri, options, cached_response);
         switch(disp) {
           case FRESH:                                                            // CACHE
HIT: FRESH
             if (cached_response != null) {
@@ -371,9 +382,12 @@
             }
           case STALE:                                                            // CACHE
HIT: STALE
             // revalidate the cached entry
-            if (cached_response != null && cached_response.getEntityTag() != null)
{
-              options.setIfModifiedSince(cached_response.getLastModified());
-              options.setIfNoneMatch(cached_response.getEntityTag().toString());
+            if (cached_response != null) {
+              if (cached_response.getEntityTag() != null)
+                options.setIfNoneMatch(cached_response.getEntityTag().toString());
+              else if (cached_response.getLastModified() != null) 
+                options.setIfModifiedSince(cached_response.getLastModified());
+              else options.setNoCache(true);
             } else {
               disp = CacheDisposition.TRANSPARENT;
             }
@@ -387,7 +401,7 @@
                  httpMethod.getStatusCode() == 412) &&
                 cached_response != null) return cached_response;
             ClientResponse response = new CommonsResponse(abdera,httpMethod);
-            response = (options.getUseLocalCache()) ?
+            response = usecache ?
               response = cache.update(options, response, cached_response) : 
               response;
             checkRequestException(response,options);
@@ -469,4 +483,37 @@
       client.getHttpConnectionManager()).shutdown();
   }
 
+  /**
+   * Set the maximum number of connections allowed for a single host
+   */
+  public void setMaxConnectionsPerHost(int max) {
+    client.getHttpConnectionManager().getParams().setIntParameter(
+      HttpConnectionManagerParams.MAX_HOST_CONNECTIONS, max);
+  }
+  
+  /**
+   * Return the maximum number of connections allowed for a single host
+   */
+  public int getMaxConnectionsPerHost() {
+    return client.getHttpConnectionManager().getParams().getIntParameter(
+      HttpConnectionManagerParams.MAX_HOST_CONNECTIONS,
+      MultiThreadedHttpConnectionManager.DEFAULT_MAX_HOST_CONNECTIONS);
+  }
+  
+  /**
+   * Return the maximum number of connections allowed for the client
+   */
+  public void setMaxConnectionsTotal(int max) {
+    client.getHttpConnectionManager().getParams().setIntParameter(
+      HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS, max);
+  }
+  
+  /**
+   * Return the maximum number of connections allowed for the client
+   */
+  public int getMaxConnectionsTotal() {
+    return client.getHttpConnectionManager().getParams().getIntParameter(
+      HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS,
+      MultiThreadedHttpConnectionManager.DEFAULT_MAX_TOTAL_CONNECTIONS);
+  }
 }



Mime
View raw message