hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r984346 - in /httpcomponents/httpclient/trunk/httpclient-cache/src: main/java/org/apache/http/client/cache/ main/java/org/apache/http/impl/client/cache/ test/java/org/apache/http/impl/client/cache/
Date Wed, 11 Aug 2010 08:59:06 GMT
Author: olegk
Date: Wed Aug 11 08:59:05 2010
New Revision: 984346

URL: http://svn.apache.org/viewvc?rev=984346&view=rev
Log:
Use ResourceFactory to handle system resource allocation

Added:
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/ResourceFactory.java
  (with props)
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryFactory.java
  (with props)
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/FileResourceFactory.java
  (with props)
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HeapResourceFactory.java
  (with props)
Removed:
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheEntryFactory.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/FileCacheEntryFactory.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/MemCacheEntryFactory.java
Modified:
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryUpdater.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/AbstractProtocolTest.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/DoNotTestProtocolRequirements.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntry.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntryGenerator.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingHttpClient.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolDeviations.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRequirements.java

Added: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/ResourceFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/ResourceFactory.java?rev=984346&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/ResourceFactory.java
(added)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/ResourceFactory.java
Wed Aug 11 08:59:05 2010
@@ -0,0 +1,42 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.http.client.cache;
+
+import java.io.IOException;
+
+/**
+ * Generates {@link Resource} instances.
+ *
+ * @since 4.1
+ */
+public interface ResourceFactory {
+
+    Resource generate(String requestId, byte[] body) throws IOException;
+
+    Resource copy(String requestId, Resource resource) throws IOException;
+
+}

Propchange: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/ResourceFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/ResourceFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/ResourceFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryFactory.java?rev=984346&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryFactory.java
(added)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryFactory.java
Wed Aug 11 08:59:05 2010
@@ -0,0 +1,80 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.http.impl.client.cache;
+
+import java.io.IOException;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.http.Header;
+import org.apache.http.StatusLine;
+import org.apache.http.annotation.Immutable;
+import org.apache.http.client.cache.HttpCacheEntry;
+import org.apache.http.client.cache.ResourceFactory;
+
+@Immutable
+class CacheEntryFactory  {
+
+    private final ResourceFactory resourceFactory;
+
+    public CacheEntryFactory(final ResourceFactory resourceFactory) {
+        super();
+        this.resourceFactory = resourceFactory;
+    }
+
+    public HttpCacheEntry generate(
+            final String requestId,
+            final Date requestDate,
+            final Date responseDate,
+            final StatusLine statusLine,
+            final Header[] headers,
+            byte[] body) throws IOException {
+        return new HttpCacheEntry(requestDate,
+                responseDate,
+                statusLine,
+                headers,
+                resourceFactory.generate(requestId, body),
+                null);
+    }
+
+    public HttpCacheEntry copyVariant(
+            final String requestId,
+            final HttpCacheEntry entry,
+            final String variantURI) throws IOException {
+        Set<String> variants = new HashSet<String>(entry.getVariantURIs());
+        variants.add(variantURI);
+        return new HttpCacheEntry(
+                entry.getRequestDate(),
+                entry.getResponseDate(),
+                entry.getStatusLine(),
+                entry.getAllHeaders(),
+                resourceFactory.copy(requestId, entry.getResource()),
+                variants);
+    }
+
+}

Propchange: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryUpdater.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryUpdater.java?rev=984346&r1=984345&r2=984346&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryUpdater.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryUpdater.java
Wed Aug 11 08:59:05 2010
@@ -40,7 +40,6 @@ import org.apache.http.HttpResponse;
 import org.apache.http.annotation.Immutable;
 import org.apache.http.client.cache.HeaderConstants;
 import org.apache.http.client.cache.HttpCacheEntry;
-import org.apache.http.client.cache.HttpCacheEntryFactory;
 import org.apache.http.impl.cookie.DateParseException;
 import org.apache.http.impl.cookie.DateUtils;
 import org.apache.http.protocol.HTTP;
@@ -55,13 +54,13 @@ import org.apache.http.protocol.HTTP;
 @Immutable
 class CacheEntryUpdater {
 
-    private final HttpCacheEntryFactory cacheEntryFactory;
+    private final CacheEntryFactory cacheEntryFactory;
 
     CacheEntryUpdater() {
-        this(new MemCacheEntryFactory());
+        this(new CacheEntryFactory(new HeapResourceFactory()));
     }
 
-    CacheEntryUpdater(final HttpCacheEntryFactory cacheEntryFactory) {
+    CacheEntryUpdater(final CacheEntryFactory cacheEntryFactory) {
         super();
         this.cacheEntryFactory = cacheEntryFactory;
     }

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java?rev=984346&r1=984345&r2=984346&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java
Wed Aug 11 08:59:05 2010
@@ -50,8 +50,8 @@ import org.apache.http.client.ResponseHa
 import org.apache.http.client.cache.HeaderConstants;
 import org.apache.http.client.cache.HttpCache;
 import org.apache.http.client.cache.HttpCacheEntry;
-import org.apache.http.client.cache.HttpCacheEntryFactory;
 import org.apache.http.client.cache.HttpCacheUpdateCallback;
+import org.apache.http.client.cache.ResourceFactory;
 import org.apache.http.client.methods.HttpUriRequest;
 import org.apache.http.conn.ClientConnectionManager;
 import org.apache.http.entity.ByteArrayEntity;
@@ -76,7 +76,7 @@ public class CachingHttpClient implement
 
     private final HttpClient backend;
     private final HttpCache responseCache;
-    private final HttpCacheEntryFactory cacheEntryFactory;
+    private final CacheEntryFactory cacheEntryFactory;
     private final CacheValidityPolicy validityPolicy;
     private final ResponseCachingPolicy responseCachingPolicy;
     private final URIExtractor uriExtractor;
@@ -100,7 +100,7 @@ public class CachingHttpClient implement
     public CachingHttpClient(
             HttpClient client,
             HttpCache cache,
-            HttpCacheEntryFactory cacheEntryFactory,
+            ResourceFactory resourceFactory,
             CacheConfig config) {
         super();
         if (client == null) {
@@ -109,8 +109,8 @@ public class CachingHttpClient implement
         if (cache == null) {
             throw new IllegalArgumentException("HttpCache may not be null");
         }
-        if (cacheEntryFactory == null) {
-            throw new IllegalArgumentException("HttpCacheEntryFactory may not be null");
+        if (resourceFactory == null) {
+            throw new IllegalArgumentException("ResourceFactory may not be null");
         }
         if (config == null) {
             throw new IllegalArgumentException("CacheConfig may not be null");
@@ -119,7 +119,7 @@ public class CachingHttpClient implement
         this.sharedCache = config.isSharedCache();
         this.backend = client;
         this.responseCache = cache;
-        this.cacheEntryFactory = cacheEntryFactory;
+        this.cacheEntryFactory = new CacheEntryFactory(resourceFactory);
 
         this.validityPolicy = new CacheValidityPolicy();
         this.responseCachingPolicy = new ResponseCachingPolicy(maxObjectSizeBytes, sharedCache);
@@ -138,62 +138,62 @@ public class CachingHttpClient implement
     public CachingHttpClient() {
         this(new DefaultHttpClient(),
                 new BasicHttpCache(MAX_CACHE_ENTRIES),
-                new MemCacheEntryFactory(),
+                new HeapResourceFactory(),
                 new CacheConfig());
     }
 
     public CachingHttpClient(CacheConfig config) {
         this(new DefaultHttpClient(),
                 new BasicHttpCache(MAX_CACHE_ENTRIES),
-                new MemCacheEntryFactory(),
+                new HeapResourceFactory(),
                 config);
     }
 
     public CachingHttpClient(HttpClient client) {
         this(client,
                 new BasicHttpCache(MAX_CACHE_ENTRIES),
-                new MemCacheEntryFactory(),
+                new HeapResourceFactory(),
                 new CacheConfig());
     }
 
     public CachingHttpClient(HttpClient client, CacheConfig config) {
         this(client,
                 new BasicHttpCache(MAX_CACHE_ENTRIES),
-                new MemCacheEntryFactory(),
+                new HeapResourceFactory(),
                 config);
     }
 
     public CachingHttpClient(
             HttpCache cache,
-            HttpCacheEntryFactory cacheEntryFactory) {
+            ResourceFactory resourceFactory) {
         this(new DefaultHttpClient(),
                 cache,
-                cacheEntryFactory,
+                resourceFactory,
                 new CacheConfig());
     }
 
     public CachingHttpClient(
             HttpCache cache,
-            HttpCacheEntryFactory cacheEntryFactory,
+            ResourceFactory resourceFactory,
             CacheConfig config) {
         this(new DefaultHttpClient(),
                 cache,
-                cacheEntryFactory,
+                resourceFactory,
                 config);
     }
 
     public CachingHttpClient(
             HttpClient client,
             HttpCache cache,
-            HttpCacheEntryFactory cacheEntryFactory) {
+            ResourceFactory resourceFactory) {
         this(client,
                 cache,
-                cacheEntryFactory,
+                resourceFactory,
                 new CacheConfig());
     }
 
     CachingHttpClient(HttpClient backend, CacheValidityPolicy validityPolicy, ResponseCachingPolicy
responseCachingPolicy,
-                             HttpCacheEntryFactory cacheEntryFactory, URIExtractor uriExtractor,
+                             CacheEntryFactory cacheEntryFactory, URIExtractor uriExtractor,
                              HttpCache responseCache, CachedHttpResponseGenerator responseGenerator,
                              CacheInvalidator cacheInvalidator, CacheableRequestPolicy cacheableRequestPolicy,
                              CachedResponseSuitabilityChecker suitabilityChecker,

Added: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/FileResourceFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/FileResourceFactory.java?rev=984346&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/FileResourceFactory.java
(added)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/FileResourceFactory.java
Wed Aug 11 08:59:05 2010
@@ -0,0 +1,94 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.http.impl.client.cache;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import org.apache.http.annotation.Immutable;
+import org.apache.http.client.cache.Resource;
+import org.apache.http.client.cache.ResourceFactory;
+
+/**
+ * Generates {@link Resource} instances whose body is stored in a temporary file.
+ *
+ * @since 4.1
+ */
+@Immutable
+public class FileResourceFactory implements ResourceFactory {
+
+    private final File cacheDir;
+    private final BasicIdGenerator idgen;
+
+    public FileResourceFactory(final File cacheDir) {
+        super();
+        this.cacheDir = cacheDir;
+        this.idgen = new BasicIdGenerator();
+    }
+
+    private File generateUniqueCacheFile(final String requestId) {
+        StringBuilder buffer = new StringBuilder();
+        this.idgen.generate(buffer);
+        buffer.append('.');
+        int len = Math.min(requestId.length(), 100);
+        for (int i = 0; i < len; i++) {
+            char ch = requestId.charAt(i);
+            if (Character.isLetterOrDigit(ch) || ch == '.') {
+                buffer.append(ch);
+            } else {
+                buffer.append('-');
+            }
+        }
+        return new File(this.cacheDir, buffer.toString());
+    }
+
+    public Resource generate(final String requestId, final byte[] body) throws IOException
{
+        File file = generateUniqueCacheFile(requestId);
+        FileOutputStream outstream = new FileOutputStream(file);
+        try {
+            outstream.write(body);
+        } finally {
+            outstream.close();
+        }
+        return new FileResource(file);
+    }
+
+    public Resource copy(final String requestId, final Resource resource) throws IOException
{
+        File file = generateUniqueCacheFile(requestId);
+
+        if (resource instanceof FileResource) {
+            File src = ((FileResource) resource).getFile();
+            IOUtils.copyFile(src, file);
+        } else {
+            FileOutputStream out = new FileOutputStream(file);
+            IOUtils.copyAndClose(resource.getInputStream(), out);
+        }
+        return new FileResource(file);
+    }
+
+}

Propchange: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/FileResourceFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/FileResourceFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/FileResourceFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HeapResourceFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HeapResourceFactory.java?rev=984346&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HeapResourceFactory.java
(added)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HeapResourceFactory.java
Wed Aug 11 08:59:05 2010
@@ -0,0 +1,60 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.http.impl.client.cache;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import org.apache.http.annotation.Immutable;
+import org.apache.http.client.cache.Resource;
+import org.apache.http.client.cache.ResourceFactory;
+
+/**
+ * Generates {@link Resource} instances stored entirely in heap.
+ *
+ * @since 4.1
+ */
+@Immutable
+public class HeapResourceFactory implements ResourceFactory {
+
+    public Resource generate(final String requestId, final byte[] body) throws IOException
{
+        return new HeapResource(body);
+    }
+
+    public Resource copy(final String requestId, final Resource resource) throws IOException
{
+        byte[] body;
+        if (resource instanceof HeapResource) {
+            body = ((HeapResource) resource).getByteArray();
+        } else {
+            ByteArrayOutputStream outstream = new ByteArrayOutputStream();
+            IOUtils.copyAndClose(resource.getInputStream(), outstream);
+            body = outstream.toByteArray();
+        }
+        return new HeapResource(body);
+    }
+
+}

Propchange: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HeapResourceFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HeapResourceFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HeapResourceFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/AbstractProtocolTest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/AbstractProtocolTest.java?rev=984346&r1=984345&r2=984346&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/AbstractProtocolTest.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/AbstractProtocolTest.java
Wed Aug 11 08:59:05 2010
@@ -10,7 +10,6 @@ import org.apache.http.HttpStatus;
 import org.apache.http.HttpVersion;
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.cache.HttpCache;
-import org.apache.http.client.cache.HttpCacheEntryFactory;
 import org.apache.http.impl.cookie.DateUtils;
 import org.apache.http.message.BasicHttpRequest;
 import org.apache.http.message.BasicHttpResponse;
@@ -26,7 +25,6 @@ public abstract class AbstractProtocolTe
     protected int entityLength = 128;
     protected HttpHost host;
     protected HttpEntity body;
-    protected HttpEntity mockEntity;
     protected HttpClient mockBackend;
     protected HttpCache mockCache;
     protected HttpRequest request;
@@ -34,7 +32,6 @@ public abstract class AbstractProtocolTe
     protected CacheConfig params;
     protected CachingHttpClient impl;
     protected HttpCache cache;
-    protected HttpCacheEntryFactory cacheEntryFactory;
 
     public static HttpRequest eqRequest(HttpRequest in) {
         EasyMock.reportMatcher(new RequestEquivalent(in));
@@ -52,25 +49,21 @@ public abstract class AbstractProtocolTe
         originResponse = make200Response();
 
         cache = new BasicHttpCache(MAX_ENTRIES);
-        cacheEntryFactory = new MemCacheEntryFactory();
         mockBackend = EasyMock.createMock(HttpClient.class);
-        mockEntity = EasyMock.createMock(HttpEntity.class);
         mockCache = EasyMock.createMock(HttpCache.class);
         params = new CacheConfig();
         params.setMaxObjectSizeBytes(MAX_BYTES);
-        impl = new CachingHttpClient(mockBackend, cache, cacheEntryFactory, params);
+        impl = new CachingHttpClient(mockBackend, cache, new HeapResourceFactory(), params);
     }
 
     protected void replayMocks() {
         EasyMock.replay(mockBackend);
         EasyMock.replay(mockCache);
-        EasyMock.replay(mockEntity);
     }
 
     protected void verifyMocks() {
         EasyMock.verify(mockBackend);
         EasyMock.verify(mockCache);
-        EasyMock.verify(mockEntity);
     }
 
     protected HttpResponse make200Response() {
@@ -95,9 +88,8 @@ public abstract class AbstractProtocolTe
     protected void emptyMockCacheExpectsNoPuts() throws Exception {
         mockBackend = EasyMock.createMock(HttpClient.class);
         mockCache = EasyMock.createMock(HttpCache.class);
-        mockEntity = EasyMock.createMock(HttpEntity.class);
 
-        impl = new CachingHttpClient(mockBackend, mockCache, cacheEntryFactory, params);
+        impl = new CachingHttpClient(mockBackend, mockCache, new HeapResourceFactory(), params);
 
         EasyMock.expect(mockCache.getEntry((String) EasyMock.anyObject())).andReturn(null)
                 .anyTimes();
@@ -108,7 +100,7 @@ public abstract class AbstractProtocolTe
 
     protected void behaveAsNonSharedCache() {
         params.setSharedCache(false);
-        impl = new CachingHttpClient(mockBackend, cache, cacheEntryFactory, params);
+        impl = new CachingHttpClient(mockBackend, cache, new HeapResourceFactory(), params);
     }
 
     public AbstractProtocolTest() {

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/DoNotTestProtocolRequirements.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/DoNotTestProtocolRequirements.java?rev=984346&r1=984345&r2=984346&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/DoNotTestProtocolRequirements.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/DoNotTestProtocolRequirements.java
Wed Aug 11 08:59:05 2010
@@ -82,7 +82,7 @@ public class DoNotTestProtocolRequiremen
         mockCache = EasyMock.createMock(HttpCache.class);
         CacheConfig params = new CacheConfig();
         params.setMaxObjectSizeBytes(MAX_BYTES);
-        impl = new CachingHttpClient(mockBackend, cache, new MemCacheEntryFactory(), params);
+        impl = new CachingHttpClient(mockBackend, cache, new HeapResourceFactory(), params);
     }
 
     private HttpResponse make200Response() {

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntry.java?rev=984346&r1=984345&r2=984346&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntry.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntry.java
Wed Aug 11 08:59:05 2010
@@ -108,7 +108,7 @@ public class TestCacheEntry {
         Header[] headers = new Header[]{};
         CacheEntry entry = new CacheEntry(headers);
 
-        MemCacheEntryFactory entryGenerator = new MemCacheEntryFactory();
+        CacheEntryFactory entryGenerator = new CacheEntryFactory(new HeapResourceFactory());
 
         HttpCacheEntry addedOne = entryGenerator.copyVariant(null, entry, "foo");
         HttpCacheEntry addedTwo = entryGenerator.copyVariant(null, addedOne, "bar");

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntryGenerator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntryGenerator.java?rev=984346&r1=984345&r2=984346&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntryGenerator.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntryGenerator.java
Wed Aug 11 08:59:05 2010
@@ -28,31 +28,28 @@ package org.apache.http.impl.client.cach
 
 import java.util.Date;
 
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.HttpStatus;
-import org.apache.http.ProtocolVersion;
+import org.apache.http.Header;
 import org.apache.http.client.cache.HttpCacheEntry;
-import org.apache.http.entity.ByteArrayEntity;
-import org.apache.http.message.BasicHttpResponse;
+import org.apache.http.message.BasicHeader;
 import org.junit.Assert;
 import org.junit.Test;
 
 public class TestCacheEntryGenerator {
 
     @Test
-    public void testEntryMatchesInputs() {
+    public void testEntryMatchesInputs() throws Exception {
 
-        MemCacheEntryFactory gen = new MemCacheEntryFactory();
+        CacheEntryFactory gen = new CacheEntryFactory(new HeapResourceFactory());
 
-        HttpResponse response = new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 1),
-                HttpStatus.SC_OK, "Success");
-        HttpEntity entity = new ByteArrayEntity(new byte[] {});
-        response.setEntity(entity);
+        Header h = new BasicHeader("fooHeader", "fooHeaderValue");
 
-        response.setHeader("fooHeader", "fooHeaderValue");
-
-        HttpCacheEntry entry = gen.generateEntry(new Date(), new Date(), response, new byte[]
{});
+        HttpCacheEntry entry = gen.generate(
+                null,
+                new Date(),
+                new Date(),
+                new OKStatus(),
+                new Header[] { h },
+                new byte[] {});
 
         Assert.assertEquals("HTTP", entry.getProtocolVersion().getProtocol());
         Assert.assertEquals(1, entry.getProtocolVersion().getMajor());

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingHttpClient.java?rev=984346&r1=984345&r2=984346&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingHttpClient.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingHttpClient.java
Wed Aug 11 08:59:05 2010
@@ -48,7 +48,6 @@ import org.apache.http.client.HttpClient
 import org.apache.http.client.ResponseHandler;
 import org.apache.http.client.cache.HttpCache;
 import org.apache.http.client.cache.HttpCacheEntry;
-import org.apache.http.client.cache.HttpCacheEntryFactory;
 import org.apache.http.client.methods.HttpUriRequest;
 import org.apache.http.conn.ClientConnectionManager;
 import org.apache.http.entity.ByteArrayEntity;
@@ -98,7 +97,7 @@ public class TestCachingHttpClient {
     private CacheEntry mockVariantCacheEntry;
     private CacheEntry mockUpdatedCacheEntry;
     private URIExtractor mockExtractor;
-    private HttpCacheEntryFactory mockEntryGenerator;
+    private CacheEntryFactory mockEntryGenerator;
     private CachedHttpResponseGenerator mockResponseGenerator;
     private SizeLimitedResponseReader mockResponseReader;
     private ClientConnectionManager mockConnectionManager;
@@ -141,7 +140,7 @@ public class TestCachingHttpClient {
         mockUpdatedCacheEntry = EasyMock.createMock(CacheEntry.class);
         mockVariantCacheEntry = EasyMock.createMock(CacheEntry.class);
         mockExtractor = EasyMock.createMock(URIExtractor.class);
-        mockEntryGenerator = EasyMock.createMock(HttpCacheEntryFactory.class);
+        mockEntryGenerator = EasyMock.createMock(CacheEntryFactory.class);
         mockResponseGenerator = EasyMock.createMock(CachedHttpResponseGenerator.class);
         mockCachedResponse = EasyMock.createMock(HttpResponse.class);
         mockConditionalRequestBuilder = EasyMock.createMock(ConditionalRequestBuilder.class);

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolDeviations.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolDeviations.java?rev=984346&r1=984345&r2=984346&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolDeviations.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolDeviations.java
Wed Aug 11 08:59:05 2010
@@ -100,7 +100,7 @@ public class TestProtocolDeviations {
 
         CacheConfig params = new CacheConfig();
         params.setMaxObjectSizeBytes(MAX_BYTES);
-        impl = new CachingHttpClient(mockBackend, cache, new MemCacheEntryFactory(), params);
+        impl = new CachingHttpClient(mockBackend, cache, new HeapResourceFactory(), params);
     }
 
     private HttpResponse make200Response() {

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRequirements.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRequirements.java?rev=984346&r1=984345&r2=984346&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRequirements.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRequirements.java
Wed Aug 11 08:59:05 2010
@@ -43,6 +43,7 @@ import org.apache.http.HttpVersion;
 import org.apache.http.ProtocolVersion;
 import org.apache.http.client.ClientProtocolException;
 import org.apache.http.client.cache.HttpCacheEntry;
+import org.apache.http.entity.BasicHttpEntity;
 import org.apache.http.entity.ByteArrayEntity;
 import org.apache.http.impl.client.RequestWrapper;
 import org.apache.http.impl.cookie.DateUtils;
@@ -548,7 +549,7 @@ public class TestProtocolRequirements ex
         BasicHttpEntityEnclosingRequest post = EasyMock.createMockBuilder(
                 BasicHttpEntityEnclosingRequest.class).withConstructor("POST", "/", HttpVersion.HTTP_1_1)
                 .addMockedMethods("expectContinue").createMock();
-        post.setEntity(mockEntity);
+        post.setEntity(new BasicHttpEntity());
         post.setHeader("Content-Length", "128");
 
         Capture<HttpEntityEnclosingRequest> reqCap = new Capture<HttpEntityEnclosingRequest>();
@@ -593,7 +594,7 @@ public class TestProtocolRequirements ex
         BasicHttpEntityEnclosingRequest post = EasyMock.createMockBuilder(
                 BasicHttpEntityEnclosingRequest.class).withConstructor("POST", "/", HttpVersion.HTTP_1_1)
                 .addMockedMethods("expectContinue").createMock();
-        post.setEntity(mockEntity);
+        post.setEntity(new BasicHttpEntity());
         post.setHeader("Content-Length", "128");
 
         Capture<HttpEntityEnclosingRequest> reqCap = new Capture<HttpEntityEnclosingRequest>();
@@ -2221,7 +2222,7 @@ public class TestProtocolRequirements ex
 
         mockCache.putEntry(EasyMock.eq("http://foo.example.com/thing"), EasyMock.isA(HttpCacheEntry.class));
 
-        impl = new CachingHttpClient(mockBackend, mockCache, cacheEntryFactory, params);
+        impl = new CachingHttpClient(mockBackend, mockCache, new HeapResourceFactory(), params);
 
         HttpRequest validate = new BasicHttpRequest("GET", "/thing", HttpVersion.HTTP_1_1);
         validate.setHeader("If-None-Match", "\"etag\"");
@@ -2263,7 +2264,7 @@ public class TestProtocolRequirements ex
 
         CacheEntry entry = new CacheEntry(tenSecondsAgo, eightSecondsAgo, hdrs, bytes);
 
-        impl = new CachingHttpClient(mockBackend, mockCache, cacheEntryFactory, params);
+        impl = new CachingHttpClient(mockBackend, mockCache, new HeapResourceFactory(), params);
 
         EasyMock.expect(mockCache.getEntry("http://foo.example.com/thing")).andReturn(entry);
 
@@ -2304,7 +2305,7 @@ public class TestProtocolRequirements ex
 
         CacheEntry entry = new CacheEntry(tenSecondsAgo, eightSecondsAgo, hdrs, bytes);
 
-        impl = new CachingHttpClient(mockBackend, mockCache, cacheEntryFactory, params);
+        impl = new CachingHttpClient(mockBackend, mockCache, new HeapResourceFactory(), params);
 
         EasyMock.expect(mockCache.getEntry("http://foo.example.com/thing")).andReturn(entry);
         EasyMock.expect(
@@ -2505,7 +2506,7 @@ public class TestProtocolRequirements ex
 
         CacheEntry entry = new CacheEntry(tenSecondsAgo, eightSecondsAgo, hdrs, bytes);
 
-        impl = new CachingHttpClient(mockBackend, mockCache, cacheEntryFactory, params);
+        impl = new CachingHttpClient(mockBackend, mockCache, new HeapResourceFactory(), params);
 
         EasyMock.expect(mockCache.getEntry("http://foo.example.com/thing")).andReturn(entry);
 
@@ -2549,7 +2550,7 @@ public class TestProtocolRequirements ex
 
         CacheEntry entry = new CacheEntry(requestTime, responseTime, hdrs, bytes);
 
-        impl = new CachingHttpClient(mockBackend, mockCache, cacheEntryFactory, params);
+        impl = new CachingHttpClient(mockBackend, mockCache, new HeapResourceFactory(), params);
 
         HttpResponse validated = make200Response();
         validated.setHeader("Cache-Control", "public");



Mime
View raw message