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 public class TmfSyntheticEventProviderStub
extends TmfEventProvider
<TmfSyntheticEventStub
> {
33 public static final int BLOCK_SIZE
= 100;
34 public static final int NB_EVENTS
= 1000;
36 public TmfSyntheticEventProviderStub() {
37 super("TmfSyntheticEventProviderStub", TmfSyntheticEventStub
.class);
40 @SuppressWarnings("unchecked")
42 public ITmfContext
armRequest(final ITmfDataRequest
<TmfSyntheticEventStub
> request
) {
44 // Get the TmfSyntheticEventStub provider
45 ITmfDataProvider
<TmfEvent
>[] eventProviders
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfEventProviderStub
.class);
46 ITmfDataProvider
<TmfEvent
> provider
= eventProviders
[0];
48 // make sure we have the right type of request
49 if (!(request
instanceof ITmfEventRequest
<?
>)) {
54 TmfEventRequest
<TmfSyntheticEventStub
> eventRequest
= (TmfEventRequest
<TmfSyntheticEventStub
>) request
;
55 TmfTimeRange range
= eventRequest
.getRange();
56 final TmfEventRequest
<TmfEvent
> subRequest
=
57 new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, BLOCK_SIZE
) {
59 public void handleData() {
60 TmfEvent
[] events
= getData();
61 if (events
.length
> 0) {
62 for (TmfEvent e
: events
) {
63 handleIncomingData(e
);
70 provider
.sendRequest(subRequest
);
72 // Return a dummy context
73 return new TmfContext();
76 // Queue 2 synthetic events per base event
77 private void handleIncomingData(TmfEvent e
) {
78 queueResult(new TmfSyntheticEventStub(e
));
79 queueResult(new TmfSyntheticEventStub(e
));
82 private static final int TIMEOUT
= 10000;
85 public TmfSyntheticEventStub
getNext(ITmfContext context
) {
86 TmfSyntheticEventStub data
= null;
88 data
= fDataQueue
.poll(TIMEOUT
, TimeUnit
.MILLISECONDS
);
90 throw new InterruptedException();
93 catch (InterruptedException e
) {
98 public void queueResult(TmfSyntheticEventStub data
) {
101 ok
= fDataQueue
.offer(data
, TIMEOUT
, TimeUnit
.MILLISECONDS
);
103 throw new InterruptedException();
106 catch (InterruptedException e
) {