org.apache.flink.cep.nfa.sharedbuffer.SharedBuffer Java Examples

The following examples show how to use org.apache.flink.cep.nfa.sharedbuffer.SharedBuffer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CepOperator.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private void migrateOldState() throws Exception {
	getKeyedStateBackend().applyToAllKeys(
		VoidNamespace.INSTANCE,
		VoidNamespaceSerializer.INSTANCE,
		new ValueStateDescriptor<>(
			"nfaOperatorStateName",
			new NFA.NFASerializer<>(inputSerializer)
		),
		new KeyedStateFunction<Object, ValueState<MigratedNFA<IN>>>() {
			@Override
			public void process(Object key, ValueState<MigratedNFA<IN>> state) throws Exception {
				MigratedNFA<IN> oldState = state.value();
				computationStates.update(new NFAState(oldState.getComputationStates()));
				org.apache.flink.cep.nfa.SharedBuffer<IN> sharedBuffer = oldState.getSharedBuffer();
				partialMatches.init(sharedBuffer.getEventsBuffer(), sharedBuffer.getPages());
				state.clear();
			}
		}
	);
}
 
Example #2
Source File: AfterMatchSkipITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testSharedBufferIsProperlyCleared() throws Exception {
	List<StreamRecord<Event>> inputEvents = new ArrayList<>();

	for (int i = 0; i < 4; i++) {
		inputEvents.add(new StreamRecord<>(new Event(1, "a", 1.0), i));
	}

	SkipPastLastStrategy matchSkipStrategy = AfterMatchSkipStrategy.skipPastLastEvent();
	Pattern<Event, ?> pattern = Pattern.<Event>begin("start", matchSkipStrategy)
		.where(new SimpleCondition<Event>() {
			private static final long serialVersionUID = 5726188262756267490L;

			@Override
			public boolean filter(Event value) throws Exception {
				return true;
			}
		}).times(2);

	SharedBuffer<Event> sharedBuffer = TestSharedBuffer.createTestBuffer(Event.createTypeSerializer());
	NFATestHarness nfaTestHarness = NFATestHarness.forPattern(pattern).withSharedBuffer(sharedBuffer).build();

	nfaTestHarness.feedRecords(inputEvents);

	assertThat(sharedBuffer.isEmpty(), Matchers.is(true));
}
 
Example #3
Source File: CepOperator.java    From flink with Apache License 2.0 6 votes vote down vote up
private void migrateOldState() throws Exception {
	getKeyedStateBackend().applyToAllKeys(
		VoidNamespace.INSTANCE,
		VoidNamespaceSerializer.INSTANCE,
		new ValueStateDescriptor<>(
			"nfaOperatorStateName",
			new NFA.NFASerializer<>(inputSerializer)
		),
		new KeyedStateFunction<Object, ValueState<MigratedNFA<IN>>>() {
			@Override
			public void process(Object key, ValueState<MigratedNFA<IN>> state) throws Exception {
				MigratedNFA<IN> oldState = state.value();
				computationStates.update(new NFAState(oldState.getComputationStates()));
				org.apache.flink.cep.nfa.SharedBuffer<IN> sharedBuffer = oldState.getSharedBuffer();
				partialMatches.init(sharedBuffer.getEventsBuffer(), sharedBuffer.getPages());
				state.clear();
			}
		}
	);
}
 
Example #4
Source File: CepOperator.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void initializeState(StateInitializationContext context) throws Exception {
	super.initializeState(context);

	// initializeState through the provided context
	computationStates = context.getKeyedStateStore().getState(
		new ValueStateDescriptor<>(
			NFA_STATE_NAME,
			new NFAStateSerializer()));

	partialMatches = new SharedBuffer<>(context.getKeyedStateStore(), inputSerializer);

	elementQueueState = context.getKeyedStateStore().getMapState(
			new MapStateDescriptor<>(
					EVENT_QUEUE_STATE_NAME,
					LongSerializer.INSTANCE,
					new ListSerializer<>(inputSerializer)));

	migrateOldState();
}
 
Example #5
Source File: AfterMatchSkipITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testSharedBufferIsProperlyCleared() throws Exception {
	List<StreamRecord<Event>> inputEvents = new ArrayList<>();

	for (int i = 0; i < 4; i++) {
		inputEvents.add(new StreamRecord<>(new Event(1, "a", 1.0), i));
	}

	SkipPastLastStrategy matchSkipStrategy = AfterMatchSkipStrategy.skipPastLastEvent();
	Pattern<Event, ?> pattern = Pattern.<Event>begin("start", matchSkipStrategy)
		.where(new SimpleCondition<Event>() {
			private static final long serialVersionUID = 5726188262756267490L;

			@Override
			public boolean filter(Event value) throws Exception {
				return true;
			}
		}).times(2);

	SharedBuffer<Event> sharedBuffer = TestSharedBuffer.createTestBuffer(Event.createTypeSerializer());
	NFATestHarness nfaTestHarness = NFATestHarness.forPattern(pattern).withSharedBuffer(sharedBuffer).build();

	nfaTestHarness.feedRecords(inputEvents);

	assertThat(sharedBuffer.isEmpty(), Matchers.is(true));
}
 
Example #6
Source File: CepOperator.java    From flink with Apache License 2.0 6 votes vote down vote up
private void migrateOldState() throws Exception {
	getKeyedStateBackend().applyToAllKeys(
		VoidNamespace.INSTANCE,
		VoidNamespaceSerializer.INSTANCE,
		new ValueStateDescriptor<>(
			"nfaOperatorStateName",
			new NFA.NFASerializer<>(inputSerializer)
		),
		new KeyedStateFunction<Object, ValueState<MigratedNFA<IN>>>() {
			@Override
			public void process(Object key, ValueState<MigratedNFA<IN>> state) throws Exception {
				MigratedNFA<IN> oldState = state.value();
				computationStates.update(new NFAState(oldState.getComputationStates()));
				org.apache.flink.cep.nfa.SharedBuffer<IN> sharedBuffer = oldState.getSharedBuffer();
				partialMatches.init(sharedBuffer.getEventsBuffer(), sharedBuffer.getPages());
				state.clear();
			}
		}
	);
}
 
Example #7
Source File: CepOperator.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void initializeState(StateInitializationContext context) throws Exception {
	super.initializeState(context);

	// initializeState through the provided context
	computationStates = context.getKeyedStateStore().getState(
		new ValueStateDescriptor<>(
			NFA_STATE_NAME,
			new NFAStateSerializer()));

	partialMatches = new SharedBuffer<>(context.getKeyedStateStore(), inputSerializer);

	elementQueueState = context.getKeyedStateStore().getMapState(
			new MapStateDescriptor<>(
					EVENT_QUEUE_STATE_NAME,
					LongSerializer.INSTANCE,
					new ListSerializer<>(inputSerializer)));

	migrateOldState();
}
 
Example #8
Source File: AfterMatchSkipITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testSharedBufferIsProperlyCleared() throws Exception {
	List<StreamRecord<Event>> inputEvents = new ArrayList<>();

	for (int i = 0; i < 4; i++) {
		inputEvents.add(new StreamRecord<>(new Event(1, "a", 1.0), i));
	}

	SkipPastLastStrategy matchSkipStrategy = AfterMatchSkipStrategy.skipPastLastEvent();
	Pattern<Event, ?> pattern = Pattern.<Event>begin("start", matchSkipStrategy)
		.where(new SimpleCondition<Event>() {
			private static final long serialVersionUID = 5726188262756267490L;

			@Override
			public boolean filter(Event value) throws Exception {
				return true;
			}
		}).times(2);

	SharedBuffer<Event> sharedBuffer = TestSharedBuffer.createTestBuffer(Event.createTypeSerializer());
	NFATestHarness nfaTestHarness = NFATestHarness.forPattern(pattern).withSharedBuffer(sharedBuffer).build();

	nfaTestHarness.feedRecords(inputEvents);

	assertThat(sharedBuffer.isEmpty(), Matchers.is(true));
}
 
Example #9
Source File: CepOperator.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public void initializeState(StateInitializationContext context) throws Exception {
	super.initializeState(context);

	// initializeState through the provided context
	computationStates = context.getKeyedStateStore().getState(
		new ValueStateDescriptor<>(
			NFA_STATE_NAME,
			new NFAStateSerializer()));

	partialMatches = new SharedBuffer<>(context.getKeyedStateStore(), inputSerializer);

	elementQueueState = context.getKeyedStateStore().getMapState(
			new MapStateDescriptor<>(
					EVENT_QUEUE_STATE_NAME,
					LongSerializer.INSTANCE,
					new ListSerializer<>(inputSerializer)));

	migrateOldState();
}
 
Example #10
Source File: NFATestHarness.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private NFATestHarness(
		SharedBuffer<Event> sharedBuffer,
		NFA<Event> nfa,
		NFAState nfaState,
		AfterMatchSkipStrategy afterMatchSkipStrategy,
		TimerService timerService) {
	this.sharedBuffer = sharedBuffer;
	this.nfa = nfa;
	this.nfaState = nfaState;
	this.afterMatchSkipStrategy = afterMatchSkipStrategy;
	this.timerService = timerService;
}
 
Example #11
Source File: NFATestHarness.java    From flink with Apache License 2.0 5 votes vote down vote up
private NFATestHarness(
		SharedBuffer<Event> sharedBuffer,
		NFA<Event> nfa,
		NFAState nfaState,
		AfterMatchSkipStrategy afterMatchSkipStrategy,
		TimerService timerService) {
	this.sharedBuffer = sharedBuffer;
	this.nfa = nfa;
	this.nfaState = nfaState;
	this.afterMatchSkipStrategy = afterMatchSkipStrategy;
	this.timerService = timerService;
}
 
Example #12
Source File: NFA.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public MigratedNFA<T> deserialize(DataInputView source) throws IOException {
	MigrationUtils.skipSerializedStates(source);
	source.readLong();
	source.readBoolean();

	org.apache.flink.cep.nfa.SharedBuffer<T> sharedBuffer = sharedBufferSerializer.deserialize(source);
	Queue<ComputationState> computationStates = deserializeComputationStates(sharedBuffer, eventSerializer, source);

	return new MigratedNFA<>(computationStates, sharedBuffer);
}
 
Example #13
Source File: NFA.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected NFASerializer<T> createOuterSerializerWithNestedSerializers(TypeSerializer<?>[] nestedSerializers) {
	@SuppressWarnings("unchecked")
	TypeSerializer<T> eventSerializer = (TypeSerializer<T>) nestedSerializers[0];

	@SuppressWarnings("unchecked")
	TypeSerializer<org.apache.flink.cep.nfa.SharedBuffer<T>> sharedBufferSerializer =
		(TypeSerializer<org.apache.flink.cep.nfa.SharedBuffer<T>>) nestedSerializers[1];

	return new NFASerializer<>(eventSerializer, sharedBufferSerializer);
}
 
Example #14
Source File: NFATestHarness.java    From flink with Apache License 2.0 5 votes vote down vote up
private NFATestHarness(
		SharedBuffer<Event> sharedBuffer,
		NFA<Event> nfa,
		NFAState nfaState,
		AfterMatchSkipStrategy afterMatchSkipStrategy,
		TimerService timerService) {
	this.sharedBuffer = sharedBuffer;
	this.nfa = nfa;
	this.nfaState = nfaState;
	this.afterMatchSkipStrategy = afterMatchSkipStrategy;
	this.timerService = timerService;
}
 
Example #15
Source File: NFA.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public MigratedNFA<T> deserialize(DataInputView source) throws IOException {
	MigrationUtils.skipSerializedStates(source);
	source.readLong();
	source.readBoolean();

	org.apache.flink.cep.nfa.SharedBuffer<T> sharedBuffer = sharedBufferSerializer.deserialize(source);
	Queue<ComputationState> computationStates = deserializeComputationStates(sharedBuffer, eventSerializer, source);

	return new MigratedNFA<>(computationStates, sharedBuffer);
}
 
Example #16
Source File: NFA.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected NFASerializer<T> createOuterSerializerWithNestedSerializers(TypeSerializer<?>[] nestedSerializers) {
	@SuppressWarnings("unchecked")
	TypeSerializer<T> eventSerializer = (TypeSerializer<T>) nestedSerializers[0];

	@SuppressWarnings("unchecked")
	TypeSerializer<org.apache.flink.cep.nfa.SharedBuffer<T>> sharedBufferSerializer =
		(TypeSerializer<org.apache.flink.cep.nfa.SharedBuffer<T>>) nestedSerializers[1];

	return new NFASerializer<>(eventSerializer, sharedBufferSerializer);
}
 
Example #17
Source File: NFA.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public MigratedNFA<T> deserialize(DataInputView source) throws IOException {
	MigrationUtils.skipSerializedStates(source);
	source.readLong();
	source.readBoolean();

	org.apache.flink.cep.nfa.SharedBuffer<T> sharedBuffer = sharedBufferSerializer.deserialize(source);
	Queue<ComputationState> computationStates = deserializeComputationStates(sharedBuffer, eventSerializer, source);

	return new MigratedNFA<>(computationStates, sharedBuffer);
}
 
Example #18
Source File: NFA.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected NFASerializer<T> createOuterSerializerWithNestedSerializers(TypeSerializer<?>[] nestedSerializers) {
	@SuppressWarnings("unchecked")
	TypeSerializer<T> eventSerializer = (TypeSerializer<T>) nestedSerializers[0];

	@SuppressWarnings("unchecked")
	TypeSerializer<org.apache.flink.cep.nfa.SharedBuffer<T>> sharedBufferSerializer =
		(TypeSerializer<org.apache.flink.cep.nfa.SharedBuffer<T>>) nestedSerializers[1];

	return new NFASerializer<>(eventSerializer, sharedBufferSerializer);
}
 
Example #19
Source File: NFA.java    From flink with Apache License 2.0 4 votes vote down vote up
public org.apache.flink.cep.nfa.SharedBuffer<T> getSharedBuffer() {
	return sharedBuffer;
}
 
Example #20
Source File: NFATestHarness.java    From flink with Apache License 2.0 4 votes vote down vote up
public NFATestHarnessBuilderBase withSharedBuffer(SharedBuffer<Event> sharedBuffer) {
	this.sharedBuffer = sharedBuffer;
	return this;
}
 
Example #21
Source File: NFATestHarness.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public NFATestHarnessBuilderBase withSharedBuffer(SharedBuffer<Event> sharedBuffer) {
	this.sharedBuffer = sharedBuffer;
	return this;
}
 
Example #22
Source File: NFA.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
NFASerializer(
		TypeSerializer<T> typeSerializer,
		TypeSerializer<org.apache.flink.cep.nfa.SharedBuffer<T>> sharedBufferSerializer) {
	this.eventSerializer = typeSerializer;
	this.sharedBufferSerializer = sharedBufferSerializer;
}
 
Example #23
Source File: NFA.java    From flink with Apache License 2.0 4 votes vote down vote up
NFASerializer(
		TypeSerializer<T> typeSerializer,
		TypeSerializer<org.apache.flink.cep.nfa.SharedBuffer<T>> sharedBufferSerializer) {
	this.eventSerializer = typeSerializer;
	this.sharedBufferSerializer = sharedBufferSerializer;
}
 
Example #24
Source File: NFA.java    From flink with Apache License 2.0 4 votes vote down vote up
public NFASerializer(TypeSerializer<T> typeSerializer) {
	this(typeSerializer,
		new org.apache.flink.cep.nfa.SharedBuffer.SharedBufferSerializer<>(
			StringSerializer.INSTANCE,
			typeSerializer));
}
 
Example #25
Source File: NFA.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public NFASerializer(TypeSerializer<T> typeSerializer) {
	this(typeSerializer,
		new org.apache.flink.cep.nfa.SharedBuffer.SharedBufferSerializer<>(
			StringSerializer.INSTANCE,
			typeSerializer));
}
 
Example #26
Source File: NFA.java    From flink with Apache License 2.0 4 votes vote down vote up
public NFASerializerConfigSnapshot(
		TypeSerializer<T> eventSerializer,
		TypeSerializer<org.apache.flink.cep.nfa.SharedBuffer<T>> sharedBufferSerializer) {

	super(eventSerializer, sharedBufferSerializer);
}
 
Example #27
Source File: NFA.java    From flink with Apache License 2.0 4 votes vote down vote up
MigratedNFA(
		final Queue<ComputationState> computationStates,
		final org.apache.flink.cep.nfa.SharedBuffer<T> sharedBuffer) {
	this.sharedBuffer = sharedBuffer;
	this.computationStates = computationStates;
}
 
Example #28
Source File: NFA.java    From flink with Apache License 2.0 4 votes vote down vote up
public NFASerializerConfigSnapshot(
		TypeSerializer<T> eventSerializer,
		TypeSerializer<org.apache.flink.cep.nfa.SharedBuffer<T>> sharedBufferSerializer) {

	super(eventSerializer, sharedBufferSerializer);
}
 
Example #29
Source File: NFA.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public org.apache.flink.cep.nfa.SharedBuffer<T> getSharedBuffer() {
	return sharedBuffer;
}
 
Example #30
Source File: NFA.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
MigratedNFA(
		final Queue<ComputationState> computationStates,
		final org.apache.flink.cep.nfa.SharedBuffer<T> sharedBuffer) {
	this.sharedBuffer = sharedBuffer;
	this.computationStates = computationStates;
}