01: /*
02: * TclInterruptedException.java
03: *
04: * Copyright (c) 2006 Moses DeJong
05: *
06: * See the file "license.terms" for information on usage and
07: * redistribution of this file, and for a DISCLAIMER OF ALL
08: * WARRANTIES.
09: *
10: * RCS: @(#) $Id: TclInterruptedException.java,v 1.1 2006/04/27 02:16:13 mdejong Exp $
11: *
12: */
13:
14: package tcl.lang;
15:
16: /**
17: * Signals that an interp has been interrupted via the
18: * Interp.setInterrupted() API. This exception is used
19: * to unwind the Tcl stack and remove pending events
20: * from the Tcl event queue.
21: */
22:
23: public final class TclInterruptedException extends RuntimeException {
24: Interp interp;
25:
26: public TclInterruptedException(Interp interp) {
27: this .interp = interp;
28: }
29:
30: // This method should be invoked after the Tcl
31: // stack has been fully unwound to cleanup
32: // Interp state, remove any pending events,
33: // and dispose of the Interp object.
34:
35: public void disposeInterruptedInterp() {
36: interp.disposeInterrupted();
37: }
38: }
39:
40: // This class implements an event that will raise
41: // a TclInterruptedException in the interp. This
42: // event is queued from a thread other the one
43: // the interp is executing in, so be careful
44: // not to interact with the interp since it
45: // would not be thread safe. This event will
46: // wake up a Jacl thread waiting in a vwait
47: // or in the main processing loop. This class is
48: // used only in Jacl's Interp implementaton.
49:
50: class TclInterruptedExceptionEvent extends TclEvent implements
51: EventDeleter {
52: Interp interp;
53: boolean wasProcessed;
54: boolean exceptionRaised;
55:
56: TclInterruptedExceptionEvent(Interp interp) {
57: this .interp = interp;
58: this .wasProcessed = false;
59: this .exceptionRaised = false;
60: }
61:
62: // processEvent() is invoked in the interp thread,
63: // so this code can interact with the interp.
64:
65: public int processEvent(int flags) {
66: wasProcessed = true;
67: interp.checkInterrupted();
68:
69: // Should never reach here since
70: // an earlier call to setInterrupted()
71: // would cause checkInterrupted() to
72: // raise a TclInterruptedException.
73: // return code just makes the compiler happy.
74:
75: return 1;
76: }
77:
78: // Implement EventDeleter so that this event can
79: // delete itself from the pending event queue.
80: // This method returns 1 when an event should
81: // be deleted from the queue.
82:
83: public int deleteEvent(TclEvent evt) {
84: if (evt == this ) {
85: return 1;
86: }
87: return 0;
88: }
89:
90: }
|