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

The following examples show how to use org.apache.flink.api.java.typeutils.runtime.DataInputViewStream. 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: StatefulComplexPayloadSerializer.java    From flink with 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 #2
Source File: InternalTimersSnapshotReaderWriters.java    From flink with 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 #3
Source File: StatefulComplexPayloadSerializer.java    From flink with 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 #4
Source File: RowDataSerializer.java    From flink with 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 #5
Source File: RowDataSerializer.java    From flink with 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 #6
Source File: InternalTimersSnapshotReaderWriters.java    From flink with 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 #7
Source File: BaseRowSerializer.java    From flink with 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 File: InternalTimersSnapshotReaderWriters.java    From Flink-CEPplus with 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 #9
Source File: StatefulComplexPayloadSerializer.java    From Flink-CEPplus with 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 #10
Source File: SortedMapSerializerSnapshot.java    From flink with 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 #11
Source File: KryoSerializerSnapshotData.java    From Flink-CEPplus with 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
Source File: GenericArraySerializerConfigSnapshot.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
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 File: JavaSerializer.java    From flink with 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 #14
Source File: LegacyStateMetaInfoReaders.java    From flink with 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 #15
Source File: GenericArraySerializerConfigSnapshot.java    From flink with Apache License 2.0 5 votes vote down vote up
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 #16
Source File: KryoSerializerSnapshotData.java    From flink with 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 #17
Source File: KryoSerializer.java    From flink with 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 #18
Source File: MapDataSerializer.java    From flink with 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 File: ArrayDataSerializer.java    From flink with 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 #20
Source File: LegacyStateMetaInfoReaders.java    From Flink-CEPplus with 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 #21
Source File: MapDataSerializer.java    From flink with 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 #22
Source File: ArrayDataSerializer.java    From flink with 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 #23
Source File: JavaSerializer.java    From Flink-CEPplus with 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 File: BaseArraySerializer.java    From flink with 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 #25
Source File: TimestampedHiveInputSplit.java    From flink with 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 #26
Source File: KryoSerializer.java    From Flink-CEPplus with 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 #27
Source File: JavaSerializer.java    From flink with 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 #28
Source File: LegacyStateMetaInfoReaders.java    From flink with 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 #29
Source File: GenericArraySerializerConfigSnapshot.java    From flink with Apache License 2.0 5 votes vote down vote up
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 #30
Source File: KryoSerializerSnapshotData.java    From flink with 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;
	}
}