Return-Path: Delivered-To: apmail-incubator-abdera-commits-archive@locus.apache.org Received: (qmail 30473 invoked from network); 13 Jul 2007 00:49:45 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 13 Jul 2007 00:49:45 -0000 Received: (qmail 62259 invoked by uid 500); 13 Jul 2007 00:49:48 -0000 Delivered-To: apmail-incubator-abdera-commits-archive@incubator.apache.org Received: (qmail 62226 invoked by uid 500); 13 Jul 2007 00:49:48 -0000 Mailing-List: contact abdera-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: abdera-dev@incubator.apache.org Delivered-To: mailing list abdera-commits@incubator.apache.org Received: (qmail 62215 invoked by uid 99); 13 Jul 2007 00:49:47 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Jul 2007 17:49:47 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Jul 2007 17:49:44 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 9AA311A981A; Thu, 12 Jul 2007 17:49:24 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: abdera-commits@incubator.apache.org From: jmsnell@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070713004924.9AA311A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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); + } }