1 /*******************************************************************************
2 * Copyright (c) 2009 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
10 * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
11 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.lttng
.state
;
14 import java
.util
.Vector
;
16 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEvent
;
17 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimeRange
;
18 import org
.eclipse
.linuxtools
.tmf
.request
.TmfDataRequest
;
19 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfSignalManager
;
20 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfExperiment
;
23 * This class is an extension of Data Request which includes specific references
24 * i.e. a status listener to indicate the start and end of the request
29 public class StateDataRequest
extends TmfDataRequest
<TmfEvent
> {
30 // ========================================================================
32 // =======================================================================
33 private Vector
<IStateDataRequestListener
> listeners
= new Vector
<IStateDataRequestListener
>();
34 private String transactionId
= ""; /* optional user's attribute */
35 private StateManager manager
= null;
36 private long numOfEvents
= 0;
37 private boolean broadcast
= false;
39 // ========================================================================
41 // =======================================================================
49 public StateDataRequest(TmfTimeRange range
, long offset
, int nbEvents
,
50 int maxBlockSize
, IStateDataRequestListener listener
,
51 StateManager manager
) {
53 super(range
, offset
, nbEvents
, maxBlockSize
);
54 this.manager
= manager
;
55 if (listener
!= null && !listeners
.contains(listener
)) {
56 listeners
.add(listener
);
66 * @param transactionID
67 * optional use by user application
69 public StateDataRequest(TmfTimeRange range
, long offset
, int nbEvents
,
70 int maxBlockSize
, IStateDataRequestListener listener
,
71 String transactionID
, StateManager manager
) {
73 this(range
, offset
, nbEvents
, maxBlockSize
, listener
, manager
);
74 this.transactionId
= transactionID
;
77 // ========================================================================
79 // =======================================================================
82 * Trigger the start to process this request right after the notification to
83 * the interested listeners
87 * true: All views, false: only to registered listeners
89 public void startRequestInd(TmfExperiment experiment
, boolean broadcast
) {
91 // Notify all state views.
92 this.broadcast
= broadcast
;
93 TmfSignalManager
.dispatchSignal(new RequestStartedSignal(this));
95 // Notify specific state views
96 for (IStateDataRequestListener listener
: listeners
) {
97 listener
.processingStarted(new RequestStartedSignal(this));
101 // trigger the start to process this request
102 experiment
.processRequest(this, true);
106 * to be called by the handleCompletion in superclass method, notifies the
107 * interested listeners. i.e. if the request start indicated broadcast, the
108 * completion will also be broadcasted otherwise only registered listeners
111 public void notifyCompletion() {
113 // Notify all state views.
114 TmfSignalManager
.dispatchSignal(new RequestCompletedSignal(this));
116 // Notify specific state views
117 for (IStateDataRequestListener listener
: listeners
) {
118 listener
.processingCompleted(new RequestCompletedSignal(this));
123 public void notifyStarting() {
124 for (IStateDataRequestListener listener
: listeners
) {
125 listener
.processingStarted(new RequestStartedSignal(this));
129 public String
getTransactionId() {
130 return transactionId
;
133 public StateManager
getStateManager() {
137 // public IStateDataRequestListener getListener() {
141 public void addListener(IStateDataRequestListener listener
) {
142 if (!listeners
.contains(listener
)) {
143 listeners
.add(listener
);
147 public void removeListener(IStateDataRequestListener listener
) {
148 if (listener
!= null) {
149 listeners
.remove(listener
);
155 * the numOfEvents to set
157 public void setNumOfEvents(long numOfEvents
) {
158 this.numOfEvents
= numOfEvents
;
162 * @return the numOfEvents
164 public long getNumOfEvents() {