TraceCompletionInformationUtil { public static void initialiseLinks(TraceCompletionInformation ci, long fragmentBaseTime, Node n, StringBuilder nodeId) { TraceCompletionInformation.Communication c = new TraceCompletionInformation.Communication(); c.getIds().add(nodeId.toString()); c.setMultipleConsumers(true); c.setBaseDuration(n.getTimestamp() - fragmentBaseTime); c.setExpire(System.currentTimeMillis()+ TraceCompletionInformation.Communication.DEFAULT_EXPIRY_WINDOW_MILLIS); if (log.isLoggable(Level.FINEST)) { log.finest("Adding communication to completion information: ci=" + ci + " comms=" + c); } ci.getCommunications().add(c); if (n.getClass() == Producer.class) { List<CorrelationIdentifier> cids = n.findCorrelationIds(Scope.Interaction, Scope.ControlFlow); if (!cids.isEmpty()) { c = new TraceCompletionInformation.Communication(); for (int i = 0; i < cids.size(); i++) { c.getIds().add(cids.get(i).getValue()); } c.setMultipleConsumers(((Producer) n).multipleConsumers()); c.setBaseDuration(n.getTimestamp() - fragmentBaseTime); c.setExpire(System.currentTimeMillis() + TraceCompletionInformation.Communication.DEFAULT_EXPIRY_WINDOW_MILLIS); if (log.isLoggable(Level.FINEST)) { log.finest("Adding communication to completion information: ci=" + ci + " comms=" + c); } ci.getCommunications().add(c); } } else if (n.containerNode()) { ContainerNode cn = (ContainerNode) n; for (int i = 0; i < cn.getNodes().size(); i++) { int len = nodeId.length(); nodeId.append(':'); nodeId.append(i); initialiseLinks(ci, fragmentBaseTime, cn.getNodes().get(i), nodeId); nodeId.delete(len, nodeId.length()); } } }  static void initialiseLinks(TraceCompletionInformation ci, long fragmentBaseTime, Node n,
            StringBuilder nodeId);  }
@Test public void testInitialiseLinks() { TraceCompletionInformation ci = new TraceCompletionInformation(); long fragmentBaseTime = 100000000; Consumer consumer = new Consumer(); consumer.setTimestamp(fragmentBaseTime); Producer p1 = new Producer(); p1.setTimestamp(200000000); p1.addInteractionCorrelationId("p1id"); consumer.getNodes().add(p1); Component comp1 = new Component(); comp1.setTimestamp(300000000); consumer.getNodes().add(comp1); Producer p2 = new Producer(); p2.setTimestamp(400000000); comp1.getNodes().add(p2); Producer p3 = new Producer(); p3.setTimestamp(450000000); p3.addControlFlowCorrelationId("p3id"); p3.getProperties().add(new Property(InteractionNode.PROPERTY_PUBLISH, "true")); comp1.getNodes().add(p3); TraceCompletionInformationUtil.initialiseLinks(ci, fragmentBaseTime, consumer, new StringBuilder("trace1:0")); assertEquals(7, ci.getCommunications().size()); assertTrue(ci.getCommunications().get(0).getIds().contains("trace1:0")); assertTrue(ci.getCommunications().get(0).isMultipleConsumers()); assertEquals(consumer.getTimestamp() - fragmentBaseTime, ci.getCommunications().get(0).getBaseDuration()); assertTrue(ci.getCommunications().get(1).getIds().contains("trace1:0:0")); assertTrue(ci.getCommunications().get(1).isMultipleConsumers()); assertEquals(p1.getTimestamp() - fragmentBaseTime, ci.getCommunications().get(1).getBaseDuration()); assertTrue(ci.getCommunications().get(2).getIds().contains("p1id")); assertFalse(ci.getCommunications().get(2).isMultipleConsumers()); assertEquals(p1.getTimestamp() - fragmentBaseTime, ci.getCommunications().get(2).getBaseDuration()); assertTrue(ci.getCommunications().get(3).getIds().contains("trace1:0:1")); assertTrue(ci.getCommunications().get(3).isMultipleConsumers()); assertEquals(comp1.getTimestamp() - fragmentBaseTime, ci.getCommunications().get(3).getBaseDuration()); assertTrue(ci.getCommunications().get(4).getIds().contains("trace1:0:1:0")); assertTrue(ci.getCommunications().get(4).isMultipleConsumers()); assertEquals(p2.getTimestamp() - fragmentBaseTime, ci.getCommunications().get(4).getBaseDuration()); assertTrue(ci.getCommunications().get(5).getIds().contains("trace1:0:1:1")); assertTrue(ci.getCommunications().get(5).isMultipleConsumers()); assertEquals(p3.getTimestamp() - fragmentBaseTime, ci.getCommunications().get(5).getBaseDuration()); assertTrue(ci.getCommunications().get(6).getIds().contains("p3id")); assertTrue(ci.getCommunications().get(6).isMultipleConsumers()); assertEquals(p3.getTimestamp() - fragmentBaseTime, ci.getCommunications().get(6).getBaseDuration()); }