From 44d7b6f393bb60fe6e1bd2cde923ca4331ed6b31 Mon Sep 17 00:00:00 2001 From: Nils Christian Ehmke <nie@informatik.uni-kiel.de> Date: Tue, 16 Dec 2014 11:16:37 +0100 Subject: [PATCH] Added some comparators; Minor refactoring to the execution entries --- .../model/domain/AbstractExecutionEntry.java | 80 +++++++++++++++++++ .../domain/AggregatedExecutionEntry.java | 63 ++------------- .../gui/model/domain/ExecutionEntry.java | 74 +---------------- .../java/kieker/gui/view/TracesSubView.java | 4 + .../ExecutionEntryContainerComparator.java | 19 +++++ .../util/ExecutionEntryTraceIDComparator.java | 19 +++++ 6 files changed, 130 insertions(+), 129 deletions(-) create mode 100644 src/main/java/kieker/gui/model/domain/AbstractExecutionEntry.java create mode 100644 src/main/java/kieker/gui/view/util/ExecutionEntryContainerComparator.java create mode 100644 src/main/java/kieker/gui/view/util/ExecutionEntryTraceIDComparator.java diff --git a/src/main/java/kieker/gui/model/domain/AbstractExecutionEntry.java b/src/main/java/kieker/gui/model/domain/AbstractExecutionEntry.java new file mode 100644 index 00000000..28089c44 --- /dev/null +++ b/src/main/java/kieker/gui/model/domain/AbstractExecutionEntry.java @@ -0,0 +1,80 @@ +package kieker.gui.model.domain; + +import java.util.ArrayList; +import java.util.List; + +public abstract class AbstractExecutionEntry<T extends AbstractExecutionEntry<T>> { + + protected final String container; + protected final String component; + protected final String operation; + + protected String failedCause; + protected T parent; + protected final List<T> children = new ArrayList<>(); + + public AbstractExecutionEntry(final String container, final String component, final String operation) { + this.container = container; + this.component = component; + this.operation = operation; + } + + public int getTraceDepth() { + int traceDepth = this.children.isEmpty() ? 0 : 1; + + int maxChildrenTraceDepth = 0; + for (final T child : this.children) { + maxChildrenTraceDepth = Math.max(maxChildrenTraceDepth, child.getTraceDepth()); + } + traceDepth += maxChildrenTraceDepth; + + return traceDepth; + } + + public int getTraceSize() { + int traceSize = 1; + + for (final T child : this.children) { + traceSize += child.getTraceSize(); + } + return traceSize; + } + + public boolean isFailed() { + return (this.failedCause != null); + } + + public String getFailedCause() { + return this.failedCause; + } + + public void setFailedCause(final String failedCause) { + this.failedCause = failedCause; + } + + public String getContainer() { + return this.container; + } + + public String getComponent() { + return this.component; + } + + public String getOperation() { + return this.operation; + } + + public List<T> getChildren() { + return this.children; + } + + public void addExecutionEntry(final T entry) { + this.children.add(entry); + entry.parent = (T) this; + } + + public T getParent() { + return this.parent; + } + +} diff --git a/src/main/java/kieker/gui/model/domain/AggregatedExecutionEntry.java b/src/main/java/kieker/gui/model/domain/AggregatedExecutionEntry.java index b48d7564..39e0afcf 100644 --- a/src/main/java/kieker/gui/model/domain/AggregatedExecutionEntry.java +++ b/src/main/java/kieker/gui/model/domain/AggregatedExecutionEntry.java @@ -16,69 +16,23 @@ package kieker.gui.model.domain; -import java.util.ArrayList; -import java.util.List; +public final class AggregatedExecutionEntry extends AbstractExecutionEntry<AggregatedExecutionEntry> { -public final class AggregatedExecutionEntry { - - private final List<AggregatedExecutionEntry> children = new ArrayList<>(); - private final String failedCause; - private final String container; - private final String component; - private final String operation; private long minDuration; private long maxDuration; private long avgDuration; private int calls; public AggregatedExecutionEntry(final ExecutionEntry execEntry) { - this.container = execEntry.getContainer(); - this.component = execEntry.getComponent(); - this.operation = execEntry.getOperation(); - this.failedCause = execEntry.getFailedCause(); + super(execEntry.getContainer(), execEntry.getComponent(), execEntry.getOperation()); + + this.setFailedCause(execEntry.getFailedCause()); this.minDuration = execEntry.getDuration(); this.maxDuration = execEntry.getDuration(); for (final ExecutionEntry child : execEntry.getChildren()) { - this.children.add(new AggregatedExecutionEntry(child)); - } - } - - public int getTraceDepth() { - int traceDepth = this.children.isEmpty() ? 0 : 1; - - int maxChildrenTraceDepth = 0; - for (final AggregatedExecutionEntry child : this.children) { - maxChildrenTraceDepth = Math.max(maxChildrenTraceDepth, child.getTraceDepth()); - } - traceDepth += maxChildrenTraceDepth; - - return traceDepth; - } - - public int getTraceSize() { - int traceSize = 1; - - for (final AggregatedExecutionEntry child : this.children) { - traceSize += child.getTraceSize(); + super.addExecutionEntry(new AggregatedExecutionEntry(child)); } - return traceSize; - } - - public List<AggregatedExecutionEntry> getChildren() { - return this.children; - } - - public String getContainer() { - return this.container; - } - - public String getComponent() { - return this.component; - } - - public String getOperation() { - return this.operation; } public void incrementCalls(final ExecutionEntry executionEntry) { @@ -108,11 +62,4 @@ public final class AggregatedExecutionEntry { return this.calls; } - public String getFailedCause() { - return this.failedCause; - } - - public boolean isFailed() { - return (this.failedCause != null); - } } diff --git a/src/main/java/kieker/gui/model/domain/ExecutionEntry.java b/src/main/java/kieker/gui/model/domain/ExecutionEntry.java index 04b42985..e79c687e 100644 --- a/src/main/java/kieker/gui/model/domain/ExecutionEntry.java +++ b/src/main/java/kieker/gui/model/domain/ExecutionEntry.java @@ -16,54 +16,23 @@ package kieker.gui.model.domain; -import java.util.ArrayList; import java.util.Iterator; -import java.util.List; /** * A simplified representation of an execution within a trace. As an instance of this class can contain other instances, it can be used to represent a trace tree. - * + * * @author Nils Christian Ehmke */ -public final class ExecutionEntry { +public final class ExecutionEntry extends AbstractExecutionEntry<ExecutionEntry> { private final long traceID; - private final String container; - private final String component; - private final String operation; private float percent; private long duration; - private String failedCause; - private ExecutionEntry parent; - private final List<ExecutionEntry> children = new ArrayList<>(); public ExecutionEntry(final long traceID, final String container, final String component, final String operation) { + super(container, component, operation); this.traceID = traceID; - this.container = container; - this.component = component; - this.operation = operation; - } - - public int getTraceDepth() { - int traceDepth = this.children.isEmpty() ? 0 : 1; - - int maxChildrenTraceDepth = 0; - for (final ExecutionEntry child : this.children) { - maxChildrenTraceDepth = Math.max(maxChildrenTraceDepth, child.getTraceDepth()); - } - traceDepth += maxChildrenTraceDepth; - - return traceDepth; - } - - public int getTraceSize() { - int traceSize = 1; - - for (final ExecutionEntry child : this.children) { - traceSize += child.getTraceSize(); - } - return traceSize; } public long getTraceID() { @@ -78,47 +47,10 @@ public final class ExecutionEntry { this.duration = duration; } - public boolean isFailed() { - return (this.failedCause != null); - } - - public String getFailedCause() { - return this.failedCause; - } - - public void setFailedCause(final String failedCause) { - this.failedCause = failedCause; - } - public float getPercent() { return this.percent; } - public String getContainer() { - return this.container; - } - - public String getComponent() { - return this.component; - } - - public String getOperation() { - return this.operation; - } - - public List<ExecutionEntry> getChildren() { - return this.children; - } - - public void addExecutionEntry(final ExecutionEntry entry) { - this.children.add(entry); - entry.parent = this; - } - - public ExecutionEntry getParent() { - return this.parent; - } - public void recalculateValues() { this.updatePercent(); } diff --git a/src/main/java/kieker/gui/view/TracesSubView.java b/src/main/java/kieker/gui/view/TracesSubView.java index 737ee89a..830a1a12 100644 --- a/src/main/java/kieker/gui/view/TracesSubView.java +++ b/src/main/java/kieker/gui/view/TracesSubView.java @@ -10,8 +10,10 @@ import kieker.gui.model.PropertiesModel; import kieker.gui.model.TracesSubViewModel; import kieker.gui.model.domain.ExecutionEntry; import kieker.gui.view.util.ExecutionEntryComponentComparator; +import kieker.gui.view.util.ExecutionEntryContainerComparator; import kieker.gui.view.util.ExecutionEntryDurationComparator; import kieker.gui.view.util.ExecutionEntryOperationComparator; +import kieker.gui.view.util.ExecutionEntryTraceIDComparator; import kieker.gui.view.util.TreeColumnSortListener; import org.eclipse.swt.SWT; @@ -173,9 +175,11 @@ public class TracesSubView implements Observer { this.tree.addSelectionListener(this.controller); this.tree.addListener(SWT.SetData, new DataProvider()); + trclmnExecutionContainer.addSelectionListener(new TreeColumnSortListener<>(new ExecutionEntryContainerComparator())); trclmnComponent.addSelectionListener(new TreeColumnSortListener<>(new ExecutionEntryComponentComparator())); trclmnOperation.addSelectionListener(new TreeColumnSortListener<>(new ExecutionEntryOperationComparator())); trclmnDuration.addSelectionListener(new TreeColumnSortListener<>(new ExecutionEntryDurationComparator())); + trclmnTraceId.addSelectionListener(new TreeColumnSortListener<>(new ExecutionEntryTraceIDComparator())); } public Tree getTree() { diff --git a/src/main/java/kieker/gui/view/util/ExecutionEntryContainerComparator.java b/src/main/java/kieker/gui/view/util/ExecutionEntryContainerComparator.java new file mode 100644 index 00000000..9095cda7 --- /dev/null +++ b/src/main/java/kieker/gui/view/util/ExecutionEntryContainerComparator.java @@ -0,0 +1,19 @@ +package kieker.gui.view.util; + +import kieker.gui.model.domain.ExecutionEntry; + +import org.eclipse.swt.SWT; + +public class ExecutionEntryContainerComparator extends AbstractDirectedComparator<ExecutionEntry> { + + @Override + public int compare(final ExecutionEntry arg0, final ExecutionEntry arg1) { + int result = arg0.getContainer().compareTo(arg1.getContainer()); + if (this.getDirection() == SWT.UP) { + result = -result; + } + return result; + + } + +} diff --git a/src/main/java/kieker/gui/view/util/ExecutionEntryTraceIDComparator.java b/src/main/java/kieker/gui/view/util/ExecutionEntryTraceIDComparator.java new file mode 100644 index 00000000..cd9dea0a --- /dev/null +++ b/src/main/java/kieker/gui/view/util/ExecutionEntryTraceIDComparator.java @@ -0,0 +1,19 @@ +package kieker.gui.view.util; + +import kieker.gui.model.domain.ExecutionEntry; + +import org.eclipse.swt.SWT; + +public class ExecutionEntryTraceIDComparator extends AbstractDirectedComparator<ExecutionEntry> { + + @Override + public int compare(final ExecutionEntry arg0, final ExecutionEntry arg1) { + int result = Long.compare(arg0.getTraceID(), arg1.getTraceID()); + if (this.getDirection() == SWT.UP) { + result = -result; + } + return result; + + } + +} -- GitLab