Skip to content

Commit b1237e8

Browse files
committed
close the tailer
1 parent 5a54e38 commit b1237e8

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

micro-log-streamer/src/main/java/com/aol/micro/server/log/LogTailer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public void tail(TailerListener listener) {
3131
File file = new File(
3232
fileLocation);
3333
Tailer tailer = Tailer.create(file, listener, 10);
34+
3435
tailer.run();
3536
}
3637

micro-log-streamer/src/main/java/com/aol/micro/server/log/rest/LogStreamer.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,12 @@ public void write(OutputStream os) throws IOException, WebApplicationException {
8484
@AllArgsConstructor
8585
static class LogListener implements TailerListener {
8686
private final Writer writer;
87+
private volatile Tailer tailer;
8788

8889
@Override
8990
public void init(Tailer tailer) {
90-
// TODO Auto-generated method stub
9191

92+
this.tailer = tailer;
9293
}
9394

9495
@Override
@@ -97,7 +98,7 @@ public void fileNotFound() {
9798
writer.write("File not found!");
9899
writer.flush();
99100
} catch (IOException e) {
100-
101+
tailer.stop();
101102
}
102103

103104
}
@@ -107,8 +108,7 @@ public void fileRotated() {
107108
try {
108109
writer.flush();
109110
} catch (IOException e) {
110-
// TODO Auto-generated catch block
111-
e.printStackTrace();
111+
tailer.stop();
112112
}
113113
}
114114

@@ -121,22 +121,29 @@ public void handle(String line) {
121121
writer.write("\n");
122122
// writer.flush();
123123
} catch (IOException e) {
124-
e.printStackTrace();
124+
tailer.stop();
125125
}
126126

127127
}
128128

129129
@Override
130130
public void handle(Exception ex) {
131-
ex.printStackTrace();
131+
132132
try {
133+
writer.write("Error " + ex.getMessage());
134+
writer.write("/n");
133135
writer.flush();
134136
} catch (IOException e) {
135-
// TODO Auto-generated catch block
136-
e.printStackTrace();
137+
tailer.stop();
137138
}
138139
}
139140

141+
private LogListener(Writer writer) {
142+
143+
this.writer = writer;
144+
this.tailer = null;
145+
}
146+
140147
}
141148

142149
}

0 commit comments

Comments
 (0)