You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by tr...@apache.org on 2007/10/16 10:13:03 UTC
svn commit: r585074 - in /mina:
branches/1.0/core/src/main/java/org/apache/mina/filter/codec/
branches/1.1/core/src/main/java/org/apache/mina/filter/codec/
trunk/core/src/main/java/org/apache/mina/filter/codec/
Author: trustin
Date: Tue Oct 16 01:13:01 2007
New Revision: 585074
URL: http://svn.apache.org/viewvc?rev=585074&view=rev
Log:
Improved ProtocolCodecFilter to handle the exceptions thrown by decoders more robustly.
* Now retries if an exception is raised (only when the decoder is capable.)
Modified:
mina/branches/1.0/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
mina/branches/1.1/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
mina/trunk/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
Modified: mina/branches/1.0/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
URL: http://svn.apache.org/viewvc/mina/branches/1.0/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java?rev=585074&r1=585073&r2=585074&view=diff
==============================================================================
--- mina/branches/1.0/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java (original)
+++ mina/branches/1.0/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java Tue Oct 16 01:13:01 2007
@@ -149,23 +149,38 @@
ProtocolDecoderOutput decoderOut = getDecoderOut(session, nextFilter);
try {
- synchronized (decoderOut) {
- decoder.decode(session, in, decoderOut);
+ while (in.hasRemaining()) {
+ int oldPos = in.position();
+ try {
+ synchronized (decoderOut) {
+ decoder.decode(session, in, decoderOut);
+ }
+ // Finish decoding if no exception was thrown.
+ decoderOut.flush();
+ break;
+ } catch (Throwable t) {
+ ProtocolDecoderException pde;
+ if (t instanceof ProtocolDecoderException) {
+ pde = (ProtocolDecoderException) t;
+ } else {
+ pde = new ProtocolDecoderException(t);
+ }
+ pde.setHexdump(in.getHexDump());
+
+ // Fire the exceptionCaught event.
+ decoderOut.flush();
+ nextFilter.exceptionCaught(session, pde);
+
+ // Stop retrying if the buffer position didn't change
+ // because retrying can cause an infinite loop.
+ if (in.position() == oldPos) {
+ break;
+ }
+ }
}
- } catch (Throwable t) {
- ProtocolDecoderException pde;
- if (t instanceof ProtocolDecoderException) {
- pde = (ProtocolDecoderException) t;
- } else {
- pde = new ProtocolDecoderException(t);
- }
- pde.setHexdump(in.getHexDump());
- throw pde;
} finally {
// Release the read buffer.
in.release();
-
- decoderOut.flush();
}
}
Modified: mina/branches/1.1/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
URL: http://svn.apache.org/viewvc/mina/branches/1.1/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java?rev=585074&r1=585073&r2=585074&view=diff
==============================================================================
--- mina/branches/1.1/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java (original)
+++ mina/branches/1.1/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java Tue Oct 16 01:13:01 2007
@@ -152,28 +152,38 @@
ProtocolDecoderOutput decoderOut = getDecoderOut(session, nextFilter);
try {
- synchronized (decoderOut) {
- decoder.decode(session, in, decoderOut);
+ while (in.hasRemaining()) {
+ int oldPos = in.position();
+ try {
+ synchronized (decoderOut) {
+ decoder.decode(session, in, decoderOut);
+ }
+ // Finish decoding if no exception was thrown.
+ decoderOut.flush();
+ break;
+ } catch (Throwable t) {
+ ProtocolDecoderException pde;
+ if (t instanceof ProtocolDecoderException) {
+ pde = (ProtocolDecoderException) t;
+ } else {
+ pde = new ProtocolDecoderException(t);
+ }
+ pde.setHexdump(in.getHexDump());
+
+ // Fire the exceptionCaught event.
+ decoderOut.flush();
+ nextFilter.exceptionCaught(session, pde);
+
+ // Stop retrying if the buffer position didn't change
+ // because retrying can cause an infinite loop.
+ if (in.position() == oldPos) {
+ break;
+ }
+ }
}
- } catch (Throwable t) {
- ProtocolDecoderException pde;
- if (t instanceof ProtocolDecoderException) {
- pde = (ProtocolDecoderException) t;
- } else {
- pde = new ProtocolDecoderException(t);
- }
- pde.setHexdump(in.getHexDump());
- throw pde;
} finally {
- // Dispose the decoder if this session is connectionless.
- if (session.getTransportType().isConnectionless()) {
- disposeDecoder(session);
- }
-
// Release the read buffer.
in.release();
-
- decoderOut.flush();
}
}
Modified: mina/trunk/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java?rev=585074&r1=585073&r2=585074&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java Tue Oct 16 01:13:01 2007
@@ -158,21 +158,34 @@
ProtocolDecoder decoder = getDecoder0(session);
ProtocolDecoderOutput decoderOut = getDecoderOut(session, nextFilter);
- try {
- synchronized (decoderOut) {
- decoder.decode(session, in, decoderOut);
+ while (in.hasRemaining()) {
+ int oldPos = in.position();
+ try {
+ synchronized (decoderOut) {
+ decoder.decode(session, in, decoderOut);
+ }
+ // Finish decoding if no exception was thrown.
+ decoderOut.flush();
+ break;
+ } catch (Throwable t) {
+ ProtocolDecoderException pde;
+ if (t instanceof ProtocolDecoderException) {
+ pde = (ProtocolDecoderException) t;
+ } else {
+ pde = new ProtocolDecoderException(t);
+ }
+ pde.setHexdump(in.getHexDump());
+
+ // Fire the exceptionCaught event.
+ decoderOut.flush();
+ nextFilter.exceptionCaught(session, pde);
+
+ // Stop retrying if the buffer position didn't change
+ // because retrying will cause an infinite loop.
+ if (in.position() == oldPos) {
+ break;
+ }
}
- } catch (Throwable t) {
- ProtocolDecoderException pde;
- if (t instanceof ProtocolDecoderException) {
- pde = (ProtocolDecoderException) t;
- } else {
- pde = new ProtocolDecoderException(t);
- }
- pde.setHexdump(in.getHexDump());
- throw pde;
- } finally {
- decoderOut.flush();
}
}