Skip to content
This repository was archived by the owner on Sep 19, 2021. It is now read-only.

Commit 05b2008

Browse files
committed
Finish Integration With Relay
Added a system called the Timeline which allows work to be set to run at specific points in time. This allows work to be queued. To allow the relay server data to merge in with the server, a work item is set to run every minute. When it finishs, it sets itself to run again in a minute. When data needs to be sent to the relay, a work item is added to the timeline so that the current connection can be closed before sending data to the relay. The timeline allowed for the Hub to be removed as work items to handle connections could be added to the timeline. Closes #4.
1 parent c61ff47 commit 05b2008

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

src/codeu/chat/server/Server.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040

4141
public final class Server {
4242

43-
private final static Logger.Log LOG = Logger.newLog(Server.class);
43+
private static final Logger.Log LOG = Logger.newLog(Server.class);
44+
45+
private static final int RELAY_REFRESH_MS = 5000; // 5 seconds
4446

4547
private final Timeline timeline = new Timeline();
4648

@@ -80,8 +82,7 @@ public void run() {
8082

8183
}
8284

83-
// Do this again in 5 seconds
84-
timeline.scheduleIn(5000, this);
85+
timeline.scheduleIn(RELAY_REFRESH_MS, this);
8586
}
8687
});
8788
}

src/codeu/chat/util/Timeline.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public void scheduleAt(long timeMs, Runnable callback) {
161161
public void stop() {
162162
running = false;
163163

164-
// Interrupt does not force a thread to exit. It signal's the
164+
// Interrupt does not force a thread to exit. It signals the
165165
// thead that it is time to stop execution. As the threads may
166166
// be sleeping, this will force them awake.
167167
executor.interrupt();
@@ -189,7 +189,7 @@ private static void forceJoin(Thread thread) {
189189

190190
private static <T> void forceAdd(BlockingQueue<T> queue, T value) {
191191
while (!queue.offer(value)) {
192-
// try again...
192+
LOG.warning("Failed to add to queue, trying again...");
193193
}
194194
}
195195
}

0 commit comments

Comments
 (0)