mirror of
https://github.com/magefree/mage.git
synced 2025-12-21 02:52:02 -08:00
updated session state
This commit is contained in:
parent
48e1b45091
commit
09be5934f5
1 changed files with 11 additions and 15 deletions
|
|
@ -77,8 +77,6 @@ public class Session {
|
||||||
private CallbackClientDaemon callbackDaemon;
|
private CallbackClientDaemon callbackDaemon;
|
||||||
private ScheduledFuture<?> future;
|
private ScheduledFuture<?> future;
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
private boolean reconnecting = false;
|
|
||||||
private boolean connecting = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For locking session object.
|
* For locking session object.
|
||||||
|
|
@ -94,7 +92,6 @@ public class Session {
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized boolean connect(Connection connection) {
|
public synchronized boolean connect(Connection connection) {
|
||||||
this.connecting = true;
|
|
||||||
if (isConnected()) {
|
if (isConnected()) {
|
||||||
disconnect(true);
|
disconnect(true);
|
||||||
}
|
}
|
||||||
|
|
@ -103,6 +100,7 @@ public class Session {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean connect() {
|
public boolean connect() {
|
||||||
|
sessionState = SessionState.CONNECTING;
|
||||||
try {
|
try {
|
||||||
System.setSecurityManager(null);
|
System.setSecurityManager(null);
|
||||||
System.setProperty("http.nonProxyHosts", "code.google.com");
|
System.setProperty("http.nonProxyHosts", "code.google.com");
|
||||||
|
|
@ -130,25 +128,20 @@ public class Session {
|
||||||
this.userName = connection.getUsername();
|
this.userName = connection.getUsername();
|
||||||
sessionId = server.registerClient(userName, client.getId(), client.getVersion());
|
sessionId = server.registerClient(userName, client.getId(), client.getVersion());
|
||||||
callbackDaemon = new CallbackClientDaemon(sessionId, client, server);
|
callbackDaemon = new CallbackClientDaemon(sessionId, client, server);
|
||||||
|
sessionState = SessionState.CONNECTED;
|
||||||
serverState = server.getServerState();
|
serverState = server.getServerState();
|
||||||
future = sessionExecutor.scheduleWithFixedDelay(new ServerPinger(), 5, 5, TimeUnit.SECONDS);
|
future = sessionExecutor.scheduleWithFixedDelay(new ServerPinger(), 5, 5, TimeUnit.SECONDS);
|
||||||
logger.info("Connected to RMI server at " + connection.getHost() + ":" + connection.getPort());
|
logger.info("Connected to RMI server at " + connection.getHost() + ":" + connection.getPort());
|
||||||
client.connected("Connected to " + connection.getHost() + ":" + connection.getPort() + " ");
|
client.connected("Connected to " + connection.getHost() + ":" + connection.getPort() + " ");
|
||||||
reconnecting = false;
|
|
||||||
connecting = false;
|
|
||||||
return true;
|
return true;
|
||||||
} catch (MageException ex) {
|
} catch (MageException ex) {
|
||||||
logger.fatal("", ex);
|
logger.fatal("", ex);
|
||||||
if (!reconnecting) {
|
|
||||||
disconnect(false);
|
disconnect(false);
|
||||||
client.showMessage("Unable to connect to server. " + ex.getMessage());
|
client.showMessage("Unable to connect to server. " + ex.getMessage());
|
||||||
}
|
|
||||||
} catch (RemoteException ex) {
|
} catch (RemoteException ex) {
|
||||||
logger.fatal("Unable to connect to server - ", ex);
|
logger.fatal("Unable to connect to server - ", ex);
|
||||||
if (!reconnecting) {
|
|
||||||
disconnect(false);
|
disconnect(false);
|
||||||
client.showMessage("Unable to connect to server. " + ex.getMessage());
|
client.showMessage("Unable to connect to server. " + ex.getMessage());
|
||||||
}
|
|
||||||
} catch (NotBoundException ex) {
|
} catch (NotBoundException ex) {
|
||||||
logger.fatal("Unable to connect to server - ", ex);
|
logger.fatal("Unable to connect to server - ", ex);
|
||||||
}
|
}
|
||||||
|
|
@ -158,9 +151,11 @@ public class Session {
|
||||||
public synchronized void disconnect(boolean showMessage) {
|
public synchronized void disconnect(boolean showMessage) {
|
||||||
if (sessionState == SessionState.CONNECTED)
|
if (sessionState == SessionState.CONNECTED)
|
||||||
sessionState = SessionState.DISCONNECTING;
|
sessionState = SessionState.DISCONNECTING;
|
||||||
if (connection == null)
|
if (future != null && !future.isDone())
|
||||||
|
future.cancel(true);
|
||||||
|
if (connection == null || server == null)
|
||||||
return;
|
return;
|
||||||
if (sessionState == SessionState.CONNECTED) {
|
if (sessionState == SessionState.DISCONNECTING) {
|
||||||
try {
|
try {
|
||||||
server.deregisterClient(sessionId);
|
server.deregisterClient(sessionId);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
|
@ -728,6 +723,7 @@ public class Session {
|
||||||
|
|
||||||
private void handleRemoteException(RemoteException ex) {
|
private void handleRemoteException(RemoteException ex) {
|
||||||
logger.fatal("Communication error", ex);
|
logger.fatal("Communication error", ex);
|
||||||
|
sessionState = SessionState.SERVER_UNAVAILABLE;
|
||||||
disconnect(false);
|
disconnect(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue