Source code: javax/ide/debug/ServerConnector.java
1 package javax.ide.debug;
2
3 import java.io.IOException;
4
5 /**
6 * ServerConnectors allow clients to start the debugger listening by calling
7 * the method {@link ServerConnector#startListening} waiting for a debuggee
8 * process to start. The debugge process can be started by the extension or
9 * the IDE. When the debuggee process is launched, the listening debugger will
10 * automatically accept the connection.
11 *
12 * IDE providers must provide an implementation of this interface. Extension
13 * writers can access the <code>Connector</code> through the
14 * {@link Debugger#getServerConnector} method.
15 */
16 public abstract class ServerConnector extends Connector
17 {
18 private boolean _isListening = false;
19
20 /**
21 * Tell the debugger to start listening for and accept a connection
22 * from a debuggee. This method will return after the debugger
23 * starts listening, but before it actually accepts a connection.
24 * (The debugger will create and start a new thread to accept
25 * the connection). After the debugger accepts a connection, it
26 * will automatically stop listening for subsequent connections.
27 *
28 * After calling this method, the extension writer should either start the
29 * debuggee process or tell the IDE to do so by calling {@link
30 * Connector#startDebuggee}.
31 *
32 * To tell the debugger to stop listening before it accepts a
33 * connection, (for example, if the extension was unable to start the
34 * debuggee process successfully), the extension should call
35 * {@link #stopListening}.
36 *
37 * If this ServerConnector has already accepted a connection (and
38 * has automatically stopped listening), it may or may not be able
39 * to start listening again. If it does not support listening for
40 * another connection, this method will throw
41 * <code>UnsupportedOperationException</code>.
42 *
43 * @exception IOException if this connector is unable to start
44 * listening.
45 * @exception UnsupportedOperationException if this connector has
46 * already accepted a connection and does not support listening for
47 * another connection.
48 */
49 public final void startListening() throws IOException
50 {
51 try
52 {
53 startListeningImpl();
54 }
55 finally
56 {
57 _isListening = true;
58 }
59 }
60
61 protected abstract void startListeningImpl() throws IOException;
62
63 /**
64 * Check if the debugger is listening for a debuggee connection.
65 * @return true if listening; false otherwise.
66 */
67 public final boolean isListening()
68 {
69 return _isListening;
70 }
71
72 /**
73 * Tell the listening debugger to stop listening.
74 */
75 public final void stopListening()
76 {
77 try
78 {
79 stopListeningImpl();
80 }
81 finally
82 {
83 _isListening = false;
84 }
85 }
86
87 protected abstract void stopListeningImpl();
88 }
89