01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.debug.jdi.tests;
11:
12: /**
13: * An abstract reader that continuously reads.
14: */
15: abstract public class AbstractReader {
16: protected String fName;
17: protected Thread fReaderThread;
18: protected boolean fIsStopping = false;
19:
20: /**
21: * Constructor
22: * @param name
23: */
24: public AbstractReader(String name) {
25: fName = name;
26: }
27:
28: /**
29: * Continuously reads. Note that if the read involves waiting
30: * it can be interrupted and a InterruptedException will be thrown.
31: */
32: abstract protected void readerLoop();
33:
34: /**
35: * Start the thread that reads events.
36: *
37: */
38: public void start() {
39: fReaderThread = new Thread(new Runnable() {
40: public void run() {
41: readerLoop();
42: }
43: }, fName);
44: fReaderThread.setDaemon(true);
45: fReaderThread.start();
46: }
47:
48: /**
49: * Tells the reader loop that it should stop.
50: */
51: public void stop() {
52: fIsStopping = true;
53: if (fReaderThread != null)
54: fReaderThread.interrupt();
55: }
56: }
|