Commit | Line | Data |
---|---|---|
efc403bb AM |
1 | /******************************************************************************* |
2 | * Copyright (c) 2012 Ericsson | |
3 | * Copyright (c) 2010, 2011 École Polytechnique de Montréal | |
4 | * Copyright (c) 2010, 2011 Alexandre Montplaisir <alexandre.montplaisir@gmail.com> | |
d85d2a6d | 5 | * |
efc403bb AM |
6 | * All rights reserved. This program and the accompanying materials are |
7 | * made available under the terms of the Eclipse Public License v1.0 which | |
8 | * accompanies this distribution, and is available at | |
9 | * http://www.eclipse.org/legal/epl-v10.html | |
d85d2a6d | 10 | * |
efc403bb AM |
11 | *******************************************************************************/ |
12 | ||
13 | package org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider; | |
14 | ||
efc403bb AM |
15 | import java.util.concurrent.ArrayBlockingQueue; |
16 | import java.util.concurrent.BlockingQueue; | |
17 | ||
efc403bb AM |
18 | import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent; |
19 | import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace; | |
2c2f900e | 20 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; |
18ab1d18 AM |
21 | import org.eclipse.linuxtools.tmf.core.statesystem.IStateChangeInput; |
22 | import org.eclipse.linuxtools.tmf.core.statesystem.IStateSystemBuilder; | |
efc403bb AM |
23 | |
24 | /** | |
25 | * This is the state change input plugin for TMF's state system which handles | |
26 | * the LTTng 2.0 kernel traces in CTF format. | |
d85d2a6d | 27 | * |
efc403bb | 28 | * It uses the reference handler defined in CTFKernelHandler.java. |
d85d2a6d | 29 | * |
efc403bb | 30 | * @author alexmont |
d85d2a6d | 31 | * |
efc403bb | 32 | */ |
dc0f7bfe | 33 | public class CtfKernelStateInput implements IStateChangeInput { |
efc403bb | 34 | |
2c2f900e | 35 | private static final int EVENTS_QUEUE_SIZE = 10000; |
efc403bb AM |
36 | |
37 | private final BlockingQueue<CtfTmfEvent> eventsQueue; | |
38 | ||
2c2f900e | 39 | private final CtfTmfTrace trace; |
dc0f7bfe | 40 | private final CtfKernelHandler eventHandler; |
efc403bb AM |
41 | |
42 | private final Thread eventHandlerThread; | |
43 | ||
44 | private boolean ssAssigned; | |
45 | ||
46 | /** | |
47 | * Instantiate a new state provider plugin. | |
d85d2a6d AM |
48 | * |
49 | * @param trace | |
efc403bb | 50 | * The LTTng 2.0 kernel trace directory |
efc403bb | 51 | */ |
dc0f7bfe | 52 | public CtfKernelStateInput(CtfTmfTrace trace) { |
efc403bb | 53 | eventsQueue = new ArrayBlockingQueue<CtfTmfEvent>(EVENTS_QUEUE_SIZE); |
2c2f900e | 54 | this.trace = trace; |
dc0f7bfe | 55 | eventHandler = new CtfKernelHandler(eventsQueue); |
efc403bb AM |
56 | ssAssigned = false; |
57 | ||
58 | eventHandlerThread = new Thread(eventHandler, | |
59 | "CTF Kernel Event Handler"); //$NON-NLS-1$ | |
60 | } | |
61 | ||
62 | @Override | |
2c2f900e AM |
63 | public CtfTmfTrace getTrace() { |
64 | return trace; | |
65 | } | |
efc403bb | 66 | |
2c2f900e AM |
67 | @Override |
68 | public long getStartTime() { | |
69 | return trace.getStartTime().getValue(); | |
70 | } | |
efc403bb | 71 | |
2c2f900e AM |
72 | @Override |
73 | public CtfTmfEvent getExpectedEventType() { | |
74 | return CtfTmfEvent.getNullEvent(); | |
efc403bb AM |
75 | } |
76 | ||
77 | @Override | |
d26f90fd AM |
78 | public void assignTargetStateSystem(IStateSystemBuilder ssb) { |
79 | eventHandler.assignStateSystem(ssb); | |
efc403bb | 80 | ssAssigned = true; |
2c2f900e | 81 | eventHandlerThread.start(); |
efc403bb AM |
82 | } |
83 | ||
efc403bb | 84 | @Override |
2c2f900e AM |
85 | public void processEvent(ITmfEvent event) { |
86 | /* Make sure the target state system has been assigned */ | |
87 | if (!ssAssigned) { | |
88 | System.err.println("Cannot process event without a target state system"); //$NON-NLS-1$ | |
89 | return; | |
90 | } | |
d85d2a6d | 91 | |
2c2f900e AM |
92 | /* Insert the event we're received into the events queue */ |
93 | CtfTmfEvent currentEvent = (CtfTmfEvent) event; | |
94 | try { | |
95 | eventsQueue.put(currentEvent); | |
96 | } catch (InterruptedException e) { | |
97 | e.printStackTrace(); | |
98 | } | |
99 | } | |
100 | ||
101 | @Override | |
102 | public void dispose() { | |
103 | /* Insert a null event in the queue to stop the event handler's thread. */ | |
104 | try { | |
105 | eventsQueue.put(CtfTmfEvent.getNullEvent()); | |
106 | eventHandlerThread.join(); | |
107 | } catch (InterruptedException e) { | |
108 | e.printStackTrace(); | |
109 | } | |
110 | ssAssigned = false; | |
111 | eventHandler.assignStateSystem(null); | |
efc403bb AM |
112 | } |
113 | } |