• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java IntCounter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



IntCounter类属于org.apache.flink.api.common.accumulators包,在下文中一共展示了IntCounter类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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() throws Exception {
	super.open();

	timerService = getInternalTimerService(
			"timer",
			LongSerializer.INSTANCE,
			this);

	getRuntimeContext().addAccumulator(SUCCESSFUL_PROCESS_CHECK_ACCUMULATOR, new IntCounter());
	getRuntimeContext().addAccumulator(SUCCESSFUL_EVENT_TIME_CHECK_ACCUMULATOR, new IntCounter());
	getRuntimeContext().addAccumulator(SUCCESSFUL_PROCESSING_TIME_CHECK_ACCUMULATOR, new IntCounter());
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:14,代码来源:StatefulJobSavepointFrom12MigrationITCase.java


示例4: 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


示例5: checkUserAccumulators

import org.apache.flink.api.common.accumulators.IntCounter; //导入依赖的package包/类
private static boolean checkUserAccumulators(int expected, Map<String, Accumulator<?, ?>> accumulatorMap) {
	LOG.info("checking user accumulators");
	return accumulatorMap.containsKey(ACCUMULATOR_NAME) && expected == ((IntCounter) accumulatorMap.get(ACCUMULATOR_NAME)).getLocalValue();
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:5,代码来源:AccumulatorLiveITCase.java


示例6: open

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

	getRuntimeContext().addAccumulator(SUCCESSFUL_CHECK_ACCUMULATOR, new IntCounter());
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:7,代码来源:StatefulJobSavepointFrom11MigrationITCase.java


示例7: getIntCounter

import org.apache.flink.api.common.accumulators.IntCounter; //导入依赖的package包/类
@Override
public IntCounter getIntCounter(String name) {
	return (IntCounter) getAccumulator(name, IntCounter.class);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:5,代码来源:AbstractRuntimeUDFContext.java


示例8: testHandleRequest

import org.apache.flink.api.common.accumulators.IntCounter; //导入依赖的package包/类
@Test
public void testHandleRequest() throws Exception {

	// Instance the handler.
	final RestHandlerConfiguration restHandlerConfiguration = RestHandlerConfiguration.fromConfiguration(new Configuration());

	final SubtaskExecutionAttemptAccumulatorsHandler handler = new SubtaskExecutionAttemptAccumulatorsHandler(
		CompletableFuture.completedFuture("127.0.0.1:9527"),
		() -> null,
		Time.milliseconds(100L),
		restHandlerConfiguration.getResponseHeaders(),
		null,
		new ExecutionGraphCache(
			restHandlerConfiguration.getTimeout(),
			Time.milliseconds(restHandlerConfiguration.getRefreshInterval())),
		TestingUtils.defaultExecutor());

	// Instance a empty request.
	final HandlerRequest<EmptyRequestBody, SubtaskAttemptMessageParameters> request = new HandlerRequest<>(
		EmptyRequestBody.getInstance(),
		new SubtaskAttemptMessageParameters()
	);

	final Map<String, Accumulator<?, ?>> userAccumulators = new HashMap<>(2);
	userAccumulators.put("IntCounter", new IntCounter(10));
	userAccumulators.put("LongCounter", new LongCounter(100L));

	// Instance the expected result.
	final StringifiedAccumulatorResult[] accumulatorResults =
		StringifiedAccumulatorResult.stringifyAccumulatorResults(userAccumulators);

	final int attemptNum = 1;
	final int subtaskIndex = 2;

	// Instance the tested execution.
	final ArchivedExecution execution = new ArchivedExecution(
		accumulatorResults,
		null,
		new ExecutionAttemptID(),
		attemptNum,
		ExecutionState.FINISHED,
		null,
		null,
		subtaskIndex,
		new long[ExecutionState.values().length]);

	// Invoke tested method.
	final SubtaskExecutionAttemptAccumulatorsInfo accumulatorsInfo = handler.handleRequest(request, execution);

	final ArrayList<UserAccumulator> userAccumulatorList = new ArrayList<>(userAccumulators.size());
	for (StringifiedAccumulatorResult accumulatorResult : accumulatorResults) {
		userAccumulatorList.add(
			new UserAccumulator(
				accumulatorResult.getName(),
				accumulatorResult.getType(),
				accumulatorResult.getValue()));
	}

	final SubtaskExecutionAttemptAccumulatorsInfo expected = new SubtaskExecutionAttemptAccumulatorsInfo(
		subtaskIndex,
		attemptNum,
		execution.getAttemptId().toString(),
		userAccumulatorList);

	// Verify.
	assertEquals(expected, accumulatorsInfo);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:68,代码来源:SubtaskExecutionAttemptAccumulatorsHandlerTest.java


示例9: testAccumulatorsAndMetricsForwarding

import org.apache.flink.api.common.accumulators.IntCounter; //导入依赖的package包/类
/**
 * Verifies that {@link ExecutionGraph#updateState(TaskExecutionState)} updates the accumulators and metrics for an
 * execution that failed or was canceled.
 */
@Test
public void testAccumulatorsAndMetricsForwarding() throws Exception {
	final JobVertexID jid1 = new JobVertexID();
	final JobVertexID jid2 = new JobVertexID();

	JobVertex v1 = new JobVertex("v1", jid1);
	JobVertex v2 = new JobVertex("v2", jid2);

	Tuple2<ExecutionGraph, Map<ExecutionAttemptID, Execution>> graphAndExecutions = setupExecution(v1, 1, v2, 1);
	ExecutionGraph graph = graphAndExecutions.f0;
	
	// verify behavior for canceled executions
	Execution execution1 = graphAndExecutions.f1.values().iterator().next();

	IOMetrics ioMetrics = new IOMetrics(0, 0, 0, 0, 0, 0.0, 0.0, 0.0, 0.0, 0.0);
	Map<String, Accumulator<?, ?>> accumulators = new HashMap<>();
	accumulators.put("acc", new IntCounter(4));
	AccumulatorSnapshot accumulatorSnapshot = new AccumulatorSnapshot(graph.getJobID(), execution1.getAttemptId(), accumulators);
	
	TaskExecutionState state = new TaskExecutionState(graph.getJobID(), execution1.getAttemptId(), ExecutionState.CANCELED, null, accumulatorSnapshot, ioMetrics);
	
	graph.updateState(state);
	
	assertEquals(ioMetrics, execution1.getIOMetrics());
	assertNotNull(execution1.getUserAccumulators());
	assertEquals(4, execution1.getUserAccumulators().get("acc").getLocalValue());
	
	// verify behavior for failed executions
	Execution execution2 = graphAndExecutions.f1.values().iterator().next();

	IOMetrics ioMetrics2 = new IOMetrics(0, 0, 0, 0, 0, 0.0, 0.0, 0.0, 0.0, 0.0);
	Map<String, Accumulator<?, ?>> accumulators2 = new HashMap<>();
	accumulators2.put("acc", new IntCounter(8));
	AccumulatorSnapshot accumulatorSnapshot2 = new AccumulatorSnapshot(graph.getJobID(), execution2.getAttemptId(), accumulators2);

	TaskExecutionState state2 = new TaskExecutionState(graph.getJobID(), execution2.getAttemptId(), ExecutionState.FAILED, null, accumulatorSnapshot2, ioMetrics2);

	graph.updateState(state2);

	assertEquals(ioMetrics2, execution2.getIOMetrics());
	assertNotNull(execution2.getUserAccumulators());
	assertEquals(8, execution2.getUserAccumulators().get("acc").getLocalValue());
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:48,代码来源:ExecutionGraphDeploymentTest.java


示例10: getIntCounter

import org.apache.flink.api.common.accumulators.IntCounter; //导入依赖的package包/类
@Override
public IntCounter getIntCounter(String name) {
	throw new UnsupportedOperationException("Int counters are not supported in rich async functions.");
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:5,代码来源:RichAsyncFunction.java


示例11: getIntCounter

import org.apache.flink.api.common.accumulators.IntCounter; //导入依赖的package包/类
@Override
public IntCounter getIntCounter(String name) {
	throw new UnsupportedOperationException();
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:5,代码来源:MockRuntimeContext.java


示例12: getIntCounter

import org.apache.flink.api.common.accumulators.IntCounter; //导入依赖的package包/类
@Override
public IntCounter getIntCounter(String name) {
	return context.getIntCounter(name);
}
 
开发者ID:citlab,项目名称:vs.msc.ws14,代码行数:5,代码来源:WrappingFunction.java


示例13: getIntCounter

import org.apache.flink.api.common.accumulators.IntCounter; //导入依赖的package包/类
/**
 * Convenience function to create a counter object for integers.
 */
@PublicEvolving
IntCounter getIntCounter(String name);
 
开发者ID:axbaretto,项目名称:flink,代码行数:6,代码来源:RuntimeContext.java


示例14: getIntCounter

import org.apache.flink.api.common.accumulators.IntCounter; //导入依赖的package包/类
/**
 * Convenience function to create a counter object for integers.
 */
IntCounter getIntCounter(String name);
 
开发者ID:citlab,项目名称:vs.msc.ws14,代码行数:5,代码来源:RuntimeContext.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Scoreboard类代码示例发布时间:2022-05-23
下一篇:
Java XBreakpointGroupingRule类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap