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

The following examples show how to use org.apache.flink.streaming.api.operators.InternalTimer#getTimestamp() . 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: RowTimeSortOperator.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void onEventTime(InternalTimer<BaseRow, VoidNamespace> timer) throws Exception {
	long timestamp = timer.getTimestamp();

	// gets all rows for the triggering timestamps
	List<BaseRow> inputs = dataState.get(timestamp);
	if (inputs != null) {
		// sort rows on secondary fields if necessary
		if (comparator != null) {
			inputs.sort(comparator);
		}

		// emit rows in order
		inputs.forEach((BaseRow row) -> collector.collect(row));

		// remove emitted rows from state
		dataState.remove(timestamp);
		lastTriggeringTsState.update(timestamp);
	}
}
 
Example 2
Source File: DelaySink.java    From stateful-functions with Apache License 2.0 6 votes vote down vote up
@Override
public void onProcessingTime(InternalTimer<String, VoidNamespace> timer) throws Exception {
  final long triggerTimestamp = timer.getTimestamp();
  final Reductions reductions = reductionsSupplier.get();

  Iterable<Message> delayedMessages = delayedMessagesBuffer.getForTimestamp(triggerTimestamp);
  if (delayedMessages == null) {
    throw new IllegalStateException(
        "A delayed message timer was triggered with timestamp "
            + triggerTimestamp
            + ", but no messages were buffered for it.");
  }
  for (Message delayedMessage : delayedMessages) {
    if (thisPartition.contains(delayedMessage.target())) {
      reductions.enqueue(delayedMessage);
    } else {
      remoteSink.accept(delayedMessage);
    }
  }
  // we clear the delayedMessageBuffer *before* we process the enqueued local reductions, because
  // processing the envelops might actually trigger a delayed message to be sent with the same
  // @triggerTimestamp
  // so it would be re-enqueued into the delayedMessageBuffer.
  delayedMessagesBuffer.clearForTimestamp(triggerTimestamp);
  reductions.processEnvelopes();
}
 
Example 3
Source File: DelaySink.java    From flink-statefun with Apache License 2.0 6 votes vote down vote up
@Override
public void onProcessingTime(InternalTimer<String, VoidNamespace> timer) throws Exception {
  final long triggerTimestamp = timer.getTimestamp();
  final Reductions reductions = reductionsSupplier.get();

  Iterable<Message> delayedMessages = delayedMessagesBuffer.getForTimestamp(triggerTimestamp);
  if (delayedMessages == null) {
    throw new IllegalStateException(
        "A delayed message timer was triggered with timestamp "
            + triggerTimestamp
            + ", but no messages were buffered for it.");
  }
  for (Message delayedMessage : delayedMessages) {
    if (thisPartition.contains(delayedMessage.target())) {
      reductions.enqueue(delayedMessage);
    } else {
      remoteSink.accept(delayedMessage);
    }
  }
  // we clear the delayedMessageBuffer *before* we process the enqueued local reductions, because
  // processing the envelops might actually trigger a delayed message to be sent with the same
  // @triggerTimestamp
  // so it would be re-enqueued into the delayedMessageBuffer.
  delayedMessagesBuffer.clearForTimestamp(triggerTimestamp);
  reductions.processEnvelopes();
}
 
Example 4
Source File: RowTimeSortOperator.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void onEventTime(InternalTimer<RowData, VoidNamespace> timer) throws Exception {
	long timestamp = timer.getTimestamp();

	// gets all rows for the triggering timestamps
	List<RowData> inputs = dataState.get(timestamp);
	if (inputs != null) {
		// sort rows on secondary fields if necessary
		if (comparator != null) {
			inputs.sort(comparator);
		}

		// emit rows in order
		inputs.forEach((RowData row) -> collector.collect(row));

		// remove emitted rows from state
		dataState.remove(timestamp);
		lastTriggeringTsState.update(timestamp);
	}
}
 
Example 5
Source File: BaseTwoInputStreamOperatorWithStateRetention.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * The users of this class are not allowed to use processing time timers.
 * See class javadoc.
 */
@Override
public final void onProcessingTime(InternalTimer<Object, VoidNamespace> timer) throws Exception {
	if (stateCleaningEnabled) {
		long timerTime = timer.getTimestamp();
		Long cleanupTime = latestRegisteredCleanupTimer.value();

		if (cleanupTime != null && cleanupTime == timerTime) {
			cleanupState(cleanupTime);
			latestRegisteredCleanupTimer.clear();
		}
	}
}
 
Example 6
Source File: BaseTwoInputStreamOperatorWithStateRetention.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * The users of this class are not allowed to use processing time timers.
 * See class javadoc.
 */
@Override
public final void onProcessingTime(InternalTimer<Object, VoidNamespace> timer) throws Exception {
	if (stateCleaningEnabled) {
		long timerTime = timer.getTimestamp();
		Long cleanupTime = latestRegisteredCleanupTimer.value();

		if (cleanupTime != null && cleanupTime == timerTime) {
			cleanupState(cleanupTime);
			latestRegisteredCleanupTimer.clear();
		}
	}
}