TsReaper commented on a change in pull request #12069: URL: https://github.com/apache/flink/pull/12069#discussion_r425261853
########## File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/collect/CollectCoordinationResponse.java ########## @@ -0,0 +1,104 @@ +/* + * 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.streaming.api.operators.collect; + +import org.apache.flink.api.common.typeutils.TypeSerializer; +import org.apache.flink.api.common.typeutils.base.ListSerializer; +import org.apache.flink.api.common.typeutils.base.LongSerializer; +import org.apache.flink.api.common.typeutils.base.StringSerializer; +import org.apache.flink.core.memory.DataInputViewStreamWrapper; +import org.apache.flink.core.memory.DataOutputViewStreamWrapper; +import org.apache.flink.runtime.operators.coordination.CoordinationResponse; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.List; + +/** + * A {@link CoordinationResponse} from the coordinator containing the required batch or new results + * and other necessary information in serialized form. + */ +public class CollectCoordinationResponse<T> implements CoordinationResponse { + + private static final long serialVersionUID = 1L; + + private static final TypeSerializer<String> versionSerializer = StringSerializer.INSTANCE; + private static final TypeSerializer<Long> offsetSerializer = LongSerializer.INSTANCE; + private static final TypeSerializer<Long> checkpointIdSerializer = LongSerializer.INSTANCE; + + private final String version; + private final long offset; + private final long lastCheckpointId; + private final byte[] resultBytes; + + public CollectCoordinationResponse( + String version, + long offset, + long lastCheckpointId, + List<T> results, + TypeSerializer<T> elementSerializer) throws IOException { + this.version = version; + this.offset = offset; + this.lastCheckpointId = lastCheckpointId; + + ListSerializer<T> listSerializer = new ListSerializer<>(elementSerializer); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputViewStreamWrapper wrapper = new DataOutputViewStreamWrapper(baos); + listSerializer.serialize(results, wrapper); + this.resultBytes = baos.toByteArray(); Review comment: I doubt if this is necessary. What's the purpose of making this change? It seems to me that this change just adds an extra method call. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org