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
getLocation() {
81 public boolean hasValidRank() {
82 return curRank
!= CtfLocation
.INVALID_LOCATION
.getTimestamp();
86 public void setLocation(ITmfLocation location
) {
87 curLocation
= (CtfLocation
) location
;
88 if (curLocation
!= null) {
89 getIterator().seek(curLocation
.getLocationInfo());
94 public void setRank(long rank
) {
100 public void increaseRank() {
101 if (hasValidRank()) {
106 // -------------------------------------------
107 // CtfTmfTrace Helpers
108 // -------------------------------------------
111 * Gets the current event. Wrapper to help CtfTmfTrace
113 * @return The event or null
115 public synchronized CtfTmfEvent
getCurrentEvent() {
116 return getIterator().getCurrentEvent();
120 * Advances to a the next event. Wrapper to help CtfTmfTrace
122 * @return success or not
124 public synchronized boolean advance() {
125 final CtfLocationData curLocationData
= this.curLocation
.getLocationInfo();
126 boolean retVal
= getIterator().advance();
127 CtfTmfEvent currentEvent
= getIterator().getCurrentEvent();
129 if (currentEvent
!= null) {
130 final long timestampValue
= currentEvent
.getTimestamp().getValue();
131 if (curLocationData
.getTimestamp() == timestampValue
) {
132 curLocation
= new CtfLocation(timestampValue
, curLocationData
.getIndex() + 1);
134 curLocation
= new CtfLocation(timestampValue
, 0L);
137 curLocation
= new CtfLocation(CtfLocation
.INVALID_LOCATION
);
144 public void dispose() {
149 * Seeks to a given timestamp. Wrapper to help CtfTmfTrace
153 * @return success or not
155 public synchronized boolean seek(final long timestamp
) {
156 curLocation
= new CtfLocation(timestamp
, 0);
157 return getIterator().seek(timestamp
);
161 * Seeks to a given location. Wrapper to help CtfTmfTrace
163 * unique location to find the event.
165 * @return success or not
168 public synchronized boolean seek(final CtfLocationData location
) {
169 curLocation
= new CtfLocation(location
);
170 return getIterator().seek(location
);
176 * @see java.lang.Object#clone()
179 public CtfTmfLightweightContext
clone() {
180 CtfTmfLightweightContext ret
= new CtfTmfLightweightContext(fTrace
);
181 ret
.curLocation
= curLocation
.clone();
182 ret
.curRank
= curRank
;
186 // -------------------------------------------
188 // -------------------------------------------
190 * Get iterator, called every time to get an iterator, no local copy is
191 * stored so that there is no need to "update"
193 * @return an iterator
195 private CtfIterator
getIterator() {
196 return CtfIteratorManager
.getIterator(fTrace
, this);