1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.osgi.equinoxtools.console;
20
21 import java.io.IOException;
22 import java.io.Writer;
23 import java.util.ArrayList;
24 import java.util.List;
25
26
27
28
29 public class WebConsoleWriterOutputStream extends org.eclipse.jetty.io.WriterOutputStream
30 {
31
32
33
34
35 public interface OnFlushListener
36 {
37
38
39
40 public void onFlush();
41
42 }
43
44 public interface MessageBroadcaster
45 {
46 public void broadcast();
47 }
48
49 private List<OnFlushListener> _callBacks;
50
51 public WebConsoleWriterOutputStream(Writer writer, String encoding)
52 {
53 super(writer, encoding);
54 }
55
56 @Override
57 public synchronized void flush() throws IOException
58 {
59 super.flush();
60 if (_callBacks != null)
61 {
62 for (OnFlushListener listener : _callBacks)
63 {
64 listener.onFlush();
65 }
66 }
67 }
68
69 public synchronized void addOnFlushListener(OnFlushListener callback)
70 {
71 if (_callBacks == null)
72 {
73 _callBacks = new ArrayList<WebConsoleWriterOutputStream.OnFlushListener>();
74 }
75 if (!_callBacks.contains(callback))
76 {
77 _callBacks.add(callback);
78 }
79 }
80 public synchronized boolean removeOnFlushListener(OnFlushListener callback)
81 {
82 if (_callBacks != null)
83 {
84 return _callBacks.remove(callback);
85 }
86 return false;
87 }
88 public synchronized List<OnFlushListener> getOnFlushListeners()
89 {
90 return _callBacks;
91 }
92
93 }