You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2017/10/19 14:04:56 UTC
[3/4] httpcomponents-client git commit: Upgraded Ehcache to version
3.4.0
Upgraded Ehcache to version 3.4.0
Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/commit/26024a3b
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/tree/26024a3b
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/diff/26024a3b
Branch: refs/heads/master
Commit: 26024a3b8e256075398bfbc89d966b255b13281b
Parents: f215fdc
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Thu Oct 19 15:49:57 2017 +0200
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Thu Oct 19 15:52:30 2017 +0200
----------------------------------------------------------------------
httpclient5-cache/pom.xml | 4 +-
.../impl/cache/CachedHttpResponseGenerator.java | 2 +-
.../impl/cache/NoopCacheEntrySerializer.java | 53 +++++++++++++++
.../cache/ehcache/EhcacheHttpCacheStorage.java | 71 ++++++++++----------
httpclient5-osgi/pom.xml | 2 +-
pom.xml | 6 +-
6 files changed, 95 insertions(+), 43 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/26024a3b/httpclient5-cache/pom.xml
----------------------------------------------------------------------
diff --git a/httpclient5-cache/pom.xml b/httpclient5-cache/pom.xml
index 8e1a202..e6f45f1 100644
--- a/httpclient5-cache/pom.xml
+++ b/httpclient5-cache/pom.xml
@@ -56,8 +56,8 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>net.sf.ehcache</groupId>
- <artifactId>ehcache-core</artifactId>
+ <groupId>org.ehcache.modules</groupId>
+ <artifactId>ehcache-api</artifactId>
<scope>compile</scope>
<optional>true</optional>
</dependency>
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/26024a3b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachedHttpResponseGenerator.java
----------------------------------------------------------------------
diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachedHttpResponseGenerator.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachedHttpResponseGenerator.java
index 304add1..d558837 100644
--- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachedHttpResponseGenerator.java
+++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachedHttpResponseGenerator.java
@@ -46,7 +46,7 @@ import org.apache.hc.core5.http.HttpVersion;
import org.apache.hc.core5.http.message.BasicHeader;
/**
- * Rebuilds an {@link HttpResponse} from a {@link net.sf.ehcache.CacheEntry}
+ * Rebuilds an {@link HttpResponse} from a {@link HttpCacheEntry}
*
* @since 4.1
*/
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/26024a3b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/NoopCacheEntrySerializer.java
----------------------------------------------------------------------
diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/NoopCacheEntrySerializer.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/NoopCacheEntrySerializer.java
new file mode 100644
index 0000000..76f1716
--- /dev/null
+++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/NoopCacheEntrySerializer.java
@@ -0,0 +1,53 @@
+/*
+ * ====================================================================
+ * 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.hc.client5.http.impl.cache;
+
+import org.apache.hc.client5.http.cache.HttpCacheEntrySerializer;
+import org.apache.hc.client5.http.cache.HttpCacheStorageEntry;
+import org.apache.hc.client5.http.cache.ResourceIOException;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
+
+/**
+ * @since 5.0
+ */
+@Contract(threading = ThreadingBehavior.IMMUTABLE)
+public class NoopCacheEntrySerializer implements HttpCacheEntrySerializer<HttpCacheStorageEntry> {
+
+ public static final NoopCacheEntrySerializer INSTANCE = new NoopCacheEntrySerializer();
+
+ @Override
+ public HttpCacheStorageEntry serialize(final HttpCacheStorageEntry cacheEntry) throws ResourceIOException {
+ return cacheEntry;
+ }
+
+ @Override
+ public HttpCacheStorageEntry deserialize(final HttpCacheStorageEntry cacheEntry) throws ResourceIOException {
+ return cacheEntry;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/26024a3b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ehcache/EhcacheHttpCacheStorage.java
----------------------------------------------------------------------
diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ehcache/EhcacheHttpCacheStorage.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ehcache/EhcacheHttpCacheStorage.java
index 36cc4c2..c3d7a38 100644
--- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ehcache/EhcacheHttpCacheStorage.java
+++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ehcache/EhcacheHttpCacheStorage.java
@@ -27,14 +27,14 @@
package org.apache.hc.client5.http.impl.cache.ehcache;
import org.apache.hc.client5.http.cache.HttpCacheEntrySerializer;
+import org.apache.hc.client5.http.cache.HttpCacheStorageEntry;
import org.apache.hc.client5.http.cache.ResourceIOException;
-import org.apache.hc.client5.http.impl.cache.AbstractBinaryCacheStorage;
-import org.apache.hc.client5.http.impl.cache.CacheConfig;
+import org.apache.hc.client5.http.impl.cache.AbstractSerializingCacheStorage;
import org.apache.hc.client5.http.impl.cache.ByteArrayCacheEntrySerializer;
+import org.apache.hc.client5.http.impl.cache.CacheConfig;
+import org.apache.hc.client5.http.impl.cache.NoopCacheEntrySerializer;
import org.apache.hc.core5.util.Args;
-
-import net.sf.ehcache.Ehcache;
-import net.sf.ehcache.Element;
+import org.ehcache.Cache;
/**
* <p>This class is a storage backend for cache entries that uses the
@@ -53,19 +53,30 @@ import net.sf.ehcache.Element;
* itself.</p>
* @since 4.1
*/
-public class EhcacheHttpCacheStorage extends AbstractBinaryCacheStorage<Element> {
+public class EhcacheHttpCacheStorage<T> extends AbstractSerializingCacheStorage<T, T> {
- private final Ehcache cache;
+ /**
+ * Creates cache that stores {@link HttpCacheStorageEntry}s without direct serialization.
+ *
+ * @since 5.0
+ */
+ public static EhcacheHttpCacheStorage<HttpCacheStorageEntry> createObjectCache(
+ final Cache<String, HttpCacheStorageEntry> cache, final CacheConfig config) {
+ return new EhcacheHttpCacheStorage<>(cache, config, NoopCacheEntrySerializer.INSTANCE);
+ }
/**
- * Constructs a storage backend using the provided Ehcache
- * with default configuration options.
- * @param cache where to store cached origin responses
+ * Creates cache that stores serialized {@link HttpCacheStorageEntry}s.
+ *
+ * @since 5.0
*/
- public EhcacheHttpCacheStorage(final Ehcache cache){
- this(cache, CacheConfig.DEFAULT, ByteArrayCacheEntrySerializer.INSTANCE);
+ public static EhcacheHttpCacheStorage<byte[]> createSerializedCache(
+ final Cache<String, byte[]> cache, final CacheConfig config) {
+ return new EhcacheHttpCacheStorage<>(cache, config, ByteArrayCacheEntrySerializer.INSTANCE);
}
+ private final Cache<String, T> cache;
+
/**
* Constructs a storage backend using the provided Ehcache
* with the given configuration options, but using an alternative
@@ -77,9 +88,9 @@ public class EhcacheHttpCacheStorage extends AbstractBinaryCacheStorage<Element>
* @param serializer alternative serialization mechanism
*/
public EhcacheHttpCacheStorage(
- final Ehcache cache,
+ final Cache<String, T> cache,
final CacheConfig config,
- final HttpCacheEntrySerializer<byte[]> serializer) {
+ final HttpCacheEntrySerializer<T> serializer) {
super((config != null ? config : CacheConfig.DEFAULT).getMaxUpdateRetries(), serializer);
this.cache = Args.notNull(cache, "Ehcache");
}
@@ -90,41 +101,29 @@ public class EhcacheHttpCacheStorage extends AbstractBinaryCacheStorage<Element>
}
@Override
- protected void store(final String storageKey, final byte[] storageObject) throws ResourceIOException {
- cache.put(new Element(storageKey, storageKey));
- }
-
- private byte[] castAsByteArray(final Object storageObject) throws ResourceIOException {
- if (storageObject == null) {
- return null;
- }
- if (storageObject instanceof byte[]) {
- return (byte[]) storageObject;
- } else {
- throw new ResourceIOException("Unexpected cache content: " + storageObject.getClass());
- }
+ protected void store(final String storageKey, final T storageObject) throws ResourceIOException {
+ cache.put(storageKey, storageObject);
}
@Override
- protected byte[] restore(final String storageKey) throws ResourceIOException {
- final Element element = cache.get(storageKey);
- return element != null ? castAsByteArray(element.getObjectValue()) : null;
+ protected T restore(final String storageKey) throws ResourceIOException {
+ return cache.get(storageKey);
}
@Override
- protected Element getForUpdateCAS(final String storageKey) throws ResourceIOException {
+ protected T getForUpdateCAS(final String storageKey) throws ResourceIOException {
return cache.get(storageKey);
}
@Override
- protected byte[] getStorageObject(final Element element) throws ResourceIOException {
- return castAsByteArray(element.getObjectValue());
+ protected T getStorageObject(final T element) throws ResourceIOException {
+ return element;
}
@Override
- protected boolean updateCAS(final String storageKey, final Element element, final byte[] storageObject) throws ResourceIOException {
- final Element newElement = new Element(storageKey, storageObject);
- return cache.replace(element, newElement);
+ protected boolean updateCAS(
+ final String storageKey, final T oldStorageObject, final T storageObject) throws ResourceIOException {
+ return cache.replace(storageKey, oldStorageObject, storageObject);
}
@Override
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/26024a3b/httpclient5-osgi/pom.xml
----------------------------------------------------------------------
diff --git a/httpclient5-osgi/pom.xml b/httpclient5-osgi/pom.xml
index 2912a93..54b33d9 100644
--- a/httpclient5-osgi/pom.xml
+++ b/httpclient5-osgi/pom.xml
@@ -136,7 +136,7 @@
org.osgi.service.cm,
org.apache.logging.log4j;version=${log4j.osgi.import.version},
org.apache.hc.core5.*;version=${httpcore.osgi.import.version},
- net.sf.ehcache.*;resolution:=optional,
+ org.ehcache.*;resolution:=optional,
net.spy.memcached.*;resolution:=optional
</Import-Package>
<Bundle-Activator>org.apache.hc.client5.http.osgi.impl.HttpProxyConfigurationActivator</Bundle-Activator>
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/26024a3b/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 55161b4..dfbc366 100644
--- a/pom.xml
+++ b/pom.xml
@@ -71,7 +71,7 @@
<httpcore.version>5.0-alpha4</httpcore.version>
<log4j.version>2.8.2</log4j.version>
<commons-codec.version>1.10</commons-codec.version>
- <ehcache.version>2.6.11</ehcache.version>
+ <ehcache.version>3.4.0</ehcache.version>
<memcached.version>2.12.0</memcached.version>
<slf4j.version>1.7.13</slf4j.version>
<junit.version>4.12</junit.version>
@@ -121,8 +121,8 @@
<version>${commons-codec.version}</version>
</dependency>
<dependency>
- <groupId>net.sf.ehcache</groupId>
- <artifactId>ehcache-core</artifactId>
+ <groupId>org.ehcache.modules</groupId>
+ <artifactId>ehcache-api</artifactId>
<version>${ehcache.version}</version>
</dependency>
<dependency>