mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-25 09:32:11 +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() {
|
public void disable() {
|
||||||
enabled = false;
|
enabled = false;
|
||||||
Formatters.clearSingleton();
|
Formatters.clearSingleton();
|
||||||
|
|
||||||
|
extensionService.disableUpdates();
|
||||||
|
|
||||||
disableSystems(
|
disableSystems(
|
||||||
taskSystem,
|
taskSystem,
|
||||||
cacheSystem,
|
cacheSystem,
|
||||||
|
@ -39,6 +39,7 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation for {@link ExtensionService}.
|
* Implementation for {@link ExtensionService}.
|
||||||
@ -58,6 +59,7 @@ public class ExtensionSvc implements ExtensionService {
|
|||||||
private final ErrorLogger errorLogger;
|
private final ErrorLogger errorLogger;
|
||||||
|
|
||||||
private final Map<String, DataValueGatherer> extensionGatherers;
|
private final Map<String, DataValueGatherer> extensionGatherers;
|
||||||
|
private final AtomicBoolean enabled;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ExtensionSvc(
|
public ExtensionSvc(
|
||||||
@ -80,6 +82,7 @@ public class ExtensionSvc implements ExtensionService {
|
|||||||
this.errorLogger = errorLogger;
|
this.errorLogger = errorLogger;
|
||||||
|
|
||||||
extensionGatherers = new HashMap<>();
|
extensionGatherers = new HashMap<>();
|
||||||
|
enabled = new AtomicBoolean(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void register() {
|
public void register() {
|
||||||
@ -152,12 +155,14 @@ public class ExtensionSvc implements ExtensionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updatePlayerValues(UUID playerUUID, String playerName, CallEvents event) {
|
public void updatePlayerValues(UUID playerUUID, String playerName, CallEvents event) {
|
||||||
|
if (!enabled.get()) return; // Plugin is disabling
|
||||||
for (DataValueGatherer gatherer : extensionGatherers.values()) {
|
for (DataValueGatherer gatherer : extensionGatherers.values()) {
|
||||||
updatePlayerValues(gatherer, playerUUID, playerName, event);
|
updatePlayerValues(gatherer, playerUUID, playerName, event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updatePlayerValues(DataValueGatherer gatherer, UUID playerUUID, String playerName, CallEvents 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 (gatherer.shouldSkipEvent(event)) return;
|
||||||
if (playerUUID == null && playerName == null) return;
|
if (playerUUID == null && playerName == null) return;
|
||||||
|
|
||||||
@ -172,14 +177,20 @@ public class ExtensionSvc implements ExtensionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateServerValues(CallEvents event) {
|
public void updateServerValues(CallEvents event) {
|
||||||
|
if (!enabled.get()) return; // Plugin is disabling
|
||||||
for (DataValueGatherer gatherer : extensionGatherers.values()) {
|
for (DataValueGatherer gatherer : extensionGatherers.values()) {
|
||||||
updateServerValues(gatherer, event);
|
updateServerValues(gatherer, event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateServerValues(DataValueGatherer gatherer, CallEvents event) {
|
public void updateServerValues(DataValueGatherer gatherer, CallEvents event) {
|
||||||
|
if (!enabled.get()) return; // Plugin is disabling
|
||||||
if (gatherer.shouldSkipEvent(event)) return;
|
if (gatherer.shouldSkipEvent(event)) return;
|
||||||
|
|
||||||
gatherer.updateValues();
|
gatherer.updateValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void disableUpdates() {
|
||||||
|
enabled.set(false);
|
||||||
|
}
|
||||||
}
|
}
|
@ -49,6 +49,7 @@ import java.util.HashSet;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.RejectedExecutionException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Object that can be called to place data about players to the database.
|
* 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) {
|
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);
|
Parameters parameters = Parameters.player(serverInfo.getServerUUID(), playerUUID, playerName);
|
||||||
ExtensionDataBuilder dataBuilder = extension.getExtension().newExtensionDataBuilder();
|
ExtensionDataBuilder dataBuilder = extension.getExtension().newExtensionDataBuilder();
|
||||||
|
|
||||||
@ -305,6 +314,14 @@ public class DataValueGatherer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateValues() {
|
public void updateValues() {
|
||||||
|
try {
|
||||||
|
tryToUpdateValues();
|
||||||
|
} catch (RejectedExecutionException ignore) {
|
||||||
|
// Database has shut down
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void tryToUpdateValues() {
|
||||||
Parameters parameters = Parameters.server(serverInfo.getServerUUID());
|
Parameters parameters = Parameters.server(serverInfo.getServerUUID());
|
||||||
ExtensionDataBuilder dataBuilder = extension.getExtension().newExtensionDataBuilder();
|
ExtensionDataBuilder dataBuilder = extension.getExtension().newExtensionDataBuilder();
|
||||||
|
|
||||||
@ -362,15 +379,19 @@ public class DataValueGatherer {
|
|||||||
|
|
||||||
private void logFailure(Throwable cause, String pluginName, String methodName) {
|
private void logFailure(Throwable cause, String pluginName, String methodName) {
|
||||||
ErrorContext.Builder context = ErrorContext.builder()
|
ErrorContext.Builder context = ErrorContext.builder()
|
||||||
.whatToDo("Report and/or disable " + pluginName + " extension in the Plan config.")
|
.whatToDo(getWhatToDoMessage(pluginName))
|
||||||
.related(pluginName)
|
.related(pluginName)
|
||||||
.related("Method:" + methodName);
|
.related("Method:" + methodName);
|
||||||
errorLogger.warn(cause, context.build());
|
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) {
|
private void logFailure(DataExtensionMethodCallException methodCallFailed) {
|
||||||
ErrorContext.Builder context = ErrorContext.builder()
|
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(methodCallFailed.getPluginName())
|
||||||
.related("Method:" + methodCallFailed.getMethodName().orElse("-"));
|
.related("Method:" + methodCallFailed.getMethodName().orElse("-"));
|
||||||
errorLogger.warn(methodCallFailed, context.build());
|
errorLogger.warn(methodCallFailed, context.build());
|
||||||
@ -378,7 +399,7 @@ public class DataValueGatherer {
|
|||||||
|
|
||||||
private void logFailure(Throwable unexpectedError) {
|
private void logFailure(Throwable unexpectedError) {
|
||||||
ErrorContext.Builder context = ErrorContext.builder()
|
ErrorContext.Builder context = ErrorContext.builder()
|
||||||
.whatToDo("Report and/or disable " + extension.getPluginName() + " extension in the Plan config.")
|
.whatToDo(getWhatToDoMessage(extension.getPluginName()))
|
||||||
.related(extension.getPluginName());
|
.related(extension.getPluginName());
|
||||||
errorLogger.warn(unexpectedError, context.build());
|
errorLogger.warn(unexpectedError, context.build());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user