Add a set of synchronous version of methods for MastershipService
Change-Id: I61da650eb545c14b5fa824ac92d1ebe62126dec3
diff --git a/core/api/src/main/java/org/onosproject/mastership/MastershipAdminService.java b/core/api/src/main/java/org/onosproject/mastership/MastershipAdminService.java
index 4d21233..091cf8e 100644
--- a/core/api/src/main/java/org/onosproject/mastership/MastershipAdminService.java
+++ b/core/api/src/main/java/org/onosproject/mastership/MastershipAdminService.java
@@ -16,7 +16,9 @@
package org.onosproject.mastership;
import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
+import org.onlab.util.Tools;
import org.onosproject.cluster.NodeId;
import org.onosproject.net.DeviceId;
import org.onosproject.net.MastershipRole;
@@ -26,6 +28,8 @@
*/
public interface MastershipAdminService {
+ long TIMEOUT_MILLIS = 3000;
+
/**
* Applies the current mastership role for the specified device.
*
@@ -37,6 +41,18 @@
CompletableFuture<Void> setRole(NodeId instance, DeviceId deviceId, MastershipRole role);
/**
+ * Synchronous version of setRole.
+ * Applies the current mastership role for the specified device.
+ *
+ * @param instance controller instance identifier
+ * @param deviceId device identifier
+ * @param role requested role
+ */
+ default void setRoleSync(NodeId instance, DeviceId deviceId, MastershipRole role) {
+ Tools.futureGetOrElse(setRole(instance, deviceId, role), TIMEOUT_MILLIS, TimeUnit.MILLISECONDS, null);
+ }
+
+ /**
* Balances the mastership to be shared as evenly as possibly by all
* online instances.
*/