ajothomas commented on code in PR #1605: URL: https://github.com/apache/samza/pull/1605#discussion_r876389555
########## samza-core/src/main/java/org/apache/samza/drain/SinglePollDrainMonitor.java: ########## @@ -0,0 +1,103 @@ +/* + * 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.drain; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; +import java.util.List; +import java.util.Optional; +import org.apache.samza.config.ApplicationConfig; +import org.apache.samza.config.Config; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * {@link DrainMonitor} implementation which polls the {@link DrainManager} for {@link DrainNotification} exactly one + * time. + * + * One time poll is triggered by calling {@link #start()}. The poll and callback invocation happens on the caller's + * thread. + * + * This is intended to be used by SamzaContainer to check if the container should be set in drain mode prior to starting + * the registered consumers. This particularly applies for cases where the container did not complete the previous drain + * request and should immediately drain upon restart without consuming any new messages. + * + * {@link DrainMonitor.Callback} should be registered prior to calling {@link #start()}. + * Callback's {@link Callback#onDrain()} method is called by the monitor when DrainNotification matching the current + * deployment id is encountered. + * */ +public class SinglePollDrainMonitor implements DrainMonitor { Review Comment: The idea was to provide a clean interface with methods- start()- to start the monitoring on container start and stop() on container shutdown(). PollingDrainMonitor checks for drain periodically on a separate executor while SinglePollMonitor will check for drain once on the calling thread. This seemed cleaner and easier to reason about. We could surely merge them into one having the following methods - oneTimePoll(), startContinuousPoll(), stopContinuousPoll() which would make the code less verbose. -- 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. To unsubscribe, e-mail: commits-unsubscr...@samza.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org