diff options
author | Maros Marsalek <mmarsale@cisco.com> | 2016-06-29 16:01:40 +0200 |
---|---|---|
committer | Maros Marsalek <mmarsale@cisco.com> | 2016-06-29 16:06:48 +0200 |
commit | f1bbf132dd65e6fbb26b23c9c1c39f86ce7f08bc (patch) | |
tree | 5d8243fb3dbc943301c81a863932b8a3ee642f05 /v3po/vpp-translate-utils/src | |
parent | d757d43b658bebeea75787d7a3b712e06c9ef69b (diff) |
HONEYCOMB-105 Make interface notification creation thread safe
Change-Id: Ife48ff6ed3c8290f223fd14df1366927923bad30
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Diffstat (limited to 'v3po/vpp-translate-utils/src')
-rw-r--r-- | v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/NamingContext.java | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/NamingContext.java b/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/NamingContext.java index bcc980dd4..dc77106fb 100644 --- a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/NamingContext.java +++ b/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/NamingContext.java @@ -76,6 +76,9 @@ public final class NamingContext implements AutoCloseable { if (!containsName(index, mappingContext)) { final String artificialName = getArtificialName(index); LOG.info("Assigning artificial name: {} for index: {}", artificialName, index); + for (StackTraceElement stackTraceElement : Thread.currentThread().getStackTrace()) { + LOG.error("{}", stackTraceElement.toString()); + } addName(index, artificialName, mappingContext); } @@ -88,6 +91,27 @@ public final class NamingContext implements AutoCloseable { } /** + * Retrieve name for mapping stored provided mappingContext instance. if present + * + * @param index index of a mapped item + * @param mappingContext mapping context providing context data for current transaction + * + * @return name mapped to provided index + */ + @Nonnull + public synchronized Optional<String> getNameIfPresent(final int index, + @Nonnull final MappingContext mappingContext) { + final Optional<Mappings> read = mappingContext.read(namingContextIid.child(Mappings.class)); + + return read.isPresent() + ? Optional.of(read.get().getMapping().stream() + .filter(mapping -> mapping.getIndex().equals(index)) + .collect(SINGLE_ITEM_COLLECTOR) + .getName()) + : Optional.absent(); + } + + /** * Check whether mapping is present for index. * * @param index index of a mapped item |