You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by el...@apache.org on 2010/10/02 01:30:30 UTC

svn commit: r1003705 - in /mina/branches/3.0/core/src: main/java/org/apache/mina/ main/java/org/apache/mina/service/ main/java/org/apache/mina/transport/socket/nio/ test/java/org/apache/mina/session/ test/java/org/apache/mina/transport/socket/nio/

Author: elecharny
Date: Fri Oct  1 23:30:29 2010
New Revision: 1003705

URL: http://svn.apache.org/viewvc?rev=1003705&view=rev
Log:
o Added the IoHandler interface
o Closing the channel when unbinding
o Fixed the NioAcceptorTest which was failing 
o Formating

Added:
    mina/branches/3.0/core/src/main/java/org/apache/mina/service/IoHandler.java
Modified:
    mina/branches/3.0/core/src/main/java/org/apache/mina/IoConnector.java
    mina/branches/3.0/core/src/main/java/org/apache/mina/IoSession.java
    mina/branches/3.0/core/src/main/java/org/apache/mina/transport/socket/nio/NioSelectorProcessor.java
    mina/branches/3.0/core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketAcceptor.java
    mina/branches/3.0/core/src/test/java/org/apache/mina/session/AbstractIoSessionTest.java
    mina/branches/3.0/core/src/test/java/org/apache/mina/transport/socket/nio/NioAcceptorTest.java

Modified: mina/branches/3.0/core/src/main/java/org/apache/mina/IoConnector.java
URL: http://svn.apache.org/viewvc/mina/branches/3.0/core/src/main/java/org/apache/mina/IoConnector.java?rev=1003705&r1=1003704&r2=1003705&view=diff
==============================================================================
--- mina/branches/3.0/core/src/main/java/org/apache/mina/IoConnector.java (original)
+++ mina/branches/3.0/core/src/main/java/org/apache/mina/IoConnector.java Fri Oct  1 23:30:29 2010
@@ -19,45 +19,44 @@
  */
 package org.apache.mina;
 
-
 import java.net.SocketAddress;
 
+import org.apache.mina.service.IoHandler;
 
 /**
  * Connects to endpoint, communicates with the server, and fires events to
  * {@link IoHandler}s.
  * 
- *
+ * 
  * @author <a href="http://mina.apache.org">Apache MINA Project</a>
  */
-public interface IoConnector extends IoService
-{
+public interface IoConnector extends IoService {
     /**
-     * Returns the connect timeout in milliseconds.  The default value is 1 minute.
+     * Returns the connect timeout in milliseconds. The default value is 1
+     * minute.
      */
     long getConnectTimeoutMillis();
 
-
     /**
-     * Sets the connect timeout in milliseconds.  The default value is 1 minute.
+     * Sets the connect timeout in milliseconds. The default value is 1 minute.
      */
-    void setConnectTimeoutMillis( long connectTimeoutInMillis );
-
+    void setConnectTimeoutMillis(long connectTimeoutInMillis);
 
     /**
      * Connects to the specified remote address.
-     *
+     * 
      * @return the {@link ConnectFuture} instance which is completed when the
      *         connection attempt initiated by this call succeeds or fails.
      */
-    ConnectFuture connect( SocketAddress remoteAddress );
-
+    ConnectFuture connect(SocketAddress remoteAddress);
 
     /**
-     * Connects to the specified remote address binding to the specified local address.
-     *
+     * Connects to the specified remote address binding to the specified local
+     * address.
+     * 
      * @return the {@link ConnectFuture} instance which is completed when the
      *         connection attempt initiated by this call succeeds or fails.
      */
-    ConnectFuture connect( SocketAddress remoteAddress, SocketAddress localAddress );
+    ConnectFuture connect(SocketAddress remoteAddress,
+            SocketAddress localAddress);
 }

Modified: mina/branches/3.0/core/src/main/java/org/apache/mina/IoSession.java
URL: http://svn.apache.org/viewvc/mina/branches/3.0/core/src/main/java/org/apache/mina/IoSession.java?rev=1003705&r1=1003704&r2=1003705&view=diff
==============================================================================
--- mina/branches/3.0/core/src/main/java/org/apache/mina/IoSession.java (original)
+++ mina/branches/3.0/core/src/main/java/org/apache/mina/IoSession.java Fri Oct  1 23:30:29 2010
@@ -22,14 +22,16 @@ package org.apache.mina;
 import java.net.SocketAddress;
 import java.util.Set;
 
+import org.apache.mina.service.IoHandler;
+
 /**
  * A handle which represents connection between two end-points regardless of
  * transport types.
  * <p/>
- * {@link IoSession} provides user-defined attributes.  User-defined attributes
- * are application-specific data which are associated with a session.
- * It often contains objects that represents the state of a higher-level protocol
- * and becomes a way to exchange data between filters and handlers.
+ * {@link IoSession} provides user-defined attributes. User-defined attributes
+ * are application-specific data which are associated with a session. It often
+ * contains objects that represents the state of a higher-level protocol and
+ * becomes a way to exchange data between filters and handlers.
  * <p/>
  * <h3>Adjusting Transport Type Specific Properties</h3>
  * <p/>
@@ -38,24 +40,30 @@ import java.util.Set;
  * <p/>
  * <h3>Thread Safety</h3>
  * <p/>
- * {@link IoSession} is thread-safe.  But please note that performing
- * more than one {@link #write(Object)} calls at the same time will
- * cause the {@link IoFilter#filterWrite(IoFilter.NextFilter,IoSession,WriteRequest)}
- * to be executed simultaneously, and therefore you have to make sure the
+ * {@link IoSession} is thread-safe. But please note that performing more than
+ * one {@link #write(Object)} calls at the same time will cause the
+ * {@link IoFilter#filterWrite(IoFilter.NextFilter,IoSession,WriteRequest)} to
+ * be executed simultaneously, and therefore you have to make sure the
  * {@link IoFilter} implementations you're using are thread-safe, too.
  * </p>
  * <p/>
- *
+ * 
  * @author <a href="http://mina.apache.org">Apache MINA Project</a>
  */
 public interface IoSession {
-    
+
     /**
      * the unique identifier of this session
+     * 
      * @return a unique identifier
      */
     long getId();
 
+    /**
+     * @return the {@link IoHandler} which handles this session.
+     */
+    IoHandler getHandler();
+
     /* ADDRESSES */
 
     /**
@@ -68,14 +76,15 @@ public interface IoSession {
      * session.
      */
     SocketAddress getLocalAddress();
-    
+
     /**
-     * @return the {@link IoService} which provides {@link IoSession} to this session.
+     * @return the {@link IoService} which provides {@link IoSession} to this
+     *         session.
      */
     IoService getService();
 
     /* READ / WRITE / CLOSE */
-    
+
     /**
      * Returns <code>true</code> if this session is connected with remote peer.
      */
@@ -88,16 +97,17 @@ public interface IoSession {
     boolean isClosing();
 
     /**
-     * Closes this session immediately or after all queued write requests
-     * are flushed.  This operation is asynchronous.  Wait for the returned
+     * Closes this session immediately or after all queued write requests are
+     * flushed. This operation is asynchronous. Wait for the returned
      * {@link CloseFuture} if you want to wait for the session actually closed.
-     *
-     * @param immediately {@code true} to close this session immediately.
-     *                    {@code false} to close this session after all queued
-     *                    write requests are flushed.
+     * 
+     * @param immediately
+     *            {@code true} to close this session immediately. {@code false}
+     *            to close this session after all queued write requests are
+     *            flushed.
      */
     CloseFuture close(boolean immediately);
-    
+
     /* READ/WRITE PAUSE MANAGEMENT */
 
     /**
@@ -119,21 +129,23 @@ public interface IoSession {
      * Resumes write operations for this session.
      */
     void resumeWrite();
-    
+
     /**
-     * Is read operation is suspended for this session. 
+     * Is read operation is suspended for this session.
+     * 
      * @return <code>true</code> if suspended
      */
     boolean isReadSuspended();
-    
+
     /**
      * Is write operation is suspended for this session.
+     * 
      * @return <code>true</code> if suspended
      */
     boolean isWriteSuspended();
-    
+
     /* BASIC STATS */
-    
+
     /**
      * Returns the total number of bytes which were read from this session.
      */
@@ -145,14 +157,15 @@ public interface IoSession {
     long getWrittenBytes();
 
     /* IDLE */
-    
+
     /**
-     * get the session configuration, it where the idle timeout are set
-     * and other transport specific configuration. 
+     * get the session configuration, it where the idle timeout are set and
+     * other transport specific configuration.
+     * 
      * @return the configuration of this session.
      */
     IoSessionConfig getConfig();
-    
+
     /**
      * @return the session's creation time in milliseconds
      */
@@ -173,36 +186,40 @@ public interface IoSession {
      */
     long getLastWriteTime();
 
-    
     /* ATTACHEMENT MANAGEMENT */
-    
+
     /**
      * Returns the value of the user-defined attribute of this session.
-     *
-     * @param name the name of the attribute
+     * 
+     * @param name
+     *            the name of the attribute
      * @return <tt>null</tt> if there is no attribute with the specified name
      */
     Object getAttribute(Object name);
 
     /**
      * Sets a user-defined attribute.
-     *
-     * @param name   the name of the attribute
-     * @param value the value of the attribute
-     * @return The old value of the attribute.  <tt>null</tt> if it is new.
+     * 
+     * @param name
+     *            the name of the attribute
+     * @param value
+     *            the value of the attribute
+     * @return The old value of the attribute. <tt>null</tt> if it is new.
      */
     Object setAttribute(Object name, Object value);
 
     /**
      * Removes a user-defined attribute with the specified name.
-     * @param name the name of the attribute
-     * @return The old value of the attribute.  <tt>null</tt> if not found.
+     * 
+     * @param name
+     *            the name of the attribute
+     * @return The old value of the attribute. <tt>null</tt> if not found.
      */
     Object removeAttribute(Object name);
 
     /**
-     * Returns <tt>true</tt> if this session contains the attribute with
-     * the specified <tt>name</tt>.
+     * Returns <tt>true</tt> if this session contains the attribute with the
+     * specified <tt>name</tt>.
      */
     boolean containsAttribute(Object name);
 

Added: mina/branches/3.0/core/src/main/java/org/apache/mina/service/IoHandler.java
URL: http://svn.apache.org/viewvc/mina/branches/3.0/core/src/main/java/org/apache/mina/service/IoHandler.java?rev=1003705&view=auto
==============================================================================
--- mina/branches/3.0/core/src/main/java/org/apache/mina/service/IoHandler.java (added)
+++ mina/branches/3.0/core/src/main/java/org/apache/mina/service/IoHandler.java Fri Oct  1 23:30:29 2010
@@ -0,0 +1,81 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.service;
+
+import java.io.IOException;
+
+import org.apache.mina.IdleStatus;
+import org.apache.mina.IoSession;
+
+/**
+ * Handles all I/O events fired by MINA.
+ * 
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ * 
+ * @see IoHandlerAdapter
+ */
+public interface IoHandler {
+    /**
+     * Invoked from an I/O processor thread when a new connection has been
+     * created. Because this method is supposed to be called from the same
+     * thread that handles I/O of multiple sessions, please implement this
+     * method to perform tasks that consumes minimal amount of time such as
+     * socket parameter and user-defined session attribute initialization.
+     */
+    void sessionCreated(IoSession session) throws Exception;
+
+    /**
+     * Invoked when a connection has been opened. This method is invoked after
+     * {@link #sessionCreated(IoSession)}. The biggest difference from
+     * {@link #sessionCreated(IoSession)} is that it's invoked from other thread
+     * than an I/O processor thread once thread model is configured properly.
+     */
+    void sessionOpened(IoSession session) throws Exception;
+
+    /**
+     * Invoked when a connection is closed.
+     */
+    void sessionClosed(IoSession session) throws Exception;
+
+    /**
+     * Invoked with the related {@link IdleStatus} when a connection becomes
+     * idle. This method is not invoked if the transport type is UDP; it's a
+     * known bug, and will be fixed in 2.0.
+     */
+    void sessionIdle(IoSession session, IdleStatus status) throws Exception;
+
+    /**
+     * Invoked when any exception is thrown by user {@link IoHandler}
+     * implementation or by MINA. If <code>cause</code> is an instance of
+     * {@link IOException}, MINA will close the connection automatically.
+     */
+    void exceptionCaught(IoSession session, Throwable cause) throws Exception;
+
+    /**
+     * Invoked when a message is received.
+     */
+    void messageReceived(IoSession session, Object message) throws Exception;
+
+    /**
+     * Invoked when a message written by {@link IoSession#write(Object)} is sent
+     * out.
+     */
+    void messageSent(IoSession session, Object message) throws Exception;
+}
\ No newline at end of file

Modified: mina/branches/3.0/core/src/main/java/org/apache/mina/transport/socket/nio/NioSelectorProcessor.java
URL: http://svn.apache.org/viewvc/mina/branches/3.0/core/src/main/java/org/apache/mina/transport/socket/nio/NioSelectorProcessor.java?rev=1003705&r1=1003704&r2=1003705&view=diff
==============================================================================
--- mina/branches/3.0/core/src/main/java/org/apache/mina/transport/socket/nio/NioSelectorProcessor.java (original)
+++ mina/branches/3.0/core/src/main/java/org/apache/mina/transport/socket/nio/NioSelectorProcessor.java Fri Oct  1 23:30:29 2010
@@ -41,54 +41,53 @@ import org.slf4j.LoggerFactory;
 /**
  * 
  * @author <a href="http://mina.apache.org">Apache MINA Project</a>
- *
+ * 
  */
 public class NioSelectorProcessor implements SelectorProcessor {
 
     private SelectorStrategy strategy;
-        
+
     private Logger log;
-    
-    private Map<SocketAddress,ServerSocketChannel> serverSocketChannels = new ConcurrentHashMap<SocketAddress, ServerSocketChannel>();
 
-    public NioSelectorProcessor(String name,SelectorStrategy strategy) {
+    private Map<SocketAddress, ServerSocketChannel> serverSocketChannels = new ConcurrentHashMap<SocketAddress, ServerSocketChannel>();
+
+    public NioSelectorProcessor(String name, SelectorStrategy strategy) {
         this.strategy = strategy;
-        this.log = LoggerFactory.getLogger("SelectorProcessor["+name+"]");
+        this.log = LoggerFactory.getLogger("SelectorProcessor[" + name + "]");
     }
-    
+
     private Selector selector;
-    
+
     // new binded server to add to the selector
     private final Queue<ServerSocketChannel> serverToAdd = new ConcurrentLinkedQueue<ServerSocketChannel>();
-    
+
     // server to remove of the selector
     private final Queue<ServerSocketChannel> serverToRemove = new ConcurrentLinkedQueue<ServerSocketChannel>();
-    
-    
+
     // new session freshly accepted, placed here for being added to the selector
     private final Queue<IoSession> sessionToConnect = new ConcurrentLinkedQueue<IoSession>();
-    
+
     // session to be removed of the selector
     private final Queue<IoSession> sessionToClose = new ConcurrentLinkedQueue<IoSession>();
-    
+
     /**
-     * Add a bound server channel for starting accepting 
-     * new client connections.
+     * Add a bound server channel for starting accepting new client connections.
+     * 
      * @param serverChannel
      */
     public void add(ServerSocketChannel serverChannel) {
-        log.debug("adding a server channel "+serverChannel);
+        log.debug("adding a server channel " + serverChannel);
         serverToAdd.add(serverChannel);
         wakeupWorker();
     }
-        
+
     private Object workerLock = new Object();
-    
+
     private SelectorWorker worker = null;
-    
+
     private void wakeupWorker() {
         synchronized (workerLock) {
-            if (worker == null ) {
+            if (worker == null) {
                 worker = new SelectorWorker();
                 worker.start();
             }
@@ -97,39 +96,38 @@ public class NioSelectorProcessor implem
             selector.wakeup();
         }
     }
-    
+
     @Override
     public void bindAndAcceptAddress(SocketAddress address) throws IOException {
         ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
-        
+
         serverSocketChannel.socket().bind(address);
         serverSocketChannel.configureBlocking(false);
-        serverSocketChannels.put(address,serverSocketChannel);
+        serverSocketChannels.put(address, serverSocketChannel);
         add(serverSocketChannel);
-        
-                
     }
-    
+
     @Override
     public void unbind(SocketAddress address) throws IOException {
         ServerSocketChannel channel = serverSocketChannels.get(address);
         channel.socket().close();
+        channel.close();
         serverSocketChannels.remove(channel);
-        log.debug("removing a server channel "+channel);
+        log.debug("removing a server channel " + channel);
         serverToRemove.add(channel);
         wakeupWorker();
     }
-    
+
     @Override
     public void createSession(Object clientSocket) {
-        // TODO Auto-generated method stub        
+        // TODO Auto-generated method stub
     }
 
     private class SelectorWorker extends Thread {
-        
+
         // map for finding the keys associated with a given server
         private Map<ServerSocketChannel, SelectionKey> serverKey = new HashMap<ServerSocketChannel, SelectionKey>();
-        
+
         @Override
         public void run() {
             if (selector == null) {
@@ -137,12 +135,12 @@ public class NioSelectorProcessor implem
                 try {
                     selector = Selector.open();
                 } catch (IOException e) {
-                   log.error("IOException while opening a new Selector",e);
+                    log.error("IOException while opening a new Selector", e);
                 }
             }
-            
-            for(;;) {
-                try {                    
+
+            for (;;) {
+                try {
                     // pop server sockets for removing
                     if (serverToRemove.size() > 0) {
                         while (!serverToRemove.isEmpty()) {
@@ -155,37 +153,41 @@ public class NioSelectorProcessor implem
                             }
                         }
                     }
-                    
+
                     // pop new server sockets for accepting
                     if (serverToAdd.size() > 0) {
                         while (!serverToAdd.isEmpty()) {
                             ServerSocketChannel channel = serverToAdd.poll();
-                            SelectionKey key = channel.register(selector, SelectionKey.OP_ACCEPT);
+                            SelectionKey key = channel.register(selector,
+                                    SelectionKey.OP_ACCEPT);
                             key.attach(channel);
-                        }          
+                        }
                     }
                     log.debug("selecting...");
                     int result = selector.select();
-                    log.debug("... done selecting : "+result);
-                    
+                    log.debug("... done selecting : " + result);
+
                     if (result > 0) {
                         // process selected keys
-                        for (SelectionKey key:selector.selectedKeys()) {
+                        for (SelectionKey key : selector.selectedKeys()) {
                             if (key.isAcceptable()) {
                                 log.debug("acceptable new client");
                                 // accepted connection
-                                SocketChannel newClientChannel = ((ServerSocketChannel)key.attachment()).accept();
+                                SocketChannel newClientChannel = ((ServerSocketChannel) key
+                                        .attachment()).accept();
                                 log.debug("client accepted");
                                 // and give it's to the strategy
-                                strategy.getSelectorForNewSession(NioSelectorProcessor.this).createSession(newClientChannel);
-                                
+                                strategy.getSelectorForNewSession(
+                                        NioSelectorProcessor.this)
+                                        .createSession(newClientChannel);
+
                             }
                         }
                     }
                 } catch (IOException e) {
-                    log.error("IOException while selecting selector",e);
+                    log.error("IOException while selecting selector", e);
                 }
-                
+
                 // stop the worker if needed
                 synchronized (workerLock) {
                     if (selector.keys().isEmpty()) {
@@ -193,7 +195,7 @@ public class NioSelectorProcessor implem
                         break;
                     }
                 }
-            } 
+            }
         }
-    }    
+    }
 }

Modified: mina/branches/3.0/core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketAcceptor.java
URL: http://svn.apache.org/viewvc/mina/branches/3.0/core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketAcceptor.java?rev=1003705&r1=1003704&r2=1003705&view=diff
==============================================================================
--- mina/branches/3.0/core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketAcceptor.java (original)
+++ mina/branches/3.0/core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketAcceptor.java Fri Oct  1 23:30:29 2010
@@ -25,54 +25,55 @@ import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
 
-import org.apache.mina.IoServiceListener;
 import org.apache.mina.service.AbstractIoAcceptor;
 import org.apache.mina.service.SelectorStrategy;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
 /**
- * TODO 
+ * TODO
  * 
  * @author <a href="http://mina.apache.org">Apache MINA Project</a>
  */
 public class NioSocketAcceptor extends AbstractIoAcceptor {
-    
+
     static final Logger LOG = LoggerFactory.getLogger(NioSocketAcceptor.class);
-    
+
     // list of bound addresses
-    private Set<SocketAddress> addresses = Collections.synchronizedSet(new HashSet<SocketAddress>());
-    
+    private Set<SocketAddress> addresses = Collections
+            .synchronizedSet(new HashSet<SocketAddress>());
+
     // map of the created selection keys, mainly used for cancelling them.
-   // private Map<SocketAddress,NioSelectorProcessor> serverSocketChannels = new ConcurrentHashMap<SocketAddress, NioSelectorProcessor>();
-    
+    // private Map<SocketAddress,NioSelectorProcessor> serverSocketChannels =
+    // new ConcurrentHashMap<SocketAddress, NioSelectorProcessor>();
+
     // the strategy for dispatching servers and client to selector threads.
     private SelectorStrategy strategy;
-    
+
     public NioSocketAcceptor(SelectorStrategy strategy) {
-        this.strategy = strategy; 
+        this.strategy = strategy;
     }
-    
-    
+
     @Override
     public void bind(SocketAddress... localAddress) throws IOException {
-        if ( localAddress == null ) {
+        if (localAddress == null) {
             // We should at least have one address to bind on
-            throw new IllegalStateException( "LocalAdress cannot be null" );
+            throw new IllegalStateException("LocalAdress cannot be null");
         }
-        
-        for(SocketAddress address : localAddress) {
+
+        for (SocketAddress address : localAddress) {
             // check if the address is already bound
             synchronized (this) {
                 if (addresses.contains(address)) {
-                    throw new IOException("address "+address+" already bound");
+                    throw new IOException("address " + address
+                            + " already bound");
                 }
-                
-                LOG.debug("binding address {}",address);
-                
+
+                LOG.debug("binding address {}", address);
+
                 addresses.add(address);
-                NioSelectorProcessor processor = (NioSelectorProcessor)strategy.getSelectorForBindNewAddress();
+                NioSelectorProcessor processor = (NioSelectorProcessor) strategy
+                        .getSelectorForBindNewAddress();
                 processor.bindAndAcceptAddress(address);
             }
         }
@@ -86,19 +87,19 @@ public class NioSocketAcceptor extends A
     @Override
     public void unbind(SocketAddress... localAddresses) throws IOException {
         for (SocketAddress socketAddress : localAddresses) {
-            LOG.debug("unbinding {}",socketAddress);
+            LOG.debug("unbinding {}", socketAddress);
             synchronized (this) {
                 strategy.unbind(socketAddress);
+                addresses.remove(socketAddress);
             }
         }
     }
 
     @Override
     public void unbindAll() throws IOException {
-        for (SocketAddress socketAddress: addresses) {
+        for (SocketAddress socketAddress : addresses) {
             unbind(socketAddress);
         }
     }
 
-    
 }
\ No newline at end of file

Modified: mina/branches/3.0/core/src/test/java/org/apache/mina/session/AbstractIoSessionTest.java
URL: http://svn.apache.org/viewvc/mina/branches/3.0/core/src/test/java/org/apache/mina/session/AbstractIoSessionTest.java?rev=1003705&r1=1003704&r2=1003705&view=diff
==============================================================================
--- mina/branches/3.0/core/src/test/java/org/apache/mina/session/AbstractIoSessionTest.java (original)
+++ mina/branches/3.0/core/src/test/java/org/apache/mina/session/AbstractIoSessionTest.java Fri Oct  1 23:30:29 2010
@@ -7,7 +7,7 @@ import junit.framework.Assert;
 import org.apache.mina.CloseFuture;
 import org.apache.mina.IoService;
 import org.apache.mina.IoSessionConfig;
-import org.apache.mina.session.AbstractIoSession;
+import org.apache.mina.service.IoHandler;
 import org.junit.Test;
 
 public class AbstractIoSessionTest {
@@ -72,23 +72,30 @@ public class AbstractIoSessionTest {
         @Override
         public void suspendWrite() {
         }
+
+        @Override
+        public IoHandler getHandler() {
+            // TODO Auto-generated method stub
+            return null;
+        }
     }
 
     @Test
     public void testGetId() {
-        Assert.assertNotSame((new DummySession(null)).getId(), (new DummySession(null)).getId());
-        
+        Assert.assertNotSame((new DummySession(null)).getId(),
+                (new DummySession(null)).getId());
+
     }
 
     @Test
     public void testCreationTime() {
-           long before = System.currentTimeMillis();
-           long creation = (new DummySession(null)).getCreationTime();
-           long after = System.currentTimeMillis();
-           Assert.assertTrue( creation <= after);
-           Assert.assertTrue( creation >= before);
+        long before = System.currentTimeMillis();
+        long creation = (new DummySession(null)).getCreationTime();
+        long after = System.currentTimeMillis();
+        Assert.assertTrue(creation <= after);
+        Assert.assertTrue(creation >= before);
     }
-    
+
     @Test
     public void testAttachment() {
         AbstractIoSession aio = new DummySession(null);

Modified: mina/branches/3.0/core/src/test/java/org/apache/mina/transport/socket/nio/NioAcceptorTest.java
URL: http://svn.apache.org/viewvc/mina/branches/3.0/core/src/test/java/org/apache/mina/transport/socket/nio/NioAcceptorTest.java?rev=1003705&r1=1003704&r2=1003705&view=diff
==============================================================================
--- mina/branches/3.0/core/src/test/java/org/apache/mina/transport/socket/nio/NioAcceptorTest.java (original)
+++ mina/branches/3.0/core/src/test/java/org/apache/mina/transport/socket/nio/NioAcceptorTest.java Fri Oct  1 23:30:29 2010
@@ -22,6 +22,7 @@ package org.apache.mina.transport.socket
 
 import java.io.IOException;
 import java.net.InetSocketAddress;
+import java.net.SocketAddress;
 
 import junit.framework.Assert;
 
@@ -31,32 +32,36 @@ import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
 /**
  * A basic Acceptor test
+ * 
  * @author <a href="http://mina.apache.org">Apache MINA Project</a>
- *
+ * 
  */
 public class NioAcceptorTest {
-    
-    static final private Logger LOG = LoggerFactory.getLogger(NioAcceptorTest.class);
-    
+
+    static final private Logger LOG = LoggerFactory
+            .getLogger(NioAcceptorTest.class);
+
     @Test
     public void acceptorTest() {
         LOG.info("starting NioAcceptorTest");
-        
-        OneThreadSelectorStrategy strategy = new OneThreadSelectorStrategy(new SelectorFactory(NioSelectorProcessor.class));
+
+        OneThreadSelectorStrategy strategy = new OneThreadSelectorStrategy(
+                new SelectorFactory(NioSelectorProcessor.class));
         NioSocketAcceptor acceptor = new NioSocketAcceptor(strategy);
+        SocketAddress address = new InetSocketAddress(9999);
+
         try {
-            acceptor.bind(new InetSocketAddress(9999));
+            acceptor.bind(address);
             LOG.debug("Waiting 25 sec");
             Thread.sleep(25000);
             LOG.debug("Unbinding");
-            
-            acceptor.unbind(new InetSocketAddress(9999));
-            
-            LOG.debug("Trying to rebind the freed port");            
-            acceptor.bind(new InetSocketAddress(9999));
+
+            acceptor.unbind(address);
+
+            LOG.debug("Trying to rebind the freed port");
+            acceptor.bind(address);
             LOG.debug("Bound");
         } catch (IOException e) {
             e.printStackTrace();
@@ -70,14 +75,14 @@ public class NioAcceptorTest {
             LOG.info("Trying to bind an already bound port");
             // try to bind an already bound port
             acceptor.bind(new InetSocketAddress(9999));
-            
+
             Assert.fail();
-            
+
         } catch (IOException e) {
-            LOG.info("catching the exception",e);
+            LOG.info("catching the exception", e);
             ex = e;
         }
         Assert.assertNotNull(ex);
-        
+
     }
 }
\ No newline at end of file