2010-11-09 Francois Chouinard <fchouinard@gmail.com> Contribution for Bug315307
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng / src / org / eclipse / linuxtools / lttng / state / evProcessor / AbsEventToHandlerResolver.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.lttng.state.evProcessor;
14
15 import java.util.Set;
16
17 import org.eclipse.linuxtools.lttng.TraceDebug;
18 import org.eclipse.linuxtools.lttng.event.LttngEvent;
19 import org.eclipse.linuxtools.lttng.event.LttngSyntheticEvent;
20 import org.eclipse.linuxtools.lttng.state.model.LttngTraceState;
21 import org.eclipse.linuxtools.tmf.event.TmfEvent;
22
23 /**
24 * @author alvaro
25 *
26 */
27 public abstract class AbsEventToHandlerResolver implements
28 IEventToHandlerResolver, ITransEventProcessor {
29
30 Long fbeforeEventCount = 0L;
31 Long fstateUpdateCount = 0L;
32 Long filteredOutEventsCount = 0L;
33
34 /* (non-Javadoc)
35 * @see org.eclipse.linuxtools.lttng.state.evProcessor.IEventToHandlerResolver#getBeforeProcessor(java.lang.String)
36 */
37 @Override
38 public abstract ILttngEventProcessor getBeforeProcessor(String eventType);
39
40 /* (non-Javadoc)
41 * @see org.eclipse.linuxtools.lttng.state.evProcessor.IEventToHandlerResolver#getAfterProcessor(java.lang.String)
42 */
43 @Override
44 public abstract ILttngEventProcessor getAfterProcessor(String eventType);
45
46 /* (non-Javadoc)
47 * @see org.eclipse.linuxtools.lttng.state.evProcessor.IEventToHandlerResolver#getfinishProcessor()
48 */
49 @Override
50 public abstract ILttngEventProcessor getfinishProcessor();
51
52 /* (non-Javadoc)
53 * @see org.eclipse.linuxtools.lttng.state.evProcessor.IEventToHandlerResolver#getStateUpdaterProcessor(java.lang.String)
54 */
55 @Override
56 public abstract ILttngEventProcessor getStateUpdaterProcessor(
57 String eventType);
58
59 /* (non-Javadoc)
60 * @see org.eclipse.linuxtools.lttng.state.evProcessor.ILttngEventProcessor#process(org.eclipse.linuxtools.lttng.event.LttngEvent, org.eclipse.linuxtools.lttng.state.model.LttngTraceState)
61 */
62 @Override
63 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
64 if (trcEvent instanceof LttngSyntheticEvent) {
65
66 // prepare to dispatch synthetic events to its corresponding handler
67 LttngSyntheticEvent synEvent = (LttngSyntheticEvent) trcEvent;
68 ILttngEventProcessor processor = null;
69 String eventType = synEvent.getMarkerName();
70
71 switch (synEvent.getSynType()) {
72 case STARTREQ: {
73 // Status indicators do not contain a valid marker name
74 reset();
75 return false;
76 }
77
78 case BEFORE: {
79 processor = getBeforeProcessor(eventType);
80 // increment event count only for one sequence indicator,
81 // Note: BEFORE is selected to be used as an indicator to
82 // prevent duplicated updates in the state system
83 incrementBeforeEventCount();
84 break;
85 }
86
87 case UPDATE: {
88 processor = getStateUpdaterProcessor(eventType);
89 incrementStateUpdateCount();
90 break;
91 }
92
93 case AFTER: {
94 processor = getAfterProcessor(eventType);
95 break;
96 }
97
98 case ENDREQ: {
99 processor = getfinishProcessor();
100 TraceDebug.debug("EndRequest satus received:"); //$NON-NLS-1$
101 break;
102 }
103
104 default:
105 // Nothing to do
106 break;
107
108 }
109
110 // For BEFORE/UPDATE/AFTER
111 // TODO: Implement filter of events not associated to this trace
112 // Make sure the event received is associated to this trace
113 // handling context, Implementing a trace compare for each event
114 // is not acceptable due to performance, and a reference check
115 // may not be feasible since there are trace clones used either
116 // to build the state system check points or UI requests.
117
118 // if (traceSt != null && trcEvent.getParentTrace() !=
119 // traceSt.getContext().getTraceIdRef()) {
120 // // increment the number of events filtered out
121 // filteredOutEventsCount++;
122 // return false;
123 // }
124
125 if (processor != null) {
126 processor.process(trcEvent, traceSt);
127 }
128 }
129
130 return true;
131 }
132
133 /*
134 * (non-Javadoc)
135 *
136 * @see
137 * org.eclipse.linuxtools.lttng.state.evProcessor.IBaseEventProcessor#process
138 * (org.eclipse.linuxtools.tmf.event.TmfEvent,
139 * org.eclipse.linuxtools.lttng.state.model.LttngTraceState)
140 */
141 @Override
142 public void process(TmfEvent tmfEvent, LttngTraceState traceSt) {
143 if (tmfEvent == null) {
144 return;
145 }
146
147 if (!(tmfEvent instanceof LttngSyntheticEvent)) {
148 TraceDebug
149 .debug("The event received is not an instance of LttngSyntheticEvent and can not be processed"); //$NON-NLS-1$
150 return;
151 }
152
153 LttngSyntheticEvent trcEvent = (LttngSyntheticEvent) tmfEvent;
154
155 process(trcEvent, traceSt);
156 }
157
158 /*
159 * (non-Javadoc)
160 *
161 * @see org.eclipse.linuxtools.lttng.state.evProcessor.IBaseEventProcessor#
162 * getEventsNotHandled()
163 */
164 public Set<String> getEventsNotHandled() {
165 return null;
166 }
167
168 /*
169 * (non-Javadoc)
170 *
171 * @see org.eclipse.linuxtools.lttng.state.evProcessor.ITransEventProcessor#
172 * getEventCount()
173 */
174 @Override
175 public Long getBeforeEventCount() {
176 return fbeforeEventCount;
177 }
178
179 /*
180 * (non-Javadoc)
181 *
182 * @see org.eclipse.linuxtools.lttng.state.evProcessor.ITransEventProcessor#
183 * getStateUpdateCount()
184 */
185 @Override
186 public Long getStateUpdateCount() {
187 return fstateUpdateCount;
188 }
189
190 /*
191 * (non-Javadoc)
192 *
193 * @see org.eclipse.linuxtools.lttng.state.evProcessor.ITransEventProcessor#
194 * getFilteredOutEventCount()
195 */
196 @Override
197 public Long getFilteredOutEventCount() {
198 return filteredOutEventsCount;
199 }
200
201 /**
202 * <p>
203 * Initialise counter values, e.g before new requests
204 * </p>
205 */
206 protected void reset() {
207 fbeforeEventCount = 0L;
208 fstateUpdateCount = 0L;
209 filteredOutEventsCount = 0L;
210 }
211
212 /**
213 * Multi-threading not expected
214 */
215 protected void incrementBeforeEventCount() {
216 fbeforeEventCount++;
217 }
218
219 /**
220 * Multi-threading not expected
221 */
222 protected void incrementStateUpdateCount() {
223 fstateUpdateCount++;
224 }
225 }
This page took 0.034732 seconds and 5 git commands to generate.