directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r122747 - in incubator/directory/network/trunk/mina/src/java/org/apache/mina/io: . socket
Date Sun, 19 Dec 2004 08:44:57 GMT
Author: trustin
Date: Sun Dec 19 00:44:56 2004
New Revision: 122747

URL: http://svn.apache.org/viewcvs?view=rev&rev=122747
Log:
Connector returns new session instance now.
Modified:
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/Connector.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

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/Connector.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/Connector.java?view=diff&rev=122747&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/Connector.java&r1=122746&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/Connector.java&r2=122747
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/Connector.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/Connector.java	Sun
Dec 19 00:44:56 2004
@@ -30,13 +30,13 @@
  */
 public interface Connector
 {
-    void connect( SocketAddress address, IoHandler defaultHandler )
+    IoSession connect( SocketAddress address, IoHandler defaultHandler )
             throws IOException;
 
-    void connect( SocketAddress address, int timeout,
-                 IoHandler defaultHandler ) throws IOException;
-    
-    void addFilter(int priority, IoHandlerFilter filter);
-    
-    void removeFilter(IoHandlerFilter filter);
+    IoSession connect( SocketAddress address, int timeout,
+                      IoHandler defaultHandler ) throws IOException;
+
+    void addFilter( int priority, IoHandlerFilter filter );
+
+    void removeFilter( IoHandlerFilter filter );
 }

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=122747&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpConnector.java&r1=122746&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpConnector.java&r2=122747
==============================================================================
--- 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
Sun Dec 19 00:44:56 2004
@@ -32,6 +32,7 @@
 import org.apache.mina.io.Connector;
 import org.apache.mina.io.IoHandler;
 import org.apache.mina.io.IoHandlerFilter;
+import org.apache.mina.io.IoSession;
 import org.apache.mina.util.IoHandlerFilterManager;
 
 /**
@@ -62,14 +63,14 @@
         selector = Selector.open();
     }
 
-    public void connect( SocketAddress address, IoHandler defaultHandler )
+    public IoSession connect( SocketAddress address, IoHandler defaultHandler )
             throws IOException
     {
-        connect( address, Integer.MAX_VALUE, defaultHandler );
+        return connect( address, Integer.MAX_VALUE, defaultHandler );
     }
 
-    public void connect( SocketAddress address, int timeout,
-                        IoHandler defaultHandler ) throws IOException
+    public IoSession connect( SocketAddress address, int timeout,
+                             IoHandler defaultHandler ) throws IOException
     {
         Validate.notNull( address );
         Validate.notNull( defaultHandler );
@@ -86,7 +87,7 @@
 
         if( ch.connect( address ) )
         {
-            newSession( ch, defaultHandler );
+            return newSession( ch, defaultHandler );
         }
         else
         {
@@ -121,6 +122,8 @@
 
             if( entry.exception != null )
                 throw entry.exception;
+            else
+                return entry.session;
         }
     }
 
@@ -141,14 +144,14 @@
             try
             {
                 ch.finishConnect();
+                TcpSession session = newSession( ch, entry.handler );
+                entry.session = session;
                 entry.done = true;
 
                 synchronized( entry )
                 {
                     entry.notify();
                 }
-
-                newSession( ch, entry.handler );
             }
             catch( IOException e )
             {
@@ -198,10 +201,11 @@
         }
     }
 
-    private void newSession( SocketChannel ch, IoHandler handler )
+    private TcpSession newSession( SocketChannel ch, IoHandler handler )
     {
         TcpSession session = new TcpSession( filterManager, ch, handler );
         TcpIoProcessor.getInstance().addSession( session );
+        return session;
     }
 
     private class Worker extends Thread
@@ -245,6 +249,8 @@
         private final long deadline;
 
         private final IoHandler handler;
+
+        private TcpSession session;
 
         private boolean done;
 

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=122747&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpIoProcessor.java&r1=122746&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpIoProcessor.java&r2=122747
==============================================================================
--- 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
Sun Dec 19 00:44:56 2004
@@ -51,7 +51,8 @@
         }
         catch( IOException e )
         {
-            InternalError error = new InternalError( "Failed to open selector." );
+            InternalError error = new InternalError(
+                                                     "Failed to open selector." );
             error.initCause( e );
             throw error;
         }
@@ -83,6 +84,11 @@
 
     public void addSession( TcpSession session )
     {
+        synchronized( newSessions )
+        {
+            newSessions.push( session );
+        }
+
         if( worker == null )
         {
             synchronized( this )
@@ -93,11 +99,6 @@
                     worker.start();
                 }
             }
-        }
-
-        synchronized( newSessions )
-        {
-            newSessions.push( session );
         }
 
         selector.wakeup();

Mime
View raw message