Pavlin Radoslavov | a6b754c | 2014-11-18 13:55:37 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onlab.onos.cluster; |
| 17 | |
| 18 | /** |
Madan Jampani | 1d3494e | 2014-11-20 11:24:22 -0800 | [diff] [blame] | 19 | * Service for leader election. |
Madan Jampani | 1ee9178 | 2014-11-20 20:24:24 -0800 | [diff] [blame] | 20 | * 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 Radoslavov | a6b754c | 2014-11-18 13:55:37 -0800 | [diff] [blame] | 24 | */ |
| 25 | public interface LeadershipService { |
| 26 | |
| 27 | /** |
Madan Jampani | 1ee9178 | 2014-11-20 20:24:24 -0800 | [diff] [blame] | 28 | * 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 Jampani | 1d3494e | 2014-11-20 11:24:22 -0800 | [diff] [blame] | 35 | * Joins the leadership contest. |
| 36 | * @param path topic for which this controller node wishes to be a leader. |
Pavlin Radoslavov | a6b754c | 2014-11-18 13:55:37 -0800 | [diff] [blame] | 37 | */ |
Madan Jampani | 1d3494e | 2014-11-20 11:24:22 -0800 | [diff] [blame] | 38 | void runForLeadership(String path); |
Pavlin Radoslavov | a6b754c | 2014-11-18 13:55:37 -0800 | [diff] [blame] | 39 | |
| 40 | /** |
Madan Jampani | 1d3494e | 2014-11-20 11:24:22 -0800 | [diff] [blame] | 41 | * 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 Radoslavov | a6b754c | 2014-11-18 13:55:37 -0800 | [diff] [blame] | 49 | */ |
| 50 | void addListener(LeadershipEventListener listener); |
| 51 | |
| 52 | /** |
Madan Jampani | 1d3494e | 2014-11-20 11:24:22 -0800 | [diff] [blame] | 53 | * Unregisters a event listener for leadership events. |
| 54 | * @param listener listener to be removed. |
Pavlin Radoslavov | a6b754c | 2014-11-18 13:55:37 -0800 | [diff] [blame] | 55 | */ |
| 56 | void removeListener(LeadershipEventListener listener); |
Madan Jampani | 1d3494e | 2014-11-20 11:24:22 -0800 | [diff] [blame] | 57 | } |