Java Code Examples for org.apache.flink.streaming.api.TimerService#registerEventTimeTimer()

The following examples show how to use org.apache.flink.streaming.api.TimerService#registerEventTimeTimer() . 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: KeyedProcessOperatorTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public void processElement(Integer value, Context ctx, Collector<String> out) throws Exception {
	final TimerService timerService = ctx.timerService();
	final ValueState<Integer> state = getRuntimeContext().getState(this.state);
	if (state.value() == null) {
		out.collect("INPUT:" + value);
		state.update(value);
		if (expectedTimeDomain.equals(TimeDomain.EVENT_TIME)) {
			timerService.registerEventTimeTimer(timerService.currentWatermark() + 5);
		} else {
			timerService.registerProcessingTimeTimer(timerService.currentProcessingTime() + 5);
		}
	} else {
		state.clear();
		if (expectedTimeDomain.equals(TimeDomain.EVENT_TIME)) {
			timerService.deleteEventTimeTimer(timerService.currentWatermark() + 4);
		} else {
			timerService.deleteProcessingTimeTimer(timerService.currentProcessingTime() + 4);
		}
	}
}
 
Example 2
Source File: KeyedProcessOperatorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void processElement(Integer value, Context ctx, Collector<String> out) throws Exception {
	final TimerService timerService = ctx.timerService();
	final ValueState<Integer> state = getRuntimeContext().getState(this.state);
	if (state.value() == null) {
		out.collect("INPUT:" + value);
		state.update(value);
		if (expectedTimeDomain.equals(TimeDomain.EVENT_TIME)) {
			timerService.registerEventTimeTimer(timerService.currentWatermark() + 5);
		} else {
			timerService.registerProcessingTimeTimer(timerService.currentProcessingTime() + 5);
		}
	} else {
		state.clear();
		if (expectedTimeDomain.equals(TimeDomain.EVENT_TIME)) {
			timerService.deleteEventTimeTimer(timerService.currentWatermark() + 4);
		} else {
			timerService.deleteProcessingTimeTimer(timerService.currentProcessingTime() + 4);
		}
	}
}
 
Example 3
Source File: EventTimeJoinExercise.java    From flink-training-exercises with Apache License 2.0 6 votes vote down vote up
@Override
public void processElement1(Trade trade,
							Context context,
							Collector<EnrichedTrade> out)
		throws Exception {

	System.out.println("Received " + trade.toString());
	TimerService timerService = context.timerService();

	if (context.timestamp() > timerService.currentWatermark()) {
		// Do the join later, by which time any relevant Customer records should have have arrived.
		tradeMap.put(trade.timestamp, trade);
		timerService.registerEventTimeTimer(trade.timestamp);
	} else {
		// Late Trades land here.
	}
}
 
Example 4
Source File: KeyedProcessOperatorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void processElement(Integer value, Context ctx, Collector<String> out) throws Exception {
	final TimerService timerService = ctx.timerService();
	final ValueState<Integer> state = getRuntimeContext().getState(this.state);
	if (state.value() == null) {
		out.collect("INPUT:" + value);
		state.update(value);
		if (expectedTimeDomain.equals(TimeDomain.EVENT_TIME)) {
			timerService.registerEventTimeTimer(timerService.currentWatermark() + 5);
		} else {
			timerService.registerProcessingTimeTimer(timerService.currentProcessingTime() + 5);
		}
	} else {
		state.clear();
		if (expectedTimeDomain.equals(TimeDomain.EVENT_TIME)) {
			timerService.deleteEventTimeTimer(timerService.currentWatermark() + 4);
		} else {
			timerService.deleteProcessingTimeTimer(timerService.currentProcessingTime() + 4);
		}
	}
}
 
Example 5
Source File: KeyedCoProcessOperatorTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private void handleValue(
	Object value,
	Collector<String> out,
	TimerService timerService,
	int channel) throws IOException {
	final ValueState<String> state = getRuntimeContext().getState(this.state);
	if (state.value() == null) {
		out.collect("INPUT" + channel + ":" + value);
		state.update(String.valueOf(value));
		timerService.registerEventTimeTimer(timerService.currentWatermark() + 5);
	} else {
		state.clear();
		timerService.deleteEventTimeTimer(timerService.currentWatermark() + 4);
	}
}
 
Example 6
Source File: KeyedProcessOperatorTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void processElement(Integer value, Context ctx, Collector<String> out) throws Exception {
	final TimerService timerService = ctx.timerService();

	timerService.registerProcessingTimeTimer(3);
	timerService.registerEventTimeTimer(4);
	timerService.registerProcessingTimeTimer(5);
	timerService.registerEventTimeTimer(6);
	timerService.deleteProcessingTimeTimer(3);
	timerService.deleteEventTimeTimer(4);
}
 
Example 7
Source File: LegacyKeyedCoProcessOperatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private void handleValue(
	Object value,
	Collector<String> out,
	TimerService timerService,
	int channel) throws IOException {
	final ValueState<String> state = getRuntimeContext().getState(this.state);
	if (state.value() == null) {
		out.collect("INPUT" + channel + ":" + value);
		state.update(String.valueOf(value));
		timerService.registerEventTimeTimer(timerService.currentWatermark() + 5);
	} else {
		state.clear();
		timerService.deleteEventTimeTimer(timerService.currentWatermark() + 4);
	}
}
 
Example 8
Source File: KeyedCoProcessOperatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private void handleValue(
	Object value,
	Collector<String> out,
	TimerService timerService,
	int channel) throws IOException {
	final ValueState<String> state = getRuntimeContext().getState(this.state);
	if (state.value() == null) {
		out.collect("INPUT" + channel + ":" + value);
		state.update(String.valueOf(value));
		timerService.registerEventTimeTimer(timerService.currentWatermark() + 5);
	} else {
		state.clear();
		timerService.deleteEventTimeTimer(timerService.currentWatermark() + 4);
	}
}
 
Example 9
Source File: KeyedProcessOperatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void processElement(Integer value, Context ctx, Collector<String> out) throws Exception {
	final TimerService timerService = ctx.timerService();

	timerService.registerProcessingTimeTimer(3);
	timerService.registerEventTimeTimer(4);
	timerService.registerProcessingTimeTimer(5);
	timerService.registerEventTimeTimer(6);
	timerService.deleteProcessingTimeTimer(3);
	timerService.deleteEventTimeTimer(4);
}
 
Example 10
Source File: CarEventSort.java    From flink-training-exercises with Apache License 2.0 5 votes vote down vote up
@Override
public void processElement(ConnectedCarEvent event, Context context, Collector<ConnectedCarEvent> out) throws Exception {
	TimerService timerService = context.timerService();

	if (context.timestamp() > timerService.currentWatermark()) {
		PriorityQueue<ConnectedCarEvent> queue = queueState.value();
		if (queue == null) {
			queue = new PriorityQueue<>(10);
		}
		queue.add(event);
		queueState.update(queue);
		timerService.registerEventTimeTimer(event.timestamp);
	}
}
 
Example 11
Source File: CheckpointedLongRidesSolution.java    From flink-training-exercises with Apache License 2.0 5 votes vote down vote up
@Override
public void processElement(TaxiRide ride, Context context, Collector<TaxiRide> out) throws Exception {
	TimerService timerService = context.timerService();

	if (ride.isStart) {
		// the matching END might have arrived first (out of order); don't overwrite it
		if (rideState.value() == null) {
			rideState.update(ride);
		}
	} else {
		rideState.update(ride);
	}

	timerService.registerEventTimeTimer(ride.getEventTime() + 120 * 60 * 1000);
}
 
Example 12
Source File: LongRidesSolution.java    From flink-training-exercises with Apache License 2.0 5 votes vote down vote up
@Override
public void processElement(TaxiRide ride, Context context, Collector<TaxiRide> out) throws Exception {
	TimerService timerService = context.timerService();

	if (ride.isStart) {
		// the matching END might have arrived first; don't overwrite it
		if (rideState.value() == null) {
			rideState.update(ride);
		}
	} else {
		rideState.update(ride);
	}

	timerService.registerEventTimeTimer(ride.getEventTime() + 120 * 60 * 1000);
}
 
Example 13
Source File: LegacyKeyedCoProcessOperatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private void handleValue(
	Object value,
	Collector<String> out,
	TimerService timerService,
	int channel) throws IOException {
	final ValueState<String> state = getRuntimeContext().getState(this.state);
	if (state.value() == null) {
		out.collect("INPUT" + channel + ":" + value);
		state.update(String.valueOf(value));
		timerService.registerEventTimeTimer(timerService.currentWatermark() + 5);
	} else {
		state.clear();
		timerService.deleteEventTimeTimer(timerService.currentWatermark() + 4);
	}
}
 
Example 14
Source File: KeyedCoProcessOperatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private void handleValue(
	Object value,
	Collector<String> out,
	TimerService timerService,
	int channel) throws IOException {
	final ValueState<String> state = getRuntimeContext().getState(this.state);
	if (state.value() == null) {
		out.collect("INPUT" + channel + ":" + value);
		state.update(String.valueOf(value));
		timerService.registerEventTimeTimer(timerService.currentWatermark() + 5);
	} else {
		state.clear();
		timerService.deleteEventTimeTimer(timerService.currentWatermark() + 4);
	}
}
 
Example 15
Source File: KeyedProcessOperatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void processElement(Integer value, Context ctx, Collector<String> out) throws Exception {
	final TimerService timerService = ctx.timerService();

	timerService.registerProcessingTimeTimer(3);
	timerService.registerEventTimeTimer(4);
	timerService.registerProcessingTimeTimer(5);
	timerService.registerEventTimeTimer(6);
	timerService.deleteProcessingTimeTimer(3);
	timerService.deleteEventTimeTimer(4);
}