[Bug292967] Second part of request coalescing + unit tests + minor fixes.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.tests / stubs / org / eclipse / linuxtools / tmf / component / TmfSyntheticEventProviderStub.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 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.component;
14
15 import org.eclipse.linuxtools.tmf.event.TmfEvent;
16 import org.eclipse.linuxtools.tmf.event.TmfSyntheticEventStub;
17 import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
18 import org.eclipse.linuxtools.tmf.request.TmfDataRequest;
19 import org.eclipse.linuxtools.tmf.request.TmfEventRequest;
20 import org.eclipse.linuxtools.tmf.trace.ITmfContext;
21 import org.eclipse.linuxtools.tmf.trace.TmfContext;
22
23 /**
24 * <b><u>TmfSyntheticEventProviderStub</u></b>
25 * <p>
26 * TODO: Implement me. Please.
27 */
28 public class TmfSyntheticEventProviderStub extends TmfEventProvider<TmfSyntheticEventStub> {
29
30 public static final int BLOCK_SIZE = 100;
31 public static final int NB_EVENTS = 1000;
32
33 public TmfSyntheticEventProviderStub() {
34 super(TmfSyntheticEventStub.class);
35 }
36
37 @SuppressWarnings("unchecked")
38 @Override
39 public ITmfContext armRequest(final TmfDataRequest<TmfSyntheticEventStub> request) {
40
41 // Get the TmfSyntheticEventStub provider
42 ITmfDataProvider<TmfEvent>[] eventProviders = (ITmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class, TmfEventProviderStub.class);
43 ITmfDataProvider<TmfEvent> provider = eventProviders[0];
44
45 // make sure we have the right type of request
46 if (!(request instanceof TmfEventRequest<?>)) {
47 request.cancel();
48 return null;
49 }
50
51 TmfEventRequest<TmfSyntheticEventStub> eventRequest = (TmfEventRequest<TmfSyntheticEventStub>) request;
52 TmfTimeRange range = eventRequest.getRange();
53 final TmfEventRequest<TmfEvent> subRequest =
54 new TmfEventRequest<TmfEvent>(TmfEvent.class, range, NB_EVENTS, BLOCK_SIZE) {
55 @Override
56 public void handleData() {
57 TmfEvent[] events = getData();
58 if (events.length > 0) {
59 for (TmfEvent e : events) {
60 handleIncomingData(e);
61 }
62 } else {
63 request.done();
64 }
65 }
66 };
67 provider.sendRequest(subRequest); // , false);
68
69 // Return a dummy context
70 return new TmfContext();
71 }
72
73 // Queue 2 synthetic events per base event
74 private void handleIncomingData(TmfEvent e) {
75 queueResult(new TmfSyntheticEventStub(e));
76 queueResult(new TmfSyntheticEventStub(e));
77 }
78
79 }
This page took 0.031035 seconds and 5 git commands to generate.