You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2004/11/09 11:43:09 UTC

svn commit: rev 57013 - incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber

Author: akarasulu
Date: Tue Nov  9 02:43:08 2004
New Revision: 57013

Modified:
   incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/TupleEncodingVisitor.java
   incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/TupleTreeAnalyzer.java
Log:
Changes ...

 o added extra constructor and feature to prevent vm exit on analyzer
 o solved bug that shows up in SEDA with multithreaded environment on
   the encoding visitor; more on this below

Notes ...

  Encountered a really nasty and perplexing bug where it seemed as though the
order of output events were being mangled by SEDA.  This infact was not the
case.  What was happening?  The encoding visitor was trying to reuse a buffer
for Tag and Length bytes of a TLV.  After calling decodeOccurred on the callback
it was reusing this buffer causing a race condition that was overwriting these
buffers.  Basically the callback would enqueue the buffer handing it off to
be flushed to the client by the output manager.  While the output manager was
processing or waiting to process the event the encoder was resetting or flushing
the buffer to be reused then writing to it.  This basically was overwriting 
bytes in these buffers before they could be flushed out the door.

Lessons learned ...

 o First too many events are being spewed for just a couple bytes at a time.  
   What a waste!!!
 o Second I really need to rewrite the ber code, it's way out of control.  
   We got too many copies going on.  We need to eliminate buffer creation
   and copies.  Alan save me man!
 o Third Alex should not write code more complex than a Hello world app.



Modified: incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/TupleEncodingVisitor.java
==============================================================================
--- incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/TupleEncodingVisitor.java	(original)
+++ incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/TupleEncodingVisitor.java	Tue Nov  9 02:43:08 2004
@@ -35,50 +35,9 @@
  * @author <a href="mailto:directory-dev@incubator.apache.org"> Apache Directory
  *         Project</a> $Rev$
  */
-public class TupleEncodingVisitor
-        extends AbstractStatefulEncoder
+public class TupleEncodingVisitor extends AbstractStatefulEncoder
         implements TupleNodeVisitor
 {
-    /** the default buffer size to use */
-    public final static int DEFAULT_BUFSZ = 64;
-    /** the buffer associated with this encoder */
-    ByteBuffer buf;
-
-
-    // ------------------------------------------------------------------------
-    // C O N S T R U C T O R S
-    // ------------------------------------------------------------------------
-
-
-    /**
-     * Creates an encoding visitor with a default sized buffer filled as a
-     * Tuple tree is visited in prefix order.
-     */
-    public TupleEncodingVisitor()
-    {
-        buf = ByteBuffer.allocate( DEFAULT_BUFSZ );
-    }
-
-
-    /**
-     * Creates an encoding visitor using the argument buffer which is filled as
-     * a Tuple tree is visited in prefix order.
-     */
-    public TupleEncodingVisitor( ByteBuffer buf )
-    {
-        this.buf = buf;
-    }
-
-
-    /**
-     * Creates an encoding visitor using the argument byte array which is
-     * filled as a Tuple tree is visited in prefix order.
-     */
-    public TupleEncodingVisitor( byte[] buf )
-    {
-        this.buf = ByteBuffer.wrap( buf );
-    }
-
 
     // ------------------------------------------------------------------------
     // TupleNodeVisitor Implemenations
@@ -113,20 +72,9 @@
     {
         Tuple tlv = node.getTuple();
 
-        if ( buf.remaining() < tlv.getTagLength() )
-        {
-            super.encodeOccurred( buf.flip() );
-            buf.rewind();
-        }
-
+        int size = tlv.getTagLength() + tlv.getLengthLength();
+        ByteBuffer buf = ByteBuffer.wrap( new byte[size] );
         tlv.setTag( buf, tlv.getTagLength() );
-
-        if ( buf.remaining() < tlv.getLengthLength() )
-        {
-            super.encodeOccurred( buf.flip() );
-            buf.rewind();
-        }
-
         tlv.setLength( buf, tlv.getLengthLength() );
         super.encodeOccurred( buf.flip() );
         buf.rewind();

Modified: incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/TupleTreeAnalyzer.java
==============================================================================
--- incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/TupleTreeAnalyzer.java	(original)
+++ incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/TupleTreeAnalyzer.java	Tue Nov  9 02:43:08 2004
@@ -62,6 +62,7 @@
  */
 public class TupleTreeAnalyzer extends JFrame implements TreeSelectionListener
 {
+    private boolean doVmExit = true;
     private BorderLayout layout = new BorderLayout();
     private JLabel statusBar = new JLabel("Ready");
     private JSplitPane jSplitPane1 = new JSplitPane();
@@ -85,10 +86,21 @@
 
 
     /** Creates new form JFrame */
-    public TupleTreeAnalyzer( DefaultMutableTupleNode root ) 
+    public TupleTreeAnalyzer( DefaultMutableTupleNode root )
     {
         this.root = root ;
-        
+
+        initGUI() ;
+        pack() ;
+    }
+
+
+    /** Creates new form JFrame */
+    public TupleTreeAnalyzer( DefaultMutableTupleNode root, boolean doVmExit )
+    {
+        this.root = root ;
+        this.doVmExit = doVmExit;
+
         initGUI() ;
         pack() ;
     }
@@ -135,7 +147,10 @@
         fileExit.addActionListener(
             new ActionListener() {
                 public void actionPerformed(ActionEvent e) {
-                    System.exit(0);
+                    if ( doVmExit )
+                    {
+                        System.exit(0);
+                    }
                 }
             });
         // create About menu item
@@ -188,7 +203,7 @@
         print.addActionListener(
             new java.awt.event.ActionListener() {
                 public void actionPerformed(java.awt.event.ActionEvent e) {
-                    // PrintDialog.print(getGraphics());
+                    hexDumpTupleTree();
                 }
             }); menuFile.add(print);
         menuFile.add(fileExit);
@@ -284,11 +299,19 @@
         jTree1.getSelectionModel().addTreeSelectionListener( this );
     }
 
+    private void hexDumpTupleTree()
+    {
+    }
+
     /** Exit the Application */
     private void exitForm(WindowEvent evt)
     {
         System.out.println("Closing window: " + evt.getWindow().getName());
-        System.exit(0);
+
+        if ( doVmExit )
+        {
+            System.exit(0);
+        }
     }