Skip to content

Commit 39ba2cd

Browse files
committed
Merge pull request #95 from testmycode/background-comet
Do all comet connection attempts in a background thread.
2 parents 2234240 + 97d9b25 commit 39ba2cd

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

tmc-plugin/src/fi/helsinki/cs/tmc/model/PushEventListener.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,13 @@ public static void start() {
5555
this.eventBus = TmcEventBus.getDefault();
5656
this.shouldReconnect = false;
5757

58-
initClientIfPossible();
59-
6058
this.eventBus.subscribeDependent(new TmcEventListener() {
6159
public void receive(TmcSettings.SavedEvent e) {
62-
reconnect();
60+
reconnectSoon();
6361
}
6462

6563
public void receive(CourseDb.ChangedEvent e) {
66-
reconnect();
64+
reconnectSoon();
6765
}
6866
}, this);
6967

@@ -73,14 +71,25 @@ public void receive(CourseDb.ChangedEvent e) {
7371
public void run() {
7472
ensureConnected();
7573
}
76-
}, CONNECTION_CHECK_INTERVAL);
74+
}, 0, CONNECTION_CHECK_INTERVAL);
7775
}
7876

7977
private synchronized void ensureConnected() {
80-
if (client != null && client.isDisconnected()) {
78+
if (client == null || client.isDisconnected()) {
8179
initClientIfPossible();
8280
}
8381
}
82+
83+
private void reconnectSoon() {
84+
Thread t = new Thread() {
85+
@Override
86+
public void run() {
87+
reconnect();
88+
}
89+
};
90+
t.setDaemon(true);
91+
t.start();
92+
}
8493

8594
private synchronized void reconnect() {
8695
if (client != null && client.isConnected()) {

0 commit comments

Comments
 (0)