当前位置: 首页>>代码示例>>Java>>正文


Java IntCounter.add方法代码示例

本文整理汇总了Java中org.apache.flink.api.common.accumulators.IntCounter.add方法的典型用法代码示例。如果您正苦于以下问题:Java IntCounter.add方法的具体用法?Java IntCounter.add怎么用?Java IntCounter.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.flink.api.common.accumulators.IntCounter的用法示例。


在下文中一共展示了IntCounter.add方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: stringifyingResultsShouldIncorporateAccumulatorLocalValueDirectly

import org.apache.flink.api.common.accumulators.IntCounter; //导入方法依赖的package包/类
@Test
public void stringifyingResultsShouldIncorporateAccumulatorLocalValueDirectly() {
	final String name = "a";
	final int targetValue = 314159;
	final IntCounter acc = new IntCounter();
	acc.add(targetValue);
	final Map<String, Accumulator<?, ?>> accumulatorMap = new HashMap<>();
	accumulatorMap.put(name, acc);

	final StringifiedAccumulatorResult[] results = StringifiedAccumulatorResult.stringifyAccumulatorResults(accumulatorMap);

	assertEquals(1, results.length);

	final StringifiedAccumulatorResult firstResult = results[0];
	assertEquals(name, firstResult.getName());
	assertEquals("IntCounter", firstResult.getType());
	assertEquals(Integer.toString(targetValue), firstResult.getValue());
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:19,代码来源:StringifiedAccumulatorResultTest.java

示例2: open

import org.apache.flink.api.common.accumulators.IntCounter; //导入方法依赖的package包/类
@Override
public void open(Configuration parameters) {

	// Add counters using convenience functions
	this.cntNumLines = getRuntimeContext().getIntCounter("num-lines");
	this.wordsPerLineDistribution = getRuntimeContext().getHistogram("words-per-line");

	// Add built-in accumulator without convenience function
	getRuntimeContext().addAccumulator("open-close-counter", this.openCloseCounter);

	// Add custom counter
	this.distinctWords = new SetAccumulator<>();
	this.getRuntimeContext().addAccumulator("distinct-words", distinctWords);

	// Create counter and test increment
	IntCounter simpleCounter = getRuntimeContext().getIntCounter("simple-counter");
	simpleCounter.add(1);
	Assert.assertEquals(simpleCounter.getLocalValue().intValue(), 1);

	// Test if we get the same counter
	IntCounter simpleCounter2 = getRuntimeContext().getIntCounter("simple-counter");
	Assert.assertEquals(simpleCounter.getLocalValue(), simpleCounter2.getLocalValue());

	// Should fail if we request it with different type
	try {
		@SuppressWarnings("unused")
		DoubleCounter simpleCounter3 = getRuntimeContext().getDoubleCounter("simple-counter");
		// DoubleSumAggregator longAggregator3 = (DoubleSumAggregator)
		// getRuntimeContext().getAggregator("custom",
		// DoubleSumAggregator.class);
		Assert.fail("Should not be able to obtain previously created counter with different type");
	}
	catch (UnsupportedOperationException ex) {
		// expected!
	}

	// Test counter used in open() and closed()
	this.openCloseCounter.add(0.5);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:40,代码来源:AccumulatorITCase.java

示例3: open

import org.apache.flink.api.common.accumulators.IntCounter; //导入方法依赖的package包/类
@Override
public void open(Configuration parameters) {
  
	// Add counters using convenience functions
	this.cntNumLines = getRuntimeContext().getIntCounter("num-lines");
	this.wordsPerLineDistribution = getRuntimeContext().getHistogram("words-per-line");

	// Add built-in accumulator without convenience function
	getRuntimeContext().addAccumulator("open-close-counter", this.openCloseCounter);

	// Add custom counter. Didn't find a way to do this with
	// getAccumulator()
	this.distinctWords = new SetAccumulator<StringValue>();
	this.getRuntimeContext().addAccumulator("distinct-words", distinctWords);

	// Create counter and test increment
	IntCounter simpleCounter = getRuntimeContext().getIntCounter("simple-counter");
	simpleCounter.add(1);
	Assert.assertEquals(simpleCounter.getLocalValue().intValue(), 1);

	// Test if we get the same counter
	IntCounter simpleCounter2 = getRuntimeContext().getIntCounter("simple-counter");
	Assert.assertEquals(simpleCounter.getLocalValue(), simpleCounter2.getLocalValue());

	// Should fail if we request it with different type
	try {
		@SuppressWarnings("unused")
		DoubleCounter simpleCounter3 = getRuntimeContext().getDoubleCounter("simple-counter");
		// DoubleSumAggregator longAggregator3 = (DoubleSumAggregator)
		// getRuntimeContext().getAggregator("custom",
		// DoubleSumAggregator.class);
		Assert.fail("Should not be able to obtain previously created counter with different type");
	} catch (UnsupportedOperationException ex) {
	}

	// Test counter used in open() and closed()
	this.openCloseCounter.add(0.5);
}
 
开发者ID:citlab,项目名称:vs.msc.ws14,代码行数:39,代码来源:AccumulatorITCase.java


注:本文中的org.apache.flink.api.common.accumulators.IntCounter.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。