1 /*******************************************************************************
2 * Copyright (c) 2009 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 (fchouinard@gmail.com) - Initial API and implementation
11 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.eventlog
;
16 import java
.io
.FileNotFoundException
;
17 import java
.io
.IOException
;
18 import java
.util
.Vector
;
20 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEvent
;
21 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimestamp
;
24 * <b><u>TmfRequestHandlerStub</u></b>
26 * TODO: Implement me. Please.
28 public class TmfRequestHandlerStub
implements ITmfRequestHandler
{
31 String filename
= "Test-100K";
33 // A constant to limit the number of events for the tests
34 public static final int MAX_GENERATED_EVENTS
= 1000;
36 private ITmfEventParser fParser
;
37 private TmfEventStreamStub fStream
;
39 public TmfRequestHandlerStub() throws FileNotFoundException
{
40 fParser
= new TmfEventParserStub();
41 fStream
= new TmfEventStreamStub(filename
, fParser
);
45 * @see org.eclipse.linuxtools.tmf.eventlog.ITmfRequestHandler#processRequest(org.eclipse.linuxtools.tmf.eventlog.TmfEventRequest, boolean)
47 public void process(final TmfEventRequest request
, boolean waitForCompletion
) {
49 Thread thread
= new Thread() {
52 TmfTimestamp startTime
= request
.getRange().getStartTime();
53 TmfTimestamp endTime
= request
.getRange().getEndTime();
54 int blockSize
= request
.getBlockize();
56 int nbRequestedEvents
= request
.getNbRequestedEvents();
57 if (nbRequestedEvents
<= 0) {
58 nbRequestedEvents
= MAX_GENERATED_EVENTS
;
61 Vector
<TmfEvent
> events
= new Vector
<TmfEvent
>();
64 TmfEvent event
= fStream
.seek(startTime
);
65 while (!request
.isCancelled() && nbEvents
< nbRequestedEvents
&&
66 event
!= null && event
.getTimestamp().compareTo(endTime
, false) <= 0 )
69 if (++nbEvents
% blockSize
== 0) {
70 request
.newEvents(events
);
71 events
.removeAllElements();
73 event
= fStream
.getNextEvent();
75 request
.newEvents(events
);
77 } catch (IOException e
) {
78 // TODO Auto-generated catch block
85 if (waitForCompletion
) {
86 request
.waitForCompletion();