mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-10 02:17:41 +01:00
Disable DataExtension data updates during plugin shutdown.
The storage of this data during shutdown is skipped already, but method calls to other potentially disabled plugins can throw errors. Affects issues: - Fixed #2432
This commit is contained in:
parent
37f11e3269
commit
0910b3adef
@ -222,6 +222,9 @@ public class PlanSystem implements SubSystem {
|
||||
public void disable() {
|
||||
enabled = false;
|
||||
Formatters.clearSingleton();
|
||||
|
||||
extensionService.disableUpdates();
|
||||
|
||||
disableSystems(
|
||||
taskSystem,
|
||||
cacheSystem,
|
||||
|
@ -39,6 +39,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* Implementation for {@link ExtensionService}.
|
||||
@ -58,6 +59,7 @@ public class ExtensionSvc implements ExtensionService {
|
||||
private final ErrorLogger errorLogger;
|
||||
|
||||
private final Map<String, DataValueGatherer> extensionGatherers;
|
||||
private final AtomicBoolean enabled;
|
||||
|
||||
@Inject
|
||||
public ExtensionSvc(
|
||||
@ -80,6 +82,7 @@ public class ExtensionSvc implements ExtensionService {
|
||||
this.errorLogger = errorLogger;
|
||||
|
||||
extensionGatherers = new HashMap<>();
|
||||
enabled = new AtomicBoolean(true);
|
||||
}
|
||||
|
||||
public void register() {
|
||||
@ -152,12 +155,14 @@ public class ExtensionSvc implements ExtensionService {
|
||||
}
|
||||
|
||||
public void updatePlayerValues(UUID playerUUID, String playerName, CallEvents event) {
|
||||
if (!enabled.get()) return; // Plugin is disabling
|
||||
for (DataValueGatherer gatherer : extensionGatherers.values()) {
|
||||
updatePlayerValues(gatherer, playerUUID, playerName, event);
|
||||
}
|
||||
}
|
||||
|
||||
public void updatePlayerValues(DataValueGatherer gatherer, UUID playerUUID, String playerName, CallEvents event) {
|
||||
if (!enabled.get()) return; // Plugin is disabling
|
||||
if (gatherer.shouldSkipEvent(event)) return;
|
||||
if (playerUUID == null && playerName == null) return;
|
||||
|
||||
@ -172,14 +177,20 @@ public class ExtensionSvc implements ExtensionService {
|
||||
}
|
||||
|
||||
public void updateServerValues(CallEvents event) {
|
||||
if (!enabled.get()) return; // Plugin is disabling
|
||||
for (DataValueGatherer gatherer : extensionGatherers.values()) {
|
||||
updateServerValues(gatherer, event);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateServerValues(DataValueGatherer gatherer, CallEvents event) {
|
||||
if (!enabled.get()) return; // Plugin is disabling
|
||||
if (gatherer.shouldSkipEvent(event)) return;
|
||||
|
||||
gatherer.updateValues();
|
||||
}
|
||||
|
||||
public void disableUpdates() {
|
||||
enabled.set(false);
|
||||
}
|
||||
}
|
@ -49,6 +49,7 @@ import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
|
||||
/**
|
||||
* Object that can be called to place data about players to the database.
|
||||
@ -293,6 +294,14 @@ public class DataValueGatherer {
|
||||
}
|
||||
|
||||
public void updateValues(UUID playerUUID, String playerName) {
|
||||
try {
|
||||
tryToUpdateValues(playerUUID, playerName);
|
||||
} catch (RejectedExecutionException ignore) {
|
||||
// Database has shut down
|
||||
}
|
||||
}
|
||||
|
||||
private void tryToUpdateValues(UUID playerUUID, String playerName) {
|
||||
Parameters parameters = Parameters.player(serverInfo.getServerUUID(), playerUUID, playerName);
|
||||
ExtensionDataBuilder dataBuilder = extension.getExtension().newExtensionDataBuilder();
|
||||
|
||||
@ -305,6 +314,14 @@ public class DataValueGatherer {
|
||||
}
|
||||
|
||||
public void updateValues() {
|
||||
try {
|
||||
tryToUpdateValues();
|
||||
} catch (RejectedExecutionException ignore) {
|
||||
// Database has shut down
|
||||
}
|
||||
}
|
||||
|
||||
private void tryToUpdateValues() {
|
||||
Parameters parameters = Parameters.server(serverInfo.getServerUUID());
|
||||
ExtensionDataBuilder dataBuilder = extension.getExtension().newExtensionDataBuilder();
|
||||
|
||||
@ -362,15 +379,19 @@ public class DataValueGatherer {
|
||||
|
||||
private void logFailure(Throwable cause, String pluginName, String methodName) {
|
||||
ErrorContext.Builder context = ErrorContext.builder()
|
||||
.whatToDo("Report and/or disable " + pluginName + " extension in the Plan config.")
|
||||
.whatToDo(getWhatToDoMessage(pluginName))
|
||||
.related(pluginName)
|
||||
.related("Method:" + methodName);
|
||||
errorLogger.warn(cause, context.build());
|
||||
}
|
||||
|
||||
private String getWhatToDoMessage(String pluginName) {
|
||||
return "Report and/or disable " + pluginName + " extension in the Plan config.";
|
||||
}
|
||||
|
||||
private void logFailure(DataExtensionMethodCallException methodCallFailed) {
|
||||
ErrorContext.Builder context = ErrorContext.builder()
|
||||
.whatToDo("Report and/or disable " + methodCallFailed.getPluginName() + " extension in the Plan config.")
|
||||
.whatToDo(getWhatToDoMessage(methodCallFailed.getPluginName()))
|
||||
.related(methodCallFailed.getPluginName())
|
||||
.related("Method:" + methodCallFailed.getMethodName().orElse("-"));
|
||||
errorLogger.warn(methodCallFailed, context.build());
|
||||
@ -378,7 +399,7 @@ public class DataValueGatherer {
|
||||
|
||||
private void logFailure(Throwable unexpectedError) {
|
||||
ErrorContext.Builder context = ErrorContext.builder()
|
||||
.whatToDo("Report and/or disable " + extension.getPluginName() + " extension in the Plan config.")
|
||||
.whatToDo(getWhatToDoMessage(extension.getPluginName()))
|
||||
.related(extension.getPluginName());
|
||||
errorLogger.warn(unexpectedError, context.build());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user