tmf.core: Introduce TmfTimestamp factory methods
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core.tests / stubs / org / eclipse / tracecompass / tmf / tests / stubs / component / TmfSyntheticEventProviderStub.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2014 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.tracecompass.tmf.tests.stubs.component;
14
15 import java.util.concurrent.BlockingQueue;
16 import java.util.concurrent.LinkedBlockingQueue;
17 import java.util.concurrent.TimeUnit;
18
19 import org.eclipse.jdt.annotation.NonNull;
20 import org.eclipse.tracecompass.internal.tmf.core.component.TmfProviderManager;
21 import org.eclipse.tracecompass.tmf.core.component.ITmfEventProvider;
22 import org.eclipse.tracecompass.tmf.core.component.TmfEventProvider;
23 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
24 import org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest;
25 import org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest.ExecutionType;
26 import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest;
27 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
28 import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
29 import org.eclipse.tracecompass.tmf.core.trace.TmfContext;
30 import org.eclipse.tracecompass.tmf.tests.stubs.event.TmfSyntheticEventStub;
31
32 /**
33 * <b><u>TmfSyntheticEventProviderStub</u></b>
34 * <p>
35 * TODO: Implement me. Please.
36 */
37 @SuppressWarnings("javadoc")
38 public class TmfSyntheticEventProviderStub extends TmfEventProvider {
39
40 public static final int NB_EVENTS = 1000;
41
42 private final BlockingQueue<ITmfEvent> fDataQueue = new LinkedBlockingQueue<>(1000);
43
44 public TmfSyntheticEventProviderStub() {
45 super("TmfSyntheticEventProviderStub", TmfSyntheticEventStub.class);
46 }
47
48 @Override
49 public ITmfContext armRequest(final ITmfEventRequest request) {
50
51 // Get the TmfSyntheticEventStub provider
52 final ITmfEventProvider[] eventProviders = TmfProviderManager.getProviders(ITmfEvent.class, TmfEventProviderStub.class);
53 final ITmfEventProvider provider = eventProviders[0];
54
55 final TmfTimeRange range = request.getRange();
56 final TmfEventRequest subRequest =
57 new TmfEventRequest(ITmfEvent.class, range, 0, NB_EVENTS, ExecutionType.FOREGROUND) {
58 @Override
59 public void handleData(final ITmfEvent event) {
60 super.handleData(event);
61 handleIncomingData(event);
62 }
63 };
64 provider.sendRequest(subRequest);
65
66 // Return a dummy context
67 return new TmfContext();
68 }
69
70 // Queue 2 synthetic events per base event
71 private void handleIncomingData(final @NonNull ITmfEvent e) {
72 queueResult(new TmfSyntheticEventStub(e));
73 queueResult(new TmfSyntheticEventStub(e));
74 }
75
76 private static final int TIMEOUT = 10000;
77
78 @Override
79 public TmfSyntheticEventStub getNext(final ITmfContext context) {
80 TmfSyntheticEventStub data = null;
81 try {
82 data = (TmfSyntheticEventStub) fDataQueue.poll(TIMEOUT, TimeUnit.MILLISECONDS);
83 if (data == null) {
84 throw new InterruptedException();
85 }
86 }
87 catch (final InterruptedException e) {
88 }
89 return data;
90 }
91
92 public void queueResult(final TmfSyntheticEventStub data) {
93 boolean ok = false;
94 try {
95 ok = fDataQueue.offer(data, TIMEOUT, TimeUnit.MILLISECONDS);
96 if (!ok) {
97 throw new InterruptedException();
98 }
99 }
100 catch (final InterruptedException e) {
101 }
102 }
103
104 }
This page took 0.034026 seconds and 5 git commands to generate.