2010-07-29 Francois Chouinard <fchouinard@gmail.com> Fixes for Bug321252 and Bug321253
[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.event.LttngSyntheticEvent.SequenceInd;
21 import org.eclipse.linuxtools.lttng.state.model.LttngTraceState;
22 import org.eclipse.linuxtools.tmf.event.TmfEvent;
23
24 /**
25 * @author alvaro
26 *
27 */
28 public 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 */
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 public abstract ILttngEventProcessor getAfterProcessor(String eventType);
44
45 /* (non-Javadoc)
46 * @see org.eclipse.linuxtools.lttng.state.evProcessor.IEventToHandlerResolver#getfinishProcessor()
47 */
48 public abstract ILttngEventProcessor getfinishProcessor();
49
50 /* (non-Javadoc)
51 * @see org.eclipse.linuxtools.lttng.state.evProcessor.IEventToHandlerResolver#getStateUpdaterProcessor(java.lang.String)
52 */
53 public abstract ILttngEventProcessor getStateUpdaterProcessor(
54 String eventType);
55
56 /* (non-Javadoc)
57 * @see org.eclipse.linuxtools.lttng.state.evProcessor.ILttngEventProcessor#process(org.eclipse.linuxtools.lttng.event.LttngEvent, org.eclipse.linuxtools.lttng.state.model.LttngTraceState)
58 */
59 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
60 if (trcEvent instanceof LttngSyntheticEvent) {
61
62 // prepare to dispatch synthetic events to its corresponding handler
63 LttngSyntheticEvent synEvent = (LttngSyntheticEvent) trcEvent;
64 ILttngEventProcessor processor = null;
65
66 // Status indicators do not contain a valid marker name
67 if (synEvent.getSynType() == SequenceInd.STARTREQ) {
68 reset();
69 return false;
70 }
71
72 if (synEvent.getSynType() == SequenceInd.ENDREQ) {
73 processor = getfinishProcessor();
74 TraceDebug.debug("EndRequest satus received:");
75 } else {
76 // valid marker name expected
77 String eventType = synEvent.getMarkerName();
78
79 if (synEvent.getSynType() == SequenceInd.BEFORE) {
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();
85 }
86 else if (synEvent.getSynType() == SequenceInd.UPDATE) {
87 processor = getStateUpdaterProcessor(eventType);
88 incrementStateUpdateCount();
89 }
90 else if (synEvent.getSynType() == SequenceInd.AFTER) {
91 processor = getAfterProcessor(eventType);
92 }
93
94 // TODO: Implement filter of events not associated to this trace
95 // Make sure the event received is associated to this trace
96 // handling context, Implementing a trace compare for each event
97 // is not acceptable due to performance, and a reference check
98 // may not be feasible since there are trace clones used either
99 // to build the state system check points or UI requests.
100
101 // if (traceSt != null && trcEvent.getParentTrace() !=
102 // traceSt.getContext().getTraceIdRef()) {
103 // // increment the number of events filtered out
104 // filteredOutEventsCount++;
105 // return false;
106 // }
107 }
108
109 if (processor != null) {
110 processor.process(trcEvent, traceSt);
111 }
112 }
113
114 return true;
115 }
116
117 /*
118 * (non-Javadoc)
119 *
120 * @see
121 * org.eclipse.linuxtools.lttng.state.evProcessor.IBaseEventProcessor#process
122 * (org.eclipse.linuxtools.tmf.event.TmfEvent,
123 * org.eclipse.linuxtools.lttng.state.model.LttngTraceState)
124 */
125 public void process(TmfEvent tmfEvent, LttngTraceState traceSt) {
126 if (tmfEvent == null) {
127 return;
128 }
129
130 if (!(tmfEvent instanceof LttngSyntheticEvent)) {
131 TraceDebug
132 .debug("The event received is not an instance of LttngSyntheticEvent and can not be processed");
133 return;
134 }
135
136 LttngSyntheticEvent trcEvent = (LttngSyntheticEvent) tmfEvent;
137
138 process(trcEvent, traceSt);
139 }
140
141 /*
142 * (non-Javadoc)
143 *
144 * @see org.eclipse.linuxtools.lttng.state.evProcessor.IBaseEventProcessor#
145 * getEventsNotHandled()
146 */
147 public Set<String> getEventsNotHandled() {
148 return null;
149 }
150
151 /*
152 * (non-Javadoc)
153 *
154 * @see org.eclipse.linuxtools.lttng.state.evProcessor.ITransEventProcessor#
155 * getEventCount()
156 */
157 public Long getBeforeEventCount() {
158 return fbeforeEventCount;
159 }
160
161 /*
162 * (non-Javadoc)
163 *
164 * @see org.eclipse.linuxtools.lttng.state.evProcessor.ITransEventProcessor#
165 * getStateUpdateCount()
166 */
167 public Long getStateUpdateCount() {
168 return fstateUpdateCount;
169 }
170
171 /*
172 * (non-Javadoc)
173 *
174 * @see org.eclipse.linuxtools.lttng.state.evProcessor.ITransEventProcessor#
175 * getFilteredOutEventCount()
176 */
177 public Long getFilteredOutEventCount() {
178 return filteredOutEventsCount;
179 }
180
181 /**
182 * <p>
183 * Initialise counter values, e.g before new requests
184 * </p>
185 */
186 protected void reset() {
187 fbeforeEventCount = 0L;
188 fstateUpdateCount = 0L;
189 filteredOutEventsCount = 0L;
190 }
191
192 /**
193 * Multi-threading not expected
194 */
195 protected void incrementBeforeEventCount() {
196 fbeforeEventCount++;
197 }
198
199 /**
200 * Multi-threading not expected
201 */
202 protected void incrementStateUpdateCount() {
203 fstateUpdateCount++;
204 }
205 }
This page took 0.040435 seconds and 6 git commands to generate.