Renamed the bundle class.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.tests / stubs / org / eclipse / linuxtools / tmf / eventlog / TmfRequestHandlerStub.java
1 /*******************************************************************************
2 * Copyright (c) 2009 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 (fchouinard@gmail.com) - Initial API and implementation
11 *******************************************************************************/
12
13
14 package org.eclipse.linuxtools.tmf.eventlog;
15
16 import java.io.FileNotFoundException;
17 import java.io.IOException;
18 import java.util.Vector;
19
20 import org.eclipse.linuxtools.tmf.event.TmfEvent;
21 import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
22
23 /**
24 * <b><u>TmfRequestHandlerStub</u></b>
25 * <p>
26 * TODO: Implement me. Please.
27 */
28 public class TmfRequestHandlerStub implements ITmfRequestHandler {
29
30 // The test file
31 String filename = "Test-100K";
32
33 // A constant to limit the number of events for the tests
34 public static final int MAX_GENERATED_EVENTS = 1000;
35
36 private ITmfEventParser fParser;
37 private TmfEventStreamStub fStream;
38
39 public TmfRequestHandlerStub() throws FileNotFoundException {
40 fParser = new TmfEventParserStub();
41 fStream = new TmfEventStreamStub(filename, fParser);
42 }
43
44 /* (non-Javadoc)
45 * @see org.eclipse.linuxtools.tmf.eventlog.ITmfRequestHandler#processRequest(org.eclipse.linuxtools.tmf.eventlog.TmfEventRequest, boolean)
46 */
47 public void process(final TmfEventRequest request, boolean waitForCompletion) {
48
49 Thread thread = new Thread() {
50 @Override
51 public void run() {
52 TmfTimestamp startTime = request.getRange().getStartTime();
53 TmfTimestamp endTime = request.getRange().getEndTime();
54 int blockSize = request.getBlockize();
55
56 int nbRequestedEvents = request.getNbRequestedEvents();
57 if (nbRequestedEvents <= 0) {
58 nbRequestedEvents = MAX_GENERATED_EVENTS;
59 }
60
61 Vector<TmfEvent> events = new Vector<TmfEvent>();
62 int nbEvents = 0;
63 try {
64 TmfEvent event = fStream.seek(startTime);
65 while (!request.isCancelled() && nbEvents < nbRequestedEvents &&
66 event != null && event.getTimestamp().compareTo(endTime, false) <= 0 )
67 {
68 events.add(event);
69 if (++nbEvents % blockSize == 0) {
70 request.newEvents(events);
71 events.removeAllElements();
72 }
73 event = fStream.getNextEvent();
74 }
75 request.newEvents(events);
76 request.done();
77 } catch (IOException e) {
78 // TODO Auto-generated catch block
79 e.printStackTrace();
80 }
81 }
82 };
83 thread.start();
84
85 if (waitForCompletion) {
86 request.waitForCompletion();
87 }
88 }
89
90 }
This page took 0.031226 seconds and 5 git commands to generate.