2010-10-26 Francois Chouinard <fchouinard@gmail.com> Contribution for Bug309042
[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;
20import org.eclipse.linuxtools.lttng.event.LttngSyntheticEvent.SequenceInd;
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;
70
71 // Status indicators do not contain a valid marker name
72 if (synEvent.getSynType() == SequenceInd.STARTREQ) {
73 reset();
74 return false;
75 }
76
77 if (synEvent.getSynType() == SequenceInd.ENDREQ) {
78 processor = getfinishProcessor();
79 TraceDebug.debug("EndRequest satus received:");
80 } else {
81 // valid marker name expected
82 String eventType = synEvent.getMarkerName();
83
84 if (synEvent.getSynType() == SequenceInd.BEFORE) {
85 processor = getBeforeProcessor(eventType);
86 // increment event count only for one sequence indicator,
87 // Note: BEFORE is selected to be used as an indicator to
88 // prevent duplicated updates in the state system
89 incrementBeforeEventCount();
90 }
9dbeec54 91 else if (synEvent.getSynType() == SequenceInd.UPDATE) {
5d10d135
ASL
92 processor = getStateUpdaterProcessor(eventType);
93 incrementStateUpdateCount();
94 }
9dbeec54 95 else if (synEvent.getSynType() == SequenceInd.AFTER) {
5d10d135
ASL
96 processor = getAfterProcessor(eventType);
97 }
98
99 // TODO: Implement filter of events not associated to this trace
100 // Make sure the event received is associated to this trace
550d787e
FC
101 // handling context, Implementing a trace compare for each event
102 // is not acceptable due to performance, and a reference check
103 // may not be feasible since there are trace clones used either
104 // to build the state system check points or UI requests.
105
106 // if (traceSt != null && trcEvent.getParentTrace() !=
107 // traceSt.getContext().getTraceIdRef()) {
108 // // increment the number of events filtered out
109 // filteredOutEventsCount++;
110 // return false;
111 // }
5d10d135
ASL
112 }
113
114 if (processor != null) {
115 processor.process(trcEvent, traceSt);
116 }
117 }
118
119 return true;
120 }
121
122 /*
123 * (non-Javadoc)
124 *
125 * @see
126 * org.eclipse.linuxtools.lttng.state.evProcessor.IBaseEventProcessor#process
127 * (org.eclipse.linuxtools.tmf.event.TmfEvent,
128 * org.eclipse.linuxtools.lttng.state.model.LttngTraceState)
129 */
d4011df2 130 @Override
5d10d135
ASL
131 public void process(TmfEvent tmfEvent, LttngTraceState traceSt) {
132 if (tmfEvent == null) {
133 return;
134 }
135
136 if (!(tmfEvent instanceof LttngSyntheticEvent)) {
137 TraceDebug
138 .debug("The event received is not an instance of LttngSyntheticEvent and can not be processed");
139 return;
140 }
141
142 LttngSyntheticEvent trcEvent = (LttngSyntheticEvent) tmfEvent;
143
144 process(trcEvent, traceSt);
145 }
146
147 /*
148 * (non-Javadoc)
149 *
150 * @see org.eclipse.linuxtools.lttng.state.evProcessor.IBaseEventProcessor#
151 * getEventsNotHandled()
152 */
153 public Set<String> getEventsNotHandled() {
154 return null;
155 }
156
157 /*
158 * (non-Javadoc)
159 *
160 * @see org.eclipse.linuxtools.lttng.state.evProcessor.ITransEventProcessor#
161 * getEventCount()
162 */
d4011df2 163 @Override
5d10d135
ASL
164 public Long getBeforeEventCount() {
165 return fbeforeEventCount;
166 }
167
168 /*
169 * (non-Javadoc)
170 *
171 * @see org.eclipse.linuxtools.lttng.state.evProcessor.ITransEventProcessor#
172 * getStateUpdateCount()
173 */
d4011df2 174 @Override
5d10d135
ASL
175 public Long getStateUpdateCount() {
176 return fstateUpdateCount;
177 }
178
179 /*
180 * (non-Javadoc)
181 *
182 * @see org.eclipse.linuxtools.lttng.state.evProcessor.ITransEventProcessor#
183 * getFilteredOutEventCount()
184 */
d4011df2 185 @Override
5d10d135
ASL
186 public Long getFilteredOutEventCount() {
187 return filteredOutEventsCount;
188 }
189
190 /**
191 * <p>
192 * Initialise counter values, e.g before new requests
193 * </p>
194 */
195 protected void reset() {
196 fbeforeEventCount = 0L;
197 fstateUpdateCount = 0L;
198 filteredOutEventsCount = 0L;
199 }
200
201 /**
202 * Multi-threading not expected
203 */
204 protected void incrementBeforeEventCount() {
205 fbeforeEventCount++;
206 }
207
208 /**
209 * Multi-threading not expected
210 */
211 protected void incrementStateUpdateCount() {
212 fstateUpdateCount++;
213 }
214}
This page took 0.035666 seconds and 5 git commands to generate.