@Override public void run() { List<Integer> commandsToPost = new ArrayList<>(); while (commandsToPost.size() < MAXIMUM_COMMANDS_TO_POST) { Integer posted = completed.poll(); if (posted == null) break; commandsToPost.add(posted); } if (!commandsToPost.isEmpty()) { try { platform.getApiClient().deleteCommand(commandsToPost); } catch (IOException | ApiException e) { platform.log(Level.SEVERE, "Unable to mark commands as completed", e); // TODO: Retry? } } }
private void processOnlinePlayers() { // Check for online players and execute their commands. List<QueuedPlayer> processNow = new ArrayList<>(); lock.lock(); try { for (Iterator<QueuedPlayer> it = due.values().iterator(); it.hasNext(); ) { QueuedPlayer qp = it.next(); if (platform.isPlayerOnline(qp)) { if (processNow.size() < MAXIMUM_ONLINE_PLAYERS_TO_EXECUTE) { processNow.add(qp); it.remove(); } } } } finally { lock.unlock(); } if (!processNow.isEmpty()) { if (verbose) { platform.log(Level.INFO, String.format("Executing commands for %d online players...", processNow.size())); } for (int i = 0; i < processNow.size(); i++) { QueuedPlayer qp = processNow.get(i); platform.executeAsyncLater(new PlayerCommandExecutor(qp, platform), DELAY_BETWEEN_PLAYERS * (i + 1), TimeUnit.MILLISECONDS); } } }
public void flush() { if (!completed.isEmpty()) { for (List<Integer> list : Lists.partition(new ArrayList<>(completed), MAXIMUM_COMMANDS_TO_POST)) { try { platform.getApiClient().deleteCommand(list); } catch (IOException | ApiException e) { platform.log(Level.SEVERE, "Unable to mark commands as completed", e); break; } } } } }
@Override public void run() { if (platform.getApiClient() == null) { // no API client return; } try { listing.set(platform.getApiClient().retrieveListing()); } catch (IOException | ApiException e) { platform.log(Level.SEVERE, "Error whilst retrieving listing", e); return; } lastUpdate.set(new Date()); if (updateTask != null) { updateTask.run(); } }
platform.log(Level.INFO, "Already fetching due player information!"); return; platform.log(Level.INFO, "Fetching all due players..."); platform.log(Level.SEVERE, "Could not fetch due players queue", e); return; platform.log(Level.INFO, String.format("Fetched due players (%d found).", allDue.size())); platform.log(Level.INFO, "Executing commands that can be completed now...");
@Override public void run() { QueueInformation information; try { information = platform.getApiClient().getPlayerQueue(player.getId()); } catch (IOException | ApiException e) { // TODO: Implement retry logic. platform.log(Level.SEVERE, "Could not fetch command queue for player", e); return; } platform.log(Level.INFO, String.format("Fetched %d commands for player '%s'.", information.getCommands().size(), player.getName())); // Queue commands for later. for (QueuedCommand command : information.getCommands()) { platform.getExecutor().queue(new ToRunQueuedCommand(player, command, true)); } } }
platform.log(Level.INFO, String.format("Dispatching command '%s' for player '%s'.", finalCommand, command.getPlayer().getName())); try { platform.dispatchCommand(finalCommand); completedCommandsTask.add(command.getCommand().getId()); } catch (Exception e) { platform.log(Level.SEVERE, String.format("Could not dispatch command '%s' for player '%s'. " + "This is typically a plugin error, not an issue with BuycraftX.", finalCommand, command.getPlayer().getName()), e); platform.log(Level.SEVERE, "Command execution took " + timeMs.toPlainString() + "ms to complete. " + "This likely indicates an issue with one of your server's plugins, which can cause lag."); } else { platform.log(Level.SEVERE, "Command execution took " + timeMs.toPlainString() + "ms to complete. " + "This likely indicates an issue with one of your server's plugins, which will slow command execution.");
@Override public void run() { if (platform.getApiClient() == null) { return; // no API client } QueueInformation information; try { // Retrieve offline command queue. information = platform.getApiClient().retrieveOfflineQueue(); } catch (IOException | ApiException e) { platform.log(Level.SEVERE, "Could not fetch command queue", e); return; } // Queue commands for later. for (QueuedCommand command : information.getCommands()) { platform.getExecutor().queue(new ToRunQueuedCommand(command.getPlayer(), command, false)); } } }