Java Code Examples for org.apache.flink.runtime.state.KeyedStateBackend#getKeySerializer()

The following examples show how to use org.apache.flink.runtime.state.KeyedStateBackend#getKeySerializer() . 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: InternalTimeServiceManager.java    From flink with Apache License 2.0 5 votes vote down vote up
public <N> InternalTimerService<N> getInternalTimerService(
		String name,
		TypeSerializer<N> namespaceSerializer,
		Triggerable<K, N> triggerable,
		KeyedStateBackend<K> keyedStateBackend) {
	checkNotNull(keyedStateBackend, "Timers can only be used on keyed operators.");

	TypeSerializer<K> keySerializer = keyedStateBackend.getKeySerializer();
	// the following casting is to overcome type restrictions.
	TimerSerializer<K, N> timerSerializer = new TimerSerializer<>(keySerializer, namespaceSerializer);
	return getInternalTimerService(name, timerSerializer, triggerable);
}
 
Example 2
Source File: AbstractStreamOperator.java    From Flink-CEPplus with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a {@link InternalTimerService} that can be used to query current processing time
 * and event time and to set timers. An operator can have several timer services, where
 * each has its own namespace serializer. Timer services are differentiated by the string
 * key that is given when requesting them, if you call this method with the same key
 * multiple times you will get the same timer service instance in subsequent requests.
 *
 * <p>Timers are always scoped to a key, the currently active key of a keyed stream operation.
 * When a timer fires, this key will also be set as the currently active key.
 *
 * <p>Each timer has attached metadata, the namespace. Different timer services
 * can have a different namespace type. If you don't need namespace differentiation you
 * can use {@link VoidNamespaceSerializer} as the namespace serializer.
 *
 * @param name The name of the requested timer service. If no service exists under the given
 *             name a new one will be created and returned.
 * @param namespaceSerializer {@code TypeSerializer} for the timer namespace.
 * @param triggerable The {@link Triggerable} that should be invoked when timers fire
 *
 * @param <N> The type of the timer namespace.
 */
public <K, N> InternalTimerService<N> getInternalTimerService(
		String name,
		TypeSerializer<N> namespaceSerializer,
		Triggerable<K, N> triggerable) {

	checkTimerServiceInitialization();

	// the following casting is to overcome type restrictions.
	KeyedStateBackend<K> keyedStateBackend = getKeyedStateBackend();
	TypeSerializer<K> keySerializer = keyedStateBackend.getKeySerializer();
	InternalTimeServiceManager<K> keyedTimeServiceHandler = (InternalTimeServiceManager<K>) timeServiceManager;
	TimerSerializer<K, N> timerSerializer = new TimerSerializer<>(keySerializer, namespaceSerializer);
	return keyedTimeServiceHandler.getInternalTimerService(name, timerSerializer, triggerable);
}
 
Example 3
Source File: AbstractStreamOperator.java    From flink with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a {@link InternalTimerService} that can be used to query current processing time
 * and event time and to set timers. An operator can have several timer services, where
 * each has its own namespace serializer. Timer services are differentiated by the string
 * key that is given when requesting them, if you call this method with the same key
 * multiple times you will get the same timer service instance in subsequent requests.
 *
 * <p>Timers are always scoped to a key, the currently active key of a keyed stream operation.
 * When a timer fires, this key will also be set as the currently active key.
 *
 * <p>Each timer has attached metadata, the namespace. Different timer services
 * can have a different namespace type. If you don't need namespace differentiation you
 * can use {@link VoidNamespaceSerializer} as the namespace serializer.
 *
 * @param name The name of the requested timer service. If no service exists under the given
 *             name a new one will be created and returned.
 * @param namespaceSerializer {@code TypeSerializer} for the timer namespace.
 * @param triggerable The {@link Triggerable} that should be invoked when timers fire
 *
 * @param <N> The type of the timer namespace.
 */
public <K, N> InternalTimerService<N> getInternalTimerService(
		String name,
		TypeSerializer<N> namespaceSerializer,
		Triggerable<K, N> triggerable) {

	checkTimerServiceInitialization();

	// the following casting is to overcome type restrictions.
	KeyedStateBackend<K> keyedStateBackend = getKeyedStateBackend();
	TypeSerializer<K> keySerializer = keyedStateBackend.getKeySerializer();
	InternalTimeServiceManager<K> keyedTimeServiceHandler = (InternalTimeServiceManager<K>) timeServiceManager;
	TimerSerializer<K, N> timerSerializer = new TimerSerializer<>(keySerializer, namespaceSerializer);
	return keyedTimeServiceHandler.getInternalTimerService(name, timerSerializer, triggerable);
}