Author: markt
Date: Thu Feb 23 11:35:24 2012
New Revision: 1292749

URL: http://svn.apache.org/viewvc?rev=1292749&view=rev
Log:
More javadoc and cleanup

Modified:
    tomcat/trunk/java/org/apache/catalina/websocket/WsFrame.java
    tomcat/trunk/java/org/apache/catalina/websocket/WsInputStream.java
    tomcat/trunk/java/org/apache/catalina/websocket/WsOutbound.java

Modified: tomcat/trunk/java/org/apache/catalina/websocket/WsFrame.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/websocket/WsFrame.java?rev=1292749&r1=1292748&r2=1292749&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/websocket/WsFrame.java (original)
+++ tomcat/trunk/java/org/apache/catalina/websocket/WsFrame.java Thu Feb 23 
11:35:24 2012
@@ -23,7 +23,7 @@ import org.apache.catalina.util.Conversi
 import org.apache.coyote.http11.upgrade.UpgradeProcessor;
 
 /**
- * Represents a WebSocket frame with the exception of the payload for
+ * Represents a complete WebSocket frame with the exception of the payload for
  * non-control frames.
  */
 public class WsFrame {
@@ -35,6 +35,17 @@ public class WsFrame {
     private long payloadLength;
     private ByteBuffer payload;
 
+    /**
+     * Create the new WebSocket frame, reading data from the processor as
+     * necessary.
+     *
+     * @param processor Processor associated with the WebSocket connection on
+     *                  which the frame has been sent
+     *
+     * @throws IOException  If a problem occurs processing the frame. Any
+     *                      exception will trigger the closing of the WebSocket
+     *                      connection.
+     */
     public WsFrame(UpgradeProcessor<?> processor) throws IOException {
 
         int b = processorRead(processor);

Modified: tomcat/trunk/java/org/apache/catalina/websocket/WsInputStream.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/websocket/WsInputStream.java?rev=1292749&r1=1292748&r2=1292749&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/websocket/WsInputStream.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/websocket/WsInputStream.java Thu Feb 
23 11:35:24 2012
@@ -37,6 +37,7 @@ public class WsInputStream extends java.
 
     private String error = null;
 
+
     public WsInputStream(UpgradeProcessor<?> processor, WsOutbound outbound)
             throws IOException {
         this.processor = processor;
@@ -44,10 +45,12 @@ public class WsInputStream extends java.
         processFrame();
     }
 
+
     public WsFrame getFrame() {
         return frame;
     }
 
+
     private void processFrame() throws IOException {
         frame = new WsFrame(processor);
         readThisFragment = 0;
@@ -73,8 +76,8 @@ public class WsInputStream extends java.
                 } else if (getFrame().getOpCode() == Constants.OPCODE_CLOSE) {
                     outbound.close(frame);
                 } else{
-                    // TODO
-                    throw new IOException("TODO");
+                    // TODO i18n
+                    throw new IOException("Unknown control frame");
                 }
                 processFrame();
             }

Modified: tomcat/trunk/java/org/apache/catalina/websocket/WsOutbound.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/websocket/WsOutbound.java?rev=1292749&r1=1292748&r2=1292749&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/websocket/WsOutbound.java (original)
+++ tomcat/trunk/java/org/apache/catalina/websocket/WsOutbound.java Thu Feb 23 
11:35:24 2012
@@ -25,6 +25,9 @@ import java.nio.charset.CoderResult;
 import org.apache.coyote.http11.upgrade.UpgradeOutbound;
 import org.apache.tomcat.util.buf.B2CConverter;
 
+/**
+ * Provides the means to write WebSocket messages to the client.
+ */
 public class WsOutbound {
 
     private static final int DEFAULT_BUFFER_SIZE = 8192;
@@ -45,6 +48,18 @@ public class WsOutbound {
     }
 
 
+    /**
+     * Adds the data to the buffer for binary data. If a textual message is
+     * currently in progress that message will be completed and a new binary
+     * message started. If the buffer for binary data is full, the buffer will
+     * be flushed and a new binary continuation fragment started.
+     *
+     * @param b The byte (only the least significant byte is used) of data to
+     *          send to the client.
+     *
+     * @throws IOException  If a flush is required and an error occurs writing
+     *                      the WebSocket frame to the client
+     */
     public void writeBinaryData(int b) throws IOException {
         if (bb.position() == bb.capacity()) {
             doFlush(false);
@@ -60,6 +75,17 @@ public class WsOutbound {
     }
 
 
+    /**
+     * Adds the data to the buffer for textual data. If a binary message is
+     * currently in progress that message will be completed and a new textual
+     * message started. If the buffer for textual data is full, the buffer will
+     * be flushed and a new textual continuation fragment started.
+     *
+     * @param b The character to send to the client.
+     *
+     * @throws IOException  If a flush is required and an error occurs writing
+     *                      the WebSocket frame to the client
+     */
     public void writeTextData(char c) throws IOException {
         if (cb.position() == cb.capacity()) {
             doFlush(false);
@@ -100,6 +126,7 @@ public class WsOutbound {
         doFlush(true);
     }
 
+
     private void doFlush(boolean finalFragment) throws IOException {
         if (text == null) {
             // No data
@@ -138,6 +165,7 @@ public class WsOutbound {
         }
     }
 
+
     private boolean validateCloseStatus(int status) {
 
         if (status == 1000 || status == 1001 || status == 1002 ||
@@ -155,6 +183,7 @@ public class WsOutbound {
         return false;
     }
 
+
     public void close(int status, ByteBuffer data) throws IOException {
         // TODO Think about threading requirements for writing. This is not
         // currently thread safe and writing almost certainly needs to be.
@@ -184,6 +213,7 @@ public class WsOutbound {
         upgradeOutbound = null;
     }
 
+
     public void pong(ByteBuffer data) throws IOException {
         // TODO Think about threading requirements for writing. This is not
         // currently thread safe and writing almost certainly needs to be.
@@ -204,6 +234,7 @@ public class WsOutbound {
         upgradeOutbound.flush();
     }
 
+
     /**
      * Writes the provided bytes as the payload in a new WebSocket frame.
      *
@@ -269,6 +300,9 @@ public class WsOutbound {
     }
 
 
+    /*
+     * Convert the textual message to bytes and then output it.
+     */
     private void doWriteText(CharBuffer buffer, boolean finalFragment)
             throws IOException {
         CharsetEncoder encoder = B2CConverter.UTF_8.newEncoder();



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to