Madan Jampani | 620f70d | 2016-01-30 22:22:47 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Madan Jampani | 620f70d | 2016-01-30 22:22:47 -0800 | [diff] [blame] | 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.onosproject.cluster; |
| 17 | |
| 18 | import java.util.Map; |
| 19 | import org.onosproject.store.Store; |
| 20 | |
| 21 | /** |
| 22 | * Store interface for managing {@link LeadershipService} state. |
| 23 | */ |
| 24 | public interface LeadershipStore extends Store<LeadershipEvent, LeadershipStoreDelegate> { |
| 25 | |
| 26 | /** |
Jon Hall | 7a8bfc6 | 2016-05-26 17:59:04 -0700 | [diff] [blame] | 27 | * Adds registration for the local instance to be part of the leadership contest for topic. |
Madan Jampani | 620f70d | 2016-01-30 22:22:47 -0800 | [diff] [blame] | 28 | * |
| 29 | * @param topic leadership topic |
| 30 | * @return Updated leadership after operation is completed |
| 31 | */ |
| 32 | Leadership addRegistration(String topic); |
| 33 | |
| 34 | /** |
| 35 | * Unregisters the local instance from leadership contest for topic. |
| 36 | * |
| 37 | * @param topic leadership topic |
| 38 | */ |
| 39 | void removeRegistration(String topic); |
| 40 | |
| 41 | /** |
| 42 | * Unregisters an instance from all leadership contests. |
| 43 | * |
| 44 | * @param nodeId node identifier |
| 45 | */ |
| 46 | void removeRegistration(NodeId nodeId); |
| 47 | |
| 48 | /** |
| 49 | * Updates state so that given node is leader for a topic. |
| 50 | * |
| 51 | * @param topic leadership topic |
| 52 | * @param toNodeId identifier of the desired leader |
| 53 | * @return {@code true} if the transfer succeeded; {@code false} otherwise. |
| 54 | * This method can return {@code false} if the node is not registered for the topic |
| 55 | */ |
| 56 | boolean moveLeadership(String topic, NodeId toNodeId); |
| 57 | |
| 58 | /** |
| 59 | * Attempts to make a node the top candidate. |
| 60 | * |
| 61 | * @param topic leadership topic |
| 62 | * @param nodeId node identifier |
| 63 | * @return {@code true} if the specified node is now the top candidate. |
| 64 | * This method will return {@code false} if the node is not registered for the topic |
| 65 | */ |
| 66 | boolean makeTopCandidate(String topic, NodeId nodeId); |
| 67 | |
| 68 | /** |
| 69 | * Returns the current leadership for topic. |
| 70 | * |
| 71 | * @param topic leadership topic |
| 72 | * @return current leadership |
| 73 | */ |
| 74 | Leadership getLeadership(String topic); |
| 75 | |
| 76 | /** |
| 77 | * Return current leadership for all topics. |
| 78 | * |
| 79 | * @return topic to leadership mapping |
| 80 | */ |
| 81 | Map<String, Leadership> getLeaderships(); |
| 82 | } |