1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package com.mindtree.techworks.insight.gui.action;
25
26 import java.awt.event.ActionEvent;
27
28 import javax.swing.AbstractAction;
29 import javax.swing.JOptionPane;
30
31 import com.mindtree.techworks.insight.InsightConstants;
32 import com.mindtree.techworks.insight.appender.ParsedEventAppender;
33 import com.mindtree.techworks.insight.gui.Insight;
34 import com.mindtree.techworks.insight.gui.widgets.StatusBar;
35 import com.mindtree.techworks.insight.model.ReceiverFormat;
36 import com.mindtree.techworks.insight.preferences.util.Log4JPatternInterpeter;
37 import com.mindtree.techworks.insight.preferences.util.PreferenceInterpreter;
38 import com.mindtree.techworks.insight.receiver.AbstractReceiver;
39 import com.mindtree.techworks.insight.receiver.ReceiverInitializationException;
40 import com.mindtree.techworks.insight.receiver.ReceiverInterpreter;
41 import com.mindtree.techworks.insight.receiver.ReceiverListener;
42 import com.mindtree.techworks.insight.receiver.RemoteProtocolStreamReceiver;
43 import com.mindtree.techworks.insight.receiver.RuntimeNamespaceContainer;
44 import com.mindtree.techworks.insight.spi.LogNamespace;
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60 public class RemoteProtocolListenerAction extends AbstractAction implements
61 ReceiverListener {
62
63
64
65
66
67
68
69
70 private static final long serialVersionUID = -2277220522584222352L;
71
72
73
74
75 private static RemoteProtocolListenerAction instance;
76
77
78
79
80
81
82
83
84 private Insight insight;
85
86
87
88
89 private AbstractReceiver receiver;
90
91
92
93
94
95
96
97
98
99 private RemoteProtocolListenerAction () {
100
101 RuntimeNamespaceContainer.initializeAvailableNamespaceColorList ();
102 }
103
104
105
106
107
108
109
110
111
112
113 public static final RemoteProtocolListenerAction getInstance () {
114
115 if (null == instance) {
116 synchronized (RemoteProtocolListenerAction.class) {
117 if (null == instance) {
118 instance = new RemoteProtocolListenerAction ();
119 }
120 }
121 }
122 return instance;
123 }
124
125
126
127
128
129
130
131
132 public void startLoadEventNotification (LogNamespace[] namespaces) {
133
134
135
136 }
137
138
139
140
141
142 public void endLoadEventNotification (LogNamespace[] namespaces,
143 int infoFlag) {
144
145 StatusBar.getInstance ().clearDisplay (1);
146 if (infoFlag == ReceiverInterpreter.SUCCESS) {
147
148 for (int i = 0; i < namespaces.length; i++ ) {
149 RuntimeNamespaceContainer.getLoadedNamespaces().add(namespaces[i]);
150 }
151 } else {
152 JOptionPane.showMessageDialog (insight, InsightConstants
153 .getLiteral ("ERROR_NO_MATCHING_ENTRIES"), InsightConstants
154 .getLiteral ("ERROR"), JOptionPane.ERROR_MESSAGE);
155 }
156 }
157
158
159
160
161
162
163
164
165 public void actionPerformed (ActionEvent event) {
166
167 startupReceiver ();
168
169 }
170
171
172
173
174
175
176
177
178
179
180
181
182 public void initialize (Insight insightInstance) {
183
184 if (this.insight == null) {
185 this.insight = insightInstance;
186 }
187 }
188
189
190
191
192
193
194 public AbstractReceiver getReceiver () {
195
196 return receiver;
197 }
198
199
200
201
202
203
204
205
206 private void startupReceiver () {
207
208 int portToListenOn = PreferenceInterpreter
209 .getRemoteProtocolListenerPort ();
210 StatusBar
211 .getInstance ()
212 .setDisplayText (
213 1,
214 InsightConstants
215 .getLiteral ("REMOTE_PROTOCOL_LISTENING")
216 + portToListenOn, true);
217
218 ReceiverFormat[] receiverFormat = Log4JPatternInterpeter
219 .getInterpretedRecieverFormat ();
220
221 try {
222 this.receiver = new RemoteProtocolStreamReceiver (receiverFormat,
223 portToListenOn);
224 } catch (ReceiverInitializationException rie) {
225 StatusBar.getInstance ().setDisplayText (1, rie.getMessage (),
226 false);
227 return;
228 }
229 this.receiver.addAppender (ParsedEventAppender
230 .getInstance (this.insight.getController ()));
231 this.receiver.addReceiverListener (this);
232 this.receiver.addMutatorListener (this.insight.getController ());
233 this.receiver.addMutatorListener (this.insight.getController ()
234 .getCurrentLogEventModel ().getPageSet ());
235 this.receiver.startup ();
236
237 }
238
239 }