diff options
author | Marek Gradzki <mgradzki@cisco.com> | 2017-03-21 13:38:21 +0100 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2017-03-22 08:58:00 +0100 |
commit | 3bd0a6a0bcd1cec006500c60de20eb0904697263 (patch) | |
tree | 847fedb3a20a63eac6cc20830d22c1d84f767564 /infra/translate-utils/src/main/java/io/fd | |
parent | 9297f70f8a75fae4c3b5ad8fe7324a5420895352 (diff) |
HONEYCOMB-348: include dump params in entity key
Change-Id: I18b2ea3c897c467740f19bf346d13240aac458ac
Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'infra/translate-utils/src/main/java/io/fd')
3 files changed, 24 insertions, 10 deletions
diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/CacheKeyFactory.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/CacheKeyFactory.java index bf4659e89..0f045e5f7 100644 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/CacheKeyFactory.java +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/CacheKeyFactory.java @@ -17,18 +17,19 @@ package io.fd.honeycomb.translate.util.read.cache; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; /** * Provides keys for provided {@code InstanceIdentifier} */ -public interface CacheKeyFactory { +public interface CacheKeyFactory<U> { /** - * Construct key accordingly to provided {@code InstanceIdentifier<?>} + * Construct key accordingly to provided {@code InstanceIdentifier<?>} and dumpParams */ @Nonnull - String createKey(@Nonnull final InstanceIdentifier<?> actualContextIdentifier); + String createKey(@Nonnull final InstanceIdentifier<?> actualContextIdentifier, @Nullable final U dumpParams); /** * Returns type of data, for which is this factory creating keys diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/DumpCacheManager.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/DumpCacheManager.java index adcd32e0c..d3cfd415a 100644 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/DumpCacheManager.java +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/DumpCacheManager.java @@ -42,7 +42,7 @@ public final class DumpCacheManager<T, U> { private final EntityDumpExecutor<T, U> dumpExecutor; private final EntityDumpPostProcessingFunction<T> postProcessor; - private final CacheKeyFactory cacheKeyFactory; + private final CacheKeyFactory<U> cacheKeyFactory; private final Class<?> acceptOnly; private DumpCacheManager(DumpCacheManagerBuilder<T, U> builder) { @@ -66,7 +66,7 @@ public final class DumpCacheManager<T, U> { @Nonnull final ModificationCache cache, final U dumpParams) throws ReadFailedException { - final String entityKey = this.cacheKeyFactory.createKey(identifier); + final String entityKey = this.cacheKeyFactory.createKey(identifier, dumpParams); // this key binding to every log has its logic ,because every customizer have its own cache manager and if // there is need for debugging/fixing some complex call with a lot of data,you can get lost in those logs LOG.debug("Loading dump for KEY[{}]", entityKey); @@ -120,7 +120,7 @@ public final class DumpCacheManager<T, U> { /** * Key providing unique(type-aware) keys. */ - public DumpCacheManagerBuilder<T, U> withCacheKeyFactory(@Nonnull final CacheKeyFactory cacheKeyFactory) { + public DumpCacheManagerBuilder<T, U> withCacheKeyFactory(@Nonnull final CacheKeyFactory<U> cacheKeyFactory) { this.cacheKeyFactory = cacheKeyFactory; return this; } diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/TypeAwareIdentifierCacheKeyFactory.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/TypeAwareIdentifierCacheKeyFactory.java index ba4e7e493..3cefedb95 100644 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/TypeAwareIdentifierCacheKeyFactory.java +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/TypeAwareIdentifierCacheKeyFactory.java @@ -20,11 +20,13 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static org.opendaylight.yangtools.yang.binding.InstanceIdentifier.IdentifiableItem; +import com.google.common.annotations.VisibleForTesting; import java.util.Collections; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.StreamSupport; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.Identifiable; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -32,9 +34,11 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; /** * Factory providing cache keys to easier switching between scopes of caching */ -public final class TypeAwareIdentifierCacheKeyFactory implements CacheKeyFactory { +public final class TypeAwareIdentifierCacheKeyFactory<U> implements CacheKeyFactory<U> { private static final String KEY_PARTS_SEPARATOR = "|"; + @VisibleForTesting + protected static final String NO_PARAMS_KEY = "NO_PARAMS"; // should be Set<Class<? extends DataObject & Identifiable<?>>>, but that's not possible for wildcards private final Set<Class<? extends DataObject>> additionalKeyTypes; @@ -78,14 +82,15 @@ public final class TypeAwareIdentifierCacheKeyFactory implements CacheKeyFactory } @Override - public String createKey(@Nonnull final InstanceIdentifier<?> actualContextIdentifier) { + public String createKey(@Nonnull final InstanceIdentifier<?> actualContextIdentifier, @Nullable final U dumpParams) { checkNotNull(actualContextIdentifier, "Cannot construct key for null InstanceIdentifier"); // easiest case when only simple key is needed if (additionalKeyTypes.isEmpty()) { return String - .join(KEY_PARTS_SEPARATOR, type.getTypeName(), actualContextIdentifier.getTargetType().toString()); + .join(KEY_PARTS_SEPARATOR, type.getTypeName(), params(dumpParams), + actualContextIdentifier.getTargetType().toString()); } checkArgument(isUniqueKeyConstructable(actualContextIdentifier), @@ -95,7 +100,15 @@ public final class TypeAwareIdentifierCacheKeyFactory implements CacheKeyFactory // joins unique key in form : type | additional keys | actual context return String .join(KEY_PARTS_SEPARATOR, type.getTypeName(), additionalKeys(actualContextIdentifier), - actualContextIdentifier.getTargetType().toString()); + params(dumpParams), actualContextIdentifier.getTargetType().toString()); + } + + private String params(final U dumpParams) { + if (dumpParams == null) { + return NO_PARAMS_KEY; + } else { + return String.valueOf(dumpParams.hashCode()); + } } @Override |