Author: elecharny Date: Sun Mar 8 17:21:07 2009 New Revision: 751472 URL: http://svn.apache.org/viewvc?rev=751472&view=rev Log: o Added some comments in the AbstractPollingConnectionlessAcceptor o Renamed the startupWorker() method to startupAcceptor()
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 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=751472&r1=751471&r2=751472&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 Mar 8 17:21:07 2009 @@ -134,7 +134,7 @@ protected IoFuture dispose0() throws Exception { unbind(); if (!disposalFuture.isDone()) { - startupWorker(); + startupAcceptor(); wakeup(); } return disposalFuture; @@ -146,22 +146,39 @@ @Override protected final Set<SocketAddress> bindInternal( List<? extends SocketAddress> localAddresses) throws Exception { + // Create a bind request as a Future operation. When the selector + // have handled the registration, it will signal this future. AcceptorOperationFuture request = new AcceptorOperationFuture(localAddresses); + // adds the Registration request to the queue for the Workers + // to handle registerQueue.add(request); - startupWorker(); + + // creates the Acceptor instance and has the local + // executor kick it off. + startupAcceptor(); + + // As we just started the acceptor, we have to unblock the select() + // in order to process the bind request we just have added to the + // registerQueue. wakeup(); + // Now, we wait until this request is completed. request.awaitUninterruptibly(); if (request.getException() != null) { throw request.getException(); } + // Update the local addresses. + // setLocalAddresses() shouldn't be called from the worker thread + // because of deadlock. Set<SocketAddress> newLocalAddresses = new HashSet<SocketAddress>(); - for (H handle: boundHandles.values()) { + + for (H handle:boundHandles.values()) { newLocalAddresses.add(localAddress(handle)); } + return newLocalAddresses; } @@ -174,7 +191,7 @@ AcceptorOperationFuture request = new AcceptorOperationFuture(localAddresses); cancelQueue.add(request); - startupWorker(); + startupAcceptor(); wakeup(); request.awaitUninterruptibly(); @@ -297,7 +314,10 @@ } } - private void startupWorker() { + /** + * Starts the inner Acceptor thread. + */ + private void startupAcceptor() { if (!selectable) { registerQueue.clear(); cancelQueue.clear(); 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=751472&r1=751471&r2=751472&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 Mar 8 17:21:07 2009 @@ -334,7 +334,7 @@ // because of deadlock. Set<SocketAddress> newLocalAddresses = new HashSet<SocketAddress>(); - for (H handle : boundHandles.values()) { + for (H handle:boundHandles.values()) { newLocalAddresses.add(localAddress(handle)); }