@Override public Map<String, T> getServices() { Map<String, T> snapshotMap = Maps.newLinkedHashMap(); for (Map.Entry<String, Optional<LeaderService>> entry : _leaderMap.asMap().entrySet()) { String name = entry.getKey(); Optional<LeaderService> ref = entry.getValue(); if (!ref.isPresent()) { continue; } Optional<Service> service = ref.get().getCurrentDelegateService(); if (!service.isPresent()) { continue; } //noinspection unchecked snapshotMap.put(name, (T) service.get()); } return snapshotMap; }
@Override public Map<String, T> getServices() { Map<String, T> snapshotMap = Maps.newLinkedHashMap(); for (Map.Entry<String, Optional<LeaderService>> entry : _leaderMap.asMap().entrySet()) { String name = entry.getKey(); Optional<LeaderService> ref = entry.getValue(); if (!ref.isPresent()) { continue; } Optional<Service> service = ref.get().getCurrentDelegateService(); if (!service.isPresent()) { continue; } //noinspection unchecked snapshotMap.put(name, (T) service.get()); } return snapshotMap; }
boolean relinquishLeadership() { if (hasLeadership()) { // Release leadership by stopping the delegate service, but do not stop the leadership service itself Service delegateService = _leaderService.getCurrentDelegateService().orNull(); if (delegateService != null) { _log.info("Relinquishing leadership of partition {} for {}", _partition, _serviceName); delegateService.stopAsync(); } return true; } else { return false; } }
boolean relinquishLeadership() { if (hasLeadership()) { // Release leadership by stopping the delegate service, but do not stop the leadership service itself Service delegateService = _leaderService.getCurrentDelegateService().orNull(); if (delegateService != null) { _log.info("Relinquishing leadership of partition {} for {}", _partition, _serviceName); delegateService.stopAsync(); } return true; } else { return false; } }
boolean hasLeadership() { if (!_leaderService.isRunning() || !_leaderService.hasLeadership()) { return false; } // It's possible we technically have leadership but are in the process of giving it up because we already // are leading the maximum number of partitions. Verify that this isn't a rejected service. Service delegateService = _leaderService.getCurrentDelegateService().orNull(); return delegateService == null || !(delegateService instanceof RelinquishService); }
boolean hasLeadership() { if (!_leaderService.isRunning() || !_leaderService.hasLeadership()) { return false; } // It's possible we technically have leadership but are in the process of giving it up because we already // are leading the maximum number of partitions. Verify that this isn't a rejected service. Service delegateService = _leaderService.getCurrentDelegateService().orNull(); return delegateService == null || !(delegateService instanceof RelinquishService); }
Optional<Service> opt = leaderService.getCurrentDelegateService(); if (opt.isPresent()) { service = opt.get();
Optional<Service> opt = leaderService.getCurrentDelegateService(); if (opt.isPresent()) { service = opt.get();
Service actualService = leaderService.getCurrentDelegateService().orNull(); if (actualService == null || !actualService.isRunning()) { out.printf("Process is not currently elected leader: %s%n", name);
Service actualService = leaderService.getCurrentDelegateService().orNull(); if (actualService == null || !actualService.isRunning()) { out.printf("Process is not currently elected leader: %s%n", name);