blob: e70cc1f511f9095aa4b1e44b1c6d8168697cb675 [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 */
16package org.onlab.onos.cluster;
17
18/**
Madan Jampani1d3494e2014-11-20 11:24:22 -080019 * Service for leader election.
Madan Jampani1ee91782014-11-20 20:24:24 -080020 * Leadership contests are organized around topics. A instance can join the
21 * leadership race for a topic or withdraw from a race it has previously joined.
22 * Listeners can be added to receive notifications asynchronously for various
23 * leadership contests.
Pavlin Radoslavova6b754c2014-11-18 13:55:37 -080024 */
25public interface LeadershipService {
26
27 /**
Madan Jampani1ee91782014-11-20 20:24:24 -080028 * Gets the most recent leader for the topic.
29 * @param path topic
30 * @return node who is the leader, null if so such topic exists.
31 */
32 ControllerNode getLeader(String path);
33
34 /**
Madan Jampani1d3494e2014-11-20 11:24:22 -080035 * Joins the leadership contest.
36 * @param path topic for which this controller node wishes to be a leader.
Pavlin Radoslavova6b754c2014-11-18 13:55:37 -080037 */
Madan Jampani1d3494e2014-11-20 11:24:22 -080038 void runForLeadership(String path);
Pavlin Radoslavova6b754c2014-11-18 13:55:37 -080039
40 /**
Madan Jampani1d3494e2014-11-20 11:24:22 -080041 * Withdraws from a leadership contest.
42 * @param path topic for which this controller node no longer wishes to be a leader.
43 */
44 void withdraw(String path);
45
46 /**
47 * Registers a event listener to be notified of leadership events.
48 * @param listener listener that will asynchronously notified of leadership events.
Pavlin Radoslavova6b754c2014-11-18 13:55:37 -080049 */
50 void addListener(LeadershipEventListener listener);
51
52 /**
Madan Jampani1d3494e2014-11-20 11:24:22 -080053 * Unregisters a event listener for leadership events.
54 * @param listener listener to be removed.
Pavlin Radoslavova6b754c2014-11-18 13:55:37 -080055 */
56 void removeListener(LeadershipEventListener listener);
Madan Jampani1d3494e2014-11-20 11:24:22 -080057}