assertNotSame("tmpEvent is null after first event",null,tmpEvent );
assertTrue("tmpEvent has wrong reference after first event",((String)tmpEvent.getReference().getReference()).contains(firstEventReference) );
assertNotSame("tmpContext is null after first seekEvent()",null,testStream1.getCurrentLocation() );
- assertEquals("tmpContext has wrong timestamp after first seekEvent()",locationAfterFirstEvent, ((TmfLocation<Long>) testStream1.getCurrentLocation()).getValue());
+ assertEquals("tmpContext has wrong timestamp after first seekEvent()",locationAfterFirstEvent, ((TmfLocation<Long>) testStream1.getCurrentLocation()).getLocation());
// Test CPU number of the trace
assertSame("getCpuNumber() return wrong number of cpu",traceCpuNumber ,testStream1.getCpuNumber() );
}
/* (non-Javadoc)
* @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#seekLocation(java.lang.Object)
*/
+ @Override
@SuppressWarnings("unchecked")
- public TmfContext seekLocation(ITmfLocation location) {
+ public TmfContext seekLocation(ITmfLocation<?> location) {
TmfContext context = null;
try {
synchronized(fTrace) {
- fTrace.seek((location != null) ? ((TmfLocation<Long>) location).getValue() : 0);
+ fTrace.seek((location != null) ? ((TmfLocation<Long>) location).getLocation() : 0);
context = new TmfContext(getCurrentLocation(), 0);
// TmfTraceContext context2 = new TmfTraceContext(getCurrentLocation(), 0);
// TmfEvent event = parseEvent(context2);
* @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#getCurrentLocation()
*/
@Override
- public ITmfLocation getCurrentLocation() {
+ public ITmfLocation<?> getCurrentLocation() {
try {
return new TmfLocation<Long>(fTrace.getFilePointer());
} catch (IOException e) {
import org.eclipse.linuxtools.tmf.trace.ITmfLocation;
-public class LttngLocation implements ITmfLocation {
+public class LttngLocation implements ITmfLocation<Long[]> {
private final static Long DEFAULT_LAST_TIME = -1L;
private final static Long DEFAULT_CURR_TIME = 0L;
public String toString() {
return "\tLttngLocation[ Last : " + lastReadTime + " Current : " + currentTime + " ]";
}
+
+ // ------------------------------------------------------------------------
+ // ITmfLocation
+ // ------------------------------------------------------------------------
+
+ public void setLocation(Long[] location) {
+ lastReadTime = ((Long[]) location)[0];
+ currentTime = ((Long[]) location)[1];
+ }
+
+ public Long[] getLocation() {
+ return new Long[] {lastReadTime, currentTime };
+ }
}
}
// Make sure eventCount stay consistent!
- eventCount = location.getValue();
+ eventCount = location.getLocation();
// Restore the stored traceState
stateIn.setTraceStateModel(traceState);
private void skipToPosition(TmfLocation<Long> skip) {
try {
- long skipPosition = skip.getValue();
+ long skipPosition = skip.getLocation();
if ( skipPosition < 0 ) {
skipPosition = 0L;
}
}
}
- @SuppressWarnings("unchecked")
- public TmfContext seekLocation(ITmfLocation location) {
+ @Override
+ @SuppressWarnings("unchecked")
+ public TmfContext seekLocation(ITmfLocation<?> location) {
if (location == null) {
location = new TmfLocation<Long>(0L);
}
- if (!((TmfLocation<Long>) location).getValue().equals(nbCharRead)) {
+ if (!((TmfLocation<Long>) location).getLocation().equals(nbCharRead)) {
skipToPosition((TmfLocation<Long>) location);
}
}
@Override
- public ITmfLocation getCurrentLocation() {
+ public ITmfLocation<?> getCurrentLocation() {
return new TmfLocation<Long>(nbCharRead);
}
}
@Override
- public ITmfLocation getCurrentLocation() {
+ public ITmfLocation<?> getCurrentLocation() {
return currentLocation;
}
- public synchronized TmfContext seekLocation(ITmfLocation location) {
+ @Override
+ public synchronized TmfContext seekLocation(ITmfLocation<?> location) {
if ( joie == true ) {
System.out.println("seekLocation(location) location -> " + location);
synchronized(stream) {
long location = 0;
if (context != null)
- location = ((TmfLocation<Long>) (context.getLocation())).getValue();
+ location = ((TmfLocation<Long>) (context.getLocation())).getLocation();
stream.seek(location);
try {
// Operators
// ------------------------------------------------------------------------
+ @Override
@SuppressWarnings("unchecked")
- public TmfContext seekLocation(ITmfLocation location) {
+ public TmfContext seekLocation(ITmfLocation<?> location) {
try {
synchronized(fTrace) {
// Position the trace at the requested location and
// returns the corresponding context
- long loc = (location != null) ? ((TmfLocation<Long>) location).getValue() : 0;
+ long loc = (location != null) ? ((TmfLocation<Long>) location).getLocation() : 0;
if (loc != fTrace.getFilePointer()) {
fTrace.seek(loc);
}
// Returns a brand new context based on the location provided
// Arms the event queues
// NOTE: This is a fine example of pathological coupling...
- public TmfExperimentContext seekLocation(ITmfLocation location) {
+ public TmfExperimentContext seekLocation(ITmfLocation<?> location) {
if (location instanceof TmfExperimentLocation || location == null) {
- ITmfLocation[] oldloc = (location != null) ? ((TmfExperimentLocation) location).getLocations() : new TmfExperimentLocation[fTraces.length];
- ITmfLocation[] newloc = new ITmfLocation[fTraces.length];
+ ITmfLocation<?>[] oldloc = (location != null) ? ((TmfExperimentLocation) location).getLocation() : new TmfExperimentLocation[fTraces.length];
+ ITmfLocation<?>[] newloc = new ITmfLocation[fTraces.length];
TmfContext[] contexts = new TmfContext[fTraces.length];
TmfExperimentContext context = new TmfExperimentContext(fTraces, contexts);
}
// Position the experiment at the checkpoint
- ITmfLocation location;
+ ITmfLocation<?> location;
synchronized (fCheckpoints) {
if (fCheckpoints.size() > 0) {
if (index >= fCheckpoints.size()) {
TmfContext trcloc = expContext.getContexts()[trace];
TmfEvent event = expContext.getTraces()[trace].parseEvent(trcloc);
TmfExperimentLocation exploc = (TmfExperimentLocation) expContext.getLocation();
- exploc.getLocations()[trace] = trcloc.getLocation().clone();
+ exploc.getLocation()[trace] = trcloc.getLocation().clone();
expContext.updateRank(1);
expContext.getEvents()[trace] = expContext.getTraces()[trace].getNextEvent(trcloc);
return event;
fContexts = contexts;
fEvents = new TmfEvent[fTraces.length];
- ITmfLocation[] locations = new ITmfLocation[fTraces.length];
+ ITmfLocation<?>[] locations = new ITmfLocation[fTraces.length];
long rank = 0;
for (int i = 0; i < fTraces.length; i++) {
if (contexts[i] != null) {
package org.eclipse.linuxtools.tmf.experiment;
import org.eclipse.linuxtools.tmf.trace.ITmfLocation;
+import org.eclipse.linuxtools.tmf.trace.TmfLocation;
/**
* <b><u>TmfExperimentLocation</u></b>
* <p>
* The experiment location is the set of its traces' locations.
*/
-public class TmfExperimentLocation implements ITmfLocation {
+public class TmfExperimentLocation extends TmfLocation<ITmfLocation<?>[]> {
- private ITmfLocation[] fLocations;
-
- public TmfExperimentLocation(ITmfLocation[] locations) {
- fLocations = locations;
- }
-
- public ITmfLocation[] getLocations() {
- return fLocations;
+ public TmfExperimentLocation(ITmfLocation<?>[] locations) {
+ super(locations);
}
@Override
public TmfExperimentLocation clone() {
- ITmfLocation[] locations = new ITmfLocation[fLocations.length];
- for (int i = 0; i < fLocations.length; i++) {
- locations[i] = fLocations[i].clone();
+ ITmfLocation<?>[] locations = (ITmfLocation<?>[]) getLocation();
+ ITmfLocation<?>[] clones = new ITmfLocation[locations.length];
+ for (int i = 0; i < locations.length; i++) {
+ clones[i] = locations[i].clone();
}
- return new TmfExperimentLocation(locations);
+ return new TmfExperimentLocation(clones);
}
}
*/
public interface ITmfContext extends Cloneable {
- public void setLocation(ITmfLocation location);
- public ITmfLocation getLocation();
+ public void setLocation(ITmfLocation<?> location);
+ public ITmfLocation<?> getLocation();
- public void setRank(long value);
+ public void setRank(long rank);
public long getRank();
- public void updateRank(int value);
+ public void updateRank(int rank);
}
/**
* <b><u>ITmfLocation</u></b>
* <p>
- * This is a place-holder for the context objects.
+ * This is a place-holder for the location objects.
*/
-public interface ITmfLocation extends Cloneable {
-
- public ITmfLocation clone();
+public interface ITmfLocation<L> extends Cloneable {
+
+ public void setLocation(L location);
+
+ public L getLocation();
+
+ public ITmfLocation<L> clone();
}
* @param data.index
* @return a context object for subsequent reads
*/
- public TmfContext seekLocation(ITmfLocation location);
+ public TmfContext seekLocation(ITmfLocation<?> location);
public TmfContext seekEvent(TmfTimestamp timestamp);
public TmfContext seekEvent(long rank);
// ------------------------------------------------------------------------
private final TmfTimestamp fTimestamp;
- private final ITmfLocation fLocation;
+ private final ITmfLocation<?> fLocation;
// ------------------------------------------------------------------------
// Constructors
* @param ts
* @param location
*/
- public TmfCheckpoint(TmfTimestamp ts, ITmfLocation location) {
+ public TmfCheckpoint(TmfTimestamp ts, ITmfLocation<?> location) {
fTimestamp = ts;
fLocation = location;
}
/**
* @return the checkpoint event stream location
*/
- public ITmfLocation getLocation() {
+ public ITmfLocation<?> getLocation() {
return fLocation;
}
*/
public class TmfContext implements ITmfContext, Cloneable {
- private ITmfLocation fLocation;
+ private ITmfLocation<?> fLocation;
private long fRank;
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
- public TmfContext(ITmfLocation loc, long rank) {
+ public TmfContext(ITmfLocation<?> loc, long rank) {
fLocation = loc;
fRank = rank;
}
- public TmfContext(ITmfLocation location) {
+ public TmfContext(ITmfLocation<?> location) {
this(location, 0);
}
// ITmfContext
// ------------------------------------------------------------------------
- public void setLocation(ITmfLocation loc) {
- fLocation = loc;
+ public void setLocation(ITmfLocation<?> location) {
+ fLocation = location;
}
- public ITmfLocation getLocation() {
+ public ITmfLocation<?> getLocation() {
return fLocation;
}
- public void setRank(long value) {
- fRank = value;
+ public void setRank(long rank) {
+ fRank = rank;
}
public long getRank() {
return fRank;
}
- public void updateRank(int value) {
- fRank += value;
+ public void updateRank(int delta) {
+ fRank += delta;
}
}
/**
* <b><u>TmfLocation</u></b>
* <p>
- * Implement me. Please.
+ * A generic implementation of ITmfLocation
*/
-public class TmfLocation<T> implements ITmfLocation {
+public class TmfLocation<L> implements ITmfLocation<L> {
- private T fLocation;
+ private L fLocation;
- public TmfLocation(T location) {
+ public TmfLocation(L location) {
fLocation = location;
}
- public void setValue(T location) {
+ public void setLocation(L location) {
fLocation = location;
}
- public T getValue() {
+ public L getLocation() {
return fLocation;
}
+ @Override
+ public String toString() {
+ return fLocation.toString();
+ }
+
@Override
@SuppressWarnings("unchecked")
- public TmfLocation<T> clone() {
+ public TmfLocation<L> clone() {
try {
- return (TmfLocation<T>) super.clone();
+ return (TmfLocation<L>) super.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
return null;
}
+
}
}
// Position the stream at the checkpoint
- ITmfLocation location;
+ ITmfLocation<?> location;
synchronized (fCheckpoints) {
if (fCheckpoints.size() > 0) {
if (index >= fCheckpoints.size()) {
// Position the stream at the previous checkpoint
int index = (int) rank / fIndexPageSize;
- ITmfLocation location;
+ ITmfLocation<?> location;
synchronized (fCheckpoints) {
if (fCheckpoints.size() > 0) {
if (index >= fCheckpoints.size()) {
/**
* To be implemented by the concrete class
*/
- public abstract ITmfLocation getCurrentLocation();
+ public abstract TmfContext seekLocation(ITmfLocation<?> location);
+ public abstract ITmfLocation<?> getCurrentLocation();
public abstract TmfEvent parseEvent(TmfContext context);
// ------------------------------------------------------------------------
/* (non-Javadoc)
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
*/
- @SuppressWarnings("rawtypes")
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
// Position the trace at the beginning
TmfContext context = seekLocation(null);
- TmfLocation location = (TmfLocation) context.getLocation();
+ ITmfLocation<?> location = context.getLocation();
// Get the first event
TmfEvent event = getNextEvent(context);
// We will need this location at the next iteration
if ((nbEvents % fIndexPageSize) == 0) {
- location = (TmfLocation) context.getLocation();
+ location = context.getLocation();
}
event = getNextEvent(context);