mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-27 19:47:49 +01:00
Replaced TaskSystem implementations with dagger modules
- Removes the need for duplicate code in 5 places in charge of registering the tasks for different platforms, as all the delays were the same too. Affects issues: - Close #1387
This commit is contained in:
parent
68ce65b4d5
commit
c8fb39ada5
@ -1,154 +0,0 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan;
|
||||
|
||||
import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
|
||||
import com.djrapitops.plan.extension.ExtensionServerMethodCallerTask;
|
||||
import com.djrapitops.plan.gathering.ShutdownHook;
|
||||
import com.djrapitops.plan.gathering.timed.BukkitPingCounter;
|
||||
import com.djrapitops.plan.gathering.timed.ServerTPSCounter;
|
||||
import com.djrapitops.plan.gathering.timed.SystemUsageBuffer;
|
||||
import com.djrapitops.plan.gathering.timed.TPSCounter;
|
||||
import com.djrapitops.plan.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.settings.config.paths.DataGatheringSettings;
|
||||
import com.djrapitops.plan.settings.config.paths.TimeSettings;
|
||||
import com.djrapitops.plan.settings.upkeep.ConfigStoreTask;
|
||||
import com.djrapitops.plan.storage.upkeep.DBCleanTask;
|
||||
import com.djrapitops.plan.storage.upkeep.LogsFolderCleanTask;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* TaskSystem responsible for registering tasks for Bukkit.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
public class BukkitTaskSystem extends TaskSystem {
|
||||
|
||||
private final Plan plugin;
|
||||
private final PlanConfig config;
|
||||
private final ShutdownHook shutdownHook;
|
||||
private final JSONCache.CleanTask jsonCacheCleanTask;
|
||||
private final LogsFolderCleanTask logsFolderCleanTask;
|
||||
private final BukkitPingCounter pingCounter;
|
||||
private final ConfigStoreTask configStoreTask;
|
||||
private final DBCleanTask dbCleanTask;
|
||||
private final ExtensionServerMethodCallerTask extensionServerMethodCallerTask;
|
||||
private final TPSCounter tpsCounter;
|
||||
private final SystemUsageBuffer.RamAndCpuTask ramAndCpuTask;
|
||||
private final SystemUsageBuffer.DiskTask diskTask;
|
||||
|
||||
@Inject
|
||||
public BukkitTaskSystem(
|
||||
Plan plugin,
|
||||
PlanConfig config,
|
||||
ShutdownHook shutdownHook,
|
||||
RunnableFactory runnableFactory,
|
||||
|
||||
ServerTPSCounter<World> tpsCounter,
|
||||
BukkitPingCounter pingCounter,
|
||||
ExtensionServerMethodCallerTask extensionServerMethodCallerTask,
|
||||
|
||||
LogsFolderCleanTask logsFolderCleanTask,
|
||||
ConfigStoreTask configStoreTask,
|
||||
DBCleanTask dbCleanTask,
|
||||
JSONCache.CleanTask jsonCacheCleanTask,
|
||||
SystemUsageBuffer.RamAndCpuTask ramAndCpuTask,
|
||||
SystemUsageBuffer.DiskTask diskTask
|
||||
) {
|
||||
super(runnableFactory);
|
||||
this.plugin = plugin;
|
||||
this.config = config;
|
||||
this.shutdownHook = shutdownHook;
|
||||
this.jsonCacheCleanTask = jsonCacheCleanTask;
|
||||
|
||||
this.tpsCounter = tpsCounter;
|
||||
this.pingCounter = pingCounter;
|
||||
this.extensionServerMethodCallerTask = extensionServerMethodCallerTask;
|
||||
|
||||
this.logsFolderCleanTask = logsFolderCleanTask;
|
||||
this.configStoreTask = configStoreTask;
|
||||
this.dbCleanTask = dbCleanTask;
|
||||
this.ramAndCpuTask = ramAndCpuTask;
|
||||
this.diskTask = diskTask;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
registerTPSCounter();
|
||||
registerPingCounter();
|
||||
registerExtensionDataGatheringTask();
|
||||
registerUpkeepTasks();
|
||||
|
||||
shutdownHook.register();
|
||||
}
|
||||
|
||||
private void registerUpkeepTasks() {
|
||||
// +40 ticks / 2 seconds so that update check task runs first.
|
||||
long storeDelay = TimeAmount.toTicks(config.get(TimeSettings.CONFIG_UPDATE_INTERVAL), TimeUnit.MILLISECONDS) + 40;
|
||||
registerTask(configStoreTask).runTaskLaterAsynchronously(storeDelay);
|
||||
registerTask(logsFolderCleanTask).runTaskLaterAsynchronously(TimeAmount.toTicks(30L, TimeUnit.SECONDS));
|
||||
registerTask(dbCleanTask).runTaskTimerAsynchronously(
|
||||
TimeAmount.toTicks(20, TimeUnit.SECONDS),
|
||||
TimeAmount.toTicks(config.get(TimeSettings.CLEAN_DATABASE_PERIOD), TimeUnit.MILLISECONDS)
|
||||
);
|
||||
long minute = TimeAmount.toTicks(1, TimeUnit.MINUTES);
|
||||
registerTask(jsonCacheCleanTask).runTaskTimerAsynchronously(minute, minute);
|
||||
}
|
||||
|
||||
private void registerTPSCounter() {
|
||||
long halfSecondTicks = TimeAmount.toTicks(500L, TimeUnit.MILLISECONDS);
|
||||
long secondTicks = TimeAmount.toTicks(1L, TimeUnit.SECONDS);
|
||||
long minuteTicks = TimeAmount.toTicks(1L, TimeUnit.MINUTES);
|
||||
registerTask(tpsCounter).runTaskTimer(minuteTicks, secondTicks);
|
||||
registerTask(ramAndCpuTask).runTaskTimerAsynchronously(minuteTicks - halfSecondTicks, secondTicks);
|
||||
registerTask(diskTask).runTaskTimerAsynchronously(50L * secondTicks, minuteTicks);
|
||||
}
|
||||
|
||||
private void registerPingCounter() {
|
||||
try {
|
||||
Long pingDelay = config.get(TimeSettings.PING_SERVER_ENABLE_DELAY);
|
||||
if (pingDelay < TimeUnit.HOURS.toMillis(1L) && config.isTrue(DataGatheringSettings.PING)) {
|
||||
plugin.registerListener(pingCounter);
|
||||
long startDelay = TimeAmount.toTicks(pingDelay, TimeUnit.MILLISECONDS);
|
||||
registerTask(pingCounter).runTaskTimer(startDelay, 40L);
|
||||
}
|
||||
} catch (ExceptionInInitializerError | NoClassDefFoundError ignore) {
|
||||
// Running CraftBukkit
|
||||
}
|
||||
}
|
||||
|
||||
private void registerExtensionDataGatheringTask() {
|
||||
long extensionRefreshPeriod = TimeAmount.toTicks(config.get(TimeSettings.EXTENSION_DATA_REFRESH_PERIOD), TimeUnit.MILLISECONDS);
|
||||
registerTask(extensionServerMethodCallerTask).runTaskTimerAsynchronously(
|
||||
TimeAmount.toTicks(30, TimeUnit.SECONDS), extensionRefreshPeriod
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
super.disable();
|
||||
Bukkit.getScheduler().cancelTasks(plugin);
|
||||
}
|
||||
}
|
@ -120,16 +120,19 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
|
||||
*/
|
||||
@Override
|
||||
public void onDisable() {
|
||||
if (serverShutdownSave != null) {
|
||||
serverShutdownSave.performSave();
|
||||
}
|
||||
if (system != null) {
|
||||
system.disable();
|
||||
}
|
||||
if (serverShutdownSave != null) serverShutdownSave.performSave();
|
||||
cancelAllTasks();
|
||||
if (system != null) system.disable();
|
||||
|
||||
logger.info(locale != null ? locale.getString(PluginLang.DISABLED) : PluginLang.DISABLED.getDefault());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelAllTasks() {
|
||||
runnableFactory.cancelAllKnownTasks();
|
||||
Bukkit.getScheduler().cancelTasks(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return getDescription().getVersion();
|
||||
|
@ -26,6 +26,7 @@ import com.djrapitops.plan.modules.SystemObjectProvidingModule;
|
||||
import com.djrapitops.plan.modules.bukkit.BukkitPlanModule;
|
||||
import com.djrapitops.plan.modules.bukkit.BukkitServerPropertiesModule;
|
||||
import com.djrapitops.plan.modules.bukkit.BukkitSuperClassBindingModule;
|
||||
import com.djrapitops.plan.modules.bukkit.BukkitTaskModule;
|
||||
import dagger.BindsInstance;
|
||||
import dagger.Component;
|
||||
|
||||
@ -45,7 +46,8 @@ import javax.inject.Singleton;
|
||||
|
||||
ServerCommandModule.class,
|
||||
BukkitServerPropertiesModule.class,
|
||||
BukkitSuperClassBindingModule.class
|
||||
BukkitSuperClassBindingModule.class,
|
||||
BukkitTaskModule.class
|
||||
})
|
||||
public interface PlanBukkitComponent {
|
||||
|
||||
|
@ -23,9 +23,12 @@
|
||||
*/
|
||||
package com.djrapitops.plan.gathering.timed;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plan.delivery.domain.DateObj;
|
||||
import com.djrapitops.plan.identification.ServerInfo;
|
||||
import com.djrapitops.plan.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.settings.config.paths.DataGatheringSettings;
|
||||
import com.djrapitops.plan.settings.config.paths.TimeSettings;
|
||||
import com.djrapitops.plan.storage.database.DBSystem;
|
||||
import com.djrapitops.plan.storage.database.transactions.events.PingStoreTransaction;
|
||||
@ -60,7 +63,7 @@ import java.util.logging.Logger;
|
||||
* @author games647
|
||||
*/
|
||||
@Singleton
|
||||
public class BukkitPingCounter extends AbsRunnable implements Listener {
|
||||
public class BukkitPingCounter extends TaskSystem.Task implements Listener {
|
||||
|
||||
//the server is pinging the client every 40 Ticks (2 sec) - so check it then
|
||||
//https://github.com/bergerkiller/CraftSource/blob/master/net.minecraft.server/PlayerConnection.java#L178
|
||||
@ -70,13 +73,23 @@ public class BukkitPingCounter extends AbsRunnable implements Listener {
|
||||
private static MethodHandle PING_FIELD;
|
||||
private static MethodHandle GET_HANDLE_METHOD;
|
||||
|
||||
private final Map<UUID, List<DateObj<Integer>>> playerHistory;
|
||||
|
||||
private final Plan plugin;
|
||||
private final PlanConfig config;
|
||||
private final DBSystem dbSystem;
|
||||
private final ServerInfo serverInfo;
|
||||
private final RunnableFactory runnableFactory;
|
||||
|
||||
@Inject
|
||||
public BukkitPingCounter(
|
||||
Plan plugin,
|
||||
PlanConfig config,
|
||||
DBSystem dbSystem,
|
||||
ServerInfo serverInfo,
|
||||
RunnableFactory runnableFactory
|
||||
) {
|
||||
this.plugin = plugin;
|
||||
BukkitPingCounter.loadPingMethodDetails();
|
||||
this.config = config;
|
||||
this.dbSystem = dbSystem;
|
||||
@ -85,12 +98,6 @@ public class BukkitPingCounter extends AbsRunnable implements Listener {
|
||||
playerHistory = new HashMap<>();
|
||||
}
|
||||
|
||||
private final Map<UUID, List<DateObj<Integer>>> playerHistory;
|
||||
|
||||
private final PlanConfig config;
|
||||
private final DBSystem dbSystem;
|
||||
private final ServerInfo serverInfo;
|
||||
private final RunnableFactory runnableFactory;
|
||||
|
||||
private static void loadPingMethodDetails() {
|
||||
PING_METHOD_AVAILABLE = isPingMethodAvailable();
|
||||
@ -135,6 +142,17 @@ public class BukkitPingCounter extends AbsRunnable implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(RunnableFactory runnableFactory) {
|
||||
Long startDelay = config.get(TimeSettings.PING_SERVER_ENABLE_DELAY);
|
||||
if (startDelay < TimeUnit.HOURS.toMillis(1L) && config.isTrue(DataGatheringSettings.PING)) {
|
||||
plugin.registerListener(this);
|
||||
long delay = TimeAmount.toTicks(startDelay, TimeUnit.MILLISECONDS);
|
||||
long period = 40L;
|
||||
runnableFactory.create(null, this).runTaskTimer(delay, period);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
long time = System.currentTimeMillis();
|
||||
|
@ -17,8 +17,6 @@
|
||||
package com.djrapitops.plan.modules.bukkit;
|
||||
|
||||
import com.djrapitops.plan.BukkitServerShutdownSave;
|
||||
import com.djrapitops.plan.BukkitTaskSystem;
|
||||
import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plan.gathering.BukkitSensor;
|
||||
import com.djrapitops.plan.gathering.ServerSensor;
|
||||
import com.djrapitops.plan.gathering.ServerShutdownSave;
|
||||
@ -51,9 +49,6 @@ public interface BukkitSuperClassBindingModule {
|
||||
@Binds
|
||||
ConfigSystem bindConfigSystem(BukkitConfigSystem configSystem);
|
||||
|
||||
@Binds
|
||||
TaskSystem bindTaskSystem(BukkitTaskSystem taskSystem);
|
||||
|
||||
@Binds
|
||||
ListenerSystem bindListenerSystem(BukkitListenerSystem listenerSystem);
|
||||
|
||||
|
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan.modules.bukkit;
|
||||
|
||||
import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
|
||||
import com.djrapitops.plan.extension.ExtensionServerDataUpdater;
|
||||
import com.djrapitops.plan.gathering.ShutdownHook;
|
||||
import com.djrapitops.plan.gathering.timed.BukkitPingCounter;
|
||||
import com.djrapitops.plan.gathering.timed.ServerTPSCounter;
|
||||
import com.djrapitops.plan.gathering.timed.SystemUsageBuffer;
|
||||
import com.djrapitops.plan.settings.upkeep.ConfigStoreTask;
|
||||
import com.djrapitops.plan.storage.upkeep.DBCleanTask;
|
||||
import com.djrapitops.plan.storage.upkeep.LogsFolderCleanTask;
|
||||
import dagger.Binds;
|
||||
import dagger.Module;
|
||||
import dagger.multibindings.IntoSet;
|
||||
import org.bukkit.World;
|
||||
|
||||
@Module
|
||||
public interface BukkitTaskModule {
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindTPSCounter(ServerTPSCounter<World> tpsCounter);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindPingCounter(BukkitPingCounter pingCounter);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindExtensionServerDataUpdater(ExtensionServerDataUpdater extensionServerDataUpdater);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindLogCleanTask(LogsFolderCleanTask logsFolderCleanTask);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindConfigStoreTask(ConfigStoreTask configStoreTask);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindDBCleanTask(DBCleanTask cleanTask);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindJSONCacheCleanTask(JSONCache.CleanTask cleanTask);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindRamAndCpuTask(SystemUsageBuffer.RamAndCpuTask ramAndCpuTask);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindDiskTask(SystemUsageBuffer.DiskTask diskTask);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindShutdownHookRegistration(ShutdownHook.Registrar registrar);
|
||||
|
||||
}
|
@ -1,129 +0,0 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan;
|
||||
|
||||
import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
|
||||
import com.djrapitops.plan.extension.ExtensionServerMethodCallerTask;
|
||||
import com.djrapitops.plan.gathering.timed.BungeePingCounter;
|
||||
import com.djrapitops.plan.gathering.timed.ProxyTPSCounter;
|
||||
import com.djrapitops.plan.gathering.timed.SystemUsageBuffer;
|
||||
import com.djrapitops.plan.gathering.timed.TPSCounter;
|
||||
import com.djrapitops.plan.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.settings.config.paths.DataGatheringSettings;
|
||||
import com.djrapitops.plan.settings.config.paths.TimeSettings;
|
||||
import com.djrapitops.plan.settings.upkeep.NetworkConfigStoreTask;
|
||||
import com.djrapitops.plan.storage.upkeep.DBCleanTask;
|
||||
import com.djrapitops.plan.storage.upkeep.LogsFolderCleanTask;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* TaskSystem responsible for registering tasks for Bungee.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
public class BungeeTaskSystem extends TaskSystem {
|
||||
|
||||
private final PlanBungee plugin;
|
||||
private final PlanConfig config;
|
||||
private final TPSCounter tpsCounter;
|
||||
private final BungeePingCounter pingCounter;
|
||||
private final LogsFolderCleanTask logsFolderCleanTask;
|
||||
private final NetworkConfigStoreTask networkConfigStoreTask;
|
||||
private final DBCleanTask dbCleanTask;
|
||||
private final JSONCache.CleanTask jsonCacheCleanTask;
|
||||
private final ExtensionServerMethodCallerTask extensionServerMethodCallerTask;
|
||||
private final SystemUsageBuffer.RamAndCpuTask ramAndCpuTask;
|
||||
private final SystemUsageBuffer.DiskTask diskTask;
|
||||
|
||||
@Inject
|
||||
public BungeeTaskSystem(
|
||||
PlanBungee plugin,
|
||||
PlanConfig config,
|
||||
RunnableFactory runnableFactory,
|
||||
ProxyTPSCounter tpsCounter,
|
||||
BungeePingCounter pingCounter,
|
||||
LogsFolderCleanTask logsFolderCleanTask,
|
||||
NetworkConfigStoreTask networkConfigStoreTask,
|
||||
DBCleanTask dbCleanTask,
|
||||
JSONCache.CleanTask jsonCacheCleanTask,
|
||||
ExtensionServerMethodCallerTask extensionServerMethodCallerTask,
|
||||
SystemUsageBuffer.RamAndCpuTask ramAndCpuTask,
|
||||
SystemUsageBuffer.DiskTask diskTask
|
||||
) {
|
||||
super(runnableFactory);
|
||||
this.plugin = plugin;
|
||||
this.config = config;
|
||||
this.tpsCounter = tpsCounter;
|
||||
|
||||
this.pingCounter = pingCounter;
|
||||
this.logsFolderCleanTask = logsFolderCleanTask;
|
||||
this.networkConfigStoreTask = networkConfigStoreTask;
|
||||
this.dbCleanTask = dbCleanTask;
|
||||
this.jsonCacheCleanTask = jsonCacheCleanTask;
|
||||
this.extensionServerMethodCallerTask = extensionServerMethodCallerTask;
|
||||
this.ramAndCpuTask = ramAndCpuTask;
|
||||
this.diskTask = diskTask;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
registerTasks();
|
||||
}
|
||||
|
||||
private void registerTPSCounter() {
|
||||
long halfSecondTicks = TimeAmount.toTicks(500L, TimeUnit.MILLISECONDS);
|
||||
long secondTicks = TimeAmount.toTicks(1L, TimeUnit.SECONDS);
|
||||
long minuteTicks = TimeAmount.toTicks(1L, TimeUnit.MINUTES);
|
||||
registerTask(tpsCounter).runTaskTimer(minuteTicks, secondTicks);
|
||||
registerTask(ramAndCpuTask).runTaskTimerAsynchronously(minuteTicks - halfSecondTicks, secondTicks);
|
||||
registerTask(diskTask).runTaskTimerAsynchronously(50L * secondTicks, minuteTicks);
|
||||
}
|
||||
|
||||
private void registerTasks() {
|
||||
registerTPSCounter();
|
||||
registerTask(logsFolderCleanTask).runTaskLaterAsynchronously(TimeAmount.toTicks(30L, TimeUnit.SECONDS));
|
||||
|
||||
Long pingDelay = config.get(TimeSettings.PING_SERVER_ENABLE_DELAY);
|
||||
if (pingDelay < TimeUnit.HOURS.toMillis(1L) && config.isTrue(DataGatheringSettings.PING)) {
|
||||
plugin.registerListener(pingCounter);
|
||||
long startDelay = TimeAmount.toTicks(pingDelay, TimeUnit.MILLISECONDS);
|
||||
registerTask(pingCounter).runTaskTimer(startDelay, 40L);
|
||||
}
|
||||
|
||||
// +40 ticks / 2 seconds so that update check task runs first.
|
||||
long storeDelay = TimeAmount.toTicks(config.get(TimeSettings.CONFIG_UPDATE_INTERVAL), TimeUnit.MILLISECONDS) + 40;
|
||||
registerTask(networkConfigStoreTask).runTaskLaterAsynchronously(storeDelay);
|
||||
|
||||
registerTask(dbCleanTask).runTaskTimerAsynchronously(
|
||||
TimeAmount.toTicks(20, TimeUnit.SECONDS),
|
||||
TimeAmount.toTicks(config.get(TimeSettings.CLEAN_DATABASE_PERIOD), TimeUnit.MILLISECONDS)
|
||||
);
|
||||
long minute = TimeAmount.toTicks(1, TimeUnit.MINUTES);
|
||||
registerTask(jsonCacheCleanTask).runTaskTimerAsynchronously(minute, minute);
|
||||
|
||||
long extensionRefreshPeriod = TimeAmount.toTicks(config.get(TimeSettings.EXTENSION_DATA_REFRESH_PERIOD), TimeUnit.MILLISECONDS);
|
||||
registerTask(extensionServerMethodCallerTask).runTaskTimerAsynchronously(
|
||||
TimeAmount.toTicks(30, TimeUnit.SECONDS), extensionRefreshPeriod
|
||||
);
|
||||
}
|
||||
}
|
@ -74,6 +74,7 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin {
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
cancelAllTasks();
|
||||
if (system != null) system.disable();
|
||||
|
||||
logger.info(locale.getString(PluginLang.DISABLED));
|
||||
|
@ -21,10 +21,7 @@ import com.djrapitops.plan.modules.APFModule;
|
||||
import com.djrapitops.plan.modules.PlaceholderModule;
|
||||
import com.djrapitops.plan.modules.ProxySuperClassBindingModule;
|
||||
import com.djrapitops.plan.modules.SystemObjectProvidingModule;
|
||||
import com.djrapitops.plan.modules.bungee.BungeeCommandModule;
|
||||
import com.djrapitops.plan.modules.bungee.BungeePlanModule;
|
||||
import com.djrapitops.plan.modules.bungee.BungeeServerPropertiesModule;
|
||||
import com.djrapitops.plan.modules.bungee.BungeeSuperClassBindingModule;
|
||||
import com.djrapitops.plan.modules.bungee.*;
|
||||
import dagger.BindsInstance;
|
||||
import dagger.Component;
|
||||
|
||||
@ -45,7 +42,8 @@ import javax.inject.Singleton;
|
||||
|
||||
ProxySuperClassBindingModule.class,
|
||||
BungeeSuperClassBindingModule.class,
|
||||
BungeeServerPropertiesModule.class
|
||||
BungeeServerPropertiesModule.class,
|
||||
BungeeTaskModule.class
|
||||
})
|
||||
public interface PlanBungeeComponent {
|
||||
|
||||
|
@ -23,9 +23,12 @@
|
||||
*/
|
||||
package com.djrapitops.plan.gathering.timed;
|
||||
|
||||
import com.djrapitops.plan.PlanBungee;
|
||||
import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plan.delivery.domain.DateObj;
|
||||
import com.djrapitops.plan.identification.ServerInfo;
|
||||
import com.djrapitops.plan.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.settings.config.paths.DataGatheringSettings;
|
||||
import com.djrapitops.plan.settings.config.paths.TimeSettings;
|
||||
import com.djrapitops.plan.storage.database.DBSystem;
|
||||
import com.djrapitops.plan.storage.database.transactions.events.PingStoreTransaction;
|
||||
@ -50,10 +53,11 @@ import java.util.concurrent.TimeUnit;
|
||||
* @author BrainStone
|
||||
*/
|
||||
@Singleton
|
||||
public class BungeePingCounter extends AbsRunnable implements Listener {
|
||||
public class BungeePingCounter extends TaskSystem.Task implements Listener {
|
||||
|
||||
private final Map<UUID, List<DateObj<Integer>>> playerHistory;
|
||||
|
||||
private final PlanBungee plugin;
|
||||
private final PlanConfig config;
|
||||
private final DBSystem dbSystem;
|
||||
private final ServerInfo serverInfo;
|
||||
@ -61,11 +65,13 @@ public class BungeePingCounter extends AbsRunnable implements Listener {
|
||||
|
||||
@Inject
|
||||
public BungeePingCounter(
|
||||
PlanBungee plugin,
|
||||
PlanConfig config,
|
||||
DBSystem dbSystem,
|
||||
ServerInfo serverInfo,
|
||||
RunnableFactory runnableFactory
|
||||
) {
|
||||
this.plugin = plugin;
|
||||
this.config = config;
|
||||
this.dbSystem = dbSystem;
|
||||
this.serverInfo = serverInfo;
|
||||
@ -102,6 +108,18 @@ public class BungeePingCounter extends AbsRunnable implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(RunnableFactory runnableFactory) {
|
||||
Long startDelay = config.get(TimeSettings.PING_SERVER_ENABLE_DELAY);
|
||||
if (startDelay < TimeUnit.HOURS.toMillis(1L) && config.isTrue(DataGatheringSettings.PING)) {
|
||||
plugin.registerListener(this);
|
||||
|
||||
long delay = TimeAmount.toTicks(startDelay, TimeUnit.MILLISECONDS);
|
||||
long period = 40L;
|
||||
runnableFactory.create(null, this).runTaskTimerAsynchronously(delay, period);
|
||||
}
|
||||
}
|
||||
|
||||
public void addPlayer(ProxiedPlayer player) {
|
||||
playerHistory.put(player.getUniqueId(), new ArrayList<>());
|
||||
}
|
||||
|
@ -16,8 +16,6 @@
|
||||
*/
|
||||
package com.djrapitops.plan.modules.bungee;
|
||||
|
||||
import com.djrapitops.plan.BungeeTaskSystem;
|
||||
import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plan.gathering.BungeeSensor;
|
||||
import com.djrapitops.plan.gathering.ServerSensor;
|
||||
import com.djrapitops.plan.gathering.listeners.BungeeListenerSystem;
|
||||
@ -38,9 +36,6 @@ public interface BungeeSuperClassBindingModule {
|
||||
@Binds
|
||||
ServerInfo bindServerInfo(BungeeServerInfo serverInfo);
|
||||
|
||||
@Binds
|
||||
TaskSystem bindTaskSystem(BungeeTaskSystem taskSystem);
|
||||
|
||||
@Binds
|
||||
ListenerSystem bindListenerSystem(BungeeListenerSystem listenerSystem);
|
||||
|
||||
|
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan.modules.bungee;
|
||||
|
||||
import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
|
||||
import com.djrapitops.plan.extension.ExtensionServerDataUpdater;
|
||||
import com.djrapitops.plan.gathering.timed.BungeePingCounter;
|
||||
import com.djrapitops.plan.gathering.timed.ProxyTPSCounter;
|
||||
import com.djrapitops.plan.gathering.timed.SystemUsageBuffer;
|
||||
import com.djrapitops.plan.settings.upkeep.NetworkConfigStoreTask;
|
||||
import com.djrapitops.plan.storage.upkeep.DBCleanTask;
|
||||
import com.djrapitops.plan.storage.upkeep.LogsFolderCleanTask;
|
||||
import dagger.Binds;
|
||||
import dagger.Module;
|
||||
import dagger.multibindings.IntoSet;
|
||||
|
||||
@Module
|
||||
public interface BungeeTaskModule {
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindTPSCounter(ProxyTPSCounter counter);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindPingCounter(BungeePingCounter counter);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindNetworkConfigStoreTask(NetworkConfigStoreTask configStoreTask);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindExtensionServerDataUpdater(ExtensionServerDataUpdater extensionServerDataUpdater);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindLogCleanTask(LogsFolderCleanTask logsFolderCleanTask);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindDBCleanTask(DBCleanTask cleanTask);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindJSONCacheCleanTask(JSONCache.CleanTask cleanTask);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindRamAndCpuTask(SystemUsageBuffer.RamAndCpuTask ramAndCpuTask);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindDiskTask(SystemUsageBuffer.DiskTask diskTask);
|
||||
|
||||
}
|
@ -47,4 +47,8 @@ public interface PlanPlugin extends IPlugin {
|
||||
}
|
||||
|
||||
void registerCommand(Subcommand command);
|
||||
|
||||
default void cancelAllTasks() {
|
||||
getRunnableFactory().cancelAllKnownTasks();
|
||||
}
|
||||
}
|
||||
|
@ -17,31 +17,36 @@
|
||||
package com.djrapitops.plan;
|
||||
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.PluginRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* TaskSystem that registers tasks that were previously registered inside Plugin classes.
|
||||
*
|
||||
* Subclasses register actual tasks.
|
||||
* TaskSystem that registers tasks for the plugin.
|
||||
* See platform specific [Platform]TaskModule classes for what Tasks are registered.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public abstract class TaskSystem implements SubSystem {
|
||||
@Singleton
|
||||
public class TaskSystem implements SubSystem {
|
||||
|
||||
protected final RunnableFactory runnableFactory;
|
||||
private final RunnableFactory runnableFactory;
|
||||
private final Set<Task> tasks;
|
||||
|
||||
protected TaskSystem(RunnableFactory runnableFactory) {
|
||||
@Inject
|
||||
public TaskSystem(
|
||||
RunnableFactory runnableFactory,
|
||||
Set<Task> tasks
|
||||
) {
|
||||
this.runnableFactory = runnableFactory;
|
||||
this.tasks = tasks;
|
||||
}
|
||||
|
||||
protected PluginRunnable registerTask(AbsRunnable runnable) {
|
||||
String taskName = runnable.getClass().getSimpleName();
|
||||
return registerTask(taskName, runnable);
|
||||
}
|
||||
|
||||
public PluginRunnable registerTask(String name, AbsRunnable runnable) {
|
||||
return runnableFactory.create(name, runnable);
|
||||
@Override
|
||||
public void enable() {
|
||||
for (Task task : tasks) task.register(runnableFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -49,4 +54,8 @@ public abstract class TaskSystem implements SubSystem {
|
||||
runnableFactory.cancelAllKnownTasks();
|
||||
}
|
||||
|
||||
public static abstract class Task extends AbsRunnable {
|
||||
public abstract void register(RunnableFactory runnableFactory);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,7 +16,6 @@
|
||||
*/
|
||||
package com.djrapitops.plan.delivery.export;
|
||||
|
||||
import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plan.identification.Server;
|
||||
import com.djrapitops.plan.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.settings.config.paths.ExportSettings;
|
||||
@ -24,6 +23,7 @@ import com.djrapitops.plan.storage.database.DBSystem;
|
||||
import com.djrapitops.plan.storage.database.queries.objects.ServerQueries;
|
||||
import com.djrapitops.plan.utilities.logging.ErrorLogger;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
@ -41,8 +41,8 @@ public class ExportScheduler {
|
||||
|
||||
private final PlanConfig config;
|
||||
private final DBSystem dbSystem;
|
||||
private final TaskSystem taskSystem;
|
||||
|
||||
private final RunnableFactory runnableFactory;
|
||||
private final Exporter exporter;
|
||||
private final ErrorLogger errorLogger;
|
||||
|
||||
@ -50,13 +50,13 @@ public class ExportScheduler {
|
||||
public ExportScheduler(
|
||||
PlanConfig config,
|
||||
DBSystem dbSystem,
|
||||
TaskSystem taskSystem,
|
||||
RunnableFactory runnableFactory,
|
||||
Exporter exporter,
|
||||
ErrorLogger errorLogger
|
||||
) {
|
||||
this.config = config;
|
||||
this.dbSystem = dbSystem;
|
||||
this.taskSystem = taskSystem;
|
||||
this.runnableFactory = runnableFactory;
|
||||
this.exporter = exporter;
|
||||
this.errorLogger = errorLogger;
|
||||
}
|
||||
@ -68,7 +68,7 @@ public class ExportScheduler {
|
||||
|
||||
private void schedulePlayersPageExport() {
|
||||
long period = TimeAmount.toTicks(config.get(ExportSettings.EXPORT_PERIOD), TimeUnit.MILLISECONDS);
|
||||
taskSystem.registerTask("Players page export",
|
||||
runnableFactory.create("Players page export",
|
||||
new ExportTask(exporter, Exporter::exportPlayersPage, errorLogger)
|
||||
).runTaskTimerAsynchronously(0L, period);
|
||||
}
|
||||
@ -84,14 +84,14 @@ public class ExportScheduler {
|
||||
long offset = period / serverCount;
|
||||
|
||||
Optional<Server> proxy = servers.stream().filter(Server::isProxy).findFirst();
|
||||
proxy.ifPresent(mainServer -> taskSystem.registerTask("Network export",
|
||||
proxy.ifPresent(mainServer -> runnableFactory.create("Network export",
|
||||
new ExportTask(exporter, same -> same.exportServerPage(mainServer), errorLogger))
|
||||
.runTaskTimerAsynchronously(0L, period)
|
||||
);
|
||||
|
||||
int offsetMultiplier = proxy.isPresent() ? 1 : 0; // Delay first server export if on a network.
|
||||
for (Server server : servers) {
|
||||
taskSystem.registerTask("Server export",
|
||||
runnableFactory.create("Server export",
|
||||
new ExportTask(exporter, same -> {
|
||||
same.exportServerPage(server);
|
||||
same.exportServerJSON(server);
|
||||
|
@ -16,11 +16,13 @@
|
||||
*/
|
||||
package com.djrapitops.plan.delivery.webserver.cache;
|
||||
|
||||
import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plan.delivery.web.resolver.MimeType;
|
||||
import com.djrapitops.plan.delivery.web.resolver.Response;
|
||||
import com.djrapitops.plan.delivery.webserver.resolver.json.RootJSONResolver;
|
||||
import com.djrapitops.plan.storage.file.ResourceCache;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -141,7 +143,7 @@ public class JSONCache {
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class CleanTask extends AbsRunnable {
|
||||
public static class CleanTask extends TaskSystem.Task {
|
||||
|
||||
@Inject
|
||||
public CleanTask() {
|
||||
@ -153,5 +155,11 @@ public class JSONCache {
|
||||
cleanUp();
|
||||
ResourceCache.cleanUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(RunnableFactory runnableFactory) {
|
||||
long minute = TimeAmount.toTicks(1, TimeUnit.MINUTES);
|
||||
runnableFactory.create(null, this).runTaskTimerAsynchronously(minute, minute);
|
||||
}
|
||||
}
|
||||
}
|
@ -16,10 +16,15 @@
|
||||
*/
|
||||
package com.djrapitops.plan.extension;
|
||||
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plan.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.settings.config.paths.TimeSettings;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Task for updating {@link DataExtension} server values periodically.
|
||||
@ -27,17 +32,29 @@ import javax.inject.Singleton;
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
public class ExtensionServerMethodCallerTask extends AbsRunnable {
|
||||
public class ExtensionServerDataUpdater extends TaskSystem.Task {
|
||||
|
||||
private final ExtensionSvc service;
|
||||
private final PlanConfig config;
|
||||
|
||||
@Inject
|
||||
public ExtensionServerMethodCallerTask(ExtensionSvc service) {
|
||||
public ExtensionServerDataUpdater(
|
||||
ExtensionSvc service,
|
||||
PlanConfig config
|
||||
) {
|
||||
this.service = service;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
service.updateServerValues(CallEvents.SERVER_PERIODICAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(RunnableFactory runnableFactory) {
|
||||
long period = TimeAmount.toTicks(config.get(TimeSettings.EXTENSION_DATA_REFRESH_PERIOD), TimeUnit.MILLISECONDS);
|
||||
long delay = TimeAmount.toTicks(30, TimeUnit.SECONDS);
|
||||
runnableFactory.create(null, this).runTaskTimerAsynchronously(delay, period);
|
||||
}
|
||||
}
|
@ -16,6 +16,9 @@
|
||||
*/
|
||||
package com.djrapitops.plan.gathering;
|
||||
|
||||
import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
@ -78,4 +81,22 @@ public class ShutdownHook extends Thread {
|
||||
Logger.getGlobal().log(Level.SEVERE, "Plan failed to save sessions on JVM shutdown.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class Registrar extends TaskSystem.Task {
|
||||
private final ShutdownHook shutdownHook;
|
||||
|
||||
@Inject
|
||||
public Registrar(ShutdownHook shutdownHook) {this.shutdownHook = shutdownHook;}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
shutdownHook.register();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(RunnableFactory runnableFactory) {
|
||||
runnableFactory.create(null, this).runTaskAsynchronously();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,17 +16,20 @@
|
||||
*/
|
||||
package com.djrapitops.plan.gathering.timed;
|
||||
|
||||
import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plan.gathering.SystemUsage;
|
||||
import com.djrapitops.plan.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.settings.config.paths.DataGatheringSettings;
|
||||
import com.djrapitops.plan.utilities.logging.ErrorContext;
|
||||
import com.djrapitops.plan.utilities.logging.ErrorLogger;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Task for performing system resource usage checks asynchronously
|
||||
@ -64,7 +67,7 @@ public class SystemUsageBuffer {
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class RamAndCpuTask extends AbsRunnable {
|
||||
public static class RamAndCpuTask extends TaskSystem.Task {
|
||||
private final SystemUsageBuffer buffer;
|
||||
private final PluginLogger logger;
|
||||
|
||||
@ -84,10 +87,17 @@ public class SystemUsageBuffer {
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(RunnableFactory runnableFactory) {
|
||||
long delay = TimeAmount.toTicks(1, TimeUnit.MINUTES) - TimeAmount.toTicks(500, TimeUnit.MILLISECONDS);
|
||||
long period = TimeAmount.toTicks(1, TimeUnit.SECONDS);
|
||||
runnableFactory.create(null, this).runTaskTimerAsynchronously(delay, period);
|
||||
}
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class DiskTask extends AbsRunnable {
|
||||
public static class DiskTask extends TaskSystem.Task {
|
||||
private final PlanConfig config;
|
||||
private final SystemUsageBuffer buffer;
|
||||
private final PluginLogger logger;
|
||||
@ -121,6 +131,13 @@ public class SystemUsageBuffer {
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(RunnableFactory runnableFactory) {
|
||||
long delay = TimeAmount.toTicks(50, TimeUnit.SECONDS);
|
||||
long period = TimeAmount.toTicks(1, TimeUnit.SECONDS);
|
||||
runnableFactory.create(null, this).runTaskTimerAsynchronously(delay, period);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,18 +16,22 @@
|
||||
*/
|
||||
package com.djrapitops.plan.gathering.timed;
|
||||
|
||||
import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plan.utilities.logging.ErrorContext;
|
||||
import com.djrapitops.plan.utilities.logging.ErrorLogger;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Class responsible for calculating TPS every second.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public abstract class TPSCounter extends AbsRunnable {
|
||||
public abstract class TPSCounter extends TaskSystem.Task {
|
||||
|
||||
protected final PluginLogger logger;
|
||||
protected final ErrorLogger errorLogger;
|
||||
@ -51,6 +55,12 @@ public abstract class TPSCounter extends AbsRunnable {
|
||||
}
|
||||
}
|
||||
|
||||
public void register(RunnableFactory runnableFactory) {
|
||||
long delay = TimeAmount.toTicks(1L, TimeUnit.MINUTES);
|
||||
long period = TimeAmount.toTicks(1L, TimeUnit.SECONDS);
|
||||
runnableFactory.create(null, this).runTaskTimer(delay, period);
|
||||
}
|
||||
|
||||
public abstract void pulse();
|
||||
|
||||
}
|
||||
|
@ -17,7 +17,6 @@
|
||||
package com.djrapitops.plan.settings.network;
|
||||
|
||||
import com.djrapitops.plan.SubSystem;
|
||||
import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plan.identification.ServerInfo;
|
||||
import com.djrapitops.plan.settings.config.Config;
|
||||
import com.djrapitops.plan.settings.config.ConfigReader;
|
||||
@ -35,6 +34,7 @@ import com.djrapitops.plan.utilities.logging.ErrorLogger;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
@ -62,8 +62,8 @@ public class ServerSettingsManager implements SubSystem {
|
||||
private final PlanConfig config;
|
||||
private final DBSystem dbSystem;
|
||||
private final ServerInfo serverInfo;
|
||||
private final TaskSystem taskSystem;
|
||||
private final ErrorLogger errorLogger;
|
||||
private final RunnableFactory runnableFactory;
|
||||
private final PluginLogger logger;
|
||||
private FileWatcher watcher;
|
||||
|
||||
@ -73,7 +73,7 @@ public class ServerSettingsManager implements SubSystem {
|
||||
PlanConfig config,
|
||||
DBSystem dbSystem,
|
||||
ServerInfo serverInfo,
|
||||
TaskSystem taskSystem,
|
||||
RunnableFactory runnableFactory,
|
||||
PluginLogger logger,
|
||||
ErrorLogger errorLogger
|
||||
) {
|
||||
@ -81,7 +81,7 @@ public class ServerSettingsManager implements SubSystem {
|
||||
this.config = config;
|
||||
this.dbSystem = dbSystem;
|
||||
this.serverInfo = serverInfo;
|
||||
this.taskSystem = taskSystem;
|
||||
this.runnableFactory = runnableFactory;
|
||||
this.logger = logger;
|
||||
this.errorLogger = errorLogger;
|
||||
}
|
||||
@ -125,7 +125,8 @@ public class ServerSettingsManager implements SubSystem {
|
||||
|
||||
private void scheduleDBCheckTask() {
|
||||
long checkPeriod = TimeAmount.toTicks(config.get(TimeSettings.CONFIG_UPDATE_INTERVAL), TimeUnit.MILLISECONDS);
|
||||
taskSystem.registerTask("Config Update DB Checker", new AbsRunnable() {
|
||||
|
||||
runnableFactory.create("Config Update DB Checker", new AbsRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
checkDBForNewConfigSettings(dbSystem.getDatabase());
|
||||
|
@ -16,16 +16,20 @@
|
||||
*/
|
||||
package com.djrapitops.plan.settings.upkeep;
|
||||
|
||||
import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plan.identification.ServerInfo;
|
||||
import com.djrapitops.plan.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.settings.config.paths.TimeSettings;
|
||||
import com.djrapitops.plan.storage.database.DBSystem;
|
||||
import com.djrapitops.plan.storage.database.transactions.StoreConfigTransaction;
|
||||
import com.djrapitops.plan.storage.file.PlanFiles;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Task that stores a server config in the database on boot.
|
||||
@ -33,7 +37,7 @@ import javax.inject.Singleton;
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
public class ConfigStoreTask extends AbsRunnable {
|
||||
public class ConfigStoreTask extends TaskSystem.Task {
|
||||
|
||||
private final PlanFiles files;
|
||||
private final PlanConfig config;
|
||||
@ -63,4 +67,10 @@ public class ConfigStoreTask extends AbsRunnable {
|
||||
logger.debug("Config Store Task - Config in db now up to date.");
|
||||
cancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(RunnableFactory runnableFactory) {
|
||||
long delay = TimeAmount.toTicks(config.get(TimeSettings.CONFIG_UPDATE_INTERVAL), TimeUnit.MILLISECONDS) + 40;
|
||||
runnableFactory.create(null, this).runTaskLaterAsynchronously(delay);
|
||||
}
|
||||
}
|
@ -16,13 +16,18 @@
|
||||
*/
|
||||
package com.djrapitops.plan.settings.upkeep;
|
||||
|
||||
import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plan.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.settings.config.paths.TimeSettings;
|
||||
import com.djrapitops.plan.settings.network.NetworkSettingManager;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.io.File;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Task on networks that stores server configs in /plugins/Plan/serverConfiguration in database on boot.
|
||||
@ -30,14 +35,17 @@ import java.util.UUID;
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
public class NetworkConfigStoreTask extends AbsRunnable {
|
||||
public class NetworkConfigStoreTask extends TaskSystem.Task {
|
||||
|
||||
private final NetworkSettingManager networkSettingManager;
|
||||
private final PlanConfig config;
|
||||
|
||||
@Inject
|
||||
public NetworkConfigStoreTask(
|
||||
PlanConfig config,
|
||||
NetworkSettingManager networkSettingManager
|
||||
) {
|
||||
this.config = config;
|
||||
this.networkSettingManager = networkSettingManager;
|
||||
}
|
||||
|
||||
@ -47,6 +55,13 @@ public class NetworkConfigStoreTask extends AbsRunnable {
|
||||
cancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(RunnableFactory runnableFactory) {
|
||||
long delay = TimeAmount.toTicks(config.get(TimeSettings.CONFIG_UPDATE_INTERVAL), TimeUnit.MILLISECONDS) + 40;
|
||||
|
||||
runnableFactory.create(null, this).runTaskLaterAsynchronously(delay);
|
||||
}
|
||||
|
||||
private void updateDBConfigs() {
|
||||
File[] configFiles = networkSettingManager.getConfigFiles();
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.djrapitops.plan.storage.upkeep;
|
||||
|
||||
import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plan.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveUnsatisfiedConditionalPlayerResultsTransaction;
|
||||
import com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveUnsatisfiedConditionalServerResultsTransaction;
|
||||
@ -35,9 +36,10 @@ import com.djrapitops.plan.storage.database.transactions.init.RemoveDuplicateUse
|
||||
import com.djrapitops.plan.storage.database.transactions.init.RemoveOldExtensionsTransaction;
|
||||
import com.djrapitops.plan.storage.database.transactions.init.RemoveOldSampledDataTransaction;
|
||||
import com.djrapitops.plan.utilities.logging.ErrorLogger;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
@ -47,6 +49,7 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.djrapitops.plan.storage.database.sql.building.Sql.*;
|
||||
|
||||
@ -56,7 +59,7 @@ import static com.djrapitops.plan.storage.database.sql.building.Sql.*;
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
public class DBCleanTask extends AbsRunnable {
|
||||
public class DBCleanTask extends TaskSystem.Task {
|
||||
|
||||
private final Locale locale;
|
||||
private final DBSystem dbSystem;
|
||||
@ -120,6 +123,13 @@ public class DBCleanTask extends AbsRunnable {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(RunnableFactory runnableFactory) {
|
||||
long delay = TimeAmount.toTicks(20, TimeUnit.SECONDS);
|
||||
long period = TimeAmount.toTicks(config.get(TimeSettings.CLEAN_DATABASE_PERIOD), TimeUnit.MILLISECONDS);
|
||||
runnableFactory.create(null, this).runTaskTimerAsynchronously(delay, period);
|
||||
}
|
||||
|
||||
// VisibleForTesting
|
||||
public int cleanOldPlayers(Database database) {
|
||||
long now = System.currentTimeMillis();
|
||||
|
@ -16,11 +16,13 @@
|
||||
*/
|
||||
package com.djrapitops.plan.storage.upkeep;
|
||||
|
||||
import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plan.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.settings.config.paths.PluginSettings;
|
||||
import com.djrapitops.plan.storage.file.PlanFiles;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
@ -36,7 +38,7 @@ import java.util.concurrent.TimeUnit;
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
public class LogsFolderCleanTask extends AbsRunnable {
|
||||
public class LogsFolderCleanTask extends TaskSystem.Task {
|
||||
|
||||
private final File folder;
|
||||
private final PlanConfig config;
|
||||
@ -71,6 +73,12 @@ public class LogsFolderCleanTask extends AbsRunnable {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(RunnableFactory runnableFactory) {
|
||||
long delay = TimeAmount.toTicks(30L, TimeUnit.SECONDS);
|
||||
runnableFactory.create(null, this).runTaskLaterAsynchronously(delay);
|
||||
}
|
||||
|
||||
private void cleanFolder() {
|
||||
long now = System.currentTimeMillis();
|
||||
for (File file : Objects.requireNonNull(folder.listFiles())) {
|
||||
|
@ -19,16 +19,19 @@ package utilities.dagger;
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plan.gathering.ServerSensor;
|
||||
import com.djrapitops.plan.gathering.importing.importers.Importer;
|
||||
import com.djrapitops.plan.gathering.listeners.ListenerSystem;
|
||||
import com.djrapitops.plan.processing.Processing;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import dagger.multibindings.ElementsIntoSet;
|
||||
import org.mockito.Mockito;
|
||||
import utilities.mocks.TestProcessing;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ -41,13 +44,15 @@ import static org.mockito.Mockito.when;
|
||||
public class PluginSuperClassBindingModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
TaskSystem provideTaskSystem(RunnableFactory runnableFactory) {
|
||||
return new TaskSystem(runnableFactory) {
|
||||
@Override
|
||||
public void enable() {
|
||||
}
|
||||
};
|
||||
@ElementsIntoSet
|
||||
Set<Importer> provideEmptyImporterSet() {
|
||||
return new HashSet<>();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@ElementsIntoSet
|
||||
Set<TaskSystem.Task> provideEmptyTaskSet() {
|
||||
return new HashSet<>();
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -1,151 +0,0 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan;
|
||||
|
||||
import cn.nukkit.Server;
|
||||
import cn.nukkit.level.Level;
|
||||
import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
|
||||
import com.djrapitops.plan.extension.ExtensionServerMethodCallerTask;
|
||||
import com.djrapitops.plan.gathering.ShutdownHook;
|
||||
import com.djrapitops.plan.gathering.timed.NukkitPingCounter;
|
||||
import com.djrapitops.plan.gathering.timed.ServerTPSCounter;
|
||||
import com.djrapitops.plan.gathering.timed.SystemUsageBuffer;
|
||||
import com.djrapitops.plan.gathering.timed.TPSCounter;
|
||||
import com.djrapitops.plan.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.settings.config.paths.DataGatheringSettings;
|
||||
import com.djrapitops.plan.settings.config.paths.TimeSettings;
|
||||
import com.djrapitops.plan.settings.upkeep.ConfigStoreTask;
|
||||
import com.djrapitops.plan.storage.upkeep.DBCleanTask;
|
||||
import com.djrapitops.plan.storage.upkeep.LogsFolderCleanTask;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* TaskSystem responsible for registering tasks for Nukkit.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
public class NukkitTaskSystem extends TaskSystem {
|
||||
|
||||
private final PlanNukkit plugin;
|
||||
private final PlanConfig config;
|
||||
private final ShutdownHook shutdownHook;
|
||||
private final JSONCache.CleanTask jsonCacheCleanTask;
|
||||
private final LogsFolderCleanTask logsFolderCleanTask;
|
||||
private final TPSCounter tpsCounter;
|
||||
private final NukkitPingCounter pingCounter;
|
||||
private final ConfigStoreTask configStoreTask;
|
||||
private final DBCleanTask dbCleanTask;
|
||||
private final SystemUsageBuffer.RamAndCpuTask ramAndCpuTask;
|
||||
private final SystemUsageBuffer.DiskTask diskTask;
|
||||
private final ExtensionServerMethodCallerTask extensionServerMethodCallerTask;
|
||||
|
||||
@Inject
|
||||
public NukkitTaskSystem(
|
||||
PlanNukkit plugin,
|
||||
PlanConfig config,
|
||||
ShutdownHook shutdownHook,
|
||||
RunnableFactory runnableFactory,
|
||||
|
||||
ServerTPSCounter<Level> tpsCounter,
|
||||
NukkitPingCounter pingCounter,
|
||||
ExtensionServerMethodCallerTask extensionServerMethodCallerTask,
|
||||
|
||||
LogsFolderCleanTask logsFolderCleanTask,
|
||||
ConfigStoreTask configStoreTask,
|
||||
DBCleanTask dbCleanTask,
|
||||
JSONCache.CleanTask jsonCacheCleanTask,
|
||||
SystemUsageBuffer.RamAndCpuTask ramAndCpuTask,
|
||||
SystemUsageBuffer.DiskTask diskTask
|
||||
) {
|
||||
super(runnableFactory);
|
||||
this.plugin = plugin;
|
||||
this.config = config;
|
||||
this.shutdownHook = shutdownHook;
|
||||
this.jsonCacheCleanTask = jsonCacheCleanTask;
|
||||
|
||||
this.tpsCounter = tpsCounter;
|
||||
this.pingCounter = pingCounter;
|
||||
this.extensionServerMethodCallerTask = extensionServerMethodCallerTask;
|
||||
|
||||
this.logsFolderCleanTask = logsFolderCleanTask;
|
||||
this.configStoreTask = configStoreTask;
|
||||
this.dbCleanTask = dbCleanTask;
|
||||
this.ramAndCpuTask = ramAndCpuTask;
|
||||
this.diskTask = diskTask;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
registerTPSCounter();
|
||||
registerPingCounter();
|
||||
registerExtensionDataGatheringTask();
|
||||
registerUpkeepTasks();
|
||||
|
||||
shutdownHook.register();
|
||||
}
|
||||
|
||||
private void registerUpkeepTasks() {
|
||||
// +40 ticks / 2 seconds so that update check task runs first.
|
||||
long storeDelay = TimeAmount.toTicks(config.get(TimeSettings.CONFIG_UPDATE_INTERVAL), TimeUnit.MILLISECONDS) + 40;
|
||||
registerTask(configStoreTask).runTaskLaterAsynchronously(storeDelay);
|
||||
registerTask(logsFolderCleanTask).runTaskLaterAsynchronously(TimeAmount.toTicks(30L, TimeUnit.SECONDS));
|
||||
registerTask(dbCleanTask).runTaskTimerAsynchronously(
|
||||
TimeAmount.toTicks(20, TimeUnit.SECONDS),
|
||||
TimeAmount.toTicks(config.get(TimeSettings.CLEAN_DATABASE_PERIOD), TimeUnit.MILLISECONDS)
|
||||
);
|
||||
long minute = TimeAmount.toTicks(1, TimeUnit.MINUTES);
|
||||
registerTask(jsonCacheCleanTask).runTaskTimerAsynchronously(minute, minute);
|
||||
}
|
||||
|
||||
private void registerTPSCounter() {
|
||||
long halfSecondTicks = TimeAmount.toTicks(500L, TimeUnit.MILLISECONDS);
|
||||
long secondTicks = TimeAmount.toTicks(1L, TimeUnit.SECONDS);
|
||||
long minuteTicks = TimeAmount.toTicks(1L, TimeUnit.MINUTES);
|
||||
registerTask(tpsCounter).runTaskTimer(minuteTicks, secondTicks);
|
||||
registerTask(ramAndCpuTask).runTaskTimerAsynchronously(minuteTicks - halfSecondTicks, secondTicks);
|
||||
registerTask(diskTask).runTaskTimerAsynchronously(50L * secondTicks, minuteTicks);
|
||||
}
|
||||
|
||||
private void registerPingCounter() {
|
||||
Long pingDelay = config.get(TimeSettings.PING_SERVER_ENABLE_DELAY);
|
||||
if (pingDelay < TimeUnit.HOURS.toMillis(1L) && config.isTrue(DataGatheringSettings.PING)) {
|
||||
plugin.registerListener(pingCounter);
|
||||
long startDelay = TimeAmount.toTicks(pingDelay, TimeUnit.MILLISECONDS);
|
||||
registerTask(pingCounter).runTaskTimer(startDelay, 40L);
|
||||
}
|
||||
}
|
||||
|
||||
private void registerExtensionDataGatheringTask() {
|
||||
long extensionRefreshPeriod = TimeAmount.toTicks(config.get(TimeSettings.EXTENSION_DATA_REFRESH_PERIOD), TimeUnit.MILLISECONDS);
|
||||
registerTask(extensionServerMethodCallerTask).runTaskTimerAsynchronously(
|
||||
TimeAmount.toTicks(30, TimeUnit.SECONDS), extensionRefreshPeriod
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
super.disable();
|
||||
Optional.ofNullable(Server.getInstance().getScheduler()).ifPresent(scheduler -> scheduler.cancelTask(plugin));
|
||||
}
|
||||
}
|
@ -17,6 +17,7 @@
|
||||
package com.djrapitops.plan;
|
||||
|
||||
import cn.nukkit.Player;
|
||||
import cn.nukkit.Server;
|
||||
import cn.nukkit.command.Command;
|
||||
import cn.nukkit.command.CommandSender;
|
||||
import com.djrapitops.plan.addons.placeholderapi.NukkitPlaceholderRegistrar;
|
||||
@ -36,6 +37,7 @@ import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@ -98,16 +100,19 @@ public class PlanNukkit extends NukkitPlugin implements PlanPlugin {
|
||||
*/
|
||||
@Override
|
||||
public void onDisable() {
|
||||
if (serverShutdownSave != null) {
|
||||
serverShutdownSave.performSave();
|
||||
}
|
||||
if (system != null) {
|
||||
system.disable();
|
||||
}
|
||||
if (serverShutdownSave != null) serverShutdownSave.performSave();
|
||||
cancelAllTasks();
|
||||
if (system != null) system.disable();
|
||||
|
||||
logger.info(locale != null ? locale.getString(PluginLang.DISABLED) : PluginLang.DISABLED.getDefault());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelAllTasks() {
|
||||
runnableFactory.cancelAllKnownTasks();
|
||||
Optional.ofNullable(Server.getInstance().getScheduler()).ifPresent(scheduler -> scheduler.cancelTask(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender actualSender, Command actualCommand, String label, String[] args) {
|
||||
String name = actualCommand.getName();
|
||||
|
@ -26,6 +26,7 @@ import com.djrapitops.plan.modules.SystemObjectProvidingModule;
|
||||
import com.djrapitops.plan.modules.nukkit.NukkitPlanModule;
|
||||
import com.djrapitops.plan.modules.nukkit.NukkitServerPropertiesModule;
|
||||
import com.djrapitops.plan.modules.nukkit.NukkitSuperClassBindingModule;
|
||||
import com.djrapitops.plan.modules.nukkit.NukkitTaskModule;
|
||||
import dagger.BindsInstance;
|
||||
import dagger.Component;
|
||||
|
||||
@ -45,7 +46,8 @@ import javax.inject.Singleton;
|
||||
|
||||
ServerCommandModule.class,
|
||||
NukkitServerPropertiesModule.class,
|
||||
NukkitSuperClassBindingModule.class
|
||||
NukkitSuperClassBindingModule.class,
|
||||
NukkitTaskModule.class
|
||||
})
|
||||
public interface PlanNukkitComponent {
|
||||
|
||||
|
@ -29,9 +29,12 @@ import cn.nukkit.event.EventHandler;
|
||||
import cn.nukkit.event.Listener;
|
||||
import cn.nukkit.event.player.PlayerJoinEvent;
|
||||
import cn.nukkit.event.player.PlayerQuitEvent;
|
||||
import com.djrapitops.plan.PlanNukkit;
|
||||
import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plan.delivery.domain.DateObj;
|
||||
import com.djrapitops.plan.identification.ServerInfo;
|
||||
import com.djrapitops.plan.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.settings.config.paths.DataGatheringSettings;
|
||||
import com.djrapitops.plan.settings.config.paths.TimeSettings;
|
||||
import com.djrapitops.plan.storage.database.DBSystem;
|
||||
import com.djrapitops.plan.storage.database.transactions.events.PingStoreTransaction;
|
||||
@ -53,10 +56,11 @@ import java.util.concurrent.TimeUnit;
|
||||
* @author games647
|
||||
*/
|
||||
@Singleton
|
||||
public class NukkitPingCounter extends AbsRunnable implements Listener {
|
||||
public class NukkitPingCounter extends TaskSystem.Task implements Listener {
|
||||
|
||||
private final Map<UUID, List<DateObj<Integer>>> playerHistory;
|
||||
|
||||
private final PlanNukkit plugin;
|
||||
private final PlanConfig config;
|
||||
private final DBSystem dbSystem;
|
||||
private final ServerInfo serverInfo;
|
||||
@ -64,11 +68,13 @@ public class NukkitPingCounter extends AbsRunnable implements Listener {
|
||||
|
||||
@Inject
|
||||
public NukkitPingCounter(
|
||||
PlanNukkit plugin,
|
||||
PlanConfig config,
|
||||
DBSystem dbSystem,
|
||||
ServerInfo serverInfo,
|
||||
RunnableFactory runnableFactory
|
||||
) {
|
||||
this.plugin = plugin;
|
||||
this.config = config;
|
||||
this.dbSystem = dbSystem;
|
||||
this.serverInfo = serverInfo;
|
||||
@ -105,6 +111,17 @@ public class NukkitPingCounter extends AbsRunnable implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(RunnableFactory runnableFactory) {
|
||||
Long enableDelay = config.get(TimeSettings.PING_SERVER_ENABLE_DELAY);
|
||||
if (enableDelay < TimeUnit.HOURS.toMillis(1L) && config.isTrue(DataGatheringSettings.PING)) {
|
||||
plugin.registerListener(this);
|
||||
long delay = TimeAmount.toTicks(enableDelay, TimeUnit.MILLISECONDS);
|
||||
long period = 40L;
|
||||
runnableFactory.create(null, this).runTaskTimer(delay, period);
|
||||
}
|
||||
}
|
||||
|
||||
public void addPlayer(Player player) {
|
||||
playerHistory.put(player.getUniqueId(), new ArrayList<>());
|
||||
}
|
||||
|
@ -18,8 +18,6 @@ package com.djrapitops.plan.modules.nukkit;
|
||||
|
||||
import cn.nukkit.level.Level;
|
||||
import com.djrapitops.plan.NukkitServerShutdownSave;
|
||||
import com.djrapitops.plan.NukkitTaskSystem;
|
||||
import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plan.gathering.NukkitSensor;
|
||||
import com.djrapitops.plan.gathering.ServerSensor;
|
||||
import com.djrapitops.plan.gathering.ServerShutdownSave;
|
||||
@ -51,9 +49,6 @@ public interface NukkitSuperClassBindingModule {
|
||||
@Binds
|
||||
ConfigSystem bindConfigSystem(NukkitConfigSystem configSystem);
|
||||
|
||||
@Binds
|
||||
TaskSystem bindTaskSystem(NukkitTaskSystem taskSystem);
|
||||
|
||||
@Binds
|
||||
ListenerSystem bindListenerSystem(NukkitListenerSystem listenerSystem);
|
||||
|
||||
|
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan.modules.nukkit;
|
||||
|
||||
import cn.nukkit.level.Level;
|
||||
import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
|
||||
import com.djrapitops.plan.extension.ExtensionServerDataUpdater;
|
||||
import com.djrapitops.plan.gathering.ShutdownHook;
|
||||
import com.djrapitops.plan.gathering.timed.NukkitPingCounter;
|
||||
import com.djrapitops.plan.gathering.timed.ServerTPSCounter;
|
||||
import com.djrapitops.plan.gathering.timed.SystemUsageBuffer;
|
||||
import com.djrapitops.plan.settings.upkeep.ConfigStoreTask;
|
||||
import com.djrapitops.plan.storage.upkeep.DBCleanTask;
|
||||
import com.djrapitops.plan.storage.upkeep.LogsFolderCleanTask;
|
||||
import dagger.Binds;
|
||||
import dagger.Module;
|
||||
import dagger.multibindings.IntoSet;
|
||||
|
||||
@Module
|
||||
public interface NukkitTaskModule {
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindTPSCounter(ServerTPSCounter<Level> tpsCounter);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindPingCounter(NukkitPingCounter pingCounter);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindExtensionServerDataUpdater(ExtensionServerDataUpdater extensionServerDataUpdater);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindLogCleanTask(LogsFolderCleanTask logsFolderCleanTask);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindConfigStoreTask(ConfigStoreTask configStoreTask);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindDBCleanTask(DBCleanTask cleanTask);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindJSONCacheCleanTask(JSONCache.CleanTask cleanTask);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindRamAndCpuTask(SystemUsageBuffer.RamAndCpuTask ramAndCpuTask);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindDiskTask(SystemUsageBuffer.DiskTask diskTask);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindShutdownHookRegistration(ShutdownHook.Registrar registrar);
|
||||
|
||||
}
|
@ -38,6 +38,7 @@ import org.spongepowered.api.event.game.state.GameStartedServerEvent;
|
||||
import org.spongepowered.api.event.game.state.GameStoppingServerEvent;
|
||||
import org.spongepowered.api.plugin.Dependency;
|
||||
import org.spongepowered.api.plugin.Plugin;
|
||||
import org.spongepowered.api.scheduler.Task;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
@ -123,16 +124,21 @@ public class PlanSponge extends SpongePlugin implements PlanPlugin {
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
if (serverShutdownSave != null) {
|
||||
serverShutdownSave.performSave();
|
||||
}
|
||||
if (system != null) {
|
||||
system.disable();
|
||||
}
|
||||
if (serverShutdownSave != null) serverShutdownSave.performSave();
|
||||
cancelAllTasks();
|
||||
if (system != null) system.disable();
|
||||
|
||||
logger.info(locale.getString(PluginLang.DISABLED));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelAllTasks() {
|
||||
runnableFactory.cancelAllKnownTasks();
|
||||
for (Task task : Sponge.getScheduler().getScheduledTasks(this)) {
|
||||
task.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getResource(String resource) {
|
||||
return getClass().getResourceAsStream("/" + resource);
|
||||
|
@ -25,6 +25,7 @@ import com.djrapitops.plan.modules.SystemObjectProvidingModule;
|
||||
import com.djrapitops.plan.modules.sponge.SpongePlanModule;
|
||||
import com.djrapitops.plan.modules.sponge.SpongeServerPropertiesModule;
|
||||
import com.djrapitops.plan.modules.sponge.SpongeSuperClassBindingModule;
|
||||
import com.djrapitops.plan.modules.sponge.SpongeTaskModule;
|
||||
import dagger.BindsInstance;
|
||||
import dagger.Component;
|
||||
|
||||
@ -44,7 +45,8 @@ import javax.inject.Singleton;
|
||||
|
||||
ServerCommandModule.class,
|
||||
SpongeSuperClassBindingModule.class,
|
||||
SpongeServerPropertiesModule.class
|
||||
SpongeServerPropertiesModule.class,
|
||||
SpongeTaskModule.class
|
||||
})
|
||||
public interface PlanSpongeComponent {
|
||||
|
||||
|
@ -1,149 +0,0 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan;
|
||||
|
||||
import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
|
||||
import com.djrapitops.plan.extension.ExtensionServerMethodCallerTask;
|
||||
import com.djrapitops.plan.gathering.ShutdownHook;
|
||||
import com.djrapitops.plan.gathering.timed.ServerTPSCounter;
|
||||
import com.djrapitops.plan.gathering.timed.SpongePingCounter;
|
||||
import com.djrapitops.plan.gathering.timed.SystemUsageBuffer;
|
||||
import com.djrapitops.plan.gathering.timed.TPSCounter;
|
||||
import com.djrapitops.plan.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.settings.config.paths.DataGatheringSettings;
|
||||
import com.djrapitops.plan.settings.config.paths.TimeSettings;
|
||||
import com.djrapitops.plan.settings.upkeep.ConfigStoreTask;
|
||||
import com.djrapitops.plan.storage.upkeep.DBCleanTask;
|
||||
import com.djrapitops.plan.storage.upkeep.LogsFolderCleanTask;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.scheduler.Task;
|
||||
import org.spongepowered.api.world.World;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Singleton
|
||||
public class SpongeTaskSystem extends TaskSystem {
|
||||
|
||||
private final PlanSponge plugin;
|
||||
private final PlanConfig config;
|
||||
private final ShutdownHook shutdownHook;
|
||||
private final TPSCounter tpsCounter;
|
||||
private final JSONCache.CleanTask jsonCacheCleanTask;
|
||||
private final SystemUsageBuffer.RamAndCpuTask ramAndCpuTask;
|
||||
private final SystemUsageBuffer.DiskTask diskTask;
|
||||
private final SpongePingCounter pingCounter;
|
||||
private final LogsFolderCleanTask logsFolderCleanTask;
|
||||
private final ConfigStoreTask configStoreTask;
|
||||
private final DBCleanTask dbCleanTask;
|
||||
private final ExtensionServerMethodCallerTask extensionServerMethodCallerTask;
|
||||
|
||||
@Inject
|
||||
public SpongeTaskSystem(
|
||||
PlanSponge plugin,
|
||||
PlanConfig config,
|
||||
ShutdownHook shutdownHook,
|
||||
RunnableFactory runnableFactory,
|
||||
|
||||
ServerTPSCounter<World> tpsCounter,
|
||||
SpongePingCounter pingCounter,
|
||||
ExtensionServerMethodCallerTask extensionServerMethodCallerTask,
|
||||
|
||||
LogsFolderCleanTask logsFolderCleanTask,
|
||||
ConfigStoreTask configStoreTask,
|
||||
DBCleanTask dbCleanTask,
|
||||
JSONCache.CleanTask jsonCacheCleanTask,
|
||||
SystemUsageBuffer.RamAndCpuTask ramAndCpuTask,
|
||||
SystemUsageBuffer.DiskTask diskTask
|
||||
) {
|
||||
super(runnableFactory);
|
||||
this.plugin = plugin;
|
||||
this.config = config;
|
||||
this.shutdownHook = shutdownHook;
|
||||
|
||||
this.tpsCounter = tpsCounter;
|
||||
this.pingCounter = pingCounter;
|
||||
this.extensionServerMethodCallerTask = extensionServerMethodCallerTask;
|
||||
|
||||
this.logsFolderCleanTask = logsFolderCleanTask;
|
||||
this.configStoreTask = configStoreTask;
|
||||
this.dbCleanTask = dbCleanTask;
|
||||
this.jsonCacheCleanTask = jsonCacheCleanTask;
|
||||
|
||||
this.ramAndCpuTask = ramAndCpuTask;
|
||||
this.diskTask = diskTask;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
registerTPSCounter();
|
||||
registerPingCounter();
|
||||
registerExtensionDataGatheringTask();
|
||||
registerUpkeepTasks();
|
||||
|
||||
shutdownHook.register();
|
||||
}
|
||||
|
||||
private void registerUpkeepTasks() {
|
||||
// +40 ticks / 2 seconds so that update check task runs first.
|
||||
long storeDelay = TimeAmount.toTicks(config.get(TimeSettings.CONFIG_UPDATE_INTERVAL), TimeUnit.MILLISECONDS) + 40;
|
||||
registerTask(configStoreTask).runTaskLaterAsynchronously(storeDelay);
|
||||
registerTask(logsFolderCleanTask).runTaskLaterAsynchronously(TimeAmount.toTicks(30L, TimeUnit.SECONDS));
|
||||
registerTask(dbCleanTask).runTaskTimerAsynchronously(
|
||||
TimeAmount.toTicks(20, TimeUnit.SECONDS),
|
||||
TimeAmount.toTicks(config.get(TimeSettings.CLEAN_DATABASE_PERIOD), TimeUnit.MILLISECONDS)
|
||||
);
|
||||
long minute = TimeAmount.toTicks(1, TimeUnit.MINUTES);
|
||||
registerTask(jsonCacheCleanTask).runTaskTimerAsynchronously(minute, minute);
|
||||
}
|
||||
|
||||
private void registerTPSCounter() {
|
||||
long halfSecondTicks = TimeAmount.toTicks(500L, TimeUnit.MILLISECONDS);
|
||||
long secondTicks = TimeAmount.toTicks(1L, TimeUnit.SECONDS);
|
||||
long minuteTicks = TimeAmount.toTicks(1L, TimeUnit.MINUTES);
|
||||
registerTask(tpsCounter).runTaskTimer(minuteTicks, secondTicks);
|
||||
registerTask(ramAndCpuTask).runTaskTimerAsynchronously(minuteTicks - halfSecondTicks, secondTicks);
|
||||
registerTask(diskTask).runTaskTimerAsynchronously(50L * secondTicks, minuteTicks);
|
||||
}
|
||||
|
||||
private void registerPingCounter() {
|
||||
Long pingDelay = config.get(TimeSettings.PING_SERVER_ENABLE_DELAY);
|
||||
if (pingDelay < TimeUnit.HOURS.toMillis(1L) && config.isTrue(DataGatheringSettings.PING)) {
|
||||
plugin.registerListener(pingCounter);
|
||||
long startDelay = TimeAmount.toTicks(pingDelay, TimeUnit.MILLISECONDS);
|
||||
registerTask(pingCounter).runTaskTimer(startDelay, 40L);
|
||||
}
|
||||
}
|
||||
|
||||
private void registerExtensionDataGatheringTask() {
|
||||
long extensionRefreshPeriod = TimeAmount.toTicks(config.get(TimeSettings.EXTENSION_DATA_REFRESH_PERIOD), TimeUnit.MILLISECONDS);
|
||||
registerTask(extensionServerMethodCallerTask).runTaskTimerAsynchronously(
|
||||
TimeAmount.toTicks(30, TimeUnit.SECONDS), extensionRefreshPeriod
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
super.disable();
|
||||
for (Task task : Sponge.getScheduler().getScheduledTasks(plugin)) {
|
||||
task.cancel();
|
||||
}
|
||||
}
|
||||
}
|
@ -23,9 +23,12 @@
|
||||
*/
|
||||
package com.djrapitops.plan.gathering.timed;
|
||||
|
||||
import com.djrapitops.plan.PlanSponge;
|
||||
import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plan.delivery.domain.DateObj;
|
||||
import com.djrapitops.plan.identification.ServerInfo;
|
||||
import com.djrapitops.plan.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.settings.config.paths.DataGatheringSettings;
|
||||
import com.djrapitops.plan.settings.config.paths.TimeSettings;
|
||||
import com.djrapitops.plan.storage.database.DBSystem;
|
||||
import com.djrapitops.plan.storage.database.transactions.events.PingStoreTransaction;
|
||||
@ -46,10 +49,11 @@ import java.util.concurrent.TimeUnit;
|
||||
*
|
||||
* @author BrainStone
|
||||
*/
|
||||
public class SpongePingCounter extends AbsRunnable {
|
||||
public class SpongePingCounter extends TaskSystem.Task {
|
||||
|
||||
private final Map<UUID, List<DateObj<Integer>>> playerHistory;
|
||||
|
||||
private final PlanSponge plugin;
|
||||
private final PlanConfig config;
|
||||
private final DBSystem dbSystem;
|
||||
private final ServerInfo serverInfo;
|
||||
@ -57,11 +61,13 @@ public class SpongePingCounter extends AbsRunnable {
|
||||
|
||||
@Inject
|
||||
public SpongePingCounter(
|
||||
PlanSponge plugin,
|
||||
PlanConfig config,
|
||||
DBSystem dbSystem,
|
||||
ServerInfo serverInfo,
|
||||
RunnableFactory runnableFactory
|
||||
) {
|
||||
this.plugin = plugin;
|
||||
this.config = config;
|
||||
this.dbSystem = dbSystem;
|
||||
this.serverInfo = serverInfo;
|
||||
@ -98,6 +104,17 @@ public class SpongePingCounter extends AbsRunnable {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(RunnableFactory runnableFactory) {
|
||||
Long startDelay = config.get(TimeSettings.PING_SERVER_ENABLE_DELAY);
|
||||
if (startDelay < TimeUnit.HOURS.toMillis(1L) && config.isTrue(DataGatheringSettings.PING)) {
|
||||
plugin.registerListener(this);
|
||||
long delay = TimeAmount.toTicks(startDelay, TimeUnit.MILLISECONDS);
|
||||
long period = 40L;
|
||||
runnableFactory.create(null, this).runTaskTimer(delay, period);
|
||||
}
|
||||
}
|
||||
|
||||
public void addPlayer(Player player) {
|
||||
playerHistory.put(player.getUniqueId(), new ArrayList<>());
|
||||
}
|
||||
|
@ -17,8 +17,6 @@
|
||||
package com.djrapitops.plan.modules.sponge;
|
||||
|
||||
import com.djrapitops.plan.SpongeServerShutdownSave;
|
||||
import com.djrapitops.plan.SpongeTaskSystem;
|
||||
import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plan.gathering.ServerSensor;
|
||||
import com.djrapitops.plan.gathering.ServerShutdownSave;
|
||||
import com.djrapitops.plan.gathering.SpongeSensor;
|
||||
@ -56,9 +54,6 @@ public interface SpongeSuperClassBindingModule {
|
||||
@Binds
|
||||
ConfigSystem bindConfigSystem(SpongeConfigSystem configSystem);
|
||||
|
||||
@Binds
|
||||
TaskSystem bindTaskSystem(SpongeTaskSystem taskSystem);
|
||||
|
||||
@Binds
|
||||
ListenerSystem bindListenerSystem(SpongeListenerSystem listenerSystem);
|
||||
|
||||
|
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan.modules.sponge;
|
||||
|
||||
import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
|
||||
import com.djrapitops.plan.extension.ExtensionServerDataUpdater;
|
||||
import com.djrapitops.plan.gathering.ShutdownHook;
|
||||
import com.djrapitops.plan.gathering.timed.ServerTPSCounter;
|
||||
import com.djrapitops.plan.gathering.timed.SpongePingCounter;
|
||||
import com.djrapitops.plan.gathering.timed.SystemUsageBuffer;
|
||||
import com.djrapitops.plan.settings.upkeep.ConfigStoreTask;
|
||||
import com.djrapitops.plan.storage.upkeep.DBCleanTask;
|
||||
import com.djrapitops.plan.storage.upkeep.LogsFolderCleanTask;
|
||||
import dagger.Binds;
|
||||
import dagger.Module;
|
||||
import dagger.multibindings.IntoSet;
|
||||
import org.spongepowered.api.world.World;
|
||||
|
||||
@Module
|
||||
public interface SpongeTaskModule {
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindTPSCounter(ServerTPSCounter<World> tpsCounter);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindPingCounter(SpongePingCounter pingCounter);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindExtensionServerDataUpdater(ExtensionServerDataUpdater extensionServerDataUpdater);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindLogCleanTask(LogsFolderCleanTask logsFolderCleanTask);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindConfigStoreTask(ConfigStoreTask configStoreTask);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindDBCleanTask(DBCleanTask cleanTask);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindJSONCacheCleanTask(JSONCache.CleanTask cleanTask);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindRamAndCpuTask(SystemUsageBuffer.RamAndCpuTask ramAndCpuTask);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindDiskTask(SystemUsageBuffer.DiskTask diskTask);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindShutdownHookRegistration(ShutdownHook.Registrar registrar);
|
||||
|
||||
}
|
@ -102,7 +102,8 @@ public class PlanVelocity extends VelocityPlugin implements PlanPlugin {
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
system.disable();
|
||||
cancelAllTasks();
|
||||
if (system != null) system.disable();
|
||||
|
||||
logger.info(locale.getString(PluginLang.DISABLED));
|
||||
}
|
||||
|
@ -21,10 +21,7 @@ import com.djrapitops.plan.modules.APFModule;
|
||||
import com.djrapitops.plan.modules.PlaceholderModule;
|
||||
import com.djrapitops.plan.modules.ProxySuperClassBindingModule;
|
||||
import com.djrapitops.plan.modules.SystemObjectProvidingModule;
|
||||
import com.djrapitops.plan.modules.velocity.VelocityCommandModule;
|
||||
import com.djrapitops.plan.modules.velocity.VelocityPlanModule;
|
||||
import com.djrapitops.plan.modules.velocity.VelocityServerPropertiesModule;
|
||||
import com.djrapitops.plan.modules.velocity.VelocitySuperClassBindingModule;
|
||||
import com.djrapitops.plan.modules.velocity.*;
|
||||
import dagger.BindsInstance;
|
||||
import dagger.Component;
|
||||
|
||||
@ -45,7 +42,8 @@ import javax.inject.Singleton;
|
||||
|
||||
ProxySuperClassBindingModule.class,
|
||||
VelocitySuperClassBindingModule.class,
|
||||
VelocityServerPropertiesModule.class
|
||||
VelocityServerPropertiesModule.class,
|
||||
VelocityTaskModule.class
|
||||
})
|
||||
public interface PlanVelocityComponent {
|
||||
|
||||
|
@ -1,128 +0,0 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan;
|
||||
|
||||
import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
|
||||
import com.djrapitops.plan.extension.ExtensionServerMethodCallerTask;
|
||||
import com.djrapitops.plan.gathering.timed.ProxyTPSCounter;
|
||||
import com.djrapitops.plan.gathering.timed.SystemUsageBuffer;
|
||||
import com.djrapitops.plan.gathering.timed.TPSCounter;
|
||||
import com.djrapitops.plan.gathering.timed.VelocityPingCounter;
|
||||
import com.djrapitops.plan.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.settings.config.paths.DataGatheringSettings;
|
||||
import com.djrapitops.plan.settings.config.paths.TimeSettings;
|
||||
import com.djrapitops.plan.settings.upkeep.NetworkConfigStoreTask;
|
||||
import com.djrapitops.plan.storage.upkeep.DBCleanTask;
|
||||
import com.djrapitops.plan.storage.upkeep.LogsFolderCleanTask;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* TaskSystem responsible for registering tasks for Velocity.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
public class VelocityTaskSystem extends TaskSystem {
|
||||
|
||||
private final PlanVelocity plugin;
|
||||
private final PlanConfig config;
|
||||
private final TPSCounter tpsCounter;
|
||||
private final VelocityPingCounter pingCounter;
|
||||
private final LogsFolderCleanTask logsFolderCleanTask;
|
||||
private final NetworkConfigStoreTask networkConfigStoreTask;
|
||||
private final DBCleanTask dbCleanTask;
|
||||
private final JSONCache.CleanTask jsonCacheCleanTask;
|
||||
private final ExtensionServerMethodCallerTask extensionServerMethodCallerTask;
|
||||
private final SystemUsageBuffer.RamAndCpuTask ramAndCpuTask;
|
||||
private final SystemUsageBuffer.DiskTask diskTask;
|
||||
|
||||
@Inject
|
||||
public VelocityTaskSystem(
|
||||
PlanVelocity plugin,
|
||||
PlanConfig config,
|
||||
RunnableFactory runnableFactory,
|
||||
ProxyTPSCounter tpsCounter,
|
||||
VelocityPingCounter pingCounter,
|
||||
LogsFolderCleanTask logsFolderCleanTask,
|
||||
NetworkConfigStoreTask networkConfigStoreTask,
|
||||
DBCleanTask dbCleanTask,
|
||||
JSONCache.CleanTask jsonCacheCleanTask,
|
||||
ExtensionServerMethodCallerTask extensionServerMethodCallerTask,
|
||||
SystemUsageBuffer.RamAndCpuTask ramAndCpuTask,
|
||||
SystemUsageBuffer.DiskTask diskTask
|
||||
) {
|
||||
super(runnableFactory);
|
||||
this.plugin = plugin;
|
||||
this.config = config;
|
||||
this.tpsCounter = tpsCounter;
|
||||
this.pingCounter = pingCounter;
|
||||
this.logsFolderCleanTask = logsFolderCleanTask;
|
||||
this.networkConfigStoreTask = networkConfigStoreTask;
|
||||
this.dbCleanTask = dbCleanTask;
|
||||
this.jsonCacheCleanTask = jsonCacheCleanTask;
|
||||
this.extensionServerMethodCallerTask = extensionServerMethodCallerTask;
|
||||
this.ramAndCpuTask = ramAndCpuTask;
|
||||
this.diskTask = diskTask;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
registerTasks();
|
||||
}
|
||||
|
||||
private void registerTPSCounter() {
|
||||
long halfSecondTicks = TimeAmount.toTicks(500L, TimeUnit.MILLISECONDS);
|
||||
long secondTicks = TimeAmount.toTicks(1L, TimeUnit.SECONDS);
|
||||
long minuteTicks = TimeAmount.toTicks(1L, TimeUnit.MINUTES);
|
||||
registerTask(tpsCounter).runTaskTimer(minuteTicks, secondTicks);
|
||||
registerTask(ramAndCpuTask).runTaskTimerAsynchronously(minuteTicks - halfSecondTicks, secondTicks);
|
||||
registerTask(diskTask).runTaskTimerAsynchronously(50L * secondTicks, minuteTicks);
|
||||
}
|
||||
|
||||
private void registerTasks() {
|
||||
registerTPSCounter();
|
||||
registerTask(logsFolderCleanTask).runTaskLaterAsynchronously(TimeAmount.toTicks(30L, TimeUnit.SECONDS));
|
||||
|
||||
Long pingDelay = config.get(TimeSettings.PING_SERVER_ENABLE_DELAY);
|
||||
if (pingDelay < TimeUnit.HOURS.toMillis(1L) && config.isTrue(DataGatheringSettings.PING)) {
|
||||
plugin.registerListener(pingCounter);
|
||||
long startDelay = TimeAmount.toTicks(pingDelay, TimeUnit.MILLISECONDS);
|
||||
registerTask(pingCounter).runTaskTimer(startDelay, 40L);
|
||||
}
|
||||
|
||||
// +40 ticks / 2 seconds so that update check task runs first.
|
||||
long storeDelay = TimeAmount.toTicks(config.get(TimeSettings.CONFIG_UPDATE_INTERVAL), TimeUnit.MILLISECONDS) + 40;
|
||||
registerTask(networkConfigStoreTask).runTaskLaterAsynchronously(storeDelay);
|
||||
|
||||
registerTask(dbCleanTask).runTaskTimerAsynchronously(
|
||||
TimeAmount.toTicks(20, TimeUnit.SECONDS),
|
||||
TimeAmount.toTicks(config.get(TimeSettings.CLEAN_DATABASE_PERIOD), TimeUnit.MILLISECONDS)
|
||||
);
|
||||
long minute = TimeAmount.toTicks(1, TimeUnit.MINUTES);
|
||||
registerTask(jsonCacheCleanTask).runTaskTimerAsynchronously(minute, minute);
|
||||
|
||||
long extensionRefreshPeriod = TimeAmount.toTicks(config.get(TimeSettings.EXTENSION_DATA_REFRESH_PERIOD), TimeUnit.MILLISECONDS);
|
||||
registerTask(extensionServerMethodCallerTask).runTaskTimerAsynchronously(
|
||||
TimeAmount.toTicks(30, TimeUnit.SECONDS), extensionRefreshPeriod
|
||||
);
|
||||
}
|
||||
}
|
@ -24,9 +24,11 @@
|
||||
package com.djrapitops.plan.gathering.timed;
|
||||
|
||||
import com.djrapitops.plan.PlanVelocity;
|
||||
import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plan.delivery.domain.DateObj;
|
||||
import com.djrapitops.plan.identification.ServerInfo;
|
||||
import com.djrapitops.plan.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.settings.config.paths.DataGatheringSettings;
|
||||
import com.djrapitops.plan.settings.config.paths.TimeSettings;
|
||||
import com.djrapitops.plan.storage.database.DBSystem;
|
||||
import com.djrapitops.plan.storage.database.transactions.events.PingStoreTransaction;
|
||||
@ -51,7 +53,7 @@ import java.util.concurrent.TimeUnit;
|
||||
* @author MicleBrick
|
||||
*/
|
||||
@Singleton
|
||||
public class VelocityPingCounter extends AbsRunnable {
|
||||
public class VelocityPingCounter extends TaskSystem.Task {
|
||||
|
||||
final Map<UUID, List<DateObj<Integer>>> playerHistory;
|
||||
|
||||
@ -106,6 +108,17 @@ public class VelocityPingCounter extends AbsRunnable {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(RunnableFactory runnableFactory) {
|
||||
Long startDelay = config.get(TimeSettings.PING_SERVER_ENABLE_DELAY);
|
||||
if (startDelay < TimeUnit.HOURS.toMillis(1L) && config.isTrue(DataGatheringSettings.PING)) {
|
||||
plugin.registerListener(this);
|
||||
long delay = TimeAmount.toTicks(startDelay, TimeUnit.MILLISECONDS);
|
||||
long period = 40L;
|
||||
runnableFactory.create(null, this).runTaskTimer(delay, period);
|
||||
}
|
||||
}
|
||||
|
||||
void addPlayer(Player player) {
|
||||
playerHistory.put(player.getUniqueId(), new ArrayList<>());
|
||||
}
|
||||
|
@ -16,8 +16,6 @@
|
||||
*/
|
||||
package com.djrapitops.plan.modules.velocity;
|
||||
|
||||
import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plan.VelocityTaskSystem;
|
||||
import com.djrapitops.plan.gathering.ServerSensor;
|
||||
import com.djrapitops.plan.gathering.VelocitySensor;
|
||||
import com.djrapitops.plan.gathering.listeners.ListenerSystem;
|
||||
@ -38,9 +36,6 @@ public interface VelocitySuperClassBindingModule {
|
||||
@Binds
|
||||
ServerInfo bindServerInfo(VelocityServerInfo serverInfo);
|
||||
|
||||
@Binds
|
||||
TaskSystem bindTaskSystem(VelocityTaskSystem taskSystem);
|
||||
|
||||
@Binds
|
||||
ListenerSystem bindListenerSystem(VelocityListenerSystem listenerSystem);
|
||||
|
||||
|
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan.modules.velocity;
|
||||
|
||||
import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
|
||||
import com.djrapitops.plan.extension.ExtensionServerDataUpdater;
|
||||
import com.djrapitops.plan.gathering.timed.ProxyTPSCounter;
|
||||
import com.djrapitops.plan.gathering.timed.SystemUsageBuffer;
|
||||
import com.djrapitops.plan.gathering.timed.VelocityPingCounter;
|
||||
import com.djrapitops.plan.settings.upkeep.NetworkConfigStoreTask;
|
||||
import com.djrapitops.plan.storage.upkeep.DBCleanTask;
|
||||
import com.djrapitops.plan.storage.upkeep.LogsFolderCleanTask;
|
||||
import dagger.Binds;
|
||||
import dagger.Module;
|
||||
import dagger.multibindings.IntoSet;
|
||||
|
||||
@Module
|
||||
public interface VelocityTaskModule {
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindTPSCounter(ProxyTPSCounter counter);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindPingCounter(VelocityPingCounter counter);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindNetworkConfigStoreTask(NetworkConfigStoreTask configStoreTask);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindExtensionServerDataUpdater(ExtensionServerDataUpdater extensionServerDataUpdater);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindLogCleanTask(LogsFolderCleanTask logsFolderCleanTask);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindDBCleanTask(DBCleanTask cleanTask);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindJSONCacheCleanTask(JSONCache.CleanTask cleanTask);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindRamAndCpuTask(SystemUsageBuffer.RamAndCpuTask ramAndCpuTask);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindDiskTask(SystemUsageBuffer.DiskTask diskTask);
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user