cameronlee314 commented on a change in pull request #1027: SAMZA-2046: Startpoint fan out implementation URL: https://github.com/apache/samza/pull/1027#discussion_r283468904
########## File path: samza-core/src/main/java/org/apache/samza/startpoint/StartpointFanOut.java ########## @@ -0,0 +1,123 @@ +/* + * 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.samza.startpoint; + +import com.google.common.collect.ImmutableMap; +import java.time.Instant; +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; +import org.apache.samza.Partition; +import org.apache.samza.SamzaException; +import org.apache.samza.serializers.Serde; +import org.apache.samza.system.SystemStreamPartition; +import org.codehaus.jackson.map.ObjectMapper; + + +/** + * Holds the {@link Startpoint} fan outs for each {@link SystemStreamPartition}. Each StartpointFanOut maps to a + * {@link org.apache.samza.container.TaskName} + */ +class StartpointFanOut { + private final Instant timestamp; + private final Map<SystemStreamPartition, Startpoint> fanOuts; + + StartpointFanOut(Instant timestamp, Map<SystemStreamPartition, Startpoint> fanOuts) { + this.timestamp = timestamp; + this.fanOuts = fanOuts; + } + + // Unused in code, but useful for auditing when the fan out is serialized into the store + Instant getTimestamp() { + return timestamp; + } + + Map<SystemStreamPartition, Startpoint> getFanOuts() { + return fanOuts; + } + + static class StartpointFanOutSerde implements Serde<StartpointFanOut> { + private static final String TIMESTAMP = "timestamp"; + private static final String FAN_OUTS = "fanOuts"; + private static final String SYSTEM = "system"; + private static final String STREAM = "stream"; + private static final String PARTITION = "partition"; + + private final ObjectMapper mapper = new ObjectMapper(); + private final StartpointSerde startpointSerde = new StartpointSerde(); Review comment: It seems a little awkward to do this explicit two-step serde, one for this container object and then another for the actual `Startpoint`. Could we follow the `SamzaObjectMapper` pattern where we define serializers/deserializers for certain classes? Then I think this serde would be able to implicitly use the `Startpoint` serde. In fact, `SamzaObjectMapper` already has a `SystemStreamPartitionSerializer` and `SystemStreamPartitionDeserializer`. I'm not sure if it is better to directly reuse `SamzaObjectMapper` or not, but it's patterns/components might be leverageable. ---------------------------------------------------------------- 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: [email protected] With regards, Apache Git Services
