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
.event
.LttngEventContent
;
21 import org
.eclipse
.linuxtools
.lttng
.event
.LttngEventField
;
22 import org
.eclipse
.linuxtools
.lttng
.jni
.JniTrace
;
23 import org
.eclipse
.linuxtools
.lttng
.state
.evProcessor
.AbsEventProcessorFactory
;
24 import org
.eclipse
.linuxtools
.lttng
.state
.evProcessor
.EventProcessorProxy
;
25 import org
.eclipse
.linuxtools
.lttng
.state
.evProcessor
.IEventProcessing
;
26 import org
.eclipse
.linuxtools
.lttng
.state
.model
.ILttngStateInputRef
;
27 import org
.eclipse
.linuxtools
.lttng
.state
.model
.LttngTraceState
;
28 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEvent
;
29 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventField
;
30 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfTrace
;
36 public class StateStacksHandler
{
37 // ========================================================================
39 // =======================================================================
40 protected LttngTraceState traceStateModel
= null;
41 protected Set
<String
> eventsNotHandled
= null;
42 protected Vector
<IEventProcessing
> listeners
= new Vector
<IEventProcessing
>();
44 // ========================================================================
46 // ========================================================================
47 public StateStacksHandler(LttngTraceState model
) {
48 // It's assumed to have one instance of this class per Trace
49 this.traceStateModel
= model
;
52 // ========================================================================
54 // =======================================================================
56 * Initialised by manager, any time a JniTrace selection is updated
62 void init(JniTrace trace
, TmfTrace log
) throws LttngStateException
{
63 if (trace
== null || log
== null) {
64 StringBuilder sb
= new StringBuilder(
65 "No JniTrace object available, trace must be set via method setTrace(JniTrace trace)");
66 throw new LttngStateException(sb
.toString());
69 // this.trace = trace;
70 ILttngStateInputRef ref
= new LttngStateInputRef(trace
, log
);
71 this.traceStateModel
.init(ref
);
75 void processEvent(TmfEvent tmfEvent
) /* throws LttngStateException */{
76 if (tmfEvent
== null) {
80 if (!(tmfEvent
instanceof LttngEvent
)) {
82 .debug("The event received is not an instance of LttngEvent and can not be processed");
85 LttngEvent trcEvent
= (LttngEvent
) tmfEvent
;
86 // LttngEventField[] fields = ((LttngEventContent)trcEvent.getContent()).getFields();
88 if (trcEvent
!= null) {
89 String inEventName
= trcEvent
.getMarkerName();
90 // String inChannel = trcEvent.getChannelName();
91 // TraceDebug.debug("Event: " + inEventName);
93 // Check if the received event is a transition state event
94 // TODO: Remove temporarily to allow other events to go to the
96 // Needs restructuring.
97 // Events eventStruct = StateStrings.getInstance()
98 // .getStateTransEventMap().get(inEventName);
99 // if (eventStruct != null) {
100 // String expectedChannel = eventStruct.getParent().getInName();
101 // check that received channel is the expected channel in the
103 // if (inChannel.equals(expectedChannel)) {
104 // Notify the before Handlers
105 Set
<AbsEventProcessorFactory
> handlerRegister
= EventProcessorProxy
106 .getInstance().getProcessingFactories();
108 // Notify the state BEFORE update handlers
109 for (Iterator
<AbsEventProcessorFactory
> iterator
= handlerRegister
110 .iterator(); iterator
.hasNext();) {
111 AbsEventProcessorFactory handlerRegistry
= (AbsEventProcessorFactory
) iterator
113 IEventProcessing handler
= handlerRegistry
114 .getBeforeProcessor(inEventName
);
115 if (handler
!= null) {
116 // process State Update
117 handler
.process(trcEvent
, traceStateModel
);
122 // Notify the STATE UPDATE handlers
123 // Only one state update expected
124 for (Iterator
<AbsEventProcessorFactory
> iterator
= handlerRegister
125 .iterator(); iterator
.hasNext();) {
126 AbsEventProcessorFactory handlerRegistry
= (AbsEventProcessorFactory
) iterator
128 IEventProcessing handler
= handlerRegistry
129 .getStateUpdaterProcessor(inEventName
);
130 if (handler
!= null) {
131 // process State Update
132 handler
.process(trcEvent
, traceStateModel
);
137 // Notify the AFTER update handlers
138 for (Iterator
<AbsEventProcessorFactory
> iterator
= handlerRegister
139 .iterator(); iterator
.hasNext();) {
140 AbsEventProcessorFactory handlerRegistry
= (AbsEventProcessorFactory
) iterator
142 IEventProcessing handler
= handlerRegistry
143 .getAfterProcessor(inEventName
);
144 if (handler
!= null) {
145 // process State Update
146 handler
.process(trcEvent
, traceStateModel
);
151 // StringBuilder sb = new StringBuilder(
152 // "Unexpected channel received for: " + inEventName
153 // + ", channel rec: " + inChannel
154 // + " chanel expected: " + expectedChannel);
155 // TraceDebug.debug(sb.toString());
162 * Used for troubleshooting when debug mode is on
166 Set
<String
> getEventsNotHandled() {
167 return eventsNotHandled
;
171 * Needed for checkpoint
173 * @param LttngTraceState
175 public LttngTraceState
getTraceStateModel() {
176 return traceStateModel
;
180 * Needed for checkpoint
182 * @param LttngTraceState
184 public void setTraceStateModel(LttngTraceState newTraceState
) {
185 traceStateModel
= newTraceState
;
189 * Needed for verification purposes
193 void registerListener(IEventProcessing listener
) {
194 this.listeners
.add(listener
);
198 * Needed for verification purposes
202 void deregisterListener(IEventProcessing listener
) {
203 this.listeners
.remove(listener
);