blob: 65ec687a1aa1c7649d36d615231b27e33f43946c [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;
Madan Jampani59610512015-02-25 15:25:43 -080019import java.util.Set;
Yuta HIGUCHIc2bf3d82014-11-28 18:50:41 -080020
Pavlin Radoslavova6b754c2014-11-18 13:55:37 -080021/**
Madan Jampani1d3494e2014-11-20 11:24:22 -080022 * Service for leader election.
Madan Jampani1ee91782014-11-20 20:24:24 -080023 * Leadership contests are organized around topics. A instance can join the
24 * leadership race for a topic or withdraw from a race it has previously joined.
25 * Listeners can be added to receive notifications asynchronously for various
26 * leadership contests.
Pavlin Radoslavova6b754c2014-11-18 13:55:37 -080027 */
28public interface LeadershipService {
29
30 /**
Madan Jampani59610512015-02-25 15:25:43 -080031 * Returns the current leader for the topic.
Madan Jampani1ee91782014-11-20 20:24:24 -080032 * @param path topic
Madan Jampani8d21c792014-12-01 16:31:07 -080033 * @return nodeId of the leader, null if so such topic exists.
Madan Jampani1ee91782014-11-20 20:24:24 -080034 */
Madan Jampani8d21c792014-12-01 16:31:07 -080035 NodeId getLeader(String path);
Madan Jampani1ee91782014-11-20 20:24:24 -080036
37 /**
Madan Jampani59610512015-02-25 15:25:43 -080038 * Returns the current leadership info for the topic.
39 * @param path topic
40 * @return leadership info or null if so such topic exists.
41 */
42 Leadership getLeadership(String path);
43
44 /**
45 * Returns the set of topics owned by the specified node.
46 * @param nodeId node Id.
47 * @return set of topics for which this node is the current leader.
48 */
49 Set<String> ownedTopics(NodeId nodeId);
50
51 /**
Madan Jampani1d3494e2014-11-20 11:24:22 -080052 * Joins the leadership contest.
53 * @param path topic for which this controller node wishes to be a leader.
Pavlin Radoslavova6b754c2014-11-18 13:55:37 -080054 */
Madan Jampani1d3494e2014-11-20 11:24:22 -080055 void runForLeadership(String path);
Pavlin Radoslavova6b754c2014-11-18 13:55:37 -080056
57 /**
Madan Jampani1d3494e2014-11-20 11:24:22 -080058 * Withdraws from a leadership contest.
59 * @param path topic for which this controller node no longer wishes to be a leader.
60 */
61 void withdraw(String path);
62
Madan Jampani59610512015-02-25 15:25:43 -080063 /**
64 * Returns the current leader board.
65 * @return mapping from topic to leadership info.
66 */
Yuta HIGUCHIc2bf3d82014-11-28 18:50:41 -080067 Map<String, Leadership> getLeaderBoard();
68
Madan Jampani1d3494e2014-11-20 11:24:22 -080069 /**
70 * Registers a event listener to be notified of leadership events.
71 * @param listener listener that will asynchronously notified of leadership events.
Pavlin Radoslavova6b754c2014-11-18 13:55:37 -080072 */
73 void addListener(LeadershipEventListener listener);
74
75 /**
Madan Jampani1d3494e2014-11-20 11:24:22 -080076 * Unregisters a event listener for leadership events.
77 * @param listener listener to be removed.
Pavlin Radoslavova6b754c2014-11-18 13:55:37 -080078 */
79 void removeListener(LeadershipEventListener listener);
Brian O'Connorabafb502014-12-02 22:26:20 -080080}