| author | Matthew Khouzam | 2012-04-03 10:23:05 (EDT) |
|---|---|---|
| committer | Francois Chouinard | 2012-04-16 14:20:21 (EDT) |
| commit | 2919a69f6f41680224803d99f3acec8590370540 (patch) (side-by-side diff) | |
| tree | da79e9b271d7d8a909ac9b48cdc1d9e71af9332a | |
| parent | 5e260bf62b056088f0862337d0ab95c6b0ca3d12 (diff) | |
| download | org.eclipse.linuxtools-2919a69f6f41680224803d99f3acec8590370540.zip org.eclipse.linuxtools-2919a69f6f41680224803d99f3acec8590370540.tar.gz org.eclipse.linuxtools-2919a69f6f41680224803d99f3acec8590370540.tar.bz2 | |
Change certain classes to use ITmfEvent instead of TmfEvent.
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
5 files changed, 197 insertions, 146 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperiment.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperiment.java index 1aa669b..8b22946 100644 --- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperiment.java +++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperiment.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2009, 2010 Ericsson - * + * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which * accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: * Francois Chouinard - Initial API and implementation *******************************************************************************/ @@ -153,6 +153,34 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl } /** + * Copy constructor + * + * @param other + */ + @SuppressWarnings("unchecked") + public TmfExperiment(TmfExperiment<T> other) { + super(other.getName() + "(clone)", other.fType); //$NON-NLS-1$ + + fEpoch = other.fEpoch; + fIndexPageSize = other.fIndexPageSize; + + fTraces = new ITmfTrace[other.fTraces.length]; + for (int trace = 0; trace < other.fTraces.length; trace++) { + fTraces[trace] = other.fTraces[trace].copy(); + } + + fNbEvents = other.fNbEvents; + fTimeRange = other.fTimeRange; + } + + @Override + public TmfExperiment<T> copy() { + TmfExperiment<T> experiment = new TmfExperiment<T>(this); + TmfSignalManager.deregister(experiment); + return experiment; + } + + /** * Clears the experiment */ @Override @@ -215,7 +243,7 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl // ------------------------------------------------------------------------ public static void setCurrentExperiment(TmfExperiment<?> experiment) { - if (fCurrentExperiment != null && fCurrentExperiment != experiment) { + if ((fCurrentExperiment != null) && (fCurrentExperiment != experiment)) { fCurrentExperiment.dispose(); } fCurrentExperiment = experiment; @@ -236,7 +264,7 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl /** * Returns the rank of the first event with the requested timestamp. If none, returns the index of the next event * (if any). - * + * * @param timestamp the event timestamp * @return the corresponding event rank */ @@ -248,7 +276,7 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl /** * Returns the timestamp of the event at the requested index. If none, returns null. - * + * * @param index the event index (rank) * @return the corresponding event timestamp */ @@ -271,11 +299,13 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl for (ITmfTrace<T> trace : fTraces) { ITmfTimestamp traceStartTime = trace.getStartTime(); - if (traceStartTime.compareTo(startTime, true) < 0) + if (traceStartTime.compareTo(startTime, true) < 0) { startTime = traceStartTime; + } ITmfTimestamp traceEndTime = trace.getEndTime(); - if (traceEndTime.compareTo(endTime, true) > 0) + if (traceEndTime.compareTo(endTime, true) > 0) { endTime = traceEndTime; + } } fTimeRange = new TmfTimeRange(startTime, endTime); } @@ -289,7 +319,7 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl ITmfTimestamp timestamp = (request instanceof ITmfEventRequest<?>) ? ((ITmfEventRequest<T>) request).getRange().getStartTime() : null; - if (TmfTimestamp.BIG_BANG.equals(timestamp) || request.getIndex() > 0) { + if (TmfTimestamp.BIG_BANG.equals(timestamp) || (request.getIndex() > 0)) { timestamp = null; // use request index } @@ -300,7 +330,7 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl ((ITmfEventRequest<T>) request).setStartIndex((int) context.getRank()); } else { // Seek by rank - if ((fExperimentContext != null) && fExperimentContext.getRank() == request.getIndex()) { + if ((fExperimentContext != null) && (fExperimentContext.getRank() == request.getIndex())) { // We are already at the right context -> no need to seek context = fExperimentContext; } else { @@ -315,7 +345,7 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl @Override public T getNext(ITmfContext context) { if (context instanceof TmfExperimentContext) { - return (T) getNextEvent((TmfExperimentContext) context); + return (T) getNextEvent(context); } return null; } @@ -329,7 +359,7 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl @Override public synchronized TmfExperimentContext seekLocation(ITmfLocation<?> location) { // Validate the location - if (location != null && !(location instanceof TmfExperimentLocation)) { + if ((location != null) && !(location instanceof TmfExperimentLocation)) { return null; // Throw an exception? } @@ -342,7 +372,7 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl new ITmfLocation<?>[fTraces.length]), new long[fTraces.length]) : (TmfExperimentLocation) location.clone(); // Create and populate the context's traces contexts - TmfExperimentContext context = new TmfExperimentContext(fTraces, new TmfContext[fTraces.length]); + TmfExperimentContext context = new TmfExperimentContext(fTraces, new ITmfContext[fTraces.length]); // Tracer.trace("Ctx: SeekLocation - start"); long rank = 0; @@ -359,7 +389,7 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl // Set the trace location and read the corresponding event /* The (TmfContext) cast should be safe since we created 'context' * ourselves higher up. */ - expLocation.getLocation().locations[i] = ((TmfContext) context.getContexts()[i]).getLocation().clone(); + expLocation.getLocation().locations[i] = (ITmfLocation<? extends Comparable<?>>) (context.getContexts()[i]).getLocation().clone(); context.getEvents()[i] = fTraces[i].getNextEvent(context.getContexts()[i]); } @@ -377,7 +407,7 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl /* * (non-Javadoc) - * + * * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#seekEvent(org.eclipse.linuxtools .tmf.event.TmfTimestamp) */ @Override @@ -417,7 +447,7 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl // And locate the event ITmfEvent event = parseEvent(context); - while (event != null && event.getTimestamp().compareTo(timestamp, false) < 0) { + while ((event != null) && (event.getTimestamp().compareTo(timestamp, false) < 0)) { getNextEvent(context); event = parseEvent(context); } @@ -432,7 +462,7 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl /* * (non-Javadoc) - * + * * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#seekEvent(long) */ @Override @@ -460,7 +490,7 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl // And locate the event ITmfEvent event = parseEvent(context); long pos = context.getRank(); - while (event != null && pos++ < rank) { + while ((event != null) && (pos++ < rank)) { getNextEvent(context); event = parseEvent(context); } @@ -504,7 +534,7 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl // int trace = context.getLastTrace(); // // StringBuffer result = new StringBuffer("Ctx: " + (isBefore ? "B " : "A ")); -// +// // result.append("[Ctx: fLoc= " + context0.getLocation().toString() + ", fRnk= " + context0.getRank() + "] "); // result.append("[Evt: " + event0.getTimestamp().toString() + "] "); // result.append("[Loc: fLoc= " + location0.getLocation()[0].toString() + ", fRnk= " + location0.getRanks()[0] + "] "); @@ -514,7 +544,7 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl /** * Scan the next events from all traces and return the next one in chronological order. - * + * * @param context the trace context * @return the next event */ @@ -559,7 +589,7 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl } else { for (int i = 0; i < eventArray.length; i++) { ITmfEvent event = eventArray[i]; - if (event != null && event.getTimestamp() != null) { + if ((event != null) && (event.getTimestamp() != null)) { ITmfTimestamp otherTS = event.getTimestamp(); if (otherTS.compareTo(timestamp, true) < 0) { trace = i; @@ -599,7 +629,7 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl public synchronized void updateIndex(ITmfContext context, ITmfTimestamp timestamp) { // Build the index as we go along long rank = context.getRank(); - if (context.isValidRank() && (rank % fIndexPageSize) == 0) { + if (context.isValidRank() && ((rank % fIndexPageSize) == 0)) { // Determine the table position long position = rank / fIndexPageSize; // Add new entry at proper location (if empty) @@ -614,7 +644,7 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl /* * (non-Javadoc) - * + * * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#parseEvent(org.eclipse.linuxtools .tmf.trace.TmfContext) */ @Override @@ -646,7 +676,7 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl ITmfTimestamp timestamp = TmfTimestamp.BIG_CRUNCH; for (int i = 0; i < expContext.getTraces().length; i++) { ITmfEvent event = expContext.getEvents()[i]; - if (event != null && event.getTimestamp() != null) { + if ((event != null) && (event.getTimestamp() != null)) { ITmfTimestamp otherTS = event.getTimestamp(); if (otherTS.compareTo(timestamp, true) < 0) { trace = i; @@ -665,7 +695,7 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl /* * (non-Javadoc) - * + * * @see java.lang.Object#toString() */ @Override @@ -717,11 +747,11 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl if (trace.getStartTime().compareTo(startTimestamp) < 0) { startTimestamp = trace.getStartTime(); } - if (trace.getStreamingInterval() != 0 && trace.getEndTime().compareTo(endTimestamp) > 0) { + if ((trace.getStreamingInterval() != 0) && (trace.getEndTime().compareTo(endTimestamp) > 0)) { endTimestamp = trace.getEndTime(); } } - if (safeTimestamp != null && safeTimestamp.compareTo(getTimeRange().getEndTime(), false) > 0) { + if ((safeTimestamp != null) && (safeTimestamp.compareTo(getTimeRange().getEndTime(), false) > 0)) { timeRange = new TmfTimeRange(startTimestamp, safeTimestamp); } else { timeRange = null; @@ -759,7 +789,7 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl /* * The experiment holds the globally ordered events of its set of traces. It is expected to provide access to each * individual event by index i.e. it must be possible to request the Nth event of the experiment. - * + * * The purpose of the index is to keep the information needed to rapidly restore the traces contexts at regular * intervals (every INDEX_PAGE_SIZE event). */ @@ -844,10 +874,11 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl super.handleData(event); if (event != null) { ITmfTimestamp ts = event.getTimestamp(); - if (startTime == null) + if (startTime == null) { startTime = ts.clone(); + } lastTime = ts.clone(); - if ((getNbRead() % fIndexPageSize) == 1 && getNbRead() != 1) { + if (((getNbRead() % fIndexPageSize) == 1) && (getNbRead() != 1)) { updateExperiment(); } } @@ -901,12 +932,13 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl }; sendRequest((ITmfDataRequest<T>) request); - if (waitForCompletion) + if (waitForCompletion) { try { request.waitForCompletion(); } catch (InterruptedException e) { e.printStackTrace(); } + } } protected void notifyListeners() { @@ -929,11 +961,11 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl @TmfSignalHandler public void endSync(TmfEndSynchSignal signal) { - if (fEndSynchReference != null && fEndSynchReference.intValue() == signal.getReference()) { + if ((fEndSynchReference != null) && (fEndSynchReference.intValue() == signal.getReference())) { fEndSynchReference = null; initializeStreamingMonitor(); } - + } @TmfSignalHandler diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperimentContext.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperimentContext.java index 4e8e65f..36a38df 100644 --- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperimentContext.java +++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperimentContext.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2009, 2010 Ericsson - * + * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which * accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: * Francois Chouinard - Initial API and implementation *******************************************************************************/ @@ -26,7 +26,7 @@ import org.eclipse.linuxtools.tmf.core.trace.TmfContext; * <p> * This implies that the "next" event from each trace has already been * read and that we at least know its timestamp. This doesn't imply that a - * full parse of the event content was performed (read: LTTng works like + * full parse of the event content was performed (read: LTTng works like * this). * <p> * The last trace refers to the trace from which the last event was @@ -37,7 +37,7 @@ public class TmfExperimentContext extends TmfContext { // ------------------------------------------------------------------------ // Constants // ------------------------------------------------------------------------ - + public static final int NO_TRACE = -1; // ------------------------------------------------------------------------ @@ -46,6 +46,7 @@ public class TmfExperimentContext extends TmfContext { private ITmfTrace<?>[] fTraces = new ITmfTrace[0]; private ITmfContext[] fContexts; + private final ITmfContext[] fContexts; private ITmfEvent[] fEvents; private int lastTraceRead; @@ -69,7 +70,7 @@ public class TmfExperimentContext extends TmfContext { rank += contexts[i].getRank(); } } - + setLocation(new TmfExperimentLocation(new TmfLocationArray(locations), ranks)); setRank(rank); lastTraceRead = NO_TRACE; @@ -82,16 +83,18 @@ public class TmfExperimentContext extends TmfContext { public TmfExperimentContext(TmfExperimentContext other) { this(other.fTraces, other.cloneContexts()); fEvents = other.fEvents; - if (other.getLocation() != null) - setLocation(other.getLocation().clone()); + if (other.getLocation() != null) { + setLocation(other.getLocation().clone()); + } setRank(other.getRank()); setLastTrace(other.lastTraceRead); } private ITmfContext[] cloneContexts() { - ITmfContext[] contexts = new TmfContext[fContexts.length]; - for (int i = 0; i < fContexts.length; i++) - contexts[i] = fContexts[i].clone(); + ITmfContext[] contexts = new ITmfContext[fContexts.length]; + for (int i = 0; i < fContexts.length; i++) { + contexts[i] = fContexts[i].clone(); + } return contexts; } @@ -127,30 +130,32 @@ public class TmfExperimentContext extends TmfContext { public int hashCode() { int result = 17; for (int i = 0; i < fTraces.length; i++) { - result = 37 * result + fTraces[i].hashCode(); - result = 37 * result + fContexts[i].hashCode(); + result = (37 * result) + fTraces[i].hashCode(); + result = (37 * result) + fContexts[i].hashCode(); } return result; } - + @Override public boolean equals(Object other) { - if (this == other) + if (this == other) { return true; - if (!super.equals(other)) + } + if (!super.equals(other)) { return false; + } if (!(other instanceof TmfExperimentContext)) { return false; } TmfExperimentContext o = (TmfExperimentContext) other; boolean isEqual = true; int i = 0; - while (isEqual && i < fTraces.length) { + while (isEqual && (i < fTraces.length)) { isEqual &= fTraces[i].equals(o.fTraces[i]); isEqual &= fContexts[i].equals(o.fContexts[i]); i++; } return isEqual; } - + } diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomEventsTable.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomEventsTable.java index 5ca2618..8dd4b95 100644 --- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomEventsTable.java +++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomEventsTable.java @@ -1,11 +1,11 @@ /*******************************************************************************
* Copyright (c) 2010 Ericsson
- *
+ *
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* Patrick Tasse - Initial API and implementation
*******************************************************************************/
@@ -16,7 +16,7 @@ import java.util.LinkedList; import java.util.List;
import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTraceDefinition.OutputColumn;
-import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable;
import org.eclipse.linuxtools.tmf.ui.widgets.ColumnData;
@@ -25,8 +25,8 @@ import org.eclipse.swt.widgets.Composite; public class CustomEventsTable extends TmfEventsTable {
- private CustomTraceDefinition fDefinition;
-
+ private final CustomTraceDefinition fDefinition;
+
public CustomEventsTable(CustomTraceDefinition definition, Composite parent, int cacheSize) {
super(parent, cacheSize, new ColumnData[0]);
fDefinition = definition;
@@ -34,18 +34,19 @@ public class CustomEventsTable extends TmfEventsTable { }
protected void createColumnHeaders() {
- if (fDefinition == null)
- return;
+ if (fDefinition == null) {
+ return;
+ }
List<ColumnData> columnData = new LinkedList<ColumnData>();
for (OutputColumn outputColumn : fDefinition.outputs) {
ColumnData column = new ColumnData(outputColumn.name, 0, SWT.LEFT);
columnData.add(column);
}
- setColumnHeaders((ColumnData[]) columnData.toArray(new ColumnData[0]));
+ setColumnHeaders(columnData.toArray(new ColumnData[0]));
}
@Override
- public TmfEventField[] extractItemFields(TmfEvent event) {
+ public TmfEventField[] extractItemFields(ITmfEvent event) {
if (event instanceof CustomEvent) {
TmfEventField[] fields = ((CustomEvent) event).extractItemFields();
// String[] labels = new String[fields.length];
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsCache.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsCache.java index a3f39bd..adefd6f 100644 --- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsCache.java +++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsCache.java @@ -1,11 +1,11 @@ /*******************************************************************************
* Copyright (c) 2011 Ericsson
- *
+ *
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* Patrick Tasse - Initial API and implementation
******************************************************************************/
@@ -19,7 +19,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.linuxtools.tmf.core.component.ITmfDataProvider;
-import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
import org.eclipse.linuxtools.tmf.core.filter.ITmfFilter;
import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
@@ -27,34 +27,34 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; public class TmfEventsCache {
public static class CachedEvent {
- TmfEvent event;
+ ITmfEvent event;
long rank;
- public CachedEvent (TmfEvent event, long rank) {
- this.event = event;
+ public CachedEvent (ITmfEvent iTmfEvent, long rank) {
+ this.event = iTmfEvent;
this.rank = rank;
}
}
- private CachedEvent[] fCache;
+ private final CachedEvent[] fCache;
private int fCacheStartIndex = 0;
private int fCacheEndIndex = 0;
private ITmfTrace<?> fTrace;
- private TmfEventsTable fTable;
+ private final TmfEventsTable fTable;
private ITmfFilter fFilter;
- private ArrayList<Integer> fFilterIndex = new ArrayList<Integer>(); // contains the event rank at each 'cache size' filtered events
+ private final ArrayList<Integer> fFilterIndex = new ArrayList<Integer>(); // contains the event rank at each 'cache size' filtered events
public TmfEventsCache(int cacheSize, TmfEventsTable table) {
fCache = new CachedEvent[cacheSize];
fTable = table;
}
-
+
public void setTrace(ITmfTrace<?> trace) {
fTrace = trace;
clear();
}
-
+
public synchronized void clear() {
fCacheStartIndex = 0;
fCacheEndIndex = 0;
@@ -65,12 +65,12 @@ public class TmfEventsCache { fFilter = filter;
clear();
}
-
+
public void clearFilter() {
fFilter = null;
clear();
}
-
+
public synchronized CachedEvent getEvent(int index) {
if ((index >= fCacheStartIndex) && (index < fCacheEndIndex)) {
int i = index - fCacheStartIndex;
@@ -87,8 +87,8 @@ public class TmfEventsCache { }
return null;
}
-
- public synchronized void storeEvent(TmfEvent event, long rank, int index) {
+
+ public synchronized void storeEvent(ITmfEvent event, long rank, int index) {
if (fCacheStartIndex == fCacheEndIndex) {
fCacheStartIndex = index;
fCacheEndIndex = index;
@@ -100,28 +100,28 @@ public class TmfEventsCache { fCacheEndIndex++;
}
}
- if (fFilter != null && index % fCache.length == 0) {
+ if ((fFilter != null) && ((index % fCache.length) == 0)) {
int i = index / fCache.length;
fFilterIndex.add(i, Integer.valueOf((int) rank));
}
}
-
+
@SuppressWarnings("unchecked")
public synchronized int getFilteredEventIndex(final long rank) {
int current;
int startRank;
- TmfDataRequest<TmfEvent> request;
+ TmfDataRequest<ITmfEvent> request;
synchronized (this) {
int start = 0;
int end = fFilterIndex.size();
-
- if (fCacheEndIndex - fCacheStartIndex > 1) {
+
+ if ((fCacheEndIndex - fCacheStartIndex) > 1) {
if (rank < fCache[0].rank) {
- end = fCacheStartIndex / fCache.length + 1;
+ end = (fCacheStartIndex / fCache.length) + 1;
} else if (rank > fCache[fCacheEndIndex - fCacheStartIndex - 1].rank) {
start = fCacheEndIndex / fCache.length;
} else {
- for (int i = 0; i < fCacheEndIndex - fCacheStartIndex; i++) {
+ for (int i = 0; i < (fCacheEndIndex - fCacheStartIndex); i++) {
if (fCache[i].rank >= rank) {
return fCacheStartIndex + i;
}
@@ -129,7 +129,7 @@ public class TmfEventsCache { return fCacheEndIndex;
}
}
-
+
current = (start + end) / 2;
while (current != start) {
if (rank < fFilterIndex.get(current)) {
@@ -142,23 +142,25 @@ public class TmfEventsCache { }
startRank = fFilterIndex.get(current);
}
-
+
final int index = current * fCache.length;
-
- class DataRequest<T extends TmfEvent> extends TmfDataRequest<T> {
+
+ class DataRequest<T extends ITmfEvent> extends TmfDataRequest<T> {
int fRank;
int fIndex;
-
+
DataRequest(Class<T> dataType, int start, int nbRequested) {
super(dataType, start, nbRequested);
fRank = start;
fIndex = index;
}
-
+
@Override
public void handleData(T event) {
super.handleData(event);
- if (isCancelled()) return;
+ if (isCancelled()) {
+ return;
+ }
if (fRank >= rank) {
cancel();
return;
@@ -173,21 +175,21 @@ public class TmfEventsCache { return fIndex;
}
}
-
- request = new DataRequest<TmfEvent>(TmfEvent.class, startRank, TmfDataRequest.ALL_DATA);
- ((ITmfDataProvider<TmfEvent>) fTrace).sendRequest(request);
+
+ request = new DataRequest<ITmfEvent>(ITmfEvent.class, startRank, TmfDataRequest.ALL_DATA);
+ ((ITmfDataProvider<ITmfEvent>) fTrace).sendRequest(request);
try {
request.waitForCompletion();
- return ((DataRequest<TmfEvent>) request).getFilteredIndex();
+ return ((DataRequest<ITmfEvent>) request).getFilteredIndex();
} catch (InterruptedException e) {
}
return 0;
}
-
+
// ------------------------------------------------------------------------
// Event cache population
// ------------------------------------------------------------------------
-
+
// The event fetching job
private Job job;
private synchronized void populateCache(final int index) {
@@ -196,14 +198,14 @@ public class TmfEventsCache { * 1. The job must exist
* 2. It must be running (i.e. not completed)
* 3. The requested index must be within the cache range
- *
+ *
* If the job meets these conditions, we simply exit.
* Otherwise, we create a new job but we might have to cancel
* an existing job for an obsolete range.
*/
if (job != null) {
if (job.getState() != Job.NONE) {
- if (index >= fCacheStartIndex && index < (fCacheStartIndex + fCache.length)) {
+ if ((index >= fCacheStartIndex) && (index < (fCacheStartIndex + fCache.length))) {
return;
}
// The new index is out of the requested range
@@ -211,7 +213,7 @@ public class TmfEventsCache { job.cancel();
}
}
-
+
fCacheStartIndex = index;
fCacheEndIndex = index;
@@ -233,12 +235,12 @@ public class TmfEventsCache { skipCount = index - (i * fCache.length);
}
}
-
- TmfDataRequest<TmfEvent> request = new TmfDataRequest<TmfEvent>(TmfEvent.class, startIndex, nbRequested) {
+
+ TmfDataRequest<ITmfEvent> request = new TmfDataRequest<ITmfEvent>(ITmfEvent.class, startIndex, nbRequested) {
private int count = 0;
private long rank = startIndex;
@Override
- public void handleData(TmfEvent event) {
+ public void handleData(ITmfEvent event) {
// If the job is canceled, cancel the request so waitForCompletion() will unlock
if (monitor.isCanceled()) {
cancel();
@@ -246,7 +248,7 @@ public class TmfEventsCache { }
super.handleData(event);
if (event != null) {
- if ((fFilter == null || fFilter.matches(event)) && skipCount-- <= 0) {
+ if (((fFilter == null) || fFilter.matches(event)) && (skipCount-- <= 0)) {
synchronized (TmfEventsCache.this) {
fCache[count] = new CachedEvent(event.clone(), rank);
count++;
@@ -259,14 +261,14 @@ public class TmfEventsCache { }
if (count >= fCache.length) {
cancel();
- } else if (fFilter != null && count >= fTable.getTable().getItemCount() - 3) { // -1 for header row, -2 for top and bottom filter status rows
+ } else if ((fFilter != null) && (count >= (fTable.getTable().getItemCount() - 3))) { // -1 for header row, -2 for top and bottom filter status rows
cancel();
}
rank++;
}
};
- ((ITmfDataProvider<TmfEvent>) fTrace).sendRequest(request);
+ ((ITmfDataProvider<ITmfEvent>) fTrace).sendRequest(request);
try {
request.waitForCompletion();
} catch (InterruptedException e) {
@@ -274,7 +276,7 @@ public class TmfEventsCache { }
fTable.cacheUpdated(true);
-
+
// Flag the UI thread that the cache is ready
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsTable.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsTable.java index 5d0abfe..c5dbf74 100644 --- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsTable.java +++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsTable.java @@ -1,11 +1,11 @@ /*******************************************************************************
* Copyright (c) 2010 Ericsson
- *
+ *
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* Francois Chouinard - Initial API and implementation
* Patrick Tasse - Factored out from events view
@@ -197,7 +197,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS private boolean fCacheUpdateBusy = false;
private boolean fCacheUpdatePending = false;
private boolean fCacheUpdateCompleted = false;
- private Object fCacheUpdateSyncObj = new Object();
+ private final Object fCacheUpdateSyncObj = new Object();
private boolean fDisposeOnClose;
@@ -292,7 +292,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS }
if (fTable.getData(Key.FILTER_OBJ) != null) {
- if (event.index == 1 || event.index == fTable.getItemCount() - 1) {
+ if ((event.index == 1) || (event.index == (fTable.getItemCount() - 1))) {
setFilterStatusRowItemData(item);
return;
}
@@ -350,7 +350,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS if (!bounds.contains(event.x,event.y)) {
return;
}
- if (tooltipShell != null && !tooltipShell.isDisposed()) {
+ if ((tooltipShell != null) && !tooltipShell.isDisposed()) {
tooltipShell.dispose();
}
tooltipShell = new Shell(fTable.getShell(), SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL);
@@ -423,7 +423,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS return;
}
TableItem[] selection = fTable.getSelection();
- if (selection != null && selection.length > 0) {
+ if ((selection != null) && (selection.length > 0)) {
TmfTimestamp ts = (TmfTimestamp) fTable.getSelection()[0].getData(Key.TIMESTAMP);
if (ts != null) {
broadcast(new TmfTimeSynchSignal(fTable, ts));
@@ -533,10 +533,10 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS if (item != null) {
Rectangle imageBounds = item.getImageBounds(0);
imageBounds.width = BOOKMARK_IMAGE.getBounds().width;
- if (point.x <= imageBounds.x + imageBounds.width) {
+ if (point.x <= (imageBounds.x + imageBounds.width)) {
// Right-click on left margin
Long rank = (Long) item.getData(Key.RANK);
- if (rank != null && fBookmarksFile != null) {
+ if ((rank != null) && (fBookmarksFile != null)) {
if (fBookmarksMap.containsKey(rank)) {
tablePopupMenu.add(new ToggleBookmarkAction(
Messages.TmfEventsTable_RemoveBookmarkActionText, rank));
@@ -626,7 +626,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS stopFilterThread();
ColorSettingsManager.removeColorSettingsListener(this);
fComposite.dispose();
- if (fTrace != null && fDisposeOnClose) {
+ if ((fTrace != null) && fDisposeOnClose) {
fTrace.dispose();
}
fResourceManager.dispose();
@@ -643,14 +643,14 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS /**
* @param columnData
- *
+ *
* FIXME: Add support for column selection
*/
protected void setColumnHeaders(ColumnData[] columnData) {
fTable.setColumnHeaders(columnData);
}
- protected void setItemData(TableItem item, TmfEvent event, long rank) {
+ protected void setItemData(TableItem item, ITmfEvent event, long rank) {
ITmfEventField[] fields = extractItemFields(event);
String[] content = new String[fields.length];
for (int i = 0; i < fields.length; i++) {
@@ -739,7 +739,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS protected void setFilterStatusRowItemData(TableItem item) {
for (int i = 0; i < fTable.getColumns().length; i++) {
if (i == 0) {
- if (fTrace == null || fFilterCheckCount == fTrace.getNbEvents()) {
+ if ((fTrace == null) || (fFilterCheckCount == fTrace.getNbEvents())) {
item.setImage(FILTER_IMAGE);
} else {
item.setImage(STOP_IMAGE);
@@ -778,7 +778,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS item = fTable.getItem(point);
// Header row selected
- if (item != null && fTable.indexOf(item) == 0) {
+ if ((item != null) && (fTable.indexOf(item) == 0)) {
// Icon selected
if (item.getImageBounds(0).contains(point)) {
@@ -1044,7 +1044,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS private TmfEventRequest<TmfEvent> request;
private boolean refreshBusy = false;
private boolean refreshPending = false;
- private Object syncObj = new Object();
+ private final Object syncObj = new Object();
public FilterThread(ITmfFilterTreeNode filter) {
super("Filter Thread"); //$NON-NLS-1$
@@ -1066,15 +1066,16 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS @Override
public void handleData(TmfEvent event) {
super.handleData(event);
- if (request.isCancelled())
+ if (request.isCancelled()) {
return;
+ }
if (filter.matches(event)) {
long rank = fFilterCheckCount;
int index = (int) fFilterMatchCount;
fFilterMatchCount++;
fCache.storeEvent(event.clone(), rank, index);
refreshTable();
- } else if (fFilterCheckCount % 100 == 0) {
+ } else if ((fFilterCheckCount % 100) == 0) {
refreshTable();
}
fFilterCheckCount++;
@@ -1100,10 +1101,12 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
- if (request.isCancelled())
+ if (request.isCancelled()) {
return;
- if (fTable.isDisposed())
+ }
+ if (fTable.isDisposed()) {
return;
+ }
fTable.setItemCount((int) fFilterMatchCount + 3); // +1 for header row, +2 for top and bottom filter
// status rows
fTable.refresh();
@@ -1215,7 +1218,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS final Display display = Display.getDefault();
if (startIndex < 0) {
rank = (int) fTrace.getNbEvents() - 1;
- } else if (startIndex >= fTable.getItemCount() - (eventFilter == null ? 1 : 3)) { // -1 for header row, -2
+ } else if (startIndex >= (fTable.getItemCount() - (eventFilter == null ? 1 : 3))) { // -1 for header row, -2
// for top and bottom
// filter status rows
rank = 0;
@@ -1227,7 +1230,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS break;
}
rank = event.rank;
- if (searchFilter.matches(event.event) && (eventFilter == null || eventFilter.matches(event.event))) {
+ if (searchFilter.matches(event.event) && ((eventFilter == null) || eventFilter.matches(event.event))) {
foundRank = event.rank;
break;
}
@@ -1240,7 +1243,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS if (foundRank == -1) {
if (direction == Direction.FORWARD) {
rank++;
- if (rank > fTrace.getNbEvents() - 1) {
+ if (rank > (fTrace.getNbEvents() - 1)) {
rank = 0;
}
} else {
@@ -1253,11 +1256,12 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS }
int startRank = (int) rank;
boolean wrapped = false;
- while (!monitor.isCanceled() && foundRank == -1 && fTrace != null) {
+ while (!monitor.isCanceled() && (foundRank == -1) && (fTrace != null)) {
int nbRequested = (direction == Direction.FORWARD ? Integer.MAX_VALUE : Math.min((int) rank + 1,
fTrace.getIndexPageSize()));
if (direction == Direction.BACKWARD) {
rank = Math.max(0, rank - fTrace.getIndexPageSize() + 1);
+
}
request = new TmfDataRequest<TmfEvent>(TmfEvent.class, (int) rank, nbRequested) {
long currentRank = rank;
@@ -1265,7 +1269,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS @Override
public void handleData(TmfEvent event) {
super.handleData(event);
- if (searchFilter.matches(event) && (eventFilter == null || eventFilter.matches(event))) {
+ if (searchFilter.matches(event) && ((eventFilter == null) || eventFilter.matches(event))) {
foundRank = currentRank;
if (direction == Direction.FORWARD) {
done();
@@ -1305,7 +1309,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS rank = (int) fTrace.getNbEvents() - 1;
wrapped = true;
}
- if (rank <= startRank && wrapped) {
+ if ((rank <= startRank) && wrapped) {
synchronized (fSearchSyncObj) {
fSearchThread = null;
}
@@ -1324,10 +1328,12 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS display.asyncExec(new Runnable() {
@Override
public void run() {
- if (monitor.isCanceled())
+ if (monitor.isCanceled()) {
return;
- if (fTable.isDisposed())
+ }
+ if (fTable.isDisposed()) {
return;
+ }
fTable.setSelection(selection);
fSelectedRank = foundRank;
synchronized (fSearchSyncObj) {
@@ -1355,8 +1361,9 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS }
protected void packColumns() {
- if (fPackDone)
+ if (fPackDone) {
return;
+ }
for (TableColumn column : fTable.getColumns()) {
int headerWidth = column.getWidth();
column.pack();
@@ -1370,10 +1377,10 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS /**
* @param event
* @return
- *
+ *
* FIXME: Add support for column selection
*/
- protected ITmfEventField[] extractItemFields(TmfEvent event) {
+ protected ITmfEventField[] extractItemFields(ITmfEvent event) {
ITmfEventField[] fields = new TmfEventField[0];
if (event != null) {
String timestamp = ((Long) event.getTimestamp().getValue()).toString();
@@ -1403,7 +1410,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS * true if the trace should be disposed when the table is disposed
*/
public void setTrace(ITmfTrace<?> trace, boolean disposeOnClose) {
- if (fTrace != null && fDisposeOnClose) {
+ if ((fTrace != null) && fDisposeOnClose) {
fTrace.dispose();
}
fTrace = trace;
@@ -1418,7 +1425,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS fTable.removeAll();
fCache.setTrace(fTrace); // Clear the cache
if (fTrace != null) {
- if (!fTable.isDisposed() && fTrace != null) {
+ if (!fTable.isDisposed() && (fTrace != null)) {
if (fTable.getData(Key.FILTER_OBJ) == null) {
fTable.setItemCount((int) fTrace.getNbEvents() + 1); // +1 for header row
} else {
@@ -1590,7 +1597,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS /*
* (non-Javadoc)
- *
+ *
* @see
* org.eclipse.linuxtools.tmf.ui.views.colors.IColorSettingsListener#colorSettingsChanged(org.eclipse.linuxtools
* .tmf.ui.views.colors.ColorSetting[])
@@ -1618,16 +1625,17 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS @TmfSignalHandler
public void experimentUpdated(TmfExperimentUpdatedSignal signal) {
- if ((signal.getExperiment() != fTrace) || fTable.isDisposed())
+ if ((signal.getExperiment() != fTrace) || fTable.isDisposed()) {
return;
+ }
// Perform the refresh on the UI thread
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
- if (!fTable.isDisposed() && fTrace != null) {
+ if (!fTable.isDisposed() && (fTrace != null)) {
if (fTable.getData(Key.FILTER_OBJ) == null) {
fTable.setItemCount((int) fTrace.getNbEvents() + 1); // +1 for header row
- if (fPendingGotoRank != -1 && fPendingGotoRank + 1 < fTable.getItemCount()) { // +1 for header row
+ if ((fPendingGotoRank != -1) && ((fPendingGotoRank + 1) < fTable.getItemCount())) { // +1 for header row
fTable.setSelection((int) fPendingGotoRank + 1); // +1 for header row
fPendingGotoRank = -1;
}
@@ -1635,7 +1643,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS startFilterThread();
}
}
- if (!fRawViewer.isDisposed() && fTrace != null) {
+ if (!fRawViewer.isDisposed() && (fTrace != null)) {
fRawViewer.refreshEventCount();
}
}
@@ -1644,16 +1652,17 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS @TmfSignalHandler
public void traceUpdated(TmfTraceUpdatedSignal signal) {
- if ((signal.getTrace() != fTrace) || fTable.isDisposed())
+ if ((signal.getTrace() != fTrace) || fTable.isDisposed()) {
return;
+ }
// Perform the refresh on the UI thread
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
- if (!fTable.isDisposed() && fTrace != null) {
+ if (!fTable.isDisposed() && (fTrace != null)) {
if (fTable.getData(Key.FILTER_OBJ) == null) {
fTable.setItemCount((int) fTrace.getNbEvents() + 1); // +1 for header row
- if (fPendingGotoRank != -1 && fPendingGotoRank + 1 < fTable.getItemCount()) { // +1 for header row
+ if ((fPendingGotoRank != -1) && ((fPendingGotoRank + 1) < fTable.getItemCount())) { // +1 for header row
fTable.setSelection((int) fPendingGotoRank + 1); // +1 for header row
fPendingGotoRank = -1;
}
@@ -1661,7 +1670,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS startFilterThread();
}
}
- if (!fRawViewer.isDisposed() && fTrace != null) {
+ if (!fRawViewer.isDisposed() && (fTrace != null)) {
fRawViewer.refreshEventCount();
}
}
@@ -1712,12 +1721,14 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS @Override
public void run() {
// Return if table is disposed
- if (fTable.isDisposed())
+ if (fTable.isDisposed()) {
return;
+ }
int index = (int) rank;
- if (fTable.isDisposed())
+ if (fTable.isDisposed()) {
return;
+ }
if (fTable.getData(Key.FILTER_OBJ) != null) {
index = fCache.getFilteredEventIndex(rank) + 1; // +1 for top filter status row
}
@@ -1738,7 +1749,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS /**
* Display an exception in a message box
- *
+ *
* @param e the exception
*/
private void displayException(Exception e) {
|

