Revert "Use custom async thread execution pool"
This reverts commit a574245bb9e6760724d32c5ba61bbe25a50ada94.
This commit is contained in:
parent
a574245bb9
commit
5e0ee51692
@ -333,7 +333,7 @@ public class AuthMe extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Wait for tasks and close data source
|
// Wait for tasks and close data source
|
||||||
new TaskCloser(this, database, bukkitService).run();
|
new TaskCloser(this, database).run();
|
||||||
|
|
||||||
// Disabled correctly
|
// Disabled correctly
|
||||||
ConsoleLogger.info("AuthMe " + this.getDescription().getVersion() + " disabled!");
|
ConsoleLogger.info("AuthMe " + this.getDescription().getVersion() + " disabled!");
|
||||||
|
|||||||
@ -3,7 +3,6 @@ package fr.xephi.authme.initialization;
|
|||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.service.BukkitService;
|
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
import org.bukkit.scheduler.BukkitWorker;
|
import org.bukkit.scheduler.BukkitWorker;
|
||||||
|
|
||||||
@ -23,27 +22,22 @@ public class TaskCloser implements Runnable {
|
|||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
private final AuthMe plugin;
|
private final AuthMe plugin;
|
||||||
private final DataSource dataSource;
|
private final DataSource dataSource;
|
||||||
private final BukkitService bukkitService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param plugin the plugin instance
|
* @param plugin the plugin instance
|
||||||
* @param dataSource the data source (nullable)
|
* @param dataSource the data source (nullable)
|
||||||
* @param bukkitService the bukkit service instance (nullable)
|
|
||||||
*/
|
*/
|
||||||
public TaskCloser(AuthMe plugin, DataSource dataSource, BukkitService bukkitService) {
|
public TaskCloser(AuthMe plugin, DataSource dataSource) {
|
||||||
this.scheduler = plugin.getServer().getScheduler();
|
this.scheduler = plugin.getServer().getScheduler();
|
||||||
this.logger = plugin.getLogger();
|
this.logger = plugin.getLogger();
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.dataSource = dataSource;
|
this.dataSource = dataSource;
|
||||||
this.bukkitService = bukkitService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
logger.info("Closing scheduled tasks:");
|
|
||||||
|
|
||||||
List<Integer> pendingTasks = getPendingTasks();
|
List<Integer> pendingTasks = getPendingTasks();
|
||||||
logger.log(Level.INFO, "Waiting for {0} tasks to finish", pendingTasks.size());
|
logger.log(Level.INFO, "Waiting for {0} tasks to finish", pendingTasks.size());
|
||||||
int progress = 0;
|
int progress = 0;
|
||||||
@ -75,16 +69,6 @@ public class TaskCloser implements Runnable {
|
|||||||
tries--;
|
tries--;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("Closing async tasks...");
|
|
||||||
if(bukkitService != null) {
|
|
||||||
try {
|
|
||||||
bukkitService.closeAsyncPool();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
logger.log(Level.WARNING, "Unable to close some async task", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("Closing datasource...");
|
|
||||||
if (dataSource != null) {
|
if (dataSource != null) {
|
||||||
dataSource.close();
|
dataSource.close();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import fr.xephi.authme.ConsoleLogger;
|
|||||||
import fr.xephi.authme.initialization.SettingsDependent;
|
import fr.xephi.authme.initialization.SettingsDependent;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||||
import fr.xephi.authme.util.Utils;
|
|
||||||
import org.bukkit.BanEntry;
|
import org.bukkit.BanEntry;
|
||||||
import org.bukkit.BanList;
|
import org.bukkit.BanList;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -26,10 +25,6 @@ import java.util.Collection;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
import java.util.concurrent.SynchronousQueue;
|
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service for operations requiring the Bukkit API, such as for scheduling.
|
* Service for operations requiring the Bukkit API, such as for scheduling.
|
||||||
@ -46,35 +41,13 @@ public class BukkitService implements SettingsDependent {
|
|||||||
private Method getOnlinePlayers;
|
private Method getOnlinePlayers;
|
||||||
private boolean useAsyncTasks;
|
private boolean useAsyncTasks;
|
||||||
|
|
||||||
// Async executor
|
|
||||||
private ThreadPoolExecutor asyncExecutor;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
BukkitService(AuthMe authMe, Settings settings) {
|
BukkitService(AuthMe authMe, Settings settings) {
|
||||||
this.authMe = authMe;
|
this.authMe = authMe;
|
||||||
getOnlinePlayersIsCollection = initializeOnlinePlayersIsCollectionField();
|
getOnlinePlayersIsCollection = initializeOnlinePlayersIsCollectionField();
|
||||||
|
|
||||||
int coreCount = Utils.getCoreCount();
|
|
||||||
// Keep 1 free core for the main thread and the OS
|
|
||||||
if(coreCount != 1) {
|
|
||||||
coreCount--;
|
|
||||||
}
|
|
||||||
asyncExecutor = new ThreadPoolExecutor(coreCount, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS,
|
|
||||||
new SynchronousQueue<>());
|
|
||||||
|
|
||||||
reload(settings);
|
reload(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Wait the shutdown of the async execution pool.
|
|
||||||
*
|
|
||||||
* @throws InterruptedException if the shutdown is interrupted
|
|
||||||
*/
|
|
||||||
public void closeAsyncPool() throws InterruptedException {
|
|
||||||
asyncExecutor.shutdown();
|
|
||||||
asyncExecutor.awaitTermination(30, TimeUnit.SECONDS);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Schedules a once off task to occur as soon as possible.
|
* Schedules a once off task to occur as soon as possible.
|
||||||
* <p>
|
* <p>
|
||||||
@ -162,12 +135,12 @@ public class BukkitService implements SettingsDependent {
|
|||||||
* Returns a task that will run asynchronously.
|
* Returns a task that will run asynchronously.
|
||||||
*
|
*
|
||||||
* @param task the task to be run
|
* @param task the task to be run
|
||||||
|
* @return a BukkitTask that contains the id number
|
||||||
* @throws IllegalArgumentException if plugin is null
|
* @throws IllegalArgumentException if plugin is null
|
||||||
* @throws IllegalArgumentException if task is null
|
* @throws IllegalArgumentException if task is null
|
||||||
*/
|
*/
|
||||||
public void runTaskAsynchronously(Runnable task) {
|
public BukkitTask runTaskAsynchronously(Runnable task) {
|
||||||
asyncExecutor.execute(task);
|
return Bukkit.getScheduler().runTaskAsynchronously(authMe, task);
|
||||||
//Bukkit.getScheduler().runTaskAsynchronously(authMe, task);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -3,7 +3,6 @@ package fr.xephi.authme.initialization;
|
|||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.ReflectionTestUtils;
|
import fr.xephi.authme.ReflectionTestUtils;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.service.BukkitService;
|
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.PluginLogger;
|
import org.bukkit.plugin.PluginLogger;
|
||||||
@ -50,8 +49,6 @@ public class TaskCloserTest {
|
|||||||
private BukkitScheduler bukkitScheduler;
|
private BukkitScheduler bukkitScheduler;
|
||||||
@Mock
|
@Mock
|
||||||
private DataSource dataSource;
|
private DataSource dataSource;
|
||||||
@Mock
|
|
||||||
private BukkitService bukkitService;
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void initAuthMe() {
|
public void initAuthMe() {
|
||||||
@ -59,7 +56,7 @@ public class TaskCloserTest {
|
|||||||
given(server.getScheduler()).willReturn(bukkitScheduler);
|
given(server.getScheduler()).willReturn(bukkitScheduler);
|
||||||
ReflectionTestUtils.setField(JavaPlugin.class, authMe, "server", server);
|
ReflectionTestUtils.setField(JavaPlugin.class, authMe, "server", server);
|
||||||
ReflectionTestUtils.setField(JavaPlugin.class, authMe, "logger", logger);
|
ReflectionTestUtils.setField(JavaPlugin.class, authMe, "logger", logger);
|
||||||
taskCloser = spy(new TaskCloser(authMe, dataSource, bukkitService));
|
taskCloser = spy(new TaskCloser(authMe, dataSource));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -123,7 +120,7 @@ public class TaskCloserTest {
|
|||||||
/** Test implementation for {@link #shouldStopForInterruptedThread()}. */
|
/** Test implementation for {@link #shouldStopForInterruptedThread()}. */
|
||||||
private void shouldStopForInterruptedThread0() throws InterruptedException {
|
private void shouldStopForInterruptedThread0() throws InterruptedException {
|
||||||
// given
|
// given
|
||||||
taskCloser = spy(new TaskCloser(authMe, null, bukkitService));
|
taskCloser = spy(new TaskCloser(authMe, null));
|
||||||
// First two times do nothing, third time throw exception when we sleep
|
// First two times do nothing, third time throw exception when we sleep
|
||||||
doNothing().doNothing().doThrow(InterruptedException.class).when(taskCloser).sleep();
|
doNothing().doNothing().doThrow(InterruptedException.class).when(taskCloser).sleep();
|
||||||
mockActiveWorkers();
|
mockActiveWorkers();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user