tmf: Null-annotate state system API classes
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core.tests / stubs / org / eclipse / tracecompass / tmf / tests / stubs / analysis / TestExperimentAnalysis.java
1 /*******************************************************************************
2 * Copyright (c) 2014 École Polytechnique de Montréal
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 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.tmf.tests.stubs.analysis;
14
15 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
16
17 import java.util.HashSet;
18 import java.util.Set;
19
20 import org.eclipse.jdt.annotation.NonNull;
21 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder;
22 import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
23 import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
24 import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
25 import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
26 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
27 import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
28 import org.eclipse.tracecompass.tmf.core.statesystem.AbstractTmfStateProvider;
29 import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider;
30 import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule;
31 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
32
33 /**
34 * Stubs for experiment analysis. This analysis is a state system analysis that
35 * simply counts the number of traces for which events were received. The number
36 * of traces is the value of attribute
37 * {@link TestExperimentAnalysis#TRACE_QUARK_NAME}.
38 *
39 * @author Geneviève Bastien
40 */
41 public class TestExperimentAnalysis extends TmfStateSystemAnalysisModule {
42
43 /**
44 * The quark counting the number of traces
45 */
46 public static final String TRACE_QUARK_NAME = "Traces";
47
48 @Override
49 protected ITmfStateProvider createStateProvider() {
50 return new TestExpStateSystemProvider(checkNotNull(getTrace()));
51 }
52
53 @Override
54 protected StateSystemBackendType getBackendType() {
55 return StateSystemBackendType.INMEM;
56 }
57
58 private class TestExpStateSystemProvider extends AbstractTmfStateProvider {
59
60 private static final int VERSION = 1;
61 private final Set<ITmfTrace> fTraces = new HashSet<>();
62 private int fCount = 0;
63
64 /**
65 * Constructor
66 *
67 * @param trace
68 * The LTTng 2.0 kernel trace directory
69 */
70 public TestExpStateSystemProvider(@NonNull ITmfTrace trace) {
71 super(trace, TmfEvent.class, "Stub State System for Experiment");
72 }
73
74 @Override
75 public int getVersion() {
76 return VERSION;
77 }
78
79 @Override
80 public ITmfStateProvider getNewInstance() {
81 return new TestExpStateSystemProvider(this.getTrace());
82 }
83
84 @Override
85 protected void eventHandle(ITmfEvent event) {
86 ITmfStateSystemBuilder ss = checkNotNull(getStateSystemBuilder());
87 if (!fTraces.contains(event.getTrace())) {
88 try {
89 int quarkId = ss.getQuarkAbsoluteAndAdd(TRACE_QUARK_NAME);
90 ss.modifyAttribute(event.getTimestamp().getValue(), TmfStateValue.newValueInt(++fCount), quarkId);
91 fTraces.add(event.getTrace());
92 } catch (TimeRangeException | AttributeNotFoundException | StateValueTypeException e) {
93
94 }
95 }
96 }
97 }
98 }
This page took 0.03297 seconds and 5 git commands to generate.