1 /*******************************************************************************
2 * Copyright (c) 2009, 2014 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.tests
.stubs
.component
;
15 import java
.util
.concurrent
.BlockingQueue
;
16 import java
.util
.concurrent
.LinkedBlockingQueue
;
17 import java
.util
.concurrent
.TimeUnit
;
19 import org
.eclipse
.jdt
.annotation
.NonNull
;
20 import org
.eclipse
.tracecompass
.internal
.tmf
.core
.component
.TmfProviderManager
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.component
.ITmfEventProvider
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.component
.TmfEventProvider
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.request
.ITmfEventRequest
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.request
.ITmfEventRequest
.ExecutionType
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.request
.TmfEventRequest
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfContext
;
29 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfContext
;
30 import org
.eclipse
.tracecompass
.tmf
.tests
.stubs
.event
.TmfSyntheticEventStub
;
33 * <b><u>TmfSyntheticEventProviderStub</u></b>
35 * TODO: Implement me. Please.
37 @SuppressWarnings("javadoc")
38 public class TmfSyntheticEventProviderStub
extends TmfEventProvider
{
40 public static final int NB_EVENTS
= 1000;
42 private final BlockingQueue
<ITmfEvent
> fDataQueue
= new LinkedBlockingQueue
<>(1000);
44 public TmfSyntheticEventProviderStub() {
45 super("TmfSyntheticEventProviderStub", TmfSyntheticEventStub
.class);
49 public ITmfContext
armRequest(final ITmfEventRequest request
) {
51 // Get the TmfSyntheticEventStub provider
52 final ITmfEventProvider
[] eventProviders
= TmfProviderManager
.getProviders(ITmfEvent
.class, TmfEventProviderStub
.class);
53 final ITmfEventProvider provider
= eventProviders
[0];
55 final TmfTimeRange range
= request
.getRange();
56 final TmfEventRequest subRequest
=
57 new TmfEventRequest(ITmfEvent
.class, range
, 0, NB_EVENTS
, ExecutionType
.FOREGROUND
) {
59 public void handleData(final ITmfEvent event
) {
60 super.handleData(event
);
61 handleIncomingData(event
);
64 provider
.sendRequest(subRequest
);
66 // Return a dummy context
67 return new TmfContext();
70 // Queue 2 synthetic events per base event
71 private void handleIncomingData(final @NonNull ITmfEvent e
) {
72 queueResult(new TmfSyntheticEventStub(e
));
73 queueResult(new TmfSyntheticEventStub(e
));
76 private static final int TIMEOUT
= 10000;
79 public TmfSyntheticEventStub
getNext(final ITmfContext context
) {
80 TmfSyntheticEventStub data
= null;
82 data
= (TmfSyntheticEventStub
) fDataQueue
.poll(TIMEOUT
, TimeUnit
.MILLISECONDS
);
84 throw new InterruptedException();
87 catch (final InterruptedException e
) {
92 public void queueResult(final TmfSyntheticEventStub data
) {
95 ok
= fDataQueue
.offer(data
, TIMEOUT
, TimeUnit
.MILLISECONDS
);
97 throw new InterruptedException();
100 catch (final InterruptedException e
) {