Fix a range synch issue in the Events table
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng / src / org / eclipse / linuxtools / lttng / state / evProcessor / AbsEventToHandlerResolver.java
CommitLineData
5d10d135
ASL
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
13package org.eclipse.linuxtools.lttng.state.evProcessor;
14
15import java.util.Set;
16
17import org.eclipse.linuxtools.lttng.TraceDebug;
18import org.eclipse.linuxtools.lttng.event.LttngEvent;
19import org.eclipse.linuxtools.lttng.event.LttngSyntheticEvent;
5d10d135
ASL
20import org.eclipse.linuxtools.lttng.state.model.LttngTraceState;
21import org.eclipse.linuxtools.tmf.event.TmfEvent;
22
23/**
24 * @author alvaro
25 *
26 */
27public 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 */
d4011df2 37 @Override
5d10d135
ASL
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 */
d4011df2 43 @Override
5d10d135
ASL
44 public abstract ILttngEventProcessor getAfterProcessor(String eventType);
45
46 /* (non-Javadoc)
47 * @see org.eclipse.linuxtools.lttng.state.evProcessor.IEventToHandlerResolver#getfinishProcessor()
48 */
d4011df2 49 @Override
5d10d135
ASL
50 public abstract ILttngEventProcessor getfinishProcessor();
51
52 /* (non-Javadoc)
53 * @see org.eclipse.linuxtools.lttng.state.evProcessor.IEventToHandlerResolver#getStateUpdaterProcessor(java.lang.String)
54 */
d4011df2 55 @Override
5d10d135
ASL
56 public abstract ILttngEventProcessor getStateUpdaterProcessor(
57 String eventType);
58
550d787e
FC
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)
5d10d135 61 */
d4011df2 62 @Override
5d10d135
ASL
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;
c1c69938 69 String eventType = synEvent.getMarkerName();
5d10d135 70
c1c69938
FC
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: {
5d10d135
ASL
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();
c1c69938 84 break;
5d10d135 85 }
c1c69938
FC
86
87 case UPDATE: {
5d10d135
ASL
88 processor = getStateUpdaterProcessor(eventType);
89 incrementStateUpdateCount();
c1c69938 90 break;
5d10d135 91 }
c1c69938
FC
92
93 case AFTER: {
5d10d135 94 processor = getAfterProcessor(eventType);
c1c69938
FC
95 break;
96 }
97
98 case ENDREQ: {
99 processor = getfinishProcessor();
3b38ea61 100 TraceDebug.debug("EndRequest satus received:"); //$NON-NLS-1$
c1c69938 101 break;
5d10d135 102 }
c1c69938
FC
103
104 default:
105 // Nothing to do
106 break;
5d10d135 107
5d10d135 108 }
c1c69938
FC
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 // }
5d10d135
ASL
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 */
d4011df2 141 @Override
5d10d135
ASL
142 public void process(TmfEvent tmfEvent, LttngTraceState traceSt) {
143 if (tmfEvent == null) {
144 return;
145 }
146
147 if (!(tmfEvent instanceof LttngSyntheticEvent)) {
148 TraceDebug
3b38ea61 149 .debug("The event received is not an instance of LttngSyntheticEvent and can not be processed"); //$NON-NLS-1$
5d10d135
ASL
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 */
d4011df2 174 @Override
5d10d135
ASL
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 */
d4011df2 185 @Override
5d10d135
ASL
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 */
d4011df2 196 @Override
5d10d135
ASL
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.037459 seconds and 5 git commands to generate.