You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2019/02/18 10:31:39 UTC

[GitHub] tzulitai commented on a change in pull request #7696: [FLINK-11588][core] Migrating the CopyableValueSerializer

tzulitai commented on a change in pull request #7696: [FLINK-11588][core] Migrating the CopyableValueSerializer
URL: https://github.com/apache/flink/pull/7696#discussion_r257637887
 
 

 ##########
 File path: flink-core/src/main/java/org/apache/flink/api/common/typeutils/GenericTypeSerializerSnapshot.java
 ##########
 @@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.api.common.typeutils;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.core.memory.DataInputView;
+import org.apache.flink.core.memory.DataOutputView;
+import org.apache.flink.util.InstantiationUtil;
+
+import java.io.IOException;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+import static org.apache.flink.util.Preconditions.checkState;
+
+/**
+ * Base {@link TypeSerializerSnapshot} for serializers for generic types.
+ *
+ * @param <T> The type to be instantiated.
+ */
+@Internal
+public abstract class GenericTypeSerializerSnapshot<T, S extends TypeSerializer> implements TypeSerializerSnapshot<T> {
+
+	private static final int VERSION = 2;
+	private Class<T> typeClass;
+
+	protected GenericTypeSerializerSnapshot() {
+	}
+
+	protected GenericTypeSerializerSnapshot(Class<T> typeClass) {
+		this.typeClass = checkNotNull(typeClass, "type class can not be NULL");
+	}
+
+	/**
+	 * Create a serializer that is able to serialize the generic type {@code typeClass}.
+	 */
+	protected abstract TypeSerializer<T> createSerializer(Class<T> typeClass);
+
+	/**
+	 * Gets the type class from the corresponding serializer.
+	 */
+	protected abstract Class<T> getTypeClass(S serializer);
+
+	/**
+	 * Gets the serializer's class.
+	 */
+	protected abstract Class<?> serializerClass();
+
+	@Override
+	public int getCurrentVersion() {
+		return VERSION;
+	}
+
+	@Override
+	public void writeSnapshot(DataOutputView out) throws IOException {
 
 Review comment:
   since this is a abstract base snapshot class to be used by different serializers' snapshots, do we want some versioning in the base class that allows the subclass formats to evolve independently?
   
   Either that, of we make the `writeSnapshot`, `readSnapshot`, `getCurrentVersion` methods final, meaning that the subclasses don't really add any new information and therefore the serialization format is solely defined by this base class only.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services