directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 56905 - in incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common: name util
Date Mon, 08 Nov 2004 05:50:46 GMT
Author: akarasulu
Date: Sun Nov  7 21:50:45 2004
New Revision: 56905

Added:
   incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/util/ParserPipedInputStream.java
Modified:
   incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/name/DnParser.java
Log:
Got a really nasty problem with the parser where we were getting an ugly 
"Read end Dead" exception because of some nasty hacks in the Piped streams
specifically to handle and deal with two threads reading.  We do not have 
this issue since we use the dangerous case where a single thread does both
:) but for our case its ok and it works just fine without deadlocks: or 
at least we think.


Modified: incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/name/DnParser.java
==============================================================================
--- incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/name/DnParser.java
(original)
+++ incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/name/DnParser.java
Sun Nov  7 21:50:45 2004
@@ -27,6 +27,7 @@
 
 import org.apache.ldap.common.util.ExceptionUtils ;
 import org.apache.ldap.common.util.NestableRuntimeException ;
+import org.apache.ldap.common.util.ParserPipedInputStream;
 import org.apache.ldap.common.exception.LdapNamingException;
 import org.apache.ldap.common.exception.LdapInvalidNameException;
 import org.apache.ldap.common.message.ResultCodeEnum;
@@ -42,8 +43,7 @@
  * @see <a href="http://www.faqs.org/rfcs/rfc2253.html">RFC 2253</a>
  * @see <a href="http://www.faqs.org/rfcs/rfc1779.html">RFC 1779</a>
  */
-public class DnParser
-    implements NameParser
+public class DnParser implements NameParser
 {
     /** */
     private PipedOutputStream m_parserIn ;
@@ -124,7 +124,7 @@
         // Create selector and piped plumbing to feed the parser.
         this.m_parserIn = new PipedOutputStream() ;
         this.m_selector = new TokenStreamSelector() ;
-        PipedInputStream in = new PipedInputStream() ;
+        PipedInputStream in = new ParserPipedInputStream() ;
         this.m_parserIn.connect( in ) ;
 
         // Create lexers and add them to the selector.

Added: incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/util/ParserPipedInputStream.java
==============================================================================
--- (empty file)
+++ incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/util/ParserPipedInputStream.java
Sun Nov  7 21:50:45 2004
@@ -0,0 +1,62 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.ldap.common.util;
+
+
+import java.io.PipedInputStream;
+import java.io.IOException;
+
+
+/**
+ * A piped input stream that fixes the "Read end Dead" issue when a single
+ * thread is used.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class ParserPipedInputStream extends PipedInputStream
+{
+    protected synchronized void receive(int b) throws IOException 
+    {
+        while (in == out)
+        {
+            /* full: kick any waiting readers */
+            notifyAll();
+            try
+            {
+                wait(1000);
+            }
+            catch ( InterruptedException ex )
+            {
+                throw new java.io.InterruptedIOException();
+            }
+        }
+
+        if (in < 0)
+        {
+            in = 0;
+            out = 0;
+        }
+
+        buffer[in++] = (byte)(b & 0xFF);
+
+        if ( in >= buffer.length )
+        {
+            in = 0;
+        }
+    }
+}

Mime
View raw message