mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -08:00
download: reworked connection:
- added shareable code with default proxy, headers and other settings for download tasks like images, symbols, mtgjson, etc; - use XmageURLConnection.downloadText for text resources - use XmageURLConnection.downloadBinary for any file resources - added user agent with app version for all requests; - added http logs and improved error messages;
This commit is contained in:
parent
fad63389d0
commit
e1cffbde40
35 changed files with 713 additions and 464 deletions
|
|
@ -6,7 +6,7 @@ import mage.server.record.UserStats;
|
|||
import mage.server.record.UserStatsRepository;
|
||||
import mage.server.util.ServerMessagesUtil;
|
||||
import mage.util.ThreadUtils;
|
||||
import mage.util.XMageThreadFactory;
|
||||
import mage.util.XmageThreadFactory;
|
||||
import mage.view.UserView;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
|
@ -34,10 +34,10 @@ public class UserManagerImpl implements UserManager {
|
|||
private static final Logger logger = Logger.getLogger(UserManagerImpl.class);
|
||||
|
||||
protected final ScheduledExecutorService CONNECTION_EXPIRED_EXECUTOR = Executors.newSingleThreadScheduledExecutor(
|
||||
new XMageThreadFactory(ThreadUtils.THREAD_PREFIX_SERVICE_CONNECTION_EXPIRED_CHECK)
|
||||
new XmageThreadFactory(ThreadUtils.THREAD_PREFIX_SERVICE_CONNECTION_EXPIRED_CHECK)
|
||||
);
|
||||
protected final ScheduledExecutorService USERS_LIST_REFRESH_EXECUTOR = Executors.newSingleThreadScheduledExecutor(
|
||||
new XMageThreadFactory(ThreadUtils.THREAD_PREFIX_SERVICE_USERS_LIST_REFRESH)
|
||||
new XmageThreadFactory(ThreadUtils.THREAD_PREFIX_SERVICE_USERS_LIST_REFRESH)
|
||||
);
|
||||
|
||||
private List<UserView> userInfoList = new ArrayList<>(); // all users list for main room/chat
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import mage.server.User;
|
|||
import mage.server.managers.ManagerFactory;
|
||||
import mage.util.MultiAmountMessage;
|
||||
import mage.util.ThreadUtils;
|
||||
import mage.util.XMageThreadFactory;
|
||||
import mage.util.XmageThreadFactory;
|
||||
import mage.utils.StreamUtils;
|
||||
import mage.utils.timer.PriorityTimer;
|
||||
import mage.view.*;
|
||||
|
|
@ -244,7 +244,7 @@ public class GameController implements GameCallback {
|
|||
// wait all players
|
||||
if (JOIN_WAITING_EXECUTOR == null) {
|
||||
JOIN_WAITING_EXECUTOR = Executors.newSingleThreadScheduledExecutor(
|
||||
new XMageThreadFactory(ThreadUtils.THREAD_PREFIX_GAME_JOIN_WAITING + " " + game.getId())
|
||||
new XmageThreadFactory(ThreadUtils.THREAD_PREFIX_GAME_JOIN_WAITING + " " + game.getId())
|
||||
);
|
||||
}
|
||||
JOIN_WAITING_EXECUTOR.scheduleAtFixedRate(() -> {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import mage.server.RoomImpl;
|
|||
import mage.server.User;
|
||||
import mage.server.managers.ManagerFactory;
|
||||
import mage.util.ThreadUtils;
|
||||
import mage.util.XMageThreadFactory;
|
||||
import mage.util.XmageThreadFactory;
|
||||
import mage.view.MatchView;
|
||||
import mage.view.RoomUsersView;
|
||||
import mage.view.TableView;
|
||||
|
|
@ -40,7 +40,7 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
|||
private static List<MatchView> lobbyMatches = new ArrayList<>();
|
||||
private static List<RoomUsersView> lobbyUsers = new ArrayList<>();
|
||||
private static final ScheduledExecutorService UPDATE_LOBBY_EXECUTOR = Executors.newSingleThreadScheduledExecutor(
|
||||
new XMageThreadFactory(ThreadUtils.THREAD_PREFIX_SERVICE_LOBBY_REFRESH)
|
||||
new XmageThreadFactory(ThreadUtils.THREAD_PREFIX_SERVICE_LOBBY_REFRESH)
|
||||
);
|
||||
|
||||
private final ManagerFactory managerFactory;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package mage.server.util;
|
||||
|
||||
import mage.util.ThreadUtils;
|
||||
import mage.util.XMageThreadFactory;
|
||||
import mage.util.XmageThreadFactory;
|
||||
import mage.utils.StreamUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
|
@ -47,7 +47,7 @@ public enum ServerMessagesUtil {
|
|||
|
||||
ServerMessagesUtil() {
|
||||
ScheduledExecutorService NEWS_MESSAGES_EXECUTOR = Executors.newSingleThreadScheduledExecutor(
|
||||
new XMageThreadFactory(ThreadUtils.THREAD_PREFIX_SERVICE_NEWS_REFRESH)
|
||||
new XmageThreadFactory(ThreadUtils.THREAD_PREFIX_SERVICE_NEWS_REFRESH)
|
||||
);
|
||||
NEWS_MESSAGES_EXECUTOR.scheduleAtFixedRate(this::reloadMessages, 5, SERVER_MSG_REFRESH_RATE_SECS, TimeUnit.SECONDS);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package mage.server.util;
|
|||
import mage.server.managers.ConfigSettings;
|
||||
import mage.server.managers.ThreadExecutor;
|
||||
import mage.util.ThreadUtils;
|
||||
import mage.util.XMageThreadFactory;
|
||||
import mage.util.XmageThreadFactory;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.util.concurrent.*;
|
||||
|
|
@ -42,31 +42,31 @@ public class ThreadExecutorImpl implements ThreadExecutor {
|
|||
callExecutor = new CachedThreadPoolWithException();
|
||||
((ThreadPoolExecutor) callExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
||||
((ThreadPoolExecutor) callExecutor).allowCoreThreadTimeOut(true);
|
||||
((ThreadPoolExecutor) callExecutor).setThreadFactory(new XMageThreadFactory(ThreadUtils.THREAD_PREFIX_CALL_REQUEST));
|
||||
((ThreadPoolExecutor) callExecutor).setThreadFactory(new XmageThreadFactory(ThreadUtils.THREAD_PREFIX_CALL_REQUEST));
|
||||
|
||||
//gameExecutor = Executors.newFixedThreadPool(config.getMaxGameThreads());
|
||||
gameExecutor = new FixedThreadPoolWithException(config.getMaxGameThreads());
|
||||
((ThreadPoolExecutor) gameExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
||||
((ThreadPoolExecutor) gameExecutor).allowCoreThreadTimeOut(true);
|
||||
((ThreadPoolExecutor) gameExecutor).setThreadFactory(new XMageThreadFactory(ThreadUtils.THREAD_PREFIX_GAME));
|
||||
((ThreadPoolExecutor) gameExecutor).setThreadFactory(new XmageThreadFactory(ThreadUtils.THREAD_PREFIX_GAME));
|
||||
|
||||
//tourney = Executors.newFixedThreadPool(config.getMaxGameThreads() / GAMES_PER_TOURNEY_RATIO);
|
||||
tourneyExecutor = new FixedThreadPoolWithException(config.getMaxGameThreads() / GAMES_PER_TOURNEY_RATIO);
|
||||
((ThreadPoolExecutor) tourneyExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
||||
((ThreadPoolExecutor) tourneyExecutor).allowCoreThreadTimeOut(true);
|
||||
((ThreadPoolExecutor) tourneyExecutor).setThreadFactory(new XMageThreadFactory(ThreadUtils.THREAD_PREFIX_TOURNEY));
|
||||
((ThreadPoolExecutor) tourneyExecutor).setThreadFactory(new XmageThreadFactory(ThreadUtils.THREAD_PREFIX_TOURNEY));
|
||||
|
||||
timeoutExecutor = Executors.newScheduledThreadPool(4);
|
||||
((ThreadPoolExecutor) timeoutExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
||||
((ThreadPoolExecutor) timeoutExecutor).allowCoreThreadTimeOut(true);
|
||||
((ThreadPoolExecutor) timeoutExecutor).setThreadFactory(new XMageThreadFactory(ThreadUtils.THREAD_PREFIX_TIMEOUT));
|
||||
((ThreadPoolExecutor) timeoutExecutor).setThreadFactory(new XmageThreadFactory(ThreadUtils.THREAD_PREFIX_TIMEOUT));
|
||||
|
||||
timeoutIdleExecutor = Executors.newScheduledThreadPool(4);
|
||||
((ThreadPoolExecutor) timeoutIdleExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
||||
((ThreadPoolExecutor) timeoutIdleExecutor).allowCoreThreadTimeOut(true);
|
||||
((ThreadPoolExecutor) timeoutIdleExecutor).setThreadFactory(new XMageThreadFactory(ThreadUtils.THREAD_PREFIX_TIMEOUT_IDLE));
|
||||
((ThreadPoolExecutor) timeoutIdleExecutor).setThreadFactory(new XmageThreadFactory(ThreadUtils.THREAD_PREFIX_TIMEOUT_IDLE));
|
||||
|
||||
serverHealthExecutor = Executors.newSingleThreadScheduledExecutor(new XMageThreadFactory(ThreadUtils.THREAD_PREFIX_SERVICE_HEALTH));
|
||||
serverHealthExecutor = Executors.newSingleThreadScheduledExecutor(new XmageThreadFactory(ThreadUtils.THREAD_PREFIX_SERVICE_HEALTH));
|
||||
}
|
||||
|
||||
static class CachedThreadPoolWithException extends ThreadPoolExecutor {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue