analysis.os.linux.core: Change the == operator with the equals() method
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.timing.core / src / org / eclipse / tracecompass / analysis / timing / core / segmentstore / AbstractSegmentStoreAnalysisEventBasedModule.java
1 /*******************************************************************************
2 * Copyright (c) 2016 Ericsson
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 package org.eclipse.tracecompass.analysis.timing.core.segmentstore;
10
11 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
12
13 import org.eclipse.core.runtime.IProgressMonitor;
14 import org.eclipse.jdt.annotation.Nullable;
15 import org.eclipse.tracecompass.segmentstore.core.ISegment;
16 import org.eclipse.tracecompass.segmentstore.core.ISegmentStore;
17 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
18 import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
19 import org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest;
20 import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest;
21 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
22
23 /**
24 * Abstract class to create an event base segment store analysis. It uses an
25 * event request to define how events will generate segments.
26 *
27 * @author Jean-Christian Kouame
28 *
29 */
30 public abstract class AbstractSegmentStoreAnalysisEventBasedModule extends AbstractSegmentStoreAnalysisModule {
31
32 private @Nullable ITmfEventRequest fOngoingRequest = null;
33
34 /**
35 * Returns the analysis request for creating the segment store
36 *
37 * @param segmentStore
38 * a segment store to fill
39 * @return the segment store analysis request implementation
40 */
41 protected abstract AbstractSegmentStoreAnalysisRequest createAnalysisRequest(ISegmentStore<ISegment> segmentStore);
42
43 @Override
44 protected void canceling() {
45 ITmfEventRequest req = fOngoingRequest;
46 if ((req != null) && (!req.isCompleted())) {
47 req.cancel();
48 }
49 }
50
51 @Override
52 protected boolean buildAnalysisSegments(ISegmentStore<ISegment> segmentStore, IProgressMonitor monitor) throws TmfAnalysisException {
53 ITmfTrace trace = checkNotNull(getTrace());
54 /* Cancel an ongoing request */
55 ITmfEventRequest req = fOngoingRequest;
56 if ((req != null) && (!req.isCompleted())) {
57 req.cancel();
58 }
59
60 /* Create a new request */
61 req = createAnalysisRequest(segmentStore);
62 fOngoingRequest = req;
63 trace.sendRequest(req);
64
65 try {
66 req.waitForCompletion();
67 } catch (InterruptedException e) {
68 }
69
70 /* Do not process the results if the request was cancelled */
71 if (req.isCancelled() || req.isFailed()) {
72 return false;
73 }
74 return true;
75 }
76
77 /**
78 * Abstract event request to fill a a segment store
79 */
80 protected static abstract class AbstractSegmentStoreAnalysisRequest extends TmfEventRequest {
81
82 private final ISegmentStore<ISegment> fSegmentStore;
83
84 /**
85 * Constructor
86 *
87 * @param segmentStore
88 * a segment store to fill
89 */
90 public AbstractSegmentStoreAnalysisRequest(ISegmentStore<ISegment> segmentStore) {
91 super(ITmfEvent.class, 0, ITmfEventRequest.ALL_DATA, ExecutionType.BACKGROUND);
92 /*
93 * We do NOT make a copy here! We want to modify the list that was
94 * passed in parameter.
95 */
96 fSegmentStore = segmentStore;
97 }
98
99 /**
100 * Returns the segment store
101 *
102 * @return the segment store
103 */
104 public ISegmentStore<ISegment> getSegmentStore() {
105 return fSegmentStore;
106 }
107 }
108 }
This page took 0.034164 seconds and 5 git commands to generate.