Skip to content

Commit 84f2264

Browse files
author
David R. MacIver
committed
add connection and timestamp information to thrown exceptions
1 parent f0ff8de commit 84f2264

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

src/com/rabbitmq/tools/Tracer.java

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import com.rabbitmq.client.impl.AMQImpl;
4444
import com.rabbitmq.client.impl.Frame;
4545
import com.rabbitmq.utility.BlockingCell;
46+
import com.rabbitmq.utility.Utility;
4647

4748

4849
/**
@@ -95,28 +96,22 @@ private static class AsyncLogger extends Thread{
9596
}.start();
9697
}
9798

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);
106101
}
107102

108103
@Override public void run(){
109104
try {
110105
while(true){
111106
Object message = queue.take();
112107
if(message == FLUSH) ps.flush();
113-
else printMessage(message);
108+
else printMessage((String)message);
114109
}
115110
} catch (InterruptedException interrupt){
116111
}
117112
}
118113

119-
void log(Object message){
114+
void log(String message){
120115
try {
121116
queue.put(message);
122117
} catch(InterruptedException ex){
@@ -200,22 +195,31 @@ public void run() {
200195
new Thread(outHandler).start();
201196
Object result = w.uninterruptibleGet();
202197
if (result instanceof Exception) {
203-
logger.log(result);
198+
logException((Exception)result);
204199
}
205200
} catch (EOFException eofe) {
206-
logger.log(eofe);
201+
logException((Exception)eofe);
207202
} catch (IOException ioe) {
208-
logger.log(ioe);
203+
logException((Exception)ioe);
209204
} finally {
210205
try {
211206
inSock.close();
212207
outSock.close();
213208
} catch (IOException ioe2) {
214-
logger.log(ioe2);
209+
logException((Exception)ioe2);
215210
}
216211
}
217212
}
218213

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+
219223
public class DirectionHandler implements Runnable {
220224
public BlockingCell<Object> waitCell;
221225

@@ -239,7 +243,9 @@ public Frame readFrame() throws IOException {
239243
}
240244

241245
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);
243249
}
244250

245251
public void reportFrame(Frame f)
@@ -265,6 +271,7 @@ public void reportFrame(Frame f)
265271
}
266272
}
267273

274+
268275
public void doFrame() throws IOException {
269276
Frame f = readFrame();
270277

0 commit comments

Comments
 (0)