mirror of
https://github.com/CivMC/Civ.git
synced 2026-07-18 00:20:44 +00:00
Merge pull request #41 from okx-code/fix-culling
Fix dormant snitches still being active & snitches not changing state over restarts
This commit is contained in:
@@ -213,6 +213,14 @@ public class Snitch extends LocationTrackable {
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a boolean representing whether the snitch is currently active (e.g., recording snitch hits)
|
||||
* Currently used to synchronise the state in DormantCullingAppender with the real activity of the snitch.
|
||||
*/
|
||||
public boolean getActiveStatus() {
|
||||
return this.active;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces all appenders of this snitch to persist their current state
|
||||
*/
|
||||
|
||||
@@ -100,15 +100,11 @@ public class DormantCullingAppender
|
||||
this.nextUpdate = update;
|
||||
}
|
||||
|
||||
private long calcFutureUpdate() {
|
||||
switch (getActivityStatus()) {
|
||||
case CULLED:
|
||||
return Long.MAX_VALUE;
|
||||
case DORMANT:
|
||||
return getLastRefresh() + this.config.getTotalLifeTime();
|
||||
default:
|
||||
case ACTIVE:
|
||||
return getLastRefresh() + this.config.getLifetime();
|
||||
private void syncNextUpdate() {
|
||||
switch (this.databaseKnownStatus) {
|
||||
case CULLED -> cullSnitch();
|
||||
case DORMANT -> deactivateSnitch();
|
||||
default -> updateInternalProgressTime(getLastRefresh() + this.config.getLifetime());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,9 +116,8 @@ public class DormantCullingAppender
|
||||
updateLastRefresh();
|
||||
}
|
||||
this.databaseKnownStatus = getActivityStatus();
|
||||
updateInternalProgressTime(calcFutureUpdate());
|
||||
syncNextUpdate();
|
||||
JukeAlert.getInstance().getSnitchCullManager().addCulling(this);
|
||||
updateState();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@@ -185,27 +180,38 @@ public class DormantCullingAppender
|
||||
final ActivityStatus currentStatus = getActivityStatus();
|
||||
// Culled
|
||||
if (currentStatus == ActivityStatus.CULLED && this.databaseKnownStatus != ActivityStatus.CULLED) {
|
||||
this.databaseKnownStatus = ActivityStatus.CULLED;
|
||||
getSnitch().destroy(null, Cause.CULL);
|
||||
updateInternalProgressTime(Long.MAX_VALUE);
|
||||
LOGGER.info("Culling snitch [" + getSnitch() + "] for exceeding life timer");
|
||||
cullSnitch();
|
||||
}
|
||||
// Dormant
|
||||
else if (currentStatus == ActivityStatus.DORMANT && this.databaseKnownStatus != ActivityStatus.DORMANT) {
|
||||
this.databaseKnownStatus = ActivityStatus.DORMANT;
|
||||
updateInternalProgressTime(System.currentTimeMillis() + this.config.getDormantLifeTime());
|
||||
getSnitch().setActiveStatus(false);
|
||||
LOGGER.info("Deactivating snitch [" + getSnitch() + "] for exceeding dormant timer");
|
||||
deactivateSnitch();
|
||||
}
|
||||
// Active
|
||||
else if (this.databaseKnownStatus != ActivityStatus.ACTIVE) {
|
||||
else if (currentStatus == ActivityStatus.ACTIVE && this.databaseKnownStatus != ActivityStatus.ACTIVE) {
|
||||
this.databaseKnownStatus = ActivityStatus.ACTIVE;
|
||||
getSnitch().setActiveStatus(true);
|
||||
JukeAlert.getInstance().getSnitchCullManager().updateCulling(this, calcFutureUpdate());
|
||||
syncNextUpdate();
|
||||
JukeAlert.getInstance().getSnitchCullManager().updateCulling(this, this.getNextUpdate());
|
||||
LOGGER.info("Re-activating snitch [" + getSnitch() + "]");
|
||||
}
|
||||
}
|
||||
|
||||
private void cullSnitch() {
|
||||
this.databaseKnownStatus = ActivityStatus.CULLED;
|
||||
getSnitch().destroy(null, Cause.CULL);
|
||||
updateInternalProgressTime(Long.MAX_VALUE);
|
||||
LOGGER.info("Culling snitch [" + getSnitch() + "] for exceeding life timer");
|
||||
}
|
||||
|
||||
private void deactivateSnitch() {
|
||||
updateInternalProgressTime(getLastRefresh() + this.config.getTotalLifeTime());
|
||||
this.databaseKnownStatus = ActivityStatus.DORMANT;
|
||||
if (getSnitch().getActiveStatus()) {
|
||||
getSnitch().setActiveStatus(false);
|
||||
LOGGER.info("Deactivating snitch [" + getSnitch() + "] for exceeding dormant timer");
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public Class<DormantCullingConfig> getConfigClass() {
|
||||
|
||||
Reference in New Issue
Block a user