1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 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
.component
;
15 import java
.util
.concurrent
.TimeUnit
;
17 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEvent
;
18 import org
.eclipse
.linuxtools
.tmf
.event
.TmfSyntheticEventStub
;
19 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimeRange
;
20 import org
.eclipse
.linuxtools
.tmf
.request
.ITmfDataRequest
;
21 import org
.eclipse
.linuxtools
.tmf
.request
.ITmfEventRequest
;
22 import org
.eclipse
.linuxtools
.tmf
.request
.TmfEventRequest
;
23 import org
.eclipse
.linuxtools
.tmf
.trace
.ITmfContext
;
24 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfContext
;
27 * <b><u>TmfSyntheticEventProviderStub</u></b>
29 * TODO: Implement me. Please.
31 @SuppressWarnings("nls")
32 public class TmfSyntheticEventProviderStub
extends TmfEventProvider
<TmfSyntheticEventStub
> {
34 public static final int BLOCK_SIZE
= 100;
35 public static final int NB_EVENTS
= 1000;
37 public TmfSyntheticEventProviderStub() {
38 super("TmfSyntheticEventProviderStub", TmfSyntheticEventStub
.class);
41 @SuppressWarnings("unchecked")
43 public ITmfContext
armRequest(final ITmfDataRequest
<TmfSyntheticEventStub
> request
) {
45 // Get the TmfSyntheticEventStub provider
46 ITmfDataProvider
<TmfEvent
>[] eventProviders
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfEventProviderStub
.class);
47 ITmfDataProvider
<TmfEvent
> provider
= eventProviders
[0];
49 // make sure we have the right type of request
50 if (!(request
instanceof ITmfEventRequest
<?
>)) {
55 TmfEventRequest
<TmfSyntheticEventStub
> eventRequest
= (TmfEventRequest
<TmfSyntheticEventStub
>) request
;
56 TmfTimeRange range
= eventRequest
.getRange();
57 final TmfEventRequest
<TmfEvent
> subRequest
=
58 new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, BLOCK_SIZE
) {
60 public void handleData(TmfEvent event
) {
61 super.handleData(event
);
63 handleIncomingData(event
);
68 provider
.sendRequest(subRequest
);
70 // Return a dummy context
71 return new TmfContext();
74 // Queue 2 synthetic events per base event
75 private void handleIncomingData(TmfEvent e
) {
76 queueResult(new TmfSyntheticEventStub(e
));
77 queueResult(new TmfSyntheticEventStub(e
));
80 private static final int TIMEOUT
= 10000;
83 public TmfSyntheticEventStub
getNext(ITmfContext context
) {
84 TmfSyntheticEventStub data
= null;
86 data
= fDataQueue
.poll(TIMEOUT
, TimeUnit
.MILLISECONDS
);
88 throw new InterruptedException();
91 catch (InterruptedException e
) {
96 public void queueResult(TmfSyntheticEventStub data
) {
99 ok
= fDataQueue
.offer(data
, TIMEOUT
, TimeUnit
.MILLISECONDS
);
101 throw new InterruptedException();
104 catch (InterruptedException e
) {