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 2008/06/28 23:27:00 UTC

svn commit: r672582 - in /mina/trunk/core/src/main/java/org/apache/mina: core/polling/AbstractPollingIoConnector.java transport/socket/nio/NioSocketConnector.java

Author: jvermillard
Date: Sat Jun 28 14:27:00 2008
New Revision: 672582

URL: http://svn.apache.org/viewvc?rev=672582&view=rev
Log:
more javadoc on AbstractPollingIoConnector and NioSocketConnector

Modified:
    mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoConnector.java
    mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketConnector.java

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=672582&r1=672581&r2=672582&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 Sat Jun 28 14:27:00 2008
@@ -192,7 +192,24 @@
      */
     protected abstract void destroy() throws Exception;
     
+    /**
+     * Create a new client socket handle from a local {@link SocketAddress}
+     * @param localAddress the socket address for binding the new client socket 
+     * @return a new client socket handle 
+     * @throws Exception any exception thrown by the underlying systems calls
+     */
     protected abstract H newHandle(SocketAddress localAddress) throws Exception;
+    
+    /**
+     * Connect a newly created client socket handle to a remote {@link SocketAddress}.
+     * This operation is non-blocking, so at end of the call the socket can be still in connection
+     * process.
+     * @param handle the client socket handle
+     * @param remoteAddress the remote address where to connect
+     * @return <tt>true</tt> if a connection was established, <tt>false</tt> if this client socket 
+     *         is in non-blocking mode and the connection operation is in progress
+     * @throws Exception
+     */
     protected abstract boolean connect(H handle, SocketAddress remoteAddress) throws Exception;
     
     /**
@@ -204,6 +221,16 @@
      * @throws Exception any exception thrown by the underlying systems calls
      */
     protected abstract boolean finishConnect(H handle) throws Exception;
+    
+    /**
+     * Create a new {@link IoSession} from a connected socket client handle.
+     * Will assign the created {@link IoSession} to the given {@link IoProcessor} for
+     * managing future I/O events.
+     * @param processor the processor in charge of this session
+     * @param handle the newly connected client socket handle
+     * @return a new {@link IoSession}
+     * @throws Exception any exception thrown by the underlying systems calls
+     */
     protected abstract T newSession(IoProcessor<T> processor, H handle) throws Exception;
 
     /**
@@ -234,10 +261,25 @@
      */
     protected abstract Iterator<H> selectedHandles();
     
+    /**
+     * {@link Iterator} for all the client sockets polled for connection.
+     * @return the list of client sockets currently polled for connection
+     */
     protected abstract Iterator<H> allHandles();
     
+    /**
+     * Register a new client socket for connection, add it to connection polling
+     * @param handle client socket handle 
+     * @param request the associated {@link ConnectionRequest}
+     * @throws Exception any exception thrown by the underlying systems calls
+     */
     protected abstract void register(H handle, ConnectionRequest request) throws Exception;
     
+    /**
+     * get the {@link ConnectionRequest} for a given client socket handle
+     * @param handle the socket client handle 
+     * @return the connection request if the socket is connecting otherwise <code>null</code>
+     */
     protected abstract ConnectionRequest connectionRequest(H handle);
 
     /**

Modified: mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketConnector.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketConnector.java?rev=672582&r1=672581&r2=672582&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketConnector.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketConnector.java Sat Jun 28 14:27:00 2008
@@ -31,7 +31,9 @@
 import org.apache.mina.core.polling.AbstractPollingIoConnector;
 import org.apache.mina.core.service.IoConnector;
 import org.apache.mina.core.service.IoProcessor;
+import org.apache.mina.core.service.SimpleIoProcessorPool;
 import org.apache.mina.core.service.TransportMetadata;
+import org.apache.mina.core.session.IoSession;
 import org.apache.mina.transport.socket.DefaultSocketSessionConfig;
 import org.apache.mina.transport.socket.SocketConnector;
 import org.apache.mina.transport.socket.SocketSessionConfig;
@@ -48,31 +50,57 @@
 
     private volatile Selector selector;
 
+    /**
+     * Constructor for {@link NioSocketConnector} with default configuration.
+     */
     public NioSocketConnector() {
         super(new DefaultSocketSessionConfig(), NioProcessor.class);
         ((DefaultSocketSessionConfig) getSessionConfig()).init(this);
     }
 
+    /**
+     * Constructor for {@link NioSocketConnector} with default configuration, and 
+     * given number of {@link NioProcessor}
+     * @param processorCount the number of processor to create and place in a
+     * {@link SimpleIoProcessorPool} 
+     */
     public NioSocketConnector(int processorCount) {
         super(new DefaultSocketSessionConfig(), NioProcessor.class, processorCount);
         ((DefaultSocketSessionConfig) getSessionConfig()).init(this);
     }
 
+    /**
+     *  Constructor for {@link NioSocketConnector} with default configuration but a
+     *  specific {@link IoProcessor}
+     * @param processor the processor to use for managing I/O events
+     */
     public NioSocketConnector(IoProcessor<NioSession> processor) {
         super(new DefaultSocketSessionConfig(), processor);
         ((DefaultSocketSessionConfig) getSessionConfig()).init(this);
     }
 
+    /**
+     *  Constructor for {@link NioSocketConnector} with a given {@link Executor} for handling 
+     *  connection events and a given {@link IoProcessor} for handling I/O events.
+     * @param executor the executor for connection
+     * @param processor the processor for I/O operations
+     */
     public NioSocketConnector(Executor executor, IoProcessor<NioSession> processor) {
         super(new DefaultSocketSessionConfig(), executor, processor);
         ((DefaultSocketSessionConfig) getSessionConfig()).init(this);
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected void init() throws Exception {
         this.selector = Selector.open();
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected void destroy() throws Exception {
         if (selector != null) {
@@ -80,35 +108,56 @@
         }
     }
 
+    /**
+     * {@inheritDoc}
+     */
     public TransportMetadata getTransportMetadata() {
         return NioSocketSession.METADATA;
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public SocketSessionConfig getSessionConfig() {
         return (SocketSessionConfig) super.getSessionConfig();
     }
-
+    
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public InetSocketAddress getDefaultRemoteAddress() {
         return (InetSocketAddress) super.getDefaultRemoteAddress();
     }
-
+    
+    /**
+     * {@inheritDoc}
+     */
     public void setDefaultRemoteAddress(InetSocketAddress defaultRemoteAddress) {
         super.setDefaultRemoteAddress(defaultRemoteAddress);
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected Iterator<SocketChannel> allHandles() {
         return new SocketChannelIterator(selector.keys());
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected boolean connect(SocketChannel handle, SocketAddress remoteAddress)
             throws Exception {
         return handle.connect(remoteAddress);
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected ConnectionRequest connectionRequest(SocketChannel handle) {
         SelectionKey key = handle.keyFor(selector);
@@ -119,6 +168,9 @@
         return (ConnectionRequest) key.attachment();
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected void close(SocketChannel handle) throws Exception {
         SelectionKey key = handle.keyFor(selector);
@@ -128,6 +180,9 @@
         handle.close();
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected boolean finishConnect(SocketChannel handle) throws Exception {
         SelectionKey key = handle.keyFor(selector);
@@ -141,6 +196,9 @@
         return false;
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected SocketChannel newHandle(SocketAddress localAddress)
             throws Exception {
@@ -159,27 +217,42 @@
         return ch;
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected NioSession newSession(IoProcessor<NioSession> processor, SocketChannel handle) {
         return new NioSocketSession(this, processor, handle);
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected void register(SocketChannel handle, ConnectionRequest request)
             throws Exception {
         handle.register(selector, SelectionKey.OP_CONNECT, request);
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected boolean select(int timeout) throws Exception {
         return selector.select(timeout) > 0;
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected Iterator<SocketChannel> selectedHandles() {
         return new SocketChannelIterator(selector.selectedKeys());
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected void wakeup() {
         selector.wakeup();
@@ -193,15 +266,24 @@
             this.i = selectedKeys.iterator();
         }
 
+        /**
+         * {@inheritDoc}
+         */
         public boolean hasNext() {
             return i.hasNext();
         }
 
+        /**
+         * {@inheritDoc}
+         */
         public SocketChannel next() {
             SelectionKey key = i.next();
             return (SocketChannel) key.channel();
         }
 
+        /**
+         * {@inheritDoc}
+         */
         public void remove() {
             i.remove();
         }