org.apache.flink.streaming.api.operators.InternalTimerService Java Examples

The following examples show how to use org.apache.flink.streaming.api.operators.InternalTimerService. 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: CoBroadcastWithKeyedOperator.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public void open() throws Exception {
	super.open();

	InternalTimerService<VoidNamespace> internalTimerService =
			getInternalTimerService("user-timers", VoidNamespaceSerializer.INSTANCE, this);

	TimerService timerService = new SimpleTimerService(internalTimerService);

	collector = new TimestampedCollector<>(output);

	this.broadcastStates = new HashMap<>(broadcastStateDescriptors.size());
	for (MapStateDescriptor<?, ?> descriptor: broadcastStateDescriptors) {
		broadcastStates.put(descriptor, getOperatorStateBackend().getBroadcastState(descriptor));
	}

	rwContext = new ReadWriteContextImpl(getExecutionConfig(), getKeyedStateBackend(), userFunction, broadcastStates, timerService);
	rContext = new ReadOnlyContextImpl(getExecutionConfig(), userFunction, broadcastStates, timerService);
	onTimerContext = new OnTimerContextImpl(getExecutionConfig(), userFunction, broadcastStates, timerService);
}
 
Example #2
Source File: Workarounds.java    From beam with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("all")
public static InternalPriorityQueue<InternalTimer<Object, TimerInternals.TimerData>>
    retrieveInternalProcessingTimerQueue(
        InternalTimerService<TimerInternals.TimerData> timerService) {
  Field internalProcessingTimerQueue = null;
  try {
    internalProcessingTimerQueue =
        InternalTimerServiceImpl.class.getDeclaredField("processingTimeTimersQueue");
    internalProcessingTimerQueue.setAccessible(true);
    return (InternalPriorityQueue) internalProcessingTimerQueue.get(timerService);
  } catch (Exception e) {
    throw new IllegalStateException("Failed to retrieve processing timer queue.", e);
  } finally {
    if (internalProcessingTimerQueue != null) {
      internalProcessingTimerQueue.setAccessible(false);
    }
  }
}
 
Example #3
Source File: CoBroadcastWithKeyedOperator.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void open() throws Exception {
	super.open();

	InternalTimerService<VoidNamespace> internalTimerService =
			getInternalTimerService("user-timers", VoidNamespaceSerializer.INSTANCE, this);

	TimerService timerService = new SimpleTimerService(internalTimerService);

	collector = new TimestampedCollector<>(output);

	this.broadcastStates = new HashMap<>(broadcastStateDescriptors.size());
	for (MapStateDescriptor<?, ?> descriptor: broadcastStateDescriptors) {
		broadcastStates.put(descriptor, getOperatorStateBackend().getBroadcastState(descriptor));
	}

	rwContext = new ReadWriteContextImpl(getExecutionConfig(), getKeyedStateBackend(), userFunction, broadcastStates, timerService);
	rContext = new ReadOnlyContextImpl(getExecutionConfig(), userFunction, broadcastStates, timerService);
	onTimerContext = new OnTimerContextImpl(getExecutionConfig(), userFunction, broadcastStates, timerService);
}
 
Example #4
Source File: KeyedStateReaderOperator.java    From flink with Apache License 2.0 6 votes vote down vote up
private Context(KeyedStateBackend<K> keyedStateBackend, InternalTimerService<VoidNamespace> timerService) throws Exception {
	eventTimers = keyedStateBackend.getPartitionedState(
		USER_TIMERS_NAME,
		StringSerializer.INSTANCE,
		new ListStateDescriptor<>(EVENT_TIMER_STATE, Types.LONG));

	timerService.forEachEventTimeTimer((namespace, timer) -> {
		if (namespace.equals(VoidNamespace.INSTANCE)) {
			eventTimers.add(timer);
		}
	});

	procTimers = keyedStateBackend.getPartitionedState(
		USER_TIMERS_NAME,
		StringSerializer.INSTANCE,
		new ListStateDescriptor<>(PROC_TIMER_STATE, Types.LONG));

	timerService.forEachProcessingTimeTimer((namespace, timer) -> {
		if (namespace.equals(VoidNamespace.INSTANCE)) {
			procTimers.add(timer);
		}
	});
}
 
Example #5
Source File: CoBroadcastWithKeyedOperator.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void open() throws Exception {
	super.open();

	InternalTimerService<VoidNamespace> internalTimerService =
			getInternalTimerService("user-timers", VoidNamespaceSerializer.INSTANCE, this);

	TimerService timerService = new SimpleTimerService(internalTimerService);

	collector = new TimestampedCollector<>(output);

	this.broadcastStates = new HashMap<>(broadcastStateDescriptors.size());
	for (MapStateDescriptor<?, ?> descriptor: broadcastStateDescriptors) {
		broadcastStates.put(descriptor, getOperatorStateBackend().getBroadcastState(descriptor));
	}

	rwContext = new ReadWriteContextImpl(getExecutionConfig(), getKeyedStateBackend(), userFunction, broadcastStates, timerService);
	rContext = new ReadOnlyContextImpl(getExecutionConfig(), userFunction, broadcastStates, timerService);
	onTimerContext = new OnTimerContextImpl(getExecutionConfig(), userFunction, broadcastStates, timerService);
}
 
Example #6
Source File: KeyedStateInputFormat.java    From flink with Apache License 2.0 6 votes vote down vote up
private Context(AbstractKeyedStateBackend<K> keyedStateBackend, InternalTimerService<VoidNamespace> timerService) throws Exception {
	eventTimers = keyedStateBackend.getPartitionedState(
		USER_TIMERS_NAME,
		StringSerializer.INSTANCE,
		new ListStateDescriptor<>(EVENT_TIMER_STATE, Types.LONG)
	);

	timerService.forEachEventTimeTimer((namespace, timer) -> {
		if (namespace.equals(VoidNamespace.INSTANCE)) {
			eventTimers.add(timer);
		}
	});

	procTimers = keyedStateBackend.getPartitionedState(
		USER_TIMERS_NAME,
		StringSerializer.INSTANCE,
		new ListStateDescriptor<>(PROC_TIMER_STATE, Types.LONG)
	);

	timerService.forEachProcessingTimeTimer((namespace, timer) -> {
		if (namespace.equals(VoidNamespace.INSTANCE)) {
			procTimers.add(timer);
		}
	});
}
 
Example #7
Source File: FlinkTimerServiceFactory.java    From stateful-functions with Apache License 2.0 5 votes vote down vote up
@Override
public InternalTimerService<VoidNamespace> createTimerService(
    Triggerable<String, VoidNamespace> triggerable) {
  final TimerSerializer<String, VoidNamespace> timerSerializer =
      new TimerSerializer<>(StringSerializer.INSTANCE, VoidNamespaceSerializer.INSTANCE);

  return timeServiceManager.getInternalTimerService(
      DELAYED_MSG_TIMER_SERVICE_NAME, timerSerializer, triggerable);
}
 
Example #8
Source File: TriggerTestHarness.java    From flink with Apache License 2.0 5 votes vote down vote up
public TestOnMergeContext(
		K key,
		W targetWindow,
		Collection<W> mergedWindows,
		InternalTimerService<W> timerService,
		KeyedStateBackend<Integer> stateBackend,
		TypeSerializer<W> windowSerializer) {
	super(key, targetWindow, timerService, stateBackend, windowSerializer);

	this.mergedWindows = mergedWindows;
}
 
Example #9
Source File: FlinkTimerServiceFactory.java    From flink-statefun with Apache License 2.0 5 votes vote down vote up
@Override
public InternalTimerService<VoidNamespace> createTimerService(
    Triggerable<String, VoidNamespace> triggerable) {
  final TimerSerializer<String, VoidNamespace> timerSerializer =
      new TimerSerializer<>(StringSerializer.INSTANCE, VoidNamespaceSerializer.INSTANCE);

  return timeServiceManager.getInternalTimerService(
      DELAYED_MSG_TIMER_SERVICE_NAME, timerSerializer, triggerable);
}
 
Example #10
Source File: BaseTemporalSortOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void open() throws Exception {
	InternalTimerService<VoidNamespace> internalTimerService = getInternalTimerService("user-timers",
			VoidNamespaceSerializer.INSTANCE,
			this);
	timerService = new SimpleTimerService(internalTimerService);
	collector = new TimestampedCollector<>(output);
}
 
Example #11
Source File: BaseTwoInputStreamOperatorWithStateRetention.java    From flink with Apache License 2.0 5 votes vote down vote up
private void initializeTimerService() {
	InternalTimerService<VoidNamespace> internalTimerService = getInternalTimerService(
		TIMERS_STATE_NAME,
		VoidNamespaceSerializer.INSTANCE,
		this);

	timerService = new SimpleTimerService(internalTimerService);
}
 
Example #12
Source File: KeyedStateBootstrapOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void open() throws Exception {
	super.open();

	Supplier<InternalTimerService<VoidNamespace>> internalTimerService = () -> getInternalTimerService(
		"user-timers",
		VoidNamespaceSerializer.INSTANCE,
		VoidTriggerable.instance());

	TimerService timerService = new LazyTimerService(internalTimerService, getProcessingTimeService());

	context = new KeyedStateBootstrapOperator<K, IN>.ContextImpl(userFunction, timerService);
}
 
Example #13
Source File: KeyedStateReaderOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void open() throws Exception {
	super.open();

	InternalTimerService<VoidNamespace> timerService = getInternalTimerService(USER_TIMERS_NAME);
	context = new Context<>(getKeyedStateBackend(), timerService);
}
 
Example #14
Source File: KeyedCoProcessOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void open() throws Exception {
	super.open();
	collector = new TimestampedCollector<>(output);

	InternalTimerService<VoidNamespace> internalTimerService =
			getInternalTimerService("user-timers", VoidNamespaceSerializer.INSTANCE, this);

	TimerService timerService = new SimpleTimerService(internalTimerService);

	context = new ContextImpl<>(userFunction, timerService);
	onTimerContext = new OnTimerContextImpl<>(userFunction, timerService);
}
 
Example #15
Source File: LegacyKeyedCoProcessOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void open() throws Exception {
	super.open();
	collector = new TimestampedCollector<>(output);

	InternalTimerService<VoidNamespace> internalTimerService =
			getInternalTimerService("user-timers", VoidNamespaceSerializer.INSTANCE, this);

	TimerService timerService = new SimpleTimerService(internalTimerService);

	context = new ContextImpl<>(userFunction, timerService);
	onTimerContext = new OnTimerContextImpl<>(userFunction, timerService);
}
 
Example #16
Source File: TriggerTestHarness.java    From flink with Apache License 2.0 5 votes vote down vote up
TestTriggerContext(
		K key,
		W window,
		InternalTimerService<W> timerService,
		KeyedStateBackend<Integer> stateBackend,
		TypeSerializer<W> windowSerializer) {
	this.key = key;
	this.window = window;
	this.timerService = timerService;
	this.stateBackend = stateBackend;
	this.windowSerializer = windowSerializer;
}
 
Example #17
Source File: KeyedCoProcessOperator.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void open() throws Exception {
	super.open();
	collector = new TimestampedCollector<>(output);

	InternalTimerService<VoidNamespace> internalTimerService =
			getInternalTimerService("user-timers", VoidNamespaceSerializer.INSTANCE, this);

	TimerService timerService = new SimpleTimerService(internalTimerService);

	context = new ContextImpl<>(userFunction, timerService);
	onTimerContext = new OnTimerContextImpl<>(userFunction, timerService);
}
 
Example #18
Source File: TriggerTestHarness.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
TestTriggerContext(
		K key,
		W window,
		InternalTimerService<W> timerService,
		KeyedStateBackend<Integer> stateBackend,
		TypeSerializer<W> windowSerializer) {
	this.key = key;
	this.window = window;
	this.timerService = timerService;
	this.stateBackend = stateBackend;
	this.windowSerializer = windowSerializer;
}
 
Example #19
Source File: TriggerTestHarness.java    From flink with Apache License 2.0 5 votes vote down vote up
TestTriggerContext(
		K key,
		W window,
		InternalTimerService<W> timerService,
		KeyedStateBackend<Integer> stateBackend,
		TypeSerializer<W> windowSerializer) {
	this.key = key;
	this.window = window;
	this.timerService = timerService;
	this.stateBackend = stateBackend;
	this.windowSerializer = windowSerializer;
}
 
Example #20
Source File: TriggerTestHarness.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public TestOnMergeContext(
		K key,
		W targetWindow,
		Collection<W> mergedWindows,
		InternalTimerService<W> timerService,
		KeyedStateBackend<Integer> stateBackend,
		TypeSerializer<W> windowSerializer) {
	super(key, targetWindow, timerService, stateBackend, windowSerializer);

	this.mergedWindows = mergedWindows;
}
 
Example #21
Source File: BaseTemporalSortOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void open() throws Exception {
	InternalTimerService<VoidNamespace> internalTimerService = getInternalTimerService("user-timers",
			VoidNamespaceSerializer.INSTANCE,
			this);
	timerService = new SimpleTimerService(internalTimerService);
	collector = new TimestampedCollector<>(output);
}
 
Example #22
Source File: LegacyKeyedCoProcessOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void open() throws Exception {
	super.open();
	collector = new TimestampedCollector<>(output);

	InternalTimerService<VoidNamespace> internalTimerService =
			getInternalTimerService("user-timers", VoidNamespaceSerializer.INSTANCE, this);

	TimerService timerService = new SimpleTimerService(internalTimerService);

	context = new ContextImpl<>(userFunction, timerService);
	onTimerContext = new OnTimerContextImpl<>(userFunction, timerService);
}
 
Example #23
Source File: KeyedCoProcessOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void open() throws Exception {
	super.open();
	collector = new TimestampedCollector<>(output);

	InternalTimerService<VoidNamespace> internalTimerService =
			getInternalTimerService("user-timers", VoidNamespaceSerializer.INSTANCE, this);

	TimerService timerService = new SimpleTimerService(internalTimerService);

	context = new ContextImpl<>(userFunction, timerService);
	onTimerContext = new OnTimerContextImpl<>(userFunction, timerService);
}
 
Example #24
Source File: BaseTwoInputStreamOperatorWithStateRetention.java    From flink with Apache License 2.0 5 votes vote down vote up
private void initializeTimerService() {
	InternalTimerService<VoidNamespace> internalTimerService = getInternalTimerService(
		TIMERS_STATE_NAME,
		VoidNamespaceSerializer.INSTANCE,
		this);

	timerService = new SimpleTimerService(internalTimerService);
}
 
Example #25
Source File: TriggerTestHarness.java    From flink with Apache License 2.0 5 votes vote down vote up
public TestOnMergeContext(
		K key,
		W targetWindow,
		Collection<W> mergedWindows,
		InternalTimerService<W> timerService,
		KeyedStateBackend<Integer> stateBackend,
		TypeSerializer<W> windowSerializer) {
	super(key, targetWindow, timerService, stateBackend, windowSerializer);

	this.mergedWindows = mergedWindows;
}
 
Example #26
Source File: KeyedStateBootstrapOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void open() throws Exception {
	super.open();

	InternalTimerService<VoidNamespace> internalTimerService = getInternalTimerService(
		"user-timers",
		VoidNamespaceSerializer.INSTANCE,
		VoidTriggerable.instance());

	TimerService timerService = new SimpleTimerService(internalTimerService);

	context = new KeyedStateBootstrapOperator<K, IN>.ContextImpl(userFunction, timerService);
}
 
Example #27
Source File: KeyedStateInputFormat.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void open(KeyGroupRangeInputSplit split) throws IOException {
	registry = new CloseableRegistry();

	final Environment environment = new SavepointEnvironment
		.Builder(getRuntimeContext(), split.getNumKeyGroups())
		.setSubtaskIndex(split.getSplitNumber())
		.setPrioritizedOperatorSubtaskState(split.getPrioritizedOperatorSubtaskState())
		.build();

	final StreamOperatorStateContext context = getStreamOperatorStateContext(environment);

	keyedStateBackend = (AbstractKeyedStateBackend<K>) context.keyedStateBackend();

	final DefaultKeyedStateStore keyedStateStore = new DefaultKeyedStateStore(keyedStateBackend, getRuntimeContext().getExecutionConfig());
	SavepointRuntimeContext ctx = new SavepointRuntimeContext(getRuntimeContext(), keyedStateStore);
	FunctionUtils.setFunctionRuntimeContext(userFunction, ctx);

	keys = getKeyIterator(ctx);

	final InternalTimerService<VoidNamespace> timerService = restoreTimerService(context);
	try {
		this.ctx = new Context(keyedStateBackend, timerService);
	} catch (Exception e) {
		throw new IOException("Failed to restore timer state", e);
	}
}
 
Example #28
Source File: LazyTimerService.java    From flink with Apache License 2.0 4 votes vote down vote up
LazyTimerService(Supplier<InternalTimerService<VoidNamespace>> supplier, ProcessingTimeService processingTimeService) {
	this.supplier = supplier;
	this.processingTimeService = processingTimeService;
}
 
Example #29
Source File: SimpleTimerService.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public SimpleTimerService(InternalTimerService<VoidNamespace> internalTimerService) {
	this.internalTimerService = internalTimerService;
}
 
Example #30
Source File: SimpleTimerService.java    From flink with Apache License 2.0 4 votes vote down vote up
public SimpleTimerService(InternalTimerService<VoidNamespace> internalTimerService) {
	this.internalTimerService = internalTimerService;
}