protected void spawnFragment(FragmentBuilder parentBuilder, Node node, int position,
                            FragmentBuilder spawnedBuilder) {
        Trace trace = parentBuilder.getTrace();
        String id = UUID.randomUUID().toString();
        String location = null;
        String uri = null;
        String operation = null;
        String type = null; // Set to null to indicate internal

        if (!trace.getNodes().isEmpty()) {
            Node rootNode = trace.getNodes().get(0);
            uri = rootNode.getUri();
            operation = rootNode.getOperation();
        }

        // Create Producer node to represent the internal connection to the spawned fragment
        Producer producer = new Producer();
        producer.setEndpointType(type);
        producer.setUri(uri);
        producer.setOperation(operation);
        producer.getCorrelationIds().add(new CorrelationIdentifier(Scope.ControlFlow, id));

        if (node != null && node.containerNode()) {
            parentBuilder.initNode(producer);
            if (position == -1) {
                ((ContainerNode)node).getNodes().add(producer);
            } else {
                ((ContainerNode)node).getNodes().add(position, producer);
            }
        } else {
            push(location, parentBuilder, producer);
            pop(location, parentBuilder, Producer.class, uri);
        }

        // Transfer relevant details to the spawned trace and builder
        Trace spawnedTrace = spawnedBuilder.getTrace();
        spawnedTrace.setTraceId(trace.getTraceId());
        spawnedTrace.setTransaction(trace.getTransaction());

        spawnedBuilder.setLevel(parentBuilder.getLevel());

        // Create Consumer node to represent other end of internal spawn link
        Consumer consumer = new Consumer();
        consumer.setEndpointType(type);
        consumer.setUri(uri);
        consumer.setOperation(operation);
        consumer.getCorrelationIds().add(new CorrelationIdentifier(Scope.ControlFlow, id));

        push(location, spawnedBuilder, consumer);

        // Pop immediately as easier than attempting to determine end of spawned scope and
        // removing it from the stack then.
        // TODO:  Could look at moving subsequent top level nodes under this Consumer
        // at the point when the fragment is recorded
        pop(location, spawnedBuilder, Consumer.class, uri);
    }
protected void spawnFragment ( FragmentBuilder parentBuilder , Node node , int position , FragmentBuilder spawnedBuilder ) { Trace trace = parentBuilder . getTrace ( ) ; String id = UUID . randomUUID ( ) . toString ( ) ; String location = null ; String uri = null ; String operation = null ; String type = null ; if ( ! trace . getNodes ( ) . isEmpty ( ) ) { Node rootNode = trace . getNodes ( ) . get ( 0 ) ; uri = rootNode . getUri ( ) ; operation = rootNode . getOperation ( ) ; } Producer producer = new Producer ( ) ; producer . setEndpointType ( type ) ; producer . setUri ( uri ) ; producer . setOperation ( operation ) ; producer . getCorrelationIds ( ) . add ( new CorrelationIdentifier ( Scope . ControlFlow , id ) ) ; if ( node != null && node . containerNode ( ) ) { parentBuilder . initNode ( producer ) ; if ( position == - 1 ) { ( ( ContainerNode ) node ) . getNodes ( ) . add ( producer ) ; } else { ( ( ContainerNode ) node ) . getNodes ( ) . add ( position , producer ) ; } } else { push ( location , parentBuilder , producer ) ; pop ( location , parentBuilder , Producer . class , uri ) ; } Trace spawnedTrace = spawnedBuilder . getTrace ( ) ; spawnedTrace . setTraceId ( trace . getTraceId ( ) ) ; spawnedTrace . setTransaction ( trace . getTransaction ( ) ) ; spawnedBuilder . setLevel ( parentBuilder . getLevel ( ) ) ; Consumer consumer = new Consumer ( ) ; consumer . setEndpointType ( type ) ; consumer . setUri ( uri ) ; consumer . setOperation ( operation ) ; consumer . getCorrelationIds ( ) . add ( new CorrelationIdentifier ( Scope . ControlFlow , id ) ) ; push ( location , spawnedBuilder , consumer ) ; pop ( location , spawnedBuilder , Consumer . class , uri ) ; }
This method creates a new linked fragment to handle some asynchronous
activities.