taegeonum commented on a change in pull request #299: URL: https://github.com/apache/incubator-nemo/pull/299#discussion_r503603518
########## File path: compiler/frontend/beam/src/main/java/org/apache/nemo/compiler/frontend/beam/transform/NemoTimerInternals.java ########## @@ -0,0 +1,305 @@ +/* + * 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.nemo.compiler.frontend.beam.transform; + + +import com.google.common.base.MoreObjects; +import com.google.common.collect.HashBasedTable; +import com.google.common.collect.Table; +import org.apache.beam.runners.core.StateNamespace; +import org.apache.beam.runners.core.TimerInternals; +import org.apache.beam.sdk.state.*; +import org.apache.beam.sdk.transforms.windowing.BoundedWindow; +import org.apache.beam.sdk.util.WindowTracing; +import org.apache.nemo.common.Pair; +import org.joda.time.Instant; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.annotation.Nullable; +import java.util.*; + +/** + * Keep track of timer for a specific key. + * @param <K> key type + */ +public class NemoTimerInternals<K> implements TimerInternals { + private static final Logger LOG = LoggerFactory.getLogger(NemoTimerInternals.class.getName()); + /** The current set timers by namespace and ID. */ + private Table<StateNamespace, String, TimerData> existingTimers; + + /** Pending input watermark timers, in timestamp order. */ + private final NavigableSet<Pair<K, TimerData>> watermarkTimers; + + /** Pending processing time timers, in timestamp order. */ + private final NavigableSet<Pair<K, TimerData>> processingTimers; + + /** Pending synchronized processing time timers, in timestamp order. */ + private final NavigableSet<Pair<K, TimerData>> synchronizedProcessingTimers; + + /** Current input watermark. */ + private Instant inputWatermarkTime = BoundedWindow.TIMESTAMP_MIN_VALUE; + + /** Current output watermark. */ + @Nullable + private Instant outputWatermarkTime = null; + + /** Current processing time. */ + private Instant processingTime; + + /** Current synchronized processing time. */ + private Instant synchronizedProcessingTime; + + private final K key; + + public NemoTimerInternals(final K key, + final NavigableSet<Pair<K, TimerData>> watermarkTimers, + final NavigableSet<Pair<K, TimerData>> processingTimers, + final NavigableSet<Pair<K, TimerData>> synchronizedProcessingTimers) { + this.key = key; + this.watermarkTimers = watermarkTimers; + this.processingTimers = processingTimers; + this.synchronizedProcessingTimers = synchronizedProcessingTimers; + this.existingTimers = HashBasedTable.create(); + this.processingTime = Instant.now(); + this.synchronizedProcessingTime = Instant.now(); + } + + public NemoTimerInternals(final K key, + final NavigableSet<Pair<K, TimerData>> watermarkTimers, + final NavigableSet<Pair<K, TimerData>> processingTimers, + final NavigableSet<Pair<K, TimerData>> synchronizedProcessingTimers, + final Table<StateNamespace, String, TimerData> existingTimers, + final Instant inputWatermarkTime, + final Instant processingTime, + final Instant synchronizedProcessingTime, + final Instant outputWatermarkTime) { + this.key = key; + this.watermarkTimers = watermarkTimers; + this.processingTimers = processingTimers; + this.synchronizedProcessingTimers = synchronizedProcessingTimers; + this.existingTimers = existingTimers; + this.inputWatermarkTime = inputWatermarkTime; + this.processingTime = processingTime; + this.synchronizedProcessingTime = synchronizedProcessingTime; + this.outputWatermarkTime = outputWatermarkTime; + } + + /** Check if any timer exists. */ + public boolean isEmpty() { + return existingTimers.isEmpty(); + } + + /** returns current output watermark. */ + @Override + @Nullable + public Instant currentOutputWatermarkTime() { + return outputWatermarkTime; + } + + /* Review comment: please remove the commented-out code ---------------------------------------------------------------- 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]
