Commit | Line | Data |
---|---|---|
65a4afc0 JCK |
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; | |
09f15ee9 | 21 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange; |
65a4afc0 JCK |
22 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; |
23 | ||
24 | /** | |
25 | * Abstract class to create an event base segment store analysis. It uses an | |
26 | * event request to define how events will generate segments. | |
27 | * | |
28 | * @author Jean-Christian Kouame | |
29 | * | |
30 | */ | |
31 | public abstract class AbstractSegmentStoreAnalysisEventBasedModule extends AbstractSegmentStoreAnalysisModule { | |
32 | ||
33 | private @Nullable ITmfEventRequest fOngoingRequest = null; | |
34 | ||
35 | /** | |
36 | * Returns the analysis request for creating the segment store | |
37 | * | |
38 | * @param segmentStore | |
39 | * a segment store to fill | |
40 | * @return the segment store analysis request implementation | |
41 | */ | |
42 | protected abstract AbstractSegmentStoreAnalysisRequest createAnalysisRequest(ISegmentStore<ISegment> segmentStore); | |
43 | ||
44 | @Override | |
45 | protected void canceling() { | |
46 | ITmfEventRequest req = fOngoingRequest; | |
47 | if ((req != null) && (!req.isCompleted())) { | |
48 | req.cancel(); | |
49 | } | |
50 | } | |
51 | ||
52 | @Override | |
53 | protected boolean buildAnalysisSegments(ISegmentStore<ISegment> segmentStore, IProgressMonitor monitor) throws TmfAnalysisException { | |
54 | ITmfTrace trace = checkNotNull(getTrace()); | |
55 | /* Cancel an ongoing request */ | |
56 | ITmfEventRequest req = fOngoingRequest; | |
57 | if ((req != null) && (!req.isCompleted())) { | |
58 | req.cancel(); | |
59 | } | |
60 | ||
61 | /* Create a new request */ | |
62 | req = createAnalysisRequest(segmentStore); | |
63 | fOngoingRequest = req; | |
64 | trace.sendRequest(req); | |
65 | ||
66 | try { | |
67 | req.waitForCompletion(); | |
68 | } catch (InterruptedException e) { | |
69 | } | |
70 | ||
71 | /* Do not process the results if the request was cancelled */ | |
72 | if (req.isCancelled() || req.isFailed()) { | |
73 | return false; | |
74 | } | |
75 | return true; | |
76 | } | |
77 | ||
78 | /** | |
79 | * Abstract event request to fill a a segment store | |
80 | */ | |
09f15ee9 | 81 | protected abstract class AbstractSegmentStoreAnalysisRequest extends TmfEventRequest { |
65a4afc0 JCK |
82 | |
83 | private final ISegmentStore<ISegment> fSegmentStore; | |
84 | ||
85 | /** | |
86 | * Constructor | |
87 | * | |
88 | * @param segmentStore | |
89 | * a segment store to fill | |
90 | */ | |
91 | public AbstractSegmentStoreAnalysisRequest(ISegmentStore<ISegment> segmentStore) { | |
09f15ee9 | 92 | super(ITmfEvent.class, TmfTimeRange.ETERNITY, 0, ITmfEventRequest.ALL_DATA, ExecutionType.BACKGROUND, AbstractSegmentStoreAnalysisEventBasedModule.this.getDependencyLevel()); |
65a4afc0 JCK |
93 | /* |
94 | * We do NOT make a copy here! We want to modify the list that was | |
95 | * passed in parameter. | |
96 | */ | |
97 | fSegmentStore = segmentStore; | |
98 | } | |
99 | ||
100 | /** | |
101 | * Returns the segment store | |
102 | * | |
103 | * @return the segment store | |
104 | */ | |
105 | public ISegmentStore<ISegment> getSegmentStore() { | |
106 | return fSegmentStore; | |
107 | } | |
108 | } | |
109 | } |