| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2009, 2010 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.request; |
| 13 | |
| 14 | import java.util.Vector; |
| 15 | |
| 16 | import org.eclipse.linuxtools.lttng.event.LttngSyntheticEvent; |
| 17 | import org.eclipse.linuxtools.lttng.state.evProcessor.ITransEventProcessor; |
| 18 | import org.eclipse.linuxtools.tmf.component.TmfEventProvider; |
| 19 | import org.eclipse.linuxtools.tmf.event.TmfTimeRange; |
| 20 | import org.eclipse.linuxtools.tmf.request.TmfEventRequest; |
| 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 LttngSyntEventRequest extends TmfEventRequest<LttngSyntheticEvent> |
| 30 | implements ILttngSyntEventRequest { |
| 31 | |
| 32 | // ======================================================================== |
| 33 | // Data |
| 34 | // ======================================================================= |
| 35 | private Vector<IRequestStatusListener> listeners = new Vector<IRequestStatusListener>(); |
| 36 | private Long feventCount = 0L; |
| 37 | private boolean clearDataInd = false; |
| 38 | private TmfTimeRange fExperimentTimeRange = null; |
| 39 | private Object fsource = null; |
| 40 | private final ITransEventProcessor fprocessor; |
| 41 | private String fExperimentName = null; |
| 42 | |
| 43 | |
| 44 | // ======================================================================== |
| 45 | // Constructors |
| 46 | // ======================================================================= |
| 47 | /** |
| 48 | * @param range |
| 49 | * @param offset |
| 50 | * @param nbEvents |
| 51 | * @param maxBlockSize |
| 52 | * @param listener |
| 53 | * @param experimentTimeRange |
| 54 | * @param processor |
| 55 | */ |
| 56 | public LttngSyntEventRequest(TmfTimeRange range, long offset, int nbEvents, |
| 57 | int maxBlockSize, IRequestStatusListener listener, |
| 58 | TmfTimeRange experimentTimeRange, ITransEventProcessor processor) { |
| 59 | |
| 60 | this(range, offset, nbEvents, maxBlockSize, listener, experimentTimeRange, processor, "", ExecutionType.FOREGROUND); //$NON-NLS-1$ |
| 61 | } |
| 62 | /** |
| 63 | * @param range |
| 64 | * @param offset |
| 65 | * @param nbEvents |
| 66 | * @param maxBlockSize |
| 67 | * @param listener |
| 68 | * @param experimentTimeRange |
| 69 | * @param processor |
| 70 | * @param experimentName |
| 71 | */ |
| 72 | public LttngSyntEventRequest(TmfTimeRange range, long offset, int nbEvents, |
| 73 | int maxBlockSize, IRequestStatusListener listener, |
| 74 | TmfTimeRange experimentTimeRange, ITransEventProcessor processor, String experimentName) { |
| 75 | |
| 76 | this(range, offset, nbEvents, maxBlockSize, listener, experimentTimeRange, processor, experimentName, ExecutionType.FOREGROUND); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * @param range |
| 81 | * @param offset |
| 82 | * @param nbEvents |
| 83 | * @param maxBlockSize |
| 84 | * @param listener |
| 85 | * @param experimentTimeRange |
| 86 | * @param processor |
| 87 | * @param experimentName |
| 88 | * @param execType |
| 89 | */ |
| 90 | public LttngSyntEventRequest(TmfTimeRange range, long offset, int nbEvents, |
| 91 | int maxBlockSize, IRequestStatusListener listener, |
| 92 | TmfTimeRange experimentTimeRange, ITransEventProcessor processor, String experimentName, |
| 93 | ExecutionType execType) { |
| 94 | |
| 95 | super(LttngSyntheticEvent.class, range, (int) offset, nbEvents, maxBlockSize, execType); |
| 96 | fExperimentTimeRange = experimentTimeRange; |
| 97 | fExperimentName = new String(experimentName); |
| 98 | addListener(listener); |
| 99 | |
| 100 | fprocessor = processor; |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * @param listener |
| 105 | */ |
| 106 | public void addListener(IRequestStatusListener listener) { |
| 107 | if (listener != null && !listeners.contains(listener)) { |
| 108 | listeners.add(listener); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * @param listener |
| 114 | */ |
| 115 | public void removeListener(IRequestStatusListener listener) { |
| 116 | if (listener != null) { |
| 117 | listeners.remove(listener); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | // ======================================================================== |
| 122 | // Methods |
| 123 | // ======================================================================= |
| 124 | /* (non-Javadoc) |
| 125 | * @see org.eclipse.linuxtools.lttng.request.ILttngEventRequest#startRequestInd(org.eclipse.linuxtools.tmf.experiment.TmfExperiment, boolean) |
| 126 | */ |
| 127 | @Override |
| 128 | public void startRequestInd(TmfEventProvider<LttngSyntheticEvent> provider) { |
| 129 | // trigger the start to process this request |
| 130 | provider.sendRequest(this); |
| 131 | } |
| 132 | |
| 133 | /* (non-Javadoc) |
| 134 | * @see org.eclipse.linuxtools.lttng.request.ILttngEventRequest#notifyCompletion() |
| 135 | */ |
| 136 | @Override |
| 137 | public void notifyCompletion() { |
| 138 | // Notify specific state views |
| 139 | for (IRequestStatusListener listener : listeners) { |
| 140 | listener.processingCompleted(new RequestCompletedSignal(this)); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | /* (non-Javadoc) |
| 145 | * @see org.eclipse.linuxtools.lttng.request.ILttngEventRequest#notifyStarting() |
| 146 | */ |
| 147 | @Override |
| 148 | public void notifyStarting() { |
| 149 | for (IRequestStatusListener listener : listeners) { |
| 150 | listener.processingStarted(new RequestStartedSignal(this)); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | /* (non-Javadoc) |
| 155 | * @see org.eclipse.linuxtools.lttng.request.ILttngEventRequest#getExperimentTimeRange() |
| 156 | */ |
| 157 | @Override |
| 158 | public TmfTimeRange getExperimentTimeRange() { |
| 159 | return fExperimentTimeRange; |
| 160 | } |
| 161 | |
| 162 | /* |
| 163 | * (non-Javadoc) |
| 164 | * |
| 165 | * @see |
| 166 | * org.eclipse.linuxtools.lttng.request.ILttngSyntEventRequest#setSynEventCount |
| 167 | * (java.lang.Long) |
| 168 | */ |
| 169 | @Override |
| 170 | public synchronized void setSynEventCount(Long numOfEvents) { |
| 171 | this.feventCount = numOfEvents; |
| 172 | } |
| 173 | |
| 174 | /* |
| 175 | * (non-Javadoc) |
| 176 | * |
| 177 | * @see |
| 178 | * org.eclipse.linuxtools.lttng.request.ILttngSyntEventRequest#getEventCount |
| 179 | * () |
| 180 | */ |
| 181 | @Override |
| 182 | public synchronized Long getSynEventCount() { |
| 183 | return feventCount; |
| 184 | } |
| 185 | |
| 186 | /* (non-Javadoc) |
| 187 | * @see org.eclipse.linuxtools.lttng.request.ILttngEventRequest#setclearDataInd(boolean) |
| 188 | */ |
| 189 | @Override |
| 190 | public void setclearDataInd(boolean clearAllData) { |
| 191 | this.clearDataInd = clearAllData; |
| 192 | } |
| 193 | |
| 194 | /* (non-Javadoc) |
| 195 | * @see org.eclipse.linuxtools.lttng.request.ILttngEventRequest#isclearDataInd() |
| 196 | */ |
| 197 | @Override |
| 198 | public boolean isclearDataInd() { |
| 199 | return clearDataInd; |
| 200 | } |
| 201 | |
| 202 | /* (non-Javadoc) |
| 203 | * @see org.eclipse.linuxtools.lttng.request.ILttngEventRequest#handleData() |
| 204 | */ |
| 205 | @Override |
| 206 | public void handleData(LttngSyntheticEvent event) { |
| 207 | super.handleData(event); |
| 208 | } |
| 209 | |
| 210 | |
| 211 | /* |
| 212 | * (non-Javadoc) |
| 213 | * |
| 214 | * @see org.eclipse.linuxtools.tmf.request.TmfDataRequest#handleCompleted() |
| 215 | */ |
| 216 | @Override |
| 217 | public void handleCompleted() { |
| 218 | // notify listeners |
| 219 | notifyCompletion(); |
| 220 | super.handleCompleted(); |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * @return the source |
| 225 | */ |
| 226 | @Override |
| 227 | public Object getSource() { |
| 228 | return fsource; |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * @param source |
| 233 | */ |
| 234 | @Override |
| 235 | public void setSource(Object source) { |
| 236 | this.fsource = source; |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * @return the event processor associated to this request |
| 241 | */ |
| 242 | public ITransEventProcessor getProcessor() { |
| 243 | return fprocessor; |
| 244 | } |
| 245 | |
| 246 | @Override |
| 247 | public String getExperimentName() { |
| 248 | return fExperimentName; |
| 249 | } |
| 250 | |
| 251 | } |