private boolean stream()

in aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/strategy/DefaultStreamingStrategy.java [94:126]


    private boolean stream(Entity entity, Emitter emitter) {
        ArrayList<Subsegment> children = new ArrayList<>(entity.getSubsegments());
        ArrayList<Subsegment> streamable = new ArrayList<>();

        //Gather children and in the condition they are ready to stream, add them to the streamable list.
        if (children.size() > 0) {
            for (Subsegment child : children) {
                if (child.getSubsegmentsLock().tryLock()) {
                    try {
                        if (stream(child, emitter)) {
                            streamable.add(child);
                        }
                    } finally {
                        child.getSubsegmentsLock().unlock();
                    }
                }
            }
        }

        //A subsegment is marked streamable if all of its children are streamable and the entity itself is not in progress.
        if (children.size() == streamable.size() && !entity.isInProgress()) {
            return true;
        }

        //Stream the subtrees that are ready.
        for (Subsegment child : streamable) {
            emitter.sendSubsegment(child);
            child.setEmitted(true);
            entity.removeSubsegment(child);
        }

        return false;
    }