Commit | Line | Data |
---|---|---|
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 | ||
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 | ||
550d787e FC |
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) | |
5d10d135 ASL |
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 | ||
87 | if (synEvent.getSynType() == SequenceInd.UPDATE) { | |
88 | processor = getStateUpdaterProcessor(eventType); | |
89 | incrementStateUpdateCount(); | |
90 | } | |
91 | ||
92 | if (synEvent.getSynType() == SequenceInd.AFTER) { | |
93 | processor = getAfterProcessor(eventType); | |
94 | } | |
95 | ||
96 | // TODO: Implement filter of events not associated to this trace | |
97 | // Make sure the event received is associated to this trace | |
550d787e FC |
98 | // handling context, Implementing a trace compare for each event |
99 | // is not acceptable due to performance, and a reference check | |
100 | // may not be feasible since there are trace clones used either | |
101 | // to build the state system check points or UI requests. | |
102 | ||
103 | // if (traceSt != null && trcEvent.getParentTrace() != | |
104 | // traceSt.getContext().getTraceIdRef()) { | |
105 | // // increment the number of events filtered out | |
106 | // filteredOutEventsCount++; | |
107 | // return false; | |
108 | // } | |
5d10d135 ASL |
109 | } |
110 | ||
111 | if (processor != null) { | |
112 | processor.process(trcEvent, traceSt); | |
113 | } | |
114 | } | |
115 | ||
116 | return true; | |
117 | } | |
118 | ||
119 | /* | |
120 | * (non-Javadoc) | |
121 | * | |
122 | * @see | |
123 | * org.eclipse.linuxtools.lttng.state.evProcessor.IBaseEventProcessor#process | |
124 | * (org.eclipse.linuxtools.tmf.event.TmfEvent, | |
125 | * org.eclipse.linuxtools.lttng.state.model.LttngTraceState) | |
126 | */ | |
127 | public void process(TmfEvent tmfEvent, LttngTraceState traceSt) { | |
128 | if (tmfEvent == null) { | |
129 | return; | |
130 | } | |
131 | ||
132 | if (!(tmfEvent instanceof LttngSyntheticEvent)) { | |
133 | TraceDebug | |
134 | .debug("The event received is not an instance of LttngSyntheticEvent and can not be processed"); | |
135 | return; | |
136 | } | |
137 | ||
138 | LttngSyntheticEvent trcEvent = (LttngSyntheticEvent) tmfEvent; | |
139 | ||
140 | process(trcEvent, traceSt); | |
141 | } | |
142 | ||
143 | /* | |
144 | * (non-Javadoc) | |
145 | * | |
146 | * @see org.eclipse.linuxtools.lttng.state.evProcessor.IBaseEventProcessor# | |
147 | * getEventsNotHandled() | |
148 | */ | |
149 | public Set<String> getEventsNotHandled() { | |
150 | return null; | |
151 | } | |
152 | ||
153 | /* | |
154 | * (non-Javadoc) | |
155 | * | |
156 | * @see org.eclipse.linuxtools.lttng.state.evProcessor.ITransEventProcessor# | |
157 | * getEventCount() | |
158 | */ | |
159 | public Long getBeforeEventCount() { | |
160 | return fbeforeEventCount; | |
161 | } | |
162 | ||
163 | /* | |
164 | * (non-Javadoc) | |
165 | * | |
166 | * @see org.eclipse.linuxtools.lttng.state.evProcessor.ITransEventProcessor# | |
167 | * getStateUpdateCount() | |
168 | */ | |
169 | public Long getStateUpdateCount() { | |
170 | return fstateUpdateCount; | |
171 | } | |
172 | ||
173 | /* | |
174 | * (non-Javadoc) | |
175 | * | |
176 | * @see org.eclipse.linuxtools.lttng.state.evProcessor.ITransEventProcessor# | |
177 | * getFilteredOutEventCount() | |
178 | */ | |
179 | public Long getFilteredOutEventCount() { | |
180 | return filteredOutEventsCount; | |
181 | } | |
182 | ||
183 | /** | |
184 | * <p> | |
185 | * Initialise counter values, e.g before new requests | |
186 | * </p> | |
187 | */ | |
188 | protected void reset() { | |
189 | fbeforeEventCount = 0L; | |
190 | fstateUpdateCount = 0L; | |
191 | filteredOutEventsCount = 0L; | |
192 | } | |
193 | ||
194 | /** | |
195 | * Multi-threading not expected | |
196 | */ | |
197 | protected void incrementBeforeEventCount() { | |
198 | fbeforeEventCount++; | |
199 | } | |
200 | ||
201 | /** | |
202 | * Multi-threading not expected | |
203 | */ | |
204 | protected void incrementStateUpdateCount() { | |
205 | fstateUpdateCount++; | |
206 | } | |
207 | } |