diff options
author | 2016-06-29 16:01:40 +0200 | |
---|---|---|
committer | 2016-06-29 16:06:48 +0200 | |
commit | fe7e4c45bdf74e91482964070205329d5009002d (patch) | |
tree | 7f866818ca4d5f82485b5bbd377f034b8048386f /v3po/vpp-translate-utils/src/main/java | |
parent | e187f2bd1301a3f20d5316c5a14a99b733f07550 (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/main/java')
-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 |