directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r123311 - in incubator/directory/network/trunk/mina/src/java/org/apache/mina: common io io/socket protocol util
Date Sat, 25 Dec 2004 04:26:56 GMT
Author: trustin
Date: Fri Dec 24 20:26:54 2004
New Revision: 123311

URL: http://svn.apache.org/viewcvs?view=rev&rev=123311
Log:
 * Added WriteTimeoutException and SessionConfig.writeTimeout property
Added:
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/WriteTimeoutException.java
  (contents, props changed)
Modified:
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/SessionConfig.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketIoProcessor.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolViolationException.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/BasicSessionConfig.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/Queue.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/Stack.java

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/SessionConfig.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/SessionConfig.java?view=diff&rev=123311&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/SessionConfig.java&r1=123310&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/SessionConfig.java&r2=123311
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/SessionConfig.java
(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/SessionConfig.java
Fri Dec 24 20:26:54 2004
@@ -31,4 +31,10 @@
     long getIdleTimeInMillis( IdleStatus status );
 
     void setIdleTime( IdleStatus status, int idleTime );
+    
+    int getWriteTimeout();
+    
+    long getWriteTimeoutInMillis();
+    
+    void setWriteTimeout( int writeTimeout );
 }

Added: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/WriteTimeoutException.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/WriteTimeoutException.java?view=auto&rev=123311
==============================================================================
--- (empty file)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/WriteTimeoutException.java
Fri Dec 24 20:26:54 2004
@@ -0,0 +1,39 @@
+/*
+ *   @(#) $Id$
+ *
+ *   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.mina.io;
+
+import java.io.IOException;
+
+/**
+ * TODO Document me.
+ * 
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$, 
+ */
+public class WriteTimeoutException extends IOException {
+
+	public WriteTimeoutException() {
+		super();
+	}
+
+	public WriteTimeoutException(String s) {
+		super(s);
+	}
+
+}

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketIoProcessor.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketIoProcessor.java?view=diff&rev=123311&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketIoProcessor.java&r1=123310&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketIoProcessor.java&r2=123311
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketIoProcessor.java
(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketIoProcessor.java
Fri Dec 24 20:26:54 2004
@@ -28,6 +28,7 @@
 
 import org.apache.mina.common.IdleStatus;
 import org.apache.mina.common.SessionConfig;
+import org.apache.mina.io.WriteTimeoutException;
 import org.apache.mina.util.ByteBufferPool;
 import org.apache.mina.util.Queue;
 
@@ -323,6 +324,7 @@
     private void notifyIdleSession( SocketSession session, long currentTime )
     {
         SessionConfig config = session.getConfig();
+
         notifyIdleSession0( session, currentTime, config
                 .getIdleTimeInMillis( IdleStatus.BOTH_IDLE ),
                             IdleStatus.BOTH_IDLE, session.getLastIoTime() );
@@ -332,6 +334,9 @@
         notifyIdleSession0( session, currentTime, config
                 .getIdleTimeInMillis( IdleStatus.WRITER_IDLE ),
                             IdleStatus.WRITER_IDLE, session.getLastWriteTime() );
+
+        notifyWriteTimeoutSession( session, currentTime, config
+        		.getWriteTimeoutInMillis(), session.getLastWriteTime());
     }
 
     private void notifyIdleSession0( SocketSession session, long currentTime,
@@ -342,8 +347,18 @@
             && ( currentTime - lastIoTime ) >= idleTime )
         {
             session.setIdle( status );
-            session.getFilterManager().fireSessionIdle( session, status );
+           	session.getFilterManager().fireSessionIdle( session, status );
         }
+    }
+    
+    private void notifyWriteTimeoutSession( SocketSession session, long currentTime, long
writeTimeout, long lastIoTime )
+    {
+        if ( writeTimeout > 0 && ( currentTime - lastIoTime ) >= writeTimeout
&&
+             (session.getSelectionKey().interestOps() & SelectionKey.OP_WRITE) != 0)
+       	{
+       		session.getFilterManager().fireExceptionCaught( session,
+       				                                        new WriteTimeoutException());
+       	}
     }
 
     private void flushSessions()

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolViolationException.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolViolationException.java?view=diff&rev=123311&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolViolationException.java&r1=123310&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolViolationException.java&r2=123311
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolViolationException.java
(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolViolationException.java
Fri Dec 24 20:26:54 2004
@@ -23,8 +23,8 @@
 import org.apache.mina.util.ByteBuffers;
 
 /**
- * An exception that is thrown when {@link ProtocolCodec}cannot understand or
- * validate incoming data.
+ * An exception that is thrown when {@link ProtocolEncoder} and {@link ProtocolDecoder}
+ * cannot understand or validate incoming data.
  * 
  * @author Trustin Lee (trustin@apache.org)
  * @version $Rev$, $Date$

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/BasicSessionConfig.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/BasicSessionConfig.java?view=diff&rev=123311&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/BasicSessionConfig.java&r1=123310&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/BasicSessionConfig.java&r2=123311
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/BasicSessionConfig.java
(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/BasicSessionConfig.java
Fri Dec 24 20:26:54 2004
@@ -34,6 +34,8 @@
     private int idleTimeForWrite;
 
     private int idleTimeForBoth;
+    
+    private int writeTimeout;
 
     protected BasicSessionConfig()
     {
@@ -73,5 +75,23 @@
         else
             throw new IllegalArgumentException( "Unknown idle status: "
                                                 + status );
+    }
+    
+    public int getWriteTimeout()
+    {
+    	return writeTimeout;
+    }
+    
+    public long getWriteTimeoutInMillis()
+    {
+    	return writeTimeout * 1000L;
+    }
+    
+    public void setWriteTimeout( int writeTimeout )
+    {
+        if( writeTimeout < 0 )
+            throw new IllegalArgumentException( "Illegal write timeout: "
+                                                + writeTimeout );
+    	this.writeTimeout = writeTimeout;
     }
 }

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=123311&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/Queue.java&r1=123310&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/Queue.java&r2=123311
==============================================================================
--- 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	Fri Dec
24 20:26:54 2004
@@ -31,6 +31,10 @@
  */
 public class Queue implements Serializable
 {
+	private static final int DEFAULT_CAPACITY = 4;
+	
+	private static final int DEFAULT_MASK = DEFAULT_CAPACITY - 1;
+
     private Object[] items;
 
     private int mask;
@@ -47,8 +51,8 @@
      */
     public Queue()
     {
-        items = new Object[ 16 ];
-        mask = 15;
+        items = new Object[ DEFAULT_CAPACITY ];
+        mask = DEFAULT_MASK;
     }
 
     /**

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/Stack.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/Stack.java?view=diff&rev=123311&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/Stack.java&r1=123310&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/Stack.java&r2=123311
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/Stack.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/Stack.java	Fri Dec
24 20:26:54 2004
@@ -31,6 +31,8 @@
  */
 public class Stack implements Serializable
 {
+	private static final int DEFAULT_CAPACITY = 4;
+
     private Object[] items;
 
     private int size = 0;
@@ -41,7 +43,7 @@
      */
     public Stack()
     {
-        items = new Object[ 16 ];
+        items = new Object[ DEFAULT_CAPACITY ];
     }
 
     /**

Mime
View raw message