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.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.TmfEvent;
21
import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
22
import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
23
import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
24
import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
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" })
35
public class TmfSyntheticEventProviderStub extends TmfEventProvider<TmfSyntheticEventStub> {
37
public static final int BLOCK_SIZE = 100;
38
public static final int NB_EVENTS = 1000;
40
public TmfSyntheticEventProviderStub() {
41
super("TmfSyntheticEventProviderStub", TmfSyntheticEventStub.class);
44
@SuppressWarnings("unchecked")
46
public ITmfContext armRequest(final ITmfDataRequest<TmfSyntheticEventStub> request) {
48
// Get the TmfSyntheticEventStub provider
49
final ITmfDataProvider<TmfEvent>[] eventProviders = (ITmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class, TmfEventProviderStub.class);
50
final ITmfDataProvider<TmfEvent> provider = eventProviders[0];
52
// make sure we have the right type of request
53
if (!(request instanceof ITmfEventRequest<?>)) {
58
final TmfEventRequest<TmfSyntheticEventStub> eventRequest = (TmfEventRequest<TmfSyntheticEventStub>) request;
59
final TmfTimeRange range = eventRequest.getRange();
60
final TmfEventRequest<TmfEvent> subRequest =
61
new TmfEventRequest<TmfEvent>(TmfEvent.class, range, NB_EVENTS, BLOCK_SIZE) {
63
public void handleData(final TmfEvent event) {
64
super.handleData(event);
66
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 TmfEvent 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 = fDataQueue.poll(TIMEOUT, TimeUnit.MILLISECONDS);
91
throw new InterruptedException();
93
catch (final InterruptedException e) {
98
public void queueResult(final TmfSyntheticEventStub data) {
101
ok = fDataQueue.offer(data, TIMEOUT, TimeUnit.MILLISECONDS);
103
throw new InterruptedException();
105
catch (final InterruptedException e) {