Author: jvermillard Date: Tue Jun 17 06:16:56 2008 New Revision: 668646 URL: http://svn.apache.org/viewvc?rev=668646&view=rev Log: more IoService Javadoc, mainly on constructors.
Modified: mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoAcceptor.java mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoConnector.java mina/trunk/core/src/main/java/org/apache/mina/common/AbstractPollingIoAcceptor.java mina/trunk/core/src/main/java/org/apache/mina/common/AbstractPollingIoConnector.java Modified: mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoAcceptor.java URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoAcceptor.java?rev=668646&r1=668645&r2=668646&view=diff ============================================================================== --- mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoAcceptor.java (original) +++ mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoAcceptor.java Tue Jun 17 06:16:56 2008 @@ -28,6 +28,7 @@ import java.util.List; import java.util.Set; import java.util.concurrent.Executor; +import java.util.concurrent.Executors; /** @@ -55,6 +56,20 @@ */ protected final Object bindLock = new Object(); + /** + * Constructor for [EMAIL PROTECTED] AbstractIoAcceptor}. You need to provide a default + * session configuration and an [EMAIL PROTECTED] Executor} for handling I/O events. If + * null [EMAIL PROTECTED] Executor} is provided, a default one will be created using + * [EMAIL PROTECTED] Executors#newCachedThreadPool()}. + * + * [EMAIL PROTECTED] AbstractIoService#AbstractIoService(IoSessionConfig, Executor)} + * + * @param sessionConfig + * the default configuration for the managed [EMAIL PROTECTED] IoSession} + * @param executor + * the [EMAIL PROTECTED] Executor} used for handling execution of I/O + * events. Can be <code>null</code>. + */ protected AbstractIoAcceptor(IoSessionConfig sessionConfig, Executor executor) { super(sessionConfig, executor); defaultLocalAddresses.add(null); Modified: mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoConnector.java URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoConnector.java?rev=668646&r1=668645&r2=668646&view=diff ============================================================================== --- mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoConnector.java (original) +++ mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoConnector.java Tue Jun 17 06:16:56 2008 @@ -21,6 +21,7 @@ import java.net.SocketAddress; import java.util.concurrent.Executor; +import java.util.concurrent.Executors; /** * A base implementation of [EMAIL PROTECTED] IoConnector}. @@ -37,6 +38,20 @@ private long connectTimeoutInMillis = 60 * 1000L; // 1 minute by default private SocketAddress defaultRemoteAddress; + /** + * Constructor for [EMAIL PROTECTED] AbstractIoConnector}. You need to provide a default + * session configuration and an [EMAIL PROTECTED] Executor} for handling I/O events. If + * null [EMAIL PROTECTED] Executor} is provided, a default one will be created using + * [EMAIL PROTECTED] Executors#newCachedThreadPool()}. + * + * [EMAIL PROTECTED] AbstractIoService#AbstractIoService(IoSessionConfig, Executor)} + * + * @param sessionConfig + * the default configuration for the managed [EMAIL PROTECTED] IoSession} + * @param executor + * the [EMAIL PROTECTED] Executor} used for handling execution of I/O + * events. Can be <code>null</code>. + */ protected AbstractIoConnector(IoSessionConfig sessionConfig, Executor executor) { super(sessionConfig, executor); } Modified: mina/trunk/core/src/main/java/org/apache/mina/common/AbstractPollingIoAcceptor.java URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/common/AbstractPollingIoAcceptor.java?rev=668646&r1=668645&r2=668646&view=diff ============================================================================== --- mina/trunk/core/src/main/java/org/apache/mina/common/AbstractPollingIoAcceptor.java (original) +++ mina/trunk/core/src/main/java/org/apache/mina/common/AbstractPollingIoAcceptor.java Tue Jun 17 06:16:56 2008 @@ -30,6 +30,7 @@ import java.util.Set; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.Executor; +import java.util.concurrent.Executors; /** * TODO Add documentation @@ -41,43 +42,121 @@ extends AbstractIoAcceptor { private final IoProcessor<T> processor; + private final boolean createdProcessor; private final Object lock = new Object(); - private final Queue<AcceptorOperationFuture> registerQueue = - new ConcurrentLinkedQueue<AcceptorOperationFuture>(); - private final Queue<AcceptorOperationFuture> cancelQueue = - new ConcurrentLinkedQueue<AcceptorOperationFuture>(); + private final Queue<AcceptorOperationFuture> registerQueue = new ConcurrentLinkedQueue<AcceptorOperationFuture>(); + + private final Queue<AcceptorOperationFuture> cancelQueue = new ConcurrentLinkedQueue<AcceptorOperationFuture>(); + + private final Map<SocketAddress, H> boundHandles = Collections + .synchronizedMap(new HashMap<SocketAddress, H>()); - private final Map<SocketAddress, H> boundHandles = - Collections.synchronizedMap(new HashMap<SocketAddress, H>()); + private final ServiceOperationFuture disposalFuture = new ServiceOperationFuture(); - private final ServiceOperationFuture disposalFuture = - new ServiceOperationFuture(); private volatile boolean selectable; + private Worker worker; /** - * Create an acceptor with a single processing thread using a NewThreadExecutor + * Constructor for [EMAIL PROTECTED] AbstractPollingIoAcceptor}. You need to provide a default + * session configuration, a class of [EMAIL PROTECTED] IoProcessor} which will be instantiated in a + * [EMAIL PROTECTED] SimpleIoProcessorPool} for better scaling in multiprocessor systems. The default + * pool size will be used. + * + * @see SimpleIoProcessorPool + * + * @param sessionConfig + * the default configuration for the managed [EMAIL PROTECTED] IoSession} + * @param processorClass a [EMAIL PROTECTED] Class}Â of [EMAIL PROTECTED] IoProcessor} for the associated [EMAIL PROTECTED] IoSession} + * type. */ - protected AbstractPollingIoAcceptor(IoSessionConfig sessionConfig, Class<? extends IoProcessor<T>> processorClass) { - this(sessionConfig, null, new SimpleIoProcessorPool<T>(processorClass), true); + protected AbstractPollingIoAcceptor(IoSessionConfig sessionConfig, + Class<? extends IoProcessor<T>> processorClass) { + this(sessionConfig, null, new SimpleIoProcessorPool<T>(processorClass), + true); } - protected AbstractPollingIoAcceptor(IoSessionConfig sessionConfig, Class<? extends IoProcessor<T>> processorClass, int processorCount) { - this(sessionConfig, null, new SimpleIoProcessorPool<T>(processorClass, processorCount), true); + /** + * Constructor for [EMAIL PROTECTED] AbstractPollingIoAcceptor}. You need to provide a default + * session configuration, a class of [EMAIL PROTECTED] IoProcessor} which will be instantiated in a + * [EMAIL PROTECTED] SimpleIoProcessorPool} for using multiple thread for better scaling in multiprocessor + * systems. + * + * @see SimpleIoProcessorPool + * + * @param sessionConfig + * the default configuration for the managed [EMAIL PROTECTED] IoSession} + * @param processorClass a [EMAIL PROTECTED] Class}Â of [EMAIL PROTECTED] IoProcessor} for the associated [EMAIL PROTECTED] IoSession} + * type. + * @param processorCount the amount of processor to instantiate for the pool + */ + protected AbstractPollingIoAcceptor(IoSessionConfig sessionConfig, + Class<? extends IoProcessor<T>> processorClass, int processorCount) { + this(sessionConfig, null, new SimpleIoProcessorPool<T>(processorClass, + processorCount), true); } - protected AbstractPollingIoAcceptor(IoSessionConfig sessionConfig, IoProcessor<T> processor) { + /** + * Constructor for [EMAIL PROTECTED] AbstractPollingIoAcceptor}. You need to provide a default + * session configuration, a default [EMAIL PROTECTED] Executor} will be created using + * [EMAIL PROTECTED] Executors#newCachedThreadPool()}. + * + * [EMAIL PROTECTED] AbstractIoService#AbstractIoService(IoSessionConfig, Executor)} + * + * @param sessionConfig + * the default configuration for the managed [EMAIL PROTECTED] IoSession} + * @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} + */ + protected AbstractPollingIoAcceptor(IoSessionConfig sessionConfig, + IoProcessor<T> processor) { this(sessionConfig, null, processor, false); } - protected AbstractPollingIoAcceptor(IoSessionConfig sessionConfig, Executor executor, IoProcessor<T> processor) { + /** + * Constructor for [EMAIL PROTECTED] AbstractPollingIoAcceptor}. You need to provide a default + * session configuration and an [EMAIL PROTECTED] Executor} for handling I/O events. If + * null [EMAIL PROTECTED] Executor} is provided, a default one will be created using + * [EMAIL PROTECTED] Executors#newCachedThreadPool()}. + * + * [EMAIL PROTECTED] AbstractIoService#AbstractIoService(IoSessionConfig, Executor)} + * + * @param sessionConfig + * the default configuration for the managed [EMAIL PROTECTED] IoSession} + * @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} + */ + protected AbstractPollingIoAcceptor(IoSessionConfig sessionConfig, + Executor executor, IoProcessor<T> processor) { this(sessionConfig, executor, processor, false); } - private AbstractPollingIoAcceptor(IoSessionConfig sessionConfig, Executor executor, IoProcessor<T> processor, boolean createdProcessor) { + /** + * Constructor for [EMAIL PROTECTED] AbstractPollingIoAcceptor}. You need to provide a default + * session configuration and an [EMAIL PROTECTED] Executor} for handling I/O events. If + * null [EMAIL PROTECTED] Executor} is provided, a default one will be created using + * [EMAIL PROTECTED] Executors#newCachedThreadPool()}. + * + * [EMAIL PROTECTED] AbstractIoService#AbstractIoService(IoSessionConfig, Executor)} + * + * @param sessionConfig + * the default configuration for the managed [EMAIL PROTECTED] IoSession} + * @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 + */ + private AbstractPollingIoAcceptor(IoSessionConfig sessionConfig, + Executor executor, IoProcessor<T> processor, + boolean createdProcessor) { super(sessionConfig, executor); if (processor == null) { @@ -90,7 +169,7 @@ try { init(); selectable = true; - } catch (RuntimeException e){ + } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeIoException("Failed to initialize.", e); @@ -106,13 +185,22 @@ } protected abstract void init() throws Exception; + protected abstract void destroy() throws Exception; + protected abstract boolean select() throws Exception; + protected abstract void wakeup(); + protected abstract Iterator<H> selectedHandles(); + protected abstract H open(SocketAddress localAddress) throws Exception; + protected abstract SocketAddress localAddress(H handle) throws Exception; - protected abstract T accept(IoProcessor<T> processor, H handle) throws Exception; + + protected abstract T accept(IoProcessor<T> processor, H handle) + throws Exception; + protected abstract void close(H handle) throws Exception; @Override @@ -126,8 +214,10 @@ } @Override - protected final Set<SocketAddress> bind0(List<? extends SocketAddress> localAddresses) throws Exception { - AcceptorOperationFuture request = new AcceptorOperationFuture(localAddresses); + protected final Set<SocketAddress> bind0( + List<? extends SocketAddress> localAddresses) throws Exception { + AcceptorOperationFuture request = new AcceptorOperationFuture( + localAddresses); // adds the Registration request to the queue for the Workers // to handle @@ -147,7 +237,7 @@ // 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)); } @@ -178,8 +268,10 @@ } @Override - protected final void unbind0(List<? extends SocketAddress> localAddresses) throws Exception { - AcceptorOperationFuture future = new AcceptorOperationFuture(localAddresses); + protected final void unbind0(List<? extends SocketAddress> localAddresses) + throws Exception { + AcceptorOperationFuture future = new AcceptorOperationFuture( + localAddresses); cancelQueue.add(future); startupWorker(); @@ -218,8 +310,8 @@ if (nHandles == 0) { synchronized (lock) { - if (registerQueue.isEmpty() && - cancelQueue.isEmpty()) { + if (registerQueue.isEmpty() + && cancelQueue.isEmpty()) { worker = null; break; } @@ -306,7 +398,7 @@ List<SocketAddress> localAddresses = future.getLocalAddresses(); try { - for (SocketAddress a: localAddresses) { + for (SocketAddress a : localAddresses) { H handle = open(a); newHandles.put(localAddress(handle), handle); } @@ -321,7 +413,7 @@ } finally { // Roll back if failed to bind all addresses. if (future.getException() != null) { - for (H handle: newHandles.values()) { + for (H handle : newHandles.values()) { try { close(handle); } catch (Exception e) { @@ -342,14 +434,14 @@ */ private int unregisterHandles() { int cancelledHandles = 0; - for (; ;) { + for (;;) { AcceptorOperationFuture future = cancelQueue.poll(); if (future == null) { break; } // close the channels - for (SocketAddress a: future.getLocalAddresses()) { + for (SocketAddress a : future.getLocalAddresses()) { H handle = boundHandles.remove(a); if (handle == null) { continue; @@ -361,7 +453,7 @@ } catch (Throwable e) { ExceptionMonitor.getInstance().exceptionCaught(e); } finally { - cancelledHandles ++; + cancelledHandles++; } } @@ -371,7 +463,8 @@ return cancelledHandles; } - public final IoSession newSession(SocketAddress remoteAddress, SocketAddress localAddress) { + public final IoSession newSession(SocketAddress remoteAddress, + SocketAddress localAddress) { throw new UnsupportedOperationException(); } } Modified: mina/trunk/core/src/main/java/org/apache/mina/common/AbstractPollingIoConnector.java URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/common/AbstractPollingIoConnector.java?rev=668646&r1=668645&r2=668646&view=diff ============================================================================== --- mina/trunk/core/src/main/java/org/apache/mina/common/AbstractPollingIoConnector.java (original) +++ mina/trunk/core/src/main/java/org/apache/mina/common/AbstractPollingIoConnector.java Tue Jun 17 06:16:56 2008 @@ -25,6 +25,7 @@ import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.Executor; +import java.util.concurrent.Executors; /** * TODO Add documentation @@ -46,22 +47,94 @@ private volatile boolean selectable; private Worker worker; + /** + * Constructor for [EMAIL PROTECTED] AbstractPollingIoConnector}. You need to provide a default + * session configuration, a class of [EMAIL PROTECTED] IoProcessor} which will be instantiated in a + * [EMAIL PROTECTED] SimpleIoProcessorPool} for better scaling in multiprocessor systems. The default + * pool size will be used. + * + * @see SimpleIoProcessorPool + * + * @param sessionConfig + * the default configuration for the managed [EMAIL PROTECTED] IoSession} + * @param processorClass a [EMAIL PROTECTED] Class}Â of [EMAIL PROTECTED] IoProcessor} for the associated [EMAIL PROTECTED] IoSession} + * type. + */ protected AbstractPollingIoConnector(IoSessionConfig sessionConfig, Class<? extends IoProcessor<T>> processorClass) { this(sessionConfig, null, new SimpleIoProcessorPool<T>(processorClass), true); } + /** + * Constructor for [EMAIL PROTECTED] AbstractPollingIoConnector}. You need to provide a default + * session configuration, a class of [EMAIL PROTECTED] IoProcessor} which will be instantiated in a + * [EMAIL PROTECTED] SimpleIoProcessorPool} for using multiple thread for better scaling in multiprocessor + * systems. + * + * @see SimpleIoProcessorPool + * + * @param sessionConfig + * the default configuration for the managed [EMAIL PROTECTED] IoSession} + * @param processorClass a [EMAIL PROTECTED] Class}Â of [EMAIL PROTECTED] IoProcessor} for the associated [EMAIL PROTECTED] IoSession} + * type. + * @param processorCount the amount of processor to instantiate for the pool + */ protected AbstractPollingIoConnector(IoSessionConfig sessionConfig, Class<? extends IoProcessor<T>> processorClass, int processorCount) { this(sessionConfig, null, new SimpleIoProcessorPool<T>(processorClass, processorCount), true); } + /** + * Constructor for [EMAIL PROTECTED] AbstractPollingIoConnector}. You need to provide a default + * session configuration, a default [EMAIL PROTECTED] Executor} will be created using + * [EMAIL PROTECTED] Executors#newCachedThreadPool()}. + * + * [EMAIL PROTECTED] AbstractIoService#AbstractIoService(IoSessionConfig, Executor)} + * + * @param sessionConfig + * the default configuration for the managed [EMAIL PROTECTED] IoSession} + * @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} + */ protected AbstractPollingIoConnector(IoSessionConfig sessionConfig, IoProcessor<T> processor) { this(sessionConfig, null, processor, false); } + /** + * Constructor for [EMAIL PROTECTED] AbstractPollingIoConnector}. You need to provide a default + * session configuration and an [EMAIL PROTECTED] Executor} for handling I/O events. If + * null [EMAIL PROTECTED] Executor} is provided, a default one will be created using + * [EMAIL PROTECTED] Executors#newCachedThreadPool()}. + * + * [EMAIL PROTECTED] AbstractIoService#AbstractIoService(IoSessionConfig, Executor)} + * + * @param sessionConfig + * the default configuration for the managed [EMAIL PROTECTED] IoSession} + * @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} + */ protected AbstractPollingIoConnector(IoSessionConfig sessionConfig, Executor executor, IoProcessor<T> processor) { this(sessionConfig, executor, processor, false); } + /** + * Constructor for [EMAIL PROTECTED] AbstractPollingIoAcceptor}. You need to provide a default + * session configuration and an [EMAIL PROTECTED] Executor} for handling I/O events. If + * null [EMAIL PROTECTED] Executor} is provided, a default one will be created using + * [EMAIL PROTECTED] Executors#newCachedThreadPool()}. + * + * [EMAIL PROTECTED] AbstractIoService#AbstractIoService(IoSessionConfig, Executor)} + * + * @param sessionConfig + * the default configuration for the managed [EMAIL PROTECTED] IoSession} + * @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 + */ private AbstractPollingIoConnector(IoSessionConfig sessionConfig, Executor executor, IoProcessor<T> processor, boolean createdProcessor) { super(sessionConfig, executor);