Java Code Examples for org.apache.flink.util.InstantiationUtil#resolveClassByName()

The following examples show how to use org.apache.flink.util.InstantiationUtil#resolveClassByName() . 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: EnumSerializer.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 {
	enumClass = InstantiationUtil.resolveClassByName(in, userCodeClassLoader);

	int numEnumConstants = in.readInt();

	@SuppressWarnings("unchecked")
	T[] previousEnums = (T[]) Array.newInstance(enumClass, numEnumConstants);
	for (int i = 0; i < numEnumConstants; i++) {
		String enumName = in.readUTF();
		try {
			previousEnums[i] = Enum.valueOf(enumClass, enumName);
		} catch (IllegalArgumentException e) {
			throw new IllegalStateException("Could not create a restore serializer for enum " +
					enumClass +
					". Probably because an enum value was removed.");
		}
	}

	this.previousEnums = previousEnums;
}
 
Example 2
Source File: PojoSerializerSnapshotData.java    From flink with Apache License 2.0 6 votes vote down vote up
private static <T> PojoSerializerSnapshotData<T> readSnapshotData(DataInputView in, ClassLoader userCodeClassLoader) throws IOException {
	Class<T> pojoClass = InstantiationUtil.resolveClassByName(in, userCodeClassLoader);

	LinkedOptionalMap<Field, TypeSerializerSnapshot<?>> fieldSerializerSnapshots = readOptionalMap(
		in,
		fieldReader(userCodeClassLoader),
		snapshotReader(userCodeClassLoader));
	LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> registeredSubclassSerializerSnapshots = readOptionalMap(
		in,
		classReader(userCodeClassLoader),
		snapshotReader(userCodeClassLoader));
	LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> nonRegisteredSubclassSerializerSnapshots = readOptionalMap(
		in,
		classReader(userCodeClassLoader),
		snapshotReader(userCodeClassLoader));

	return new PojoSerializerSnapshotData<>(pojoClass, fieldSerializerSnapshots, registeredSubclassSerializerSnapshots, nonRegisteredSubclassSerializerSnapshots);
}
 
Example 3
Source File: EnumSerializer.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public void readSnapshot(int readVersion, DataInputView in, ClassLoader userCodeClassLoader) throws IOException {
	enumClass = InstantiationUtil.resolveClassByName(in, userCodeClassLoader);

	int numEnumConstants = in.readInt();

	@SuppressWarnings("unchecked")
	T[] previousEnums = (T[]) Array.newInstance(enumClass, numEnumConstants);
	for (int i = 0; i < numEnumConstants; i++) {
		String enumName = in.readUTF();
		try {
			previousEnums[i] = Enum.valueOf(enumClass, enumName);
		} catch (IllegalArgumentException e) {
			throw new IllegalStateException("Could not create a restore serializer for enum " +
					enumClass +
					". Probably because an enum value was removed.");
		}
	}

	this.previousEnums = previousEnums;
}
 
Example 4
Source File: GenericTypeSerializerSnapshot.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public final void readSnapshot(int readVersion, DataInputView in, ClassLoader userCodeClassLoader) throws IOException {
	typeClass = InstantiationUtil.resolveClassByName(in, userCodeClassLoader);
}
 
Example 5
Source File: TupleSerializerSnapshot.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected void readOuterSnapshot(int readOuterSnapshotVersion, DataInputView in, ClassLoader userCodeClassLoader) throws IOException {
	this.tupleClass = InstantiationUtil.resolveClassByName(in, userCodeClassLoader);
}
 
Example 6
Source File: GenericArraySerializerConfigSnapshot.java    From flink with Apache License 2.0 4 votes vote down vote up
private void readV2(DataInputView in, ClassLoader classLoader) throws IOException {
	componentClass = InstantiationUtil.resolveClassByName(in, classLoader);
	nestedSnapshot = NestedSerializersSnapshotDelegate.readNestedSerializerSnapshots(in, classLoader);
}
 
Example 7
Source File: GenericTypeSerializerSnapshot.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public final void readSnapshot(int readVersion, DataInputView in, ClassLoader userCodeClassLoader) throws IOException {
	typeClass = InstantiationUtil.resolveClassByName(in, userCodeClassLoader);
}
 
Example 8
Source File: KryoSerializerSnapshotData.java    From flink with Apache License 2.0 4 votes vote down vote up
private static <T> Class<T> readTypeClass(DataInputView in, ClassLoader userCodeClassLoader) throws IOException {
	return InstantiationUtil.resolveClassByName(in, userCodeClassLoader);
}
 
Example 9
Source File: TupleSerializerSnapshot.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected void readOuterSnapshot(int readOuterSnapshotVersion, DataInputView in, ClassLoader userCodeClassLoader) throws IOException {
	this.tupleClass = InstantiationUtil.resolveClassByName(in, userCodeClassLoader);
}
 
Example 10
Source File: ScalaCaseClassSerializerSnapshot.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected void readOuterSnapshot(int readOuterSnapshotVersion, DataInputView in, ClassLoader userCodeClassLoader) throws IOException {
	this.type = InstantiationUtil.resolveClassByName(in, userCodeClassLoader);
}
 
Example 11
Source File: Tuple2CaseClassSerializerSnapshot.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected void readOuterSnapshot(int readOuterSnapshotVersion, DataInputView in, ClassLoader userCodeClassLoader) throws IOException {
	this.type = InstantiationUtil.resolveClassByName(in, userCodeClassLoader);
}
 
Example 12
Source File: Tuple2CaseClassSerializerSnapshot.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
protected void readOuterSnapshot(int readOuterSnapshotVersion, DataInputView in, ClassLoader userCodeClassLoader) throws IOException {
	this.type = InstantiationUtil.resolveClassByName(in, userCodeClassLoader);
}
 
Example 13
Source File: GenericArraySerializerConfigSnapshot.java    From flink with Apache License 2.0 4 votes vote down vote up
private void readV2(DataInputView in, ClassLoader classLoader) throws IOException {
	componentClass = InstantiationUtil.resolveClassByName(in, classLoader);
	nestedSnapshot = NestedSerializersSnapshotDelegate.readNestedSerializerSnapshots(in, classLoader);
}
 
Example 14
Source File: TypeSerializerSnapshotSerializationUtil.java    From flink with Apache License 2.0 4 votes vote down vote up
public static <T> TypeSerializerSnapshot<T> readAndInstantiateSnapshotClass(DataInputView in, ClassLoader cl) throws IOException {
	Class<TypeSerializerSnapshot<T>> clazz =
			InstantiationUtil.resolveClassByName(in, cl, TypeSerializerSnapshot.class);

	return InstantiationUtil.instantiate(clazz);
}
 
Example 15
Source File: GenericTypeSerializerSnapshot.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public final void readSnapshot(int readVersion, DataInputView in, ClassLoader userCodeClassLoader) throws IOException {
	typeClass = InstantiationUtil.resolveClassByName(in, userCodeClassLoader);
}
 
Example 16
Source File: Tuple2CaseClassSerializerSnapshot.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected void readOuterSnapshot(int readOuterSnapshotVersion, DataInputView in, ClassLoader userCodeClassLoader) throws IOException {
	this.type = InstantiationUtil.resolveClassByName(in, userCodeClassLoader);
}
 
Example 17
Source File: KryoSerializerSnapshotData.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
private static <T> Class<T> readTypeClass(DataInputView in, ClassLoader userCodeClassLoader) throws IOException {
	return InstantiationUtil.resolveClassByName(in, userCodeClassLoader);
}
 
Example 18
Source File: TupleSerializerSnapshot.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
protected void readOuterSnapshot(int readOuterSnapshotVersion, DataInputView in, ClassLoader userCodeClassLoader) throws IOException {
	this.tupleClass = InstantiationUtil.resolveClassByName(in, userCodeClassLoader);
}
 
Example 19
Source File: TypeSerializerSnapshotSerializationUtil.java    From flink with Apache License 2.0 4 votes vote down vote up
public static <T> TypeSerializerSnapshot<T> readAndInstantiateSnapshotClass(DataInputView in, ClassLoader cl) throws IOException {
	Class<TypeSerializerSnapshot<T>> clazz =
			InstantiationUtil.resolveClassByName(in, cl, TypeSerializerSnapshot.class);

	return InstantiationUtil.instantiate(clazz);
}
 
Example 20
Source File: PojoFieldUtils.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Reads a field from the given {@link DataInputView}.
 *
 * <p>This read methods avoids Java serialization, by reading the classname of the field's declaring class
 * and dynamically loading it. The field is also read by field name and obtained via reflection.
 *
 * @param in the input view to read from.
 * @param userCodeClassLoader the user classloader.
 *
 * @return the read field.
 */
static Field readField(DataInputView in, ClassLoader userCodeClassLoader) throws IOException {
	Class<?> declaringClass = InstantiationUtil.resolveClassByName(in, userCodeClassLoader);
	String fieldName = in.readUTF();
	return getField(fieldName, declaringClass);
}