tmf.core: Make getParamater synchronized
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core.tests / stubs / org / eclipse / tracecompass / tmf / tests / stubs / analysis / TestAnalysis.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 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 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;
19
20 /**
21 * Simple analysis type for test
22 */
23 public class TestAnalysis extends TmfAbstractAnalysisModule {
24
25 /**
26 * Test parameter. If set, simulate cancellation
27 */
28 public static final @NonNull String PARAM_TEST = "test";
29
30 private int fOutput = 0;
31
32 /**
33 * Constructor
34 */
35 public TestAnalysis() {
36 super();
37 }
38
39 @Override
40 public boolean canExecute(ITmfTrace trace) {
41 return true;
42 }
43
44 @Override
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");
49 }
50 int integer = ((Integer) parameter).intValue();
51 /* If PARAM_TEST is set to 0, simulate cancellation */
52 fOutput = integer;
53 if (integer == 0) {
54 return false;
55 } else if (integer == 999) {
56 /* just stay in an infinite loop until cancellation */
57 while (!monitor.isCanceled()) {
58 try {
59 Thread.sleep(0);
60 } catch (InterruptedException e) {
61 break;
62 }
63 }
64 return !monitor.isCanceled();
65 }
66 return true;
67 }
68
69 @Override
70 protected void canceling() {
71 fOutput = -1;
72 }
73
74 @Override
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);
79 }
80 return value;
81 }
82
83 @Override
84 protected void parameterChanged(String name) {
85 schedule();
86 }
87
88 /**
89 * Get the analysis output value
90 *
91 * @return The analysis output
92 */
93 public int getAnalysisOutput() {
94 return fOutput;
95 }
96
97 }
This page took 0.034421 seconds and 5 git commands to generate.