1 /*******************************************************************************
2 * Copyright (c) 2012 Ericsson
4 * All rights reserved. This program and the accompanying materials are made
5 * 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
9 * Contributors: Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
;
14 import java
.util
.ArrayList
;
15 import java
.util
.ListIterator
;
17 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfLocation
;
21 * Lightweight Context for CtfTmf traces. Should only use 3 references, 1 ref to
22 * a boxed Long, a long and an int.
25 * @author Matthew Khouzam
27 public class CtfTmfLightweightContext
implements ITmfContext
{
29 // -------------------------------------------
31 // -------------------------------------------
32 private CtfLocation curLocation
;
35 private final CtfTmfTrace fTrace
;
37 // -------------------------------------------
39 // -------------------------------------------
41 * Deprecated, use CtfTmfLightweightContext( CtfTmfTrace please )
44 * the shared iterator pool.
46 * the iterator position.
49 public CtfTmfLightweightContext(ArrayList
<CtfIterator
> iters
,
50 ListIterator
<CtfIterator
> pos
) {
51 fTrace
= iters
.get(0).getCtfTmfTrace();
52 curLocation
= new CtfLocation(new CtfLocationData(0, 0));
61 public CtfTmfLightweightContext(CtfTmfTrace ctfTmfTrace
) {
63 curLocation
= new CtfLocation(new CtfLocationData(0, 0));
66 // -------------------------------------------
67 // TmfContext Overrides
68 // -------------------------------------------
71 public long getRank() {
76 public ITmfLocation
<?
extends Comparable
<?
>> getLocation() {
81 public boolean hasValidRank() {
82 return curRank
!= CtfLocation
.INVALID_LOCATION
.getTimestamp();
86 public void setLocation(ITmfLocation
<?
extends Comparable
<?
>> location
) {
87 curLocation
= (CtfLocation
) location
;
88 getIterator().seek(curLocation
.getLocationData());
92 public void setRank(long rank
) {
98 public void increaseRank() {
104 // -------------------------------------------
105 // CtfTmfTrace Helpers
106 // -------------------------------------------
109 * Gets the current event. Wrapper to help CtfTmfTrace
111 * @return The event or null
113 public synchronized CtfTmfEvent
getCurrentEvent() {
114 return getIterator().getCurrentEvent();
118 * Advances to a the next event. Wrapper to help CtfTmfTrace
120 * @return success or not
122 public synchronized boolean advance() {
123 final CtfLocationData curLocationData
= this.curLocation
.getLocationData();
124 boolean retVal
= getIterator().advance();
125 CtfTmfEvent currentEvent
= getIterator().getCurrentEvent();
127 if (currentEvent
!= null) {
128 final long timestampValue
= currentEvent
.getTimestamp().getValue();
129 if (curLocationData
.getTimestamp() == timestampValue
) {
130 curLocation
.setLocation(timestampValue
, curLocationData
.getIndex() + 1);
132 curLocation
.setLocation(timestampValue
, 0L);
135 curLocation
.setLocation(CtfLocation
.INVALID_LOCATION
);
142 public void dispose() {
147 * Seeks to a given timestamp. Wrapper to help CtfTmfTrace
151 * @return success or not
153 public synchronized boolean seek(final long timestamp
) {
154 curLocation
.setLocation(timestamp
, 0);
155 return getIterator().seek(timestamp
);
159 * Seeks to a given location. Wrapper to help CtfTmfTrace
161 * unique location to find the event.
163 * @return success or not
166 public synchronized boolean seek(final CtfLocationData location
) {
167 curLocation
.setLocation(location
);
168 return getIterator().seek(location
);
174 * @see java.lang.Object#clone()
177 public CtfTmfLightweightContext
clone() {
178 CtfTmfLightweightContext ret
= new CtfTmfLightweightContext(fTrace
);
179 ret
.curLocation
= curLocation
.clone();
180 ret
.curRank
= curRank
;
184 // -------------------------------------------
186 // -------------------------------------------
188 * Get iterator, called every time to get an iterator, no local copy is
189 * stored so that there is no need to "update"
191 * @return an iterator
193 private CtfIterator
getIterator() {
194 return CtfIteratorManager
.getIterator(fTrace
, this);