From: Stephen Kitt Date: Thu, 30 Aug 2018 11:57:33 +0000 (+0200) Subject: Remove the object cache X-Git-Tag: v2.1.0~16 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=b0dca1bba3201625b65a86b669970561cb5e3ce0;p=yangtools.git Remove the object cache It’s been experimental for four years and isn’t used anywhere in ODL. Change-Id: Icc9778ef5ab777ae217b3ccd02e54de680460c73 Signed-off-by: Stephen Kitt --- diff --git a/common/object-cache-api/pom.xml b/common/object-cache-api/pom.xml deleted file mode 100644 index 8246568b5b..0000000000 --- a/common/object-cache-api/pom.xml +++ /dev/null @@ -1,96 +0,0 @@ - - - - - - - - org.opendaylight.odlparent - bundle-parent - 4.0.0 - - - bundle - 4.0.0 - org.opendaylight.yangtools - object-cache-api - 2.1.0-SNAPSHOT - - - ${project.basedir}/../../target/jacoco.exec - - - - - - org.opendaylight.yangtools - yangtools-artifacts - 2.1.0-SNAPSHOT - import - pom - - - - - - - org.opendaylight.yangtools - concepts - - - com.google.guava - guava - - - - - - - org.apache.felix - maven-bundle-plugin - true - - - - org.opendaylight.yangtools.objcache.impl;resolution:=optional, - * - - - - - - org.apache.maven.plugins - maven-antrun-plugin - - - process-classes - - run - - - - - - - - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - - checkstyle.violationSeverity=error - - - - - - diff --git a/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/ObjectCache.java b/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/ObjectCache.java deleted file mode 100644 index 6390abcf86..0000000000 --- a/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/ObjectCache.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.yangtools.objcache; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import org.opendaylight.yangtools.concepts.Immutable; -import org.opendaylight.yangtools.concepts.ProductAwareBuilder; - -/** - * A cache of objects. Caches are useful for reducing memory overhead - * stemming from multiple copies of identical objects -- by putting - * a cache in the instantiation path, one can expend some memory on - * indexes and spend some CPU cycles on walking the index to potentially - * end up with a reused object. - * - *

- * Note that the cached objects should really be semantically {@link Immutable}. - * This interface does not enforce that interface contract simply because - * there are third-party objects which fulfill this contract. - */ -public interface ObjectCache { - /** - * Get a reference for an object which is equal to specified object. - * The cache is free return either a cached instance, or retain the - * object and return it back. - * - * @param object type - * @param object Requested object, may be null - * @return Reference to an object which is equal to the one passed in. - * If @object was @null, this method returns @null. - */ - T getReference(@Nullable T object); - - /** - * Get a reference to an object equal to the product of a builder. - * The builder is expected to remain constant while this method - * executes. Unlike {@link #getReference(Object)}, this method has - * the potential of completely eliding the product instantiation. - * - * @param

produced object type - * @param builder type - * @param builder Builder instance, may not be null - * @return Result of builder's toInstance() product, or an equal - * object. - */ - , P> P getProduct(@Nonnull B builder); -} diff --git a/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/ObjectCacheFactory.java b/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/ObjectCacheFactory.java deleted file mode 100644 index fcd9ea6fc9..0000000000 --- a/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/ObjectCacheFactory.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.yangtools.objcache; - -import static java.util.Objects.requireNonNull; - -import javax.annotation.Nonnull; -import javax.annotation.concurrent.GuardedBy; -import org.opendaylight.yangtools.objcache.impl.StaticObjectCacheBinder; -import org.opendaylight.yangtools.objcache.spi.IObjectCacheFactory; -import org.opendaylight.yangtools.objcache.spi.NoopObjectCacheBinder; - -/** - * Point of entry for acquiring an {@link ObjectCache} instance. - */ -public final class ObjectCacheFactory { - private static volatile IObjectCacheFactory factory; - - private ObjectCacheFactory() { - throw new UnsupportedOperationException("Utility class should not be instantiated"); - } - - @GuardedBy("this") - private static synchronized IObjectCacheFactory initialize() { - // Double-check under lock - IObjectCacheFactory fa = factory; - if (fa != null) { - return fa; - } - - try { - fa = StaticObjectCacheBinder.getInstance().getProductCacheFactory(); - factory = fa; - } catch (NoClassDefFoundError e) { - fa = NoopObjectCacheBinder.INSTANCE.getProductCacheFactory(); - } - - return fa; - } - - public static synchronized void reset() { - factory = null; - } - - /** - * Get an ObjectCache for caching a particular object class. Note - * that it may be shared for multiple classes. - * - * @param objClass Class of objects which are to be cached - * @return Object cache instance. - */ - public static ObjectCache getObjectCache(@Nonnull final Class objClass) { - IObjectCacheFactory fa = factory; - if (fa == null) { - fa = initialize(); - } - - return fa.getObjectCache(requireNonNull(objClass)); - } -} diff --git a/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/impl/StaticObjectCacheBinder.java b/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/impl/StaticObjectCacheBinder.java deleted file mode 100644 index 352d7df625..0000000000 --- a/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/impl/StaticObjectCacheBinder.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.yangtools.objcache.impl; - -import org.opendaylight.yangtools.objcache.spi.AbstractObjectCacheBinder; - -/* - * This is a dummy placeholder implementation. The API package is bound to - * it at compile-time, but it is not packaged and thus not present at run-time. - */ -public final class StaticObjectCacheBinder extends AbstractObjectCacheBinder { - private StaticObjectCacheBinder() { - super(null); - } - - public static StaticObjectCacheBinder getInstance() { - throw new IllegalStateException("This class should have been replaced"); - } -} diff --git a/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/impl/package-info.java b/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/impl/package-info.java deleted file mode 100644 index ecfa94a1f4..0000000000 --- a/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/impl/package-info.java +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -/** - * Static binding implementation package. The API package is bound at compile-time - * to this package. Implementations are expected to supply this package. - */ -package org.opendaylight.yangtools.objcache.impl; \ No newline at end of file diff --git a/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/package-info.java b/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/package-info.java deleted file mode 100644 index a28685af52..0000000000 --- a/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/package-info.java +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -/** - * - */ -package org.opendaylight.yangtools.objcache; \ No newline at end of file diff --git a/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/spi/AbstractObjectCache.java b/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/spi/AbstractObjectCache.java deleted file mode 100644 index 82111c21f4..0000000000 --- a/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/spi/AbstractObjectCache.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.yangtools.objcache.spi; - -import static java.util.Objects.requireNonNull; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.FinalizableReferenceQueue; -import com.google.common.base.FinalizableSoftReference; -import com.google.common.cache.Cache; -import java.util.concurrent.ExecutionException; -import javax.annotation.Nonnull; -import org.opendaylight.yangtools.concepts.ProductAwareBuilder; -import org.opendaylight.yangtools.objcache.ObjectCache; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Abstract object cache implementation. This implementation takes care - * of interacting with the user and manages interaction with the Garbage - * Collector (via soft references). Subclasses are expected to provide - * a backing {@link Cache} instance and provide the - */ -public abstract class AbstractObjectCache implements ObjectCache { - /** - * Key used when looking up a ProductAwareBuilder product. We assume - * the builder is not being modified for the duration of the lookup, - * anything else is the user's fault. - */ - @VisibleForTesting - static final class BuilderKey { - private final ProductAwareBuilder builder; - - private BuilderKey(final ProductAwareBuilder builder) { - this.builder = requireNonNull(builder); - } - - @Override - public int hashCode() { - return builder.productHashCode(); - } - - @Override - public boolean equals(Object obj) { - /* - * We can tolerate null objects coming our way, but we need - * to be on the lookout for WeakKeys, as we cannot pass them - * directly to productEquals(). - */ - if (obj instanceof SoftKey) { - obj = ((SoftKey)obj).get(); - } - - return builder.productEquals(obj); - } - } - - /** - * Key used in the underlying map. It is essentially a soft reference, with - * slightly special properties. - * - *

- * It acts as a proxy for the object it refers to and essentially delegates - * to it. There are three exceptions here: - * - *

- * 1) This key needs to have a cached hash code. The requirement is that the - * key needs to be able to look itself up after the reference to the object - * has been cleared (and thus we can no longer look it up from there). One - * typical container where we are stored are HashMaps -- and they need it - * to be constant. - * 2) This key does not tolerate checks to see if its equal to null. While we - * could return false, we want to catch offenders who try to store nulls - * in the cache. - * 3) This key inverts the check for equality, e.g. it calls equals() on the - * object which was passed to its equals(). Instead of supplying itself, - * it supplies the referent. If the soft reference is cleared, such check - * will return false, which is fine as it prevents normal lookup from - * seeing the cleared key. Removal is handled by the explicit identity - * check. - */ - protected abstract static class SoftKey extends FinalizableSoftReference { - private final int hashCode; - - public SoftKey(final T referent, final FinalizableReferenceQueue queue) { - super(requireNonNull(referent), queue); - hashCode = referent.hashCode(); - } - - @Override - public boolean equals(final Object obj) { - if (obj == null) { - return false; - } - - // Order is important: we do not want to call equals() on ourselves! - return this == obj || obj.equals(get()); - } - - @Override - public int hashCode() { - return hashCode; - } - } - - private static final Logger LOG = LoggerFactory.getLogger(AbstractObjectCache.class); - private final FinalizableReferenceQueue queue; - private final Cache, Object> cache; - - protected AbstractObjectCache(final Cache, Object> cache, final FinalizableReferenceQueue queue) { - this.queue = requireNonNull(queue); - this.cache = requireNonNull(cache); - } - - protected SoftKey createSoftKey(final T object) { - /* - * This may look like a race (having a soft reference and not have - * it in the cache). In fact this is protected by the fact we still - * have a strong reference on the object in our arguments and that - * reference survives past method return since we return it. - */ - return new SoftKey(object, queue) { - @Override - public void finalizeReferent() { - /* - * NOTE: while it may be tempting to add "object" into this - * trace message, do not ever do that: it would retain - * a strong reference, preventing collection. - */ - LOG.trace("Invalidating key {}", this); - cache.invalidate(this); - } - }; - } - - @Override - public final , P> P getProduct(@Nonnull final B builder) { - throw new UnsupportedOperationException(); -// LOG.debug("Looking up product for {}", builder); -// -// @SuppressWarnings("unchecked") -// final P ret = (P) cache.getIfPresent(new BuilderKey(builder)); -// return ret == null ? put(Preconditions.checkNotNull(builder.toInstance())) : ret; - } - - @Override - @SuppressWarnings("unchecked") - public final T getReference(final T object) { - LOG.debug("Looking up reference for {}", object); - if (object == null) { - return null; - } - - final SoftKey key = createSoftKey(object); - try { - return (T) cache.get(key, () -> object); - } catch (ExecutionException e) { - throw new IllegalStateException("Failed to load value", e); - } - } -} diff --git a/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/spi/AbstractObjectCacheBinder.java b/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/spi/AbstractObjectCacheBinder.java deleted file mode 100644 index 718a1dd7c1..0000000000 --- a/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/spi/AbstractObjectCacheBinder.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.yangtools.objcache.spi; - -import static java.util.Objects.requireNonNull; - -import javax.annotation.Nonnull; - -public abstract class AbstractObjectCacheBinder implements ObjectCacheFactoryBinder { - private final IObjectCacheFactory factory; - - protected AbstractObjectCacheBinder(@Nonnull final IObjectCacheFactory factory) { - this.factory = requireNonNull(factory); - } - - @Override - public final IObjectCacheFactory getProductCacheFactory() { - return factory; - } -} diff --git a/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/spi/IObjectCacheFactory.java b/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/spi/IObjectCacheFactory.java deleted file mode 100644 index 8a5047aa4f..0000000000 --- a/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/spi/IObjectCacheFactory.java +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.yangtools.objcache.spi; - -import javax.annotation.Nonnull; -import org.opendaylight.yangtools.objcache.ObjectCache; - -public interface IObjectCacheFactory { - ObjectCache getObjectCache(@Nonnull Class objClass); -} diff --git a/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/spi/NoopObjectCache.java b/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/spi/NoopObjectCache.java deleted file mode 100644 index 4ba9bde42a..0000000000 --- a/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/spi/NoopObjectCache.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.yangtools.objcache.spi; - -import javax.annotation.Nonnull; -import org.opendaylight.yangtools.concepts.ProductAwareBuilder; -import org.opendaylight.yangtools.objcache.ObjectCache; - -/** - * No-operation implementation of an Object Cache. This implementation - * does not do any caching, so it only returns the request object. - */ -public final class NoopObjectCache implements ObjectCache { - private static final NoopObjectCache INSTANCE = new NoopObjectCache(); - - private NoopObjectCache() { - - } - - /** - * Get the cache instance. Since the cache does not have any state, - * this method always returns a singleton instance. - * - * @return Cache instance. - */ - public static NoopObjectCache getInstance() { - return INSTANCE; - } - - @Override - public T getReference(final T object) { - return object; - } - - @Override - public , P> P getProduct(@Nonnull final B builder) { - return builder.build(); - } -} diff --git a/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/spi/NoopObjectCacheBinder.java b/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/spi/NoopObjectCacheBinder.java deleted file mode 100644 index e8791157dd..0000000000 --- a/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/spi/NoopObjectCacheBinder.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.yangtools.objcache.spi; - -public final class NoopObjectCacheBinder extends AbstractObjectCacheBinder { - public static final NoopObjectCacheBinder INSTANCE = new NoopObjectCacheBinder(); - - private NoopObjectCacheBinder() { - super(objClass -> NoopObjectCache.getInstance()); - } -} diff --git a/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/spi/ObjectCacheFactoryBinder.java b/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/spi/ObjectCacheFactoryBinder.java deleted file mode 100644 index ab6f49bac2..0000000000 --- a/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/spi/ObjectCacheFactoryBinder.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.yangtools.objcache.spi; - -/** - * Interface binding an implementation into ObjectCacheFactory. - */ -public interface ObjectCacheFactoryBinder { - /** - * Get the implementation-specific cache factory. - * - * @return Implementation-specific factory. - */ - IObjectCacheFactory getProductCacheFactory(); -} diff --git a/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/spi/package-info.java b/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/spi/package-info.java deleted file mode 100644 index 57223b6cce..0000000000 --- a/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/spi/package-info.java +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -/** - * Service Provider Interface for Object Cache. Object cache implementations - * use classes contained in this package to implement their functionality. - */ -package org.opendaylight.yangtools.objcache.spi; \ No newline at end of file diff --git a/common/object-cache-api/src/test/java/org/opendaylight/yangtools/objcache/spi/CacheFactoryTest.java b/common/object-cache-api/src/test/java/org/opendaylight/yangtools/objcache/spi/CacheFactoryTest.java deleted file mode 100644 index 73aec29d23..0000000000 --- a/common/object-cache-api/src/test/java/org/opendaylight/yangtools/objcache/spi/CacheFactoryTest.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.yangtools.objcache.spi; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import org.junit.Test; -import org.opendaylight.yangtools.objcache.ObjectCache; -import org.opendaylight.yangtools.objcache.ObjectCacheFactory; - -public class CacheFactoryTest { - - @Test - public void testInvalidEnvironment() { - final ObjectCache oc = ObjectCacheFactory.getObjectCache(String.class); - - assertNotNull(oc); - assertEquals(NoopObjectCache.class, oc.getClass()); - } -} diff --git a/common/object-cache-api/src/test/java/org/opendaylight/yangtools/objcache/spi/CacheTest.java b/common/object-cache-api/src/test/java/org/opendaylight/yangtools/objcache/spi/CacheTest.java deleted file mode 100644 index 57f835f9ff..0000000000 --- a/common/object-cache-api/src/test/java/org/opendaylight/yangtools/objcache/spi/CacheTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.yangtools.objcache.spi; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; - -import com.google.common.base.FinalizableReferenceQueue; -import com.google.common.cache.CacheBuilder; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.objcache.ObjectCache; - -public class CacheTest { - private FinalizableReferenceQueue queue; - private ObjectCache oc; - - @Before - public void setUp() { - queue = new FinalizableReferenceQueue(); - oc = new AbstractObjectCache(CacheBuilder.newBuilder().softValues().build(), queue) { - }; - } - - @After - public void tearDown() { - queue.close(); - } - - @Test - public void testMissingKey() { - final String key1 = "abcd"; - final String key2 = "efgh"; - - assertSame(key1, oc.getReference(key1)); - assertSame(key2, oc.getReference(key2)); - } - - @Test - // This test is based on using different references - @SuppressWarnings("RedundantStringConstructorCall") - public void testPresentKey() { - final String key1 = new String("abcd"); - final String key2 = new String("abcd"); - - assertSame(key1, oc.getReference(key1)); - - final String key3 = oc.getReference(key2); - assertEquals(key2, key3); - assertNotSame(key2, key3); - assertSame(key1, key3); - } -} diff --git a/common/object-cache-api/src/test/java/org/opendaylight/yangtools/objcache/spi/SoftKeyTest.java b/common/object-cache-api/src/test/java/org/opendaylight/yangtools/objcache/spi/SoftKeyTest.java deleted file mode 100644 index 3caaf65220..0000000000 --- a/common/object-cache-api/src/test/java/org/opendaylight/yangtools/objcache/spi/SoftKeyTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.yangtools.objcache.spi; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -import com.google.common.base.FinalizableReferenceQueue; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.objcache.spi.AbstractObjectCache.SoftKey; - -public class SoftKeyTest { - private FinalizableReferenceQueue queue; - - - @Before - public void setUp() { - queue = new FinalizableReferenceQueue(); - } - - @After - public void tearDown() { - queue.close(); - } - - @Test - public void testEquals() { - final String str = "foo"; - - final SoftKey key = new SoftKey(str, queue) { - @Override - public void finalizeReferent() { - - } - }; - - assertSame(str, key.get()); - assertEquals(str.hashCode(), key.hashCode()); - assertTrue(key.equals(str)); - key.clear(); - assertNull(key.get()); - assertEquals(str.hashCode(), key.hashCode()); - assertFalse(key.equals(str)); - } -} diff --git a/common/object-cache-guava/pom.xml b/common/object-cache-guava/pom.xml deleted file mode 100644 index f85fdddb61..0000000000 --- a/common/object-cache-guava/pom.xml +++ /dev/null @@ -1,79 +0,0 @@ - - - - - - - org.opendaylight.odlparent - bundle-parent - 4.0.0 - - - - bundle - 4.0.0 - org.opendaylight.yangtools - object-cache-guava - 2.1.0-SNAPSHOT - - - ${project.basedir}/../../target/jacoco.exec - - - - - - org.opendaylight.yangtools - yangtools-artifacts - 2.1.0-SNAPSHOT - import - pom - - - - - - - ${project.groupId} - object-cache-api - - - com.google.guava - guava - - - - - - - org.apache.felix - maven-bundle-plugin - true - - - - org.opendaylight.yangtools.objcache.impl - - - org.opendaylight.yangtools.objcache.guava - - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - - checkstyle.violationSeverity=error - - - - - - diff --git a/common/object-cache-guava/src/main/java/org/opendaylight/yangtools/objcache/guava/GuavaObjectCache.java b/common/object-cache-guava/src/main/java/org/opendaylight/yangtools/objcache/guava/GuavaObjectCache.java deleted file mode 100644 index 6ee1a274f3..0000000000 --- a/common/object-cache-guava/src/main/java/org/opendaylight/yangtools/objcache/guava/GuavaObjectCache.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.yangtools.objcache.guava; - -import com.google.common.base.FinalizableReferenceQueue; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheBuilderSpec; -import org.opendaylight.yangtools.objcache.spi.AbstractObjectCache; - -final class GuavaObjectCache extends AbstractObjectCache { - GuavaObjectCache(final FinalizableReferenceQueue queue) { - super(CacheBuilder.newBuilder().softValues().build(), queue); - } - - GuavaObjectCache(final FinalizableReferenceQueue queue, final CacheBuilderSpec spec) { - super(CacheBuilder.from(spec).build(), queue); - } -} diff --git a/common/object-cache-guava/src/main/java/org/opendaylight/yangtools/objcache/guava/GuavaObjectCacheFactory.java b/common/object-cache-guava/src/main/java/org/opendaylight/yangtools/objcache/guava/GuavaObjectCacheFactory.java deleted file mode 100644 index 10a8c2a598..0000000000 --- a/common/object-cache-guava/src/main/java/org/opendaylight/yangtools/objcache/guava/GuavaObjectCacheFactory.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.yangtools.objcache.guava; - -import com.google.common.base.FinalizableReferenceQueue; -import javax.annotation.Nonnull; -import org.opendaylight.yangtools.objcache.ObjectCache; -import org.opendaylight.yangtools.objcache.spi.IObjectCacheFactory; - -public final class GuavaObjectCacheFactory implements AutoCloseable, IObjectCacheFactory { - private static final GuavaObjectCacheFactory INSTANCE = new GuavaObjectCacheFactory(); - private final FinalizableReferenceQueue queue = new FinalizableReferenceQueue(); - private final ObjectCache cache; - - private GuavaObjectCacheFactory() { - // FIXME: make this more dynamic using a spec - this.cache = new GuavaObjectCache(queue); - } - - @Override - public ObjectCache getObjectCache(@Nonnull final Class objClass) { - return cache; - } - - @Override - public void close() { - queue.close(); - } - - /** - * Return a factory instance. - * - * @return A factory instance. - */ - public static GuavaObjectCacheFactory getInstance() { - return INSTANCE; - } -} diff --git a/common/object-cache-guava/src/main/java/org/opendaylight/yangtools/objcache/guava/package-info.java b/common/object-cache-guava/src/main/java/org/opendaylight/yangtools/objcache/guava/package-info.java deleted file mode 100644 index 46b602949a..0000000000 --- a/common/object-cache-guava/src/main/java/org/opendaylight/yangtools/objcache/guava/package-info.java +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -/** - * - */ -package org.opendaylight.yangtools.objcache.guava; \ No newline at end of file diff --git a/common/object-cache-guava/src/main/java/org/opendaylight/yangtools/objcache/impl/StaticObjectCacheBinder.java b/common/object-cache-guava/src/main/java/org/opendaylight/yangtools/objcache/impl/StaticObjectCacheBinder.java deleted file mode 100644 index ff46d72992..0000000000 --- a/common/object-cache-guava/src/main/java/org/opendaylight/yangtools/objcache/impl/StaticObjectCacheBinder.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.yangtools.objcache.impl; - -import org.opendaylight.yangtools.objcache.guava.GuavaObjectCacheFactory; -import org.opendaylight.yangtools.objcache.spi.AbstractObjectCacheBinder; - -public final class StaticObjectCacheBinder extends AbstractObjectCacheBinder { - private static final StaticObjectCacheBinder INSTANCE = new StaticObjectCacheBinder(); - - private StaticObjectCacheBinder() { - super(GuavaObjectCacheFactory.getInstance()); - } - - public static StaticObjectCacheBinder getInstance() { - return INSTANCE; - } -} diff --git a/common/object-cache-guava/src/test/java/org/opendaylight/yangtools/objcache/guava/GuavaObjectCacheTest.java b/common/object-cache-guava/src/test/java/org/opendaylight/yangtools/objcache/guava/GuavaObjectCacheTest.java deleted file mode 100644 index 69218873ca..0000000000 --- a/common/object-cache-guava/src/test/java/org/opendaylight/yangtools/objcache/guava/GuavaObjectCacheTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.yangtools.objcache.guava; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; - -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.objcache.ObjectCache; -import org.opendaylight.yangtools.objcache.ObjectCacheFactory; - -public class GuavaObjectCacheTest { - private ObjectCache cache; - - @Before - public void setUp() { - cache = ObjectCacheFactory.getObjectCache(String.class); - } - - @Test - public void testCorrectWiring() { - assertEquals(GuavaObjectCache.class, cache.getClass()); - } - - @Test - public void testInitialReference() { - final String s1 = "abcd"; - final String s2 = cache.getReference(s1); - assertSame(s1, s2); - } - - @Test - // This test is based on using different references - @SuppressWarnings("RedundantStringConstructorCall") - public void testMultipleReferences() { - final String s1 = "abcd"; - final String s2 = new String(s1); - - // Preliminary check - assertEquals(s1, s2); - assertNotSame(s1, s2); - - assertSame(s1, cache.getReference(s1)); - assertSame(s1, cache.getReference(s2)); - assertNotSame(s2, cache.getReference(s2)); - } - -} diff --git a/common/object-cache-noop/pom.xml b/common/object-cache-noop/pom.xml deleted file mode 100644 index 11563e59d2..0000000000 --- a/common/object-cache-noop/pom.xml +++ /dev/null @@ -1,69 +0,0 @@ - - - - - - - org.opendaylight.odlparent - bundle-parent - 4.0.0 - - - bundle - 4.0.0 - org.opendaylight.yangtools - object-cache-noop - 2.1.0-SNAPSHOT - - - - - org.opendaylight.yangtools - yangtools-artifacts - 2.1.0-SNAPSHOT - import - pom - - - - - - - ${project.groupId} - object-cache-api - - - - - - org.apache.felix - maven-bundle-plugin - true - - - - org.opendaylight.yangtools.objcache.impl - - - org.opendaylight.yangtools.objcache.noop - - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - - checkstyle.violationSeverity=error - - - - - - diff --git a/common/object-cache-noop/src/main/java/org/opendaylight/yangtools/objcache/impl/StaticObjectCacheBinder.java b/common/object-cache-noop/src/main/java/org/opendaylight/yangtools/objcache/impl/StaticObjectCacheBinder.java deleted file mode 100644 index 3153ff2cc7..0000000000 --- a/common/object-cache-noop/src/main/java/org/opendaylight/yangtools/objcache/impl/StaticObjectCacheBinder.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.yangtools.objcache.impl; - -import org.opendaylight.yangtools.objcache.spi.AbstractObjectCacheBinder; -import org.opendaylight.yangtools.objcache.spi.NoopObjectCache; - -public final class StaticObjectCacheBinder extends AbstractObjectCacheBinder { - private static final StaticObjectCacheBinder INSTANCE = new StaticObjectCacheBinder(); - - private StaticObjectCacheBinder() { - super(objClass -> NoopObjectCache.getInstance()); - } - - public static StaticObjectCacheBinder getInstance() { - return INSTANCE; - } -} diff --git a/common/pom.xml b/common/pom.xml index bd2e11aa77..190111b80d 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -26,9 +26,6 @@ checkstyle-logging concepts mockito-configuration - object-cache-api - object-cache-guava - object-cache-noop util testutils diff --git a/features/features-yangtools-experimental/pom.xml b/features/features-yangtools-experimental/pom.xml index ebee8c9656..67f1df113a 100644 --- a/features/features-yangtools-experimental/pom.xml +++ b/features/features-yangtools-experimental/pom.xml @@ -42,12 +42,6 @@ features xml - - org.opendaylight.yangtools - odl-exp-objcache - features - xml - org.opendaylight.yangtools odl-yangtools-exp-xpath-api diff --git a/features/odl-exp-objcache/pom.xml b/features/odl-exp-objcache/pom.xml deleted file mode 100644 index d32ec98d8e..0000000000 --- a/features/odl-exp-objcache/pom.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - 4.0.0 - - - org.opendaylight.odlparent - single-feature-parent - 4.0.0 - - - - org.opendaylight.yangtools - odl-exp-objcache - 2.1.0-SNAPSHOT - feature - OpenDaylight :: Yangtools :: Experimental :: Object Cache - - - - - org.opendaylight.yangtools - yangtools-artifacts - ${project.version} - import - pom - - - - - - - org.opendaylight.yangtools - odl-yangtools-util - xml - features - - - org.opendaylight.yangtools - object-cache-guava - - - diff --git a/features/pom.xml b/features/pom.xml index a672c163ef..a0d95aecbd 100644 --- a/features/pom.xml +++ b/features/pom.xml @@ -39,7 +39,6 @@ features-yangtools - odl-exp-objcache odl-yangtools-exp-xpath-api odl-yangtools-exp-xpath-impl