|
@@ -99,7 +99,8 @@ public final class Server extends WritableFrameContainer implements Serializable
|
99
|
99
|
private transient Identity profile;
|
100
|
100
|
|
101
|
101
|
/** The current state of this server. */
|
102
|
|
- private ServerState myState = ServerState.DISCONNECTED;
|
|
102
|
+ private final ServerStatus myState = new ServerStatus();
|
|
103
|
+
|
103
|
104
|
/** The timer we're using to delay reconnects. */
|
104
|
105
|
private Timer reconnectTimer;
|
105
|
106
|
|
|
@@ -238,7 +239,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
238
|
239
|
assert profile != null;
|
239
|
240
|
|
240
|
241
|
synchronized (this) {
|
241
|
|
- switch (myState) {
|
|
242
|
+ switch (myState.getState()) {
|
242
|
243
|
case RECONNECT_WAIT:
|
243
|
244
|
reconnectTimer.cancel();
|
244
|
245
|
break;
|
|
@@ -262,7 +263,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
262
|
263
|
+ "is still connected.\n\nMy state:" + myState);
|
263
|
264
|
}
|
264
|
265
|
|
265
|
|
- myState = ServerState.CONNECTING;
|
|
266
|
+ myState.transition(ServerState.CONNECTING);
|
266
|
267
|
|
267
|
268
|
ActionManager.processEvent(CoreActionType.SERVER_CONNECTING, null, this);
|
268
|
269
|
|
|
@@ -327,7 +328,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
327
|
328
|
*/
|
328
|
329
|
public void reconnect(final String reason) {
|
329
|
330
|
synchronized (this) {
|
330
|
|
- if (myState == ServerState.CLOSING) {
|
|
331
|
+ if (myState.getState() == ServerState.CLOSING) {
|
331
|
332
|
return;
|
332
|
333
|
}
|
333
|
334
|
|
|
@@ -358,7 +359,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
358
|
359
|
*/
|
359
|
360
|
public void disconnect(final String reason) {
|
360
|
361
|
synchronized (this) {
|
361
|
|
- switch (myState) {
|
|
362
|
+ switch (myState.getState()) {
|
362
|
363
|
case CLOSING:
|
363
|
364
|
case DISCONNECTED:
|
364
|
365
|
case TRANSIENTLY_DISCONNECTED:
|
|
@@ -370,13 +371,13 @@ public final class Server extends WritableFrameContainer implements Serializable
|
370
|
371
|
break;
|
371
|
372
|
}
|
372
|
373
|
|
373
|
|
- myState = ServerState.DISCONNECTING;
|
|
374
|
+ myState.transition(ServerState.DISCONNECTING);
|
374
|
375
|
|
375
|
376
|
removeInvites();
|
376
|
377
|
updateIcon();
|
377
|
378
|
|
378
|
379
|
if (parser == null) {
|
379
|
|
- myState = ServerState.DISCONNECTED;
|
|
380
|
+ myState.transition(ServerState.DISCONNECTED);
|
380
|
381
|
} else {
|
381
|
382
|
parser.disconnect(reason);
|
382
|
383
|
}
|
|
@@ -401,7 +402,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
401
|
402
|
@Precondition("The server state is transiently disconnected")
|
402
|
403
|
private void doDelayedReconnect() {
|
403
|
404
|
synchronized (this) {
|
404
|
|
- if (myState != ServerState.TRANSIENTLY_DISCONNECTED) {
|
|
405
|
+ if (myState.getState() != ServerState.TRANSIENTLY_DISCONNECTED) {
|
405
|
406
|
throw new IllegalStateException("doDelayedReconnect when not "
|
406
|
407
|
+ "transiently disconnected\n\nState: " + myState);
|
407
|
408
|
}
|
|
@@ -416,15 +417,15 @@ public final class Server extends WritableFrameContainer implements Serializable
|
416
|
417
|
@Override
|
417
|
418
|
public void run() {
|
418
|
419
|
synchronized (Server.this) {
|
419
|
|
- if (myState == ServerState.RECONNECT_WAIT) {
|
420
|
|
- myState = ServerState.TRANSIENTLY_DISCONNECTED;
|
|
420
|
+ if (myState.getState() == ServerState.RECONNECT_WAIT) {
|
|
421
|
+ myState.transition(ServerState.TRANSIENTLY_DISCONNECTED);
|
421
|
422
|
reconnect();
|
422
|
423
|
}
|
423
|
424
|
}
|
424
|
425
|
}
|
425
|
426
|
}, delay);
|
426
|
427
|
|
427
|
|
- myState = ServerState.RECONNECT_WAIT;
|
|
428
|
+ myState.transition(ServerState.RECONNECT_WAIT);
|
428
|
429
|
updateIcon();
|
429
|
430
|
}
|
430
|
431
|
}
|
|
@@ -560,7 +561,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
560
|
561
|
*/
|
561
|
562
|
public void addChannel(final ChannelInfo chan) {
|
562
|
563
|
synchronized (this) {
|
563
|
|
- if (myState == ServerState.CLOSING) {
|
|
564
|
+ if (myState.getState() == ServerState.CLOSING) {
|
564
|
565
|
// Can't join channels while the server is closing
|
565
|
566
|
return;
|
566
|
567
|
}
|
|
@@ -585,7 +586,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
585
|
586
|
*/
|
586
|
587
|
public void addQuery(final String host) {
|
587
|
588
|
synchronized (this) {
|
588
|
|
- if (myState == ServerState.CLOSING) {
|
|
589
|
+ if (myState.getState() == ServerState.CLOSING) {
|
589
|
590
|
// Can't open queries while the server is closing
|
590
|
591
|
return;
|
591
|
592
|
}
|
|
@@ -660,7 +661,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
660
|
661
|
* Updates this server's icon.
|
661
|
662
|
*/
|
662
|
663
|
private void updateIcon() {
|
663
|
|
- final String icon = myState == ServerState.CONNECTED
|
|
664
|
+ final String icon = myState.getState() == ServerState.CONNECTED
|
664
|
665
|
? serverInfo.getSSL() ? "secure-server" : "server"
|
665
|
666
|
: "server-disconnected";
|
666
|
667
|
setIcon(icon);
|
|
@@ -709,7 +710,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
709
|
710
|
*/
|
710
|
711
|
public void join(final String channel) {
|
711
|
712
|
synchronized (this) {
|
712
|
|
- if (myState == ServerState.CONNECTED) {
|
|
713
|
+ if (myState.getState() == ServerState.CONNECTED) {
|
713
|
714
|
removeInvites(channel);
|
714
|
715
|
|
715
|
716
|
if (hasChannel(channel)) {
|
|
@@ -728,7 +729,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
728
|
729
|
@Override
|
729
|
730
|
public void sendLine(final String line) {
|
730
|
731
|
synchronized (this) {
|
731
|
|
- if (parser != null && myState == ServerState.CONNECTED) {
|
|
732
|
+ if (parser != null && myState.getState() == ServerState.CONNECTED) {
|
732
|
733
|
parser.sendLine(window.getTranscoder().encode(line));
|
733
|
734
|
}
|
734
|
735
|
}
|
|
@@ -877,7 +878,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
877
|
878
|
* @return This server's state
|
878
|
879
|
*/
|
879
|
880
|
public ServerState getState() {
|
880
|
|
- return myState;
|
|
881
|
+ return myState.getState();
|
881
|
882
|
}
|
882
|
883
|
|
883
|
884
|
/** {@inheritDoc} */
|
|
@@ -895,7 +896,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
895
|
896
|
disconnect();
|
896
|
897
|
}
|
897
|
898
|
|
898
|
|
- myState = ServerState.CLOSING;
|
|
899
|
+ myState.transition(ServerState.CLOSING);
|
899
|
900
|
closeChannels();
|
900
|
901
|
closeQueries();
|
901
|
902
|
removeInvites();
|
|
@@ -1138,15 +1139,16 @@ public final class Server extends WritableFrameContainer implements Serializable
|
1138
|
1139
|
eventHandler.unregisterCallbacks();
|
1139
|
1140
|
|
1140
|
1141
|
synchronized (this) {
|
1141
|
|
- if (myState == ServerState.CLOSING || myState == ServerState.DISCONNECTED) {
|
|
1142
|
+ if (myState.getState() == ServerState.CLOSING
|
|
1143
|
+ || myState.getState() == ServerState.DISCONNECTED) {
|
1142
|
1144
|
// This has been triggered via .disconect()
|
1143
|
1145
|
return;
|
1144
|
1146
|
}
|
1145
|
1147
|
|
1146
|
|
- if (myState == ServerState.DISCONNECTING) {
|
1147
|
|
- myState = ServerState.DISCONNECTED;
|
|
1148
|
+ if (myState.getState() == ServerState.DISCONNECTING) {
|
|
1149
|
+ myState.transition(ServerState.DISCONNECTED);
|
1148
|
1150
|
} else {
|
1149
|
|
- myState = ServerState.TRANSIENTLY_DISCONNECTED;
|
|
1151
|
+ myState.transition(ServerState.TRANSIENTLY_DISCONNECTED);
|
1150
|
1152
|
}
|
1151
|
1153
|
|
1152
|
1154
|
updateIcon();
|
|
@@ -1168,7 +1170,7 @@ public final class Server extends WritableFrameContainer implements Serializable
|
1168
|
1170
|
|
1169
|
1171
|
if (getConfigManager().getOptionBool(DOMAIN_GENERAL,
|
1170
|
1172
|
"reconnectondisconnect", false)
|
1171
|
|
- && myState == ServerState.TRANSIENTLY_DISCONNECTED) {
|
|
1173
|
+ && myState.getState() == ServerState.TRANSIENTLY_DISCONNECTED) {
|
1172
|
1174
|
doDelayedReconnect();
|
1173
|
1175
|
}
|
1174
|
1176
|
}
|
|
@@ -1182,16 +1184,17 @@ public final class Server extends WritableFrameContainer implements Serializable
|
1182
|
1184
|
@Precondition("The current server state is CONNECTING")
|
1183
|
1185
|
public void onConnectError(final ParserError errorInfo) {
|
1184
|
1186
|
synchronized (this) {
|
1185
|
|
- if (myState == ServerState.CLOSING || myState == ServerState.DISCONNECTING) {
|
|
1187
|
+ if (myState.getState() == ServerState.CLOSING
|
|
1188
|
+ || myState.getState() == ServerState.DISCONNECTING) {
|
1186
|
1189
|
// Do nothing
|
1187
|
1190
|
return;
|
1188
|
|
- } else if (myState != ServerState.CONNECTING) {
|
|
1191
|
+ } else if (myState.getState() != ServerState.CONNECTING) {
|
1189
|
1192
|
// Shouldn't happen
|
1190
|
1193
|
throw new IllegalStateException("Connect error when not "
|
1191
|
1194
|
+ "connecting\n\nState: " + myState);
|
1192
|
1195
|
}
|
1193
|
1196
|
|
1194
|
|
- myState = ServerState.TRANSIENTLY_DISCONNECTED;
|
|
1197
|
+ myState.transition(ServerState.TRANSIENTLY_DISCONNECTED);
|
1195
|
1198
|
|
1196
|
1199
|
updateIcon();
|
1197
|
1200
|
|
|
@@ -1251,13 +1254,13 @@ public final class Server extends WritableFrameContainer implements Serializable
|
1251
|
1254
|
@Precondition("State is CONNECTING")
|
1252
|
1255
|
public void onPost005() {
|
1253
|
1256
|
synchronized (this) {
|
1254
|
|
- if (myState != ServerState.CONNECTING) {
|
|
1257
|
+ if (myState.getState() != ServerState.CONNECTING) {
|
1255
|
1258
|
// Shouldn't happen
|
1256
|
1259
|
throw new IllegalStateException("Received onPost005 while not "
|
1257
|
1260
|
+ "connecting\n\nState: " + myState);
|
1258
|
1261
|
}
|
1259
|
1262
|
|
1260
|
|
- myState = ServerState.CONNECTED;
|
|
1263
|
+ myState.transition(ServerState.CONNECTED);
|
1261
|
1264
|
|
1262
|
1265
|
updateIcon();
|
1263
|
1266
|
|