1 /*******************************************************************************
2 * Copyright (c) 2016 Ericsson
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
;
11 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
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
;
24 * Abstract class to create an event base segment store analysis. It uses an
25 * event request to define how events will generate segments.
27 * @author Jean-Christian Kouame
30 public abstract class AbstractSegmentStoreAnalysisEventBasedModule
extends AbstractSegmentStoreAnalysisModule
{
32 private @Nullable ITmfEventRequest fOngoingRequest
= null;
35 * Returns the analysis request for creating the segment store
38 * a segment store to fill
39 * @return the segment store analysis request implementation
41 protected abstract AbstractSegmentStoreAnalysisRequest
createAnalysisRequest(ISegmentStore
<ISegment
> segmentStore
);
44 protected void canceling() {
45 ITmfEventRequest req
= fOngoingRequest
;
46 if ((req
!= null) && (!req
.isCompleted())) {
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())) {
60 /* Create a new request */
61 req
= createAnalysisRequest(segmentStore
);
62 fOngoingRequest
= req
;
63 trace
.sendRequest(req
);
66 req
.waitForCompletion();
67 } catch (InterruptedException e
) {
70 /* Do not process the results if the request was cancelled */
71 if (req
.isCancelled() || req
.isFailed()) {
78 * Abstract event request to fill a a segment store
80 protected static abstract class AbstractSegmentStoreAnalysisRequest
extends TmfEventRequest
{
82 private final ISegmentStore
<ISegment
> fSegmentStore
;
88 * a segment store to fill
90 public AbstractSegmentStoreAnalysisRequest(ISegmentStore
<ISegment
> segmentStore
) {
91 super(ITmfEvent
.class, 0, ITmfEventRequest
.ALL_DATA
, ExecutionType
.BACKGROUND
);
93 * We do NOT make a copy here! We want to modify the list that was
94 * passed in parameter.
96 fSegmentStore
= segmentStore
;
100 * Returns the segment store
102 * @return the segment store
104 public ISegmentStore
<ISegment
> getSegmentStore() {
105 return fSegmentStore
;