1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package com.mindtree.techworks.insight.model;
26
27 import java.io.Serializable;
28
29 import com.mindtree.techworks.insight.Controller;
30 import com.mindtree.techworks.insight.InsightConstants;
31 import com.mindtree.techworks.insight.eventsearch.SearchResults;
32 import com.mindtree.techworks.insight.filter.UniqueLogCriteria;
33 import com.mindtree.techworks.insight.gui.widgets.StatusBar;
34 import com.mindtree.techworks.insight.pagination.PageSet;
35 import com.mindtree.techworks.insight.spi.LogEvent;
36
37
38
39
40
41
42
43
44
45 public class LogEventModel implements ILogEventModel, Serializable {
46
47
48
49
50 private static final long serialVersionUID = -1474266642451017271L;
51
52
53
54
55 protected PageSet pageSet;
56
57
58
59
60 protected Controller controller;
61
62
63
64
65 private LogEventModel previousLogEventModel;
66
67
68
69
70 private UniqueLogCriteria uniqueLogCriteria;
71
72
73
74
75 private SearchResults searchResults;
76
77
78
79
80 private long logEventIndex = -1;
81
82
83
84
85 private long processedEventCount;
86
87
88
89
90 private String logEventModelName;
91
92
93
94
95
96
97 public LogEventModel (Controller controller) {
98 this.controller = controller;
99 this.pageSet = new PageSet();
100 this.uniqueLogCriteria = new UniqueLogCriteria();
101 }
102
103
104
105
106
107
108 public PageSet getPageSet () {
109 return this.pageSet;
110 }
111
112
113
114
115 public void clear () {
116 this.pageSet.clear();
117 this.pageSet = null;
118 this.logEventIndex = -1;
119 this.processedEventCount = 0;
120 clearSearchResults();
121 this.uniqueLogCriteria.initialize();
122 StatusBar.getInstance().clearStatisticsDisplayText();
123 }
124
125
126
127
128
129
130
131 public void fireLogEventAdded (LogEvent logEvent) {
132 uniqueLogCriteria.add(logEvent);
133 this.processedEventCount += 1;
134
135
136 if (this.controller.getCurrentLogEventModel() == this){
137 this.controller.notifyLogEventOccurred(logEvent);
138 } else {
139
140 this.controller.setStatus();
141 }
142 }
143
144
145
146
147
148
149
150 public UniqueLogCriteria getUniqueCriteria () {
151 return uniqueLogCriteria;
152 }
153
154
155
156
157
158
159 public void setPreviousLogEventModel (LogEventModel logEventModel) {
160 this.previousLogEventModel = logEventModel;
161 }
162
163
164
165
166
167
168 public LogEventModel getPreviousLogEventModel () {
169 return this.previousLogEventModel;
170 }
171
172
173
174
175 public void setPageSet (PageSet pageSet) {
176 this.pageSet = pageSet;
177 }
178
179
180
181
182 public long getLogEventIndex () {
183 return logEventIndex;
184 }
185
186
187
188
189 public void setLogEventIndex (long logEventIndex) {
190 this.logEventIndex = logEventIndex;
191 }
192
193
194
195
196 public String getLogEventModelName () {
197 return logEventModelName;
198 }
199
200
201
202
203 public void setLogEventModelName (String logEventModelName) {
204 this.logEventModelName = logEventModelName;
205 }
206
207
208
209
210
211 public String getStatus() {
212 StringBuffer textToDisplay = new StringBuffer();
213 String currPageCnt = String.valueOf(getPageSet().getCurrentPageCnt());
214 String totPageCnt = String.valueOf(getPageSet().getTotalPageCnt());
215 textToDisplay.append(getContext());
216 textToDisplay.append(currPageCnt);
217 textToDisplay.append(InsightConstants.PAGE_STATUS_SEPARATOR);
218 textToDisplay.append(totPageCnt);
219 if (getSearchResults() != null) {
220 SearchResults searchResults = getSearchResults();
221 textToDisplay.append(InsightConstants.SEARCH_RESULT_DISP_STATUS_START);
222 textToDisplay.append(InsightConstants.SEARCH_RESULT_DISP_STATUS);
223 textToDisplay.append(String.valueOf(searchResults.getCurrentMatchingLogEventIndex() + 1));
224 textToDisplay.append(InsightConstants.PAGE_STATUS_SEPARATOR);
225 textToDisplay.append(String.valueOf(searchResults.getCountOfMatchingLogEvents()));
226 textToDisplay.append(InsightConstants.SEARCH_RESULT_DISP_STATUS_END);
227 }
228 return textToDisplay.toString();
229 }
230
231
232
233
234 public long getProcessedEventCount () {
235 return processedEventCount;
236 }
237
238
239
240
241 public void setProcessedEventCount (long processedEventCount) {
242 this.processedEventCount = processedEventCount;
243 }
244
245
246
247
248 public SearchResults getSearchResults () {
249 return searchResults;
250 }
251
252
253
254
255 public void setSearchResults (SearchResults searchResults) {
256 this.searchResults = searchResults;
257 }
258
259
260
261
262 public void clearSearchResults () {
263 this.searchResults = null;
264 }
265
266
267
268
269
270 private String getContext() {
271 LogEventModel logEventModel = this;
272 String context = logEventModel.getLogEventModelName();
273 while(true){
274 if(logEventModel.getPreviousLogEventModel()!= null){
275 logEventModel = logEventModel.getPreviousLogEventModel();
276 context = logEventModel.getLogEventModelName() + InsightConstants.TEXT_SEPARATOR + context;
277 }else{
278 break;
279 }
280 }
281 return context + InsightConstants.TEXT_INDENT;
282 }
283
284 }