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
.TmfTraceContext
;
22 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfTraceStub
;
25 * <b><u>TmfRequestHandlerStub</u></b>
27 * TODO: Implement me. Please.
29 public class TmfRequestHandlerStub
implements ITmfRequestHandler
<TmfEvent
> {
32 private static final String TEST_STREAM
= "M-Test-100K";
34 // A constant to limit the number of events for the tests
35 public static final int MAX_GENERATED_EVENTS
= 1000;
37 private TmfTraceStub fTrace
;
39 public TmfRequestHandlerStub() throws IOException
{
40 String directory
= new File(".").getCanonicalPath() + File
.separator
+ "testfiles";
41 String filename
= directory
+ File
.separator
+ TEST_STREAM
;
42 fTrace
= new TmfTraceStub(filename
);
46 * @see org.eclipse.linuxtools.tmf.eventlog.ITmfRequestHandler#processRequest(org.eclipse.linuxtools.tmf.eventlog.TmfEventRequest, boolean)
48 public void processRequest(final TmfDataRequest
<TmfEvent
> request
, boolean waitForCompletion
) {
50 Thread thread
= new Thread() {
53 TmfTimestamp startTime
= request
.getRange().getStartTime();
54 TmfTimestamp endTime
= request
.getRange().getEndTime();
55 int blockSize
= request
.getBlockize();
57 int nbRequestedEvents
= request
.getNbRequestedItems();
58 if (nbRequestedEvents
<= 0) {
59 nbRequestedEvents
= MAX_GENERATED_EVENTS
;
62 Vector
<TmfEvent
> events
= new Vector
<TmfEvent
>();
64 TmfTraceContext context
= fTrace
.seekEvent(startTime
);
65 TmfEvent event
= fTrace
.getNextEvent(context
);
66 while (!request
.isCancelled() && nbEvents
< nbRequestedEvents
&&
67 event
!= null && event
.getTimestamp().compareTo(endTime
, false) <= 0 )
70 if (++nbEvents
% blockSize
== 0) {
71 TmfEvent
[] result
= new TmfEvent
[events
.size()];
72 events
.toArray(result
);
73 request
.setData(result
);
75 events
.removeAllElements();
77 event
= fTrace
.getNextEvent(context
);
79 TmfEvent
[] result
= new TmfEvent
[events
.size()];
80 events
.toArray(result
);
82 request
.setData(result
);
89 if (waitForCompletion
) {
90 request
.waitForCompletion();
This page took 0.039936 seconds and 5 git commands to generate.