e9bea053f846347761af1b73767bfea68d455495
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng / src / org / eclipse / linuxtools / lttng / state / StateDataRequest.java
1 /*******************************************************************************
2 * Copyright (c) 2009 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 * Contributors:
10 * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
11 *******************************************************************************/
12 package org.eclipse.linuxtools.lttng.state;
13
14 import java.util.Vector;
15
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;
21
22 /**
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
25 *
26 * @author alvaro
27 *
28 */
29 public class StateDataRequest extends TmfDataRequest<TmfEvent> {
30 // ========================================================================
31 // Data
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;
38
39 // ========================================================================
40 // Constructors
41 // =======================================================================
42 /**
43 * @param range
44 * @param offset
45 * @param nbEvents
46 * @param maxBlockSize
47 * @param listener
48 */
49 public StateDataRequest(TmfTimeRange range, long offset, int nbEvents,
50 int maxBlockSize, IStateDataRequestListener listener,
51 StateManager manager) {
52
53 super(range, offset, nbEvents, maxBlockSize);
54 this.manager = manager;
55 if (listener != null && !listeners.contains(listener)) {
56 listeners.add(listener);
57 }
58 }
59
60 /**
61 * @param range
62 * @param offset
63 * @param nbEvents
64 * @param maxBlockSize
65 * @param listener
66 * @param transactionID
67 * optional use by user application
68 */
69 public StateDataRequest(TmfTimeRange range, long offset, int nbEvents,
70 int maxBlockSize, IStateDataRequestListener listener,
71 String transactionID, StateManager manager) {
72
73 this(range, offset, nbEvents, maxBlockSize, listener, manager);
74 this.transactionId = transactionID;
75 }
76
77 // ========================================================================
78 // Methods
79 // =======================================================================
80
81 /**
82 * Trigger the start to process this request right after the notification to
83 * the interested listeners
84 *
85 * @param experiment
86 * @param broadcast
87 * true: All views, false: only to registered listeners
88 */
89 public void startRequestInd(TmfExperiment experiment, boolean broadcast) {
90 if (broadcast) {
91 // Notify all state views.
92 this.broadcast = broadcast;
93 TmfSignalManager.dispatchSignal(new RequestStartedSignal(this));
94 } else {
95 // Notify specific state views
96 for (IStateDataRequestListener listener : listeners) {
97 listener.processingStarted(new RequestStartedSignal(this));
98 }
99 }
100
101 // trigger the start to process this request
102 experiment.processRequest(this, true);
103 }
104
105 /**
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
109 * will be notified.
110 */
111 public void notifyCompletion() {
112 if (broadcast) {
113 // Notify all state views.
114 TmfSignalManager.dispatchSignal(new RequestCompletedSignal(this));
115 } else {
116 // Notify specific state views
117 for (IStateDataRequestListener listener : listeners) {
118 listener.processingCompleted(new RequestCompletedSignal(this));
119 }
120 }
121 }
122
123 public void notifyStarting() {
124 for (IStateDataRequestListener listener : listeners) {
125 listener.processingStarted(new RequestStartedSignal(this));
126 }
127 }
128
129 public String getTransactionId() {
130 return transactionId;
131 }
132
133 public StateManager getStateManager() {
134 return this.manager;
135 }
136
137 // public IStateDataRequestListener getListener() {
138 // return listener;
139 // }
140
141 public void addListener(IStateDataRequestListener listener) {
142 if (!listeners.contains(listener)) {
143 listeners.add(listener);
144 }
145 }
146
147 public void removeListener(IStateDataRequestListener listener) {
148 if (listener != null) {
149 listeners.remove(listener);
150 }
151 }
152
153 /**
154 * @param numOfEvents
155 * the numOfEvents to set
156 */
157 public void setNumOfEvents(long numOfEvents) {
158 this.numOfEvents = numOfEvents;
159 }
160
161 /**
162 * @return the numOfEvents
163 */
164 public long getNumOfEvents() {
165 return numOfEvents;
166 }
167 }
This page took 0.032822 seconds and 4 git commands to generate.