You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by ad...@apache.org on 2011/08/20 19:39:46 UTC

svn commit: r1159893 - in /mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina: core/ core/state/ link/ nio/ ssl/

Author: adc
Date: Sat Aug 20 17:39:46 2011
New Revision: 1159893

URL: http://svn.apache.org/viewvc?rev=1159893&view=rev
Log:
Refactored scetches of IoByteBuffer and added IoEvent annotation

Added:
    mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/IoEvent.java
      - copied, changed from r1159830, mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/IoProperty.java
    mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/InitiateHandshakeEvent.java
    mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/SSLEngine.java
Modified:
    mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/IoBuffer.java
    mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/IoChannelState.java
    mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/state/StateMachineChannel.java
    mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/link/DownState.java
    mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/link/UpState.java
    mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/nio/IoByteBuffer.java
    mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/ClosedChannelState.java
    mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/ClosingChannelState.java
    mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/FinishedChannelState.java
    mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/HandshakeChannelState.java
    mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/SslChannel.java

Modified: mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/IoBuffer.java
URL: http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/IoBuffer.java?rev=1159893&r1=1159892&r2=1159893&view=diff
==============================================================================
--- mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/IoBuffer.java (original)
+++ mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/IoBuffer.java Sat Aug 20 17:39:46 2011
@@ -27,5 +27,9 @@ public interface IoBuffer<V>
 
     void append(V header);
 
+    void preppend(V header);
+
     int capacity();
+
+    void recycle();
 }

Modified: mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/IoChannelState.java
URL: http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/IoChannelState.java?rev=1159893&r1=1159892&r2=1159893&view=diff
==============================================================================
--- mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/IoChannelState.java (original)
+++ mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/IoChannelState.java Sat Aug 20 17:39:46 2011
@@ -34,6 +34,4 @@ public interface IoChannelState<U, D, S 
     void send(Context<S> context, D message) throws Exception;
 
     void receive(Context<S> context, U message) throws Exception;
-
-    void handle(Context<S> context, E event) throws Exception;
 }

Copied: mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/IoEvent.java (from r1159830, mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/IoProperty.java)
URL: http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/IoEvent.java?p2=mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/IoEvent.java&p1=mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/IoProperty.java&r1=1159830&r2=1159893&rev=1159893&view=diff
==============================================================================
--- mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/IoProperty.java (original)
+++ mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/IoEvent.java Sat Aug 20 17:39:46 2011
@@ -21,14 +21,12 @@ package org.apache.mina.core;
 /**
  * @author <a href="http://mina.apache.org">Apache MINA Project</a>
  */
-@java.lang.annotation.Target({java.lang.annotation.ElementType.METHOD, java.lang.annotation.ElementType.FIELD})
+@java.lang.annotation.Target({java.lang.annotation.ElementType.METHOD})
 @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
 @java.lang.annotation.Documented
-public @interface IoProperty
+public @interface IoEvent
 {
-    public String name() default "<bean name>";
+    public String name() default "<event name>";
 
-    public String type() default "<use signature>";
-
-    public IoPropertyScope scope() default IoPropertyScope.PRIVATE;
+    public Class type() default Object.class;
 }

Modified: mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/state/StateMachineChannel.java
URL: http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/state/StateMachineChannel.java?rev=1159893&r1=1159892&r2=1159893&view=diff
==============================================================================
--- mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/state/StateMachineChannel.java (original)
+++ mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/state/StateMachineChannel.java Sat Aug 20 17:39:46 2011
@@ -116,7 +116,7 @@ public abstract class StateMachineChanne
         IoChannelState<U, D, S, E> channelState = states.get(state);
         equipmentStack.inject(channelState);
 
-        channelState.handle(new StateMachineContext(), event);
+//        channelState.handle(new StateMachineContext(), event);  TODO
     }
 
     protected final void queue(E event)

Modified: mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/link/DownState.java
URL: http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/link/DownState.java?rev=1159893&r1=1159892&r2=1159893&view=diff
==============================================================================
--- mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/link/DownState.java (original)
+++ mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/link/DownState.java Sat Aug 20 17:39:46 2011
@@ -95,10 +95,4 @@ public class DownState extends BaseChann
             numTokens++;
         }
     }
-
-    @Override
-    public void handle(Context<State> stateContext, TimeoutEvent event) throws Exception
-    {
-        LOG.trace("Ignored timeout event");
-    }
 }

Modified: mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/link/UpState.java
URL: http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/link/UpState.java?rev=1159893&r1=1159892&r2=1159893&view=diff
==============================================================================
--- mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/link/UpState.java (original)
+++ mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/link/UpState.java Sat Aug 20 17:39:46 2011
@@ -24,6 +24,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import org.apache.mina.core.BaseChannelState;
+import org.apache.mina.core.IoEvent;
 import org.apache.mina.core.IoProperty;
 import org.apache.mina.core.IoPropertyScope;
 import org.apache.mina.core.api.IoDown;
@@ -89,7 +90,7 @@ public class UpState extends BaseChannel
         }
     }
 
-    @Override
+    @IoEvent(name = "timeout", type = TimeoutEvent.class)
     public void handle(Context<State> stateContext, TimeoutEvent event) throws Exception
     {
         LOG.debug("Received timeout event, tokens={}", numTokens);

Modified: mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/nio/IoByteBuffer.java
URL: http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/nio/IoByteBuffer.java?rev=1159893&r1=1159892&r2=1159893&view=diff
==============================================================================
--- mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/nio/IoByteBuffer.java (original)
+++ mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/nio/IoByteBuffer.java Sat Aug 20 17:39:46 2011
@@ -18,7 +18,10 @@
  */
 package org.apache.mina.nio;
 
+import java.nio.BufferOverflowException;
+import java.nio.BufferUnderflowException;
 import java.nio.ByteBuffer;
+import java.nio.InvalidMarkException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.logging.Logger;
@@ -34,6 +37,11 @@ public class IoByteBuffer implements IoB
     private final static String CLASS_NAME = IoByteBuffer.class.getName();
     private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
     public static final IoByteBuffer EMPTY = new IoByteBuffer();
+    private int mark = -1;
+    private int position = 0;
+    private int limit;
+    private int capacity;
+    private boolean readOnly;
 
     private final List<ByteBuffer> messages = new ArrayList<ByteBuffer>();
 
@@ -47,18 +55,569 @@ public class IoByteBuffer implements IoB
         append(byteBuffer);
     }
 
+    @Override
+    public void recycle()
+    {
+        //Todo change body of implemented methods use File | Settings | File Templates.
+    }
+
+    /**
+     * Returns this buffer's capacity. </p>
+     *
+     * @return The capacity of this buffer
+     */
+    public final int capacity()
+    {
+        return capacity;
+    }
+
+    /**
+     * Returns this buffer's position. </p>
+     *
+     * @return The position of this buffer
+     */
+    public final int position()
+    {
+        return position;
+    }
+
+    /**
+     * Sets this buffer's position.  If the mark is defined and larger than the
+     * new position then it is discarded. </p>
+     *
+     * @param newPosition The new position value; must be non-negative
+     *                    and no larger than the current limit
+     * @return This buffer
+     * @throws IllegalArgumentException If the preconditions on <tt>newPosition</tt> do not hold
+     */
+    public final IoByteBuffer position(int newPosition)
+    {
+        if ((newPosition > limit) || (newPosition < 0))
+            throw new IllegalArgumentException();
+        position = newPosition;
+        if (mark > position) mark = -1;
+        return this;
+    }
+
+    /**
+     * Returns this buffer's limit. </p>
+     *
+     * @return The limit of this buffer
+     */
+    public final int limit()
+    {
+        return limit;
+    }
+
+    /**
+     * Sets this buffer's limit.  If the position is larger than the new limit
+     * then it is set to the new limit.  If the mark is defined and larger than
+     * the new limit then it is discarded. </p>
+     *
+     * @param newLimit The new limit value; must be non-negative
+     *                 and no larger than this buffer's capacity
+     * @return This buffer
+     * @throws IllegalArgumentException If the preconditions on <tt>newLimit</tt> do not hold
+     */
+    public final IoByteBuffer limit(int newLimit)
+    {
+        if ((newLimit > capacity) || (newLimit < 0))
+            throw new IllegalArgumentException();
+        limit = newLimit;
+        if (position > limit) position = limit;
+        if (mark > limit) mark = -1;
+        return this;
+    }
+
+    /**
+     * Sets this buffer's mark at its position. </p>
+     *
+     * @return This buffer
+     */
+    public final IoByteBuffer mark()
+    {
+        mark = position;
+        return this;
+    }
+
+    /**
+     * Resets this buffer's position to the previously-marked position.
+     * <p/>
+     * <p> Invoking this method neither changes nor discards the mark's
+     * value. </p>
+     *
+     * @return This buffer
+     * @throws java.nio.InvalidMarkException If the mark has not been set
+     */
+    public final IoByteBuffer reset()
+    {
+        int m = mark;
+        if (m < 0)
+            throw new InvalidMarkException();
+        position = m;
+        return this;
+    }
+
+    /**
+     * Clears this buffer.  The position is set to zero, the limit is set to
+     * the capacity, and the mark is discarded.
+     * <p/>
+     * <p> Invoke this method before using a sequence of channel-read or
+     * <i>put</i> operations to fill this buffer.  For example:
+     * <p/>
+     * <blockquote><pre>
+     * buf.clear();     // Prepare buffer for reading
+     * in.read(buf);    // Read data</pre></blockquote>
+     * <p/>
+     * <p> This method does not actually erase the data in the buffer, but it
+     * is named as if it did because it will most often be used in situations
+     * in which that might as well be the case. </p>
+     *
+     * @return This buffer
+     */
+    public final IoByteBuffer clear()
+    {
+        position = 0;
+        limit = capacity;
+        mark = -1;
+        return this;
+    }
+
+    /**
+     * Flips this buffer.  The limit is set to the current position and then
+     * the position is set to zero.  If the mark is defined then it is
+     * discarded.
+     * <p/>
+     * <p> After a sequence of channel-read or <i>put</i> operations, invoke
+     * this method to prepare for a sequence of channel-write or relative
+     * <i>get</i> operations.  For example:
+     * <p/>
+     * <blockquote><pre>
+     * buf.put(magic);    // Prepend header
+     * in.read(buf);      // Read data into rest of buffer
+     * buf.flip();        // Flip buffer
+     * out.write(buf);    // Write header + data to channel</pre></blockquote>
+     * <p/>
+     * <p> This method is often used in conjunction with the {@link
+     * java.nio.ByteBuffer#compact compact} method when transferring data from
+     * one place to another.  </p>
+     *
+     * @return This buffer
+     */
+    public final IoByteBuffer flip()
+    {
+        limit = position;
+        position = 0;
+        mark = -1;
+        return this;
+    }
+
+    /**
+     * Rewinds this buffer.  The position is set to zero and the mark is
+     * discarded.
+     * <p/>
+     * <p> Invoke this method before a sequence of channel-write or <i>get</i>
+     * operations, assuming that the limit has already been set
+     * appropriately.  For example:
+     * <p/>
+     * <blockquote><pre>
+     * out.write(buf);    // Write remaining data
+     * buf.rewind();      // Rewind buffer
+     * buf.get(array);    // Copy data into array</pre></blockquote>
+     *
+     * @return This buffer
+     */
+    public final IoByteBuffer rewind()
+    {
+        position = 0;
+        mark = -1;
+        return this;
+    }
+
+    /**
+     * Returns the number of elements between the current position and the
+     * limit. </p>
+     *
+     * @return The number of elements remaining in this buffer
+     */
+    public final int remaining()
+    {
+        return limit - position;
+    }
+
+    /**
+     * Tells whether there are any elements between the current position and
+     * the limit. </p>
+     *
+     * @return <tt>true</tt> if, and only if, there is at least one element
+     *         remaining in this buffer
+     */
+    public final boolean hasRemaining()
+    {
+        return position < limit;
+    }
+
+    /**
+     * Tells whether or not this buffer is read-only. </p>
+     *
+     * @return <tt>true</tt> if, and only if, this buffer is read-only
+     */
+    public boolean isReadOnly()
+    {
+        return readOnly;
+    }
+
+    @Override
     public ByteBuffer[] getMessages()
     {
         return messages.toArray(new ByteBuffer[messages.size()]);
     }
 
+    @Override
     public void append(ByteBuffer header)
     {
         messages.add(header);
     }
 
-    public int capacity()
+    @Override
+    public void preppend(ByteBuffer header)
+    {
+        //Todo change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public void append(IoByteBuffer header)
+    {
+        //Todo change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public void preppend(IoByteBuffer header)
+    {
+        //Todo change body of implemented methods use File | Settings | File Templates.
+    }
+
+    /**
+     * Creates a new byte buffer whose content is a shared subsequence of
+     * this buffer's content.
+     * <p/>
+     * <p> The content of the new buffer will start at this buffer's current
+     * position.  Changes to this buffer's content will be visible in the new
+     * buffer, and vice versa; the two buffers' position, limit, and mark
+     * values will be independent.
+     * <p/>
+     * <p> The new buffer's position will be zero, its capacity and its limit
+     * will be the number of bytes remaining in this buffer, and its mark
+     * will be undefined.  The new buffer will be direct if, and only if, this
+     * buffer is direct, and it will be read-only if, and only if, this buffer
+     * is read-only.  </p>
+     *
+     * @return The new byte buffer
+     */
+    public IoByteBuffer slice()
+    {
+        return null;  //Todo change body of implemented methods use File | Settings | File Templates.
+    }
+
+    /**
+     * Creates a new byte buffer that shares this buffer's content.
+     * <p/>
+     * <p> The content of the new buffer will be that of this buffer.  Changes
+     * to this buffer's content will be visible in the new buffer, and vice
+     * versa; the two buffers' position, limit, and mark values will be
+     * independent.
+     * <p/>
+     * <p> The new buffer's capacity, limit, position, and mark values will be
+     * identical to those of this buffer.  The new buffer will be direct if,
+     * and only if, this buffer is direct, and it will be read-only if, and
+     * only if, this buffer is read-only.  </p>
+     *
+     * @return The new byte buffer
+     */
+    public IoByteBuffer duplicate()
+    {
+        return null;  //Todo change body of implemented methods use File | Settings | File Templates.
+    }
+
+    /**
+     * Creates a new, read-only byte buffer that shares this buffer's
+     * content.
+     * <p/>
+     * <p> The content of the new buffer will be that of this buffer.  Changes
+     * to this buffer's content will be visible in the new buffer; the new
+     * buffer itself, however, will be read-only and will not allow the shared
+     * content to be modified.  The two buffers' position, limit, and mark
+     * values will be independent.
+     * <p/>
+     * <p> The new buffer's capacity, limit, position, and mark values will be
+     * identical to those of this buffer.
+     * <p/>
+     * <p> If this buffer is itself read-only then this method behaves in
+     * exactly the same way as the {@link #duplicate duplicate} method.  </p>
+     *
+     * @return The new, read-only byte buffer
+     */
+    public IoByteBuffer asReadOnlyBuffer()
+    {
+        return null;  //Todo change body of implemented methods use File | Settings | File Templates.
+    }
+
+    /**
+     * Relative <i>get</i> method.  Reads the byte at this buffer's
+     * current position, and then increments the position. </p>
+     *
+     * @return The byte at the buffer's current position
+     * @throws java.nio.BufferUnderflowException
+     *          If the buffer's current position is not smaller than its limit
+     */
+    public byte get()
+    {
+        return 0;  //Todo change body of implemented methods use File | Settings | File Templates.
+    }
+
+    /**
+     * Relative <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
+     * <p/>
+     * <p> Writes the given byte into this buffer at the current
+     * position, and then increments the position. </p>
+     *
+     * @param b The byte to be written
+     * @return This buffer
+     * @throws java.nio.BufferOverflowException
+     *          If this buffer's current position is not smaller than its limit
+     * @throws java.nio.ReadOnlyBufferException
+     *          If this buffer is read-only
+     */
+    public IoByteBuffer put(byte b)
+    {
+        return null;  //Todo change body of implemented methods use File | Settings | File Templates.
+    }
+
+    /**
+     * Absolute <i>get</i> method.  Reads the byte at the given
+     * index. </p>
+     *
+     * @param index The index from which the byte will be read
+     * @return The byte at the given index
+     * @throws IndexOutOfBoundsException If <tt>index</tt> is negative
+     *                                   or not smaller than the buffer's limit
+     */
+    public byte get(int index)
     {
         return 0;  //Todo change body of implemented methods use File | Settings | File Templates.
     }
+
+    /**
+     * Absolute <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
+     * <p/>
+     * <p> Writes the given byte into this buffer at the given
+     * index. </p>
+     *
+     * @param index The index at which the byte will be written
+     * @param b     The byte value to be written
+     * @return This buffer
+     * @throws IndexOutOfBoundsException If <tt>index</tt> is negative
+     *                                   or not smaller than the buffer's limit
+     * @throws java.nio.ReadOnlyBufferException
+     *                                   If this buffer is read-only
+     */
+    public IoByteBuffer put(int index, byte b)
+    {
+        return this;  //Todo change body of implemented methods use File | Settings | File Templates.
+    }
+
+    /**
+     * Relative bulk <i>get</i> method.
+     * <p/>
+     * <p> This method transfers bytes from this buffer into the given
+     * destination array.  If there are fewer bytes remaining in the
+     * buffer than are required to satisfy the request, that is, if
+     * <tt>length</tt>&nbsp;<tt>&gt;</tt>&nbsp;<tt>remaining()</tt>, then no
+     * bytes are transferred and a {@link java.nio.BufferUnderflowException} is
+     * thrown.
+     * <p/>
+     * <p> Otherwise, this method copies <tt>length</tt> bytes from this
+     * buffer into the given array, starting at the current position of this
+     * buffer and at the given offset in the array.  The position of this
+     * buffer is then incremented by <tt>length</tt>.
+     * <p/>
+     * <p> In other words, an invocation of this method of the form
+     * <tt>src.get(dst,&nbsp;off,&nbsp;len)</tt> has exactly the same effect as
+     * the loop
+     * <p/>
+     * <pre>
+     *     for (int i = off; i < off + len; i++)
+     *         dst[i] = src.get(); </pre>
+     *
+     * except that it first checks that there are sufficient bytes in
+     * this buffer and it is potentially much more efficient. </p>
+     *
+     * @param dst    The array into which bytes are to be written
+     * @param offset The offset within the array of the first byte to be
+     *               written; must be non-negative and no larger than
+     *               <tt>dst.length</tt>
+     * @param length The maximum number of bytes to be written to the given
+     *               array; must be non-negative and no larger than
+     *               <tt>dst.length - offset</tt>
+     * @return This buffer
+     * @throws java.nio.BufferUnderflowException
+     *                                   If there are fewer than <tt>length</tt> bytes
+     *                                   remaining in this buffer
+     * @throws IndexOutOfBoundsException If the preconditions on the <tt>offset</tt> and <tt>length</tt>
+     *                                   parameters do not hold
+     */
+    public IoByteBuffer get(byte[] dst, int offset, int length)
+    {
+        checkBounds(offset, length, dst.length);
+        if (length > remaining())
+            throw new BufferUnderflowException();
+        int end = offset + length;
+        for (int i = offset; i < end; i++)
+            dst[i] = get();
+        return this;
+    }
+
+    /**
+     * Relative bulk <i>get</i> method.
+     * <p/>
+     * <p> This method transfers bytes from this buffer into the given
+     * destination array.  An invocation of this method of the form
+     * <tt>src.get(a)</tt> behaves in exactly the same way as the invocation
+     * <p/>
+     * <pre>
+     *     src.get(a, 0, a.length) </pre>
+     *
+     * @return This buffer
+     * @throws BufferUnderflowException If there are fewer than <tt>length</tt> bytes
+     *                                  remaining in this buffer
+     */
+    public IoByteBuffer get(byte[] dst)
+    {
+        return get(dst, 0, dst.length);
+    }
+
+
+    // -- Bulk put operations --
+
+    /**
+     * Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
+     * <p/>
+     * <p> This method transfers the bytes remaining in the given source
+     * buffer into this buffer.  If there are more bytes remaining in the
+     * source buffer than in this buffer, that is, if
+     * <tt>src.remaining()</tt>&nbsp;<tt>&gt;</tt>&nbsp;<tt>remaining()</tt>,
+     * then no bytes are transferred and a {@link
+     * java.nio.BufferOverflowException} is thrown.
+     * <p/>
+     * <p> Otherwise, this method copies
+     * <i>n</i>&nbsp;=&nbsp;<tt>src.remaining()</tt> bytes from the given
+     * buffer into this buffer, starting at each buffer's current position.
+     * The positions of both buffers are then incremented by <i>n</i>.
+     * <p/>
+     * <p> In other words, an invocation of this method of the form
+     * <tt>dst.put(src)</tt> has exactly the same effect as the loop
+     * <p/>
+     * <pre>
+     *     while (src.hasRemaining())
+     *         dst.put(src.get()); </pre>
+     *
+     * except that it first checks that there is sufficient space in this
+     * buffer and it is potentially much more efficient. </p>
+     *
+     * @param src The source buffer from which bytes are to be read;
+     *            must not be this buffer
+     * @return This buffer
+     * @throws java.nio.BufferOverflowException
+     *                                  If there is insufficient space in this buffer
+     *                                  for the remaining bytes in the source buffer
+     * @throws IllegalArgumentException If the source buffer is this buffer
+     * @throws java.nio.ReadOnlyBufferException
+     *                                  If this buffer is read-only
+     */
+    public IoByteBuffer put(IoByteBuffer src)
+    {
+        if (src == this)
+            throw new IllegalArgumentException();
+        int n = src.remaining();
+        if (n > remaining())
+            throw new BufferOverflowException();
+        for (int i = 0; i < n; i++)
+            put(src.get());
+        return this;
+    }
+
+    /**
+     * Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
+     * <p/>
+     * <p> This method transfers bytes into this buffer from the given
+     * source array.  If there are more bytes to be copied from the array
+     * than remain in this buffer, that is, if
+     * <tt>length</tt>&nbsp;<tt>&gt;</tt>&nbsp;<tt>remaining()</tt>, then no
+     * bytes are transferred and a {@link BufferOverflowException} is
+     * thrown.
+     * <p/>
+     * <p> Otherwise, this method copies <tt>length</tt> bytes from the
+     * given array into this buffer, starting at the given offset in the array
+     * and at the current position of this buffer.  The position of this buffer
+     * is then incremented by <tt>length</tt>.
+     * <p/>
+     * <p> In other words, an invocation of this method of the form
+     * <tt>dst.put(src,&nbsp;off,&nbsp;len)</tt> has exactly the same effect as
+     * the loop
+     * <p/>
+     * <pre>
+     *     for (int i = off; i < off + len; i++)
+     *         dst.put(a[i]); </pre>
+     *
+     * except that it first checks that there is sufficient space in this
+     * buffer and it is potentially much more efficient. </p>
+     *
+     * @param src    The array from which bytes are to be read
+     * @param offset The offset within the array of the first byte to be read;
+     *               must be non-negative and no larger than <tt>array.length</tt>
+     * @param length The number of bytes to be read from the given array;
+     *               must be non-negative and no larger than
+     *               <tt>array.length - offset</tt>
+     * @return This buffer
+     * @throws BufferOverflowException   If there is insufficient space in this buffer
+     * @throws IndexOutOfBoundsException If the preconditions on the <tt>offset</tt> and <tt>length</tt>
+     *                                   parameters do not hold
+     * @throws java.nio.ReadOnlyBufferException
+     *                                   If this buffer is read-only
+     */
+    public IoByteBuffer put(byte[] src, int offset, int length)
+    {
+        checkBounds(offset, length, src.length);
+        if (length > remaining())
+            throw new BufferOverflowException();
+        int end = offset + length;
+        for (int i = offset; i < end; i++)
+            this.put(src[i]);
+        return this;
+    }
+
+    /**
+     * Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
+     * <p/>
+     * <p> This method transfers the entire content of the given source
+     * byte array into this buffer.  An invocation of this method of the
+     * form <tt>dst.put(a)</tt> behaves in exactly the same way as the
+     * invocation
+     * <p/>
+     * <pre>
+     *     dst.put(a, 0, a.length) </pre>
+     *
+     * @return This buffer
+     * @throws BufferOverflowException If there is insufficient space in this buffer
+     * @throws java.nio.ReadOnlyBufferException
+     *                                 If this buffer is read-only
+     */
+    public final IoByteBuffer put(byte[] src)
+    {
+        return put(src, 0, src.length);
+    }
+
+    static void checkBounds(int off, int len, int size)
+    { // package-private
+        if ((off | len | (off + len) | (size - (off + len))) < 0)
+            throw new IndexOutOfBoundsException();
+    }
 }

Modified: mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/ClosedChannelState.java
URL: http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/ClosedChannelState.java?rev=1159893&r1=1159892&r2=1159893&view=diff
==============================================================================
--- mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/ClosedChannelState.java (original)
+++ mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/ClosedChannelState.java Sat Aug 20 17:39:46 2011
@@ -49,10 +49,4 @@ public class ClosedChannelState implemen
     {
         //Todo change body of implemented methods use File | Settings | File Templates.
     }
-
-    @Override
-    public void handle(Context<SslStates> sslStatesPContext, SslEvent event) throws Exception
-    {
-        //Todo change body of implemented methods use File | Settings | File Templates.
-    }
 }

Modified: mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/ClosingChannelState.java
URL: http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/ClosingChannelState.java?rev=1159893&r1=1159892&r2=1159893&view=diff
==============================================================================
--- mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/ClosingChannelState.java (original)
+++ mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/ClosingChannelState.java Sat Aug 20 17:39:46 2011
@@ -49,10 +49,4 @@ public class ClosingChannelState impleme
     {
         //Todo change body of implemented methods use File | Settings | File Templates.
     }
-
-    @Override
-    public void handle(Context<SslStates> sslStatesPContext, SslEvent event) throws Exception
-    {
-        //Todo change body of implemented methods use File | Settings | File Templates.
-    }
 }

Modified: mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/FinishedChannelState.java
URL: http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/FinishedChannelState.java?rev=1159893&r1=1159892&r2=1159893&view=diff
==============================================================================
--- mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/FinishedChannelState.java (original)
+++ mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/FinishedChannelState.java Sat Aug 20 17:39:46 2011
@@ -64,10 +64,4 @@ public class FinishedChannelState extend
     {
         //Todo change body of implemented methods use File | Settings | File Templates.
     }
-
-    @Override
-    public void handle(Context<SslStates> context, SslEvent event) throws Exception
-    {
-        //Todo change body of implemented methods use File | Settings | File Templates.
-    }
 }

Modified: mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/HandshakeChannelState.java
URL: http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/HandshakeChannelState.java?rev=1159893&r1=1159892&r2=1159893&view=diff
==============================================================================
--- mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/HandshakeChannelState.java (original)
+++ mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/HandshakeChannelState.java Sat Aug 20 17:39:46 2011
@@ -18,15 +18,18 @@
  */
 package org.apache.mina.ssl;
 
-import javax.net.ssl.SSLEngine;
+import javax.net.ssl.SSLEngineResult;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import org.apache.mina.core.BaseChannelState;
 import org.apache.mina.core.IoBufferFactory;
+import org.apache.mina.core.IoEvent;
 import org.apache.mina.core.IoProperty;
 import org.apache.mina.core.IoPropertyScope;
+import org.apache.mina.core.api.IoDown;
+import org.apache.mina.core.api.IoUp;
 import org.apache.mina.core.state.Context;
 import org.apache.mina.nio.IoByteBuffer;
 
@@ -39,6 +42,8 @@ public class HandshakeChannelState exten
     private final static Logger LOGGER = LoggerFactory.getLogger(HandshakeChannelState.class);
     private IoBufferFactory<IoByteBuffer> factory;
     private SSLEngine engine;
+    private IoDown<IoByteBuffer> child;
+    private IoUp<IoByteBuffer> parent;
 
     @IoProperty(name = "factory", scope = IoPropertyScope.GLOBAL)
     public void setFactory(IoBufferFactory<IoByteBuffer> factory)
@@ -52,68 +57,86 @@ public class HandshakeChannelState exten
         this.engine = engine;
     }
 
+    @IoProperty(name = "child", scope = IoPropertyScope.PRIVATE)
+    public void setChild(IoDown<IoByteBuffer> child)
+    {
+        this.child = child;
+    }
+
+    @IoProperty(name = "parent", scope = IoPropertyScope.PRIVATE)
+    public void setParent(IoUp<IoByteBuffer> parent)
+    {
+        this.parent = parent;
+    }
+
+    @Override
     public void send(Context<SslStates> context, IoByteBuffer message) throws Exception
     {
         IoByteBuffer ioByteBuffer = (IoByteBuffer)message;
 
         IoByteBuffer byteBuffer = factory.allocate(engine.getSession().getPacketBufferSize()).get();
-//        SSLEngineResult result = engine.wrap(ioByteBuffer.getMessages(), byteBuffer);
-//        if (result.getHandshakeStatus() == SSLEngineResult.HandshakeStatus.NEED_TASK)
-//        {
-//            Runnable runnable;
-//            while ((runnable = engine.getDelegatedTask()) != null)
-//            {
-//                LOGGER.trace("delegated task started");
-//                runnable.run();
-//                LOGGER.trace("delegated task completed");
-//            }
-//
-//            SSLEngineResult.HandshakeStatus status = engine.getHandshakeStatus();
-//            if (status == SSLEngineResult.HandshakeStatus.NEED_TASK)
-//            {
-//                throw new Exception("handshake shouldn't need additional tasks");
-//            }
-//            LOGGER.trace("handshake status: " + status);
-//        }
-//        factory.recycle(message);
+        SSLEngineResult result = engine.wrap(ioByteBuffer, byteBuffer);
+        if (result.getHandshakeStatus() == SSLEngineResult.HandshakeStatus.NEED_TASK)
+        {
+            Runnable runnable;
+            while ((runnable = engine.getDelegatedTask()) != null)
+            {
+                LOGGER.trace("delegated task started");
+                runnable.run();
+                LOGGER.trace("delegated task completed");
+            }
+
+            SSLEngineResult.HandshakeStatus status = engine.getHandshakeStatus();
+            if (status == SSLEngineResult.HandshakeStatus.NEED_TASK)
+            {
+                throw new Exception("handshake shouldn't need additional tasks");
+            }
+            LOGGER.trace("handshake status: " + status);
+        }
+
+        child.send(byteBuffer);
+        message.recycle();
     }
 
+    @Override
     public void receive(Context<SslStates> context, IoByteBuffer message) throws Exception
     {
         IoByteBuffer byteBuffer = factory.allocate(engine.getSession().getPacketBufferSize()).get();
-//        SSLEngineResult result = engine.unwrap(message.getMessages()[0], byteBuffer);
-//        if (result.getHandshakeStatus() == SSLEngineResult.HandshakeStatus.NEED_TASK)
-//        {
-//            Runnable runnable;
-//            while ((runnable = engine.getDelegatedTask()) != null)
-//            {
-//                LOGGER.trace("delegated task started");
-//                runnable.run();
-//                LOGGER.trace("delegated task completed");
-//            }
-//
-//            SSLEngineResult.HandshakeStatus status = engine.getHandshakeStatus();
-//            if (status == SSLEngineResult.HandshakeStatus.NEED_TASK)
-//            {
-//                throw new Exception("handshake shouldn't need additional tasks");
-//            }
-//
-//            LOGGER.trace("handshake status: " + status);
-//        }
-//        else if (result.getHandshakeStatus() == SSLEngineResult.HandshakeStatus.NEED_WRAP)
-//        {
-//            stateMachine.send(send(stateMachine, IoByteBuffer.EMPTY));
-//        }
-//        else if (result.getHandshakeStatus() == SSLEngineResult.HandshakeStatus.FINISHED)
-//        {
-//            stateMachine.setState(SslStates.FINISHED);
-//        }
-//        factory.recycle(message);
+        SSLEngineResult result = engine.unwrap(message, byteBuffer);
+        if (result.getHandshakeStatus() == SSLEngineResult.HandshakeStatus.NEED_TASK)
+        {
+            Runnable runnable;
+            while ((runnable = engine.getDelegatedTask()) != null)
+            {
+                LOGGER.trace("delegated task started");
+                runnable.run();
+                LOGGER.trace("delegated task completed");
+            }
+
+            SSLEngineResult.HandshakeStatus status = engine.getHandshakeStatus();
+            if (status == SSLEngineResult.HandshakeStatus.NEED_TASK)
+            {
+                throw new Exception("handshake shouldn't need additional tasks");
+            }
+
+            LOGGER.trace("handshake status: " + status);
+        }
+        else if (result.getHandshakeStatus() == SSLEngineResult.HandshakeStatus.NEED_WRAP)
+        {
+            child.send(IoByteBuffer.EMPTY);
+        }
+        else if (result.getHandshakeStatus() == SSLEngineResult.HandshakeStatus.FINISHED)
+        {
+            context.setState(SslStates.FINISHED);
+        }
+
+        parent.receive(byteBuffer);
+        message.recycle();
     }
 
-    @Override
-    public void handle(Context<SslStates> sslStatesIoByteBufferContext, SslEvent event) throws Exception
+    @IoEvent(name = "initiateHandshake", type = InitiateHandshakeEvent.class)
+    public void handle(Context<SslStates> context, InitiateHandshakeEvent event) throws Exception
     {
-        //Todo change body of implemented methods use File | Settings | File Templates.
+        send(context, IoByteBuffer.EMPTY);
     }
 }

Added: mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/InitiateHandshakeEvent.java
URL: http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/InitiateHandshakeEvent.java?rev=1159893&view=auto
==============================================================================
--- mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/InitiateHandshakeEvent.java (added)
+++ mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/InitiateHandshakeEvent.java Sat Aug 20 17:39:46 2011
@@ -0,0 +1,26 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.mina.ssl;
+
+/**
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public class InitiateHandshakeEvent extends SslEvent
+{
+}

Added: mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/SSLEngine.java
URL: http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/SSLEngine.java?rev=1159893&view=auto
==============================================================================
--- mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/SSLEngine.java (added)
+++ mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/SSLEngine.java Sat Aug 20 17:39:46 2011
@@ -0,0 +1,497 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.mina.ssl;
+
+import javax.net.ssl.SSLEngineResult;
+import javax.net.ssl.SSLException;
+import javax.net.ssl.SSLParameters;
+import javax.net.ssl.SSLSession;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.mina.nio.IoByteBuffer;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class SSLEngine
+{
+    static final Logger LOG = LoggerFactory.getLogger(SSLEngine.class);
+    private final javax.net.ssl.SSLEngine sslEngine;
+
+    public SSLEngine(javax.net.ssl.SSLEngine sslEngine)
+    {
+        if (sslEngine == null) throw new IllegalArgumentException("SSL engine canot be null");
+        this.sslEngine = sslEngine;
+    }
+
+    /**
+     * Returns the name of the peer host.
+     *
+     * @return the name of the peer host, or {@code null} if none is available.
+     */
+    public String getPeerHost()
+    {
+        return sslEngine.getPeerHost();
+    }
+
+    /**
+     * Returns the port number of the peer host.
+     *
+     * @return the port number of the peer host, or {@code -1} is none is available.
+     */
+    public int getPeerPort()
+    {
+        return sslEngine.getPeerPort();
+    }
+
+    /**
+     * Encodes the outgoing application data buffer into the network data
+     * buffer. If a handshake has not been started yet, it will automatically be
+     * started.
+     *
+     * @param src the source buffers of outgoing application data.
+     * @param dst the destination buffer for network data.
+     * @return the result object of this operation.
+     * @throws SSLException             if a problem occurred while processing the data.
+     * @throws java.nio.ReadOnlyBufferException
+     *                                  if the destination buffer is readonly.
+     * @throws IllegalArgumentException if {@code src} or {@code dst} is {@code null}.
+     * @throws IllegalStateException    if the engine does not have all the needed settings (e.g.
+     *                                  client/server mode not set).
+     */
+    public SSLEngineResult wrap(IoByteBuffer src, IoByteBuffer dst) throws SSLException
+    {
+        return null;
+    }
+
+    /**
+     * Encodes the outgoing application data buffers into the network data
+     * buffer. If a handshake has not been started yet, it will automatically be
+     * started.
+     *
+     * @param srcs the array of source buffers of outgoing application data.
+     * @param dst  the destination buffer for network data.
+     * @return the result object of this operation.
+     * @throws SSLException             if a problem occurred while processing the data.
+     * @throws java.nio.ReadOnlyBufferException
+     *                                  if the destination buffer is readonly.
+     * @throws IllegalArgumentException if {@code srcs} or {@code dst} is {@code null}.
+     * @throws IllegalStateException    if the engine does not have all the needed settings (e.g.
+     *                                  client/server mode not set).
+     */
+    public SSLEngineResult wrap(IoByteBuffer[] srcs, IoByteBuffer dst) throws javax.net.ssl.SSLException
+    {
+        return null;
+/* compiled code */
+    }
+
+    /**
+     * Encodes the outgoing application data buffers into the network data
+     * buffer. If a handshake has not been started yet, it will automatically be
+     * started.
+     *
+     * @param srcs   the array of source buffers of outgoing application data.
+     * @param offset the offset in the array of source buffers from which data is
+     *               to be retrieved.
+     * @param length the maximum number of source buffers to be used.
+     * @param dst    the destination buffer for network data.
+     * @return the result object of this operation.
+     * @throws SSLException              if a problem occurred while processing the data.
+     * @throws IndexOutOfBoundsException if {@code length} is greater than
+     *                                   {@code srcs.length - offset}.
+     * @throws java.nio.ReadOnlyBufferException
+     *                                   if the destination buffer is readonly.
+     * @throws IllegalArgumentException  if {@code srcs}, {@code dst}, or one the entries in
+     *                                   {@code srcs} is {@code null}.
+     * @throws IllegalStateException     if the engine does not have all the needed settings (e.g.
+     *                                   client/server mode not set).
+     */
+    public SSLEngineResult wrap(IoByteBuffer[] srcs, int offset, int length, IoByteBuffer dst) throws SSLException
+    {
+        return null;
+    }
+
+    /**
+     * Decodes the incoming network data buffer into the application data
+     * buffer. If a handshake has not been started yet, it will automatically be
+     * started.
+     *
+     * @param src the buffer with incoming network data
+     * @param dst the destination buffer for incoming application data.
+     * @return the result object of this operation.
+     * @throws SSLException             if a problem occurred while processing the data.
+     * @throws java.nio.ReadOnlyBufferException
+     *                                  if one of the destination buffers is read-only.
+     * @throws IllegalArgumentException if {@code src} or {@code dst} is {@code null}.
+     * @throws IllegalStateException    if the engine does not have all the needed settings (e.g.
+     *                                  client/server mode not set).
+     */
+    public SSLEngineResult unwrap(IoByteBuffer src, IoByteBuffer dst) throws javax.net.ssl.SSLException
+    { /* compiled code */
+        return null;
+    }
+
+    /**
+     * Decodes the incoming network data buffer into the application data
+     * buffers. If a handshake has not been started yet, it will automatically
+     * be started.
+     *
+     * @param src  the buffer with incoming network data
+     * @param dsts the array of destination buffers for incoming application
+     *             data.
+     * @return the result object of this operation.
+     * @throws SSLException             if a problem occurred while processing the data.
+     * @throws java.nio.ReadOnlyBufferException
+     *                                  if one of the destination buffers is read-only.
+     * @throws IllegalArgumentException if {@code src} or {@code dsts} is {@code null}.
+     * @throws IllegalStateException    if the engine does not have all the needed settings (e.g.
+     *                                  client/server mode not set).
+     */
+    public SSLEngineResult unwrap(IoByteBuffer src, IoByteBuffer[] dsts) throws javax.net.ssl.SSLException
+    { /* compiled code */
+        return null;
+    }
+
+    /**
+     * Decodes the incoming network data buffer into application data buffers.
+     * If a handshake has not been started yet, it will automatically be
+     * started.
+     *
+     * @param src    the buffer with incoming network data
+     * @param dsts   the array of destination buffers for incoming application
+     *               data.
+     * @param offset the offset in the array of destination buffers to which data
+     *               is to be transferred.
+     * @param length the maximum number of destination buffers to be used.
+     * @return the result object of this operation.
+     * @throws SSLException              if a problem occurred while processing the data.
+     * @throws IndexOutOfBoundsException if {@code length} is greater than
+     *                                   {@code dsts.length - offset}.
+     * @throws java.nio.ReadOnlyBufferException
+     *                                   if one of the destination buffers is read-only.
+     * @throws IllegalArgumentException  if {@code src}, {@code dsts}, or one of the entries in
+     *                                   {@code dsts} is {@code null}.
+     * @throws IllegalStateException     if the engine does not have all the needed settings (e.g.
+     *                                   client/server mode not set).
+     */
+    public SSLEngineResult unwrap(IoByteBuffer src, IoByteBuffer[] dsts, int offset, int length) throws SSLException
+    {
+        return null;
+    }
+
+    /**
+     * Returns a delegate task for this engine instance. Some engine operations
+     * may require the results of blocking or long running operations, and the
+     * {@code SSLEngineResult} instances returned by this engine may indicate
+     * that a delegated task result is needed. In this case the
+     * {@link Runnable#run() run} method of the returned {@code Runnable}
+     * delegated task must be called.
+     *
+     * @return a delegate task, or {@code null} if none are available.
+     */
+    public Runnable getDelegatedTask()
+    {
+        return null; // todo
+    }
+
+    /**
+     * Notifies this engine instance that no more inbound network data will be
+     * sent to this engine.
+     *
+     * @throws SSLException if this engine did not receive a needed protocol specific
+     *                      close notification message from the peer.
+     */
+    public void closeInbound() throws SSLException
+    {
+        sslEngine.closeInbound();
+    }
+
+    /**
+     * Returns whether no more inbound data will be accepted by this engine.
+     *
+     * @return {@code true} if no more inbound data will be accepted by this
+     *         engine, {@code false} otherwise.
+     */
+    public boolean isInboundDone()
+    { return sslEngine.isInboundDone(); }
+
+    /**
+     * Notifies this engine instance that no more outbound application data will
+     * be sent to this engine.
+     */
+    public void closeOutbound()
+    { sslEngine.closeOutbound(); }
+
+    /**
+     * Returns whether no more outbound data will be produced by this engine.
+     *
+     * @return {@code true} if no more outbound data will be producted by this
+     *         engine, {@code otherwise} false.
+     */
+    public boolean isOutboundDone()
+    { return sslEngine.isOutboundDone(); }
+
+    /**
+     * Returns the SSL cipher suite names that are supported by this engine.
+     * These cipher suites can be enabled using
+     * {@link #setEnabledCipherSuites(String[])}.
+     *
+     * @return the SSL cipher suite names that are supported by this engine.
+     */
+    public String[] getSupportedCipherSuites()
+    {
+        return sslEngine.getSupportedCipherSuites();
+    }
+
+    /**
+     * Returns the SSL cipher suite names that are enabled in this engine
+     * instance.
+     *
+     * @return the SSL cipher suite names that are enabled in this engine
+     *         instance.
+     */
+    public String[] getEnabledCipherSuites()
+    {
+        return sslEngine.getEnabledCipherSuites();
+    }
+
+    /**
+     * Sets the SSL cipher suite names that should be enabled in this engine
+     * instance. Only cipher suites listed by {@code getSupportedCipherSuites()}
+     * are allowed.
+     *
+     * @param suites the SSL cipher suite names to be enabled.
+     * @throws IllegalArgumentException if one of the specified cipher suites is not supported, or if
+     *                                  {@code suites} is {@code null}.
+     */
+    public void setEnabledCipherSuites(String[] suites)
+    {
+        sslEngine.setEnabledCipherSuites(suites);
+    }
+
+    /**
+     * Returns the protocol names that are supported by this engine. These
+     * protocols can be enables using {@link #setEnabledProtocols(String[])}.
+     *
+     * @return the protocol names that are supported by this engine.
+     */
+    public String[] getSupportedProtocols()
+    {
+        return sslEngine.getSupportedProtocols();
+    }
+
+    /**
+     * Returns the protocol version names that are enabled in this engine
+     * instance.
+     *
+     * @return the protocol version names that are enabled in this engine
+     *         instance.
+     */
+    public String[] getEnabledProtocols()
+    {
+        return sslEngine.getEnabledProtocols();
+    }
+
+    /**
+     * Sets the protocol version names that should be enabled in this engine
+     * instance. Only protocols listed by {@code getSupportedProtocols()} are
+     * allowed.
+     *
+     * @param protocols the protocol version names to be enabled.
+     * @throws IllegalArgumentException if one of the protocol version names is not supported, or if
+     *                                  {@code protocols} is {@code null}.
+     */
+    public void setEnabledProtocols(String[] protocols)
+    {
+        sslEngine.setEnabledProtocols(protocols);
+    }
+
+    /**
+     * Returns the SSL session for this engine instance.
+     *
+     * @return the SSL session for this engine instance.
+     */
+    public SSLSession getSession()
+    {
+        return sslEngine.getSession();
+    }
+
+    /**
+     * Initiates a handshake on this engine.
+     * <p/>
+     * Calling this method is not needed for the initial handshake: it will be
+     * called by {@code wrap} or {@code unwrap} if the initial handshake has not
+     * been started yet.
+     *
+     * @throws SSLException          if starting the handshake fails.
+     * @throws IllegalStateException if the engine does not have all the needed settings (e.g.
+     *                               client/server mode not set).
+     */
+    public void beginHandshake() throws SSLException
+    {
+        sslEngine.beginHandshake();
+    }
+
+    /**
+     * Returns the status of the handshake of this engine instance.
+     *
+     * @return the status of the handshake of this engine instance.
+     */
+    public SSLEngineResult.HandshakeStatus getHandshakeStatus()
+    {
+        return sslEngine.getHandshakeStatus();
+    }
+
+    /**
+     * Sets whether this engine should act in client (or server) mode when
+     * handshaking.
+     *
+     * @param mode {@code true} if this engine should act in client mode,
+     *             {@code false} if not.
+     * @throws IllegalArgumentException if this method is called after starting the initial
+     *                                  handshake.
+     */
+    public void setUseClientMode(boolean mode)
+    {
+        sslEngine.setUseClientMode(mode);
+    }
+
+    /**
+     * Returns whether this engine is set to act in client mode when
+     * handshaking.
+     *
+     * @return {@code true} if the engine is set to do handshaking in client
+     *         mode.
+     */
+    public boolean getUseClientMode()
+    {
+        return sslEngine.getUseClientMode();
+    }
+
+    /**
+     * Sets whether this engine must require client authentication. The client
+     * authentication is one of:
+     * <ul>
+     * <li>authentication required</li>
+     * <li>authentication requested</li>
+     * <li>no authentication needed</li>
+     * </ul>
+     * This method overrides the setting of {@link #setWantClientAuth(boolean)}.
+     *
+     * @param need {@code true} if client authentication is required,
+     *             {@code false} if no authentication is needed.
+     */
+    public void setNeedClientAuth(boolean need)
+    {
+        sslEngine.setNeedClientAuth(need);
+    }
+
+    /**
+     * Returns whether this engine instance will require client authentication.
+     *
+     * @return {@code true} if this engine will require client authentication,
+     *         {@code false} if no client authentication is needed.
+     */
+    public boolean getNeedClientAuth()
+    {
+        return sslEngine.getNeedClientAuth();
+    }
+
+    /**
+     * Sets whether this engine should request client authentication. The client
+     * authentication is one of the following:
+     * <ul>
+     * <li>authentication required</li>
+     * <li>authentication requested</li>
+     * <li>no authentication needed</li>
+     * </ul>
+     * This method overrides the setting of {@link #setNeedClientAuth(boolean)}.
+     *
+     * @param want {@code true} if client authentication should be requested,
+     *             {@code false} if no authentication is needed.
+     */
+    public void setWantClientAuth(boolean want)
+    {
+        sslEngine.setWantClientAuth(want);
+    }
+
+    /**
+     * Returns whether this engine will request client authentication.
+     *
+     * @return {@code true} if client authentication will be requested,
+     *         {@code false} otherwise.
+     */
+    public boolean getWantClientAuth()
+    {
+        return sslEngine.getWantClientAuth();
+    }
+
+    /**
+     * Sets whether new SSL sessions may be established by this engine instance.
+     *
+     * @param flag {@code true} if new SSL sessions may be established,
+     *             {@code false} if existing SSL sessions must be reused.
+     */
+    public void setEnableSessionCreation(boolean flag)
+    {
+        sslEngine.setEnableSessionCreation(flag);
+    }
+
+    /**
+     * Returns whether new SSL sessions may be established by this engine.
+     *
+     * @return {@code true} if new session may be established, {@code false} if
+     *         existing sessions must be reused.
+     */
+    public boolean getEnableSessionCreation()
+    {
+        return sslEngine.getEnableSessionCreation();
+    }
+
+    /**
+     * Returns a new SSLParameters based on this SSLSocket's current
+     * cipher suites, protocols, and client authentication settings.
+     *
+     * @since 1.6
+     * @return new SSLParameters
+     */
+    public SSLParameters getSSLParameters()
+    {
+        return sslEngine.getSSLParameters();
+    }
+
+    /**
+     * Sets various SSL handshake parameters based on the SSLParameter
+     * argument. Specifically, sets the SSLEngine's enabled cipher
+     * suites if the parameter's cipher suites are non-null. Similarly
+     * sets the enabled protocols. If the parameters specify the want
+     * or need for client authentication, those requirements are set
+     * on the SSLEngine, otherwise both are set to false.
+     *
+     * @param parameters various SSL handshake parameters
+     * @since 1.6
+     */
+    public void setSSLParameters(SSLParameters parameters)
+    {
+        sslEngine.setSSLParameters(parameters);
+    }
+}

Modified: mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/SslChannel.java
URL: http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/SslChannel.java?rev=1159893&r1=1159892&r2=1159893&view=diff
==============================================================================
--- mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/SslChannel.java (original)
+++ mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/SslChannel.java Sat Aug 20 17:39:46 2011
@@ -18,15 +18,12 @@
  */
 package org.apache.mina.ssl;
 
-import javax.net.ssl.SSLEngine;
-import java.util.Collections;
-import java.util.concurrent.Executor;
-
-import org.apache.mina.core.IoBufferFactory;
-import org.apache.mina.core.IoChannelState;
 import org.apache.mina.core.IoProperty;
 import org.apache.mina.core.IoPropertyScope;
+import org.apache.mina.core.api.IoDown;
+import org.apache.mina.core.api.IoUp;
 import org.apache.mina.core.state.StateMachineChannel;
+import org.apache.mina.link.Token;
 import org.apache.mina.nio.IoByteBuffer;
 
 
@@ -36,8 +33,9 @@ import org.apache.mina.nio.IoByteBuffer;
 public class SslChannel extends StateMachineChannel<IoByteBuffer, IoByteBuffer, SslStates, SslEvent>
 {
     private SslConfig sslConfig;
-    private IoBufferFactory factory;
     private SSLEngine engine;
+    private IoDown<IoByteBuffer> child;
+    private IoUp<IoByteBuffer> parent;
 
     public SslChannel()
     {
@@ -47,16 +45,46 @@ public class SslChannel extends StateMac
         register(SslStates.CLOSED, new ClosedChannelState());
     }
 
+    @IoProperty(name = "child", scope = IoPropertyScope.PRIVATE)
+    public IoDown<IoByteBuffer> getChild()
+    {
+        return child;
+    }
+
+    @IoProperty(name = "child", scope = IoPropertyScope.PRIVATE)
+    public void setChild(IoDown<IoByteBuffer> child)
+    {
+        this.child = child;
+    }
+
+    @IoProperty(name = "parent", scope = IoPropertyScope.PRIVATE)
+    public IoUp<IoByteBuffer> getParent()
+    {
+        return parent;
+    }
+
+    @IoProperty(name = "parent", scope = IoPropertyScope.PRIVATE)
+    public void setParent(IoUp<IoByteBuffer> parent)
+    {
+        this.parent = parent;
+    }
+
     @IoProperty(name = "sslConfig", scope = IoPropertyScope.GLOBAL)
     public void setSslConfig(SslConfig sslConfig)
     {
         this.sslConfig = sslConfig;
     }
 
-    @IoProperty(name = "factory", scope = IoPropertyScope.GLOBAL)
-    public void setFactory(IoBufferFactory factory)
+    @IoProperty(name = "engine", scope = IoPropertyScope.SESSION)
+    public SSLEngine getEngine()
     {
-        this.factory = factory;
+        return engine;
+    }
+
+    @IoProperty(name = "engine", scope = IoPropertyScope.SESSION)
+    public void setEngine(SSLEngine engine)
+    {
+        this.engine = engine;
     }
 
     @Override
@@ -64,7 +92,7 @@ public class SslChannel extends StateMac
     {
         sslConfig.getSslContext().init(sslConfig.getKeyManagers(), sslConfig.getTrustManagers(), sslConfig.getSecureRandom());
 
-        engine = sslConfig.getSslContext().createSSLEngine();
+        engine = new SSLEngine(sslConfig.getSslContext().createSSLEngine());
 
         engine.setUseClientMode(sslConfig.isClientMode());
         if (sslConfig.getSslProtocols() != null) engine.setEnabledProtocols(sslConfig.getSslProtocols());
@@ -76,11 +104,7 @@ public class SslChannel extends StateMac
 
         if (!sslConfig.isLazyHandshake())
         {
-            HandshakeChannelState state = (HandshakeChannelState)getStates().get(SslStates.HANDSHAKE);
-            state.setFactory(factory);
-            state.setEngine(engine);
-
-            // TODO: NEED TO INITIATE HANDSHAKE HERE
+            queue(new InitiateHandshakeEvent());
         }
     }
 
@@ -90,10 +114,4 @@ public class SslChannel extends StateMac
         engine.closeInbound();
         engine.closeOutbound();
     }
-
-    @IoProperty(name = "engine", scope = IoPropertyScope.SESSION)
-    public SSLEngine getEngine()
-    {
-        return engine;
-    }
 }