directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jvermill...@apache.org
Subject svn commit: r427105 - /directory/sandbox/jvermillard/mina/java/org/apache/mina/transport/socket/nio/SocketConnector.java
Date Mon, 31 Jul 2006 12:48:27 GMT
Author: jvermillard
Date: Mon Jul 31 05:48:26 2006
New Revision: 427105

URL: http://svn.apache.org/viewvc?rev=427105&view=rev
Log:
* fixed code style
* change newSession and renewSession to one method called connectSession

Modified:
    directory/sandbox/jvermillard/mina/java/org/apache/mina/transport/socket/nio/SocketConnector.java

Modified: directory/sandbox/jvermillard/mina/java/org/apache/mina/transport/socket/nio/SocketConnector.java
URL: http://svn.apache.org/viewvc/directory/sandbox/jvermillard/mina/java/org/apache/mina/transport/socket/nio/SocketConnector.java?rev=427105&r1=427104&r2=427105&view=diff
==============================================================================
--- directory/sandbox/jvermillard/mina/java/org/apache/mina/transport/socket/nio/SocketConnector.java
(original)
+++ directory/sandbox/jvermillard/mina/java/org/apache/mina/transport/socket/nio/SocketConnector.java
Mon Jul 31 05:48:26 2006
@@ -174,12 +174,7 @@
             if( ch.connect( address ) )
             {
             	SocketSessionImpl session;
-            	if(reconnectingSession==null)
-            		session= newSession( ch, handler, config );
-            	else {
-            		session=renewSession((SocketSessionImpl)reconnectingSession,ch);
-            	}
- 
+                session = connectSession( ch, handler, config , (SocketSessionImpl)reconnectingSession
);
                 success = true;
                 DefaultConnectFuture future = new DefaultConnectFuture();
                 future.setSession( session );
@@ -207,11 +202,8 @@
             }
         }
 
-        ConnectionRequest request;
-        if(reconnectingSession==null)
-        	request = new ConnectionRequest( ch, handler, config );
-        else
-        	request = new ConnectionRequest( ch, handler, config, reconnectingSession);
+        ConnectionRequest request = new ConnectionRequest( ch, handler, config, reconnectingSession
);
+        
         synchronized( lock )
         {
             try
@@ -253,8 +245,8 @@
     	if( ! ( session instanceof SocketSessionImpl ) )
             throw new IllegalArgumentException( "Unexpected session type: "
                                                 + session.getClass() );
-    	SocketSessionImpl sess=(SocketSessionImpl)session;
-    	if(sess.isConnected())
+    	SocketSessionImpl sess = (SocketSessionImpl)session;
+    	if( sess.isConnected() )
     		throw new IllegalArgumentException("The session is not closed, can't reconnect it");
     	
     	return connect(sess.getRemoteAddress(),null,sess.getHandler(),null,session);
@@ -322,10 +314,7 @@
             {
                 ch.finishConnect();
                 SocketSessionImpl session;
-                if(entry.reconnectingSession==null)
-                	session= newSession( ch, entry.handler, entry.config );
-                else
-                	session= renewSession((SocketSessionImpl) entry.reconnectingSession,ch);
+                session= connectSession( ch, entry.handler, entry.config, (SocketSessionImpl)
entry.reconnectingSession);
                 entry.setSession( session );
                 success = true;
             }
@@ -386,38 +375,32 @@
         }
     }
     
-    
-    // recycle an old session
-    private SocketSessionImpl renewSession(SocketSessionImpl reconnectingSession,SocketChannel
ch) throws IOException  {
-    	// is needed to recall session created ? I think no.
-    	//( ( SocketFilterChain ) reconnectingSession.getFilterChain() ).sessionCreated( reconnectingSession
);
-    	reconnectingSession.unclose();
-    	
-    	reconnectingSession.getManagedSessions().add( reconnectingSession );
-    	reconnectingSession.getIoProcessor().addNew( reconnectingSession );
-    	reconnectingSession.setSocketChannel(ch);
-		return (SocketSessionImpl)reconnectingSession;
-    }
-    private SocketSessionImpl newSession( SocketChannel ch, IoHandler handler, IoServiceConfig
config )
+    private SocketSessionImpl connectSession( SocketChannel ch, IoHandler handler, IoServiceConfig
config,SocketSessionImpl reconnectingSession)
         throws IOException
     {
-        SocketSessionImpl session = new SocketSessionImpl( this,
-                                                           nextProcessor(),
-                                                           managedSessions,
-                                                           config.getSessionConfig(),
-                                                           ch,
-                                                           handler,
-                                                           ch.socket().getRemoteSocketAddress()
);
-        try
-        {
-            getFilterChainBuilder().buildFilterChain( session.getFilterChain() );
-            config.getFilterChainBuilder().buildFilterChain( session.getFilterChain() );
-            config.getThreadModel().buildFilterChain( session.getFilterChain() );
-            ( ( SocketFilterChain ) session.getFilterChain() ).sessionCreated( session );
+        SocketSessionImpl session;
+        
+        if( reconnectingSession != null ) 
+        {
+            reconnectingSession.unclose();
+            session = reconnectingSession;
+            reconnectingSession.setSocketChannel(ch);
         }
-        catch( Throwable e )
+        else 
         {
-            throw ( IOException ) new IOException( "Failed to create a session." ).initCause(
e );
+            session = new SocketSessionImpl( this, nextProcessor(), managedSessions, config.getSessionConfig(),
+                                             ch, handler, ch.socket().getRemoteSocketAddress()
);
+            try
+            {
+                getFilterChainBuilder().buildFilterChain( session.getFilterChain() );
+                config.getFilterChainBuilder().buildFilterChain( session.getFilterChain()
);
+                config.getThreadModel().buildFilterChain( session.getFilterChain() );
+                ( ( SocketFilterChain ) session.getFilterChain() ).sessionCreated( session
);
+            }
+            catch( Throwable e )
+            {
+                throw ( IOException ) new IOException( "Failed to create a session." ).initCause(
e );
+            }
         }
         session.getManagedSessions().add( session );
         session.getIoProcessor().addNew( session );



Mime
View raw message