1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
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
10 * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
11 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.lttng
.state
;
14 import java
.util
.Iterator
;
16 import java
.util
.Vector
;
18 import org
.eclipse
.linuxtools
.lttng
.TraceDebug
;
19 import org
.eclipse
.linuxtools
.lttng
.event
.LttngEvent
;
20 import org
.eclipse
.linuxtools
.lttng
.state
.evProcessor
.AbsEventProcessorFactory
;
21 import org
.eclipse
.linuxtools
.lttng
.state
.evProcessor
.EventProcessorProxy
;
22 import org
.eclipse
.linuxtools
.lttng
.state
.evProcessor
.IEventProcessing
;
23 import org
.eclipse
.linuxtools
.lttng
.state
.model
.ILttngStateInputRef
;
24 import org
.eclipse
.linuxtools
.lttng
.state
.model
.LttngTraceState
;
25 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEvent
;
26 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfTrace
;
32 public class StateStacksHandler
{
33 // ========================================================================
35 // =======================================================================
36 protected LttngTraceState traceStateModel
= null;
37 protected Set
<String
> eventsNotHandled
= null;
38 protected Vector
<IEventProcessing
> listeners
= new Vector
<IEventProcessing
>();
40 // ========================================================================
42 // ========================================================================
43 public StateStacksHandler(LttngTraceState model
) {
44 // It's assumed to have one instance of this class per Trace
45 this.traceStateModel
= model
;
48 // ========================================================================
50 // =======================================================================
52 * Initialised by manager, any time a JniTrace selection is updated
58 void init(TmfTrace log
) throws LttngStateException
{
60 throw new LttngStateException("No TmfTrace object available!");
63 // this.trace = trace;
64 ILttngStateInputRef ref
= new LttngStateInputRef(log
);
65 this.traceStateModel
.init(ref
);
69 protected void processEvent(TmfEvent tmfEvent
) /* throws LttngStateException */{
70 if (tmfEvent
== null) {
74 if (!(tmfEvent
instanceof LttngEvent
)) {
76 .debug("The event received is not an instance of LttngEvent and can not be processed");
79 LttngEvent trcEvent
= (LttngEvent
) tmfEvent
;
80 // LttngEventField[] fields = ((LttngEventContent)trcEvent.getContent()).getFields();
82 if (trcEvent
!= null) {
83 String inEventName
= trcEvent
.getMarkerName();
84 // String inChannel = trcEvent.getChannelName();
85 // TraceDebug.debug("Event: " + inEventName);
87 // Check if the received event is a transition state event
88 // TODO: Remove temporarily to allow other events to go to the
90 // Needs restructuring.
91 // Events eventStruct = StateStrings.getInstance()
92 // .getStateTransEventMap().get(inEventName);
93 // if (eventStruct != null) {
94 // String expectedChannel = eventStruct.getParent().getInName();
95 // check that received channel is the expected channel in the
97 // if (inChannel.equals(expectedChannel)) {
98 // Notify the before Handlers
99 Set
<AbsEventProcessorFactory
> handlerRegister
= EventProcessorProxy
100 .getInstance().getProcessingFactories();
102 // Notify the state BEFORE update handlers
103 for (Iterator
<AbsEventProcessorFactory
> iterator
= handlerRegister
104 .iterator(); iterator
.hasNext();) {
105 AbsEventProcessorFactory handlerRegistry
= (AbsEventProcessorFactory
) iterator
107 IEventProcessing handler
= handlerRegistry
108 .getBeforeProcessor(inEventName
);
109 if (handler
!= null) {
110 // process State Update
111 handler
.process(trcEvent
, traceStateModel
);
116 // Notify the STATE UPDATE handlers
117 // Only one state update expected
118 for (Iterator
<AbsEventProcessorFactory
> iterator
= handlerRegister
119 .iterator(); iterator
.hasNext();) {
120 AbsEventProcessorFactory handlerRegistry
= (AbsEventProcessorFactory
) iterator
122 IEventProcessing handler
= handlerRegistry
123 .getStateUpdaterProcessor(inEventName
);
124 if (handler
!= null) {
125 // process State Update
126 handler
.process(trcEvent
, traceStateModel
);
131 // Notify the AFTER update handlers
132 for (Iterator
<AbsEventProcessorFactory
> iterator
= handlerRegister
133 .iterator(); iterator
.hasNext();) {
134 AbsEventProcessorFactory handlerRegistry
= (AbsEventProcessorFactory
) iterator
136 IEventProcessing handler
= handlerRegistry
137 .getAfterProcessor(inEventName
);
138 if (handler
!= null) {
139 // process State Update
140 handler
.process(trcEvent
, traceStateModel
);
145 // StringBuilder sb = new StringBuilder(
146 // "Unexpected channel received for: " + inEventName
147 // + ", channel rec: " + inChannel
148 // + " chanel expected: " + expectedChannel);
149 // TraceDebug.debug(sb.toString());
156 * Used for troubleshooting when debug mode is on
160 Set
<String
> getEventsNotHandled() {
161 return eventsNotHandled
;
165 * Needed for checkpoint
167 * @param LttngTraceState
169 public LttngTraceState
getTraceStateModel() {
170 return traceStateModel
;
174 * Needed for checkpoint
176 * @param LttngTraceState
178 public void setTraceStateModel(LttngTraceState newTraceState
) {
179 traceStateModel
= newTraceState
;
183 * Needed for verification purposes
187 void registerListener(IEventProcessing listener
) {
188 this.listeners
.add(listener
);
192 * Needed for verification purposes
196 void deregisterListener(IEventProcessing listener
) {
197 this.listeners
.remove(listener
);