diff --git a/src/main/java/kieker/analysis/dev/DependencyCreatorStage.java b/src/main/java/kieker/analysis/dev/DependencyCreatorStage.java index 003d583407922944341ff2e50e52fadc4730177e..83a9bdae7082343e214d349b67217629da8c4050 100644 --- a/src/main/java/kieker/analysis/dev/DependencyCreatorStage.java +++ b/src/main/java/kieker/analysis/dev/DependencyCreatorStage.java @@ -20,6 +20,9 @@ public class DependencyCreatorStage extends AbstractTransformation<AggregatedTra // TODO Update Statistics + operationsDependency.printDependcies(); + // operationsDependency.printOperations(); + this.getOutputPort().send(operationsDependency); super.onTerminating(); diff --git a/src/main/java/kieker/analysis/dev/OperationsDependency.java b/src/main/java/kieker/analysis/dev/OperationsDependency.java index bfb6c5e197d6f3f32600b18174f64a303506a51d..72d79a3f08cd56ad601ae7381a9908c04acaf28f 100644 --- a/src/main/java/kieker/analysis/dev/OperationsDependency.java +++ b/src/main/java/kieker/analysis/dev/OperationsDependency.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import kieker.analysis.traceanalysisdomain.AggregatedOperationCall; @@ -11,54 +12,135 @@ public class OperationsDependency { // TODO Move to Domain package - private final Map<String, List<AggregatedOperationCall>> operations = new HashMap<>(); + private final Map<OperationCallWrapper, List<AggregatedOperationCall>> operations = new HashMap<>(); - private final Map<String, OperationsDependencyRelation> calls = new HashMap<>(); + private final Map<OperationsDependencyRelation, Integer> calls = new HashMap<>(); public void addCall(final AggregatedOperationCall call) { - // TODO - if (!operations.containsKey("Key")) { - operations.put("Key", new ArrayList<>()); + + // TODO Handle failed OCs as own OC? -> currently yes + + OperationCallWrapper key = new OperationCallWrapper( + new AggregatedOperationCall(call.getContainer(), call.getComponent(), call.getOperation(), 0, call.getFailedCause())); + + OperationCallWrapper parentKey = null; + if (call.getParent() != null) { + parentKey = new OperationCallWrapper(new AggregatedOperationCall(call.getParent().getContainer(), call.getParent().getComponent(), + call.getParent().getOperation(), 0, call.getParent().getFailedCause())); + } + + if (!operations.containsKey(key)) { + operations.put(key, new ArrayList<>()); } + operations.get(key).add(call); - operations.get("Key").add(call); + OperationsDependencyRelation keyEdge = new OperationsDependencyRelation(key, parentKey); - if (!calls.containsKey("Key")) { - calls.put("Key", new OperationsDependencyRelation(call.getParent(), call, call.getCalls())); + if (!calls.containsKey(keyEdge)) { + calls.put(keyEdge, 0); } + calls.replace(keyEdge, (calls.get(keyEdge) + call.getCalls())); + } + + // TODO Just for debugging + + public void printOperations() { + + System.out.println("Operations:"); + System.out.println(); + + for (Entry<OperationCallWrapper, List<AggregatedOperationCall>> call : operations.entrySet()) { - calls.get("Key").addToCalls(call.getCalls()); + System.out.println("Key:" + call.getKey().getOperationCall().getOperation() + " / " + call.getKey().getOperationCall().getFailedCause()); + System.out.println("Calls:"); + for (AggregatedOperationCall call2 : call.getValue()) { + + System.out.println(call2.getOperation()); + // System.out.println(call2.getFailedCause()); + + } + System.out.println(); + } } - private class OperationsDependencyRelation { + // TODO Just for debugging - private final AggregatedOperationCall caller; + public void printDependcies() { - private final AggregatedOperationCall callee; + System.out.println("Dependcies"); + System.out.println("Size" + calls.size()); - private int calls; + for (Entry<OperationsDependencyRelation, Integer> call : calls.entrySet()) { - public OperationsDependencyRelation(final AggregatedOperationCall caller, final AggregatedOperationCall callee, final int calls) { - this.caller = caller; - this.callee = callee; - this.calls = calls; + System.out.println("Set begin"); + + System.out.println(call.getKey().getCaller().getOperationCall().getOperation()); + System.out.println(call.getKey().getCallee().getOperationCall().getOperation()); + System.out.println(call.getValue()); + System.out.println("Set end"); + System.out.println(); } + } + + /** + * Wrapper class for {@link AggregatedOperationCall} for calculating the hash code and check equality of two {@link AggregatedOperationCall}. + * + * @author Sören Henning + * + */ + private static class OperationCallWrapper { - public void addToCalls(final int calls) { - this.calls += calls; + private final AggregatedOperationCall operationCall; + + public OperationCallWrapper(final AggregatedOperationCall operationCall) { + this.operationCall = operationCall; + } + + public AggregatedOperationCall getOperationCall() { + return operationCall; + } + + @Override + public int hashCode() { + return this.operationCall.calculateHashCode(); + } + + @Override + public boolean equals(final Object obj) { + if (!(obj instanceof OperationCallWrapper)) { + return false; + } + return this.operationCall.isEqualTo(((OperationCallWrapper) obj).operationCall); + } + + } + + /** + * Relation between two {@link AggregatedOperationCall}. If this class will be + * extended by more attributes, new hashCode() and equals() methods are required. + * + * @author Sören Henning + * + */ + private class OperationsDependencyRelation { + + private final OperationCallWrapper caller; + + private final OperationCallWrapper callee; + + public OperationsDependencyRelation(final OperationCallWrapper caller, final OperationCallWrapper callee) { + this.caller = caller; + this.callee = callee; } - public AggregatedOperationCall getCaller() { + public OperationCallWrapper getCaller() { return caller; } - public AggregatedOperationCall getCallee() { + public OperationCallWrapper getCallee() { return callee; } - public int getCalls() { - return calls; - } } }