Improved exception handling, aborting the exchange rather than throwing.

This commit is contained in:
Simone Bordet 2015-03-10 10:36:24 +01:00
parent bab7888c59
commit 38250545fc
5 changed files with 10 additions and 8 deletions

View File

@ -94,13 +94,13 @@ public class HttpExchange
public void associate(HttpChannel channel)
{
if (!this.channel.compareAndSet(null, channel))
throw new IllegalStateException();
request.abort(new IllegalStateException());
}
public void disassociate(HttpChannel channel)
{
if (!this.channel.compareAndSet(channel, null))
throw new IllegalStateException();
request.abort(new IllegalStateException());
}
public boolean requestComplete()

View File

@ -654,7 +654,7 @@ public class HttpRequest implements Request
return listener.get(timeout, TimeUnit.MILLISECONDS);
}
catch (InterruptedException | TimeoutException x)
catch (Throwable x)
{
// Differently from the Future, the semantic of this method is that if
// the send() is interrupted or times out, we abort the request.

View File

@ -62,7 +62,8 @@ public abstract class MultiplexHttpDestination<C extends Connection> extends Htt
}
default:
{
throw new IllegalStateException();
abort(new IllegalStateException("Invalid connection state " + current));
return;
}
}
}

View File

@ -64,7 +64,7 @@ public class HttpReceiverOverHTTP extends HttpReceiver implements HttpParser.Res
public void receive()
{
if (buffer==null)
if (buffer == null)
acquireBuffer();
process();
}
@ -78,7 +78,7 @@ public class HttpReceiverOverHTTP extends HttpReceiver implements HttpParser.Res
private void releaseBuffer()
{
if (buffer==null)
if (buffer == null)
throw new IllegalStateException();
if (BufferUtil.hasContent(buffer))
throw new IllegalStateException();
@ -136,7 +136,7 @@ public class HttpReceiverOverHTTP extends HttpReceiver implements HttpParser.Res
if (LOG.isDebugEnabled())
LOG.debug(x);
BufferUtil.clear(buffer);
if (buffer!=null)
if (buffer != null)
releaseBuffer();
failAndClose(x);
}

View File

@ -116,7 +116,8 @@ public class HttpSenderOverHTTP extends HttpSender
}
default:
{
throw new IllegalStateException(result.toString());
callback.failed(new IllegalStateException(result.toString()));
return;
}
}
}