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