Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: ec09c925ee48c94bada28159fae8c6cee6e4c918 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*******************************************************************************
 * Copyright (c) 2011, 2012 Ericsson
 *
 * All rights reserved. This program and the accompanying materials are
 * made available under the terms of the Eclipse Public License v1.0 which
 * accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Mathieu Denis <mathieu.denis@polymtl.ca> - Initial implementation
 *******************************************************************************/

package org.eclipse.linuxtools.tmf.ui.viewers.statistics;

import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.AbsTmfStatisticsTree;

/**
 * Class for the TMF event requests specific to the statistics view.
 *
 * @version 2.0
 * @since 2.0
 */
public class TmfStatisticsRequest extends TmfEventRequest {

    /**
     * Reference to the statistics viewer that sent the request.
     */
    private final TmfStatisticsViewer fSender;

    /**
     * Reference to the statistics tree.
     */
    private final AbsTmfStatisticsTree fStatisticsData;

    /**
     * Tells if the request is for the whole trace or for a smaller time range.
     */
    private final boolean fGlobal;

    /**
     * Index of the last event retrieved.
     */
    private long fLastEventIndex;

    /**
     * Constructor
     *
     * @param sender
     *            Sender of this request
     * @param range
     *            The target time range
     * @param index
     *            The starting index
     * @param global
     *            Is this for a global statistics request (true), or a partial
     *            one (false)?
     */
    public TmfStatisticsRequest(TmfStatisticsViewer sender, TmfTimeRange range, long index, boolean global) {
        super(ITmfEvent.class, range, index, TmfDataRequest.ALL_DATA, sender.getPageSize(), ExecutionType.BACKGROUND);
        fGlobal = global;
        fSender = sender;
        fStatisticsData = fSender.getStatisticData();
        fLastEventIndex = index;
    }


    @Override
    public void handleData(ITmfEvent data) {
        ++fLastEventIndex;

        if (data != null) {
            final String traceName = data.getTrace().getName();
            if (fSender.isListeningTo(traceName)) {
                super.handleData(data);

                ITmfExtraEventInfo extraInfo = new ITmfExtraEventInfo() {
                    @Override
                    public String getTraceName() {
                        if (traceName == null) {
                            return Messages.TmfStatisticsView_UnknownTraceName;
                        }
                        return traceName;
                    }
                };

                if (fGlobal) {
                    fStatisticsData.registerEvent(data, extraInfo);
                } else {
                    fStatisticsData.registerEventInTimeRange(data, extraInfo);
                }

                if (getNbRead() % fSender.getRefreshRate() == 0) {
                    fSender.refresh();
                }
            }
        }
    }

    @Override
    public void handleSuccess() {
        super.handleSuccess();
        handleFinish(true);
    }

    @Override
    public void handleFailure() {
        super.handleFailure();
        handleFinish(false);
    }

    @Override
    public void handleCancel() {
        super.handleCancel();
        handleFinish(false);
    }

    /**
     * @return the index of the last event read in the experiment so far
     */
    protected long getLastEventIndex() {
        return fLastEventIndex;
    }

    /**
     * Handles the end of the request whether it is successful or not.
     *
     * @param isSuccessful
     *            Tells if the request has finished successfully or not and
     *            calls the right method from the sender in each case.
     */
    protected void handleFinish(boolean isSuccessful) {
        if (isSuccessful) {
            fSender.modelComplete(fGlobal);
        } else {
            fSender.modelIncomplete(fGlobal);
        }
    }
}

Back to the top