blob: 75cf90f2ccbc1b3aebd4c171aa5567a05f11b40d [file] [log] [blame]
Pavlin Radoslavova6b754c2014-11-18 13:55:37 -08001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.cluster;
Pavlin Radoslavova6b754c2014-11-18 13:55:37 -080017
Yuta HIGUCHIc2bf3d82014-11-28 18:50:41 -080018import java.util.Map;
19
Pavlin Radoslavova6b754c2014-11-18 13:55:37 -080020/**
Madan Jampani1d3494e2014-11-20 11:24:22 -080021 * Service for leader election.
Madan Jampani1ee91782014-11-20 20:24:24 -080022 * Leadership contests are organized around topics. A instance can join the
23 * leadership race for a topic or withdraw from a race it has previously joined.
24 * Listeners can be added to receive notifications asynchronously for various
25 * leadership contests.
Pavlin Radoslavova6b754c2014-11-18 13:55:37 -080026 */
27public interface LeadershipService {
28
29 /**
Madan Jampani1ee91782014-11-20 20:24:24 -080030 * Gets the most recent leader for the topic.
31 * @param path topic
Madan Jampani8d21c792014-12-01 16:31:07 -080032 * @return nodeId of the leader, null if so such topic exists.
Madan Jampani1ee91782014-11-20 20:24:24 -080033 */
Madan Jampani8d21c792014-12-01 16:31:07 -080034 NodeId getLeader(String path);
Madan Jampani1ee91782014-11-20 20:24:24 -080035
36 /**
Madan Jampani1d3494e2014-11-20 11:24:22 -080037 * Joins the leadership contest.
38 * @param path topic for which this controller node wishes to be a leader.
Pavlin Radoslavova6b754c2014-11-18 13:55:37 -080039 */
Madan Jampani1d3494e2014-11-20 11:24:22 -080040 void runForLeadership(String path);
Pavlin Radoslavova6b754c2014-11-18 13:55:37 -080041
42 /**
Madan Jampani1d3494e2014-11-20 11:24:22 -080043 * Withdraws from a leadership contest.
44 * @param path topic for which this controller node no longer wishes to be a leader.
45 */
46 void withdraw(String path);
47
Yuta HIGUCHIc2bf3d82014-11-28 18:50:41 -080048 Map<String, Leadership> getLeaderBoard();
49
Madan Jampani1d3494e2014-11-20 11:24:22 -080050 /**
51 * Registers a event listener to be notified of leadership events.
52 * @param listener listener that will asynchronously notified of leadership events.
Pavlin Radoslavova6b754c2014-11-18 13:55:37 -080053 */
54 void addListener(LeadershipEventListener listener);
55
56 /**
Madan Jampani1d3494e2014-11-20 11:24:22 -080057 * Unregisters a event listener for leadership events.
58 * @param listener listener to be removed.
Pavlin Radoslavova6b754c2014-11-18 13:55:37 -080059 */
60 void removeListener(LeadershipEventListener listener);
Brian O'Connorabafb502014-12-02 22:26:20 -080061}