org.apache.flink.streaming.examples.statemachine.dfa.State Java Examples

The following examples show how to use org.apache.flink.streaming.examples.statemachine.dfa.State. 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: EventsGenerator.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an event for an illegal state transition of one of the internal
 * state machines. If the generator has not yet started any state machines
 * (for example, because no call to {@link #next(int, int)} was made, yet), this
 * will return null.
 *
 * @return An event for a illegal state transition, or null, if not possible.
 */
@Nullable
public Event nextInvalid() {
	final Iterator<Entry<Integer, State>> iter = states.entrySet().iterator();
	if (iter.hasNext()) {
		final Entry<Integer, State> entry = iter.next();

		State currentState = entry.getValue();
		int address = entry.getKey();
		iter.remove();

		EventType event = currentState.randomInvalidTransition(rnd);
		return new Event(event, address);
	}
	else {
		return null;
	}
}
 
Example #2
Source File: StateMachineExample.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public void flatMap(Event evt, Collector<Alert> out) throws Exception {
	// get the current state for the key (source address)
	// if no state exists, yet, the state must be the state machine's initial state
	State state = currentState.value();
	if (state == null) {
		state = State.Initial;
	}

	// ask the state machine what state we should go to based on the given event
	State nextState = state.transition(evt.type());

	if (nextState == State.InvalidTransition) {
		// the current event resulted in an invalid transition
		// raise an alert!
		out.collect(new Alert(evt.sourceAddress(), state, evt.type()));
	}
	else if (nextState.isTerminal()) {
		// we reached a terminal state, clean up the current state
		currentState.clear();
	}
	else {
		// remember the new state
		currentState.update(nextState);
	}
}
 
Example #3
Source File: EventsGenerator.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an event for an illegal state transition of one of the internal
 * state machines. If the generator has not yet started any state machines
 * (for example, because no call to {@link #next(int, int)} was made, yet), this
 * will return null.
 *
 * @return An event for a illegal state transition, or null, if not possible.
 */
@Nullable
public Event nextInvalid() {
	final Iterator<Entry<Integer, State>> iter = states.entrySet().iterator();
	if (iter.hasNext()) {
		final Entry<Integer, State> entry = iter.next();

		State currentState = entry.getValue();
		int address = entry.getKey();
		iter.remove();

		EventType event = currentState.randomInvalidTransition(rnd);
		return new Event(event, address);
	}
	else {
		return null;
	}
}
 
Example #4
Source File: StateMachineExample.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void flatMap(Event evt, Collector<Alert> out) throws Exception {
	// get the current state for the key (source address)
	// if no state exists, yet, the state must be the state machine's initial state
	State state = currentState.value();
	if (state == null) {
		state = State.Initial;
	}

	// ask the state machine what state we should go to based on the given event
	State nextState = state.transition(evt.type());

	if (nextState == State.InvalidTransition) {
		// the current event resulted in an invalid transition
		// raise an alert!
		out.collect(new Alert(evt.sourceAddress(), state, evt.type()));
	}
	else if (nextState.isTerminal()) {
		// we reached a terminal state, clean up the current state
		currentState.clear();
	}
	else {
		// remember the new state
		currentState.update(nextState);
	}
}
 
Example #5
Source File: EventsGenerator.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an event for an illegal state transition of one of the internal
 * state machines. If the generator has not yet started any state machines
 * (for example, because no call to {@link #next(int, int)} was made, yet), this
 * will return null.
 *
 * @return An event for a illegal state transition, or null, if not possible.
 */
@Nullable
public Event nextInvalid() {
	final Iterator<Entry<Integer, State>> iter = states.entrySet().iterator();
	if (iter.hasNext()) {
		final Entry<Integer, State> entry = iter.next();

		State currentState = entry.getValue();
		int address = entry.getKey();
		iter.remove();

		EventType event = currentState.randomInvalidTransition(rnd);
		return new Event(event, address);
	}
	else {
		return null;
	}
}
 
Example #6
Source File: StateMachineExample.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void flatMap(Event evt, Collector<Alert> out) throws Exception {
	// get the current state for the key (source address)
	// if no state exists, yet, the state must be the state machine's initial state
	State state = currentState.value();
	if (state == null) {
		state = State.Initial;
	}

	// ask the state machine what state we should go to based on the given event
	State nextState = state.transition(evt.type());

	if (nextState == State.InvalidTransition) {
		// the current event resulted in an invalid transition
		// raise an alert!
		out.collect(new Alert(evt.sourceAddress(), state, evt.type()));
	}
	else if (nextState.isTerminal()) {
		// we reached a terminal state, clean up the current state
		currentState.clear();
	}
	else {
		// remember the new state
		currentState.update(nextState);
	}
}
 
Example #7
Source File: Alert.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public State state() {
	return state;
}
 
Example #8
Source File: StateMachineExample.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void open(Configuration conf) {
	// get access to the state object
	currentState = getRuntimeContext().getState(
				new ValueStateDescriptor<>("state", State.class));
}
 
Example #9
Source File: Alert.java    From flink with Apache License 2.0 4 votes vote down vote up
public State state() {
	return state;
}
 
Example #10
Source File: StateMachineExample.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void open(Configuration conf) {
	// get access to the state object
	currentState = getRuntimeContext().getState(
				new ValueStateDescriptor<>("state", State.class));
}
 
Example #11
Source File: Alert.java    From flink with Apache License 2.0 4 votes vote down vote up
public State state() {
	return state;
}
 
Example #12
Source File: StateMachineExample.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void open(Configuration conf) {
	// get access to the state object
	currentState = getRuntimeContext().getState(
				new ValueStateDescriptor<>("state", State.class));
}
 
Example #13
Source File: Alert.java    From Flink-CEPplus with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new alert.
 *
 * @param address The originating address (think 32 bit IPv4 address).
 * @param state The state that the event state machine found.
 * @param transition The transition that was considered invalid.
 */
public Alert(int address, State state, EventType transition) {
	this.address = address;
	this.state = checkNotNull(state);
	this.transition = checkNotNull(transition);
}
 
Example #14
Source File: Alert.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new alert.
 *
 * @param address The originating address (think 32 bit IPv4 address).
 * @param state The state that the event state machine found.
 * @param transition The transition that was considered invalid.
 */
public Alert(int address, State state, EventType transition) {
	this.address = address;
	this.state = checkNotNull(state);
	this.transition = checkNotNull(transition);
}
 
Example #15
Source File: Alert.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new alert.
 *
 * @param address The originating address (think 32 bit IPv4 address).
 * @param state The state that the event state machine found.
 * @param transition The transition that was considered invalid.
 */
public Alert(int address, State state, EventType transition) {
	this.address = address;
	this.state = checkNotNull(state);
	this.transition = checkNotNull(transition);
}