Added API for the (new) Leadership Service. For now there is a single
Leader elected for all purposes. In the future the leader could be per topic. Change-Id: I6d4f997b40bfdaa6fa9a5547e7641bf62c9d3ddb
Showing
3 changed files
with
126 additions
and
0 deletions
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 | +import org.onlab.onos.event.AbstractEvent; | ||
19 | + | ||
20 | +/** | ||
21 | + * Describes leadership-related event. | ||
22 | + */ | ||
23 | +public class LeadershipEvent extends AbstractEvent<LeadershipEvent.Type, ControllerNode> { | ||
24 | + | ||
25 | + /** | ||
26 | + * Type of leadership-related events. | ||
27 | + */ | ||
28 | + public enum Type { | ||
29 | + /** | ||
30 | + * Signifies that the leader has changed. The event subject is the | ||
31 | + * new leader. | ||
32 | + */ | ||
33 | + LEADER_CHANGED | ||
34 | + } | ||
35 | + | ||
36 | + /** | ||
37 | + * Creates an event of a given type and for the specified instance and the | ||
38 | + * current time. | ||
39 | + * | ||
40 | + * @param type leadership event type | ||
41 | + * @param instance cluster device subject | ||
42 | + */ | ||
43 | + public LeadershipEvent(Type type, ControllerNode instance) { | ||
44 | + super(type, instance); | ||
45 | + } | ||
46 | + | ||
47 | + /** | ||
48 | + * Creates an event of a given type and for the specified device and time. | ||
49 | + * | ||
50 | + * @param type device event type | ||
51 | + * @param instance event device subject | ||
52 | + * @param time occurrence time | ||
53 | + */ | ||
54 | + public LeadershipEvent(Type type, ControllerNode instance, long time) { | ||
55 | + super(type, instance, time); | ||
56 | + } | ||
57 | + | ||
58 | +} |
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 | +import org.onlab.onos.event.EventListener; | ||
19 | + | ||
20 | +/** | ||
21 | + * Entity capable of receiving device leadership-related events. | ||
22 | + */ | ||
23 | +public interface LeadershipEventListener extends EventListener<LeadershipEvent> { | ||
24 | +} |
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 | +/** | ||
19 | + * Service for obtaining information about the leader election. | ||
20 | + */ | ||
21 | +public interface LeadershipService { | ||
22 | + | ||
23 | + /** | ||
24 | + * Returns the current leader controller node. | ||
25 | + * | ||
26 | + * @return current leader controller node | ||
27 | + */ | ||
28 | + ControllerNode getLeader(); | ||
29 | + | ||
30 | + /** | ||
31 | + * Adds the specified leadership event listener. | ||
32 | + * | ||
33 | + * @param listener the leadership listener | ||
34 | + */ | ||
35 | + void addListener(LeadershipEventListener listener); | ||
36 | + | ||
37 | + /** | ||
38 | + * Removes the specified leadership event listener. | ||
39 | + * | ||
40 | + * @param listener the leadership listener | ||
41 | + */ | ||
42 | + void removeListener(LeadershipEventListener listener); | ||
43 | + | ||
44 | +} |
-
Please register or login to post a comment