From 3fa97d47c60b4d0ae258917c4825c68e0f30130c Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Fri, 19 Apr 2019 18:19:02 +0400 Subject: [PATCH] Improved timeout updates for slow server --- .../main/java/mage/client/table/TablesPanel.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/table/TablesPanel.java b/Mage.Client/src/main/java/mage/client/table/TablesPanel.java index 2dea14ca6c..877fb9d9b4 100644 --- a/Mage.Client/src/main/java/mage/client/table/TablesPanel.java +++ b/Mage.Client/src/main/java/mage/client/table/TablesPanel.java @@ -16,6 +16,7 @@ import mage.constants.*; import mage.game.match.MatchOptions; import mage.players.PlayerType; import mage.remote.MageRemoteException; +import mage.util.RandomUtil; import mage.view.MatchView; import mage.view.RoomUsersView; import mage.view.TableView; @@ -65,6 +66,7 @@ public class TablesPanel extends javax.swing.JPanel { public static final int REFRESH_ACTIVE_TABLES_SECS = 5; public static final int REFRESH_FINISHED_TABLES_SECS = 30; public static final int REFRESH_PLAYERS_SECS = 10; + public static final double REFRESH_TIMEOUTS_INCREASE_FACTOR = 0.8; // can increase timeouts by 80% (0.8) private final TablesTableModel tableModel; private final MatchesTableModel matchesModel; @@ -211,6 +213,12 @@ public class TablesPanel extends javax.swing.JPanel { return res; } + public static int randomizeTimout(int minTimout) { + // randomize timeouts to fix calls waves -- slow server can creates queue and moves all clients to same call window + int increase = (int) (minTimout * REFRESH_TIMEOUTS_INCREASE_FACTOR); + return minTimout + RandomUtil.nextInt(increase); + } + /** * Creates new form TablesPanel @@ -1693,8 +1701,7 @@ class UpdateTablesTask extends SwingWorker> { if (tables != null) { this.publish(tables); } - - TimeUnit.SECONDS.sleep(TablesPanel.REFRESH_ACTIVE_TABLES_SECS); + TimeUnit.SECONDS.sleep(TablesPanel.randomizeTimout(TablesPanel.REFRESH_ACTIVE_TABLES_SECS)); } return null; } @@ -1741,7 +1748,7 @@ class UpdatePlayersTask extends SwingWorker> { protected Void doInBackground() throws Exception { while (!isCancelled()) { this.publish(SessionHandler.getRoomUsers(roomId)); - TimeUnit.SECONDS.sleep(TablesPanel.REFRESH_PLAYERS_SECS); + TimeUnit.SECONDS.sleep(TablesPanel.randomizeTimout(TablesPanel.REFRESH_PLAYERS_SECS)); } return null; } @@ -1779,7 +1786,7 @@ class UpdateMatchesTask extends SwingWorker> { protected Void doInBackground() throws Exception { while (!isCancelled()) { this.publish(SessionHandler.getFinishedMatches(roomId)); - TimeUnit.SECONDS.sleep(TablesPanel.REFRESH_FINISHED_TABLES_SECS); + TimeUnit.SECONDS.sleep(TablesPanel.randomizeTimout(TablesPanel.REFRESH_FINISHED_TABLES_SECS)); } return null; }