01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tcsimulator;
05:
06: import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;
07:
08: public class EventQueueHandler implements Runnable {
09: private final LinkedQueue queue;
10: private final Setup setup;
11:
12: public EventQueueHandler(LinkedQueue queue, Setup setup) {
13: this .queue = queue;
14: this .setup = setup;
15: }
16:
17: public void run() {
18: while (true) {
19: try {
20: Object obj = this .queue.take();
21: if (obj instanceof QueueEvent) {
22: QueueEvent event = (QueueEvent) obj;
23: if (event.getAction() == QueueEvent.SERVER_CRASH) {
24: setup.crashServer();
25: } else if (event.getAction() == QueueEvent.SERVER_RESTART) {
26: setup.restartServer();
27: }
28: } else {
29: throw new AssertionError(
30: "EventQueue was populated with a non-QueueEvent object.");
31: }
32: } catch (Exception e) {
33: throw new RuntimeException(e);
34: }
35: }
36: }
37: }
|