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
.timestamp
.TmfTimeRange
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
25 * Abstract class to create an event base segment store analysis. It uses an
26 * event request to define how events will generate segments.
28 * @author Jean-Christian Kouame
31 public abstract class AbstractSegmentStoreAnalysisEventBasedModule
extends AbstractSegmentStoreAnalysisModule
{
33 private @Nullable ITmfEventRequest fOngoingRequest
= null;
36 * Returns the analysis request for creating the segment store
39 * a segment store to fill
40 * @return the segment store analysis request implementation
42 protected abstract AbstractSegmentStoreAnalysisRequest
createAnalysisRequest(ISegmentStore
<ISegment
> segmentStore
);
45 protected void canceling() {
46 ITmfEventRequest req
= fOngoingRequest
;
47 if ((req
!= null) && (!req
.isCompleted())) {
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())) {
61 /* Create a new request */
62 req
= createAnalysisRequest(segmentStore
);
63 fOngoingRequest
= req
;
64 trace
.sendRequest(req
);
67 req
.waitForCompletion();
68 } catch (InterruptedException e
) {
71 /* Do not process the results if the request was cancelled */
72 if (req
.isCancelled() || req
.isFailed()) {
79 * Abstract event request to fill a a segment store
81 protected abstract class AbstractSegmentStoreAnalysisRequest
extends TmfEventRequest
{
83 private final ISegmentStore
<ISegment
> fSegmentStore
;
89 * a segment store to fill
91 public AbstractSegmentStoreAnalysisRequest(ISegmentStore
<ISegment
> segmentStore
) {
92 super(ITmfEvent
.class, TmfTimeRange
.ETERNITY
, 0, ITmfEventRequest
.ALL_DATA
, ExecutionType
.BACKGROUND
, AbstractSegmentStoreAnalysisEventBasedModule
.this.getDependencyLevel());
94 * We do NOT make a copy here! We want to modify the list that was
95 * passed in parameter.
97 fSegmentStore
= segmentStore
;
101 * Returns the segment store
103 * @return the segment store
105 public ISegmentStore
<ISegment
> getSegmentStore() {
106 return fSegmentStore
;