lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Earwin Burrfoot (JIRA)" <j...@apache.org>
Subject [jira] Commented: (LUCENE-2345) Make it possible to subclass SegmentReader
Date Fri, 26 Mar 2010 11:14:27 GMT

    [ https://issues.apache.org/jira/browse/LUCENE-2345?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12850084#action_12850084
] 

Earwin Burrfoot commented on LUCENE-2345:
-----------------------------------------

More often than not init() methods are a sign of bad design.
I.e. in your case extending IW is crazy.
You should have an interface capturing IW methods and two implementations - one writing to
the index and another delegating to its subwriters. You don't do DirectoryReader extends SegmentReader,
do you? They both extend lucene-style-interface IndexReader.

Lucene's back compat policy got people used to writing and digesting freaky code, and I'm
not going to fight generally against it, that's a lost cause : )
But in this exact case (readers) stuffing everything in constructors, defining all fields
I can final, replacing SR.openDocStores/loadTermsIndex with reopen()-like method allows me
to tackle (at least somewhat) lifecycle complexity. Javac will force me to either initialize
something or explicitly leave it null.
Besides some real bugs in this code, I cleaned up cases where a field was inited twice, just
in case! Poor developers got lost in init() methods : }

> Make it possible to subclass SegmentReader
> ------------------------------------------
>
>                 Key: LUCENE-2345
>                 URL: https://issues.apache.org/jira/browse/LUCENE-2345
>             Project: Lucene - Java
>          Issue Type: Wish
>          Components: Index
>            Reporter: Tim Smith
>             Fix For: 3.1
>
>         Attachments: LUCENE-2345_3.0.patch
>
>
> I would like the ability to subclass SegmentReader for numerous reasons:
> * to capture initialization/close events
> * attach custom objects to an instance of a segment reader (caches, statistics, so on
and so forth)
> * override methods on segment reader as needed
> currently this isn't really possible
> I propose adding a SegmentReaderFactory that would allow creating custom subclasses of
SegmentReader
> default implementation would be something like:
> {code}
> public class SegmentReaderFactory {
>   public SegmentReader get(boolean readOnly) {
>     return readOnly ? new ReadOnlySegmentReader() : new SegmentReader();
>   }
>   public SegmentReader reopen(SegmentReader reader, boolean readOnly) {
>     return newSegmentReader(readOnly);
>   }
> }
> {code}
> It would then be made possible to pass a SegmentReaderFactory to IndexWriter (for pooled
readers) as well as to SegmentReader.get() (DirectoryReader.open, etc)
> I could prepare a patch if others think this has merit
> Obviously, this API would be "experimental/advanced/will change in future"

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org


Mime
View raw message