1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 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
.experiment
;
15 import java
.util
.Collections
;
16 import java
.util
.Vector
;
18 import org
.eclipse
.linuxtools
.tmf
.component
.TmfEventProvider
;
19 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEvent
;
20 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimeRange
;
21 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimestamp
;
22 import org
.eclipse
.linuxtools
.tmf
.request
.ITmfDataRequest
;
23 import org
.eclipse
.linuxtools
.tmf
.request
.ITmfDataRequest
.ExecutionType
;
24 import org
.eclipse
.linuxtools
.tmf
.request
.ITmfEventRequest
;
25 import org
.eclipse
.linuxtools
.tmf
.request
.TmfDataRequest
;
26 import org
.eclipse
.linuxtools
.tmf
.request
.TmfEventRequest
;
27 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfExperimentSelectedSignal
;
28 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfExperimentUpdatedSignal
;
29 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfSignalHandler
;
30 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfSignalManager
;
31 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfTraceUpdatedSignal
;
32 import org
.eclipse
.linuxtools
.tmf
.trace
.ITmfContext
;
33 import org
.eclipse
.linuxtools
.tmf
.trace
.ITmfLocation
;
34 import org
.eclipse
.linuxtools
.tmf
.trace
.ITmfTrace
;
35 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfCheckpoint
;
36 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfContext
;
39 * <b><u>TmfExperiment</u></b>
41 * TmfExperiment presents a time-ordered, unified view of a set of TmfTraces
42 * that are part of a tracing experiment.
45 public class TmfExperiment
<T
extends TmfEvent
> extends TmfEventProvider
<T
> implements ITmfTrace
{
47 // ------------------------------------------------------------------------
49 // ------------------------------------------------------------------------
51 // The currently selected experiment
52 protected static TmfExperiment
<?
> fCurrentExperiment
= null;
54 // The set of traces that constitute the experiment
55 protected ITmfTrace
[] fTraces
;
57 // The total number of events
58 protected long fNbEvents
;
60 // The experiment time range
61 protected TmfTimeRange fTimeRange
;
63 // The experiment reference timestamp (default: Zero)
64 protected TmfTimestamp fEpoch
;
66 // The experiment index
67 protected Vector
<TmfCheckpoint
> fCheckpoints
= new Vector
<TmfCheckpoint
>();
69 // The current experiment context
70 protected TmfExperimentContext fExperimentContext
;
72 // ------------------------------------------------------------------------
74 // ------------------------------------------------------------------------
81 * @param indexPageSize
83 public TmfExperiment(Class
<T
> type
, String id
, ITmfTrace
[] traces
, TmfTimestamp epoch
, int indexPageSize
) {
84 this(type
, id
, traces
, TmfTimestamp
.Zero
, indexPageSize
, false);
87 public TmfExperiment(Class
<T
> type
, String id
, ITmfTrace
[] traces
, TmfTimestamp epoch
, int indexPageSize
, boolean preIndexExperiment
) {
92 fIndexPageSize
= indexPageSize
;
94 if (preIndexExperiment
) indexExperiment(true);
99 protected TmfExperiment(String id
, Class
<T
> type
) {
108 public TmfExperiment(Class
<T
> type
, String id
, ITmfTrace
[] traces
) {
109 this(type
, id
, traces
, TmfTimestamp
.Zero
, DEFAULT_INDEX_PAGE_SIZE
);
116 * @param indexPageSize
118 public TmfExperiment(Class
<T
> type
, String id
, ITmfTrace
[] traces
, int indexPageSize
) {
119 this(type
, id
, traces
, TmfTimestamp
.Zero
, indexPageSize
);
126 public TmfExperiment(TmfExperiment
<T
> other
) {
127 super(other
.getName() + "(clone)", other
.fType
);
129 fEpoch
= other
.fEpoch
;
130 fIndexPageSize
= other
.fIndexPageSize
;
132 fTraces
= new ITmfTrace
[other
.fTraces
.length
];
133 for (int trace
= 0; trace
< other
.fTraces
.length
; trace
++) {
134 fTraces
[trace
] = other
.fTraces
[trace
].createTraceCopy();
137 fNbEvents
= other
.fNbEvents
;
138 fTimeRange
= other
.fTimeRange
;
141 public TmfExperiment
<T
> createTraceCopy() {
142 TmfExperiment
<T
> experiment
= new TmfExperiment
<T
>(this);
143 TmfSignalManager
.deregister(experiment
);
148 * Clears the experiment
151 public synchronized void dispose() {
152 if (fTraces
!= null) {
153 for (ITmfTrace trace
: fTraces
) {
158 if (fCheckpoints
!= null) {
159 fCheckpoints
.clear();
164 // ------------------------------------------------------------------------
166 // ------------------------------------------------------------------------
168 public String
getPath() {
172 public long getNbEvents() {
176 public int getCacheSize() {
177 return fIndexPageSize
;
180 public TmfTimeRange
getTimeRange() {
184 public TmfTimestamp
getStartTime() {
185 return fTimeRange
.getStartTime();
188 public TmfTimestamp
getEndTime() {
189 return fTimeRange
.getEndTime();
192 public Vector
<TmfCheckpoint
> getCheckpoints() {
196 // ------------------------------------------------------------------------
198 // ------------------------------------------------------------------------
200 private static void setCurrentExperiment(TmfExperiment
<?
> experiment
) {
201 fCurrentExperiment
= experiment
;
204 public static TmfExperiment
<?
> getCurrentExperiment() {
205 return fCurrentExperiment
;
208 public TmfTimestamp
getEpoch() {
212 public ITmfTrace
[] getTraces() {
217 * Returns the rank of the first event with the requested timestamp.
218 * If none, returns the index of the next event (if any).
223 public long getRank(TmfTimestamp timestamp
) {
224 TmfExperimentContext context
= seekEvent(timestamp
);
225 return context
.getRank();
229 * Returns the timestamp of the event at the requested index.
230 * If none, returns null.
235 public TmfTimestamp
getTimestamp(int index
) {
236 TmfExperimentContext context
= seekEvent(index
);
237 TmfEvent event
= getNextEvent(context
);
238 return (event
!= null) ? event
.getTimestamp() : null;
241 // ------------------------------------------------------------------------
243 // ------------------------------------------------------------------------
246 * Update the total number of events
248 private void updateNbEvents() {
250 for (ITmfTrace trace
: fTraces
) {
251 nbEvents
+= trace
.getNbEvents();
253 fNbEvents
= nbEvents
;
257 * Update the global time range
259 private void updateTimeRange() {
260 TmfTimestamp startTime
= fTimeRange
!= null ? fTimeRange
.getStartTime() : TmfTimestamp
.BigCrunch
;
261 TmfTimestamp endTime
= fTimeRange
!= null ? fTimeRange
.getEndTime() : TmfTimestamp
.BigBang
;
263 for (ITmfTrace trace
: fTraces
) {
264 TmfTimestamp traceStartTime
= trace
.getStartTime();
265 if (traceStartTime
.compareTo(startTime
, true) < 0)
266 startTime
= traceStartTime
;
267 TmfTimestamp traceEndTime
= trace
.getEndTime();
268 if (traceEndTime
.compareTo(endTime
, true) > 0)
269 endTime
= traceEndTime
;
271 fTimeRange
= new TmfTimeRange(startTime
, endTime
);
274 // ------------------------------------------------------------------------
276 // ------------------------------------------------------------------------
279 public ITmfContext
armRequest(ITmfDataRequest
<T
> request
) {
280 // Tracer.trace("Ctx: Arming request - start");
281 TmfTimestamp timestamp
= (request
instanceof ITmfEventRequest
<?
>) ?
282 ((ITmfEventRequest
<T
>) request
).getRange().getStartTime() : null;
283 TmfExperimentContext context
= (timestamp
!= null) ?
284 seekEvent(timestamp
) : seekEvent(request
.getIndex());
285 // Tracer.trace("Ctx: Arming request - done");
289 @SuppressWarnings("unchecked")
291 public T
getNext(ITmfContext context
) {
292 if (context
instanceof TmfExperimentContext
) {
293 return (T
) getNextEvent((TmfExperimentContext
) context
);
298 // ------------------------------------------------------------------------
299 // ITmfTrace trace positioning
300 // ------------------------------------------------------------------------
302 // Returns a brand new context based on the location provided
303 // and initializes the event queues
304 public synchronized TmfExperimentContext
seekLocation(ITmfLocation
<?
> location
) {
306 // Validate the location
307 if (location
!= null && !(location
instanceof TmfExperimentLocation
)) {
308 return null; // Throw an exception?
311 // Instantiate the location
312 TmfExperimentLocation expLocation
= (location
== null)
313 ?
new TmfExperimentLocation(new ITmfLocation
<?
>[fTraces
.length
], new long[fTraces
.length
])
314 : (TmfExperimentLocation
) location
.clone();
316 // Create and populate the context's traces contexts
317 TmfExperimentContext context
= new TmfExperimentContext(fTraces
, new TmfContext
[fTraces
.length
]);
318 // Tracer.trace("Ctx: SeekLocation - start");
321 for (int i
= 0; i
< fTraces
.length
; i
++) {
322 // Get the relevant trace attributes
323 ITmfLocation
<?
> traceLocation
= expLocation
.getLocation()[i
];
324 long traceRank
= expLocation
.getRanks()[i
];
326 // Set the corresponding sub-context
327 context
.getContexts()[i
] = fTraces
[i
].seekLocation(traceLocation
);
328 context
.getContexts()[i
].setRank(traceRank
);
331 // Set the trace location and read the corresponding event
332 expLocation
.getLocation()[i
] = context
.getContexts()[i
].getLocation();
333 context
.getEvents()[i
] = fTraces
[i
].getNextEvent(context
.getContexts()[i
]);
336 // Tracer.trace("Ctx: SeekLocation - done");
339 context
.setLocation(expLocation
);
340 context
.setLastTrace(TmfExperimentContext
.NO_TRACE
);
341 context
.setRank(rank
);
343 fExperimentContext
= context
;
349 * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#seekEvent(org.eclipse.linuxtools.tmf.event.TmfTimestamp)
351 public synchronized TmfExperimentContext
seekEvent(TmfTimestamp timestamp
) {
353 // Tracer.trace("Ctx: seekEvent(TS) - start");
355 if (timestamp
== null) {
356 timestamp
= TmfTimestamp
.BigBang
;
359 // First, find the right checkpoint
360 int index
= Collections
.binarySearch(fCheckpoints
, new TmfCheckpoint(timestamp
, null));
362 // In the very likely case that the checkpoint was not found, bsearch
363 // returns its negated would-be location (not an offset...). From that
364 // index, we can then position the stream and get the event.
366 index
= Math
.max(0, -(index
+ 2));
369 // Position the experiment at the checkpoint
370 ITmfLocation
<?
> location
;
371 synchronized (fCheckpoints
) {
372 if (fCheckpoints
.size() > 0) {
373 if (index
>= fCheckpoints
.size()) {
374 index
= fCheckpoints
.size() - 1;
376 location
= fCheckpoints
.elementAt(index
).getLocation();
383 TmfExperimentContext context
= seekLocation(location
);
384 context
.setRank((long) index
* fIndexPageSize
);
386 // And locate the event
387 TmfEvent event
= parseEvent(context
);
388 while (event
!= null && event
.getTimestamp().compareTo(timestamp
, false) < 0) {
389 getNextEvent(context
);
390 event
= parseEvent(context
);
394 context
.setLocation(null);
395 context
.setRank(ITmfContext
.UNKNOWN_RANK
);
402 * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#seekEvent(long)
404 public synchronized TmfExperimentContext
seekEvent(long rank
) {
406 // Tracer.trace("Ctx: seekEvent(rank) - start");
408 // Position the stream at the previous checkpoint
409 int index
= (int) rank
/ fIndexPageSize
;
410 ITmfLocation
<?
> location
;
411 synchronized (fCheckpoints
) {
412 if (fCheckpoints
.size() == 0) {
416 if (index
>= fCheckpoints
.size()) {
417 index
= fCheckpoints
.size() - 1;
419 location
= fCheckpoints
.elementAt(index
).getLocation();
423 TmfExperimentContext context
= seekLocation(location
);
424 context
.setRank((long) index
* fIndexPageSize
);
426 // And locate the event
427 TmfEvent event
= parseEvent(context
);
428 long pos
= context
.getRank();
429 while (event
!= null && pos
++ < rank
) {
430 getNextEvent(context
);
431 event
= parseEvent(context
);
435 context
.setLocation(null);
436 context
.setRank(ITmfContext
.UNKNOWN_RANK
);
443 * Scan the next events from all traces and return the next one
444 * in chronological order.
450 // private void dumpContext(TmfExperimentContext context, boolean isBefore) {
452 // TmfContext context0 = context.getContexts()[0];
453 // TmfEvent event0 = context.getEvents()[0];
454 // TmfExperimentLocation location0 = (TmfExperimentLocation) context.getLocation();
455 // long rank0 = context.getRank();
456 // int trace = context.getLastTrace();
458 // StringBuffer result = new StringBuffer("Ctx: " + (isBefore ? "B " : "A "));
460 // result.append("[Ctx: fLoc= " + context0.getLocation().toString() + ", fRnk= " + context0.getRank() + "] ");
461 // result.append("[Evt: " + event0.getTimestamp().toString() + "] ");
462 // result.append("[Loc: fLoc= " + location0.getLocation()[0].toString() + ", fRnk= " + location0.getRanks()[0] + "] ");
463 // result.append("[Rnk: " + rank0 + "], [Trc: " + trace + "]");
464 // Tracer.trace(result.toString());
467 public synchronized TmfEvent
getNextEvent(TmfContext context
) {
469 // Validate the context
470 if (!(context
instanceof TmfExperimentContext
)) {
471 return null; // Throw an exception?
474 if (!context
.equals(fExperimentContext
)) {
475 // Tracer.trace("Ctx: Restoring context");
476 seekLocation(context
.getLocation());
479 TmfExperimentContext expContext
= (TmfExperimentContext
) context
;
481 // dumpContext(expContext, true);
483 // If an event was consumed previously, get the next one from that trace
484 int lastTrace
= expContext
.getLastTrace();
485 if (lastTrace
!= TmfExperimentContext
.NO_TRACE
) {
486 TmfContext traceContext
= expContext
.getContexts()[lastTrace
];
487 expContext
.getEvents()[lastTrace
] = expContext
.getTraces()[lastTrace
].getNextEvent(traceContext
);
488 expContext
.setLastTrace(TmfExperimentContext
.NO_TRACE
);
491 // Scan the candidate events and identify the "next" trace to read from
492 int trace
= TmfExperimentContext
.NO_TRACE
;
493 TmfTimestamp timestamp
= TmfTimestamp
.BigCrunch
;
494 for (int i
= 0; i
< expContext
.getTraces().length
; i
++) {
495 TmfEvent event
= expContext
.getEvents()[i
];
496 if (event
!= null && event
.getTimestamp() != null) {
497 TmfTimestamp otherTS
= event
.getTimestamp();
498 if (otherTS
.compareTo(timestamp
, true) < 0) {
505 // Update the experiment context and set the "next" event
506 TmfEvent event
= null;
507 if (trace
!= TmfExperimentContext
.NO_TRACE
) {
508 updateIndex(expContext
, timestamp
);
510 TmfContext traceContext
= expContext
.getContexts()[trace
];
511 TmfExperimentLocation expLocation
= (TmfExperimentLocation
) expContext
.getLocation();
512 expLocation
.getLocation()[trace
] = traceContext
.getLocation().clone();
514 // updateIndex(expContext, timestamp);
516 expLocation
.getRanks()[trace
] = traceContext
.getRank();
517 expContext
.setLastTrace(trace
);
518 expContext
.updateRank(1);
519 event
= expContext
.getEvents()[trace
];
522 // if (event != null) {
523 // Tracer.trace("Exp: " + (expContext.getRank() - 1) + ": " + event.getTimestamp().toString());
524 // dumpContext(expContext, false);
525 // Tracer.trace("Ctx: Event returned= " + event.getTimestamp().toString());
531 public synchronized void updateIndex(ITmfContext context
, TmfTimestamp timestamp
) {
532 // Build the index as we go along
533 long rank
= context
.getRank();
534 if (context
.isValidRank() && (rank
% fIndexPageSize
) == 0) {
535 // Determine the table position
536 long position
= rank
/ fIndexPageSize
;
537 // Add new entry at proper location (if empty)
538 if (fCheckpoints
.size() == position
) {
539 ITmfLocation
<?
> location
= context
.getLocation().clone();
540 fCheckpoints
.add(new TmfCheckpoint(timestamp
.clone(), location
));
541 // System.out.println(this + "[" + (fCheckpoints.size() - 1) + "] " + timestamp + ", " + location.toString());
547 * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#parseEvent(org.eclipse.linuxtools.tmf.trace.TmfContext)
549 public TmfEvent
parseEvent(TmfContext context
) {
551 // Validate the context
552 if (!(context
instanceof TmfExperimentContext
)) {
553 return null; // Throw an exception?
556 if (!context
.equals(fExperimentContext
)) {
557 // Tracer.trace("Ctx: Restoring context");
558 seekLocation(context
.getLocation());
561 TmfExperimentContext expContext
= (TmfExperimentContext
) context
;
563 // If an event was consumed previously, get the next one from that trace
564 int lastTrace
= expContext
.getLastTrace();
565 if (lastTrace
!= TmfExperimentContext
.NO_TRACE
) {
566 TmfContext traceContext
= expContext
.getContexts()[lastTrace
];
567 expContext
.getEvents()[lastTrace
] = expContext
.getTraces()[lastTrace
].getNextEvent(traceContext
);
568 expContext
.setLastTrace(TmfExperimentContext
.NO_TRACE
);
569 fExperimentContext
= (TmfExperimentContext
) context
;
572 // Scan the candidate events and identify the "next" trace to read from
573 int trace
= TmfExperimentContext
.NO_TRACE
;
574 TmfTimestamp timestamp
= TmfTimestamp
.BigCrunch
;
575 for (int i
= 0; i
< expContext
.getTraces().length
; i
++) {
576 TmfEvent event
= expContext
.getEvents()[i
];
577 if (event
!= null && event
.getTimestamp() != null) {
578 TmfTimestamp otherTS
= event
.getTimestamp();
579 if (otherTS
.compareTo(timestamp
, true) < 0) {
586 TmfEvent event
= null;
587 if (trace
!= TmfExperimentContext
.NO_TRACE
) {
588 event
= expContext
.getEvents()[trace
];
595 * @see java.lang.Object#toString()
598 public String
toString() {
599 return "[TmfExperiment (" + getName() + ")]";
602 // ------------------------------------------------------------------------
604 // ------------------------------------------------------------------------
607 * The experiment holds the globally ordered events of its set of traces.
608 * It is expected to provide access to each individual event by index i.e.
609 * it must be possible to request the Nth event of the experiment.
611 * The purpose of the index is to keep the information needed to rapidly
612 * restore the traces contexts at regular intervals (every INDEX_PAGE_SIZE
616 // The index page size
617 private static final int DEFAULT_INDEX_PAGE_SIZE
= 5000;
618 protected int fIndexPageSize
;
620 // private static BufferedWriter fEventLog = null;
621 // private static BufferedWriter openLogFile(String filename) {
622 // BufferedWriter outfile = null;
624 // outfile = new BufferedWriter(new FileWriter(filename));
625 // } catch (IOException e) {
626 // e.printStackTrace();
631 @SuppressWarnings("unchecked")
632 private void indexExperiment(boolean waitForCompletion
) {
634 fCheckpoints
.clear();
636 // fEventLog = openLogFile("TraceEvent.log");
637 // System.out.println(System.currentTimeMillis() + ": Experiment indexing started");
639 ITmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, TmfTimeRange
.Eternity
,
640 TmfDataRequest
.ALL_DATA
, 1, ITmfDataRequest
.ExecutionType
.BACKGROUND
) {
642 // long indexingStart = System.nanoTime();
644 TmfTimestamp startTime
= null;
645 TmfTimestamp lastTime
= null;
648 public void handleData(TmfEvent event
) {
649 super.handleData(event
);
651 TmfTimestamp ts
= event
.getTimestamp();
652 if (startTime
== null)
653 startTime
= new TmfTimestamp(ts
);
654 lastTime
= new TmfTimestamp(ts
);
656 if ((getNbRead() % DEFAULT_INDEX_PAGE_SIZE
) == 0) {
663 public void handleSuccess() {
664 // long indexingEnd = System.nanoTime();
667 // System.out.println(System.currentTimeMillis() + ": Experiment indexing completed");
669 // long average = (indexingEnd - indexingStart) / fNbEvents;
670 // System.out.println(getName() + ": start=" + startTime + ", end=" + lastTime + ", elapsed=" + (indexingEnd * 1.0 - indexingStart) / 1000000000);
671 // System.out.println(getName() + ": nbEvents=" + fNbEvents + " (" + (average / 1000) + "." + (average % 1000) + " us/evt)");
674 private void updateExperiment() {
675 int nbRead
= getNbRead();
677 // updateTimeRange();
679 fTimeRange
= new TmfTimeRange(startTime
, new TmfTimestamp(lastTime
));
686 sendRequest((ITmfDataRequest
<T
>) request
);
687 if (waitForCompletion
)
689 request
.waitForCompletion();
690 } catch (InterruptedException e
) {
695 protected void notifyListeners() {
696 broadcast(new TmfExperimentUpdatedSignal(this, this)); // , null));
699 // ------------------------------------------------------------------------
701 // ------------------------------------------------------------------------
704 public void experimentSelected(TmfExperimentSelectedSignal
<T
> signal
) {
705 TmfExperiment
<?
> experiment
= signal
.getExperiment();
706 if (experiment
== this) {
707 setCurrentExperiment(experiment
);
708 indexExperiment(false);
716 public void experimentUpdated(TmfExperimentUpdatedSignal signal
) {
720 public void traceUpdated(TmfTraceUpdatedSignal signal
) {
721 // TODO: Incremental index update
726 broadcast(new TmfExperimentUpdatedSignal(this, this)); // , signal.getTrace()));
729 // ------------------------------------------------------------------------
731 // ------------------------------------------------------------------------
734 protected void queueBackgroundRequest(final ITmfDataRequest
<T
> request
, final int blockSize
, final boolean indexing
) {
736 // TODO: Handle the data requests also...
737 if (!(request
instanceof ITmfEventRequest
<?
>)) {
738 super.queueRequest(request
);
741 final ITmfEventRequest
<T
> eventRequest
= (ITmfEventRequest
<T
>) request
;
743 Thread thread
= new Thread() {
747 // final long requestStart = System.nanoTime();
749 final Integer
[] CHUNK_SIZE
= new Integer
[1];
750 CHUNK_SIZE
[0] = blockSize
+ ((indexing
) ?
1 : 0);
752 final Integer
[] nbRead
= new Integer
[1];
755 // final TmfTimestamp[] timestamp = new TmfTimestamp[1];
756 // timestamp[0] = new TmfTimestamp(eventRequest.getRange().getStartTime());
757 // final TmfTimestamp endTS = eventRequest.getRange().getEndTime();
759 final Boolean
[] isFinished
= new Boolean
[1];
760 isFinished
[0] = Boolean
.FALSE
;
762 while (!isFinished
[0]) {
764 // TmfEventRequest<T> subRequest = new TmfEventRequest<T>(eventRequest.getDataType(), new TmfTimeRange(timestamp[0], endTS), CHUNK_SIZE[0], eventRequest.getBlockize(), ExecutionType.BACKGROUND)
765 // TmfDataRequest<T> subRequest = new TmfDataRequest<T>(eventRequest.getDataType(), nbRead[0], CHUNK_SIZE[0], eventRequest.getBlockize(), ExecutionType.BACKGROUND)
766 TmfDataRequest
<T
> subRequest
= new TmfDataRequest
<T
>(eventRequest
.getDataType(), nbRead
[0], CHUNK_SIZE
[0], ExecutionType
.BACKGROUND
)
769 public void handleData(T data
) {
770 super.handleData(data
);
771 eventRequest
.handleData(data
);
772 if (getNbRead() == CHUNK_SIZE
[0]) {
773 nbRead
[0] += getNbRead();
775 if (getNbRead() > CHUNK_SIZE
[0]) {
776 System
.out
.println("ERROR - Read too many events");
781 public void handleCompleted() {
782 // System.out.println("Request completed at: " + timestamp[0]);
783 if (getNbRead() < CHUNK_SIZE
[0]) {
785 isFinished
[0] = Boolean
.TRUE
;
786 nbRead
[0] += getNbRead();
787 // System.out.println("fNbRead=" + fNbRead + ", count=" + count +", total=" + nbRead[0]);
789 super.handleCompleted();
793 if (!isFinished
[0]) {
794 queueRequest(subRequest
);
797 subRequest
.waitForCompletion();
798 // System.out.println("Finished at " + timestamp[0]);
799 } catch (InterruptedException e
) {
803 // TmfTimestamp newTS = new TmfTimestamp(timestamp[0].getValue() + 1, timestamp[0].getScale(), timestamp[0].getPrecision());
804 // timestamp[0] = newTS;
805 CHUNK_SIZE
[0] = blockSize
;
806 // System.out.println("New timestamp: " + timestamp[0]);
809 // final long requestEnded = System.nanoTime();
810 // System.out.println("Background request completed. Elapsed= " + (requestEnded * 1.0 - requestStart) / 1000000000);