Author: elecharny
Date: Sun Oct 19 11:46:42 2008
New Revision: 706052

URL: http://svn.apache.org/viewvc?rev=706052&view=rev
Log:
o Added javadoc and comment
o Renamed the Worker threads to Acceptor, Connector and Processor.

Modified:
    
mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingConnectionlessIoAcceptor.java
    
mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoAcceptor.java
    
mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoConnector.java
    
mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoProcessor.java

Modified: 
mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingConnectionlessIoAcceptor.java
URL: 
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingConnectionlessIoAcceptor.java?rev=706052&r1=706051&r2=706052&view=diff
==============================================================================
--- 
mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingConnectionlessIoAcceptor.java
 (original)
+++ 
mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingConnectionlessIoAcceptor.java
 Sun Oct 19 11:46:42 2008
@@ -75,7 +75,10 @@
     private final ServiceOperationFuture disposalFuture =
         new ServiceOperationFuture();
     private volatile boolean selectable;
-    private Worker worker;
+    
+    /** The thread responsible of accepting incoming requests */ 
+    private Acceptor acceptor;
+
     private long lastIdleCheckTime;
 
     /**
@@ -302,9 +305,9 @@
         }
 
         synchronized (lock) {
-            if (worker == null) {
-                worker = new Worker();
-                executeWorker(worker);
+            if (acceptor == null) {
+                acceptor = new Acceptor();
+                executeWorker(acceptor);
             }
         }
     }
@@ -318,7 +321,12 @@
         }
     }
 
-    private class Worker implements Runnable {
+    /**
+     * This private class is used to accept incoming connection from 
+     * clients. It's an infinite loop, which can be stopped when all
+     * the registered handles have been removed (unbound). 
+     */
+    private class Acceptor implements Runnable {
         public void run() {
             int nHandles = 0;
             lastIdleCheckTime = System.currentTimeMillis();
@@ -342,7 +350,7 @@
                     if (nHandles == 0) {
                         synchronized (lock) {
                             if (registerQueue.isEmpty() && 
cancelQueue.isEmpty()) {
-                                worker = null;
+                                acceptor = null;
                                 break;
                             }
                         }

Modified: 
mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoAcceptor.java
URL: 
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoAcceptor.java?rev=706052&r1=706051&r2=706052&view=diff
==============================================================================
--- 
mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoAcceptor.java
 (original)
+++ 
mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoAcceptor.java
 Sun Oct 19 11:46:42 2008
@@ -82,9 +82,11 @@
 
     private final ServiceOperationFuture disposalFuture = new 
ServiceOperationFuture();
 
+    /** A flag set when the acceptor has been created and initialized */
     private volatile boolean selectable;
 
-    private Worker worker;
+    /** The thread responsible of accepting incoming requests */ 
+    private Acceptor acceptor;
 
     /**
      * Constructor for [EMAIL PROTECTED] AbstractPollingIoAcceptor}. You need 
to provide a default
@@ -144,7 +146,7 @@
 
     /**
      * Constructor for [EMAIL PROTECTED] AbstractPollingIoAcceptor}. You need 
to provide a default
-     * session configuration and an [EMAIL PROTECTED] Executor} for handling 
I/O events. If
+     * session configuration and an [EMAIL PROTECTED] Executor} for handling 
I/O events. If a
      * null [EMAIL PROTECTED] Executor} is provided, a default one will be 
created using
      * [EMAIL PROTECTED] Executors#newCachedThreadPool()}.
      * 
@@ -165,7 +167,7 @@
 
     /**
      * Constructor for [EMAIL PROTECTED] AbstractPollingIoAcceptor}. You need 
to provide a default
-     * session configuration and an [EMAIL PROTECTED] Executor} for handling 
I/O events. If
+     * session configuration and an [EMAIL PROTECTED] Executor} for handling 
I/O events. If a
      * null [EMAIL PROTECTED] Executor} is provided, a default one will be 
created using
      * [EMAIL PROTECTED] Executors#newCachedThreadPool()}.
      * 
@@ -176,9 +178,11 @@
      * @param executor
      *            the [EMAIL PROTECTED] Executor} used for handling 
asynchronous execution of I/O
      *            events. Can be <code>null</code>.
-     * @param processor the [EMAIL PROTECTED] IoProcessor} for processing the 
[EMAIL PROTECTED] IoSession} of this transport, triggering 
-     *            events to the bound [EMAIL PROTECTED] IoHandler} and 
processing the chains of [EMAIL PROTECTED] IoFilter}
-     * @param createdProcessor tagging the processor as automatically created, 
so it will be automatically disposed 
+     * @param processor the [EMAIL PROTECTED] IoProcessor} for processing the 
[EMAIL PROTECTED] IoSession} of 
+     * this transport, triggering events to the bound [EMAIL PROTECTED] 
IoHandler} and processing 
+     * the chains of [EMAIL PROTECTED] IoFilter}
+     * @param createdProcessor tagging the processor as automatically created, 
so it 
+     * will be automatically disposed 
      */
     private AbstractPollingIoAcceptor(IoSessionConfig sessionConfig,
             Executor executor, IoProcessor<T> processor,
@@ -193,7 +197,11 @@
         this.createdProcessor = createdProcessor;
 
         try {
+            // Initialize the selector
             init();
+            
+            // The selector is now ready, we can switch the
+            // flag to true so that incoming connection can be accepted
             selectable = true;
         } catch (RuntimeException e) {
             throw e;
@@ -284,7 +292,7 @@
     protected IoFuture dispose0() throws Exception {
         unbind();
         if (!disposalFuture.isDone()) {
-            startupWorker();
+            startupAcceptor();
             wakeup();
         }
         return disposalFuture;
@@ -303,9 +311,9 @@
         // to handle
         registerQueue.add(request);
 
-        // creates an instance of a Worker and has the local
+        // creates the Acceptor instance and has the local
         // executor kick it off.
-        startupWorker();
+        startupAcceptor();
         wakeup();
         request.awaitUninterruptibly();
 
@@ -326,23 +334,25 @@
 
     /**
      * This method is called by the doBind() and doUnbind()
-     * methods.  If the worker object is not null, presumably
-     * the acceptor is starting up, then the worker object will
-     * be created and kicked off by the executor.  If the worker
-     * object is not null, probably already created and this class
+     * methods.  If the acceptor is null, the acceptor object will
+     * be created and kicked off by the executor.  If the acceptor
+     * object is null, probably already created and this class
      * is now working, then nothing will happen and the method
      * will just return.
      */
-    private void startupWorker() {
+    private void startupAcceptor() {
+        // If the acceptor is not ready, clear the queues
+        // TODO : they should already be clean : do we have to do that ?
         if (!selectable) {
             registerQueue.clear();
             cancelQueue.clear();
         }
 
+        // start the acceptor if not already started
         synchronized (lock) {
-            if (worker == null) {
-                worker = new Worker();
-                executeWorker(worker);
+            if (acceptor == null) {
+                acceptor = new Acceptor();
+                executeWorker(acceptor);
             }
         }
     }
@@ -357,7 +367,7 @@
                 localAddresses);
 
         cancelQueue.add(future);
-        startupWorker();
+        startupAcceptor();
         wakeup();
 
         future.awaitUninterruptibly();
@@ -367,10 +377,12 @@
     }
 
     /**
-     * This class is called by the startupWorker() method and is
+     * This class is called by the startupAcceptor() method and is
      * placed into a NamePreservingRunnable class.
+     * It's a thread accepting incoming connections from clients.
+     * The loop is stopped when all the bound handlers are unbound.
      */
-    private class Worker implements Runnable {
+    private class Acceptor implements Runnable {
         public void run() {
             int nHandles = 0;
 
@@ -395,7 +407,7 @@
                         synchronized (lock) {
                             if (registerQueue.isEmpty()
                                     && cancelQueue.isEmpty()) {
-                                worker = null;
+                                acceptor = null;
                                 break;
                             }
                         }

Modified: 
mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoConnector.java
URL: 
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoConnector.java?rev=706052&r1=706051&r2=706052&view=diff
==============================================================================
--- 
mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoConnector.java
 (original)
+++ 
mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoConnector.java
 Sun Oct 19 11:46:42 2008
@@ -73,7 +73,9 @@
     private final ServiceOperationFuture disposalFuture =
         new ServiceOperationFuture();
     private volatile boolean selectable;
-    private Worker worker;
+    
+    /** The connector thread */
+    private Connector connector;
 
     /**
      * Constructor for [EMAIL PROTECTED] AbstractPollingIoConnector}. You need 
to provide a default
@@ -356,9 +358,9 @@
         }
 
         synchronized (lock) {
-            if (worker == null) {
-                worker = new Worker();
-                executeWorker(worker);
+            if (connector == null) {
+                connector = new Connector();
+                executeWorker(connector);
             }
         }
     }
@@ -451,7 +453,7 @@
         }
     }
 
-    private class Worker implements Runnable {
+    private class Connector implements Runnable {
 
         public void run() {
             int nHandles = 0;
@@ -475,7 +477,7 @@
                     if (nHandles == 0) {
                         synchronized (lock) {
                             if (connectQueue.isEmpty()) {
-                                worker = null;
+                                connector = null;
                                 break;
                             }
                         }

Modified: 
mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoProcessor.java
URL: 
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoProcessor.java?rev=706052&r1=706051&r2=706052&view=diff
==============================================================================
--- 
mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoProcessor.java
 (original)
+++ 
mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoProcessor.java
 Sun Oct 19 11:46:42 2008
@@ -78,7 +78,9 @@
     private final Queue<T> flushingSessions = new ConcurrentLinkedQueue<T>();
     private final Queue<T> trafficControllingSessions = new 
ConcurrentLinkedQueue<T>();
 
-    private Worker worker;
+    /** The processor thread : it handles the incoming messages */
+    private Processor processor;
+    
     private long lastIdleCheckTime;
 
     private final Object disposalLock = new Object();
@@ -374,9 +376,9 @@
 
     private void startupWorker() {
         synchronized (lock) {
-            if (worker == null) {
-                worker = new Worker();
-                executor.execute(new NamePreservingRunnable(worker, 
threadName));
+            if (processor == null) {
+                processor = new Processor();
+                executor.execute(new NamePreservingRunnable(processor, 
threadName));
             }
         }
         wakeup();
@@ -843,7 +845,7 @@
     }
 
     
-    private class Worker implements Runnable {
+    private class Processor implements Runnable {
         public void run() {
             int nSessions = 0;
             lastIdleCheckTime = System.currentTimeMillis();
@@ -867,7 +869,7 @@
                     if (nSessions == 0) {
                         synchronized (lock) {
                             if (newSessions.isEmpty() && isSelectorEmpty()) {
-                                worker = null;
+                                processor = null;
                                 break;
                             }
                         }


Reply via email to