43
43
import com .rabbitmq .client .impl .AMQImpl ;
44
44
import com .rabbitmq .client .impl .Frame ;
45
45
import com .rabbitmq .utility .BlockingCell ;
46
+ import com .rabbitmq .utility .Utility ;
46
47
47
48
48
49
/**
@@ -95,28 +96,22 @@ private static class AsyncLogger extends Thread{
95
96
}.start ();
96
97
}
97
98
98
- void printMessage (Object message ){
99
- if (message instanceof Throwable ){
100
- ((Throwable )message ).printStackTrace (ps );
101
- } else if (message instanceof String ){
102
- ps .println (message );
103
- } else {
104
- throw new RuntimeException ("Unrecognised object " + message );
105
- }
99
+ void printMessage (String message ){
100
+ ps .println (message );
106
101
}
107
102
108
103
@ Override public void run (){
109
104
try {
110
105
while (true ){
111
106
Object message = queue .take ();
112
107
if (message == FLUSH ) ps .flush ();
113
- else printMessage (message );
108
+ else printMessage (( String ) message );
114
109
}
115
110
} catch (InterruptedException interrupt ){
116
111
}
117
112
}
118
113
119
- void log (Object message ){
114
+ void log (String message ){
120
115
try {
121
116
queue .put (message );
122
117
} catch (InterruptedException ex ){
@@ -200,22 +195,31 @@ public void run() {
200
195
new Thread (outHandler ).start ();
201
196
Object result = w .uninterruptibleGet ();
202
197
if (result instanceof Exception ) {
203
- logger . log ( result );
198
+ logException (( Exception ) result );
204
199
}
205
200
} catch (EOFException eofe ) {
206
- logger . log ( eofe );
201
+ logException (( Exception ) eofe );
207
202
} catch (IOException ioe ) {
208
- logger . log ( ioe );
203
+ logException (( Exception ) ioe );
209
204
} finally {
210
205
try {
211
206
inSock .close ();
212
207
outSock .close ();
213
208
} catch (IOException ioe2 ) {
214
- logger . log ( ioe2 );
209
+ logException (( Exception ) ioe2 );
215
210
}
216
211
}
217
212
}
218
213
214
+ public void log (String message ){
215
+ logger .log ("" + System .currentTimeMillis () + ": conn#"
216
+ + id + " " + message );
217
+ }
218
+
219
+ public void logException (Exception e ){
220
+ log ("uncaught " + Utility .makeStackTrace (e ));
221
+ }
222
+
219
223
public class DirectionHandler implements Runnable {
220
224
public BlockingCell <Object > waitCell ;
221
225
@@ -239,7 +243,9 @@ public Frame readFrame() throws IOException {
239
243
}
240
244
241
245
public void report (int channel , Object object ) {
242
- logger .log ("" + System .currentTimeMillis () + ": conn#" + id + " ch#" + channel + (inBound ? " -> " : " <- " ) + object );
246
+ Tracer .this .log ("ch#" + channel
247
+ + (inBound ? " -> " : " <- " )
248
+ + object );
243
249
}
244
250
245
251
public void reportFrame (Frame f )
@@ -265,6 +271,7 @@ public void reportFrame(Frame f)
265
271
}
266
272
}
267
273
274
+
268
275
public void doFrame () throws IOException {
269
276
Frame f = readFrame ();
270
277
0 commit comments