mirror of
https://github.com/correl/mage.git
synced 2024-11-25 03:00:11 +00:00
added connection leasing + cleanup
This commit is contained in:
parent
b1408507cb
commit
ade836c08a
12 changed files with 115 additions and 84 deletions
|
@ -104,44 +104,45 @@ public class Session {
|
||||||
public boolean connect() {
|
public boolean connect() {
|
||||||
sessionState = SessionState.CONNECTING;
|
sessionState = SessionState.CONNECTING;
|
||||||
try {
|
try {
|
||||||
// System.setProperty("http.nonProxyHosts", "code.google.com");
|
System.setProperty("http.nonProxyHosts", "code.google.com");
|
||||||
// System.setProperty("socksNonProxyHosts", "code.google.com");
|
System.setProperty("socksNonProxyHosts", "code.google.com");
|
||||||
//
|
|
||||||
// // clear previous values
|
// clear previous values
|
||||||
// System.clearProperty("socksProxyHost");
|
System.clearProperty("socksProxyHost");
|
||||||
// System.clearProperty("socksProxyPort");
|
System.clearProperty("socksProxyPort");
|
||||||
// System.clearProperty("http.proxyHost");
|
System.clearProperty("http.proxyHost");
|
||||||
// System.clearProperty("http.proxyPort");
|
System.clearProperty("http.proxyPort");
|
||||||
//
|
|
||||||
// switch (connection.getProxyType()) {
|
switch (connection.getProxyType()) {
|
||||||
// case SOCKS:
|
case SOCKS:
|
||||||
// System.setProperty("socksProxyHost", connection.getProxyHost());
|
System.setProperty("socksProxyHost", connection.getProxyHost());
|
||||||
// System.setProperty("socksProxyPort", Integer.toString(connection.getProxyPort()));
|
System.setProperty("socksProxyPort", Integer.toString(connection.getProxyPort()));
|
||||||
// break;
|
break;
|
||||||
// case HTTP:
|
case HTTP:
|
||||||
// System.setProperty("http.proxyHost", connection.getProxyHost());
|
System.setProperty("http.proxyHost", connection.getProxyHost());
|
||||||
// System.setProperty("http.proxyPort", Integer.toString(connection.getProxyPort()));
|
System.setProperty("http.proxyPort", Integer.toString(connection.getProxyPort()));
|
||||||
// Authenticator.setDefault(new MageAuthenticator(connection.getProxyUsername(), connection.getProxyPassword()));
|
Authenticator.setDefault(new MageAuthenticator(connection.getProxyUsername(), connection.getProxyPassword()));
|
||||||
// break;
|
break;
|
||||||
// }
|
}
|
||||||
InvokerLocator clientLocator = new InvokerLocator(connection.getURI());
|
InvokerLocator clientLocator = new InvokerLocator(connection.getURI());
|
||||||
Map<String, String> metadata = new HashMap<String, String>();
|
Map<String, String> metadata = new HashMap<String, String>();
|
||||||
metadata.put(SocketWrapper.WRITE_TIMEOUT, "2000");
|
metadata.put(SocketWrapper.WRITE_TIMEOUT, "2000");
|
||||||
metadata.put("generalizeSocketException", "true");
|
metadata.put("generalizeSocketException", "true");
|
||||||
server = (MageServer) TransporterClient.createTransporterClient(clientLocator.getLocatorURI(), MageServer.class, metadata);
|
server = (MageServer) TransporterClient.createTransporterClient(clientLocator.getLocatorURI(), MageServer.class, metadata);
|
||||||
|
|
||||||
callbackClient = new Client(clientLocator, "callback");
|
Map<String, String> clientMetadata = new HashMap<String, String>();
|
||||||
callbackClient.connect();
|
clientMetadata.put(SocketWrapper.WRITE_TIMEOUT, "2000");
|
||||||
|
clientMetadata.put("generalizeSocketException", "true");
|
||||||
|
clientMetadata.put(Client.ENABLE_LEASE, "true");
|
||||||
|
callbackClient = new Client(clientLocator, "callback", clientMetadata);
|
||||||
|
|
||||||
Map<String, String> listenerMetadata = new HashMap<String, String>();
|
Map<String, String> listenerMetadata = new HashMap<String, String>();
|
||||||
listenerMetadata.put(ConnectionValidator.VALIDATOR_PING_PERIOD, "5000");
|
listenerMetadata.put(ConnectionValidator.VALIDATOR_PING_PERIOD, "5000");
|
||||||
listenerMetadata.put(ConnectionValidator.VALIDATOR_PING_TIMEOUT, "2000");
|
listenerMetadata.put(ConnectionValidator.VALIDATOR_PING_TIMEOUT, "2000");
|
||||||
callbackClient.addConnectionListener(new ClientConnectionListener(), listenerMetadata);
|
callbackClient.connect(new ClientConnectionListener(), listenerMetadata);
|
||||||
|
|
||||||
Map<String, String> callbackMetadata = new HashMap<String, String>();
|
Map<String, String> callbackMetadata = new HashMap<String, String>();
|
||||||
callbackMetadata.put(Bisocket.IS_CALLBACK_SERVER, "true");
|
callbackMetadata.put(Bisocket.IS_CALLBACK_SERVER, "true");
|
||||||
callbackMetadata.put(SocketWrapper.WRITE_TIMEOUT, "2000");
|
|
||||||
callbackMetadata.put("generalizeSocketException", "true");
|
|
||||||
CallbackHandler callbackHandler = new CallbackHandler();
|
CallbackHandler callbackHandler = new CallbackHandler();
|
||||||
callbackClient.addListener(callbackHandler, callbackMetadata);
|
callbackClient.addListener(callbackHandler, callbackMetadata);
|
||||||
|
|
||||||
|
@ -201,7 +202,7 @@ public class Session {
|
||||||
class ClientConnectionListener implements ConnectionListener {
|
class ClientConnectionListener implements ConnectionListener {
|
||||||
@Override
|
@Override
|
||||||
public void handleConnectionException(Throwable throwable, Client client) {
|
public void handleConnectionException(Throwable throwable, Client client) {
|
||||||
logger.info("connection to server lost");
|
logger.info("connection to server lost - " + throwable.getMessage());
|
||||||
disconnect(true);
|
disconnect(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ import org.apache.log4j.Logger;
|
||||||
public class MageServerImpl implements MageServer {
|
public class MageServerImpl implements MageServer {
|
||||||
|
|
||||||
private final static Logger logger = Logger.getLogger("Mage Server");
|
private final static Logger logger = Logger.getLogger("Mage Server");
|
||||||
private static ExecutorService rmiExecutor = ThreadExecutor.getInstance().getRMIExecutor();
|
private static ExecutorService callExecutor = ThreadExecutor.getInstance().getCallExecutor();
|
||||||
|
|
||||||
private String password;
|
private String password;
|
||||||
private boolean testMode;
|
private boolean testMode;
|
||||||
|
@ -137,7 +137,7 @@ public class MageServerImpl implements MageServer {
|
||||||
public void removeTable(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
public void removeTable(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||||
try {
|
try {
|
||||||
rmiExecutor.execute(
|
callExecutor.execute(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -243,15 +243,12 @@ public class MageServerImpl implements MageServer {
|
||||||
@Override
|
@Override
|
||||||
public void deregisterClient(final String sessionId) throws MageException {
|
public void deregisterClient(final String sessionId) throws MageException {
|
||||||
try {
|
try {
|
||||||
rmiExecutor.execute(
|
callExecutor.execute(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
SessionManager.getInstance().disconnect(sessionId);
|
||||||
if (session != null) {
|
logger.info("Client deregistered ...");
|
||||||
session.kill();
|
|
||||||
logger.info("Client deregistered ...");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -265,7 +262,7 @@ public class MageServerImpl implements MageServer {
|
||||||
public void startMatch(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
public void startMatch(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||||
try {
|
try {
|
||||||
rmiExecutor.execute(
|
callExecutor.execute(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -284,7 +281,7 @@ public class MageServerImpl implements MageServer {
|
||||||
public void startChallenge(final String sessionId, final UUID roomId, final UUID tableId, final UUID challengeId) throws MageException {
|
public void startChallenge(final String sessionId, final UUID roomId, final UUID tableId, final UUID challengeId) throws MageException {
|
||||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||||
try {
|
try {
|
||||||
rmiExecutor.execute(
|
callExecutor.execute(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -303,7 +300,7 @@ public class MageServerImpl implements MageServer {
|
||||||
public void startTournament(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
public void startTournament(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||||
try {
|
try {
|
||||||
rmiExecutor.execute(
|
callExecutor.execute(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -332,7 +329,7 @@ public class MageServerImpl implements MageServer {
|
||||||
@Override
|
@Override
|
||||||
public void sendChatMessage(final UUID chatId, final String userName, final String message) throws MageException {
|
public void sendChatMessage(final UUID chatId, final String userName, final String message) throws MageException {
|
||||||
try {
|
try {
|
||||||
rmiExecutor.execute(
|
callExecutor.execute(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -349,7 +346,7 @@ public class MageServerImpl implements MageServer {
|
||||||
@Override
|
@Override
|
||||||
public void joinChat(final UUID chatId, final String sessionId, final String userName) throws MageException {
|
public void joinChat(final UUID chatId, final String sessionId, final String userName) throws MageException {
|
||||||
try {
|
try {
|
||||||
rmiExecutor.execute(
|
callExecutor.execute(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -366,7 +363,7 @@ public class MageServerImpl implements MageServer {
|
||||||
@Override
|
@Override
|
||||||
public void leaveChat(final UUID chatId, final String sessionId) throws MageException {
|
public void leaveChat(final UUID chatId, final String sessionId) throws MageException {
|
||||||
try {
|
try {
|
||||||
rmiExecutor.execute(
|
callExecutor.execute(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -417,7 +414,7 @@ public class MageServerImpl implements MageServer {
|
||||||
public void swapSeats(final String sessionId, final UUID roomId, final UUID tableId, final int seatNum1, final int seatNum2) throws MageException {
|
public void swapSeats(final String sessionId, final UUID roomId, final UUID tableId, final int seatNum1, final int seatNum2) throws MageException {
|
||||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||||
try {
|
try {
|
||||||
rmiExecutor.execute(
|
callExecutor.execute(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -436,7 +433,7 @@ public class MageServerImpl implements MageServer {
|
||||||
public void leaveTable(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
public void leaveTable(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||||
try {
|
try {
|
||||||
rmiExecutor.execute(
|
callExecutor.execute(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -466,7 +463,7 @@ public class MageServerImpl implements MageServer {
|
||||||
public void joinGame(final UUID gameId, final String sessionId) throws MageException {
|
public void joinGame(final UUID gameId, final String sessionId) throws MageException {
|
||||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||||
try {
|
try {
|
||||||
rmiExecutor.execute(
|
callExecutor.execute(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -485,7 +482,7 @@ public class MageServerImpl implements MageServer {
|
||||||
public void joinDraft(final UUID draftId, final String sessionId) throws MageException {
|
public void joinDraft(final UUID draftId, final String sessionId) throws MageException {
|
||||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||||
try {
|
try {
|
||||||
rmiExecutor.execute(
|
callExecutor.execute(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -504,7 +501,7 @@ public class MageServerImpl implements MageServer {
|
||||||
public void joinTournament(final UUID tournamentId, final String sessionId) throws MageException {
|
public void joinTournament(final UUID tournamentId, final String sessionId) throws MageException {
|
||||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||||
try {
|
try {
|
||||||
rmiExecutor.execute(
|
callExecutor.execute(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -545,7 +542,7 @@ public class MageServerImpl implements MageServer {
|
||||||
public void sendPlayerUUID(final UUID gameId, final String sessionId, final UUID data) throws MageException {
|
public void sendPlayerUUID(final UUID gameId, final String sessionId, final UUID data) throws MageException {
|
||||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||||
try {
|
try {
|
||||||
rmiExecutor.execute(
|
callExecutor.execute(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -564,7 +561,7 @@ public class MageServerImpl implements MageServer {
|
||||||
public void sendPlayerString(final UUID gameId, final String sessionId, final String data) throws MageException {
|
public void sendPlayerString(final UUID gameId, final String sessionId, final String data) throws MageException {
|
||||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||||
try {
|
try {
|
||||||
rmiExecutor.execute(
|
callExecutor.execute(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -583,7 +580,7 @@ public class MageServerImpl implements MageServer {
|
||||||
public void sendPlayerBoolean(final UUID gameId, final String sessionId, final Boolean data) throws MageException {
|
public void sendPlayerBoolean(final UUID gameId, final String sessionId, final Boolean data) throws MageException {
|
||||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||||
try {
|
try {
|
||||||
rmiExecutor.execute(
|
callExecutor.execute(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -602,7 +599,7 @@ public class MageServerImpl implements MageServer {
|
||||||
public void sendPlayerInteger(final UUID gameId, final String sessionId, final Integer data) throws MageException {
|
public void sendPlayerInteger(final UUID gameId, final String sessionId, final Integer data) throws MageException {
|
||||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||||
try {
|
try {
|
||||||
rmiExecutor.execute(
|
callExecutor.execute(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -634,7 +631,7 @@ public class MageServerImpl implements MageServer {
|
||||||
public void concedeGame(final UUID gameId, final String sessionId) throws MageException {
|
public void concedeGame(final UUID gameId, final String sessionId) throws MageException {
|
||||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||||
try {
|
try {
|
||||||
rmiExecutor.execute(
|
callExecutor.execute(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -666,7 +663,7 @@ public class MageServerImpl implements MageServer {
|
||||||
public void watchGame(final UUID gameId, final String sessionId) throws MageException {
|
public void watchGame(final UUID gameId, final String sessionId) throws MageException {
|
||||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||||
try {
|
try {
|
||||||
rmiExecutor.execute(
|
callExecutor.execute(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -685,7 +682,7 @@ public class MageServerImpl implements MageServer {
|
||||||
public void stopWatching(final UUID gameId, final String sessionId) throws MageException {
|
public void stopWatching(final UUID gameId, final String sessionId) throws MageException {
|
||||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||||
try {
|
try {
|
||||||
rmiExecutor.execute(
|
callExecutor.execute(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -704,7 +701,7 @@ public class MageServerImpl implements MageServer {
|
||||||
public void replayGame(final UUID gameId, final String sessionId) throws MageException {
|
public void replayGame(final UUID gameId, final String sessionId) throws MageException {
|
||||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||||
try {
|
try {
|
||||||
rmiExecutor.execute(
|
callExecutor.execute(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -723,7 +720,7 @@ public class MageServerImpl implements MageServer {
|
||||||
public void startReplay(final UUID gameId, final String sessionId) throws MageException {
|
public void startReplay(final UUID gameId, final String sessionId) throws MageException {
|
||||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||||
try {
|
try {
|
||||||
rmiExecutor.execute(
|
callExecutor.execute(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -742,7 +739,7 @@ public class MageServerImpl implements MageServer {
|
||||||
public void stopReplay(final UUID gameId, final String sessionId) throws MageException {
|
public void stopReplay(final UUID gameId, final String sessionId) throws MageException {
|
||||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||||
try {
|
try {
|
||||||
rmiExecutor.execute(
|
callExecutor.execute(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -761,7 +758,7 @@ public class MageServerImpl implements MageServer {
|
||||||
public void nextPlay(final UUID gameId, final String sessionId) throws MageException {
|
public void nextPlay(final UUID gameId, final String sessionId) throws MageException {
|
||||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||||
try {
|
try {
|
||||||
rmiExecutor.execute(
|
callExecutor.execute(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -780,7 +777,7 @@ public class MageServerImpl implements MageServer {
|
||||||
public void previousPlay(final UUID gameId, final String sessionId) throws MageException {
|
public void previousPlay(final UUID gameId, final String sessionId) throws MageException {
|
||||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||||
try {
|
try {
|
||||||
rmiExecutor.execute(
|
callExecutor.execute(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -816,7 +813,7 @@ public class MageServerImpl implements MageServer {
|
||||||
public void cheat(final UUID gameId, final String sessionId, final UUID playerId, final DeckCardLists deckList) throws MageException {
|
public void cheat(final UUID gameId, final String sessionId, final UUID playerId, final DeckCardLists deckList) throws MageException {
|
||||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||||
try {
|
try {
|
||||||
rmiExecutor.execute(
|
callExecutor.execute(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -867,7 +864,7 @@ public class MageServerImpl implements MageServer {
|
||||||
public void disconnectUser(final String sessionId, final String userSessionId) throws MageException {
|
public void disconnectUser(final String sessionId, final String userSessionId) throws MageException {
|
||||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||||
try {
|
try {
|
||||||
rmiExecutor.execute(
|
callExecutor.execute(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -886,7 +883,7 @@ public class MageServerImpl implements MageServer {
|
||||||
public void removeTable(final String sessionId, final UUID tableId) throws MageException {
|
public void removeTable(final String sessionId, final UUID tableId) throws MageException {
|
||||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||||
try {
|
try {
|
||||||
rmiExecutor.execute(
|
callExecutor.execute(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
|
@ -31,6 +31,7 @@ package mage.server;
|
||||||
import mage.server.util.PluginClassLoader;
|
import mage.server.util.PluginClassLoader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
|
import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javax.management.MBeanServer;
|
import javax.management.MBeanServer;
|
||||||
|
@ -47,6 +48,9 @@ import mage.server.util.config.Plugin;
|
||||||
import mage.server.util.config.GamePlugin;
|
import mage.server.util.config.GamePlugin;
|
||||||
import mage.utils.MageVersion;
|
import mage.utils.MageVersion;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import org.jboss.remoting.Client;
|
||||||
|
import org.jboss.remoting.ClientDisconnectedException;
|
||||||
|
import org.jboss.remoting.ConnectionListener;
|
||||||
import org.jboss.remoting.InvocationRequest;
|
import org.jboss.remoting.InvocationRequest;
|
||||||
import org.jboss.remoting.InvokerLocator;
|
import org.jboss.remoting.InvokerLocator;
|
||||||
import org.jboss.remoting.ServerInvocationHandler;
|
import org.jboss.remoting.ServerInvocationHandler;
|
||||||
|
@ -113,20 +117,40 @@ public class Main {
|
||||||
logger.info("Started MAGE server - listening on " + connection.toString());
|
logger.info("Started MAGE server - listening on " + connection.toString());
|
||||||
if (testMode)
|
if (testMode)
|
||||||
logger.info("MAGE server running in test mode");
|
logger.info("MAGE server running in test mode");
|
||||||
|
} catch (IOException ex) {
|
||||||
|
logger.fatal("Failed to start server - " + connection.toString(), ex);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.fatal("Failed to start server - " + connection.toString(), ex);
|
logger.fatal("Failed to start server - " + connection.toString(), ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class ClientConnectionListener implements ConnectionListener {
|
||||||
|
@Override
|
||||||
|
public void handleConnectionException(Throwable throwable, Client client) {
|
||||||
|
Session session = SessionManager.getInstance().getSession(client.getSessionId());
|
||||||
|
if (session != null) {
|
||||||
|
String sessionName = session.getUsername() + " at " + session.getHost();
|
||||||
|
if (throwable instanceof ClientDisconnectedException) {
|
||||||
|
logger.info("client disconnected - " + sessionName);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
logger.info("connection to client lost - " + sessionName);
|
||||||
|
}
|
||||||
|
SessionManager.getInstance().disconnect(client.getSessionId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static class MageTransporterServer extends TransporterServer {
|
static class MageTransporterServer extends TransporterServer {
|
||||||
|
|
||||||
Connector connector;
|
protected Connector connector;
|
||||||
|
|
||||||
public MageTransporterServer(InvokerLocator locator, Object target, String subsystem, MageServerInvocationHandler callback) throws Exception {
|
public MageTransporterServer(InvokerLocator locator, Object target, String subsystem, MageServerInvocationHandler callback) throws Exception {
|
||||||
super(locator, target, subsystem);
|
super(locator, target, subsystem);
|
||||||
connector.addInvocationHandler("callback", callback);
|
connector.addInvocationHandler("callback", callback);
|
||||||
|
connector.setLeasePeriod(5000);
|
||||||
|
connector.addConnectionListener(new ClientConnectionListener());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Connector getConnector() throws Exception {
|
public Connector getConnector() throws Exception {
|
||||||
|
@ -170,7 +194,7 @@ public class Main {
|
||||||
public void removeListener(InvokerCallbackHandler callbackHandler) {
|
public void removeListener(InvokerCallbackHandler callbackHandler) {
|
||||||
ServerInvokerCallbackHandler handler = (ServerInvokerCallbackHandler) callbackHandler;
|
ServerInvokerCallbackHandler handler = (ServerInvokerCallbackHandler) callbackHandler;
|
||||||
String sessionId = handler.getCallbackClient().getSessionId();
|
String sessionId = handler.getCallbackClient().getSessionId();
|
||||||
SessionManager.getInstance().removeSession(sessionId);
|
SessionManager.getInstance().disconnect(sessionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,9 +76,8 @@ public class Session {
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return sessionId;
|
return sessionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void kill() {
|
public void kill() {
|
||||||
SessionManager.getInstance().removeSession(sessionId);
|
|
||||||
TableManager.getInstance().removeSession(sessionId);
|
TableManager.getInstance().removeSession(sessionId);
|
||||||
GameManager.getInstance().removeSession(sessionId);
|
GameManager.getInstance().removeSession(sessionId);
|
||||||
ChatManager.getInstance().removeSession(sessionId);
|
ChatManager.getInstance().removeSession(sessionId);
|
||||||
|
|
|
@ -82,8 +82,12 @@ public class SessionManager {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeSession(String sessionId) {
|
public synchronized void disconnect(String sessionId) {
|
||||||
sessions.remove(sessionId);
|
Session session = sessions.get(sessionId);
|
||||||
|
if (session != null) {
|
||||||
|
session.kill();
|
||||||
|
sessions.remove(sessionId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Session> getSessions() {
|
public Map<String, Session> getSessions() {
|
||||||
|
|
|
@ -237,6 +237,11 @@ public class TableController {
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void kill(String sessionId) {
|
||||||
|
leaveTable(sessionId);
|
||||||
|
sessionPlayerMap.remove(sessionId);
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized void leaveTable(String sessionId) {
|
public synchronized void leaveTable(String sessionId) {
|
||||||
if (table.getState() == TableState.WAITING || table.getState() == TableState.STARTING)
|
if (table.getState() == TableState.WAITING || table.getState() == TableState.STARTING)
|
||||||
table.leaveTable(sessionPlayerMap.get(sessionId));
|
table.leaveTable(sessionPlayerMap.get(sessionId));
|
||||||
|
|
|
@ -114,7 +114,9 @@ public class TableManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeSession(String sessionId) {
|
public void removeSession(String sessionId) {
|
||||||
// TODO: search through tables and remove session
|
for (TableController controller: controllers.values()) {
|
||||||
|
controller.kill(sessionId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTableOwner(UUID tableId, String sessionId) {
|
public boolean isTableOwner(UUID tableId, String sessionId) {
|
||||||
|
|
|
@ -142,7 +142,7 @@ public class DraftController {
|
||||||
|
|
||||||
private void checkStart() {
|
private void checkStart() {
|
||||||
if (allJoined()) {
|
if (allJoined()) {
|
||||||
ThreadExecutor.getInstance().getRMIExecutor().execute(
|
ThreadExecutor.getInstance().getCallExecutor().execute(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
|
@ -209,7 +209,7 @@ public class GameController implements GameCallback {
|
||||||
|
|
||||||
private void checkStart() {
|
private void checkStart() {
|
||||||
if (allJoined()) {
|
if (allJoined()) {
|
||||||
ThreadExecutor.getInstance().getRMIExecutor().execute(
|
ThreadExecutor.getInstance().getCallExecutor().execute(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
|
@ -141,7 +141,7 @@ public class TournamentController {
|
||||||
|
|
||||||
private void checkStart() {
|
private void checkStart() {
|
||||||
if (allJoined()) {
|
if (allJoined()) {
|
||||||
ThreadExecutor.getInstance().getRMIExecutor().execute(
|
ThreadExecutor.getInstance().getCallExecutor().execute(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
|
@ -36,13 +36,13 @@ import java.util.concurrent.*;
|
||||||
*/
|
*/
|
||||||
public class ThreadExecutor {
|
public class ThreadExecutor {
|
||||||
|
|
||||||
private static ExecutorService rmiExecutor = Executors.newCachedThreadPool();
|
private static final ExecutorService callExecutor = Executors.newCachedThreadPool();
|
||||||
private static ExecutorService gameExecutor = Executors.newFixedThreadPool(ConfigSettings.getInstance().getMaxGameThreads());
|
private static final ExecutorService gameExecutor = Executors.newFixedThreadPool(ConfigSettings.getInstance().getMaxGameThreads());
|
||||||
private static ScheduledExecutorService timeoutExecutor = Executors.newScheduledThreadPool(5);
|
private static final ScheduledExecutorService timeoutExecutor = Executors.newScheduledThreadPool(5);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
((ThreadPoolExecutor)rmiExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
((ThreadPoolExecutor)callExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
||||||
((ThreadPoolExecutor)rmiExecutor).allowCoreThreadTimeOut(true);
|
((ThreadPoolExecutor)callExecutor).allowCoreThreadTimeOut(true);
|
||||||
((ThreadPoolExecutor)gameExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
((ThreadPoolExecutor)gameExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
||||||
((ThreadPoolExecutor)gameExecutor).allowCoreThreadTimeOut(true);
|
((ThreadPoolExecutor)gameExecutor).allowCoreThreadTimeOut(true);
|
||||||
((ThreadPoolExecutor)timeoutExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
((ThreadPoolExecutor)timeoutExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
||||||
|
@ -57,8 +57,8 @@ public class ThreadExecutor {
|
||||||
|
|
||||||
private ThreadExecutor() {}
|
private ThreadExecutor() {}
|
||||||
|
|
||||||
public ExecutorService getRMIExecutor() {
|
public ExecutorService getCallExecutor() {
|
||||||
return rmiExecutor;
|
return callExecutor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExecutorService getGameExecutor() {
|
public ExecutorService getGameExecutor() {
|
||||||
|
|
11
pom.xml
11
pom.xml
|
@ -31,14 +31,9 @@
|
||||||
<module>Mage.Plugins</module>
|
<module>Mage.Plugins</module>
|
||||||
<module>Mage.Server.Plugins</module>
|
<module>Mage.Server.Plugins</module>
|
||||||
<module>Mage.Server.Console</module>
|
<module>Mage.Server.Console</module>
|
||||||
<module>Mage.Tests</module>
|
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
|
||||||
<id>sonatype-org</id>
|
|
||||||
<url>https://maven.nuxeo.org/nexus/content/repositories/public/org/</url>
|
|
||||||
</repository>
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>jboss-public-repository</id>
|
<id>jboss-public-repository</id>
|
||||||
<name>JBoss Repository</name>
|
<name>JBoss Repository</name>
|
||||||
|
@ -65,6 +60,10 @@
|
||||||
<updatePolicy>never</updatePolicy>
|
<updatePolicy>never</updatePolicy>
|
||||||
</snapshots>
|
</snapshots>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>sonatype-org</id>
|
||||||
|
<url>https://maven.nuxeo.org/nexus/content/repositories/public/org/</url>
|
||||||
|
</repository>
|
||||||
<repository>
|
<repository>
|
||||||
<id>mage.googlecode.com</id>
|
<id>mage.googlecode.com</id>
|
||||||
<url>https://mage.googlecode.com/hg/repository/</url>
|
<url>https://mage.googlecode.com/hg/repository/</url>
|
||||||
|
@ -92,4 +91,4 @@
|
||||||
<properties>
|
<properties>
|
||||||
<mage-version>0.8.0</mage-version>
|
<mage-version>0.8.0</mage-version>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
|
Loading…
Reference in a new issue