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