@Test public void setRole() { mgr.setRole(NID_OTHER, DEV_MASTER, MASTER); assertEquals("wrong local role:", NONE, mgr.getLocalRole(DEV_MASTER)); assertEquals("wrong obtained role:", STANDBY, Futures.getUnchecked(mgr.requestRoleFor(DEV_MASTER))); mgr.setRole(NID_LOCAL, DEV_MASTER, MASTER); assertEquals("wrong local role:", MASTER, mgr.getLocalRole(DEV_MASTER)); }
@Override public CompletableFuture<Void> setRole(NodeId nodeId, DeviceId deviceId, MastershipRole role) { checkNotNull(nodeId, NODE_ID_NULL); checkNotNull(deviceId, DEVICE_ID_NULL); checkNotNull(role, ROLE_NULL); CompletableFuture<MastershipEvent> eventFuture = null; switch (role) { case MASTER: eventFuture = store.setMaster(nodeId, deviceId); break; case STANDBY: eventFuture = store.setStandby(nodeId, deviceId); break; case NONE: eventFuture = store.relinquishRole(nodeId, deviceId); break; default: log.info("Unknown role; ignoring"); return CompletableFuture.completedFuture(null); } return eventFuture.thenAccept(this::post) .thenApply(v -> null); }
MastershipManager extends AbstractListenerManager<MastershipEvent, MastershipListener> implements MastershipService, MastershipAdminService, MastershipTermService,
               MetricsHelper { @Override public CompletableFuture<Void> setRole(NodeId nodeId, DeviceId deviceId, MastershipRole role) { checkNotNull(nodeId, NODE_ID_NULL); checkNotNull(deviceId, DEVICE_ID_NULL); checkNotNull(role, ROLE_NULL); CompletableFuture<MastershipEvent> eventFuture = null; switch (role) { case MASTER: eventFuture = store.setMaster(nodeId, deviceId); break; case STANDBY: eventFuture = store.setStandby(nodeId, deviceId); break; case NONE: eventFuture = store.relinquishRole(nodeId, deviceId); break; default: log.info("Unknown role; ignoring"); return CompletableFuture.completedFuture(null); } return eventFuture.thenAccept(this::post) .thenApply(v -> null); } }
MastershipManager extends AbstractListenerManager<MastershipEvent, MastershipListener> implements MastershipService, MastershipAdminService, MastershipTermService,
               MetricsHelper { @Override public CompletableFuture<Void> setRole(NodeId nodeId, DeviceId deviceId, MastershipRole role) { checkNotNull(nodeId, NODE_ID_NULL); checkNotNull(deviceId, DEVICE_ID_NULL); checkNotNull(role, ROLE_NULL); CompletableFuture<MastershipEvent> eventFuture = null; switch (role) { case MASTER: eventFuture = store.setMaster(nodeId, deviceId); break; case STANDBY: eventFuture = store.setStandby(nodeId, deviceId); break; case NONE: eventFuture = store.relinquishRole(nodeId, deviceId); break; default: log.info("Unknown role; ignoring"); return CompletableFuture.completedFuture(null); } return eventFuture.thenAccept(this::post) .thenApply(v -> null); }  }
MastershipManager extends AbstractListenerManager<MastershipEvent, MastershipListener> implements MastershipService, MastershipAdminService, MastershipTermService,
               MetricsHelper { @Override public CompletableFuture<Void> setRole(NodeId nodeId, DeviceId deviceId, MastershipRole role) { checkNotNull(nodeId, NODE_ID_NULL); checkNotNull(deviceId, DEVICE_ID_NULL); checkNotNull(role, ROLE_NULL); CompletableFuture<MastershipEvent> eventFuture = null; switch (role) { case MASTER: eventFuture = store.setMaster(nodeId, deviceId); break; case STANDBY: eventFuture = store.setStandby(nodeId, deviceId); break; case NONE: eventFuture = store.relinquishRole(nodeId, deviceId); break; default: log.info("Unknown role; ignoring"); return CompletableFuture.completedFuture(null); } return eventFuture.thenAccept(this::post) .thenApply(v -> null); }  @Activate void activate(); @Deactivate void deactivate(); @Override CompletableFuture<Void> setRole(NodeId nodeId, DeviceId deviceId, MastershipRole role); @Override MastershipRole getLocalRole(DeviceId deviceId); @Override CompletableFuture<Void> relinquishMastership(DeviceId deviceId); @Override CompletableFuture<MastershipRole> requestRoleFor(DeviceId deviceId); @Override NodeId getMasterFor(DeviceId deviceId); @Override Set<DeviceId> getDevicesOf(NodeId nodeId); @Override RoleInfo getNodesFor(DeviceId deviceId); @Override MastershipTerm getMastershipTerm(DeviceId deviceId); @Override MetricsService metricsService(); @Override void balanceRoles(); }
MastershipManager extends AbstractListenerManager<MastershipEvent, MastershipListener> implements MastershipService, MastershipAdminService, MastershipTermService,
               MetricsHelper { @Override public CompletableFuture<Void> setRole(NodeId nodeId, DeviceId deviceId, MastershipRole role) { checkNotNull(nodeId, NODE_ID_NULL); checkNotNull(deviceId, DEVICE_ID_NULL); checkNotNull(role, ROLE_NULL); CompletableFuture<MastershipEvent> eventFuture = null; switch (role) { case MASTER: eventFuture = store.setMaster(nodeId, deviceId); break; case STANDBY: eventFuture = store.setStandby(nodeId, deviceId); break; case NONE: eventFuture = store.relinquishRole(nodeId, deviceId); break; default: log.info("Unknown role; ignoring"); return CompletableFuture.completedFuture(null); } return eventFuture.thenAccept(this::post) .thenApply(v -> null); }  @Activate void activate(); @Deactivate void deactivate(); @Override CompletableFuture<Void> setRole(NodeId nodeId, DeviceId deviceId, MastershipRole role); @Override MastershipRole getLocalRole(DeviceId deviceId); @Override CompletableFuture<Void> relinquishMastership(DeviceId deviceId); @Override CompletableFuture<MastershipRole> requestRoleFor(DeviceId deviceId); @Override NodeId getMasterFor(DeviceId deviceId); @Override Set<DeviceId> getDevicesOf(NodeId nodeId); @Override RoleInfo getNodesFor(DeviceId deviceId); @Override MastershipTerm getMastershipTerm(DeviceId deviceId); @Override MetricsService metricsService(); @Override void balanceRoles(); public boolean useRegionForBalanceRoles; }