|
41 | 41 | import com.rabbitmq.utility.Utility; |
42 | 42 |
|
43 | 43 | /** |
44 | | - * AMQP Protocol Analyzer program. Listens on a configurable port and when a |
45 | | - * connection arrives, makes an outbound connection to a configurable host and |
46 | | - * port. Relays frames between each pair of sockets. Commands are decoded and |
47 | | - * printed to stdout. Listens serially for subsequent connections. |
| 44 | + * AMQP Protocol Analyzer program. Listens on a port (in-port) and when a |
| 45 | + * connection arrives, makes an outbound connection to a host and |
| 46 | + * port (out-port). Relays frames from the in-port to the out-port. |
| 47 | + * Commands are decoded and printed to a supplied {@link Logger}. |
| 48 | + * <p/> |
| 49 | + * The stand-alone program ({@link #main()}) prints to <code>System.out</code>, |
| 50 | + * using a private {@link AsyncLogger} instance. When the connection closes |
| 51 | + * the program listens for a subsequent connection and traces that to the same {@link Logger}. |
| 52 | + * This continues until the program is interrupted. |
| 53 | + * <p/> |
| 54 | + * Options for controlling, for example, whether command bodies are decoded, |
| 55 | + * are obtained from <code>System.properties</code>, and are reported to the console |
| 56 | + * before starting the trace. |
| 57 | + * <p/> |
| 58 | + * A {@link Tracer} object may be instantiated, using one of the constructors |
| 59 | + * <ul> |
| 60 | + * <li><code>Tracer(int listenPort, String id, String host, int port, Logger logger, Properties props)</code></li> |
| 61 | + * <li><code>Tracer(String id)</code></li> |
| 62 | + * <li><code>Tracer(String id, Properties props)</code> |
| 63 | + * <p/>where the missing parameters default as follows: |
| 64 | + * <ul> |
| 65 | + * <li><code>listenPort</code> defaults to <code>5673</code></li> |
| 66 | + * <li><code>host</code> defaults to <q><code>localhost</code></q></li> |
| 67 | + * <li><code>port</code> defaults to <code>5672</code></li> |
| 68 | + * <li><code>logger</code> defaults to <code>new AsyncLogger(System.out)</code></li> and |
| 69 | + * <li><code>props</code> defaults to <code>System.getProperties()</code></li> |
| 70 | + * </ul> |
| 71 | + * </li> |
| 72 | + * </ul> |
| 73 | + * <p/> |
| 74 | + * These constructors block waiting for a connection to arrive on the listenPort. |
| 75 | + * Tracing does not begin until the tracer is {@link #start()}ed which {@link Logger#start()}s |
| 76 | + * the supplied logger and creates and starts a {@link Thread} for relaying and deconstructing the frames. |
| 77 | + * <p/> |
| 78 | + * The properties specified in <code>props</code> are used at {@link Tracer#start()} time and may be modified |
| 79 | + * before this call. |
| 80 | + * @see Tracer.Logger |
| 81 | + * @see Tracer.AsyncLogger |
48 | 82 | */ |
49 | 83 | public class Tracer implements Runnable { |
50 | 84 | private static final int DEFAULT_LISTEN_PORT = 5673; |
@@ -367,18 +401,20 @@ public interface Logger { |
367 | 401 | /** |
368 | 402 | * A {@link Tracer.Logger} designed to print {@link String}s to a designated {@link OutputStream} |
369 | 403 | * on a private thread. |
370 | | - * <br/>{@link String}s are read from a private queue and <i>printed</i> to a buffered {@link PrintStream} |
| 404 | + * <p/>{@link String}s are read from a private queue and <i>printed</i> to a buffered {@link PrintStream} |
371 | 405 | * which is periodically flushed, determined by a {@link #flushInterval}. |
372 | 406 | * <p/> |
373 | 407 | * When instantiated the private queue is created (an in-memory {@link ArrayBlockingQueue} in this |
374 | | - * implementation) and when {@link #start()}ed the private thread is created and started. |
| 408 | + * implementation) and when {@link #start()}ed the private thread is created and started unless it is |
| 409 | + * already present. An {@link AsyncLogger} may be started many times, but only one thread is created. |
375 | 410 | * <p/> |
376 | | - * When {@link #stop()}ed a special element is queued which causes the private thread to end when encountered. |
377 | | - * Alternatively, if the private thread is interrupted, the thread will also end. |
| 411 | + * When {@link #stop()}ed either the number of starts is decremented, or, if this count reaches zero, |
| 412 | + * a special element is queued which causes the private thread to end when encountered. |
378 | 413 | * <p/> |
379 | | - * {@link #log()} may block if the queue is full, and this may never un-block if the {@link Logger} is not started. |
| 414 | + * If the private thread is interrupted, the thread will also end, and the count set to zero, |
| 415 | + * This will cause subsequent {@link #stop()}s to be ignored, and the next {@link #start()} will create a new thread. |
380 | 416 | * <p/> |
381 | | - * {@link #start()} may be re-issued after {@link #stop()}, creating a new private thread. |
| 417 | + * {@link #log()} never blocks unless the private queue is full; this may never un-block if the {@link Logger} is stopped. |
382 | 418 | */ |
383 | 419 | public static class AsyncLogger implements Logger { |
384 | 420 | private static final int MIN_FLUSH_INTERVAL = 100; |
|
0 commit comments