Fabric leader clean up 5 (#1646)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2019 the original author or authors.
|
||||
* Copyright 2013-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -35,11 +35,11 @@ public class Leader {
|
||||
}
|
||||
|
||||
public String getRole() {
|
||||
return this.role;
|
||||
return role;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return this.id;
|
||||
return id;
|
||||
}
|
||||
|
||||
public boolean isCandidate(Candidate candidate) {
|
||||
@@ -62,17 +62,17 @@ public class Leader {
|
||||
|
||||
Leader leader = (Leader) o;
|
||||
|
||||
return Objects.equals(this.role, leader.role) && Objects.equals(this.id, leader.id);
|
||||
return Objects.equals(role, leader.role) && Objects.equals(id, leader.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.role, this.id);
|
||||
return Objects.hash(role, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("Leader{role='%s', id='%s'}", this.role, this.id);
|
||||
return String.format("Leader{role='%s', id='%s'}", role, id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2019 the original author or authors.
|
||||
* Copyright 2013-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -35,12 +35,17 @@ public class LeaderContext implements Context {
|
||||
|
||||
@Override
|
||||
public boolean isLeader() {
|
||||
return this.leadershipController.getLocalLeader().filter(l -> l.isCandidate(this.candidate)).isPresent();
|
||||
return leadershipController.getLocalLeader().filter(l -> l.isCandidate(candidate)).isPresent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void yield() {
|
||||
this.leadershipController.revoke();
|
||||
leadershipController.revoke();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRole() {
|
||||
return candidate.getRole();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2019 the original author or authors.
|
||||
* Copyright 2013-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,17 +20,15 @@ import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.context.SmartLifecycle;
|
||||
import org.springframework.core.log.LogAccessor;
|
||||
|
||||
/**
|
||||
* @author Gytis Trikleris
|
||||
*/
|
||||
public class LeaderInitiator implements SmartLifecycle {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(LeaderInitiator.class);
|
||||
private static final LogAccessor LOGGER = new LogAccessor(LeaderInitiator.class);
|
||||
|
||||
private final LeaderProperties leaderProperties;
|
||||
|
||||
@@ -54,33 +52,33 @@ public class LeaderInitiator implements SmartLifecycle {
|
||||
|
||||
@Override
|
||||
public boolean isAutoStartup() {
|
||||
return this.leaderProperties.isAutoStartup();
|
||||
return leaderProperties.isAutoStartup();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
if (!isRunning()) {
|
||||
LOGGER.debug("Leader initiator starting");
|
||||
this.leaderRecordWatcher.start();
|
||||
this.hostPodWatcher.start();
|
||||
this.scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
|
||||
this.scheduledExecutorService.scheduleAtFixedRate(this.leadershipController::update,
|
||||
this.leaderProperties.getUpdatePeriod().toMillis(),
|
||||
this.leaderProperties.getUpdatePeriod().toMillis(), TimeUnit.MILLISECONDS);
|
||||
this.isRunning = true;
|
||||
LOGGER.debug(() -> "Leader initiator starting");
|
||||
leaderRecordWatcher.start();
|
||||
hostPodWatcher.start();
|
||||
scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
|
||||
scheduledExecutorService.scheduleAtFixedRate(leadershipController::update,
|
||||
leaderProperties.getUpdatePeriod().toMillis(),
|
||||
leaderProperties.getUpdatePeriod().toMillis(), TimeUnit.MILLISECONDS);
|
||||
isRunning = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
if (isRunning()) {
|
||||
LOGGER.debug("Leader initiator stopping");
|
||||
this.scheduledExecutorService.shutdown();
|
||||
this.scheduledExecutorService = null;
|
||||
this.hostPodWatcher.stop();
|
||||
this.leaderRecordWatcher.stop();
|
||||
this.leadershipController.revoke();
|
||||
this.isRunning = false;
|
||||
LOGGER.debug(() -> "Leader initiator stopping");
|
||||
scheduledExecutorService.shutdown();
|
||||
scheduledExecutorService = null;
|
||||
hostPodWatcher.stop();
|
||||
leaderRecordWatcher.stop();
|
||||
leadershipController.revoke();
|
||||
isRunning = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +90,7 @@ public class LeaderInitiator implements SmartLifecycle {
|
||||
|
||||
@Override
|
||||
public boolean isRunning() {
|
||||
return this.isRunning;
|
||||
return isRunning;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -53,7 +53,6 @@ public final class LeaderUtils {
|
||||
finally {
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user