jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jukka Zitting <jukka.zitt...@gmail.com>
Subject Re: [jr3] Tree model
Date Tue, 28 Feb 2012 23:01:46 GMT
Hi,

On Tue, Feb 28, 2012 at 6:21 PM, Jukka Zitting <jukka.zitting@gmail.com> wrote:
> I guess you'd agree that the MicroKernel API covers a lot more
> functionality than the Tree/Leaf interfaces I drafted. Someone
> implementing the MicroKernel needs abstractions like Tree/Leaf and a
> lot more besides.

To make this clearer, see https://gist.github.com/1935626 (or the end
of this message) for a draft of how a MicroKernel implementation could
use the proposed Tree API to implement the MK read operations.

The draft relies on three extra methods: getTree(),
splitPathToElements() and serializeToJson(), all of which can be
implemented (and optimized) separately. Most notably all handing of
possible caching layers, virtual content trees, etc. can be localized
inside the getTree() method with no need to involve and change any of
the code in the other methods. That's the kind of separation of
concerns I'm looking for.

Compare that to the existing sandbox/microkernel codebase, and you
notice how the equivalent code is split across the MicroKernelImpl,
Repository and RevisionProvider/DefaultRevisionStore classes. Along
that path a lot of assumptions about the underlying storage model get
made (for example that all nodes are accessible by a string id), and a
more or less hardcoded caching mechanism gets introduced. My hope with
the proposed Tree interface is to provide a simple way to address such
issues and thus, through a shared API, make it easier to divide and
coordinate work on them.

BR,

Jukka Zitting

----

public class MicroKernelImpl implements MicroKernel {

    public boolean nodeExists(String path, String revisionId)
            throws MicroKernelException {
        Tree tree = getTree(revisionId);
        for (String name : splitPathToElements(path)) {
            if (tree == null) {
                return false;
            }
            tree = tree.get(name);
        }
        return tree != null && !tree.isLeaf();
    }

    public String getNodes(String path, String revisionId)
            throws MicroKernelException {
        return getNodes(path, revisionId, 1, 0, -1);
    }

    public String getNodes(
            String path, String revisionId, int depth, long offset, int count)
            throws MicroKernelException {
        Tree tree = getTree(revisionId);
        for (String name : splitPathToElements(path)) {
            if (tree == null) {
                throw new MicroKernelException("Path not found: " + path);
            }
            tree = tree.get(name);
        }
        if (tree != null && !tree.isLeaf()) {
            return serializeToJson(tree, depth, offset, count);
        } else {
            throw new MicroKernelException("Path not found: " + path);
        }
    }

}

Mime
View raw message