Java Code Examples for org.apache.flink.streaming.api.operators.InternalTimer#getKey()

The following examples show how to use org.apache.flink.streaming.api.operators.InternalTimer#getKey() . 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: EvictingWindowOperator.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void onEventTime(InternalTimer<K, W> timer) throws Exception {

	triggerContext.key = timer.getKey();
	triggerContext.window = timer.getNamespace();
	evictorContext.key = timer.getKey();
	evictorContext.window = timer.getNamespace();

	MergingWindowSet<W> mergingWindows = null;

	if (windowAssigner instanceof MergingWindowAssigner) {
		mergingWindows = getMergingWindowSet();
		W stateWindow = mergingWindows.getStateWindow(triggerContext.window);
		if (stateWindow == null) {
			// Timer firing for non-existent window, this can only happen if a
			// trigger did not clean up timers. We have already cleared the merging
			// window and therefore the Trigger state, however, so nothing to do.
			return;
		} else {
			evictingWindowState.setCurrentNamespace(stateWindow);
		}
	} else {
		evictingWindowState.setCurrentNamespace(triggerContext.window);
	}

	TriggerResult triggerResult = triggerContext.onEventTime(timer.getTimestamp());

	if (triggerResult.isFire()) {
		Iterable<StreamRecord<IN>> contents = evictingWindowState.get();
		if (contents != null) {
			emitWindowContents(triggerContext.window, contents, evictingWindowState);
		}
	}

	if (triggerResult.isPurge()) {
		evictingWindowState.clear();
	}

	if (windowAssigner.isEventTime() && isCleanupTime(triggerContext.window, timer.getTimestamp())) {
		clearAllState(triggerContext.window, evictingWindowState, mergingWindows);
	}

	if (mergingWindows != null) {
		// need to make sure to update the merging state in state
		mergingWindows.persist();
	}
}
 
Example 2
Source File: EvictingWindowOperator.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void onProcessingTime(InternalTimer<K, W> timer) throws Exception {
	triggerContext.key = timer.getKey();
	triggerContext.window = timer.getNamespace();
	evictorContext.key = timer.getKey();
	evictorContext.window = timer.getNamespace();

	MergingWindowSet<W> mergingWindows = null;

	if (windowAssigner instanceof MergingWindowAssigner) {
		mergingWindows = getMergingWindowSet();
		W stateWindow = mergingWindows.getStateWindow(triggerContext.window);
		if (stateWindow == null) {
			// Timer firing for non-existent window, this can only happen if a
			// trigger did not clean up timers. We have already cleared the merging
			// window and therefore the Trigger state, however, so nothing to do.
			return;
		} else {
			evictingWindowState.setCurrentNamespace(stateWindow);
		}
	} else {
		evictingWindowState.setCurrentNamespace(triggerContext.window);
	}

	TriggerResult triggerResult = triggerContext.onProcessingTime(timer.getTimestamp());

	if (triggerResult.isFire()) {
		Iterable<StreamRecord<IN>> contents = evictingWindowState.get();
		if (contents != null) {
			emitWindowContents(triggerContext.window, contents, evictingWindowState);
		}
	}

	if (triggerResult.isPurge()) {
		evictingWindowState.clear();
	}

	if (!windowAssigner.isEventTime() && isCleanupTime(triggerContext.window, timer.getTimestamp())) {
		clearAllState(triggerContext.window, evictingWindowState, mergingWindows);
	}

	if (mergingWindows != null) {
		// need to make sure to update the merging state in state
		mergingWindows.persist();
	}
}
 
Example 3
Source File: WindowOperator.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void onEventTime(InternalTimer<K, W> timer) throws Exception {
	triggerContext.key = timer.getKey();
	triggerContext.window = timer.getNamespace();

	MergingWindowSet<W> mergingWindows;

	if (windowAssigner instanceof MergingWindowAssigner) {
		mergingWindows = getMergingWindowSet();
		W stateWindow = mergingWindows.getStateWindow(triggerContext.window);
		if (stateWindow == null) {
			// Timer firing for non-existent window, this can only happen if a
			// trigger did not clean up timers. We have already cleared the merging
			// window and therefore the Trigger state, however, so nothing to do.
			return;
		} else {
			windowState.setCurrentNamespace(stateWindow);
		}
	} else {
		windowState.setCurrentNamespace(triggerContext.window);
		mergingWindows = null;
	}

	TriggerResult triggerResult = triggerContext.onEventTime(timer.getTimestamp());

	if (triggerResult.isFire()) {
		ACC contents = windowState.get();
		if (contents != null) {
			emitWindowContents(triggerContext.window, contents);
		}
	}

	if (triggerResult.isPurge()) {
		windowState.clear();
	}

	if (windowAssigner.isEventTime() && isCleanupTime(triggerContext.window, timer.getTimestamp())) {
		clearAllState(triggerContext.window, windowState, mergingWindows);
	}

	if (mergingWindows != null) {
		// need to make sure to update the merging state in state
		mergingWindows.persist();
	}
}
 
Example 4
Source File: WindowOperator.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void onProcessingTime(InternalTimer<K, W> timer) throws Exception {
	triggerContext.key = timer.getKey();
	triggerContext.window = timer.getNamespace();

	MergingWindowSet<W> mergingWindows;

	if (windowAssigner instanceof MergingWindowAssigner) {
		mergingWindows = getMergingWindowSet();
		W stateWindow = mergingWindows.getStateWindow(triggerContext.window);
		if (stateWindow == null) {
			// Timer firing for non-existent window, this can only happen if a
			// trigger did not clean up timers. We have already cleared the merging
			// window and therefore the Trigger state, however, so nothing to do.
			return;
		} else {
			windowState.setCurrentNamespace(stateWindow);
		}
	} else {
		windowState.setCurrentNamespace(triggerContext.window);
		mergingWindows = null;
	}

	TriggerResult triggerResult = triggerContext.onProcessingTime(timer.getTimestamp());

	if (triggerResult.isFire()) {
		ACC contents = windowState.get();
		if (contents != null) {
			emitWindowContents(triggerContext.window, contents);
		}
	}

	if (triggerResult.isPurge()) {
		windowState.clear();
	}

	if (!windowAssigner.isEventTime() && isCleanupTime(triggerContext.window, timer.getTimestamp())) {
		clearAllState(triggerContext.window, windowState, mergingWindows);
	}

	if (mergingWindows != null) {
		// need to make sure to update the merging state in state
		mergingWindows.persist();
	}
}
 
Example 5
Source File: EvictingWindowOperator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void onEventTime(InternalTimer<K, W> timer) throws Exception {

	triggerContext.key = timer.getKey();
	triggerContext.window = timer.getNamespace();
	evictorContext.key = timer.getKey();
	evictorContext.window = timer.getNamespace();

	MergingWindowSet<W> mergingWindows = null;

	if (windowAssigner instanceof MergingWindowAssigner) {
		mergingWindows = getMergingWindowSet();
		W stateWindow = mergingWindows.getStateWindow(triggerContext.window);
		if (stateWindow == null) {
			// Timer firing for non-existent window, this can only happen if a
			// trigger did not clean up timers. We have already cleared the merging
			// window and therefore the Trigger state, however, so nothing to do.
			return;
		} else {
			evictingWindowState.setCurrentNamespace(stateWindow);
		}
	} else {
		evictingWindowState.setCurrentNamespace(triggerContext.window);
	}

	TriggerResult triggerResult = triggerContext.onEventTime(timer.getTimestamp());

	if (triggerResult.isFire()) {
		Iterable<StreamRecord<IN>> contents = evictingWindowState.get();
		if (contents != null) {
			emitWindowContents(triggerContext.window, contents, evictingWindowState);
		}
	}

	if (triggerResult.isPurge()) {
		evictingWindowState.clear();
	}

	if (windowAssigner.isEventTime() && isCleanupTime(triggerContext.window, timer.getTimestamp())) {
		clearAllState(triggerContext.window, evictingWindowState, mergingWindows);
	}

	if (mergingWindows != null) {
		// need to make sure to update the merging state in state
		mergingWindows.persist();
	}
}
 
Example 6
Source File: EvictingWindowOperator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void onProcessingTime(InternalTimer<K, W> timer) throws Exception {
	triggerContext.key = timer.getKey();
	triggerContext.window = timer.getNamespace();
	evictorContext.key = timer.getKey();
	evictorContext.window = timer.getNamespace();

	MergingWindowSet<W> mergingWindows = null;

	if (windowAssigner instanceof MergingWindowAssigner) {
		mergingWindows = getMergingWindowSet();
		W stateWindow = mergingWindows.getStateWindow(triggerContext.window);
		if (stateWindow == null) {
			// Timer firing for non-existent window, this can only happen if a
			// trigger did not clean up timers. We have already cleared the merging
			// window and therefore the Trigger state, however, so nothing to do.
			return;
		} else {
			evictingWindowState.setCurrentNamespace(stateWindow);
		}
	} else {
		evictingWindowState.setCurrentNamespace(triggerContext.window);
	}

	TriggerResult triggerResult = triggerContext.onProcessingTime(timer.getTimestamp());

	if (triggerResult.isFire()) {
		Iterable<StreamRecord<IN>> contents = evictingWindowState.get();
		if (contents != null) {
			emitWindowContents(triggerContext.window, contents, evictingWindowState);
		}
	}

	if (triggerResult.isPurge()) {
		evictingWindowState.clear();
	}

	if (!windowAssigner.isEventTime() && isCleanupTime(triggerContext.window, timer.getTimestamp())) {
		clearAllState(triggerContext.window, evictingWindowState, mergingWindows);
	}

	if (mergingWindows != null) {
		// need to make sure to update the merging state in state
		mergingWindows.persist();
	}
}
 
Example 7
Source File: WindowOperator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void onEventTime(InternalTimer<K, W> timer) throws Exception {
	triggerContext.key = timer.getKey();
	triggerContext.window = timer.getNamespace();

	MergingWindowSet<W> mergingWindows;

	if (windowAssigner instanceof MergingWindowAssigner) {
		mergingWindows = getMergingWindowSet();
		W stateWindow = mergingWindows.getStateWindow(triggerContext.window);
		if (stateWindow == null) {
			// Timer firing for non-existent window, this can only happen if a
			// trigger did not clean up timers. We have already cleared the merging
			// window and therefore the Trigger state, however, so nothing to do.
			return;
		} else {
			windowState.setCurrentNamespace(stateWindow);
		}
	} else {
		windowState.setCurrentNamespace(triggerContext.window);
		mergingWindows = null;
	}

	TriggerResult triggerResult = triggerContext.onEventTime(timer.getTimestamp());

	if (triggerResult.isFire()) {
		ACC contents = windowState.get();
		if (contents != null) {
			emitWindowContents(triggerContext.window, contents);
		}
	}

	if (triggerResult.isPurge()) {
		windowState.clear();
	}

	if (windowAssigner.isEventTime() && isCleanupTime(triggerContext.window, timer.getTimestamp())) {
		clearAllState(triggerContext.window, windowState, mergingWindows);
	}

	if (mergingWindows != null) {
		// need to make sure to update the merging state in state
		mergingWindows.persist();
	}
}
 
Example 8
Source File: WindowOperator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void onProcessingTime(InternalTimer<K, W> timer) throws Exception {
	triggerContext.key = timer.getKey();
	triggerContext.window = timer.getNamespace();

	MergingWindowSet<W> mergingWindows;

	if (windowAssigner instanceof MergingWindowAssigner) {
		mergingWindows = getMergingWindowSet();
		W stateWindow = mergingWindows.getStateWindow(triggerContext.window);
		if (stateWindow == null) {
			// Timer firing for non-existent window, this can only happen if a
			// trigger did not clean up timers. We have already cleared the merging
			// window and therefore the Trigger state, however, so nothing to do.
			return;
		} else {
			windowState.setCurrentNamespace(stateWindow);
		}
	} else {
		windowState.setCurrentNamespace(triggerContext.window);
		mergingWindows = null;
	}

	TriggerResult triggerResult = triggerContext.onProcessingTime(timer.getTimestamp());

	if (triggerResult.isFire()) {
		ACC contents = windowState.get();
		if (contents != null) {
			emitWindowContents(triggerContext.window, contents);
		}
	}

	if (triggerResult.isPurge()) {
		windowState.clear();
	}

	if (!windowAssigner.isEventTime() && isCleanupTime(triggerContext.window, timer.getTimestamp())) {
		clearAllState(triggerContext.window, windowState, mergingWindows);
	}

	if (mergingWindows != null) {
		// need to make sure to update the merging state in state
		mergingWindows.persist();
	}
}
 
Example 9
Source File: EvictingWindowOperator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void onEventTime(InternalTimer<K, W> timer) throws Exception {

	triggerContext.key = timer.getKey();
	triggerContext.window = timer.getNamespace();
	evictorContext.key = timer.getKey();
	evictorContext.window = timer.getNamespace();

	MergingWindowSet<W> mergingWindows = null;

	if (windowAssigner instanceof MergingWindowAssigner) {
		mergingWindows = getMergingWindowSet();
		W stateWindow = mergingWindows.getStateWindow(triggerContext.window);
		if (stateWindow == null) {
			// Timer firing for non-existent window, this can only happen if a
			// trigger did not clean up timers. We have already cleared the merging
			// window and therefore the Trigger state, however, so nothing to do.
			return;
		} else {
			evictingWindowState.setCurrentNamespace(stateWindow);
		}
	} else {
		evictingWindowState.setCurrentNamespace(triggerContext.window);
	}

	TriggerResult triggerResult = triggerContext.onEventTime(timer.getTimestamp());

	if (triggerResult.isFire()) {
		Iterable<StreamRecord<IN>> contents = evictingWindowState.get();
		if (contents != null) {
			emitWindowContents(triggerContext.window, contents, evictingWindowState);
		}
	}

	if (triggerResult.isPurge()) {
		evictingWindowState.clear();
	}

	if (windowAssigner.isEventTime() && isCleanupTime(triggerContext.window, timer.getTimestamp())) {
		clearAllState(triggerContext.window, evictingWindowState, mergingWindows);
	}

	if (mergingWindows != null) {
		// need to make sure to update the merging state in state
		mergingWindows.persist();
	}
}
 
Example 10
Source File: EvictingWindowOperator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void onProcessingTime(InternalTimer<K, W> timer) throws Exception {
	triggerContext.key = timer.getKey();
	triggerContext.window = timer.getNamespace();
	evictorContext.key = timer.getKey();
	evictorContext.window = timer.getNamespace();

	MergingWindowSet<W> mergingWindows = null;

	if (windowAssigner instanceof MergingWindowAssigner) {
		mergingWindows = getMergingWindowSet();
		W stateWindow = mergingWindows.getStateWindow(triggerContext.window);
		if (stateWindow == null) {
			// Timer firing for non-existent window, this can only happen if a
			// trigger did not clean up timers. We have already cleared the merging
			// window and therefore the Trigger state, however, so nothing to do.
			return;
		} else {
			evictingWindowState.setCurrentNamespace(stateWindow);
		}
	} else {
		evictingWindowState.setCurrentNamespace(triggerContext.window);
	}

	TriggerResult triggerResult = triggerContext.onProcessingTime(timer.getTimestamp());

	if (triggerResult.isFire()) {
		Iterable<StreamRecord<IN>> contents = evictingWindowState.get();
		if (contents != null) {
			emitWindowContents(triggerContext.window, contents, evictingWindowState);
		}
	}

	if (triggerResult.isPurge()) {
		evictingWindowState.clear();
	}

	if (!windowAssigner.isEventTime() && isCleanupTime(triggerContext.window, timer.getTimestamp())) {
		clearAllState(triggerContext.window, evictingWindowState, mergingWindows);
	}

	if (mergingWindows != null) {
		// need to make sure to update the merging state in state
		mergingWindows.persist();
	}
}
 
Example 11
Source File: WindowOperator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void onEventTime(InternalTimer<K, W> timer) throws Exception {
	triggerContext.key = timer.getKey();
	triggerContext.window = timer.getNamespace();

	MergingWindowSet<W> mergingWindows;

	if (windowAssigner instanceof MergingWindowAssigner) {
		mergingWindows = getMergingWindowSet();
		W stateWindow = mergingWindows.getStateWindow(triggerContext.window);
		if (stateWindow == null) {
			// Timer firing for non-existent window, this can only happen if a
			// trigger did not clean up timers. We have already cleared the merging
			// window and therefore the Trigger state, however, so nothing to do.
			return;
		} else {
			windowState.setCurrentNamespace(stateWindow);
		}
	} else {
		windowState.setCurrentNamespace(triggerContext.window);
		mergingWindows = null;
	}

	TriggerResult triggerResult = triggerContext.onEventTime(timer.getTimestamp());

	if (triggerResult.isFire()) {
		ACC contents = windowState.get();
		if (contents != null) {
			emitWindowContents(triggerContext.window, contents);
		}
	}

	if (triggerResult.isPurge()) {
		windowState.clear();
	}

	if (windowAssigner.isEventTime() && isCleanupTime(triggerContext.window, timer.getTimestamp())) {
		clearAllState(triggerContext.window, windowState, mergingWindows);
	}

	if (mergingWindows != null) {
		// need to make sure to update the merging state in state
		mergingWindows.persist();
	}
}
 
Example 12
Source File: WindowOperator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void onProcessingTime(InternalTimer<K, W> timer) throws Exception {
	triggerContext.key = timer.getKey();
	triggerContext.window = timer.getNamespace();

	MergingWindowSet<W> mergingWindows;

	if (windowAssigner instanceof MergingWindowAssigner) {
		mergingWindows = getMergingWindowSet();
		W stateWindow = mergingWindows.getStateWindow(triggerContext.window);
		if (stateWindow == null) {
			// Timer firing for non-existent window, this can only happen if a
			// trigger did not clean up timers. We have already cleared the merging
			// window and therefore the Trigger state, however, so nothing to do.
			return;
		} else {
			windowState.setCurrentNamespace(stateWindow);
		}
	} else {
		windowState.setCurrentNamespace(triggerContext.window);
		mergingWindows = null;
	}

	TriggerResult triggerResult = triggerContext.onProcessingTime(timer.getTimestamp());

	if (triggerResult.isFire()) {
		ACC contents = windowState.get();
		if (contents != null) {
			emitWindowContents(triggerContext.window, contents);
		}
	}

	if (triggerResult.isPurge()) {
		windowState.clear();
	}

	if (!windowAssigner.isEventTime() && isCleanupTime(triggerContext.window, timer.getTimestamp())) {
		clearAllState(triggerContext.window, windowState, mergingWindows);
	}

	if (mergingWindows != null) {
		// need to make sure to update the merging state in state
		mergingWindows.persist();
	}
}