Java Code Examples for org.apache.flink.api.java.typeutils.runtime.DataInputViewStream

The following examples show how to use org.apache.flink.api.java.typeutils.runtime.DataInputViewStream. These examples are extracted from open source projects. 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
@Override
public ComplexPayload deserialize(DataInputView source) throws IOException {
	try (final DataInputViewStream inViewWrapper = new DataInputViewStream(source)) {
		Thread currentThread = Thread.currentThread();
		if (currentOwnerThread.compareAndSet(null, currentThread)) {
			return InstantiationUtil.deserializeObject(
				inViewWrapper,
				currentThread.getContextClassLoader());
		} else {
			throw new IllegalStateException("Concurrent access to type serializer detected!");
		}
	} catch (ClassNotFoundException e) {
		throw new IOException("Could not deserialize object.", e);
	} finally {
		currentOwnerThread.set(null);
	}
}
 
Example 2
@SuppressWarnings("unchecked")
@Override
protected void restoreKeyAndNamespaceSerializers(
		InternalTimersSnapshot<K, N> restoredTimersSnapshot,
		DataInputView in) throws IOException {

	DataInputViewStream dis = new DataInputViewStream(in);
	try {
		final TypeSerializer<K> keySerializer = InstantiationUtil.deserializeObject(dis, userCodeClassLoader, true);
		final TypeSerializer<N> namespaceSerializer = InstantiationUtil.deserializeObject(dis, userCodeClassLoader, true);

		restoredTimersSnapshot.setKeySerializerSnapshot(new BackwardsCompatibleSerializerSnapshot<>(keySerializer));
		restoredTimersSnapshot.setNamespaceSerializerSnapshot(new BackwardsCompatibleSerializerSnapshot<>(namespaceSerializer));
	} catch (ClassNotFoundException exception) {
		throw new IOException(exception);
	}
}
 
Example 3
Source Project: flink   Source File: BaseRowSerializer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void readSnapshot(int readVersion, DataInputView in, ClassLoader userCodeClassLoader)
		throws IOException {
	int length = in.readInt();
	DataInputViewStream stream = new DataInputViewStream(in);
	previousTypes = new LogicalType[length];
	for (int i = 0; i < length; i++) {
		try {
			previousTypes[i] = InstantiationUtil.deserializeObject(
					stream,
					userCodeClassLoader
			);
		}
		catch (ClassNotFoundException e) {
			throw new IOException(e);
		}
	}
	this.nestedSerializersSnapshotDelegate = NestedSerializersSnapshotDelegate.readNestedSerializerSnapshots(
			in,
			userCodeClassLoader
	);
}
 
Example 4
Source Project: flink   Source File: StatefulComplexPayloadSerializer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ComplexPayload deserialize(DataInputView source) throws IOException {
	try (final DataInputViewStream inViewWrapper = new DataInputViewStream(source)) {
		Thread currentThread = Thread.currentThread();
		if (currentOwnerThread.compareAndSet(null, currentThread)) {
			return InstantiationUtil.deserializeObject(
				inViewWrapper,
				currentThread.getContextClassLoader());
		} else {
			throw new IllegalStateException("Concurrent access to type serializer detected!");
		}
	} catch (ClassNotFoundException e) {
		throw new IOException("Could not deserialize object.", e);
	} finally {
		currentOwnerThread.set(null);
	}
}
 
Example 5
Source Project: flink   Source File: InternalTimersSnapshotReaderWriters.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected void restoreKeyAndNamespaceSerializers(
		InternalTimersSnapshot<K, N> restoredTimersSnapshot,
		DataInputView in) throws IOException {

	DataInputViewStream dis = new DataInputViewStream(in);
	try {
		final TypeSerializer<K> keySerializer = InstantiationUtil.deserializeObject(dis, userCodeClassLoader, true);
		final TypeSerializer<N> namespaceSerializer = InstantiationUtil.deserializeObject(dis, userCodeClassLoader, true);

		restoredTimersSnapshot.setKeySerializerSnapshot(new BackwardsCompatibleSerializerSnapshot<>(keySerializer));
		restoredTimersSnapshot.setNamespaceSerializerSnapshot(new BackwardsCompatibleSerializerSnapshot<>(namespaceSerializer));
	} catch (ClassNotFoundException exception) {
		throw new IOException(exception);
	}
}
 
Example 6
Source Project: flink   Source File: RowDataSerializer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void readSnapshot(int readVersion, DataInputView in, ClassLoader userCodeClassLoader)
	throws IOException {
	int length = in.readInt();
	DataInputViewStream stream = new DataInputViewStream(in);
	previousTypes = new LogicalType[length];
	for (int i = 0; i < length; i++) {
		try {
			previousTypes[i] = InstantiationUtil.deserializeObject(
				stream,
				userCodeClassLoader
			);
		}
		catch (ClassNotFoundException e) {
			throw new IOException(e);
		}
	}
	this.nestedSerializersSnapshotDelegate = NestedSerializersSnapshotDelegate.readNestedSerializerSnapshots(
		in,
		userCodeClassLoader
	);
}
 
Example 7
Source Project: flink   Source File: RowDataSerializer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void readSnapshot(int readVersion, DataInputView in, ClassLoader userCodeClassLoader)
	throws IOException {
	int length = in.readInt();
	DataInputViewStream stream = new DataInputViewStream(in);
	previousTypes = new LogicalType[length];
	for (int i = 0; i < length; i++) {
		try {
			previousTypes[i] = InstantiationUtil.deserializeObject(
				stream,
				userCodeClassLoader
			);
		} catch (ClassNotFoundException e) {
			throw new IOException(e);
		}
	}
	this.nestedSerializersSnapshotDelegate = NestedSerializersSnapshotDelegate.readNestedSerializerSnapshots(
		in,
		userCodeClassLoader
	);
}
 
Example 8
Source Project: flink   Source File: StatefulComplexPayloadSerializer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ComplexPayload deserialize(DataInputView source) throws IOException {
	try (final DataInputViewStream inViewWrapper = new DataInputViewStream(source)) {
		Thread currentThread = Thread.currentThread();
		if (currentOwnerThread.compareAndSet(null, currentThread)) {
			return InstantiationUtil.deserializeObject(
				inViewWrapper,
				currentThread.getContextClassLoader());
		} else {
			throw new IllegalStateException("Concurrent access to type serializer detected!");
		}
	} catch (ClassNotFoundException e) {
		throw new IOException("Could not deserialize object.", e);
	} finally {
		currentOwnerThread.set(null);
	}
}
 
Example 9
Source Project: flink   Source File: InternalTimersSnapshotReaderWriters.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected void restoreKeyAndNamespaceSerializers(
		InternalTimersSnapshot<K, N> restoredTimersSnapshot,
		DataInputView in) throws IOException {

	DataInputViewStream dis = new DataInputViewStream(in);
	try {
		final TypeSerializer<K> keySerializer = InstantiationUtil.deserializeObject(dis, userCodeClassLoader, true);
		final TypeSerializer<N> namespaceSerializer = InstantiationUtil.deserializeObject(dis, userCodeClassLoader, true);

		restoredTimersSnapshot.setKeySerializerSnapshot(new BackwardsCompatibleSerializerSnapshot<>(keySerializer));
		restoredTimersSnapshot.setNamespaceSerializerSnapshot(new BackwardsCompatibleSerializerSnapshot<>(namespaceSerializer));
	} catch (ClassNotFoundException exception) {
		throw new IOException(exception);
	}
}
 
Example 10
Source Project: Flink-CEPplus   Source File: KryoSerializer.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public T deserialize(DataInputView source) throws IOException {
	if (CONCURRENT_ACCESS_CHECK) {
		enterExclusiveThread();
	}

	try {
		checkKryoInitialized();

		if (source != previousIn) {
			DataInputViewStream inputStream = new DataInputViewStream(source);
			input = new NoFetchingInput(inputStream);
			previousIn = source;
		}

		try {
			return (T) kryo.readClassAndObject(input);
		} catch (KryoException ke) {
			Throwable cause = ke.getCause();

			if (cause instanceof EOFException) {
				throw (EOFException) cause;
			} else {
				throw ke;
			}
		}
	}
	finally {
		if (CONCURRENT_ACCESS_CHECK) {
			exitExclusiveThread();
		}
	}
}
 
Example 11
Source Project: Flink-CEPplus   Source File: KryoSerializerSnapshotData.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public SerializableSerializer<?> apply(DataInputView stream, String className) {
	try {
		try (final DataInputViewStream inViewWrapper = new DataInputViewStream(stream)) {
			return InstantiationUtil.deserializeObject(inViewWrapper, classLoader);
		}
	}
	catch (Throwable e) {
		LOG.warn("Cannot deserialize a previously serialized kryo serializer for the type " + className, e);
		return null;
	}
}
 
Example 12
private void readV1(DataInputView in, ClassLoader classLoader) throws IOException {
	nestedSnapshot = NestedSerializersSnapshotDelegate.legacyReadNestedSerializerSnapshots(in, classLoader);

	try (DataInputViewStream inViewWrapper = new DataInputViewStream(in)) {
		componentClass = InstantiationUtil.deserializeObject(inViewWrapper, classLoader);
	}
	catch (ClassNotFoundException e) {
		throw new IOException("Could not find requested element class in classpath.", e);
	}
}
 
Example 13
Source Project: Flink-CEPplus   Source File: LegacyStateMetaInfoReaders.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public StateMetaInfoSnapshot readStateMetaInfoSnapshot(
	@Nonnull DataInputView in,
	@Nonnull ClassLoader userCodeClassLoader) throws IOException {

	final String name = in.readUTF();
	final OperatorStateHandle.Mode mode = OperatorStateHandle.Mode.values()[in.readByte()];
	final Map<String, String> optionsMap = Collections.singletonMap(
		StateMetaInfoSnapshot.CommonOptionsKeys.OPERATOR_STATE_DISTRIBUTION_MODE.toString(),
		mode.toString());

	DataInputViewStream dis = new DataInputViewStream(in);
	ClassLoader previousClassLoader = Thread.currentThread().getContextClassLoader();

	try (
		InstantiationUtil.FailureTolerantObjectInputStream ois =
			new InstantiationUtil.FailureTolerantObjectInputStream(dis, userCodeClassLoader)) {
		Thread.currentThread().setContextClassLoader(userCodeClassLoader);
		TypeSerializer<?> stateSerializer = (TypeSerializer<?>) ois.readObject();
		return new StateMetaInfoSnapshot(
			name,
			StateMetaInfoSnapshot.BackendStateType.OPERATOR,
			optionsMap,
			Collections.singletonMap(
				StateMetaInfoSnapshot.CommonSerializerKeys.VALUE_SERIALIZER.toString(),
				new BackwardsCompatibleSerializerSnapshot<>(stateSerializer)));
	} catch (ClassNotFoundException exception) {
		throw new IOException(exception);
	} finally {
		Thread.currentThread().setContextClassLoader(previousClassLoader);
	}
}
 
Example 14
Source Project: Flink-CEPplus   Source File: JavaSerializer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public T deserialize(DataInputView source) throws IOException {
	try (final DataInputViewStream inViewWrapper = new DataInputViewStream(source)) {
		return InstantiationUtil.deserializeObject(
				inViewWrapper,
				Thread.currentThread().getContextClassLoader());
	} catch (ClassNotFoundException e) {
		throw new IOException("Could not deserialize object.", e);
	}
}
 
Example 15
Source Project: flink   Source File: BaseArraySerializer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void readSnapshot(int readVersion, DataInputView in, ClassLoader userCodeClassLoader) throws IOException {
	try {
		DataInputViewStream inStream = new DataInputViewStream(in);
		this.previousType = InstantiationUtil.deserializeObject(inStream, userCodeClassLoader);
		this.previousEleSer = InstantiationUtil.deserializeObject(inStream, userCodeClassLoader);
	} catch (ClassNotFoundException e) {
		throw new IOException(e);
	}
}
 
Example 16
Source Project: flink   Source File: SortedMapSerializerSnapshot.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void readSnapshot(int readVersion, DataInputView in, ClassLoader userCodeClassLoader) throws IOException {
	try {
		comparator = InstantiationUtil.deserializeObject(
				new DataInputViewStream(in), userCodeClassLoader);
	} catch (ClassNotFoundException e) {
		throw new IOException(e);
	}
	this.nestedSerializersSnapshotDelegate = NestedSerializersSnapshotDelegate.readNestedSerializerSnapshots(
			in,
			userCodeClassLoader);
}
 
Example 17
Source Project: flink   Source File: BinaryGenericSerializer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void readSnapshot(int readVersion, DataInputView in, ClassLoader userCodeClassLoader) throws IOException {
	try {
		this.previousSerializer = InstantiationUtil.deserializeObject(
				new DataInputViewStream(in), userCodeClassLoader);
	} catch (ClassNotFoundException e) {
		throw new IOException(e);
	}
}
 
Example 18
Source Project: flink   Source File: BaseMapSerializer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void readSnapshot(int readVersion, DataInputView in, ClassLoader userCodeClassLoader) throws IOException {
	try {
		DataInputViewStream inStream = new DataInputViewStream(in);
		this.previousKeyType = InstantiationUtil.deserializeObject(inStream, userCodeClassLoader);
		this.previousValueType = InstantiationUtil.deserializeObject(inStream, userCodeClassLoader);
		this.previousKeySerializer = InstantiationUtil.deserializeObject(inStream, userCodeClassLoader);
		this.previousValueSerializer = InstantiationUtil.deserializeObject(inStream, userCodeClassLoader);
	} catch (ClassNotFoundException e) {
		throw new IOException(e);
	}
}
 
Example 19
Source Project: flink   Source File: KryoSerializer.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public T deserialize(DataInputView source) throws IOException {
	if (CONCURRENT_ACCESS_CHECK) {
		enterExclusiveThread();
	}

	try {
		checkKryoInitialized();

		if (source != previousIn) {
			DataInputViewStream inputStream = new DataInputViewStream(source);
			input = new NoFetchingInput(inputStream);
			previousIn = source;
		}

		try {
			return (T) kryo.readClassAndObject(input);
		} catch (KryoException ke) {
			Throwable cause = ke.getCause();

			if (cause instanceof EOFException) {
				throw (EOFException) cause;
			} else {
				throw ke;
			}
		}
	}
	finally {
		if (CONCURRENT_ACCESS_CHECK) {
			exitExclusiveThread();
		}
	}
}
 
Example 20
Source Project: flink   Source File: KryoSerializerSnapshotData.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public SerializableSerializer<?> apply(DataInputView stream, String className) {
	try {
		try (final DataInputViewStream inViewWrapper = new DataInputViewStream(stream)) {
			return InstantiationUtil.deserializeObject(inViewWrapper, classLoader);
		}
	}
	catch (Throwable e) {
		LOG.warn("Cannot deserialize a previously serialized kryo serializer for the type " + className, e);
		return null;
	}
}
 
Example 21
private void readV1(DataInputView in, ClassLoader classLoader) throws IOException {
	nestedSnapshot = NestedSerializersSnapshotDelegate.legacyReadNestedSerializerSnapshots(in, classLoader);

	try (DataInputViewStream inViewWrapper = new DataInputViewStream(in)) {
		componentClass = InstantiationUtil.deserializeObject(inViewWrapper, classLoader);
	}
	catch (ClassNotFoundException e) {
		throw new IOException("Could not find requested element class in classpath.", e);
	}
}
 
Example 22
Source Project: flink   Source File: LegacyStateMetaInfoReaders.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public StateMetaInfoSnapshot readStateMetaInfoSnapshot(
	@Nonnull DataInputView in,
	@Nonnull ClassLoader userCodeClassLoader) throws IOException {

	final String name = in.readUTF();
	final OperatorStateHandle.Mode mode = OperatorStateHandle.Mode.values()[in.readByte()];
	final Map<String, String> optionsMap = Collections.singletonMap(
		StateMetaInfoSnapshot.CommonOptionsKeys.OPERATOR_STATE_DISTRIBUTION_MODE.toString(),
		mode.toString());

	DataInputViewStream dis = new DataInputViewStream(in);
	ClassLoader previousClassLoader = Thread.currentThread().getContextClassLoader();

	try (
		InstantiationUtil.FailureTolerantObjectInputStream ois =
			new InstantiationUtil.FailureTolerantObjectInputStream(dis, userCodeClassLoader)) {
		Thread.currentThread().setContextClassLoader(userCodeClassLoader);
		TypeSerializer<?> stateSerializer = (TypeSerializer<?>) ois.readObject();
		return new StateMetaInfoSnapshot(
			name,
			StateMetaInfoSnapshot.BackendStateType.OPERATOR,
			optionsMap,
			Collections.singletonMap(
				StateMetaInfoSnapshot.CommonSerializerKeys.VALUE_SERIALIZER.toString(),
				new BackwardsCompatibleSerializerSnapshot<>(stateSerializer)));
	} catch (ClassNotFoundException exception) {
		throw new IOException(exception);
	} finally {
		Thread.currentThread().setContextClassLoader(previousClassLoader);
	}
}
 
Example 23
Source Project: flink   Source File: JavaSerializer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public T deserialize(DataInputView source) throws IOException {
	try (final DataInputViewStream inViewWrapper = new DataInputViewStream(source)) {
		return InstantiationUtil.deserializeObject(
				inViewWrapper,
				Thread.currentThread().getContextClassLoader());
	} catch (ClassNotFoundException e) {
		throw new IOException("Could not deserialize object.", e);
	}
}
 
Example 24
Source Project: flink   Source File: TimestampedHiveInputSplit.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public TimestampedHiveInputSplit deserialize(DataInputView source) throws IOException {
	try (final DataInputViewStream inViewWrapper = new DataInputViewStream(source)) {
		return InstantiationUtil.deserializeObject(
				inViewWrapper,
				Thread.currentThread().getContextClassLoader());
	} catch (ClassNotFoundException e) {
		throw new IOException("Could not deserialize object.", e);
	}
}
 
Example 25
Source Project: flink   Source File: SortedMapSerializerSnapshot.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void readSnapshot(int readVersion, DataInputView in, ClassLoader userCodeClassLoader) throws IOException {
	try {
		comparator = InstantiationUtil.deserializeObject(
				new DataInputViewStream(in), userCodeClassLoader);
	} catch (ClassNotFoundException e) {
		throw new IOException(e);
	}
	this.nestedSerializersSnapshotDelegate = NestedSerializersSnapshotDelegate.readNestedSerializerSnapshots(
			in,
			userCodeClassLoader);
}
 
Example 26
Source Project: flink   Source File: ArrayDataSerializer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void readSnapshot(int readVersion, DataInputView in, ClassLoader userCodeClassLoader) throws IOException {
	try {
		DataInputViewStream inStream = new DataInputViewStream(in);
		this.previousType = InstantiationUtil.deserializeObject(inStream, userCodeClassLoader);
		this.previousEleSer = InstantiationUtil.deserializeObject(inStream, userCodeClassLoader);
	} catch (ClassNotFoundException e) {
		throw new IOException(e);
	}
}
 
Example 27
Source Project: flink   Source File: MapDataSerializer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void readSnapshot(int readVersion, DataInputView in, ClassLoader userCodeClassLoader) throws IOException {
	try {
		DataInputViewStream inStream = new DataInputViewStream(in);
		this.previousKeyType = InstantiationUtil.deserializeObject(inStream, userCodeClassLoader);
		this.previousValueType = InstantiationUtil.deserializeObject(inStream, userCodeClassLoader);
		this.previousKeySerializer = InstantiationUtil.deserializeObject(inStream, userCodeClassLoader);
		this.previousValueSerializer = InstantiationUtil.deserializeObject(inStream, userCodeClassLoader);
	} catch (ClassNotFoundException e) {
		throw new IOException(e);
	}
}
 
Example 28
Source Project: flink   Source File: ArrayDataSerializer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void readSnapshot(int readVersion, DataInputView in, ClassLoader userCodeClassLoader) throws IOException {
	try {
		DataInputViewStream inStream = new DataInputViewStream(in);
		this.previousType = InstantiationUtil.deserializeObject(inStream, userCodeClassLoader);
		this.previousEleSer = InstantiationUtil.deserializeObject(inStream, userCodeClassLoader);
	} catch (ClassNotFoundException e) {
		throw new IOException(e);
	}
}
 
Example 29
Source Project: flink   Source File: MapDataSerializer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void readSnapshot(int readVersion, DataInputView in, ClassLoader userCodeClassLoader) throws IOException {
	try {
		DataInputViewStream inStream = new DataInputViewStream(in);
		this.previousKeyType = InstantiationUtil.deserializeObject(inStream, userCodeClassLoader);
		this.previousValueType = InstantiationUtil.deserializeObject(inStream, userCodeClassLoader);
		this.previousKeySerializer = InstantiationUtil.deserializeObject(inStream, userCodeClassLoader);
		this.previousValueSerializer = InstantiationUtil.deserializeObject(inStream, userCodeClassLoader);
	} catch (ClassNotFoundException e) {
		throw new IOException(e);
	}
}
 
Example 30
Source Project: flink   Source File: KryoSerializer.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public T deserialize(DataInputView source) throws IOException {
	if (CONCURRENT_ACCESS_CHECK) {
		enterExclusiveThread();
	}

	try {
		checkKryoInitialized();

		if (source != previousIn) {
			DataInputViewStream inputStream = new DataInputViewStream(source);
			input = new NoFetchingInput(inputStream);
			previousIn = source;
		}

		try {
			return (T) kryo.readClassAndObject(input);
		} catch (KryoException ke) {
			Throwable cause = ke.getCause();

			if (cause instanceof EOFException) {
				throw (EOFException) cause;
			} else {
				throw ke;
			}
		}
	}
	finally {
		if (CONCURRENT_ACCESS_CHECK) {
			exitExclusiveThread();
		}
	}
}