Return-Path: X-Original-To: apmail-jackrabbit-oak-dev-archive@minotaur.apache.org Delivered-To: apmail-jackrabbit-oak-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7341910DEC for ; Tue, 15 Oct 2013 13:48:51 +0000 (UTC) Received: (qmail 9749 invoked by uid 500); 15 Oct 2013 13:48:51 -0000 Delivered-To: apmail-jackrabbit-oak-dev-archive@jackrabbit.apache.org Received: (qmail 9712 invoked by uid 500); 15 Oct 2013 13:48:51 -0000 Mailing-List: contact oak-dev-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: oak-dev@jackrabbit.apache.org Delivered-To: mailing list oak-dev@jackrabbit.apache.org Received: (qmail 9704 invoked by uid 99); 15 Oct 2013 13:48:50 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Oct 2013 13:48:50 +0000 X-ASF-Spam-Status: No, hits=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy includes SPF record at spf.trusted-forwarder.org) Received: from [64.18.1.21] (HELO exprod6og108.obsmtp.com) (64.18.1.21) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Oct 2013 13:48:41 +0000 Received: from outbound-smtp-1.corp.adobe.com ([192.150.11.134]) by exprod6ob108.postini.com ([64.18.5.12]) with SMTP ID DSNKUl1HpH6OdFjINukujlpuGpcUYDBdKqFC@postini.com; Tue, 15 Oct 2013 06:48:21 PDT Received: from inner-relay-2.corp.adobe.com ([153.32.1.52]) by outbound-smtp-1.corp.adobe.com (8.12.10/8.12.10) with ESMTP id r9FDieiH016968 for ; Tue, 15 Oct 2013 06:44:40 -0700 (PDT) Received: from nacas01.corp.adobe.com (nacas01.corp.adobe.com [10.8.189.99]) by inner-relay-2.corp.adobe.com (8.12.10/8.12.10) with ESMTP id r9FDmJOU019050 for ; Tue, 15 Oct 2013 06:48:19 -0700 (PDT) Received: from eurcas01.eur.adobe.com (10.128.4.27) by nacas01.corp.adobe.com (10.8.189.99) with Microsoft SMTP Server (TLS) id 8.3.327.1; Tue, 15 Oct 2013 06:48:19 -0700 Received: from [10.132.1.214] (10.132.1.214) by eurcas01.eur.adobe.com (10.128.4.111) with Microsoft SMTP Server id 8.3.327.1; Tue, 15 Oct 2013 14:48:18 +0100 Message-ID: <525D47B2.9010305@apache.org> Date: Tue, 15 Oct 2013 15:48:34 +0200 From: =?ISO-8859-1?Q?Michael_D=FCrig?= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.0.1 MIME-Version: 1.0 To: Subject: Re: Difference between CommitHook and Editor References: In-Reply-To: Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Nice summary Jukka! How about adding this to oak-doc? Michael On 15.10.13 3:35 , Jukka Zitting wrote: > Hi, > > On Tue, Oct 15, 2013 at 8:33 AM, Tommaso Teofili > wrote: >> What's exactly the difference and the intended usage scenarios for >> CommitHooks and Editors ? > > CommitHook is the core mechanism that Oak applies to all commits. A > commit hook is in full control of what to do with the commit, though a > typical pattern is to diff the before and after states to see what > changes are being committed. > > Since the diff operation is so common (practically all hooks want to > know what changed) and since doing it repeatedly in each separate > commit hook requires a lot of extra effort, we came up with the Editor > mechanism that allows multiple hooks to "listen" on the same diff. For > example, there's no need for the name and node type validation to each > do a separate content diff, if they can both look at the same diff. > > In addition to listening to the content diff, the editors can also > make related changes to the tree using the provided NodeBuilder > instance. An editor that doesn't need to make any changes (i.e. it > just looks at the diff and potentially throws a CommitFailedException > if something is wrong) is called a validator. > >> I see for example EditorHook is a CommitHook but uses an EditorProvider >> which returns an Editor when the CommitHook#processCommit method is call. > > Right. The idea here is that the EditorHook is the core CommitHook > implementation shared by all Editors. The EditorHook does the content > diff between the given before and after states, and notifies the > available Editors (as provided by EditorProviders) about the detected > changes. > >> If I had to write a new content validator / editor which interface should >> one use and what should I expect when choosing one instead of the other? > > The basic guideline would be: > > 1. Is a content diff *not* needed (for example a commit barrier that > simply rejects all changes during maintenance)? If it isn't, use a > CommitHook. > 2. Do you need to make content changes (for example update an > in-content index) based on the content diff? If yes, use an Editor. > 3. Otherwise use a Validator. > > Note due to the way the content diff operates, the pattern in which > the editors are called can feel a bit counter-intuitive at first. > Basically each editor *instance* is used for observing the changes to > just a single node. When there are changes to a subtree below that > node, the relevant childNodeAdded/Changed/Deleted method is expected > to return a new editor instance for observing changes in those areas. > If an editor is not interested in changes inside a particular subtree > it can return null to notify the calling EditorHook that there's no > need to look deeper. And if the effect of an editor isn't tied to the > location of the changes within the content tree (like how the name > validator simply checks the validity of all names regardless of where > they're stored), it can just return itself from those methods. If the > location is relevant, for example you need to keep track of the path > of the changed node, you can store that information as internal state > of the returned editor instance. > > Note also that due to performance reasons, it's possible in some cases > for the childNodeChanged method to be called even if there are in fact > no changes within that subtree. That should happen fairly > infrequently, but your code should be prepared to deal with such > cases, preferably by explicitly tracking relevant property and child > node change events to see if a node indeed has been modified. > > BR, > > Jukka Zitting >