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