alshabib

Merge branch 'master' of ssh://gerrit.onlab.us:29418/onos-next

1 +package org.onlab.onos.cluster;
2 +
3 +import org.onlab.onos.event.AbstractEvent;
4 +import org.onlab.onos.net.DeviceId;
5 +
6 +/**
7 + * Describes infrastructure device event.
8 + */
9 +public class MastershipEvent extends AbstractEvent<MastershipEvent.Type, DeviceId> {
10 +
11 + InstanceId master;
12 +
13 + /**
14 + * Type of mastership events.
15 + */
16 + public enum Type {
17 + /**
18 + * Signifies that the master for a device has changed.
19 + */
20 + MASTER_CHANGED
21 + }
22 +
23 + /**
24 + * Creates an event of a given type and for the specified device, master,
25 + * and the current time.
26 + *
27 + * @param type device event type
28 + * @param device event device subject
29 + * @param master master ID subject
30 + */
31 + protected MastershipEvent(Type type, DeviceId device, InstanceId master) {
32 + super(type, device);
33 + this.master = master;
34 + }
35 +
36 + /**
37 + * Creates an event of a given type and for the specified device, master,
38 + * and time.
39 + *
40 + * @param type mastership event type
41 + * @param device event device subject
42 + * @param master master ID subject
43 + * @param time occurrence time
44 + */
45 + protected MastershipEvent(Type type, DeviceId device, InstanceId master, long time) {
46 + super(type, device, time);
47 + this.master = master;
48 + }
49 +
50 + /**
51 + * Returns the current master's ID as a subject.
52 + *
53 + * @return master ID subject
54 + */
55 + public InstanceId master() {
56 + return master;
57 + }
58 +}
1 +package org.onlab.onos.cluster;
2 +
3 +import org.onlab.onos.event.EventListener;
4 +
5 +/**
6 + * Entity capable of receiving device mastership-related events.
7 + */
8 +public interface MastershipListener extends EventListener<MastershipEvent>{
9 +
10 +}
1 package org.onlab.onos.cluster; 1 package org.onlab.onos.cluster;
2 2
3 +import java.util.Set;
4 +
5 +import org.onlab.onos.net.DeviceId;
6 +import org.onlab.onos.net.MastershipRole;
7 +
3 /** 8 /**
4 * Service responsible for determining the controller instance mastership of 9 * Service responsible for determining the controller instance mastership of
5 * a device in a clustered environment. This is the central authority for 10 * a device in a clustered environment. This is the central authority for
...@@ -8,12 +13,42 @@ package org.onlab.onos.cluster; ...@@ -8,12 +13,42 @@ package org.onlab.onos.cluster;
8 */ 13 */
9 public interface MastershipService { 14 public interface MastershipService {
10 15
11 - // InstanceId getMasterFor(DeviceId deviceId) 16 + /**
12 - // Set<DeviceId> getDevicesOf(InstanceId instanceId); 17 + * Returns the current master for a given device.
18 + *
19 + * @param deviceId the identifier of the device
20 + * @return the ID of the master controller for the device
21 + */
22 + InstanceId getMasterFor(DeviceId deviceId);
23 +
24 + /**
25 + * Returns the devices for which a controller is master.
26 + *
27 + * @param instanceId the ID of the controller
28 + * @return a set of device IDs
29 + */
30 + Set<DeviceId> getDevicesOf(InstanceId instanceId);
31 +
32 + /**
33 + * Returns the mastership status of this controller for a given device.
34 + *
35 + * @param deviceId the the identifier of the device
36 + * @return the role of this controller instance
37 + */
38 + MastershipRole requestRoleFor(DeviceId deviceId);
13 39
14 - // MastershipRole requestRoleFor(DeviceId deviceId); 40 + /**
41 + * Adds the specified mastership listener.
42 + *
43 + * @param listener the mastership listener
44 + */
45 + void addListener(MastershipListener listener);
15 46
16 - // addListener/removeLister(MastershipListener listener); 47 + /**
17 - // types of events would be MASTER_CHANGED (subject ==> deviceId; master ==> instanceId) 48 + * Removes the specified device listener.
49 + *
50 + * @param listener the mastership listener
51 + */
52 + void removeListemer(MastershipListener listener);
18 53
19 } 54 }
......