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


Java ValueState.value方法代码示例

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


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

示例1: testCopyDefaultValue

import org.apache.flink.api.common.state.ValueState; //导入方法依赖的package包/类
@Test
public void testCopyDefaultValue() throws Exception {
	final AbstractKeyedStateBackend<Integer> backend = createKeyedBackend(IntSerializer.INSTANCE);

	ValueStateDescriptor<IntValue> kvId = new ValueStateDescriptor<>("id", IntValue.class, new IntValue(-1));

	ValueState<IntValue> state = backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, kvId);

	backend.setCurrentKey(1);
	IntValue default1 = state.value();

	backend.setCurrentKey(2);
	IntValue default2 = state.value();

	assertNotNull(default1);
	assertNotNull(default2);
	assertEquals(default1, default2);
	assertFalse(default1 == default2);

	backend.dispose();
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:22,代码来源:StateBackendTestBase.java

示例2: onElement

import org.apache.flink.api.common.state.ValueState; //导入方法依赖的package包/类
@Override
public TriggerResult onElement(T element, long timestamp, W window, TriggerContext ctx) throws Exception {
	ValueState<T> lastElementState = ctx.getPartitionedState(stateDesc);
	if (lastElementState.value() == null) {
		lastElementState.update(element);
		return TriggerResult.CONTINUE;
	}
	if (deltaFunction.getDelta(lastElementState.value(), element) > this.threshold) {
		lastElementState.update(element);
		return TriggerResult.FIRE;
	}
	return TriggerResult.CONTINUE;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:14,代码来源:DeltaTrigger.java

示例3: testValueStateRestoreWithWrongSerializers

import org.apache.flink.api.common.state.ValueState; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testValueStateRestoreWithWrongSerializers() throws Exception {
	CheckpointStreamFactory streamFactory = createStreamFactory();
	AbstractKeyedStateBackend<Integer> backend = createKeyedBackend(IntSerializer.INSTANCE);

	try {
		ValueStateDescriptor<String> kvId = new ValueStateDescriptor<>("id", String.class);

		ValueState<String> state = backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, kvId);

		backend.setCurrentKey(1);
		state.update("1");
		backend.setCurrentKey(2);
		state.update("2");

		// draw a snapshot
		KeyedStateHandle snapshot1 = FutureUtil.runIfNotDoneAndGet(backend.snapshot(682375462378L, 2, streamFactory, CheckpointOptions.forCheckpoint()));

		backend.dispose();
		// restore the first snapshot and validate it
		backend = restoreKeyedBackend(IntSerializer.INSTANCE, snapshot1);
		snapshot1.discardState();

		@SuppressWarnings("unchecked")
		TypeSerializer<String> fakeStringSerializer =
			(TypeSerializer<String>) (TypeSerializer<?>) FloatSerializer.INSTANCE;

		try {
			kvId = new ValueStateDescriptor<>("id", fakeStringSerializer);

			state = backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, kvId);

			state.value();

			fail("should recognize wrong serializers");
		} catch (StateMigrationException ignored) {
			// expected
		}
	} finally {
		backend.dispose();
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:44,代码来源:StateBackendTestBase.java


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