XComp commented on code in PR #22384:
URL: https://github.com/apache/flink/pull/22384#discussion_r1200710974


##########
flink-runtime/src/main/java/org/apache/flink/runtime/leaderelection/AbstractLeaderElectionService.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * 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.runtime.leaderelection;
+
+import org.apache.flink.util.Preconditions;
+
+import javax.annotation.Nullable;
+
+import java.util.UUID;
+
+/**
+ * {@code AbstractLeaderElectionService} provides a generic implementation of 
the {@link
+ * LeaderElection} handling.
+ */
+public abstract class AbstractLeaderElectionService implements 
LeaderElectionService {
+    @Override
+    public LeaderElection createLeaderElection() {
+        return new LeaderElectionImpl(this);
+    }
+
+    /**
+     * Registers the given {@link LeaderContender} with the underlying {@code
+     * LeaderElectionService}. Leadership changes are starting to be reported 
to the {@code
+     * LeaderContender}.
+     */
+    protected abstract void register(LeaderContender contender) throws 
Exception;
+
+    /** Confirms the leadership with the given session ID and address. */
+    protected abstract void confirmLeadership(UUID leaderSessionID, String 
leaderAddress);
+
+    /**
+     * Checks whether the {@code LeaderElectionService} has the leadership 
acquired for the given
+     * session ID.
+     *
+     * @return {@code true} if the service has leadership with the passed 
session ID acquired;
+     *     {@code false} otherwise.
+     */
+    protected abstract boolean hasLeadership(UUID leaderSessionId);
+
+    /** {@code LeaderElectionImpl} is the default implementation of {@link 
LeaderElection}. */
+    private static class LeaderElectionImpl implements LeaderElection {

Review Comment:
   The idea of having the `LeaderElectionImpl` being implemented as an inner 
class was to hide the `LeaderElection`-specific interface from other 
implementations. The `StandaloneLeaderElectionService` would require these 
methods to become package-private. The `EmbeddedLeaderElectionService` is not 
even in the same package. But I noticed that I could achieve the same with a 
normal class. This improves testability later on, I guess. I created 
`DefaultLeaderElectionTest` with quite basic test methods for now. I hope to 
gradually extend it in the next (future) PRs.



-- 
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: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to