org.apache.gobblin.metrics.Tag.toMap()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(4.6k)|赞(0)|评价(0)|浏览(97)

本文整理了Java中org.apache.gobblin.metrics.Tag.toMap()方法的一些代码示例,展示了Tag.toMap()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tag.toMap()方法的具体详情如下:
包路径:org.apache.gobblin.metrics.Tag
类名称:Tag
方法名:toMap

Tag.toMap介绍

[英]Converts a List of Tags to a Map of key, value pairs.
[中]将标记列表转换为键、值对的映射。

代码示例

代码示例来源:origin: apache/incubator-gobblin

/**
 * Build the {@link EventSubmitter} for this class.
 */
private EventSubmitter buildEventSubmitter(List<? extends Tag<?>> tags) {
 return new EventSubmitter.Builder(this.runtimeMetricContext, "gobblin.runtime")
   .addMetadata(Tag.toMap(Tag.tagValuesToString(tags))).build();
}

代码示例来源:origin: apache/incubator-gobblin

@Test
public void testSubTaggedMetricContext() throws Exception {
 MetricContextFactory<SimpleScopeType> factory = new MetricContextFactory<>();
 Config config = ConfigFactory.parseMap(ImmutableMap.of(
   BrokerConfigurationKeyGenerator.generateKey(factory, null, null, MetricContextFactory.TAG_KEY + ".tag1"), "value1"
 ));
 SharedResourcesBroker<SimpleScopeType> rootBroker = SharedResourcesBrokerFactory.createDefaultTopLevelBroker(config,
   SimpleScopeType.GLOBAL.defaultScopeInstance());
 MetricContext metricContext = rootBroker.getSharedResource(factory,
   new SubTaggedMetricContextKey("myMetricContext", ImmutableMap.of("tag2", "value2")));
 Map<String, String> tagMap = (Map<String, String>) Tag.toMap(Tag.tagValuesToString(metricContext.getTags()));
 Assert.assertEquals(metricContext.getName(), "myMetricContext");
 Assert.assertEquals(tagMap.get("tag1"), "value1");
 Assert.assertEquals(tagMap.get("tag2"), "value2");
 MetricContext metricContext2 = rootBroker.getSharedResource(factory,
   new SubTaggedMetricContextKey("myMetricContext", ImmutableMap.of("tag2", "value2")));
 Assert.assertEquals(metricContext, metricContext2);
 MetricContext metricContext3 = rootBroker.getSharedResource(factory,
   new SubTaggedMetricContextKey("myMetricContext", ImmutableMap.of("tag3", "value3")));
 Assert.assertNotEquals(metricContext, metricContext3);
 MetricContext parent = rootBroker.getSharedResource(factory, new MetricContextKey());
 tagMap = (Map<String, String>) Tag.toMap(Tag.tagValuesToString(parent.getTags()));
 Assert.assertEquals(metricContext.getParent().get(), parent);
 Assert.assertEquals(tagMap.get("tag1"), "value1");
 Assert.assertFalse(tagMap.containsKey("tag2"));
}

代码示例来源:origin: apache/incubator-gobblin

@Test
public void test() throws Exception {
 MetricContextFactory<SimpleScopeType> factory = new MetricContextFactory<>();
 Config config = ConfigFactory.parseMap(ImmutableMap.of(
   BrokerConfigurationKeyGenerator.generateKey(factory, null, null, MetricContextFactory.TAG_KEY + ".tag1"), "value1",
   BrokerConfigurationKeyGenerator.generateKey(factory, null, SimpleScopeType.GLOBAL, MetricContextFactory.TAG_KEY + ".tag2"), "value2",
   BrokerConfigurationKeyGenerator.generateKey(factory, null, SimpleScopeType.LOCAL, MetricContextFactory.TAG_KEY + ".tag3"), "value3"
 ));
 SharedResourcesBroker<SimpleScopeType> rootBroker = SharedResourcesBrokerFactory.createDefaultTopLevelBroker(config,
   SimpleScopeType.GLOBAL.defaultScopeInstance());
 SharedResourcesBroker<SimpleScopeType> localBroker = rootBroker.newSubscopedBuilder(SimpleScopeType.LOCAL.defaultScopeInstance()).build();
 MetricContext localContext = localBroker.getSharedResource(factory, new MetricContextKey());
 Map<String, String> tagMap = (Map<String, String>) Tag.toMap(Tag.tagValuesToString(localContext.getTags()));
 Assert.assertEquals(tagMap.get("tag1"), "value1");
 Assert.assertEquals(tagMap.get("tag2"), "value2");
 Assert.assertEquals(tagMap.get("tag3"), "value3");
 MetricContext globalContext = rootBroker.getSharedResource(factory, new MetricContextKey());
 Assert.assertEquals(localContext.getParent().get(), globalContext);
 tagMap = (Map<String, String>) Tag.toMap(Tag.tagValuesToString(globalContext.getTags()));
 Assert.assertEquals(tagMap.get("tag1"), "value1");
 Assert.assertEquals(tagMap.get("tag2"), "value2");
 Assert.assertFalse(tagMap.containsKey("tag3"));
}

代码示例来源:origin: org.apache.gobblin/gobblin-runtime

/**
 * Build the {@link EventSubmitter} for this class.
 */
private EventSubmitter buildEventSubmitter(List<? extends Tag<?>> tags) {
 return new EventSubmitter.Builder(this.runtimeMetricContext, "gobblin.runtime")
   .addMetadata(Tag.toMap(Tag.tagValuesToString(tags))).build();
}

相关文章