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