You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-dev@jackrabbit.apache.org by Chetan Mehrotra <ch...@gmail.com> on 2014/11/14 07:53:47 UTC

Export org.apache.jackrabbit.oak.plugins.tree from oak-core

Hi Team,

For OAK-2261 I need to use ImmutableTree from
org.apache.jackrabbit.oak.plugins.tree package which is currently not
exported by Oak core. To proceed further I would like to export this
package as part of OAK-2269

Unless someone objects I would make the change by EOD today

Chetan Mehrotra

Re: Export org.apache.jackrabbit.oak.plugins.tree from oak-core

Posted by Angela Schreiber <an...@adobe.com>.
Hi Chetan

I am not in favour of exporting org.apache.jackrabbit.oak.plugins.tree.
We already have too many thinks exported from oak-core (like e.g.
VersionStoreImpl) and I think it's bad of other modules depend on
the implementation details of oak-core.

But maybe you can elaborate why this would be needed.

Kind regards
Angela

On 14/11/14 07:53, "Chetan Mehrotra" <ch...@gmail.com> wrote:

>Hi Team,
>
>For OAK-2261 I need to use ImmutableTree from
>org.apache.jackrabbit.oak.plugins.tree package which is currently not
>exported by Oak core. To proceed further I would like to export this
>package as part of OAK-2269
>
>Unless someone objects I would make the change by EOD today
>
>Chetan Mehrotra


Re: Export org.apache.jackrabbit.oak.plugins.tree from oak-core

Posted by Michael Dürig <md...@apache.org>.

On 14.11.14 10:59 , Felix Meschberger wrote:
> I honestly don’t think we should be dropping good common practice and design on the notion of less typing, right ?;-)

And I always though people find Java's public final static verbosity a 
good thing ;-)

Michael

Re: Export org.apache.jackrabbit.oak.plugins.tree from oak-core

Posted by Chetan Mehrotra <ch...@gmail.com>.
I have marked OAK-2269 as Wont Fix. Would implement a minimal tree in
oak-lucene to meet indexing requirements. Thanks for all the feedback!
Chetan Mehrotra


On Fri, Nov 14, 2014 at 4:18 PM, Felix Meschberger <fm...@adobe.com> wrote:
> Hi
>
>> Am 14.11.2014 um 11:22 schrieb Chetan Mehrotra <ch...@gmail.com>:
>>
>> On Fri, Nov 14, 2014 at 3:29 PM, Felix Meschberger <fm...@adobe.com> wrote:
>>> But all fields should (I’d even say must) be private and only be accessible through getters. All non-private fields make it close to impossible to ever refactor these fields. Add to it having the containing classes be exported as API and you get implementation lock-in.
>>
>> Ack. Makes sense and as Michael mentioned that this class is not
>> suitable to be exposed as part of API due such reasons only
>>
>>> An interface is something you implement to expose a behaviour. An interface sporting constants is not defining behaviour. Therefore a „container“ for constants should not be an interface.
>>
>> Ack. I knew that I would get negative marks from you for defending
>> that when I sent that mail :)
>
> No negative marks at all ! Just to explain my train of thoughts :-)
>
> … and there are some things I am picky on :-)
>
> Regards
> Felix

Re: Export org.apache.jackrabbit.oak.plugins.tree from oak-core

Posted by Felix Meschberger <fm...@adobe.com>.
Hi

> Am 14.11.2014 um 11:22 schrieb Chetan Mehrotra <ch...@gmail.com>:
> 
> On Fri, Nov 14, 2014 at 3:29 PM, Felix Meschberger <fm...@adobe.com> wrote:
>> But all fields should (I’d even say must) be private and only be accessible through getters. All non-private fields make it close to impossible to ever refactor these fields. Add to it having the containing classes be exported as API and you get implementation lock-in.
> 
> Ack. Makes sense and as Michael mentioned that this class is not
> suitable to be exposed as part of API due such reasons only
> 
>> An interface is something you implement to expose a behaviour. An interface sporting constants is not defining behaviour. Therefore a „container“ for constants should not be an interface.
> 
> Ack. I knew that I would get negative marks from you for defending
> that when I sent that mail :)

No negative marks at all ! Just to explain my train of thoughts :-)

… and there are some things I am picky on :-)

Regards
Felix

Re: Export org.apache.jackrabbit.oak.plugins.tree from oak-core

Posted by Chetan Mehrotra <ch...@gmail.com>.
On Fri, Nov 14, 2014 at 3:29 PM, Felix Meschberger <fm...@adobe.com> wrote:
> But all fields should (I’d even say must) be private and only be accessible through getters. All non-private fields make it close to impossible to ever refactor these fields. Add to it having the containing classes be exported as API and you get implementation lock-in.

Ack. Makes sense and as Michael mentioned that this class is not
suitable to be exposed as part of API due such reasons only

> An interface is something you implement to expose a behaviour. An interface sporting constants is not defining behaviour. Therefore a „container“ for constants should not be an interface.

Ack. I knew that I would get negative marks from you for defending
that when I sent that mail :)

Chetan Mehrotra

Re: Export org.apache.jackrabbit.oak.plugins.tree from oak-core

Posted by Felix Meschberger <fm...@adobe.com>.
Hi

> Am 14.11.2014 um 08:21 schrieb Chetan Mehrotra <ch...@gmail.com>:
> 
>> E.g. the AbstractTree has protected mutable fields (bad practice per se, if exported even worse)
> If that is by design (required for MutableTree) would it still be bad.
> What would be the issue?

Just because something is by design, does not make it good :-) 

And I don’t say all fields must be final (though there is good reasons to do so).

But all fields should (I’d even say must) be private and only be accessible through getters. All non-private fields make it close to impossible to ever refactor these fields. Add to it having the containing classes be exported as API and you get implementation lock-in.

Regards
Felix

> 
>> Or TreeConstants exposing an „internal“ constant (should be a final class not an interface, actually)
> Can change it to class but I do not see much issue in using interface
> as holder for constants. Allows me to save bit on redundant typing of
> 'public static final'!. The constant is not that internal, just a name
> of hidden field

I honestly don’t think we should be dropping good common practice and design on the notion of less typing, right ? ;-)

An interface is something you implement to expose a behaviour. An interface sporting constants is not defining behaviour. Therefore a „container“ for constants should not be an interface.

Regards
Felix

Re: Export org.apache.jackrabbit.oak.plugins.tree from oak-core

Posted by Chetan Mehrotra <ch...@gmail.com>.
> E.g. the AbstractTree has protected mutable fields (bad practice per se, if exported even worse)
If that is by design (required for MutableTree) would it still be bad.
What would be the issue?

> Or TreeConstants exposing an „internal“ constant (should be a final class not an interface, actually)
Can change it to class but I do not see much issue in using interface
as holder for constants. Allows me to save bit on redundant typing of
'public static final'!. The constant is not that internal, just a name
of hidden field

Rest all classes are marked final so should be ok.

Chetan Mehrotra

Re: Export org.apache.jackrabbit.oak.plugins.tree from oak-core

Posted by Felix Meschberger <fm...@adobe.com>.
Hi

I have the impression this is not a good idea, unless you cleanse the classes.

E.g. the AbstractTree has protected mutable fields (bad practice per se, if exported even worse)

Or TreeConstants exposing an „internal“ constant (should be a final class not an interface, actually)

Or ChildOrderDiff which operates on a hidden field (and thus should not be exposed, I would assume)

Unfortunately ImmutableTree extends AbstractTree so exporting the former requires exporting the latter …

From the outside, I have not the best of all gut feelings here...

Regards
Felix

> Am 14.11.2014 um 07:53 schrieb Chetan Mehrotra <ch...@gmail.com>:
> 
> Hi Team,
> 
> For OAK-2261 I need to use ImmutableTree from
> org.apache.jackrabbit.oak.plugins.tree package which is currently not
> exported by Oak core. To proceed further I would like to export this
> package as part of OAK-2269
> 
> Unless someone objects I would make the change by EOD today
> 
> Chetan Mehrotra


Re: Export org.apache.jackrabbit.oak.plugins.tree from oak-core

Posted by Chetan Mehrotra <ch...@gmail.com>.
On Fri, Nov 14, 2014 at 2:53 PM, Alex Parvulescu
<al...@gmail.com> wrote:
> Add an index property on the definition? you can sort after reading all of
> them, there won't be too many so performance is not a concern.

The IndexRules mentioned in [1] are read in the order they are listed.
Later matching of NodeType to index rule is done in the order of the
listing taking into account the inheritance. Map this xml config to
JCR content I thought that same effect can be achieved via use of
nt:unstructured. This seemed to be more intutive

Using some ranking property ... well can be done yes but might not be intutive!

On Fri, Nov 14, 2014 at 2:53 PM, Alex Parvulescu
<al...@gmail.com> wrote:
> Can you post an example? How many levels down do you expect to have in a
> definition? I would just convert the definition to an tree-like structure
> made out of definitions, not content trees.

Did not understand what you meant by tree like structures for
definition. What needs to be supported is condition like below to
determine the applicability of rules

ancestor::*/@priority = 'high'

Implementing such logic is easier via Tree as it allows access to
ancestors. Further I was thinking to make use of Tree in aggregation
logic also

If making use of tree is so big a concern I can implement a similar
structure which meets my requirement. I did implemented something
similar but later realized that same thing can be met by Tree API and
hence switched to that. Would not be much effort to resurrect it back!

Chetan Mehrotra
[1] http://wiki.apache.org/jackrabbit/IndexingConfiguration

Re: Export org.apache.jackrabbit.oak.plugins.tree from oak-core

Posted by Alex Parvulescu <al...@gmail.com>.
Hi,

>1. Read NodeState children in orderable manner - This is required for
reading indexing rules where the order is important

Add an index property on the definition? you can sort after reading all of
them, there won't be too many so performance is not a concern.

>  Access to ancestors to evaluate condition in index rule - JR2 index
rule support conditional rule where condition requires access to
parent

Can you post an example? How many levels down do you expect to have in a
definition? I would just convert the definition to an tree-like structure
made out of definitions, not content trees.

best,
alex


On Fri, Nov 14, 2014 at 10:07 AM, Chetan Mehrotra <chetan.mehrotra@gmail.com
> wrote:

> I need to create Tree out of NodeState for following reason
>
> 1. Read NodeState children in orderable manner - This is required for
> reading indexing rules where the order is important
> 2. Access to ancestors to evaluate condition in index rule - JR2 index
> rule support conditional rule where condition requires access to
> parent
>
> > Instead I suggest to export a generic mechanism for obtaining
> (immutable) Tree instances given a node state.
> Any details on how that should be done. I just need to convert a
> NodeState to a Tree also support access to parent tree.
>
>
> Chetan Mehrotra
>
>
> On Fri, Nov 14, 2014 at 2:14 PM, Michael Dürig <md...@apache.org> wrote:
> >
> > -1.
> >
> > ImmutableTree is an internal class and as Felix points out exposes a lot
> of
> > idiosyncrasies. Further exposure will make it very difficult to evolve.
> > Instead I suggest to export a generic mechanism for obtaining (immutable)
> > Tree instances given a node state. This will in the long run allow us to
> > make ImmutableTree package-private (as MutableTree) and only rely on that
> > generic mechanism.
> >
> > Michael
> >
> >
> > On 14.11.14 7:53 , Chetan Mehrotra wrote:
> >>
> >> Hi Team,
> >>
> >> For OAK-2261 I need to use ImmutableTree from
> >> org.apache.jackrabbit.oak.plugins.tree package which is currently not
> >> exported by Oak core. To proceed further I would like to export this
> >> package as part of OAK-2269
> >>
> >> Unless someone objects I would make the change by EOD today
> >>
> >> Chetan Mehrotra
> >>
> >
>

Re: Export org.apache.jackrabbit.oak.plugins.tree from oak-core

Posted by Chetan Mehrotra <ch...@gmail.com>.
For now I have inlined the ImmutableTree within oak-lucene and have
opened OAK-2270 to ensure that this workaround gets fixed before the
release. This would allow the osgi testcases to pass.

@Michael - In the meanwhile we can discuss the possible approach for
this problem
Chetan Mehrotra


On Fri, Nov 14, 2014 at 5:28 PM, Chetan Mehrotra
<ch...@gmail.com> wrote:
> On Fri, Nov 14, 2014 at 5:10 PM, Michael Dürig <md...@apache.org> wrote:
>> I was thinking of introducing some sort of a factory for Tree instances and
>> export that API. That way we wouldn't have to come up with our one tree
>> implementations in all places where we need it but still leave the
>> underlying Tree implementation unspecified thus enabling them to evolve.
>
> That would be good. For this case I tried to have my own Tree like
> implementation. Most of the logic works fine but then got stuck with
> ReadOnlyTypeManager as that only works with real Tree! So I need to
> construct a tree from NodeState at mimimum.
>
> If i go the route of TreeFactory then one place I get stuck is support
> for assembling a tree with individual NodeState i.e. replacement for
>
> public ImmutableTree(@Nonnull ImmutableTree parent, @Nonnull String
> name, @Nonnull NodeState state)
>
> May be if we have support for "friends" in OSGi so as to allow
> oak-lucene access to internal classes as special case then usage of
> oak-core classes in oak-lucene would be at par with other classes in
> oak-core and oak-lucene would not be discriminated :(
>
> So stuck here now for proper solution. Any pointers!
>
> Chetan Mehrotra

Re: Export org.apache.jackrabbit.oak.plugins.tree from oak-core

Posted by Chetan Mehrotra <ch...@gmail.com>.
On Fri, Nov 14, 2014 at 5:10 PM, Michael Dürig <md...@apache.org> wrote:
> I was thinking of introducing some sort of a factory for Tree instances and
> export that API. That way we wouldn't have to come up with our one tree
> implementations in all places where we need it but still leave the
> underlying Tree implementation unspecified thus enabling them to evolve.

That would be good. For this case I tried to have my own Tree like
implementation. Most of the logic works fine but then got stuck with
ReadOnlyTypeManager as that only works with real Tree! So I need to
construct a tree from NodeState at mimimum.

If i go the route of TreeFactory then one place I get stuck is support
for assembling a tree with individual NodeState i.e. replacement for

public ImmutableTree(@Nonnull ImmutableTree parent, @Nonnull String
name, @Nonnull NodeState state)

May be if we have support for "friends" in OSGi so as to allow
oak-lucene access to internal classes as special case then usage of
oak-core classes in oak-lucene would be at par with other classes in
oak-core and oak-lucene would not be discriminated :(

So stuck here now for proper solution. Any pointers!

Chetan Mehrotra

Re: Export org.apache.jackrabbit.oak.plugins.tree from oak-core

Posted by Michael Dürig <md...@apache.org>.

On 14.11.14 10:07 , Chetan Mehrotra wrote:
>> >Instead I suggest to export a generic mechanism for obtaining (immutable) Tree instances given a node state.
> Any details on how that should be done. I just need to convert a
> NodeState to a Tree also support access to parent tree.

I was thinking of introducing some sort of a factory for Tree instances 
and export that API. That way we wouldn't have to come up with our one 
tree implementations in all places where we need it but still leave the 
underlying Tree implementation unspecified thus enabling them to evolve.

Michael

Re: Export org.apache.jackrabbit.oak.plugins.tree from oak-core

Posted by Chetan Mehrotra <ch...@gmail.com>.
I need to create Tree out of NodeState for following reason

1. Read NodeState children in orderable manner - This is required for
reading indexing rules where the order is important
2. Access to ancestors to evaluate condition in index rule - JR2 index
rule support conditional rule where condition requires access to
parent

> Instead I suggest to export a generic mechanism for obtaining (immutable) Tree instances given a node state.
Any details on how that should be done. I just need to convert a
NodeState to a Tree also support access to parent tree.


Chetan Mehrotra


On Fri, Nov 14, 2014 at 2:14 PM, Michael Dürig <md...@apache.org> wrote:
>
> -1.
>
> ImmutableTree is an internal class and as Felix points out exposes a lot of
> idiosyncrasies. Further exposure will make it very difficult to evolve.
> Instead I suggest to export a generic mechanism for obtaining (immutable)
> Tree instances given a node state. This will in the long run allow us to
> make ImmutableTree package-private (as MutableTree) and only rely on that
> generic mechanism.
>
> Michael
>
>
> On 14.11.14 7:53 , Chetan Mehrotra wrote:
>>
>> Hi Team,
>>
>> For OAK-2261 I need to use ImmutableTree from
>> org.apache.jackrabbit.oak.plugins.tree package which is currently not
>> exported by Oak core. To proceed further I would like to export this
>> package as part of OAK-2269
>>
>> Unless someone objects I would make the change by EOD today
>>
>> Chetan Mehrotra
>>
>

Re: Export org.apache.jackrabbit.oak.plugins.tree from oak-core

Posted by Michael Dürig <md...@apache.org>.
-1.

ImmutableTree is an internal class and as Felix points out exposes a lot 
of idiosyncrasies. Further exposure will make it very difficult to evolve.
Instead I suggest to export a generic mechanism for obtaining 
(immutable) Tree instances given a node state. This will in the long run 
allow us to make ImmutableTree package-private (as MutableTree) and only 
rely on that generic mechanism.

Michael

On 14.11.14 7:53 , Chetan Mehrotra wrote:
> Hi Team,
>
> For OAK-2261 I need to use ImmutableTree from
> org.apache.jackrabbit.oak.plugins.tree package which is currently not
> exported by Oak core. To proceed further I would like to export this
> package as part of OAK-2269
>
> Unless someone objects I would make the change by EOD today
>
> Chetan Mehrotra
>