You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by go...@apache.org on 2003/11/23 16:37:26 UTC

cvs commit: jakarta-lucene/src/demo/org/apache/lucene/demo/html HTMLParser.java HTMLParser.jj

goller      2003/11/23 07:37:26

  Modified:    src/demo/org/apache/lucene/demo/html HTMLParser.java
                        HTMLParser.jj
  Log:
  Fix for deadlock between indexing thread and parsing
  thread that occurs with long titles. Parsing thread waits
  for indexing thread to read from pipeIn, indexing thread
  waits for summary. This fixes bug #24301
  
  Revision  Changes    Path
  1.2       +34 -15    jakarta-lucene/src/demo/org/apache/lucene/demo/html/HTMLParser.java
  
  Index: HTMLParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/demo/org/apache/lucene/demo/html/HTMLParser.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- HTMLParser.java	11 Sep 2003 01:51:33 -0000	1.1
  +++ HTMLParser.java	23 Nov 2003 15:37:26 -0000	1.2
  @@ -20,8 +20,25 @@
     boolean afterTag = false;
     boolean afterSpace = false;
     String eol = System.getProperty("line.separator");
  -  PipedReader pipeIn = null;
  -  PipedWriter pipeOut;
  +  Reader pipeIn = null;
  +  Writer pipeOut;
  +  private MyPipedInputStream pipeInStream = null;
  +  private PipedOutputStream pipeOutStream = null;
  +
  +  private class MyPipedInputStream extends PipedInputStream{
  +
  +    public MyPipedInputStream(){
  +      super();
  +    }
  +
  +    public MyPipedInputStream(PipedOutputStream src) throws IOException{
  +      super(src);
  +    }
  +
  +    public boolean full() throws IOException{
  +      return this.available() >= PipedInputStream.PIPE_SIZE;
  +    }
  +  }
   
     public HTMLParser(File file) throws FileNotFoundException {
       this(new FileInputStream(file));
  @@ -32,7 +49,7 @@
         getReader();                                // spawn parsing thread
       while (true) {
         synchronized(this) {
  -        if (titleComplete || (length > SUMMARY_LENGTH))
  +        if (titleComplete || pipeInStream.full())
             break;
           wait(10);
         }
  @@ -46,7 +63,7 @@
         getReader();                                // spawn parsing thread
       while (true) {
         synchronized(this) {
  -        if (titleComplete || (length > SUMMARY_LENGTH))
  +        if (titleComplete || pipeInStream.full())
             break;
           wait(10);
         }
  @@ -60,7 +77,7 @@
         getReader();                                // spawn parsing thread
       while (true) {
         synchronized(this) {
  -        if (summary.length() >= SUMMARY_LENGTH)
  +        if (summary.length() >= SUMMARY_LENGTH || pipeInStream.full())
             break;
           wait(10);
         }
  @@ -70,16 +87,18 @@
   
       String sum = summary.toString().trim();
       String tit = getTitle();
  -    if (sum.startsWith(tit))
  -      return sum.substring(tit.length());
  +    if (sum.startsWith(tit) || sum.equals(""))
  +      return tit;
       else
         return sum;
     }
   
     public Reader getReader() throws IOException {
       if (pipeIn == null) {
  -      pipeIn = new PipedReader();
  -      pipeOut = new PipedWriter(pipeIn);
  +      pipeInStream = new MyPipedInputStream();
  +      pipeOutStream = new PipedOutputStream(pipeInStream);
  +      pipeIn = new InputStreamReader(pipeInStream);
  +      pipeOut = new OutputStreamWriter(pipeOutStream);
   
         Thread thread = new ParserThread(this);
         thread.start();                             // start parsing
  @@ -405,15 +424,15 @@
       finally { jj_save(1, xla); }
     }
   
  -  final private boolean jj_3_1() {
  -    if (jj_scan_token(ArgQuote1)) return true;
  -    if (jj_scan_token(CloseQuote1)) return true;
  -    return false;
  -  }
  -
     final private boolean jj_3_2() {
       if (jj_scan_token(ArgQuote2)) return true;
       if (jj_scan_token(CloseQuote2)) return true;
  +    return false;
  +  }
  +
  +  final private boolean jj_3_1() {
  +    if (jj_scan_token(ArgQuote1)) return true;
  +    if (jj_scan_token(CloseQuote1)) return true;
       return false;
     }
   
  
  
  
  1.3       +28 -9     jakarta-lucene/src/demo/org/apache/lucene/demo/html/HTMLParser.jj
  
  Index: HTMLParser.jj
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/demo/org/apache/lucene/demo/html/HTMLParser.jj,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- HTMLParser.jj	29 Jun 2002 22:08:26 -0000	1.2
  +++ HTMLParser.jj	23 Nov 2003 15:37:26 -0000	1.3
  @@ -84,8 +84,25 @@
     boolean afterTag = false;
     boolean afterSpace = false;
     String eol = System.getProperty("line.separator");
  -  PipedReader pipeIn = null;
  -  PipedWriter pipeOut;
  +  Reader pipeIn = null;
  +  Writer pipeOut;
  +  private MyPipedInputStream pipeInStream = null;
  +  private PipedOutputStream pipeOutStream = null;
  +  
  +  private class MyPipedInputStream extends PipedInputStream{
  +    
  +    public MyPipedInputStream(){
  +      super();
  +    }
  +    
  +    public MyPipedInputStream(PipedOutputStream src) throws IOException{
  +      super(src);
  +    }
  +    
  +    public boolean full() throws IOException{
  +      return this.available() >= PipedInputStream.PIPE_SIZE;
  +    }
  +  }
   
     public HTMLParser(File file) throws FileNotFoundException {
       this(new FileInputStream(file));
  @@ -96,7 +113,7 @@
         getReader();				  // spawn parsing thread
       while (true) {
         synchronized(this) {
  -	if (titleComplete || (length > SUMMARY_LENGTH))
  +	if (titleComplete || pipeInStream.full())
   	  break;
   	wait(10);
         }
  @@ -110,7 +127,7 @@
         getReader();				  // spawn parsing thread
       while (true) {
         synchronized(this) {
  -	if (titleComplete || (length > SUMMARY_LENGTH))
  +	if (titleComplete || pipeInStream.full())
   	  break;
   	wait(10);
         }
  @@ -124,7 +141,7 @@
         getReader();				  // spawn parsing thread
       while (true) {
         synchronized(this) {
  -	if (summary.length() >= SUMMARY_LENGTH)
  +	if (summary.length() >= SUMMARY_LENGTH || pipeInStream.full())
   	  break;
   	wait(10);
         }
  @@ -134,16 +151,18 @@
   
       String sum = summary.toString().trim();
       String tit = getTitle();
  -    if (sum.startsWith(tit))
  -      return sum.substring(tit.length());
  +    if (sum.startsWith(tit) || sum.equals(""))
  +      return tit;
       else
         return sum;
     }
   
     public Reader getReader() throws IOException {
       if (pipeIn == null) {
  -      pipeIn = new PipedReader();
  -      pipeOut = new PipedWriter(pipeIn);
  +      pipeInStream = new MyPipedInputStream();
  +      pipeOutStream = new PipedOutputStream(pipeInStream);
  +      pipeIn = new InputStreamReader(pipeInStream);
  +      pipeOut = new OutputStreamWriter(pipeOutStream);
   
         Thread thread = new ParserThread(this);
         thread.start();				  // start parsing
  
  
  

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