| 1 | /********************************************************************** |
| 2 | * Copyright (c) 2011, 2012 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 | * Bernd Hufmann - Initial API and implementation |
| 11 | **********************************************************************/ |
| 12 | package org.eclipse.linuxtools.tmf.ui.views.uml2sd.loader; |
| 13 | |
| 14 | import java.util.ArrayList; |
| 15 | import java.util.HashMap; |
| 16 | import java.util.List; |
| 17 | import java.util.Map; |
| 18 | import java.util.concurrent.CopyOnWriteArrayList; |
| 19 | import java.util.concurrent.locks.ReentrantLock; |
| 20 | |
| 21 | import org.eclipse.core.runtime.IProgressMonitor; |
| 22 | import org.eclipse.core.runtime.IStatus; |
| 23 | import org.eclipse.core.runtime.Status; |
| 24 | import org.eclipse.core.runtime.jobs.Job; |
| 25 | import org.eclipse.jface.viewers.ISelection; |
| 26 | import org.eclipse.jface.viewers.StructuredSelection; |
| 27 | import org.eclipse.linuxtools.internal.tmf.ui.Activator; |
| 28 | import org.eclipse.linuxtools.tmf.core.component.TmfComponent; |
| 29 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; |
| 30 | import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; |
| 31 | import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; |
| 32 | import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange; |
| 33 | import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; |
| 34 | import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest; |
| 35 | import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest; |
| 36 | import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest; |
| 37 | import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest; |
| 38 | import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentDisposedSignal; |
| 39 | import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal; |
| 40 | import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal; |
| 41 | import org.eclipse.linuxtools.tmf.core.signal.TmfSignal; |
| 42 | import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler; |
| 43 | import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal; |
| 44 | import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment; |
| 45 | import org.eclipse.linuxtools.tmf.core.uml2sd.ITmfSyncSequenceDiagramEvent; |
| 46 | import org.eclipse.linuxtools.tmf.core.uml2sd.TmfSyncSequenceDiagramEvent; |
| 47 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView; |
| 48 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Frame; |
| 49 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode; |
| 50 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline; |
| 51 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs.Criteria; |
| 52 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs.FilterCriteria; |
| 53 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs.FilterListDialog; |
| 54 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider; |
| 55 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFilterProvider; |
| 56 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFindProvider; |
| 57 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDGraphNodeSupporter; |
| 58 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.IUml2SDLoader; |
| 59 | import org.eclipse.swt.widgets.Display; |
| 60 | import org.eclipse.ui.ISelectionListener; |
| 61 | import org.eclipse.ui.IWorkbenchPart; |
| 62 | import org.eclipse.ui.PlatformUI; |
| 63 | import org.eclipse.ui.progress.IProgressConstants; |
| 64 | |
| 65 | /** |
| 66 | * <p> |
| 67 | * This class is a reference implementation of the <code>org.eclipse.linuxtools.tmf.ui.Uml2SDLoader</code> extension point. It provides |
| 68 | * a Sequence Diagram loader for a user space trace with specific trace content for sending and |
| 69 | * receiving signals between components. I also includes a default implementation for the <code>ITmfEvent</code> parsing. |
| 70 | * </p> |
| 71 | * |
| 72 | * The class <code>TmfUml2SDSyncLoader</code> analyzes events from type <code>ITmfEvent</code> and creates events type |
| 73 | * <code>ITmfSyncSequenceDiagramEvent</code> if the <code>ITmfEvent</code> contains all relevant information. |
| 74 | * The analysis checks that the event type strings contains either string SEND or RECEIVE. If event type matches these key |
| 75 | * words, the analyzer will look for strings sender, receiver and signal in the event fields of type <code>ITmfEventField</code>. |
| 76 | * If all the data is found a sequence diagram event from can be created. Note that Sync Messages are assumed, which |
| 77 | * means start and end time are the same. <br> |
| 78 | * <br> |
| 79 | * The parsing of the <code>ITmfEvent</code> is done in the method <code>getSequnceDiagramEvent()</code> of class |
| 80 | * <code>TmfUml2SDSyncLoader</code>. By extending the class <code>TmfUml2SDSyncLoader</code> and overwriting |
| 81 | * <code>getSequnceDiagramEvent()</code> a customized parsing algorithm can be implemented.<br> |
| 82 | * <br> |
| 83 | * Note that combined traces of multiple components, that contain the trace information about the same interactions are not |
| 84 | * supported in the class <code>TmfUml2SDSyncLoader</code>. |
| 85 | * |
| 86 | * @version 1.0 |
| 87 | * @author Bernd Hufmann |
| 88 | */ |
| 89 | public class TmfUml2SDSyncLoader extends TmfComponent implements IUml2SDLoader, ISDFindProvider, ISDFilterProvider, ISDAdvancedPagingProvider, ISelectionListener { |
| 90 | |
| 91 | // ------------------------------------------------------------------------ |
| 92 | // Constants |
| 93 | // ------------------------------------------------------------------------ |
| 94 | /** |
| 95 | * Default title name. |
| 96 | */ |
| 97 | protected final static String TITLE = Messages.TmfUml2SDSyncLoader_ViewName; |
| 98 | /** |
| 99 | * Default block size for background request. |
| 100 | */ |
| 101 | protected final static int DEFAULT_BLOCK_SIZE = 50000; |
| 102 | /** |
| 103 | * Maximum number of messages per page. |
| 104 | */ |
| 105 | protected final static int MAX_NUM_OF_MSG = 10000; |
| 106 | /** |
| 107 | * Initial time range window. |
| 108 | */ |
| 109 | protected final static long INITIAL_WINDOW_OFFSET = (1L * 100 * 1000 * 1000); // .1sec |
| 110 | |
| 111 | // ------------------------------------------------------------------------ |
| 112 | // Attributes |
| 113 | // ------------------------------------------------------------------------ |
| 114 | |
| 115 | // Experiment attributes |
| 116 | /** |
| 117 | * The TMF experiment reference. |
| 118 | */ |
| 119 | protected TmfExperiment<ITmfEvent> fExperiment = null; |
| 120 | /** |
| 121 | * The current indexing event request. |
| 122 | */ |
| 123 | protected ITmfEventRequest<ITmfEvent> fIndexRequest = null; |
| 124 | /** |
| 125 | * The current request to fill a page. |
| 126 | */ |
| 127 | protected ITmfEventRequest<ITmfEvent> fPageRequest = null; |
| 128 | /** |
| 129 | * Flag whether the time range signal was sent by this loader class or not |
| 130 | */ |
| 131 | volatile protected boolean fIsSignalSent = false; |
| 132 | /** |
| 133 | * The initial request window size. |
| 134 | */ |
| 135 | volatile protected long fInitialWindow = INITIAL_WINDOW_OFFSET; |
| 136 | |
| 137 | // The view and event attributes |
| 138 | /** |
| 139 | * The sequence diagram view reference. |
| 140 | */ |
| 141 | protected SDView fView = null; |
| 142 | /** |
| 143 | * The current sequence diagram frame reference. |
| 144 | */ |
| 145 | protected Frame fFrame = null; |
| 146 | /** |
| 147 | * The list of sequence diagram events of current page. |
| 148 | */ |
| 149 | protected List<ITmfSyncSequenceDiagramEvent> fEvents = new ArrayList<ITmfSyncSequenceDiagramEvent>(); |
| 150 | |
| 151 | // Checkpoint and page attributes |
| 152 | /** |
| 153 | * The checkpoints of the whole sequence diagram trace (i.e. start time stamp of each page) |
| 154 | */ |
| 155 | protected List<TmfTimeRange> fCheckPoints = new ArrayList<TmfTimeRange>(MAX_NUM_OF_MSG); |
| 156 | /** |
| 157 | * The current page displayed. |
| 158 | */ |
| 159 | volatile protected int fCurrentPage = 0; |
| 160 | /** |
| 161 | * The current time selected. |
| 162 | */ |
| 163 | protected ITmfTimestamp fCurrentTime = null; |
| 164 | /** |
| 165 | * Flag to specify that selection of message is done by selection or by signal. |
| 166 | */ |
| 167 | volatile protected boolean fIsSelect = false; |
| 168 | |
| 169 | // Search attributes |
| 170 | /** |
| 171 | * The job for searching across pages. |
| 172 | */ |
| 173 | protected SearchJob fFindJob = null; |
| 174 | /** |
| 175 | * List of found nodes within a page. |
| 176 | */ |
| 177 | protected List<GraphNode> fFindResults = new ArrayList<GraphNode>(); |
| 178 | /** |
| 179 | * The current find criteria reference |
| 180 | */ |
| 181 | protected Criteria fFindCriteria = null; |
| 182 | /** |
| 183 | * The current find index within the list of found nodes (<code>fFindeResults</code> within a page. |
| 184 | */ |
| 185 | volatile protected int fCurrentFindIndex = 0; |
| 186 | |
| 187 | // Filter attributes |
| 188 | /** |
| 189 | * The list of active filters. |
| 190 | */ |
| 191 | protected List<FilterCriteria> fFilterCriteria = null; |
| 192 | |
| 193 | // Thread synchronization |
| 194 | /** |
| 195 | * The synchronization lock. |
| 196 | */ |
| 197 | protected ReentrantLock fLock = new ReentrantLock(); |
| 198 | |
| 199 | // ------------------------------------------------------------------------ |
| 200 | // Constructors |
| 201 | // ------------------------------------------------------------------------ |
| 202 | /** |
| 203 | * Default constructor |
| 204 | */ |
| 205 | public TmfUml2SDSyncLoader() { |
| 206 | super(TITLE); |
| 207 | } |
| 208 | |
| 209 | /** |
| 210 | * Constructor |
| 211 | * |
| 212 | * @param name Name of loader |
| 213 | */ |
| 214 | public TmfUml2SDSyncLoader(String name) { |
| 215 | super(name); |
| 216 | } |
| 217 | |
| 218 | // ------------------------------------------------------------------------ |
| 219 | // Operations |
| 220 | // ------------------------------------------------------------------------ |
| 221 | /** |
| 222 | * Returns the current time if available else null. |
| 223 | * |
| 224 | * @return the current time if available else null |
| 225 | */ |
| 226 | public ITmfTimestamp getCurrentTime() { |
| 227 | fLock.lock(); |
| 228 | try { |
| 229 | if (fCurrentTime != null) { |
| 230 | return fCurrentTime.clone(); |
| 231 | } |
| 232 | return null; |
| 233 | } finally { |
| 234 | fLock.unlock(); |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | /** |
| 239 | * Waits for the page request to be completed |
| 240 | */ |
| 241 | public void waitForCompletion() { |
| 242 | fLock.lock(); |
| 243 | ITmfEventRequest<ITmfEvent> request = fPageRequest; |
| 244 | fLock.unlock(); |
| 245 | if (request != null) |
| 246 | try { |
| 247 | request.waitForCompletion(); |
| 248 | } catch (InterruptedException e) { |
| 249 | // ignore |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | /** |
| 254 | * Signal handler for the experiment selected signal. |
| 255 | * |
| 256 | * Spawns a request to index the experiment (checkpoints creation) as well as it fills |
| 257 | * the first page. |
| 258 | * |
| 259 | * @param signal The experiment selected signal |
| 260 | */ |
| 261 | @SuppressWarnings("unchecked") |
| 262 | @TmfSignalHandler |
| 263 | public void experimentSelected(TmfExperimentSelectedSignal<ITmfEvent> signal) { |
| 264 | |
| 265 | final Job job = new IndexingJob("Indexing " + getName() + "..."); //$NON-NLS-1$ //$NON-NLS-2$ |
| 266 | job.setUser(false); |
| 267 | job.schedule(); |
| 268 | |
| 269 | fLock.lock(); |
| 270 | try { |
| 271 | // Update the trace reference |
| 272 | TmfExperiment<ITmfEvent> exp = (TmfExperiment<ITmfEvent>) signal.getExperiment(); |
| 273 | if (!exp.equals(fExperiment)) { |
| 274 | fExperiment = exp; |
| 275 | } |
| 276 | |
| 277 | TmfTimeRange window = TmfTimeRange.ETERNITY; |
| 278 | |
| 279 | fIndexRequest = new TmfEventRequest<ITmfEvent>(ITmfEvent.class, window, TmfDataRequest.ALL_DATA, DEFAULT_BLOCK_SIZE, ITmfDataRequest.ExecutionType.BACKGROUND) { |
| 280 | |
| 281 | private ITmfTimestamp fFirstTime = null; |
| 282 | private ITmfTimestamp fLastTime = null; |
| 283 | private int fNbSeqEvents = 0; |
| 284 | private final List<ITmfSyncSequenceDiagramEvent> fSdEvents = new ArrayList<ITmfSyncSequenceDiagramEvent>(MAX_NUM_OF_MSG); |
| 285 | |
| 286 | /* |
| 287 | * (non-Javadoc) |
| 288 | * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleData(org.eclipse.linuxtools.tmf.core.event.ITmfEvent) |
| 289 | */ |
| 290 | @Override |
| 291 | public void handleData(ITmfEvent event) { |
| 292 | super.handleData(event); |
| 293 | |
| 294 | ITmfSyncSequenceDiagramEvent sdEvent = getSequnceDiagramEvent(event); |
| 295 | |
| 296 | if (sdEvent != null) { |
| 297 | ++fNbSeqEvents; |
| 298 | |
| 299 | if (fFirstTime == null) { |
| 300 | fFirstTime = event.getTimestamp().clone(); |
| 301 | } |
| 302 | |
| 303 | fLastTime = event.getTimestamp().clone(); |
| 304 | |
| 305 | if ((fNbSeqEvents % MAX_NUM_OF_MSG) == 0) { |
| 306 | fLock.lock(); |
| 307 | try { |
| 308 | fCheckPoints.add(new TmfTimeRange(fFirstTime, fLastTime)); |
| 309 | if (fView != null) { |
| 310 | fView.updateCoolBar(); |
| 311 | } |
| 312 | } finally { |
| 313 | fLock.unlock(); |
| 314 | } |
| 315 | fFirstTime = null; |
| 316 | |
| 317 | } |
| 318 | |
| 319 | if (fNbSeqEvents > MAX_NUM_OF_MSG) { |
| 320 | // page is full |
| 321 | return; |
| 322 | } |
| 323 | |
| 324 | fSdEvents.add(sdEvent); |
| 325 | |
| 326 | if (fNbSeqEvents == MAX_NUM_OF_MSG) { |
| 327 | fillCurrentPage(fSdEvents); |
| 328 | } |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | /* |
| 333 | * (non-Javadoc) |
| 334 | * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleSuccess() |
| 335 | */ |
| 336 | @Override |
| 337 | public void handleSuccess() { |
| 338 | if ((fFirstTime != null) && (fLastTime != null)) { |
| 339 | |
| 340 | fLock.lock(); |
| 341 | try { |
| 342 | fCheckPoints.add(new TmfTimeRange(fFirstTime, fLastTime)); |
| 343 | if (fView != null) { |
| 344 | fView.updateCoolBar(); |
| 345 | } |
| 346 | } finally { |
| 347 | fLock.unlock(); |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | if (fNbSeqEvents <= MAX_NUM_OF_MSG) { |
| 352 | fillCurrentPage(fSdEvents); |
| 353 | } |
| 354 | |
| 355 | super.handleSuccess(); |
| 356 | } |
| 357 | |
| 358 | /* |
| 359 | * (non-Javadoc) |
| 360 | * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleCompleted() |
| 361 | */ |
| 362 | @Override |
| 363 | public void handleCompleted() { |
| 364 | if (fEvents.isEmpty()) { |
| 365 | fFrame = new Frame(); |
| 366 | fView.setFrameSync(fFrame); |
| 367 | } |
| 368 | super.handleCompleted(); |
| 369 | job.cancel(); |
| 370 | } |
| 371 | }; |
| 372 | |
| 373 | fExperiment.sendRequest(fIndexRequest); |
| 374 | } finally { |
| 375 | fLock.unlock(); |
| 376 | } |
| 377 | |
| 378 | } |
| 379 | |
| 380 | /** |
| 381 | * Signal handler for the experiment disposed signal. |
| 382 | * |
| 383 | * @param signal The experiment disposed signal |
| 384 | */ |
| 385 | @TmfSignalHandler |
| 386 | public void experimentDisposed(TmfExperimentDisposedSignal<ITmfEvent> signal) { |
| 387 | if (signal.getExperiment() != TmfExperiment.getCurrentExperiment()) { |
| 388 | return; |
| 389 | } |
| 390 | fLock.lock(); |
| 391 | try { |
| 392 | if ((fIndexRequest != null) && !fIndexRequest.isCompleted()) { |
| 393 | fIndexRequest.cancel(); |
| 394 | fIndexRequest = null; |
| 395 | } |
| 396 | |
| 397 | cancelOngoingRequests(); |
| 398 | |
| 399 | if (fFilterCriteria != null) { |
| 400 | fFilterCriteria.clear(); |
| 401 | } |
| 402 | |
| 403 | FilterListDialog.deactivateSavedGlobalFilters(); |
| 404 | |
| 405 | resetLoader(); |
| 406 | } finally { |
| 407 | fLock.unlock(); |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | /** |
| 412 | * Moves to the page that contains the time provided by the signal. The messages will be selected |
| 413 | * if the provided time is the time of a message. |
| 414 | * |
| 415 | * @param signal The Time synch signal. |
| 416 | */ |
| 417 | @TmfSignalHandler |
| 418 | public void synchToTime(TmfTimeSynchSignal signal) { |
| 419 | fLock.lock(); |
| 420 | try { |
| 421 | if ((signal.getSource() != this) && (fFrame != null)) { |
| 422 | |
| 423 | fCurrentTime = signal.getCurrentTime(); |
| 424 | fIsSelect = true; |
| 425 | moveToMessage(); |
| 426 | } |
| 427 | } finally { |
| 428 | fLock.unlock(); |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | /** |
| 433 | * Moves to the page that contains the current time provided by signal. |
| 434 | * No message will be selected however the focus will be set to the message |
| 435 | * if the provided time is the time of a message. |
| 436 | * |
| 437 | * @param signal The time range sync signal |
| 438 | */ |
| 439 | @TmfSignalHandler |
| 440 | public void synchToTimeRange(TmfRangeSynchSignal signal) { |
| 441 | fLock.lock(); |
| 442 | try { |
| 443 | if ((signal.getSource() != this) && (fFrame != null) && !fIsSignalSent) { |
| 444 | TmfTimeRange newTimeRange = signal.getCurrentRange(); |
| 445 | ITmfTimestamp delta = newTimeRange.getEndTime().getDelta(newTimeRange.getStartTime()); |
| 446 | fInitialWindow = delta.getValue(); |
| 447 | |
| 448 | fIsSelect = false; |
| 449 | fCurrentTime = newTimeRange.getStartTime(); |
| 450 | |
| 451 | moveToMessage(); |
| 452 | } |
| 453 | } finally { |
| 454 | fLock.unlock(); |
| 455 | } |
| 456 | |
| 457 | } |
| 458 | |
| 459 | /* |
| 460 | * (non-Javadoc) |
| 461 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.IUml2SDLoader#setViewer(org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView) |
| 462 | */ |
| 463 | @SuppressWarnings("unchecked") |
| 464 | @Override |
| 465 | public void setViewer(SDView viewer) { |
| 466 | |
| 467 | fLock.lock(); |
| 468 | try { |
| 469 | fView = viewer; |
| 470 | PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().addPostSelectionListener(this); |
| 471 | fView.setSDFindProvider(this); |
| 472 | fView.setSDPagingProvider(this); |
| 473 | fView.setSDFilterProvider(this); |
| 474 | |
| 475 | resetLoader(); |
| 476 | |
| 477 | fExperiment = (TmfExperiment<ITmfEvent>) TmfExperiment.getCurrentExperiment(); |
| 478 | if (fExperiment != null) { |
| 479 | experimentSelected(new TmfExperimentSelectedSignal<ITmfEvent>(this, fExperiment)); |
| 480 | } |
| 481 | } finally { |
| 482 | fLock.unlock(); |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | /* |
| 487 | * (non-Javadoc) |
| 488 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.IUml2SDLoader#getTitleString() |
| 489 | */ |
| 490 | @Override |
| 491 | public String getTitleString() { |
| 492 | return getName(); |
| 493 | } |
| 494 | |
| 495 | /* |
| 496 | * (non-Javadoc) |
| 497 | * @see org.eclipse.linuxtools.tmf.component.TmfComponent#dispose() |
| 498 | */ |
| 499 | @Override |
| 500 | public void dispose() { |
| 501 | super.dispose(); |
| 502 | fLock.lock(); |
| 503 | try { |
| 504 | PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().removePostSelectionListener(this); |
| 505 | fView.setSDFindProvider(null); |
| 506 | fView.setSDPagingProvider(null); |
| 507 | fView.setSDFilterProvider(null); |
| 508 | fView = null; |
| 509 | } finally { |
| 510 | fLock.unlock(); |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | /* |
| 515 | * (non-Javadoc) |
| 516 | * @see org.eclipse.hyades.uml2sd.ui.actions.provider.ISDGraphNodeSupporter#isNodeSupported(int) |
| 517 | */ |
| 518 | @Override |
| 519 | public boolean isNodeSupported(int nodeType) { |
| 520 | switch (nodeType) { |
| 521 | case ISDGraphNodeSupporter.LIFELINE: |
| 522 | case ISDGraphNodeSupporter.SYNCMESSAGE: |
| 523 | return true; |
| 524 | |
| 525 | default: |
| 526 | break; |
| 527 | } |
| 528 | return false; |
| 529 | } |
| 530 | |
| 531 | /* |
| 532 | * (non-Javadoc) |
| 533 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDGraphNodeSupporter#getNodeName(int, java.lang.String) |
| 534 | */ |
| 535 | @Override |
| 536 | public String getNodeName(int nodeType, String loaderClassName) { |
| 537 | switch (nodeType) { |
| 538 | case ISDGraphNodeSupporter.LIFELINE: |
| 539 | return Messages.TmfUml2SDSyncLoader_CategoryLifeline; |
| 540 | case ISDGraphNodeSupporter.SYNCMESSAGE: |
| 541 | return Messages.TmfUml2SDSyncLoader_CategoryMessage; |
| 542 | } |
| 543 | return ""; //$NON-NLS-1$ |
| 544 | } |
| 545 | |
| 546 | /* |
| 547 | * (non-Javadoc) |
| 548 | * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection) |
| 549 | */ |
| 550 | @Override |
| 551 | public void selectionChanged(IWorkbenchPart part, ISelection selection) { |
| 552 | ISelection sel = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection(); |
| 553 | if ((sel != null) && (sel instanceof StructuredSelection)) { |
| 554 | StructuredSelection stSel = (StructuredSelection) sel; |
| 555 | if (stSel.getFirstElement() instanceof TmfSyncMessage) { |
| 556 | TmfSyncMessage syncMsg = ((TmfSyncMessage) stSel.getFirstElement()); |
| 557 | broadcast(new TmfTimeSynchSignal(this, syncMsg.getStartTime())); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | /* |
| 563 | * (non-Javadoc) |
| 564 | * @see |
| 565 | * org.eclipse.hyades.uml2sd.ui.actions.provider.ISDFindProvider#find(org.eclipse.hyades.uml2sd.ui.actions.widgets.Criteria) |
| 566 | */ |
| 567 | @Override |
| 568 | public boolean find(Criteria toSearch) { |
| 569 | fLock.lock(); |
| 570 | try { |
| 571 | if (fFrame == null) { |
| 572 | return false; |
| 573 | } |
| 574 | |
| 575 | if ((fFindResults == null) || (fFindCriteria == null) || !fFindCriteria.compareTo(toSearch)) { |
| 576 | fFindResults = new CopyOnWriteArrayList<GraphNode>(); |
| 577 | fFindCriteria = toSearch; |
| 578 | if (fFindCriteria.isLifeLineSelected()) { |
| 579 | for (int i = 0; i < fFrame.lifeLinesCount(); i++) { |
| 580 | if (fFindCriteria.matches(fFrame.getLifeline(i).getName())) { |
| 581 | fFindResults.add(fFrame.getLifeline(i)); |
| 582 | } |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | ArrayList<GraphNode> msgs = new ArrayList<GraphNode>(); |
| 587 | if (fFindCriteria.isSyncMessageSelected()) { |
| 588 | for (int i = 0; i < fFrame.syncMessageCount(); i++) { |
| 589 | if (fFindCriteria.matches(fFrame.getSyncMessage(i).getName())) { |
| 590 | msgs.add(fFrame.getSyncMessage(i)); |
| 591 | } |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | if (!msgs.isEmpty()) { |
| 596 | fFindResults.addAll(msgs); |
| 597 | } |
| 598 | |
| 599 | @SuppressWarnings("rawtypes") |
| 600 | List selection = fView.getSDWidget().getSelection(); |
| 601 | if ((selection != null) && (selection.size() == 1)) { |
| 602 | fCurrentFindIndex = fFindResults.indexOf(selection.get(0)) + 1; |
| 603 | } else { |
| 604 | fCurrentFindIndex = 0; |
| 605 | } |
| 606 | } else { |
| 607 | fCurrentFindIndex++; |
| 608 | } |
| 609 | |
| 610 | if (fFindResults.size() > fCurrentFindIndex) { |
| 611 | GraphNode current = fFindResults.get(fCurrentFindIndex); |
| 612 | fView.getSDWidget().moveTo(current); |
| 613 | return true; |
| 614 | } else { |
| 615 | fFindResults = null; |
| 616 | fCurrentFindIndex =0; |
| 617 | return findInNextPages(fFindCriteria); // search in other page |
| 618 | } |
| 619 | } finally { |
| 620 | fLock.unlock(); |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | /* |
| 625 | * (non-Javadoc) |
| 626 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFindProvider#cancel() |
| 627 | */ |
| 628 | @Override |
| 629 | public void cancel() { |
| 630 | cancelOngoingRequests(); |
| 631 | } |
| 632 | |
| 633 | /* |
| 634 | * (non-Javadoc) |
| 635 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFilterProvider#filter(java.util.List) |
| 636 | */ |
| 637 | @SuppressWarnings("unchecked") |
| 638 | @Override |
| 639 | public boolean filter(List<?> filters) { |
| 640 | fLock.lock(); |
| 641 | try { |
| 642 | cancelOngoingRequests(); |
| 643 | |
| 644 | List<FilterCriteria> list = (List<FilterCriteria>)filters; |
| 645 | fFilterCriteria = new ArrayList<FilterCriteria>(list); |
| 646 | |
| 647 | fillCurrentPage(fEvents); |
| 648 | |
| 649 | } finally { |
| 650 | fLock.unlock(); |
| 651 | } |
| 652 | return true; |
| 653 | } |
| 654 | |
| 655 | /* |
| 656 | * (non-Javadoc) |
| 657 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#hasNextPage() |
| 658 | */ |
| 659 | @Override |
| 660 | public boolean hasNextPage() { |
| 661 | fLock.lock(); |
| 662 | try { |
| 663 | int size = fCheckPoints.size(); |
| 664 | if (size > 0) { |
| 665 | return fCurrentPage < (size - 1); |
| 666 | } |
| 667 | } finally { |
| 668 | fLock.unlock(); |
| 669 | } |
| 670 | return false; |
| 671 | } |
| 672 | |
| 673 | /* |
| 674 | * (non-Javadoc) |
| 675 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#hasPrevPage() |
| 676 | */ |
| 677 | @Override |
| 678 | public boolean hasPrevPage() { |
| 679 | fLock.lock(); |
| 680 | try { |
| 681 | return fCurrentPage > 0; |
| 682 | } finally { |
| 683 | fLock.unlock(); |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | /* |
| 688 | * (non-Javadoc) |
| 689 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#nextPage() |
| 690 | */ |
| 691 | @Override |
| 692 | public void nextPage() { |
| 693 | fLock.lock(); |
| 694 | try { |
| 695 | // Safety check |
| 696 | if (fCurrentPage >= (fCheckPoints.size() - 1)) { |
| 697 | return; |
| 698 | } |
| 699 | |
| 700 | cancelOngoingRequests(); |
| 701 | fCurrentTime = null; |
| 702 | fCurrentPage++; |
| 703 | moveToPage(); |
| 704 | } finally { |
| 705 | fLock.unlock(); |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | /* |
| 710 | * (non-Javadoc) |
| 711 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#prevPage() |
| 712 | */ |
| 713 | @Override |
| 714 | public void prevPage() { |
| 715 | fLock.lock(); |
| 716 | try { |
| 717 | // Safety check |
| 718 | if (fCurrentPage <= 0) { |
| 719 | return; |
| 720 | } |
| 721 | |
| 722 | cancelOngoingRequests(); |
| 723 | fCurrentTime = null; |
| 724 | fCurrentPage--; |
| 725 | moveToPage(); |
| 726 | } finally { |
| 727 | fLock.unlock(); |
| 728 | } |
| 729 | } |
| 730 | |
| 731 | /* |
| 732 | * (non-Javadoc) |
| 733 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#firstPage() |
| 734 | */ |
| 735 | @Override |
| 736 | public void firstPage() { |
| 737 | fLock.lock(); |
| 738 | try { |
| 739 | |
| 740 | cancelOngoingRequests(); |
| 741 | fCurrentTime = null; |
| 742 | fCurrentPage = 0; |
| 743 | moveToPage(); |
| 744 | } finally { |
| 745 | fLock.unlock(); |
| 746 | } |
| 747 | } |
| 748 | |
| 749 | /* |
| 750 | * (non-Javadoc) |
| 751 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#lastPage() |
| 752 | */ |
| 753 | @Override |
| 754 | public void lastPage() { |
| 755 | fLock.lock(); |
| 756 | try { |
| 757 | cancelOngoingRequests(); |
| 758 | fCurrentTime = null; |
| 759 | fCurrentPage = fCheckPoints.size() - 1; |
| 760 | moveToPage(); |
| 761 | } finally { |
| 762 | fLock.unlock(); |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | /* |
| 767 | * (non-Javadoc) |
| 768 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#currentPage() |
| 769 | */ |
| 770 | @Override |
| 771 | public int currentPage() { |
| 772 | fLock.lock(); |
| 773 | try { |
| 774 | return fCurrentPage; |
| 775 | } finally { |
| 776 | fLock.unlock(); |
| 777 | } |
| 778 | } |
| 779 | |
| 780 | /* |
| 781 | * (non-Javadoc) |
| 782 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#pagesCount() |
| 783 | */ |
| 784 | @Override |
| 785 | public int pagesCount() { |
| 786 | fLock.lock(); |
| 787 | try { |
| 788 | return fCheckPoints.size(); |
| 789 | } finally { |
| 790 | fLock.unlock(); |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | /* |
| 795 | * (non-Javadoc) |
| 796 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#pageNumberChanged(int) |
| 797 | */ |
| 798 | @Override |
| 799 | public void pageNumberChanged(int pagenNumber) { |
| 800 | int localPageNumber = pagenNumber; |
| 801 | |
| 802 | fLock.lock(); |
| 803 | try { |
| 804 | cancelOngoingRequests(); |
| 805 | |
| 806 | if (localPageNumber < 0) { |
| 807 | localPageNumber = 0; |
| 808 | } |
| 809 | int size = fCheckPoints.size(); |
| 810 | if (localPageNumber > (size - 1)) { |
| 811 | localPageNumber = size - 1; |
| 812 | } |
| 813 | fCurrentPage = localPageNumber; |
| 814 | moveToPage(); |
| 815 | } finally { |
| 816 | fLock.unlock(); |
| 817 | } |
| 818 | } |
| 819 | |
| 820 | /* |
| 821 | * (non-Javadoc) |
| 822 | * @see org.eclipse.linuxtools.tmf.component.TmfComponent#broadcast(org.eclipse.linuxtools.tmf.signal.TmfSignal) |
| 823 | */ |
| 824 | @Override |
| 825 | public void broadcast(TmfSignal signal) { |
| 826 | fIsSignalSent = true; |
| 827 | super.broadcast(signal); |
| 828 | fIsSignalSent = false; |
| 829 | } |
| 830 | |
| 831 | /** |
| 832 | * Cancels any ongoing find operation |
| 833 | */ |
| 834 | protected void cancelOngoingRequests() { |
| 835 | fLock.lock(); |
| 836 | try { |
| 837 | // Cancel the search thread |
| 838 | if (fFindJob != null) { |
| 839 | fFindJob.cancel(); |
| 840 | } |
| 841 | |
| 842 | fFindResults = null; |
| 843 | fFindCriteria = null; |
| 844 | fCurrentFindIndex = 0; |
| 845 | |
| 846 | if ((fPageRequest != null) && !fPageRequest.isCompleted()) { |
| 847 | fPageRequest.cancel(); |
| 848 | fPageRequest = null; |
| 849 | } |
| 850 | } finally { |
| 851 | fLock.unlock(); |
| 852 | } |
| 853 | } |
| 854 | |
| 855 | /** |
| 856 | * Resets loader attributes |
| 857 | */ |
| 858 | protected void resetLoader() { |
| 859 | fLock.lock(); |
| 860 | try { |
| 861 | fCurrentTime = null; |
| 862 | fEvents.clear(); |
| 863 | fCheckPoints.clear(); |
| 864 | fCurrentPage = 0; |
| 865 | fCurrentFindIndex = 0; |
| 866 | fFindCriteria = null; |
| 867 | fFindResults = null; |
| 868 | fInitialWindow = INITIAL_WINDOW_OFFSET; |
| 869 | fView.setFrameSync(new Frame()); |
| 870 | fFrame = null; |
| 871 | } |
| 872 | finally { |
| 873 | fLock.unlock(); |
| 874 | } |
| 875 | |
| 876 | } |
| 877 | |
| 878 | /** |
| 879 | * Fills current page with sequence diagram content. |
| 880 | * |
| 881 | * @param events sequence diagram events |
| 882 | */ |
| 883 | protected void fillCurrentPage(List<ITmfSyncSequenceDiagramEvent> events) { |
| 884 | |
| 885 | fLock.lock(); |
| 886 | try { |
| 887 | fEvents = new ArrayList<ITmfSyncSequenceDiagramEvent>(events); |
| 888 | if (fView != null) { |
| 889 | fView.toggleWaitCursorAsync(true); |
| 890 | } |
| 891 | } finally { |
| 892 | fLock.unlock(); |
| 893 | } |
| 894 | |
| 895 | final Frame frame = new Frame(); |
| 896 | |
| 897 | if (!events.isEmpty()) { |
| 898 | Map<String, Lifeline> nodeToLifelineMap = new HashMap<String, Lifeline>(); |
| 899 | |
| 900 | frame.setName(Messages.TmfUml2SDSyncLoader_FrameName); |
| 901 | |
| 902 | for (int i = 0; i < events.size(); i++) { |
| 903 | |
| 904 | ITmfSyncSequenceDiagramEvent sdEvent = events.get(i); |
| 905 | |
| 906 | if ((nodeToLifelineMap.get(sdEvent.getSender()) == null) && (!filterLifeLine(sdEvent.getSender()))) { |
| 907 | Lifeline lifeline = new Lifeline(); |
| 908 | lifeline.setName(sdEvent.getSender()); |
| 909 | nodeToLifelineMap.put(sdEvent.getSender(), lifeline); |
| 910 | frame.addLifeLine(lifeline); |
| 911 | } |
| 912 | |
| 913 | if ((nodeToLifelineMap.get(sdEvent.getReceiver()) == null) && (!filterLifeLine(sdEvent.getReceiver()))) { |
| 914 | Lifeline lifeline = new Lifeline(); |
| 915 | lifeline.setName(sdEvent.getReceiver()); |
| 916 | nodeToLifelineMap.put(sdEvent.getReceiver(), lifeline); |
| 917 | frame.addLifeLine(lifeline); |
| 918 | } |
| 919 | } |
| 920 | |
| 921 | int eventOccurence = 1; |
| 922 | |
| 923 | for (int i = 0; i < events.size(); i++) { |
| 924 | ITmfSyncSequenceDiagramEvent sdEvent = events.get(i); |
| 925 | |
| 926 | // Check message filter |
| 927 | if (filterMessage(sdEvent)) { |
| 928 | continue; |
| 929 | } |
| 930 | |
| 931 | // Set the message sender and receiver |
| 932 | Lifeline startLifeline = nodeToLifelineMap.get(sdEvent.getSender()); |
| 933 | Lifeline endLifeline = nodeToLifelineMap.get(sdEvent.getReceiver()); |
| 934 | |
| 935 | // Check if any of the lifelines were filtered |
| 936 | if ((startLifeline == null) || (endLifeline == null)) { |
| 937 | continue; |
| 938 | } |
| 939 | |
| 940 | int tmp = Math.max(startLifeline.getEventOccurrence(), endLifeline.getEventOccurrence()); |
| 941 | eventOccurence = Math.max(eventOccurence, tmp); |
| 942 | |
| 943 | startLifeline.setCurrentEventOccurrence(eventOccurence); |
| 944 | endLifeline.setCurrentEventOccurrence(eventOccurence); |
| 945 | |
| 946 | TmfSyncMessage message = new TmfSyncMessage(sdEvent, eventOccurence++); |
| 947 | |
| 948 | message.setStartLifeline(startLifeline); |
| 949 | message.setEndLifeline(endLifeline); |
| 950 | |
| 951 | message.setTime(sdEvent.getStartTime()); |
| 952 | |
| 953 | // add the message to the frame |
| 954 | frame.addMessage(message); |
| 955 | |
| 956 | } |
| 957 | fLock.lock(); |
| 958 | try { |
| 959 | if (!fView.getSDWidget().isDisposed()) { |
| 960 | fView.getSDWidget().getDisplay().asyncExec(new Runnable() { |
| 961 | |
| 962 | @Override |
| 963 | public void run() { |
| 964 | |
| 965 | fLock.lock(); |
| 966 | try { |
| 967 | // check if view was disposed in the meanwhile |
| 968 | if ((fView != null) && (!fView.getSDWidget().isDisposed())) { |
| 969 | fFrame = frame; |
| 970 | fView.setFrame(fFrame); |
| 971 | |
| 972 | if (fCurrentTime != null) { |
| 973 | moveToMessageInPage(); |
| 974 | } |
| 975 | |
| 976 | if (fFindCriteria != null) { |
| 977 | find(fFindCriteria); |
| 978 | } |
| 979 | |
| 980 | fView.toggleWaitCursorAsync(false); |
| 981 | } |
| 982 | } finally { |
| 983 | fLock.unlock(); |
| 984 | } |
| 985 | |
| 986 | } |
| 987 | }); |
| 988 | } |
| 989 | } |
| 990 | finally { |
| 991 | fLock.unlock(); |
| 992 | } |
| 993 | } |
| 994 | } |
| 995 | |
| 996 | /** |
| 997 | * Moves to a certain message defined by timestamp (across pages) |
| 998 | */ |
| 999 | protected void moveToMessage() { |
| 1000 | int page = 0; |
| 1001 | |
| 1002 | fLock.lock(); |
| 1003 | try { |
| 1004 | page = getPage(fCurrentTime); |
| 1005 | |
| 1006 | if (page == fCurrentPage) { |
| 1007 | moveToMessageInPage(); |
| 1008 | return; |
| 1009 | } |
| 1010 | fCurrentPage = page; |
| 1011 | moveToPage(false); |
| 1012 | } finally { |
| 1013 | fLock.unlock(); |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | /** |
| 1018 | * Moves to a certain message defined by timestamp in current page |
| 1019 | */ |
| 1020 | protected void moveToMessageInPage() { |
| 1021 | fLock.lock(); |
| 1022 | try { |
| 1023 | if (!fView.getSDWidget().isDisposed()) { |
| 1024 | // Check for GUI thread |
| 1025 | if(Display.getCurrent() != null) { |
| 1026 | // Already in GUI thread - execute directly |
| 1027 | TmfSyncMessage prevMessage = null; |
| 1028 | TmfSyncMessage syncMessage = null; |
| 1029 | boolean isExactTime = false; |
| 1030 | for (int i = 0; i < fFrame.syncMessageCount(); i++) { |
| 1031 | if (fFrame.getSyncMessage(i) instanceof TmfSyncMessage) { |
| 1032 | syncMessage = (TmfSyncMessage) fFrame.getSyncMessage(i); |
| 1033 | if (syncMessage.getStartTime().compareTo(fCurrentTime, false) == 0) { |
| 1034 | isExactTime = true; |
| 1035 | break; |
| 1036 | } else if ((syncMessage.getStartTime().compareTo(fCurrentTime, false) > 0) && (prevMessage != null)) { |
| 1037 | syncMessage = prevMessage; |
| 1038 | break; |
| 1039 | } |
| 1040 | prevMessage = syncMessage; |
| 1041 | } |
| 1042 | } |
| 1043 | if (fIsSelect && isExactTime) { |
| 1044 | fView.getSDWidget().moveTo(syncMessage); |
| 1045 | } |
| 1046 | else { |
| 1047 | fView.getSDWidget().ensureVisible(syncMessage); |
| 1048 | fView.getSDWidget().clearSelection(); |
| 1049 | fView.getSDWidget().redraw(); |
| 1050 | } |
| 1051 | } |
| 1052 | else { |
| 1053 | // Not in GUI thread - queue action in GUI thread. |
| 1054 | fView.getSDWidget().getDisplay().asyncExec(new Runnable() { |
| 1055 | @Override |
| 1056 | public void run() { |
| 1057 | moveToMessageInPage(); |
| 1058 | } |
| 1059 | }); |
| 1060 | } |
| 1061 | } |
| 1062 | } |
| 1063 | finally { |
| 1064 | fLock.unlock(); |
| 1065 | } |
| 1066 | } |
| 1067 | |
| 1068 | /** |
| 1069 | * Moves to a certain message defined by timestamp (across pages) |
| 1070 | */ |
| 1071 | protected void moveToPage() { |
| 1072 | moveToPage(true); |
| 1073 | } |
| 1074 | |
| 1075 | /** |
| 1076 | * Moves to a certain page. |
| 1077 | * |
| 1078 | * @param notifyAll true to broadcast time range signal to other signal handlers else false |
| 1079 | */ |
| 1080 | protected void moveToPage(boolean notifyAll) { |
| 1081 | |
| 1082 | TmfTimeRange window = null; |
| 1083 | |
| 1084 | fLock.lock(); |
| 1085 | try { |
| 1086 | // Safety check |
| 1087 | if (fCurrentPage > fCheckPoints.size()) { |
| 1088 | return; |
| 1089 | } |
| 1090 | window = fCheckPoints.get(fCurrentPage); |
| 1091 | } finally { |
| 1092 | fLock.unlock(); |
| 1093 | } |
| 1094 | |
| 1095 | if (window == null) { |
| 1096 | window = TmfTimeRange.ETERNITY; |
| 1097 | } |
| 1098 | |
| 1099 | fPageRequest = new TmfEventRequest<ITmfEvent>(ITmfEvent.class, window, TmfDataRequest.ALL_DATA, 1, ITmfDataRequest.ExecutionType.FOREGROUND) { |
| 1100 | private final List<ITmfSyncSequenceDiagramEvent> fSdEvent = new ArrayList<ITmfSyncSequenceDiagramEvent>(); |
| 1101 | |
| 1102 | @Override |
| 1103 | public void handleData(ITmfEvent event) { |
| 1104 | super.handleData(event); |
| 1105 | |
| 1106 | ITmfSyncSequenceDiagramEvent sdEvent = getSequnceDiagramEvent(event); |
| 1107 | |
| 1108 | if (sdEvent != null) { |
| 1109 | fSdEvent.add(sdEvent); |
| 1110 | } |
| 1111 | } |
| 1112 | |
| 1113 | @Override |
| 1114 | public void handleSuccess() { |
| 1115 | fillCurrentPage(fSdEvent); |
| 1116 | super.handleSuccess(); |
| 1117 | } |
| 1118 | |
| 1119 | }; |
| 1120 | |
| 1121 | fExperiment.sendRequest(fPageRequest); |
| 1122 | |
| 1123 | if (notifyAll) { |
| 1124 | TmfTimeRange timeRange = getSignalTimeRange(window.getStartTime()); |
| 1125 | broadcast(new TmfRangeSynchSignal(this, timeRange, timeRange.getStartTime())); |
| 1126 | } |
| 1127 | } |
| 1128 | |
| 1129 | /** |
| 1130 | * Gets page that contains timestamp |
| 1131 | * |
| 1132 | * @param time The timestamp |
| 1133 | * @return page that contains the time |
| 1134 | */ |
| 1135 | protected int getPage(ITmfTimestamp time) { |
| 1136 | int page; |
| 1137 | int size; |
| 1138 | fLock.lock(); |
| 1139 | try { |
| 1140 | size = fCheckPoints.size(); |
| 1141 | for (page = 0; page < size; page++) { |
| 1142 | TmfTimeRange timeRange = fCheckPoints.get(page); |
| 1143 | if (timeRange.getEndTime().compareTo(time, false) >= 0) { |
| 1144 | break; |
| 1145 | } |
| 1146 | } |
| 1147 | if (page >= size) { |
| 1148 | page = size - 1; |
| 1149 | } |
| 1150 | return page; |
| 1151 | } finally { |
| 1152 | fLock.unlock(); |
| 1153 | } |
| 1154 | } |
| 1155 | |
| 1156 | /** |
| 1157 | * Background search in trace for expression in criteria. |
| 1158 | * |
| 1159 | * @param findCriteria The find criteria |
| 1160 | * @return true if background request was started else false |
| 1161 | */ |
| 1162 | protected boolean findInNextPages(Criteria findCriteria) { |
| 1163 | fLock.lock(); |
| 1164 | try { |
| 1165 | if (fFindJob != null) { |
| 1166 | return true; |
| 1167 | } |
| 1168 | |
| 1169 | int nextPage = fCurrentPage + 1; |
| 1170 | |
| 1171 | if ((nextPage) >= fCheckPoints.size()) { |
| 1172 | // we are at the end |
| 1173 | return false; |
| 1174 | } |
| 1175 | |
| 1176 | TmfTimeRange window = new TmfTimeRange(fCheckPoints.get(nextPage).getStartTime().clone(), fCheckPoints.get(fCheckPoints.size()-1).getEndTime().clone()); |
| 1177 | fFindJob = new SearchJob(findCriteria, window); |
| 1178 | fFindJob.schedule(); |
| 1179 | fView.toggleWaitCursorAsync(true); |
| 1180 | } finally { |
| 1181 | fLock.unlock(); |
| 1182 | } |
| 1183 | return true; |
| 1184 | } |
| 1185 | |
| 1186 | /** |
| 1187 | * Gets time range for time range signal. |
| 1188 | * |
| 1189 | * @param startTime The start time of time range. |
| 1190 | * @return the time range |
| 1191 | */ |
| 1192 | protected TmfTimeRange getSignalTimeRange(ITmfTimestamp startTime) { |
| 1193 | fLock.lock(); |
| 1194 | try { |
| 1195 | TmfTimestamp initialEndOfWindow = new TmfTimestamp(startTime.getValue() + fInitialWindow, startTime.getScale(), startTime.getPrecision()); |
| 1196 | return new TmfTimeRange(startTime, initialEndOfWindow); |
| 1197 | } |
| 1198 | finally { |
| 1199 | fLock.unlock(); |
| 1200 | } |
| 1201 | } |
| 1202 | |
| 1203 | /** |
| 1204 | * Checks if filter criteria matches the message name in given SD event. |
| 1205 | * |
| 1206 | * @param sdEvent The SD event to check |
| 1207 | * @return true if match else false. |
| 1208 | */ |
| 1209 | protected boolean filterMessage(ITmfSyncSequenceDiagramEvent sdEvent) { |
| 1210 | fLock.lock(); |
| 1211 | try { |
| 1212 | if (fFilterCriteria != null) { |
| 1213 | for(FilterCriteria criteria : fFilterCriteria) { |
| 1214 | if (criteria.isActive() && criteria.getCriteria().isSyncMessageSelected() && criteria.getCriteria().matches(sdEvent.getName())) { |
| 1215 | return true; |
| 1216 | } |
| 1217 | } |
| 1218 | } |
| 1219 | } finally { |
| 1220 | fLock.unlock(); |
| 1221 | } |
| 1222 | return false; |
| 1223 | } |
| 1224 | |
| 1225 | /** |
| 1226 | * Checks if filter criteria matches a lifeline name (sender or receiver) in given SD event. |
| 1227 | * |
| 1228 | * @param lifeline the message receiver |
| 1229 | * @return true if match else false. |
| 1230 | */ |
| 1231 | protected boolean filterLifeLine(String lifeline) { |
| 1232 | fLock.lock(); |
| 1233 | try { |
| 1234 | if (fFilterCriteria != null) { |
| 1235 | for(FilterCriteria criteria : fFilterCriteria) { |
| 1236 | if (criteria.isActive() && criteria.getCriteria().isLifeLineSelected() && criteria.getCriteria().matches(lifeline)) { |
| 1237 | return true; |
| 1238 | } |
| 1239 | } |
| 1240 | } |
| 1241 | } finally { |
| 1242 | fLock.unlock(); |
| 1243 | } |
| 1244 | return false; |
| 1245 | } |
| 1246 | |
| 1247 | /** |
| 1248 | * Job to search in trace for given time range. |
| 1249 | */ |
| 1250 | protected class SearchJob extends Job { |
| 1251 | |
| 1252 | /** |
| 1253 | * The search event request. |
| 1254 | */ |
| 1255 | final protected SearchEventRequest fSearchRequest; |
| 1256 | |
| 1257 | /** |
| 1258 | * Constructor |
| 1259 | * |
| 1260 | * @param findCriteria The search criteria |
| 1261 | * @param window Time range to search in |
| 1262 | */ |
| 1263 | public SearchJob(Criteria findCriteria, TmfTimeRange window) { |
| 1264 | super(Messages.TmfUml2SDSyncLoader_SearchJobDescrition); |
| 1265 | fSearchRequest = new SearchEventRequest(window, TmfDataRequest.ALL_DATA, 1, ITmfDataRequest.ExecutionType.FOREGROUND, findCriteria); |
| 1266 | } |
| 1267 | |
| 1268 | /* |
| 1269 | * (non-Javadoc) |
| 1270 | * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) |
| 1271 | */ |
| 1272 | @Override |
| 1273 | protected IStatus run(IProgressMonitor monitor) { |
| 1274 | fSearchRequest.setMonitor(monitor); |
| 1275 | |
| 1276 | fExperiment.sendRequest(fSearchRequest); |
| 1277 | |
| 1278 | try { |
| 1279 | fSearchRequest.waitForCompletion(); |
| 1280 | } catch (InterruptedException e) { |
| 1281 | Activator.getDefault().logError("Search request interrupted!", e); //$NON-NLS-1$ |
| 1282 | } |
| 1283 | |
| 1284 | IStatus status = Status.OK_STATUS; |
| 1285 | if (fSearchRequest.isFound() && (fSearchRequest.getFoundTime() != null)) { |
| 1286 | fCurrentTime = fSearchRequest.getFoundTime(); |
| 1287 | |
| 1288 | // Avoid double-selection. Selection will be done when calling find(criteria) |
| 1289 | // after moving to relevant page |
| 1290 | fIsSelect = false; |
| 1291 | if (!fView.getSDWidget().isDisposed()) { |
| 1292 | fView.getSDWidget().getDisplay().asyncExec(new Runnable() { |
| 1293 | |
| 1294 | @Override |
| 1295 | public void run() { |
| 1296 | moveToMessage(); |
| 1297 | } |
| 1298 | }); |
| 1299 | } |
| 1300 | } |
| 1301 | else { |
| 1302 | if (monitor.isCanceled()) { |
| 1303 | status = Status.CANCEL_STATUS; |
| 1304 | } |
| 1305 | else { |
| 1306 | // String was not found |
| 1307 | status = new Status(Status.WARNING, Activator.PLUGIN_ID, Messages.TmfUml2SDSyncLoader_SearchNotFound); |
| 1308 | } |
| 1309 | setProperty(IProgressConstants.KEEP_PROPERTY, Boolean.TRUE); |
| 1310 | } |
| 1311 | monitor.done(); |
| 1312 | |
| 1313 | fLock.lock(); |
| 1314 | try { |
| 1315 | fView.toggleWaitCursorAsync(false); |
| 1316 | fFindJob = null; |
| 1317 | } finally { |
| 1318 | fLock.unlock(); |
| 1319 | } |
| 1320 | |
| 1321 | return status; |
| 1322 | } |
| 1323 | |
| 1324 | /* |
| 1325 | * (non-Javadoc) |
| 1326 | * @see org.eclipse.core.runtime.jobs.Job#canceling() |
| 1327 | */ |
| 1328 | @Override |
| 1329 | protected void canceling() { |
| 1330 | fSearchRequest.cancel(); |
| 1331 | fLock.lock(); |
| 1332 | try { |
| 1333 | fFindJob = null; |
| 1334 | } finally { |
| 1335 | fLock.unlock(); |
| 1336 | } |
| 1337 | } |
| 1338 | } |
| 1339 | |
| 1340 | /** |
| 1341 | * TMF event request for searching within trace. |
| 1342 | */ |
| 1343 | protected class SearchEventRequest extends TmfEventRequest<ITmfEvent> { |
| 1344 | |
| 1345 | /** |
| 1346 | * The find criteria. |
| 1347 | */ |
| 1348 | final private Criteria fCriteria; |
| 1349 | /** |
| 1350 | * A progress monitor |
| 1351 | */ |
| 1352 | private IProgressMonitor fMonitor; |
| 1353 | /** |
| 1354 | * Flag to indicate that node was found according the criteria . |
| 1355 | */ |
| 1356 | private boolean fIsFound = false; |
| 1357 | /** |
| 1358 | * Time stamp of found item. |
| 1359 | */ |
| 1360 | private ITmfTimestamp fFoundTime = null; |
| 1361 | |
| 1362 | /** |
| 1363 | * Constructor |
| 1364 | * @param range @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...) |
| 1365 | * @param nbRequested @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...) |
| 1366 | * @param blockSize @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...) |
| 1367 | * @param execType @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...) |
| 1368 | * @param criteria The search criteria |
| 1369 | */ |
| 1370 | public SearchEventRequest(TmfTimeRange range, int nbRequested, int blockSize, ExecutionType execType, Criteria criteria) { |
| 1371 | this(range, nbRequested, blockSize, execType, criteria, null); |
| 1372 | } |
| 1373 | |
| 1374 | /** |
| 1375 | * Constructor |
| 1376 | * @param range @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...) |
| 1377 | * @param nbRequested @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...) |
| 1378 | * @param blockSize @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...) |
| 1379 | * @param execType @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...) |
| 1380 | * @param criteria The search criteria |
| 1381 | * @param monitor progress monitor |
| 1382 | */ |
| 1383 | public SearchEventRequest(TmfTimeRange range, int nbRequested, int blockSize, ExecutionType execType, Criteria criteria, IProgressMonitor monitor) { |
| 1384 | super(ITmfEvent.class, range, nbRequested, blockSize, execType); |
| 1385 | fCriteria = new Criteria(criteria); |
| 1386 | fMonitor = monitor; |
| 1387 | } |
| 1388 | |
| 1389 | /* |
| 1390 | * (non-Javadoc) |
| 1391 | * @see org.eclipse.linuxtools.tmf.request.TmfDataRequest#handleData(org.eclipse.linuxtools.tmf.event.TmfData) |
| 1392 | */ |
| 1393 | @Override |
| 1394 | public void handleData(ITmfEvent event) { |
| 1395 | super.handleData(event); |
| 1396 | |
| 1397 | if ((fMonitor!= null) && fMonitor.isCanceled()) { |
| 1398 | super.cancel(); |
| 1399 | return; |
| 1400 | } |
| 1401 | |
| 1402 | ITmfSyncSequenceDiagramEvent sdEvent = getSequnceDiagramEvent(event); |
| 1403 | |
| 1404 | if (sdEvent != null) { |
| 1405 | |
| 1406 | if (fCriteria.isLifeLineSelected()) { |
| 1407 | if (fCriteria.matches(sdEvent.getSender())) { |
| 1408 | fFoundTime = event.getTimestamp().clone(); |
| 1409 | fIsFound = true; |
| 1410 | super.cancel(); |
| 1411 | } |
| 1412 | |
| 1413 | if (fCriteria.matches(sdEvent.getReceiver())) { |
| 1414 | fFoundTime = event.getTimestamp().clone(); |
| 1415 | fIsFound = true; |
| 1416 | super.cancel(); |
| 1417 | } |
| 1418 | } |
| 1419 | |
| 1420 | if (fCriteria.isSyncMessageSelected() && fCriteria.matches(sdEvent.getName())) { |
| 1421 | fFoundTime = event.getTimestamp().clone(); |
| 1422 | fIsFound = true; |
| 1423 | super.cancel(); |
| 1424 | } |
| 1425 | } |
| 1426 | } |
| 1427 | |
| 1428 | /** |
| 1429 | * Set progress monitor. |
| 1430 | * |
| 1431 | * @param monitor |
| 1432 | */ |
| 1433 | public void setMonitor(IProgressMonitor monitor) { |
| 1434 | fMonitor = monitor; |
| 1435 | } |
| 1436 | |
| 1437 | /** |
| 1438 | * Check if find criteria was met. |
| 1439 | * |
| 1440 | * @return true if find criteria was met. |
| 1441 | */ |
| 1442 | public boolean isFound() { |
| 1443 | return fIsFound; |
| 1444 | } |
| 1445 | |
| 1446 | /** |
| 1447 | * Returns timestamp of found time. |
| 1448 | * |
| 1449 | * @return timestamp of found time. |
| 1450 | */ |
| 1451 | public ITmfTimestamp getFoundTime() { |
| 1452 | return fFoundTime; |
| 1453 | } |
| 1454 | } |
| 1455 | |
| 1456 | /** |
| 1457 | * Job class to provide progress monitor feedback. |
| 1458 | * |
| 1459 | * @version 1.0 |
| 1460 | * @author Bernd Hufmann |
| 1461 | * |
| 1462 | */ |
| 1463 | protected static class IndexingJob extends Job { |
| 1464 | |
| 1465 | public IndexingJob(String name) { |
| 1466 | super(name); |
| 1467 | } |
| 1468 | |
| 1469 | @Override |
| 1470 | protected IStatus run(IProgressMonitor monitor) { |
| 1471 | while (!monitor.isCanceled()) { |
| 1472 | try { |
| 1473 | Thread.sleep(100); |
| 1474 | } catch (InterruptedException e) { |
| 1475 | return Status.OK_STATUS; |
| 1476 | } |
| 1477 | } |
| 1478 | monitor.done(); |
| 1479 | return Status.OK_STATUS; |
| 1480 | } |
| 1481 | } |
| 1482 | |
| 1483 | |
| 1484 | /** |
| 1485 | * Returns sequence diagram event if details in given event are available else null. |
| 1486 | * |
| 1487 | * @param tmfEvent Event to parse for sequence diagram event details |
| 1488 | * @return sequence diagram event if details are available else null |
| 1489 | */ |
| 1490 | protected ITmfSyncSequenceDiagramEvent getSequnceDiagramEvent(ITmfEvent tmfEvent){ |
| 1491 | //type = .*RECEIVE.* or .*SEND.* |
| 1492 | //content = sender:<sender name>:receiver:<receiver name>,signal:<signal name> |
| 1493 | String eventType = tmfEvent.getType().toString(); |
| 1494 | if (eventType.contains(Messages.TmfUml2SDSyncCloader_EventTypeSend) || eventType.contains(Messages.TmfUml2SDSyncCloader_EventTypeReceive)) { |
| 1495 | Object sender = tmfEvent.getContent().getField(Messages.TmfUml2SDSyncCloader_FieldSender); |
| 1496 | Object receiver = tmfEvent.getContent().getField(Messages.TmfUml2SDSyncCloader_FieldReceiver); |
| 1497 | Object name = tmfEvent.getContent().getField(Messages.TmfUml2SDSyncCloader_FieldSignal); |
| 1498 | if ((sender instanceof ITmfEventField) && (receiver instanceof ITmfEventField) && (name instanceof ITmfEventField)) { |
| 1499 | ITmfSyncSequenceDiagramEvent sdEvent = new TmfSyncSequenceDiagramEvent(tmfEvent, |
| 1500 | ((ITmfEventField) sender).getValue().toString(), |
| 1501 | ((ITmfEventField) receiver).getValue().toString(), |
| 1502 | ((ITmfEventField) name).getValue().toString()); |
| 1503 | |
| 1504 | return sdEvent; |
| 1505 | } |
| 1506 | } |
| 1507 | return null; |
| 1508 | } |
| 1509 | } |