directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r122741 - in incubator/directory/network/trunk/mina/src/java/org/apache/mina: io/socket protocol util
Date Sun, 19 Dec 2004 03:47:21 GMT
Author: trustin
Date: Sat Dec 18 19:47:20 2004
New Revision: 122741

URL: http://svn.apache.org/viewcvs?view=rev&rev=122741
Log:
Optimized Queue implementation
Modified:
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpAcceptor.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpConnector.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpIoProcessor.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/IoAdapter.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/AbstractWriteBuffer.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/ByteBufferPool.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/Queue.java

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpAcceptor.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpAcceptor.java?view=diff&rev=122741&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpAcceptor.java&r1=122740&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpAcceptor.java&r2=122741
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpAcceptor.java
(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpAcceptor.java
Sat Dec 18 19:47:20 2004
@@ -30,8 +30,6 @@
 import java.util.Map;
 
 import org.apache.commons.lang.Validate;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.mina.io.Acceptor;
 import org.apache.mina.io.IoHandler;
 import org.apache.mina.io.IoHandlerFilter;
@@ -47,8 +45,6 @@
 {
     private static volatile int nextId = 0;
 
-    private static final Log log = LogFactory.getLog( TcpAcceptor.class );
-
     private final IoHandlerFilterManager filterManager = new IoHandlerFilterManager();
 
     private final int id = nextId++;
@@ -120,7 +116,7 @@
         }
         catch( IOException e )
         {
-            log.error( "Unexpected exception", e );
+            e.printStackTrace();
         }
     }
 
@@ -169,7 +165,15 @@
                 }
                 catch( IOException e )
                 {
-                    log.error( "Unexpected exception.", e );
+                    e.printStackTrace();
+
+                    try
+                    {
+                        Thread.sleep( 1000 );
+                    }
+                    catch( InterruptedException e1 )
+                    {
+                    }
                 }
             }
         }

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpConnector.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpConnector.java?view=diff&rev=122741&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpConnector.java&r1=122740&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpConnector.java&r2=122741
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpConnector.java
(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpConnector.java
Sat Dec 18 19:47:20 2004
@@ -29,8 +29,6 @@
 import java.util.Set;
 
 import org.apache.commons.lang.Validate;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.mina.io.Connector;
 import org.apache.mina.io.IoHandler;
 import org.apache.mina.io.IoHandlerFilter;
@@ -46,8 +44,6 @@
 {
     private static volatile int nextId = 0;
 
-    private static final Log log = LogFactory.getLog( TcpConnector.class );
-
     private final int id = nextId++;
 
     private final IoHandlerFilterManager filterManager = new IoHandlerFilterManager();
@@ -230,7 +226,15 @@
                 }
                 catch( IOException e )
                 {
-                    log.error( "Unexpected exception.", e );
+                    e.printStackTrace();
+
+                    try
+                    {
+                        Thread.sleep( 1000 );
+                    }
+                    catch( InterruptedException e1 )
+                    {
+                    }
                 }
             }
         }

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpIoProcessor.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpIoProcessor.java?view=diff&rev=122741&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpIoProcessor.java&r1=122740&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpIoProcessor.java&r2=122741
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpIoProcessor.java
(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpIoProcessor.java
Sat Dec 18 19:47:20 2004
@@ -26,8 +26,6 @@
 import java.util.Iterator;
 import java.util.Set;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.mina.core.IdleStatus;
 import org.apache.mina.core.SessionConfig;
 import org.apache.mina.util.ByteBufferPool;
@@ -41,8 +39,6 @@
  */
 class TcpIoProcessor
 {
-    private static final Log log = LogFactory.getLog( TcpIoProcessor.class );
-
     private static final TcpIoProcessor instance;
 
     static
@@ -55,8 +51,9 @@
         }
         catch( IOException e )
         {
-            log.fatal( "Failed to open selector.", e );
-            tmp = null;
+            InternalError error = new InternalError( "Failed to open selector." );
+            error.initCause( e );
+            throw error;
         }
 
         instance = tmp;
@@ -64,11 +61,11 @@
 
     private final Selector selector;
 
-    private final Queue newSessions = new Queue( 16 );
+    private final Queue newSessions = new Queue();
 
-    private final Queue removingSessions = new Queue( 16 );
+    private final Queue removingSessions = new Queue();
 
-    private final Queue flushingSessions = new Queue( 16 );
+    private final Queue flushingSessions = new Queue();
 
     private Worker worker;
 
@@ -510,7 +507,7 @@
                 }
                 catch( IOException e )
                 {
-                    log.error( "Unexpected exception.", e );
+                    e.printStackTrace();
 
                     try
                     {

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/IoAdapter.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/IoAdapter.java?view=diff&rev=122741&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/IoAdapter.java&r1=122740&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/IoAdapter.java&r2=122741
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/IoAdapter.java
(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/IoAdapter.java
Sat Dec 18 19:47:20 2004
@@ -199,7 +199,7 @@
 
         private final SessionHandlerAdapter adapter;
 
-        private final Queue writeQueue = new Queue( 16 );
+        private final Queue writeQueue = new Queue();
 
         private Object attachment;
 

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/AbstractWriteBuffer.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/AbstractWriteBuffer.java?view=diff&rev=122741&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/AbstractWriteBuffer.java&r1=122740&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/AbstractWriteBuffer.java&r2=122741
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/AbstractWriteBuffer.java
(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/AbstractWriteBuffer.java
Sat Dec 18 19:47:20 2004
@@ -35,7 +35,7 @@
 {
     protected final ByteBuffer buf;
 
-    protected final Queue markers = new Queue( 16 );
+    protected final Queue markers = new Queue();
 
     private int baseIndex;
 

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/ByteBufferPool.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/ByteBufferPool.java?view=diff&rev=122741&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/ByteBufferPool.java&r1=122740&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/ByteBufferPool.java&r2=122741
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/ByteBufferPool.java
(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/ByteBufferPool.java
Sat Dec 18 19:47:20 2004
@@ -30,7 +30,7 @@
 {
     public static final int CAPACITY = 8192;
 
-    private static Queue buffers = new Queue( 16 );
+    private static Queue buffers = new Queue();
 
     public static synchronized ByteBuffer open()
     {

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/Queue.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/Queue.java?view=diff&rev=122741&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/Queue.java&r1=122740&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/Queue.java&r2=122741
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/Queue.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/Queue.java	Sat Dec
18 19:47:20 2004
@@ -33,6 +33,8 @@
 public class Queue implements Serializable
 {
     private Object[] items;
+    
+    private int mask;
 
     private int first = 0;
 
@@ -44,9 +46,10 @@
      * Construct a new, empty <code>Queue</code> with the specified initial
      * capacity.
      */
-    public Queue( int initialCapacity )
+    public Queue()
     {
-        items = new Object[ initialCapacity ];
+        items = new Object[ 16 ];
+        mask = 15;
     }
 
     /**
@@ -75,7 +78,7 @@
 
         Object ret = items[ first ];
         items[ first ] = null;
-        first = ( first + 1 ) % items.length;
+        first = ( first + 1 ) & mask;
 
         size--;
 
@@ -106,10 +109,11 @@
             first = 0;
             last = oldLen;
             items = tmp;
+            mask = tmp.length - 1;
         }
 
         items[ last ] = obj;
-        last = ( last + 1 ) % items.length;
+        last = ( last + 1 ) & mask;
         size++;
     }
 
@@ -136,7 +140,7 @@
             return null;
         }
 
-        return items[ ( last + items.length - 1 ) % items.length ];
+        return items[ ( last + items.length - 1 ) & mask ];
     }
 
     /**

Mime
View raw message