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 2012/09/27 14:53:23 UTC

svn commit: r1390974 - /mina/branches/2.0/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingConnectionlessIoAcceptor.java

Author: elecharny
Date: Thu Sep 27 12:53:22 2012
New Revision: 1390974

URL: http://svn.apache.org/viewvc?rev=1390974&view=rev
Log:
o Remove the Processor inner class : we don't need it for UDP. The AbstractPollingConnectionLessAcceptor is now implementing the IoProcessor class itself.
o The processReadySessions() method now takes a Set<SelectionKey> instead of an Iterator<H> : this allow the code to have direct access to the SelectionKey. We don't have anymore to retreive the SelectionKey from the Handle


Modified:
    mina/branches/2.0/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingConnectionlessIoAcceptor.java

Modified: mina/branches/2.0/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingConnectionlessIoAcceptor.java
URL: http://svn.apache.org/viewvc/mina/branches/2.0/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingConnectionlessIoAcceptor.java?rev=1390974&r1=1390973&r2=1390974&view=diff
==============================================================================
--- mina/branches/2.0/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingConnectionlessIoAcceptor.java (original)
+++ mina/branches/2.0/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingConnectionlessIoAcceptor.java Thu Sep 27 12:53:22 2012
@@ -21,6 +21,7 @@ package org.apache.mina.core.polling;
 
 import java.net.SocketAddress;
 import java.nio.channels.ClosedSelectorException;
+import java.nio.channels.SelectionKey;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -56,7 +57,7 @@ import org.apache.mina.util.ExceptionMon
   * @param <S> the type of the {@link IoSession} this processor can handle
 */
 public abstract class AbstractPollingConnectionlessIoAcceptor<S extends AbstractIoSession, H> extends
-        AbstractIoAcceptor {
+        AbstractIoAcceptor implements IoProcessor<S> {
 
     private static final IoSessionRecycler DEFAULT_RECYCLER = new ExpiringSessionRecycler();
 
@@ -69,8 +70,6 @@ public abstract class AbstractPollingCon
     /** A lock used to protect the selector to be waked up before it's created */
     private final Semaphore lock = new Semaphore(1);
 
-    private final IoProcessor<S> processor = new ConnectionlessAcceptorProcessor();
-
     private final Queue<AcceptorOperationFuture> registerQueue = new ConcurrentLinkedQueue<AcceptorOperationFuture>();
 
     private final Queue<AcceptorOperationFuture> cancelQueue = new ConcurrentLinkedQueue<AcceptorOperationFuture>();
@@ -131,7 +130,7 @@ public abstract class AbstractPollingCon
 
     protected abstract void wakeup();
 
-    protected abstract Iterator<H> selectedHandles();
+    protected abstract Set<SelectionKey> selectedHandles();
 
     protected abstract H open(SocketAddress localAddress) throws Exception;
 
@@ -265,17 +264,16 @@ public abstract class AbstractPollingCon
         }
 
         IoSession session;
-        IoSessionRecycler sessionRecycler = getSessionRecycler();
 
         synchronized (sessionRecycler) {
-            session = sessionRecycler.recycle(localAddress, remoteAddress);
+            session = sessionRecycler.recycle(remoteAddress);
 
             if (session != null) {
                 return session;
             }
 
             // If a new session needs to be created.
-            S newSession = newSession(processor, handle, remoteAddress);
+            S newSession = newSession(this, handle, remoteAddress);
             getSessionRecycler().put(newSession);
             session = newSession;
         }
@@ -310,36 +308,35 @@ public abstract class AbstractPollingCon
         }
     }
 
-    private class ConnectionlessAcceptorProcessor implements IoProcessor<S> {
-
-        public void add(S session) {
-        }
-
-        public void flush(S session) {
-            if (scheduleFlush(session)) {
-                wakeup();
-            }
-        }
-
-        public void remove(S session) {
-            getSessionRecycler().remove(session);
-            getListeners().fireSessionDestroyed(session);
-        }
-
-        public void updateTrafficControl(S session) {
-            throw new UnsupportedOperationException();
-        }
+    /**
+     * {@inheritDoc}
+     */
+    public void add(S session) {
+        // Nothing to do for UDP
+    }
 
-        public void dispose() {
+    /**
+     * {@inheritDoc}
+     */
+    public void flush(S session) {
+        if (scheduleFlush(session)) {
+            wakeup();
         }
+    }
 
-        public boolean isDisposed() {
-            return false;
-        }
+    /**
+     * {@inheritDoc}
+     */
+    public void remove(S session) {
+        getSessionRecycler().remove(session);
+        getListeners().fireSessionDestroyed(session);
+    }
 
-        public boolean isDisposing() {
-            return false;
-        }
+    /**
+     * {@inheritDoc}
+     */
+    public void updateTrafficControl(S session) {
+        throw new UnsupportedOperationException();
     }
 
     /**
@@ -442,17 +439,20 @@ public abstract class AbstractPollingCon
     }
 
     @SuppressWarnings("unchecked")
-    private void processReadySessions(Iterator<H> handles) {
-        while (handles.hasNext()) {
-            H h = handles.next();
-            handles.remove();
+    private void processReadySessions(Set<SelectionKey> handles) {
+        Iterator<SelectionKey> iterator = handles.iterator();
+
+        while (iterator.hasNext()) {
+            SelectionKey key = iterator.next();
+            H handle = (H) key.channel();
+            iterator.remove();
 
             try {
-                if (isReadable(h)) {
-                    readHandle(h);
+                if ((key != null) && key.isValid() && key.isReadable()) {
+                    readHandle(handle);
                 }
 
-                if (isWritable(h)) {
+                if ((key != null) && key.isValid() && key.isWritable()) {
                     for (IoSession session : getManagedSessions().values()) {
                         scheduleFlush((S) session);
                     }