You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by jv...@apache.org on 2012/11/08 11:43:26 UTC

svn commit: r1407005 - in /mina/mina/trunk: ./ core/src/main/java/org/apache/mina/api/ core/src/main/java/org/apache/mina/filter/logging/ core/src/main/java/org/apache/mina/service/idlechecker/ core/src/main/java/org/apache/mina/session/ core/src/main/...

Author: jvermillard
Date: Thu Nov  8 10:43:24 2012
New Revision: 1407005

URL: http://svn.apache.org/viewvc?rev=1407005&view=rev
Log:
 * fixed a dead lock on registration
 * no more select timeout
 * selector are started before the first connection
 * added the messageSent event 

Modified:
    mina/mina/trunk/core/src/main/java/org/apache/mina/api/AbstractIoFilter.java
    mina/mina/trunk/core/src/main/java/org/apache/mina/api/IoFilter.java
    mina/mina/trunk/core/src/main/java/org/apache/mina/filter/logging/LoggingFilter.java
    mina/mina/trunk/core/src/main/java/org/apache/mina/service/idlechecker/IndexedIdleChecker.java
    mina/mina/trunk/core/src/main/java/org/apache/mina/session/AbstractIoSession.java
    mina/mina/trunk/core/src/main/java/org/apache/mina/session/DefaultWriteRequest.java
    mina/mina/trunk/core/src/main/java/org/apache/mina/transport/nio/NioSelectorLoop.java
    mina/mina/trunk/core/src/main/java/org/apache/mina/transport/nio/NioTcpServer.java
    mina/mina/trunk/core/src/main/java/org/apache/mina/transport/nio/NioTcpSession.java
    mina/mina/trunk/core/src/main/java/org/apache/mina/transport/nio/NioUdpServer.java
    mina/mina/trunk/core/src/main/java/org/apache/mina/transport/nio/SelectorLoop.java
    mina/mina/trunk/examples/src/main/java/org/apache/mina/examples/echoserver/NioEchoServer.java
    mina/mina/trunk/examples/src/main/java/org/apache/mina/examples/udpecho/NioUdpEchoServer.java
    mina/mina/trunk/pom.xml

Modified: mina/mina/trunk/core/src/main/java/org/apache/mina/api/AbstractIoFilter.java
URL: http://svn.apache.org/viewvc/mina/mina/trunk/core/src/main/java/org/apache/mina/api/AbstractIoFilter.java?rev=1407005&r1=1407004&r2=1407005&view=diff
==============================================================================
--- mina/mina/trunk/core/src/main/java/org/apache/mina/api/AbstractIoFilter.java (original)
+++ mina/mina/trunk/core/src/main/java/org/apache/mina/api/AbstractIoFilter.java Thu Nov  8 10:43:24 2012
@@ -66,4 +66,11 @@ public abstract class AbstractIoFilter i
             final WriteFilterChainController controller) {
         controller.callWriteNextFilter(message);
     }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void messageSent(final IoSession session, final Object message) {
+    }
 }
\ No newline at end of file

Modified: mina/mina/trunk/core/src/main/java/org/apache/mina/api/IoFilter.java
URL: http://svn.apache.org/viewvc/mina/mina/trunk/core/src/main/java/org/apache/mina/api/IoFilter.java?rev=1407005&r1=1407004&r2=1407005&view=diff
==============================================================================
--- mina/mina/trunk/core/src/main/java/org/apache/mina/api/IoFilter.java (original)
+++ mina/mina/trunk/core/src/main/java/org/apache/mina/api/IoFilter.java Thu Nov  8 10:43:24 2012
@@ -66,4 +66,12 @@ public interface IoFilter {
      * @param message the message to process before writing
      */
     void messageWriting(IoSession session, Object message, WriteFilterChainController controller);
+
+    /**
+     * Invoked when a high level message was written to the low level O/S buffer.
+     * 
+     * @param session {@link IoSession} associated with the invocation
+     * @param message the incoming message to process
+     */
+    void messageSent(IoSession session, Object message);
 }
\ No newline at end of file

Modified: mina/mina/trunk/core/src/main/java/org/apache/mina/filter/logging/LoggingFilter.java
URL: http://svn.apache.org/viewvc/mina/mina/trunk/core/src/main/java/org/apache/mina/filter/logging/LoggingFilter.java?rev=1407005&r1=1407004&r2=1407005&view=diff
==============================================================================
--- mina/mina/trunk/core/src/main/java/org/apache/mina/filter/logging/LoggingFilter.java (original)
+++ mina/mina/trunk/core/src/main/java/org/apache/mina/filter/logging/LoggingFilter.java Thu Nov  8 10:43:24 2012
@@ -47,6 +47,9 @@ public class LoggingFilter implements Io
     /** The log level for the messageWritting event. Default to INFO. */
     private LogLevel messageWritingLevel = LogLevel.INFO;
 
+    /** The log level for the messageSent event. Default to INFO. */
+    private LogLevel messageSentLevel = LogLevel.INFO;
+
     /** The log level for the messageReceived event. Default to INFO. */
     private LogLevel messageReceivedLevel = LogLevel.INFO;
 
@@ -176,6 +179,14 @@ public class LoggingFilter implements Io
      * {@inheritDoc}
      */
     @Override
+    public void messageSent(final IoSession session, final Object message) {
+        log(messageSentLevel, "IDLE");
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
     public void messageReceived(final IoSession session, final Object message,
             final ReadFilterChainController controller) {
         if (message instanceof ByteBuffer) {
@@ -294,4 +305,23 @@ public class LoggingFilter implements Io
     public LogLevel getSessionClosedLogLevel() {
         return sessionClosedLevel;
     }
+
+    /**
+     * Get the LogLevel for the messageSent event.
+     * 
+     * @return The LogLevel for the messageSent eventType
+     */
+    public LogLevel getMessageSentLevel() {
+        return messageSentLevel;
+    }
+
+    /**
+     * Set the LogLevel for the messageSent event.
+     * 
+     * @param level The LogLevel to set
+     */
+    public void setMessageSentLevel(final LogLevel messageSentLevel) {
+        this.messageSentLevel = messageSentLevel;
+    }
+
 }
\ No newline at end of file

Modified: mina/mina/trunk/core/src/main/java/org/apache/mina/service/idlechecker/IndexedIdleChecker.java
URL: http://svn.apache.org/viewvc/mina/mina/trunk/core/src/main/java/org/apache/mina/service/idlechecker/IndexedIdleChecker.java?rev=1407005&r1=1407004&r2=1407005&view=diff
==============================================================================
--- mina/mina/trunk/core/src/main/java/org/apache/mina/service/idlechecker/IndexedIdleChecker.java (original)
+++ mina/mina/trunk/core/src/main/java/org/apache/mina/service/idlechecker/IndexedIdleChecker.java Thu Nov  8 10:43:24 2012
@@ -196,7 +196,8 @@ public class IndexedIdleChecker implemen
 
         int index = startIdx;
         do {
-            LOG.debug("scanning index {}", index);
+
+            LOG.trace("scanning index {}", index);
             // look at the read idle index
             counter += processIndex(readIdleSessionIndex, index, IdleStatus.READ_IDLE);
             counter += processIndex(writeIdleSessionIndex, index, IdleStatus.WRITE_IDLE);

Modified: mina/mina/trunk/core/src/main/java/org/apache/mina/session/AbstractIoSession.java
URL: http://svn.apache.org/viewvc/mina/mina/trunk/core/src/main/java/org/apache/mina/session/AbstractIoSession.java?rev=1407005&r1=1407004&r2=1407005&view=diff
==============================================================================
--- mina/mina/trunk/core/src/main/java/org/apache/mina/session/AbstractIoSession.java (original)
+++ mina/mina/trunk/core/src/main/java/org/apache/mina/session/AbstractIoSession.java Thu Nov  8 10:43:24 2012
@@ -728,10 +728,19 @@ public abstract class AbstractIoSession 
 
             if (request != null) {
                 ((DefaultWriteRequest) request).setFuture(future);
+                ((DefaultWriteRequest) request).setHighLevelMessage(message);
             }
         }
     }
 
+    public void processMessageSent(final Object highLevelMessage) {
+        LOG.debug("processing message '{}' sent event for session {}", highLevelMessage, this);
+        final int size = chain.length;
+        for (int i = size - 1; i <= 0; i--) {
+            chain[i].messageSent(this, highLevelMessage);
+        }
+    }
+
     /**
      * process session message received event using the filter chain. To be called by the session
      * {@link SelectorProcessor} .
@@ -752,7 +761,6 @@ public abstract class AbstractIoSession 
         }
 
         writeChainPosition++;
-        ;
     }
 
     /**

Modified: mina/mina/trunk/core/src/main/java/org/apache/mina/session/DefaultWriteRequest.java
URL: http://svn.apache.org/viewvc/mina/mina/trunk/core/src/main/java/org/apache/mina/session/DefaultWriteRequest.java?rev=1407005&r1=1407004&r2=1407005&view=diff
==============================================================================
--- mina/mina/trunk/core/src/main/java/org/apache/mina/session/DefaultWriteRequest.java (original)
+++ mina/mina/trunk/core/src/main/java/org/apache/mina/session/DefaultWriteRequest.java Thu Nov  8 10:43:24 2012
@@ -31,16 +31,20 @@ import org.apache.mina.util.ByteBufferDu
  */
 public class DefaultWriteRequest implements WriteRequest {
     /** The stored message */
-    private Object message;
+    private final Object message;
+
+    /** The high level message (before being processed by the filter chain */
+    private Object highLevelMessage;
 
     /** the future to complete when this message is written */
     private IoFuture<Void> future;
 
     /**
      * Creates a new instance of a WriteRequest
+     * 
      * @param message The stored message
      */
-    public DefaultWriteRequest(Object message) {
+    public DefaultWriteRequest(final Object message) {
         this.message = message;
     }
 
@@ -55,23 +59,34 @@ public class DefaultWriteRequest impleme
     /**
      * {@inheritDoc}
      */
+    @Override
     public IoFuture<Void> getFuture() {
         return future;
     }
 
     /**
      * Associates a Future to this WriteRequest instance
+     * 
      * @param future The associated Future
      */
-    public void setFuture(IoFuture<Void> future) {
+    public void setFuture(final IoFuture<Void> future) {
         this.future = future;
     }
 
+    public Object getHighLevelMessage() {
+        return highLevelMessage;
+    }
+
+    public void setHighLevelMessage(final Object highLevelMessage) {
+        this.highLevelMessage = highLevelMessage;
+    }
+
     /**
      * @see Object#toString()
      */
+    @Override
     public String toString() {
-        StringBuilder sb = new StringBuilder();
+        final StringBuilder sb = new StringBuilder();
 
         sb.append("WriteRequest[");
 

Modified: mina/mina/trunk/core/src/main/java/org/apache/mina/transport/nio/NioSelectorLoop.java
URL: http://svn.apache.org/viewvc/mina/mina/trunk/core/src/main/java/org/apache/mina/transport/nio/NioSelectorLoop.java?rev=1407005&r1=1407004&r2=1407005&view=diff
==============================================================================
--- mina/mina/trunk/core/src/main/java/org/apache/mina/transport/nio/NioSelectorLoop.java (original)
+++ mina/mina/trunk/core/src/main/java/org/apache/mina/transport/nio/NioSelectorLoop.java Thu Nov  8 10:43:24 2012
@@ -26,6 +26,8 @@ import java.nio.channels.SelectableChann
 import java.nio.channels.SelectionKey;
 import java.nio.channels.Selector;
 import java.util.Iterator;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentLinkedQueue;
 
 import org.apache.mina.api.RuntimeIoException;
 import org.slf4j.Logger;
@@ -38,33 +40,31 @@ public class NioSelectorLoop implements 
 
     private final Logger logger;
 
-    /**
-     * A timeout used for the select, as we need to get out to deal with idle sessions
-     */
-    private static final long SELECT_TIMEOUT = 1000L;
-
     /** the selector managed by this class */
     private Selector selector;
 
     /** the worker thread in charge of polling the selector */
     private final SelectorWorker worker;
 
-    /** the number of service using this selector */
-    private int serviceCount = 0;
-
     /** Read buffer for all the incoming bytes (default to 64Kb) */
     private final ByteBuffer readBuffer = ByteBuffer.allocate(64 * 1024);
 
+    private final Queue<Registration> registrationQueue = new ConcurrentLinkedQueue<Registration>();
+
     public NioSelectorLoop(final String prefix, final int index) {
         logger = LoggerFactory.getLogger(NioSelectorLoop.class.getName() + ":" + prefix + "-" + index);
         worker = new SelectorWorker(prefix, index);
 
         try {
+            logger.debug("open a selector");
             selector = Selector.open();
         } catch (final IOException ioe) {
             logger.error("Impossible to open a new NIO selector, O/S is out of file descriptor ?");
             throw new RuntimeIoException(ioe);
         }
+        logger.debug("starting worker thread");
+        worker.start();
+
     }
 
     /**
@@ -85,11 +85,10 @@ public class NioSelectorLoop implements 
         if (write) {
             ops |= SelectionKey.OP_WRITE;
         }
-        try {
-            channel.register(selector, ops, listener);
-        } catch (final ClosedChannelException e) {
-            logger.error("Trying to register an already closed channel : ", e);
-        }
+
+        // TODO : if it's the same selector/worker, we don't need to do that we could directly enqueue
+        registrationQueue.add(new Registration(ops, channel, listener));
+        selector.wakeup();
     }
 
     /**
@@ -133,30 +132,8 @@ public class NioSelectorLoop implements 
         }
         key.cancel();
         key.attach(null);
-    }
+        logger.debug("unregistering : {} done !", listener);
 
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public synchronized void incrementServiceCount() {
-        serviceCount++;
-        logger.debug("service count: {}", serviceCount);
-        if (serviceCount == 1) {
-            worker.start();
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public synchronized void decrementServiceCount() {
-        serviceCount--;
-        logger.debug("service count: {}", serviceCount);
-        if (serviceCount < 0) {
-            logger.error("service count should not be negative : bug ?");
-        }
     }
 
     /**
@@ -167,50 +144,56 @@ public class NioSelectorLoop implements 
 
         public SelectorWorker(final String prefix, final int index) {
             super("SelectorWorker " + prefix + "-" + index);
+            setDaemon(true);
         }
 
         @Override
         public void run() {
-            if (selector == null) {
-                logger.debug("opening a new selector");
-
-                try {
-                    selector = Selector.open();
-                } catch (final IOException e) {
-                    logger.error("IOException while opening a new Selector", e);
-                }
-            }
 
             for (;;) {
                 try {
                     logger.debug("selecting...");
                     final int readyCount = selector.select();
                     logger.debug("... done selecting : {} events", readyCount);
-                    if (readyCount > 0) {
-                        final Iterator<SelectionKey> it = selector.selectedKeys().iterator();
+                    final Iterator<SelectionKey> it = selector.selectedKeys().iterator();
+                    while (it.hasNext()) {
+                        final SelectionKey key = it.next();
+                        final SelectorListener listener = (SelectorListener) key.attachment();
+                        listener.ready(key.isAcceptable(), key.isReadable(), key.isReadable() ? readBuffer : null,
+                                key.isWritable());
+                        // if you don't remove the event of the set, the selector will present you this event again and
+                        // again
+                        it.remove();
+                    }
 
-                        while (it.hasNext()) {
-                            final SelectionKey key = it.next();
-                            final SelectorListener listener = (SelectorListener) key.attachment();
-                            listener.ready(key.isAcceptable(), key.isReadable(), key.isReadable() ? readBuffer : null,
-                                    key.isWritable());
-                            it.remove();
+                    // new registration
+                    while (!registrationQueue.isEmpty()) {
+                        final Registration reg = registrationQueue.poll();
+
+                        try {
+                            reg.channel.register(selector, reg.ops, reg.listener);
+                        } catch (final ClosedChannelException ex) {
+                            // dead session..
+                            logger.error("socket is already dead", ex);
                         }
                     }
-
                 } catch (final Exception e) {
                     logger.error("Unexpected exception : ", e);
                 }
-
-                // stop the worker if needed (no more service)
-                synchronized (NioSelectorLoop.this) {
-                    logger.debug("remaing {} service", serviceCount);
-                    if (serviceCount <= 0) {
-                        logger.debug("stop the worker");
-                        break;
-                    }
-                }
             }
         }
     }
+
+    private class Registration {
+
+        public Registration(final int ops, final SelectableChannel channel, final SelectorListener listener) {
+            this.ops = ops;
+            this.channel = channel;
+            this.listener = listener;
+        }
+
+        private final int ops;
+        private final SelectableChannel channel;
+        private final SelectorListener listener;
+    }
 }
\ No newline at end of file

Modified: mina/mina/trunk/core/src/main/java/org/apache/mina/transport/nio/NioTcpServer.java
URL: http://svn.apache.org/viewvc/mina/mina/trunk/core/src/main/java/org/apache/mina/transport/nio/NioTcpServer.java?rev=1407005&r1=1407004&r2=1407005&view=diff
==============================================================================
--- mina/mina/trunk/core/src/main/java/org/apache/mina/transport/nio/NioTcpServer.java (original)
+++ mina/mina/trunk/core/src/main/java/org/apache/mina/transport/nio/NioTcpServer.java Thu Nov  8 10:43:24 2012
@@ -120,9 +120,6 @@ public class NioTcpServer extends Abstra
 
         // it's the first address bound, let's fire the event
         this.fireServiceActivated();
-
-        // will start the selector processor if we are the first service
-        acceptSelectorLoop.incrementServiceCount();
     }
 
     /**
@@ -150,8 +147,6 @@ public class NioTcpServer extends Abstra
         this.fireServiceInactivated();
 
         // will stop the acceptor processor if we are the last service
-        acceptSelectorLoop.decrementServiceCount();
-
         idleChecker.destroy();
     }
 
@@ -260,8 +255,7 @@ public class NioTcpServer extends Abstra
         }
 
         // add the session to the queue for being added to the selector
-        // readWriteSelectorLoop.register(false, true, false, session, socketChannel);
-        // readWriteSelectorLoop.incrementServiceCount();
+        readWriteSelectorLoop.register(false, true, false, session, socketChannel);
         session.processSessionOpened();
         session.setConnected();
         idleChecker.sessionRead(session, System.currentTimeMillis());

Modified: mina/mina/trunk/core/src/main/java/org/apache/mina/transport/nio/NioTcpSession.java
URL: http://svn.apache.org/viewvc/mina/mina/trunk/core/src/main/java/org/apache/mina/transport/nio/NioTcpSession.java?rev=1407005&r1=1407004&r2=1407005&view=diff
==============================================================================
--- mina/mina/trunk/core/src/main/java/org/apache/mina/transport/nio/NioTcpSession.java (original)
+++ mina/mina/trunk/core/src/main/java/org/apache/mina/transport/nio/NioTcpSession.java Thu Nov  8 10:43:24 2012
@@ -30,6 +30,7 @@ import org.apache.mina.api.IoService;
 import org.apache.mina.service.idlechecker.IdleChecker;
 import org.apache.mina.session.AbstractIoSession;
 import org.apache.mina.session.DefaultWriteFuture;
+import org.apache.mina.session.DefaultWriteRequest;
 import org.apache.mina.session.SslHelper;
 import org.apache.mina.session.WriteRequest;
 import org.apache.mina.transport.tcp.ProxyTcpSessionConfig;
@@ -38,11 +39,11 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * A NIO based TCP session, should be used by {@link NioTcpServer} and {@link NioTcpClient}.
- * A TCP session is a connection between a our server/client and the remote end-point.
+ * A NIO based TCP session, should be used by {@link NioTcpServer} and {@link NioTcpClient}. A TCP session is a
+ * connection between a our server/client and the remote end-point.
  * 
  * @author <a href="http://mina.apache.org">Apache MINA Project</a>
- *
+ * 
  */
 public class NioTcpSession extends AbstractIoSession implements SelectorListener {
 
@@ -57,7 +58,8 @@ public class NioTcpSession extends Abstr
     /** the socket configuration */
     private final TcpSessionConfig configuration;
 
-    NioTcpSession(IoService service, SocketChannel channel, SelectorLoop selectorLoop, IdleChecker idleChecker) {
+    NioTcpSession(final IoService service, final SocketChannel channel, final SelectorLoop selectorLoop,
+            final IdleChecker idleChecker) {
         super(service, idleChecker);
         this.channel = channel;
         this.selectorLoop = selectorLoop;
@@ -66,6 +68,7 @@ public class NioTcpSession extends Abstr
 
     /**
      * Get the underlying {@link SocketChannel} of this session
+     * 
      * @return the socket channel used by this session
      */
     SocketChannel getSocketChannel() {
@@ -80,7 +83,7 @@ public class NioTcpSession extends Abstr
         if (channel == null) {
             return null;
         }
-        Socket socket = channel.socket();
+        final Socket socket = channel.socket();
 
         if (socket == null) {
             return null;
@@ -98,7 +101,7 @@ public class NioTcpSession extends Abstr
             return null;
         }
 
-        Socket socket = channel.socket();
+        final Socket socket = channel.socket();
 
         if (socket == null) {
             return null;
@@ -187,9 +190,8 @@ public class NioTcpSession extends Abstr
     protected void channelClose() {
         try {
             selectorLoop.unregister(this, channel);
-            selectorLoop.decrementServiceCount();
             channel.close();
-        } catch (IOException e) {
+        } catch (final IOException e) {
             LOG.error("Exception while closing the channel : ", e);
         }
     }
@@ -207,13 +209,13 @@ public class NioTcpSession extends Abstr
      * {@inheritDoc}
      */
     @Override
-    public void ready(boolean accept, boolean read, ByteBuffer readBuffer, boolean write) {
+    public void ready(final boolean accept, final boolean read, final ByteBuffer readBuffer, final boolean write) {
         if (read) {
             try {
 
                 LOG.debug("readable session : {}", this);
                 readBuffer.clear();
-                int readCount = channel.read(readBuffer);
+                final int readCount = channel.read(readBuffer);
 
                 LOG.debug("read {} bytes", readCount);
 
@@ -231,7 +233,7 @@ public class NioTcpSession extends Abstr
                         // We are reading data over a SSL/TLS encrypted connection.
                         // Redirect
                         // the processing to the SslHelper class.
-                        SslHelper sslHelper = getAttribute(SSL_HELPER, null);
+                        final SslHelper sslHelper = getAttribute(SSL_HELPER, null);
 
                         if (sslHelper == null) {
                             throw new IllegalStateException();
@@ -245,7 +247,7 @@ public class NioTcpSession extends Abstr
 
                     idleChecker.sessionRead(this, System.currentTimeMillis());
                 }
-            } catch (IOException e) {
+            } catch (final IOException e) {
                 LOG.error("Exception while reading : ", e);
             }
 
@@ -261,22 +263,22 @@ public class NioTcpSession extends Abstr
                 boolean isEmpty = false;
 
                 try {
-                    Queue<WriteRequest> queue = acquireWriteQueue();
+                    final Queue<WriteRequest> queue = acquireWriteQueue();
 
                     do {
                         // get a write request from the queue
-                        WriteRequest wreq = queue.peek();
+                        final WriteRequest wreq = queue.peek();
 
                         if (wreq == null) {
                             break;
                         }
 
-                        ByteBuffer buf = (ByteBuffer) wreq.getMessage();
+                        final ByteBuffer buf = (ByteBuffer) wreq.getMessage();
 
                         // Note that if the connection is secured, the buffer
                         // already
                         // contains encrypted data.
-                        int wrote = getSocketChannel().write(buf);
+                        final int wrote = getSocketChannel().write(buf);
                         incrementWrittenBytes(wrote);
                         LOG.debug("wrote {} bytes to {}", wrote, this);
 
@@ -286,11 +288,16 @@ public class NioTcpSession extends Abstr
                             // completed write request, let's remove it
                             queue.remove();
                             // complete the future
-                            DefaultWriteFuture future = (DefaultWriteFuture) wreq.getFuture();
+                            final DefaultWriteFuture future = (DefaultWriteFuture) wreq.getFuture();
 
                             if (future != null) {
                                 future.complete();
                             }
+                            // generate the message sent event
+                            final Object highLevel = ((DefaultWriteRequest) wreq).getHighLevelMessage();
+                            if (highLevel != null) {
+                                processMessageSent(highLevel);
+                            }
                         } else {
                             // output socket buffer is full, we need
                             // to give up until next selection for
@@ -316,7 +323,7 @@ public class NioTcpSession extends Abstr
                         selectorLoop.modifyRegistration(false, !isReadSuspended(), false, this, channel);
                     }
                 }
-            } catch (IOException e) {
+            } catch (final IOException e) {
                 LOG.error("Exception while reading : ", e);
             }
         }

Modified: mina/mina/trunk/core/src/main/java/org/apache/mina/transport/nio/NioUdpServer.java
URL: http://svn.apache.org/viewvc/mina/mina/trunk/core/src/main/java/org/apache/mina/transport/nio/NioUdpServer.java?rev=1407005&r1=1407004&r2=1407005&view=diff
==============================================================================
--- mina/mina/trunk/core/src/main/java/org/apache/mina/transport/nio/NioUdpServer.java (original)
+++ mina/mina/trunk/core/src/main/java/org/apache/mina/transport/nio/NioUdpServer.java Thu Nov  8 10:43:24 2012
@@ -58,7 +58,7 @@ public class NioUdpServer extends Abstra
     // the key used for selecting read event
     private SelectionKey readKey = null;
 
-    // list of all the sessions by remote socket address 
+    // list of all the sessions by remote socket address
     private final Map<SocketAddress /* remote socket address */, NioUdpSession> sessions = new ConcurrentHashMap<SocketAddress, NioUdpSession>();
 
     /**
@@ -70,8 +70,7 @@ public class NioUdpServer extends Abstra
     }
 
     /**
-     * Get the inner datagram channel for read and write operations.
-     * To be called by the {@link NioSelectorProcessor}
+     * Get the inner datagram channel for read and write operations. To be called by the {@link NioSelectorProcessor}
      * 
      * @return the datagram channel bound to this {@link NioUdpServer}.
      */
@@ -100,7 +99,7 @@ public class NioUdpServer extends Abstra
      * {@inheritDoc}
      */
     @Override
-    public void bind(SocketAddress localAddress) throws IOException {
+    public void bind(final SocketAddress localAddress) throws IOException {
         if (localAddress == null) {
             // We should at least have one address to bind on
             throw new IllegalArgumentException("LocalAdress cannot be null");
@@ -121,7 +120,6 @@ public class NioUdpServer extends Abstra
         datagramChannel.configureBlocking(false);
 
         selectorLoop.register(false, true, false, this, datagramChannel);
-        selectorLoop.incrementServiceCount();
 
         // it's the first address bound, let's fire the event
         this.fireServiceActivated();
@@ -138,8 +136,6 @@ public class NioUdpServer extends Abstra
         }
 
         selectorLoop.unregister(this, datagramChannel);
-        selectorLoop.decrementServiceCount();
-
         datagramChannel.socket().close();
         datagramChannel.close();
 
@@ -157,7 +153,7 @@ public class NioUdpServer extends Abstra
     /**
      * @param readKey the readKey to set
      */
-    public void setReadKey(SelectionKey readKey) {
+    public void setReadKey(final SelectionKey readKey) {
         this.readKey = readKey;
     }
 
@@ -165,13 +161,13 @@ public class NioUdpServer extends Abstra
      * {@inheritDoc}
      */
     @Override
-    public void ready(boolean accept, boolean read, ByteBuffer readBuffer, boolean write) {
+    public void ready(final boolean accept, final boolean read, final ByteBuffer readBuffer, final boolean write) {
         if (read) {
             try {
                 LOG.debug("readable datagram for UDP service : {}", this);
                 readBuffer.clear();
 
-                SocketAddress source = datagramChannel.receive(readBuffer);
+                final SocketAddress source = datagramChannel.receive(readBuffer);
                 readBuffer.flip();
 
                 LOG.debug("read {} bytes form {}", readBuffer.remaining(), source);
@@ -184,7 +180,7 @@ public class NioUdpServer extends Abstra
                 }
 
                 session.receivedDatagram(readBuffer);
-            } catch (IOException ex) {
+            } catch (final IOException ex) {
                 LOG.error("IOException while reading the socket", ex);
             }
         }

Modified: mina/mina/trunk/core/src/main/java/org/apache/mina/transport/nio/SelectorLoop.java
URL: http://svn.apache.org/viewvc/mina/mina/trunk/core/src/main/java/org/apache/mina/transport/nio/SelectorLoop.java?rev=1407005&r1=1407004&r2=1407005&view=diff
==============================================================================
--- mina/mina/trunk/core/src/main/java/org/apache/mina/transport/nio/SelectorLoop.java (original)
+++ mina/mina/trunk/core/src/main/java/org/apache/mina/transport/nio/SelectorLoop.java Thu Nov  8 10:43:24 2012
@@ -33,8 +33,4 @@ public interface SelectorLoop {
 
     public abstract void unregister(SelectorListener listener, SelectableChannel channel);
 
-    public abstract void incrementServiceCount();
-
-    public abstract void decrementServiceCount();
-
 }
\ No newline at end of file

Modified: mina/mina/trunk/examples/src/main/java/org/apache/mina/examples/echoserver/NioEchoServer.java
URL: http://svn.apache.org/viewvc/mina/mina/trunk/examples/src/main/java/org/apache/mina/examples/echoserver/NioEchoServer.java?rev=1407005&r1=1407004&r2=1407005&view=diff
==============================================================================
--- mina/mina/trunk/examples/src/main/java/org/apache/mina/examples/echoserver/NioEchoServer.java (original)
+++ mina/mina/trunk/examples/src/main/java/org/apache/mina/examples/echoserver/NioEchoServer.java Thu Nov  8 10:43:24 2012
@@ -86,6 +86,11 @@ public class NioEchoServer {
                     session.write(message);
                 }
             }
+
+            @Override
+            public void messageSent(final IoSession session, final Object message) {
+                LOG.info("message {} sent", message);
+            }
         });
 
         acceptor.addListeners(new IoServiceListener() {

Modified: mina/mina/trunk/examples/src/main/java/org/apache/mina/examples/udpecho/NioUdpEchoServer.java
URL: http://svn.apache.org/viewvc/mina/mina/trunk/examples/src/main/java/org/apache/mina/examples/udpecho/NioUdpEchoServer.java?rev=1407005&r1=1407004&r2=1407005&view=diff
==============================================================================
--- mina/mina/trunk/examples/src/main/java/org/apache/mina/examples/udpecho/NioUdpEchoServer.java (original)
+++ mina/mina/trunk/examples/src/main/java/org/apache/mina/examples/udpecho/NioUdpEchoServer.java Thu Nov  8 10:43:24 2012
@@ -84,6 +84,11 @@ public class NioUdpEchoServer {
                     session.write(message);
                 }
             }
+
+            @Override
+            public void messageSent(final IoSession session, final Object message) {
+                LOG.info("message {} sent", message);
+            }
         });
 
         server.addListeners(new IoServiceListener() {

Modified: mina/mina/trunk/pom.xml
URL: http://svn.apache.org/viewvc/mina/mina/trunk/pom.xml?rev=1407005&r1=1407004&r2=1407005&view=diff
==============================================================================
--- mina/mina/trunk/pom.xml (original)
+++ mina/mina/trunk/pom.xml Thu Nov  8 10:43:24 2012
@@ -122,24 +122,6 @@
         <version>${version.slf4j.api}</version>
       </dependency>
 
-      <dependency>
-        <groupId>org.slf4j</groupId>
-        <artifactId>jcl-over-slf4j</artifactId>
-        <version>${version.slf4j.jcl.over.slf4j}</version>
-      </dependency>
-
-      <dependency>
-        <groupId>org.slf4j</groupId>
-        <artifactId>slf4j-log4j12</artifactId>
-        <version>${version.slf4j.log4j12}</version>
-      </dependency>
-
-      <dependency>
-        <groupId>log4j</groupId>
-        <artifactId>log4j</artifactId>
-        <version>${version.log4j}</version>
-      </dependency>
-
       <!-- Testing -->
       <dependency>
         <groupId>junit</groupId>
@@ -161,6 +143,20 @@
         <version>${version.guava}</version>
       </dependency>
 
+      <dependency>
+        <groupId>org.slf4j</groupId>
+        <artifactId>slf4j-log4j12</artifactId>
+        <version>${version.slf4j.log4j12}</version>
+        <scope>test</scope>
+      </dependency>
+
+      <dependency>
+        <groupId>log4j</groupId>
+        <artifactId>log4j</artifactId>
+        <version>${version.log4j}</version>
+        <scope>test</scope>
+      </dependency>
+
     </dependencies>
   </dependencyManagement>