You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by ni...@apache.org on 2008/06/07 13:22:50 UTC
svn commit: r664322 -
/mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/
Author: niklas
Date: Sat Jun 7 04:22:49 2008
New Revision: 664322
URL: http://svn.apache.org/viewvc?rev=664322&view=rev
Log:
DIRMINA-591: Added Javadoc to the classes in the o.a.m.filter.codec.statemachine package.
Modified:
mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/ConsumeToCrLfDecodingState.java
mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/ConsumeToDynamicTerminatorDecodingState.java
mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/ConsumeToEndOfSessionDecodingState.java
mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/ConsumeToLinearWhitespaceDecodingState.java
mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/ConsumeToTerminatorDecodingState.java
mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/CrLfDecodingState.java
mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/DecodingState.java
mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/DecodingStateMachine.java
mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/DecodingStateProtocolDecoder.java
mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/FixedLengthDecodingState.java
mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/IntegerDecodingState.java
mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/LinearWhitespaceSkippingState.java
mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/ShortIntegerDecodingState.java
mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/SingleByteDecodingState.java
mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/SkippingState.java
Modified: mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/ConsumeToCrLfDecodingState.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/ConsumeToCrLfDecodingState.java?rev=664322&r1=664321&r2=664322&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/ConsumeToCrLfDecodingState.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/ConsumeToCrLfDecodingState.java Sat Jun 7 04:22:49 2008
@@ -23,8 +23,8 @@
import org.apache.mina.filter.codec.ProtocolDecoderOutput;
/**
- * A decoder which writes all read bytes in to a known <code>Bytes</code>
- * context until a <code>CRLF</code> has been encountered
+ * {@link DecodingState} which consumes all bytes until a <code>CRLF</code>
+ * has been encountered.
*
* @author The Apache MINA Project (dev@mina.apache.org)
* @version $Rev$, $Date$
@@ -125,6 +125,17 @@
return finishDecode(product, out);
}
+ /**
+ * Invoked when this state has reached a <code>CRLF</code>.
+ *
+ * @param product the read bytes including the <code>CRLF</code>.
+ * @param out the current {@link ProtocolDecoderOutput} used to write
+ * decoded messages.
+ * @return the next state if a state transition was triggered (use
+ * <code>this</code> for loop transitions) or <code>null</code> if
+ * the state machine has reached its end.
+ * @throws Exception if the read data violated protocol specification.
+ */
protected abstract DecodingState finishDecode(IoBuffer product,
ProtocolDecoderOutput out) throws Exception;
}
Modified: mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/ConsumeToDynamicTerminatorDecodingState.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/ConsumeToDynamicTerminatorDecodingState.java?rev=664322&r1=664321&r2=664322&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/ConsumeToDynamicTerminatorDecodingState.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/ConsumeToDynamicTerminatorDecodingState.java Sat Jun 7 04:22:49 2008
@@ -23,8 +23,8 @@
import org.apache.mina.filter.codec.ProtocolDecoderOutput;
/**
- * Consumes until a fixed (ASCII) character is reached.
- * The terminator is skipped.
+ * {@link DecodingState} which consumes all bytes until a fixed (ASCII)
+ * character is reached. The terminator is skipped.
*
* @author The Apache MINA Project (dev@mina.apache.org)
* @version $Rev$, $Date$
@@ -34,12 +34,6 @@
private IoBuffer buffer;
- /**
- * Creates a new instance.
- */
- public ConsumeToDynamicTerminatorDecodingState() {
- }
-
public DecodingState decode(IoBuffer in, ProtocolDecoderOutput out)
throws Exception {
int beginPos = in.position();
@@ -103,8 +97,26 @@
return finishDecode(product, out);
}
+ /**
+ * Determines whether the specified <code>byte</code> is a terminator.
+ *
+ * @param b the <code>byte</code> to check.
+ * @return <code>true</code> if <code>b</code> is a terminator,
+ * <code>false</code> otherwise.
+ */
protected abstract boolean isTerminator(byte b);
+ /**
+ * Invoked when this state has reached the terminator byte.
+ *
+ * @param product the read bytes not including the terminator.
+ * @param out the current {@link ProtocolDecoderOutput} used to write
+ * decoded messages.
+ * @return the next state if a state transition was triggered (use
+ * <code>this</code> for loop transitions) or <code>null</code> if
+ * the state machine has reached its end.
+ * @throws Exception if the read data violated protocol specification.
+ */
protected abstract DecodingState finishDecode(IoBuffer product,
ProtocolDecoderOutput out) throws Exception;
}
Modified: mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/ConsumeToEndOfSessionDecodingState.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/ConsumeToEndOfSessionDecodingState.java?rev=664322&r1=664321&r2=664322&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/ConsumeToEndOfSessionDecodingState.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/ConsumeToEndOfSessionDecodingState.java Sat Jun 7 04:22:49 2008
@@ -24,10 +24,8 @@
import org.apache.mina.filter.codec.ProtocolDecoderOutput;
/**
- * A {@link DecodingState} which consumes all received bytes until a configured
- * number of read bytes has been reached. Please note that this state can
- * produce the buffer with less data if the associated session has been
- * closed unexpectedly.
+ * {@link DecodingState} which consumes all received bytes until the session is
+ * closed.
*
* @author The Apache MINA Project (dev@mina.apache.org)
* @version $Rev$, $Date$
@@ -37,6 +35,13 @@
private IoBuffer buffer;
private final int maxLength;
+ /**
+ * Creates a new instance using the specified maximum length.
+ *
+ * @param maxLength the maximum number of bytes which will be consumed. If
+ * this max is reached a {@link ProtocolDecoderException} will be
+ * thrown by {@link #decode(IoBuffer, ProtocolDecoderOutput)}.
+ */
public ConsumeToEndOfSessionDecodingState(int maxLength) {
this.maxLength = maxLength;
}
@@ -67,6 +72,18 @@
}
}
- protected abstract DecodingState finishDecode(IoBuffer readData,
+ /**
+ * Invoked when this state has consumed all bytes until the session is
+ * closed.
+ *
+ * @param product the bytes read.
+ * @param out the current {@link ProtocolDecoderOutput} used to write
+ * decoded messages.
+ * @return the next state if a state transition was triggered (use
+ * <code>this</code> for loop transitions) or <code>null</code> if
+ * the state machine has reached its end.
+ * @throws Exception if the read data violated protocol specification.
+ */
+ protected abstract DecodingState finishDecode(IoBuffer product,
ProtocolDecoderOutput out) throws Exception;
}
Modified: mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/ConsumeToLinearWhitespaceDecodingState.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/ConsumeToLinearWhitespaceDecodingState.java?rev=664322&r1=664321&r2=664322&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/ConsumeToLinearWhitespaceDecodingState.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/ConsumeToLinearWhitespaceDecodingState.java Sat Jun 7 04:22:49 2008
@@ -20,7 +20,8 @@
package org.apache.mina.filter.codec.statemachine;
/**
- * TODO Add documentation
+ * {@link DecodingState} which consumes all bytes until a space (0x20) or tab
+ * (0x09) character is reached. The terminator is skipped.
*
* @author The Apache MINA Project (dev@mina.apache.org)
* @version $Rev$, $Date$
Modified: mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/ConsumeToTerminatorDecodingState.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/ConsumeToTerminatorDecodingState.java?rev=664322&r1=664321&r2=664322&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/ConsumeToTerminatorDecodingState.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/ConsumeToTerminatorDecodingState.java Sat Jun 7 04:22:49 2008
@@ -23,8 +23,8 @@
import org.apache.mina.filter.codec.ProtocolDecoderOutput;
/**
- * Consumes until a fixed (ASCII) character is reached.
- * The terminator is skipped.
+ * {@link DecodingState} which consumes all bytes until a fixed (ASCII)
+ * character is reached. The terminator is skipped.
*
* @author The Apache MINA Project (dev@mina.apache.org)
* @version $Rev$, $Date$
@@ -36,7 +36,9 @@
private IoBuffer buffer;
/**
- * @param terminator The terminator character
+ * Creates a new instance using the specified terminator character.
+ *
+ * @param terminator the terminator character.
*/
public ConsumeToTerminatorDecodingState(byte terminator) {
this.terminator = terminator;
@@ -96,6 +98,17 @@
return finishDecode(product, out);
}
+ /**
+ * Invoked when this state has reached the terminator byte.
+ *
+ * @param product the read bytes not including the terminator.
+ * @param out the current {@link ProtocolDecoderOutput} used to write
+ * decoded messages.
+ * @return the next state if a state transition was triggered (use
+ * <code>this</code> for loop transitions) or <code>null</code> if
+ * the state machine has reached its end.
+ * @throws Exception if the read data violated protocol specification.
+ */
protected abstract DecodingState finishDecode(IoBuffer product,
ProtocolDecoderOutput out) throws Exception;
}
Modified: mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/CrLfDecodingState.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/CrLfDecodingState.java?rev=664322&r1=664321&r2=664322&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/CrLfDecodingState.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/CrLfDecodingState.java Sat Jun 7 04:22:49 2008
@@ -24,10 +24,10 @@
import org.apache.mina.filter.codec.ProtocolDecoderOutput;
/**
- * Decodes a single <code>CRLF</code>.
- * If it is found, the bytes are consumed and <code>Boolean.TRUE</code>
+ * {@link DecodingState} which decodes a single <code>CRLF</code>.
+ * If it is found, the bytes are consumed and <code>true</code>
* is provided as the product. Otherwise, read bytes are pushed back
- * to the stream, and <code>Boolean.FALSE</code> is provided as the
+ * to the stream, and <code>false</code> is provided as the
* product.
* Note that if we find a CR but do not find a following LF, we raise
* an error.
@@ -92,6 +92,17 @@
return finishDecode(false, out);
}
+ /**
+ * Invoked when this state has found a <code>CRLF</code>.
+ *
+ * @param foundCRLF <code>true</code> if <code>CRLF</code> was found.
+ * @param out the current {@link ProtocolDecoderOutput} used to write
+ * decoded messages.
+ * @return the next state if a state transition was triggered (use
+ * <code>this</code> for loop transitions) or <code>null</code> if
+ * the state machine has reached its end.
+ * @throws Exception if the read data violated protocol specification.
+ */
protected abstract DecodingState finishDecode(boolean foundCRLF,
ProtocolDecoderOutput out) throws Exception;
}
Modified: mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/DecodingState.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/DecodingState.java?rev=664322&r1=664321&r2=664322&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/DecodingState.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/DecodingState.java Sat Jun 7 04:22:49 2008
@@ -24,7 +24,8 @@
import org.apache.mina.filter.codec.ProtocolDecoderOutput;
/**
- * TODO Add documentation
+ * Represents a state in a decoder state machine used by
+ * {@link DecodingStateMachine}.
*
* @author The Apache MINA Project (dev@mina.apache.org)
* @version $Rev$, $Date$
@@ -32,12 +33,30 @@
public interface DecodingState {
/**
* Invoked when data is available for this state.
+ *
+ * @param in the data to be decoded.
+ * @param out used to write decoded objects.
+ * @return the next state if a state transition was triggered (use
+ * <code>this</code> for loop transitions) or <code>null</code> if
+ * the state machine has reached its end.
+ * @throws Exception if the read data violated protocol specification.
*/
DecodingState decode(IoBuffer in, ProtocolDecoderOutput out)
throws Exception;
/**
- * Invoked when the associated {@link IoSession} is closed.
+ * Invoked when the associated {@link IoSession} is closed. This method is
+ * useful when you deal with protocols which don't specify the length of a
+ * message (e.g. HTTP responses without <tt>content-length</tt> header).
+ * Implement this method to process the remaining data that
+ * {@link #decode(IoBuffer, ProtocolDecoderOutput)} method didn't process
+ * completely.
+ *
+ * @param out used to write decoded objects.
+ * @return the next state if a state transition was triggered (use
+ * <code>this</code> for loop transitions) or <code>null</code> if
+ * the state machine has reached its end.
+ * @throws Exception if the read data violated protocol specification.
*/
DecodingState finishDecode(ProtocolDecoderOutput out) throws Exception;
}
Modified: mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/DecodingStateMachine.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/DecodingStateMachine.java?rev=664322&r1=664321&r2=664322&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/DecodingStateMachine.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/DecodingStateMachine.java Sat Jun 7 04:22:49 2008
@@ -23,12 +23,25 @@
import java.util.List;
import org.apache.mina.common.IoBuffer;
+import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.codec.ProtocolDecoderOutput;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * TODO Add documentation
+ * Abstract base class for decoder state machines. Calls {@link #init()} to
+ * get the start {@link DecodingState} of the state machine. Calls
+ * {@link #destroy()} when the state machine has reached its end state or when
+ * the session is closed.
+ * <p>
+ * NOTE: The {@link ProtocolDecoderOutput} used by this class when calling
+ * {@link DecodingState#decode(IoBuffer, ProtocolDecoderOutput)} buffers decoded
+ * messages in a {@link List}. Once the state machine has reached its end state
+ * this class will call {@link #finishDecode(List, ProtocolDecoderOutput)}. The
+ * implementation will have to take care of writing the decoded messages to the
+ * real {@link ProtocolDecoderOutput} used by the configured
+ * {@link ProtocolCodecFilter}.
+ * </p>
*
* @author The Apache MINA Project (dev@mina.apache.org)
* @version $Rev$, $Date$
@@ -51,11 +64,30 @@
private DecodingState currentState;
private boolean initialized;
+ /**
+ * Invoked to initialize this state machine.
+ *
+ * @return the start {@link DecodingState}.
+ */
protected abstract DecodingState init() throws Exception;
+ /**
+ * Called once the state machine has reached its end.
+ *
+ * @param childProducts contains the messages generated by each of the
+ * {@link DecodingState}s which were exposed to the received data
+ * during the life time of this state machine.
+ * @param out the real {@link ProtocolDecoderOutput} used by the
+ * {@link ProtocolCodecFilter}.
+ * @return the next state if the state machine should resume.
+ */
protected abstract DecodingState finishDecode(List<Object> childProducts,
ProtocolDecoderOutput out) throws Exception;
+ /**
+ * Invoked to destroy this state machine once the end state has been reached
+ * or the session has been closed.
+ */
protected abstract void destroy() throws Exception;
public DecodingState decode(IoBuffer in, ProtocolDecoderOutput out)
Modified: mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/DecodingStateProtocolDecoder.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/DecodingStateProtocolDecoder.java?rev=664322&r1=664321&r2=664322&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/DecodingStateProtocolDecoder.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/DecodingStateProtocolDecoder.java Sat Jun 7 04:22:49 2008
@@ -28,7 +28,12 @@
import org.apache.mina.util.CircularQueue;
/**
- * TODO Add documentation
+ * {@link ProtocolDecoder} which uses a {@link DecodingState} to decode data.
+ * Use a {@link DecodingStateMachine} as {@link DecodingState} to create
+ * a state machine which can decode your protocol.
+ * <p>
+ * NOTE: This is a stateful decoder. You should create one instance per session.
+ * </p>
*
* @author The Apache MINA Project (dev@mina.apache.org)
* @version $Rev$, $Date$
@@ -38,6 +43,13 @@
private final Queue<IoBuffer> undecodedBuffers = new CircularQueue<IoBuffer>();
private IoSession session;
+ /**
+ * Creates a new instance using the specified {@link DecodingState}
+ * instance.
+ *
+ * @param state the {@link DecodingState}.
+ * @throws NullPointerException if the specified state is <code>null</code>.
+ */
public DecodingStateProtocolDecoder(DecodingState state) {
if (state == null) {
throw new NullPointerException("state");
Modified: mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/FixedLengthDecodingState.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/FixedLengthDecodingState.java?rev=664322&r1=664321&r2=664322&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/FixedLengthDecodingState.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/FixedLengthDecodingState.java Sat Jun 7 04:22:49 2008
@@ -23,10 +23,10 @@
import org.apache.mina.filter.codec.ProtocolDecoderOutput;
/**
- * A {@link DecodingState} which consumes all received bytes until a configured
- * number of read bytes has been reached. Please note that this state can
- * produce the buffer with less data if the associated session has been
- * closed unexpectedly.
+ * {@link DecodingState} which consumes all received bytes until a configured
+ * number of read bytes has been reached. Please note that this state can
+ * produce a buffer with less data than the configured length if the associated
+ * session has been closed unexpectedly.
*
* @author The Apache MINA Project (dev@mina.apache.org)
* @version $Rev$, $Date$
@@ -38,9 +38,9 @@
private IoBuffer buffer;
/**
- * Constructs with a known decode length.
+ * Constructs a new instance using the specified decode length.
*
- * @param length The decode length
+ * @param length the number of bytes to read.
*/
public FixedLengthDecodingState(int length) {
this.length = length;
@@ -89,6 +89,17 @@
return finishDecode(readData ,out);
}
- protected abstract DecodingState finishDecode(IoBuffer readData,
+ /**
+ * Invoked when this state has consumed the configured number of bytes.
+ *
+ * @param product the data.
+ * @param out the current {@link ProtocolDecoderOutput} used to write
+ * decoded messages.
+ * @return the next state if a state transition was triggered (use
+ * <code>this</code> for loop transitions) or <code>null</code> if
+ * the state machine has reached its end.
+ * @throws Exception if the read data violated protocol specification.
+ */
+ protected abstract DecodingState finishDecode(IoBuffer product,
ProtocolDecoderOutput out) throws Exception;
}
Modified: mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/IntegerDecodingState.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/IntegerDecodingState.java?rev=664322&r1=664321&r2=664322&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/IntegerDecodingState.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/IntegerDecodingState.java Sat Jun 7 04:22:49 2008
@@ -24,7 +24,8 @@
import org.apache.mina.filter.codec.ProtocolDecoderOutput;
/**
- * TODO Add documentation
+ * {@link DecodingState} which decodes <code>int</code> values in big-endian
+ * order (high bytes come first).
*
* @author The Apache MINA Project (dev@mina.apache.org)
* @version $Rev$, $Date$
@@ -36,9 +37,6 @@
private int thirdByte;
private int counter;
- public IntegerDecodingState() {
- }
-
public DecodingState decode(IoBuffer in, ProtocolDecoderOutput out)
throws Exception {
while (in.hasRemaining()) {
@@ -72,6 +70,17 @@
"Unexpected end of session while waiting for an integer.");
}
+ /**
+ * Invoked when this state has consumed a complete <code>int</code>.
+ *
+ * @param value the integer.
+ * @param out the current {@link ProtocolDecoderOutput} used to write
+ * decoded messages.
+ * @return the next state if a state transition was triggered (use
+ * <code>this</code> for loop transitions) or <code>null</code> if
+ * the state machine has reached its end.
+ * @throws Exception if the read data violated protocol specification.
+ */
protected abstract DecodingState finishDecode(int value,
ProtocolDecoderOutput out) throws Exception;
}
Modified: mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/LinearWhitespaceSkippingState.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/LinearWhitespaceSkippingState.java?rev=664322&r1=664321&r2=664322&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/LinearWhitespaceSkippingState.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/LinearWhitespaceSkippingState.java Sat Jun 7 04:22:49 2008
@@ -20,7 +20,7 @@
package org.apache.mina.filter.codec.statemachine;
/**
- * TODO Add documentation
+ * {@link DecodingState} which skips space (0x20) and tab (0x09) characters.
*
* @author The Apache MINA Project (dev@mina.apache.org)
* @version $Rev$, $Date$
Modified: mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/ShortIntegerDecodingState.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/ShortIntegerDecodingState.java?rev=664322&r1=664321&r2=664322&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/ShortIntegerDecodingState.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/ShortIntegerDecodingState.java Sat Jun 7 04:22:49 2008
@@ -24,7 +24,8 @@
import org.apache.mina.filter.codec.ProtocolDecoderOutput;
/**
- * TODO Add documentation
+ * {@link DecodingState} which decodes <code>short</code> values in big-endian
+ * order (high bytes come first).
*
* @author The Apache MINA Project (dev@mina.apache.org)
* @version $Rev$, $Date$
@@ -34,9 +35,6 @@
private int highByte;
private int counter;
- public ShortIntegerDecodingState() {
- }
-
public DecodingState decode(IoBuffer in, ProtocolDecoderOutput out)
throws Exception {
@@ -63,6 +61,17 @@
"Unexpected end of session while waiting for a short integer.");
}
+ /**
+ * Invoked when this state has consumed a complete <code>short</code>.
+ *
+ * @param value the short.
+ * @param out the current {@link ProtocolDecoderOutput} used to write
+ * decoded messages.
+ * @return the next state if a state transition was triggered (use
+ * <code>this</code> for loop transitions) or <code>null</code> if
+ * the state machine has reached its end.
+ * @throws Exception if the read data violated protocol specification.
+ */
protected abstract DecodingState finishDecode(short value,
ProtocolDecoderOutput out) throws Exception;
}
Modified: mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/SingleByteDecodingState.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/SingleByteDecodingState.java?rev=664322&r1=664321&r2=664322&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/SingleByteDecodingState.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/SingleByteDecodingState.java Sat Jun 7 04:22:49 2008
@@ -24,16 +24,13 @@
import org.apache.mina.filter.codec.ProtocolDecoderOutput;
/**
- * TODO Add documentation
+ * {@link DecodingState} which decodes <code>byte</code> values.
*
* @author The Apache MINA Project (dev@mina.apache.org)
* @version $Rev$, $Date$
*/
public abstract class SingleByteDecodingState implements DecodingState {
- public SingleByteDecodingState() {
- }
-
public DecodingState decode(IoBuffer in, ProtocolDecoderOutput out)
throws Exception {
if (in.hasRemaining()) {
@@ -49,6 +46,17 @@
"Unexpected end of session while waiting for a single byte.");
}
+ /**
+ * Invoked when this state has consumed a complete <code>byte</code>.
+ *
+ * @param b the byte.
+ * @param out the current {@link ProtocolDecoderOutput} used to write
+ * decoded messages.
+ * @return the next state if a state transition was triggered (use
+ * <code>this</code> for loop transitions) or <code>null</code> if
+ * the state machine has reached its end.
+ * @throws Exception if the read data violated protocol specification.
+ */
protected abstract DecodingState finishDecode(byte b,
ProtocolDecoderOutput out) throws Exception;
}
Modified: mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/SkippingState.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/SkippingState.java?rev=664322&r1=664321&r2=664322&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/SkippingState.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/filter/codec/statemachine/SkippingState.java Sat Jun 7 04:22:49 2008
@@ -23,7 +23,8 @@
import org.apache.mina.filter.codec.ProtocolDecoderOutput;
/**
- * Skips data until {@link #canSkip(byte)} returns <tt>false</tt>.
+ * {@link DecodingState} which skips data until {@link #canSkip(byte)} returns
+ * <tt>false</tt>.
*
* @author The Apache MINA Project (dev@mina.apache.org)
* @version $Rev$, $Date$
@@ -32,12 +33,6 @@
private int skippedBytes;
- /**
- * Creates a new instance.
- */
- public SkippingState() {
- }
-
public DecodingState decode(IoBuffer in, ProtocolDecoderOutput out)
throws Exception {
int beginPos = in.position();
@@ -63,8 +58,23 @@
return finishDecode(skippedBytes);
}
+ /**
+ * Called to determine whether the specified byte can be skipped.
+ *
+ * @param b the byte to check.
+ * @return <code>true</code> if the byte can be skipped.
+ */
protected abstract boolean canSkip(byte b);
+ /**
+ * Invoked when this state cannot skip any more bytes.
+ *
+ * @param skippedBytes the number of bytes skipped.
+ * @return the next state if a state transition was triggered (use
+ * <code>this</code> for loop transitions) or <code>null</code> if
+ * the state machine has reached its end.
+ * @throws Exception if the read data violated protocol specification.
+ */
protected abstract DecodingState finishDecode(int skippedBytes)
throws Exception;
}