Skip to content

Commit 6084eb7

Browse files
author
Steve Powell
committed
Improved Javadoc for Tracer and Tracer.AsyncLogger classes.
1 parent 3ef76ef commit 6084eb7

File tree

1 file changed

+46
-10
lines changed

1 file changed

+46
-10
lines changed

src/com/rabbitmq/tools/Tracer.java

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,44 @@
4141
import com.rabbitmq.utility.Utility;
4242

4343
/**
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
4882
*/
4983
public class Tracer implements Runnable {
5084
private static final int DEFAULT_LISTEN_PORT = 5673;
@@ -367,18 +401,20 @@ public interface Logger {
367401
/**
368402
* A {@link Tracer.Logger} designed to print {@link String}s to a designated {@link OutputStream}
369403
* 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}
371405
* which is periodically flushed, determined by a {@link #flushInterval}.
372406
* <p/>
373407
* 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.
375410
* <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.
378413
* <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.
380416
* <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.
382418
*/
383419
public static class AsyncLogger implements Logger {
384420
private static final int MIN_FLUSH_INTERVAL = 100;

0 commit comments

Comments
 (0)