1 /*******************************************************************************
2 * Copyright (c) 2009, 2013 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
.linuxtools
.tmf
.tests
.stubs
.component
;
15 import java
.util
.concurrent
.TimeUnit
;
17 import org
.eclipse
.linuxtools
.internal
.tmf
.core
.component
.TmfProviderManager
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.component
.ITmfDataProvider
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.component
.TmfEventProvider
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.request
.ITmfDataRequest
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.request
.ITmfEventRequest
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfEventRequest
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimeRange
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfContext
;
27 import org
.eclipse
.linuxtools
.tmf
.tests
.stubs
.event
.TmfSyntheticEventStub
;
30 * <b><u>TmfSyntheticEventProviderStub</u></b>
32 * TODO: Implement me. Please.
34 @SuppressWarnings({"nls","javadoc"})
35 public class TmfSyntheticEventProviderStub
extends TmfEventProvider
{
37 public static final int BLOCK_SIZE
= 100;
38 public static final int NB_EVENTS
= 1000;
40 public TmfSyntheticEventProviderStub() {
41 super("TmfSyntheticEventProviderStub", TmfSyntheticEventStub
.class);
45 public ITmfContext
armRequest(final ITmfDataRequest request
) {
47 // Get the TmfSyntheticEventStub provider
48 final ITmfDataProvider
[] eventProviders
= TmfProviderManager
.getProviders(ITmfEvent
.class, TmfEventProviderStub
.class);
49 final ITmfDataProvider provider
= eventProviders
[0];
51 // make sure we have the right type of request
52 if (!(request
instanceof ITmfEventRequest
)) {
57 final TmfEventRequest eventRequest
= (TmfEventRequest
) request
;
58 final TmfTimeRange range
= eventRequest
.getRange();
59 final TmfEventRequest subRequest
=
60 new TmfEventRequest(ITmfEvent
.class, range
, NB_EVENTS
, BLOCK_SIZE
) {
62 public void handleData(final ITmfEvent event
) {
63 super.handleData(event
);
65 handleIncomingData(event
);
71 provider
.sendRequest(subRequest
);
73 // Return a dummy context
74 return new TmfContext();
77 // Queue 2 synthetic events per base event
78 private void handleIncomingData(final ITmfEvent e
) {
79 queueResult(new TmfSyntheticEventStub(e
));
80 queueResult(new TmfSyntheticEventStub(e
));
83 private static final int TIMEOUT
= 10000;
86 public TmfSyntheticEventStub
getNext(final ITmfContext context
) {
87 TmfSyntheticEventStub data
= null;
89 data
= (TmfSyntheticEventStub
) fDataQueue
.poll(TIMEOUT
, TimeUnit
.MILLISECONDS
);
91 throw new InterruptedException();
94 catch (final InterruptedException e
) {
99 public void queueResult(final TmfSyntheticEventStub data
) {
102 ok
= fDataQueue
.offer(data
, TIMEOUT
, TimeUnit
.MILLISECONDS
);
104 throw new InterruptedException();
107 catch (final InterruptedException e
) {