jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Guggisberg <stefan.guggisb...@gmail.com>
Subject Re: [jr3] Tree model
Date Wed, 29 Feb 2012 13:18:30 GMT
On Wed, Feb 29, 2012 at 12:01 AM, Jukka Zitting <jukka.zitting@gmail.com> wrote:
> 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.

i agree. the sandbox project was meant as a prototype/POC and certainly
far from being perfect.

i like the idea of a cleaner abstraction of the hierarchical model beneath
the MicroKernel api, such as the proposed Tree interface. however,
when it comes to trading efficiency for usability we should focus on
efficiency in the MicroKernel implementation.

i am e.g. concerned about the java.util.Map dependency. problematic
methods are IMO entrySet(), keySet(), containsValue() and values().

objects exposing the Map interface are usually assumed to be
fully contained in memory (at least that's my perception) and
methods like entrySet(), keySet() etc very efficient.

now consider nodes with millions of direct child nodes.
calling tree.values() will either blow your heap or requires
a non-trivial, rather complex implementation.

therefore, i'd prefer that the Tree interface didn't extend Map
but rather expose the specific methods required by a
MicroKernel implementation.

cheers
stefan

>
> 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