ctf: Update paths in the CTF-Testsuite tests
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / stubs / org / eclipse / linuxtools / tmf / tests / stubs / component / TmfSyntheticEventProviderStub.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2013 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.tests.stubs.component;
14
15 import java.util.concurrent.TimeUnit;
16
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.request.ITmfDataRequest.ExecutionType;
25 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
26 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
27 import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
28 import org.eclipse.linuxtools.tmf.tests.stubs.event.TmfSyntheticEventStub;
29
30 /**
31 * <b><u>TmfSyntheticEventProviderStub</u></b>
32 * <p>
33 * TODO: Implement me. Please.
34 */
35 @SuppressWarnings("javadoc")
36 public class TmfSyntheticEventProviderStub extends TmfEventProvider {
37
38 public static final int NB_EVENTS = 1000;
39
40 public TmfSyntheticEventProviderStub() {
41 super("TmfSyntheticEventProviderStub", TmfSyntheticEventStub.class);
42 }
43
44 @Override
45 public ITmfContext armRequest(final ITmfDataRequest request) {
46
47 // Get the TmfSyntheticEventStub provider
48 final ITmfDataProvider[] eventProviders = TmfProviderManager.getProviders(ITmfEvent.class, TmfEventProviderStub.class);
49 final ITmfDataProvider provider = eventProviders[0];
50
51 // make sure we have the right type of request
52 if (!(request instanceof ITmfEventRequest)) {
53 request.cancel();
54 return null;
55 }
56
57 final TmfEventRequest eventRequest = (TmfEventRequest) request;
58 final TmfTimeRange range = eventRequest.getRange();
59 final TmfEventRequest subRequest =
60 new TmfEventRequest(ITmfEvent.class, range, 0, NB_EVENTS, ExecutionType.FOREGROUND) {
61 @Override
62 public void handleData(final ITmfEvent event) {
63 super.handleData(event);
64 if (event != null) {
65 handleIncomingData(event);
66 } else {
67 request.done();
68 }
69 }
70 };
71 provider.sendRequest(subRequest);
72
73 // Return a dummy context
74 return new TmfContext();
75 }
76
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));
81 }
82
83 private static final int TIMEOUT = 10000;
84
85 @Override
86 public TmfSyntheticEventStub getNext(final ITmfContext context) {
87 TmfSyntheticEventStub data = null;
88 try {
89 data = (TmfSyntheticEventStub) fDataQueue.poll(TIMEOUT, TimeUnit.MILLISECONDS);
90 if (data == null) {
91 throw new InterruptedException();
92 }
93 }
94 catch (final InterruptedException e) {
95 }
96 return data;
97 }
98
99 public void queueResult(final TmfSyntheticEventStub data) {
100 boolean ok = false;
101 try {
102 ok = fDataQueue.offer(data, TIMEOUT, TimeUnit.MILLISECONDS);
103 if (!ok) {
104 throw new InterruptedException();
105 }
106 }
107 catch (final InterruptedException e) {
108 }
109 }
110
111 }
This page took 0.035424 seconds and 6 git commands to generate.