diff --git a/app/common/util/pom.xml b/app/common/util/pom.xml index 2301364f767..1310ab00b69 100644 --- a/app/common/util/pom.xml +++ b/app/common/util/pom.xml @@ -98,11 +98,6 @@ jsr305 - - com.google.guava - guava - - junit diff --git a/app/common/util/src/main/java/io/syndesis/common/util/cache/GuavaSoftCache.java b/app/common/util/src/main/java/io/syndesis/common/util/cache/GuavaSoftCache.java deleted file mode 100644 index e2fa324ce4d..00000000000 --- a/app/common/util/src/main/java/io/syndesis/common/util/cache/GuavaSoftCache.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) 2016 Red Hat, Inc. - * - * Licensed 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. - */ -package io.syndesis.common.util.cache; - -import com.google.common.cache.CacheBuilder; - -import java.util.Collection; -import java.util.Set; - -/** - * A Guava based implementation of a soft cache, to allow the garbage collector to reclaim space if the application - * is suffering for high memory usage. - */ -public class GuavaSoftCache implements Cache { - - private final com.google.common.cache.Cache cache; - - public GuavaSoftCache(int maxElements) { - this.cache = CacheBuilder.newBuilder() - .maximumSize(maxElements) - .softValues() - .build(); - } - - @Override - public V get(K key) { - return this.cache.getIfPresent(key); - } - - @Override - public Set keySet() { - return this.cache.asMap().keySet(); - } - - @Override - public Collection values() { - return this.cache.asMap().values(); - } - - @Override - public void put(K key, V value) { - this.cache.put(key, value); - } - - @Override - public V remove(K key) { - V old = this.cache.getIfPresent(key); - this.cache.invalidate(key); - return old; - } - - @Override - public void clear() { - this.cache.invalidateAll(); - } - - @Override - public int size() { - return (int) this.cache.size(); - } - - @Override - public String toString() { - return "GuavaSoftCache{" + - "cache=" + cache + - '}'; - } -} diff --git a/app/common/util/src/main/java/io/syndesis/common/util/cache/LRUCacheManager.java b/app/common/util/src/main/java/io/syndesis/common/util/cache/LRUCacheManager.java index d7f396c3dc1..ad56f4d6d2c 100644 --- a/app/common/util/src/main/java/io/syndesis/common/util/cache/LRUCacheManager.java +++ b/app/common/util/src/main/java/io/syndesis/common/util/cache/LRUCacheManager.java @@ -41,7 +41,7 @@ public void evictAll() { @Override public Cache getCache(final String name, boolean soft) { Cache cache = (Cache) caches.computeIfAbsent(name, n -> this.newCache(soft)); - if ((soft && !(cache instanceof GuavaSoftCache)) || (!soft && (cache instanceof GuavaSoftCache))) { + if ((soft && !(cache instanceof LRUSoftCache)) || (!soft && (cache instanceof LRUSoftCache))) { LOG.warn("Cache {} is being used in mixed 'soft' and 'hard' mode", name); } return cache; @@ -49,7 +49,7 @@ public Cache getCache(final String name, boolean soft) { private Cache newCache(boolean soft) { if (soft) { - return new GuavaSoftCache<>(maxElements); + return new LRUSoftCache<>(maxElements); } return new LRUDefaultCache<>(maxElements); } diff --git a/app/common/util/src/test/java/io/syndesis/common/util/cache/LRUSoftCacheTest.java b/app/common/util/src/test/java/io/syndesis/common/util/cache/LRUSoftCacheTest.java index 5e595cdbf9a..2bb817b8fb6 100644 --- a/app/common/util/src/test/java/io/syndesis/common/util/cache/LRUSoftCacheTest.java +++ b/app/common/util/src/test/java/io/syndesis/common/util/cache/LRUSoftCacheTest.java @@ -40,7 +40,7 @@ public void testSyndesisSoftCacheEmptiedOnHeapFull() { @Test public void testGuavaSoftCacheEmptiedOnHeapFull() { - Cache cache = new GuavaSoftCache<>(MAX_ELEMENTS); + Cache cache = new LRUSoftCache<>(MAX_ELEMENTS); doTest(cache); }