1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 École Polytechnique de Montréal
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 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.tests
.stubs
.analysis
;
15 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
16 import org
.eclipse
.jdt
.annotation
.NonNull
;
17 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.TmfAbstractAnalysisModule
;
18 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
21 * Simple analysis type for test
23 public class TestAnalysis
extends TmfAbstractAnalysisModule
{
26 * Test parameter. If set, simulate cancellation
28 public static final @NonNull String PARAM_TEST
= "test";
30 private int fOutput
= 0;
35 public TestAnalysis() {
40 public boolean canExecute(ITmfTrace trace
) {
45 protected boolean executeAnalysis(final IProgressMonitor monitor
) {
46 Object parameter
= getParameter(PARAM_TEST
);
47 if (!(parameter
instanceof Integer
)) {
48 throw new RuntimeException("The parameter should be set");
50 int integer
= ((Integer
) parameter
).intValue();
51 /* If PARAM_TEST is set to 0, simulate cancellation */
55 } else if (integer
== 999) {
56 /* just stay in an infinite loop until cancellation */
57 while (!monitor
.isCanceled()) {
60 } catch (InterruptedException e
) {
64 return !monitor
.isCanceled();
70 protected void canceling() {
75 public synchronized Object
getParameter(String name
) {
76 Object value
= super.getParameter(name
);
77 if ((value
!= null) && name
.equals(PARAM_TEST
) && (value
instanceof String
)) {
78 return Integer
.decode((String
) value
);
84 protected void parameterChanged(String name
) {
89 * Get the analysis output value
91 * @return The analysis output
93 public int getAnalysisOutput() {