directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r111332 - /incubator/directory/seda/branches/trustin/src/java/org/apache/mina/protocol/CoreAdapter.java
Date Thu, 09 Dec 2004 01:27:26 GMT
Author: akarasulu
Date: Wed Dec  8 17:27:24 2004
New Revision: 111332

URL: http://svn.apache.org/viewcvs?view=rev&rev=111332
Log:
formating
Modified:
   incubator/directory/seda/branches/trustin/src/java/org/apache/mina/protocol/CoreAdapter.java

Modified: incubator/directory/seda/branches/trustin/src/java/org/apache/mina/protocol/CoreAdapter.java
Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/trustin/src/java/org/apache/mina/protocol/CoreAdapter.java?view=diff&rev=111332&p1=incubator/directory/seda/branches/trustin/src/java/org/apache/mina/protocol/CoreAdapter.java&r1=111331&p2=incubator/directory/seda/branches/trustin/src/java/org/apache/mina/protocol/CoreAdapter.java&r2=111332
==============================================================================
--- incubator/directory/seda/branches/trustin/src/java/org/apache/mina/protocol/CoreAdapter.java
(original)
+++ incubator/directory/seda/branches/trustin/src/java/org/apache/mina/protocol/CoreAdapter.java
Wed Dec  8 17:27:24 2004
@@ -19,16 +19,12 @@
  */
 package org.apache.mina.protocol;
 
+
 import java.net.SocketAddress;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.mina.core.IdleStatus;
-import org.apache.mina.core.ReadBuffer;
-import org.apache.mina.core.Session;
-import org.apache.mina.core.SessionConfig;
-import org.apache.mina.core.SessionHandler;
-import org.apache.mina.core.WriteBuffer;
+import org.apache.mina.core.*;
 import org.apache.mina.util.Queue;
 
 
@@ -36,230 +32,334 @@
  * TODO Document me.
  *
  * @author Trustin Lee (trustin@apache.org)
- * @version $Rev$, $Date$,
+ * @version $Rev$, $Date: 2004-12-08 10:40:31 -0500 (Wed, 08 Dec 2004)
+ *          $,
  */
-public class CoreAdapter {
-    private static final Log log = LogFactory.getLog(CoreAdapter.class);
+public class CoreAdapter
+{
+    private static final Log log = LogFactory.getLog( CoreAdapter.class );
+
 
-    public static SessionHandler adapt(ProtocolProvider protocolProvider) {
-        return new SessionHandlerAdapter(protocolProvider);
+    public static SessionHandler adapt( ProtocolProvider protocolProvider )
+    {
+        return new SessionHandlerAdapter( protocolProvider );
     }
 
-    private static class SessionHandlerAdapter implements SessionHandler {
+
+    private static class SessionHandlerAdapter implements SessionHandler
+    {
         private final ProtocolCodec codec;
         private final ProtocolSessionHandler handler;
 
-        public SessionHandlerAdapter(ProtocolProvider protocolProvider) {
+
+        public SessionHandlerAdapter( ProtocolProvider protocolProvider )
+        {
             this.codec = protocolProvider.newCodec();
             this.handler = protocolProvider.getHandler();
         }
 
-        public void sessionOpened(Session session) {
-            ProtocolSession psession = new ProtocolSessionImpl(session, this);
-            session.setAttachment(psession);
-            fireSessionOpened(psession);
+
+        public void sessionOpened( Session session )
+        {
+            ProtocolSession psession = new ProtocolSessionImpl( session, this );
+            session.setAttachment( psession );
+            fireSessionOpened( psession );
         }
 
-        public void sessionClosed(Session session) {
-            fireSessionClosed((ProtocolSession) session.getAttachment());
+
+        public void sessionClosed( Session session )
+        {
+            fireSessionClosed( ( ProtocolSession ) session.getAttachment() );
         }
 
-        public void sessionIdle(Session session, IdleStatus status) {
-            fireSessionIdle((ProtocolSession) session.getAttachment(), status);
+
+        public void sessionIdle( Session session, IdleStatus status )
+        {
+            fireSessionIdle( ( ProtocolSession ) session.getAttachment(), status );
         }
 
-        public void exceptionCaught(Session session, Throwable cause) {
-            fireExceptionCaught((ProtocolSession) session.getAttachment(),
-                                cause);
+
+        public void exceptionCaught( Session session, Throwable cause )
+        {
+            fireExceptionCaught( ( ProtocolSession ) session.getAttachment(),
+                    cause );
         }
 
-        public void dataRead(Session session, int readBytes) {
+
+        public void dataRead( Session session, int readBytes )
+        {
             ProtocolSession psession =
-                (ProtocolSession) session.getAttachment();
+                    ( ProtocolSession ) session.getAttachment();
             ReadBuffer in = session.getReadBuffer();
             int sizeBefore;
             int sizeAfter;
             Object result;
 
-            try {
-                do {
+            try
+            {
+                do
+                {
                     result = null;
 
-                    synchronized (in) {
+                    synchronized ( in )
+                    {
                         sizeBefore = in.remaining();
-                        result = codec.decode(psession, in);
+                        result = codec.decode( psession, in );
                         sizeAfter = in.remaining();
                     }
 
-                    if (sizeBefore != sizeAfter) {
+                    if ( sizeBefore != sizeAfter )
+                    {
                         in.signal();
                     }
 
-                    if (result != null) {
-                        fireMessageReceived(psession, result);
-                    } else {
+                    if ( result != null )
+                    {
+                        fireMessageReceived( psession, result );
+                    }
+                    else
+                    {
                         break;
                     }
-                } while (sizeAfter > 0);
-            } catch (Throwable t) {
-                fireExceptionCaught(psession, t);
+                }
+                while ( sizeAfter > 0 );
+            }
+            catch ( Throwable t )
+            {
+                fireExceptionCaught( psession, t );
             }
         }
 
-        public void dataWritten(Session session, int writtenBytes) {
-            write(session);
+
+        public void dataWritten( Session session, int writtenBytes )
+        {
+            write( session );
+        }
+
+
+        public void markerReleased( Session session, Object marker )
+        {
+            fireMessageSent( ( ProtocolSession ) session.getAttachment(), marker );
         }
 
-		public void markerReleased(Session session, Object marker) {
-			fireMessageSent((ProtocolSession) session.getAttachment(), marker);
-		}
-		
-        private void write(Session session) {
+
+        private void write( Session session )
+        {
             ProtocolSessionImpl psession =
-                (ProtocolSessionImpl) session.getAttachment();
+                    ( ProtocolSessionImpl ) session.getAttachment();
             Queue writeQueue = psession.writeQueue;
 
-            if (writeQueue.isEmpty())
+            if ( writeQueue.isEmpty() )
+            {
                 return;
+            }
 
             WriteBuffer out = session.getWriteBuffer();
 
-            try {
-                while (!writeQueue.isEmpty()) {
-                    synchronized (out) {
-                        if (codec.encode(psession, writeQueue.first(), out)) {
-                        	out.putMarker(writeQueue.pop());
+            try
+            {
+                while ( !writeQueue.isEmpty() )
+                {
+                    synchronized ( out )
+                    {
+                        if ( codec.encode( psession, writeQueue.first(), out ) )
+                        {
+                            out.putMarker( writeQueue.pop() );
                             out.flush();
-                        } else {
+                        }
+                        else
+                        {
                             out.flush();
                             break;
                         }
                     }
                 }
-            } catch (Throwable t) {
-                fireExceptionCaught(psession, t);
+            }
+            catch ( Throwable t )
+            {
+                fireExceptionCaught( psession, t );
             }
         }
 
-        private void fireSessionOpened(ProtocolSession session) {
-            try {
-                handler.sessionOpened(session);
-            } catch (Throwable t) {
-                fireExceptionCaught(session, t);
+
+        private void fireSessionOpened( ProtocolSession session )
+        {
+            try
+            {
+                handler.sessionOpened( session );
+            }
+            catch ( Throwable t )
+            {
+                fireExceptionCaught( session, t );
             }
         }
 
-        private void fireSessionClosed(ProtocolSession session) {
-            try {
-                handler.sessionClosed(session);
-            } catch (Throwable t) {
-                fireExceptionCaught(session, t);
+
+        private void fireSessionClosed( ProtocolSession session )
+        {
+            try
+            {
+                handler.sessionClosed( session );
+            }
+            catch ( Throwable t )
+            {
+                fireExceptionCaught( session, t );
             }
         }
 
-        private void fireSessionIdle(ProtocolSession session,
-                                     IdleStatus idleStatus) {
-            try {
-                handler.sessionIdle(session, idleStatus);
-            } catch (Throwable t) {
-                fireExceptionCaught(session, t);
+
+        private void fireSessionIdle( ProtocolSession session,
+                                      IdleStatus idleStatus )
+        {
+            try
+            {
+                handler.sessionIdle( session, idleStatus );
+            }
+            catch ( Throwable t )
+            {
+                fireExceptionCaught( session, t );
             }
         }
 
-        private void fireMessageReceived(ProtocolSession session,
-                                         Object message) {
-            try {
-                handler.messageReceived(session, message);
-            } catch (Throwable t) {
-                fireExceptionCaught(session, t);
+
+        private void fireMessageReceived( ProtocolSession session,
+                                          Object message )
+        {
+            try
+            {
+                handler.messageReceived( session, message );
+            }
+            catch ( Throwable t )
+            {
+                fireExceptionCaught( session, t );
             }
         }
 
-        private void fireMessageSent(ProtocolSession session, Object message) {
-            try {
-                handler.messageSent(session, message);
-            } catch (Throwable t) {
-                fireExceptionCaught(session, t);
+
+        private void fireMessageSent( ProtocolSession session, Object message )
+        {
+            try
+            {
+                handler.messageSent( session, message );
+            }
+            catch ( Throwable t )
+            {
+                fireExceptionCaught( session, t );
             }
         }
 
-        private void fireExceptionCaught(ProtocolSession session,
-                                         Throwable cause) {
-            try {
-                handler.exceptionCaught(session, cause);
-            } catch (Throwable t) {
-                log.error("Exception from excaptionCaught.", t);
+
+        private void fireExceptionCaught( ProtocolSession session,
+                                          Throwable cause )
+        {
+            try
+            {
+                handler.exceptionCaught( session, cause );
+            }
+            catch ( Throwable t )
+            {
+                log.error( "Exception from excaptionCaught.", t );
             }
         }
     }
 
-    private static class ProtocolSessionImpl implements ProtocolSession {
+    private static class ProtocolSessionImpl implements ProtocolSession
+    {
         private final Session session;
         private final SessionHandlerAdapter adapter;
-        private final Queue writeQueue = new Queue(16);
+        private final Queue writeQueue = new Queue( 16 );
         private Object attachment;
 
-        private ProtocolSessionImpl(Session session,
-                                    SessionHandlerAdapter adapter) {
+
+        private ProtocolSessionImpl( Session session,
+                                     SessionHandlerAdapter adapter )
+        {
             this.session = session;
             this.adapter = adapter;
         }
 
-        public void close() {
+
+        public void close()
+        {
             session.close();
         }
 
-        public Object getAttachment() {
+
+        public Object getAttachment()
+        {
             return attachment;
         }
 
-        public void setAttachment(Object attachment) {
+
+        public void setAttachment( Object attachment )
+        {
             this.attachment = attachment;
         }
 
-        public boolean write(Object message) {
-            synchronized (session.getWriteBuffer()) {
-                writeQueue.push(message);
+
+        public boolean write( Object message )
+        {
+            synchronized ( session.getWriteBuffer() )
+            {
+                writeQueue.push( message );
             }
 
-            adapter.write(session);
+            adapter.write( session );
             return true;
         }
 
-        public boolean isConnected() {
+
+        public boolean isConnected()
+        {
             return session.isConnected();
         }
 
-        public boolean isClosed() {
+
+        public boolean isClosed()
+        {
             return session.isClosed();
         }
 
-        public SessionConfig getConfig() {
+
+        public SessionConfig getConfig()
+        {
             return session.getConfig();
         }
 
-        public SocketAddress getRemoteAddress() {
+
+        public SocketAddress getRemoteAddress()
+        {
             return session.getRemoteAddress();
         }
 
-        public SocketAddress getLocalAddress() {
+
+        public SocketAddress getLocalAddress()
+        {
             return session.getLocalAddress();
         }
 
-        public long getLastIoTime() {
+
+        public long getLastIoTime()
+        {
             return session.getLastIoTime();
         }
 
-        public long getLastReadTime() {
+
+        public long getLastReadTime()
+        {
             return session.getLastReadTime();
         }
 
-        public long getLastWriteTime() {
+
+        public long getLastWriteTime()
+        {
             return session.getLastWriteTime();
         }
 
-        public boolean isIdle(IdleStatus status) {
-            return session.isIdle(status);
+
+        public boolean isIdle( IdleStatus status )
+        {
+            return session.isIdle( status );
         }
     }
 }

Mime
View raw message