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 - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.request
;
16 import java
.io
.IOException
;
17 import java
.util
.Vector
;
19 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEvent
;
20 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimestamp
;
21 import org
.eclipse
.linuxtools
.tmf
.trace
.ITmfEventParser
;
22 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfEventParserStub
;
23 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfEventStreamStub
;
24 import org
.eclipse
.linuxtools
.tmf
.trace
.ITmfTrace
.StreamContext
;
27 * <b><u>TmfRequestHandlerStub</u></b>
29 * TODO: Implement me. Please.
31 public class TmfRequestHandlerStub
implements ITmfRequestHandler
<TmfEvent
> {
34 private static final String TEST_STREAM
= "M-Test-100K";
36 // A constant to limit the number of events for the tests
37 public static final int MAX_GENERATED_EVENTS
= 1000;
39 private ITmfEventParser fParser
;
40 private TmfEventStreamStub fStream
;
42 public TmfRequestHandlerStub() throws IOException
{
43 String directory
= new File(".").getCanonicalPath() + File
.separator
+ "testfiles";
44 String filename
= directory
+ File
.separator
+ TEST_STREAM
;
46 fParser
= new TmfEventParserStub();
47 fStream
= new TmfEventStreamStub(filename
, fParser
);
51 * @see org.eclipse.linuxtools.tmf.eventlog.ITmfRequestHandler#processRequest(org.eclipse.linuxtools.tmf.eventlog.TmfEventRequest, boolean)
53 public void processRequest(final TmfDataRequest
<TmfEvent
> request
, boolean waitForCompletion
) {
55 Thread thread
= new Thread() {
58 TmfTimestamp startTime
= request
.getRange().getStartTime();
59 TmfTimestamp endTime
= request
.getRange().getEndTime();
60 int blockSize
= request
.getBlockize();
62 int nbRequestedEvents
= request
.getNbRequestedItems();
63 if (nbRequestedEvents
<= 0) {
64 nbRequestedEvents
= MAX_GENERATED_EVENTS
;
67 Vector
<TmfEvent
> events
= new Vector
<TmfEvent
>();
69 StreamContext context
= new StreamContext(null);
70 TmfEvent event
= fStream
.getEvent(context
, startTime
);
71 while (!request
.isCancelled() && nbEvents
< nbRequestedEvents
&&
72 event
!= null && event
.getTimestamp().compareTo(endTime
, false) <= 0 )
75 if (++nbEvents
% blockSize
== 0) {
76 TmfEvent
[] result
= new TmfEvent
[events
.size()];
77 events
.toArray(result
);
78 request
.setData(result
);
80 events
.removeAllElements();
82 event
= fStream
.getNextEvent(context
);
84 TmfEvent
[] result
= new TmfEvent
[events
.size()];
85 events
.toArray(result
);
87 request
.setData(result
);
94 if (waitForCompletion
) {
95 request
.waitForCompletion();