Permalink
Browse files

- Internal connector now closes entity stream/channel upon

         completion. Suggested by Arjohn Kampman
  • Loading branch information...
1 parent 2255af6 commit 6a32115d2a29f1bb3aa7dad62ef04c7ec48f5cf6 @jlouvel jlouvel committed Apr 30, 2012
@@ -322,7 +322,7 @@ public boolean isEmpty() {
}
@Override
- protected void onReceived(Response message) {
+ protected void onReceived(Response message) throws IOException {
if (message != null) {
SipRequest request = (SipRequest) getHelper().getRequest(message);
@@ -130,7 +130,7 @@ public int getInterestOperations() {
}
@Override
- public void onCompleted(boolean endDetected) {
+ public void onCompleted(boolean endDetected) throws IOException {
// Check if we need to close the connection
if (endDetected || !getConnection().isPersistent()
|| HeaderUtils.isConnectionClose(getHeaders())) {
@@ -141,7 +141,7 @@ public void onCompleted(boolean endDetected) {
}
@Override
- protected void onReceived() {
+ protected void onReceived() throws IOException {
// Update the response
getMessage().setEntity(createEntity(getHeaders()));
@@ -162,7 +162,7 @@ protected void onReceived() {
}
@Override
- protected void onReceived(Response message) {
+ protected void onReceived(Response message) throws IOException {
// Add it to the helper queue
getHelper().getInboundMessages().add(getMessage());
@@ -95,7 +95,7 @@ public Request getActualMessage() {
}
@Override
- public void onCompleted(boolean endDetected) {
+ public void onCompleted(boolean endDetected) throws IOException {
Response message = getMessage();
if (message != null) {
@@ -117,7 +117,7 @@ protected boolean isReady() {
}
@Override
- public void onCompleted(boolean endDetected) {
+ public void onCompleted(boolean endDetected) throws IOException {
if (getMessage() != null) {
getMessages().remove(getMessage());
}
@@ -146,7 +146,7 @@ public void onTimeOut() {
Status.CONNECTOR_ERROR_COMMUNICATION, rsp);
}
}
-
+
super.onTimeOut();
}
@@ -33,6 +33,7 @@
package org.restlet.engine.connector;
+import java.io.IOException;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
@@ -94,7 +95,7 @@ public boolean isEmpty() {
}
@Override
- public void onCompleted(boolean endDetected) {
+ public void onCompleted(boolean endDetected) throws IOException {
Response message = getMessage();
if (message != null) {
@@ -33,6 +33,7 @@
package org.restlet.engine.connector;
+import java.io.IOException;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
@@ -113,7 +114,7 @@ public void onError(Status status) {
}
@Override
- protected void onReceived(Response message) {
+ protected void onReceived(Response message) throws IOException {
if ((message.getRequest() != null)
&& message.getRequest().isExpectingResponse()) {
// Add it to the inbound queue
@@ -33,6 +33,7 @@
package org.restlet.engine.connector;
+import java.io.IOException;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
@@ -95,7 +96,7 @@ public boolean isEmpty() {
}
@Override
- public void onCompleted(boolean endDetected) {
+ public void onCompleted(boolean endDetected) throws IOException {
getMessages().remove(getMessage());
if (!getMessage().getStatus().isInformational()) {
@@ -208,7 +208,7 @@ protected boolean isLineReadable() throws IOException {
}
@Override
- public void onCompleted(boolean endDetected) {
+ public void onCompleted(boolean endDetected) throws IOException {
super.onCompleted(endDetected);
if (getLogger().isLoggable(Level.FINER)) {
@@ -297,7 +297,7 @@ public void onFillEof() {
* start line and the headers must have been received, not the optional
* body.
*/
- protected void onReceived() {
+ protected void onReceived() throws IOException {
if (getLogger().isLoggable(Level.FINER)) {
getLogger()
.finer("Inbound message start line and headers received");
@@ -309,8 +309,9 @@ protected void onReceived() {
*
* @param message
* The new message received.
+ * @throws IOException
*/
- protected abstract void onReceived(Response message);
+ protected abstract void onReceived(Response message) throws IOException;
@Override
public void onTimeOut() {
@@ -268,10 +268,14 @@ protected boolean hasIoInterest() {
}
@Override
- public void onCompleted(boolean endReached) {
+ public void onCompleted(boolean endReached) throws IOException {
if (getActualMessage() != null) {
Representation messageEntity = getActualMessage().getEntity();
+ if (getEntityChannel() != null) {
+ getEntityChannel().close();
+ }
+
// Release entity
if (messageEntity != null) {
messageEntity.release();
@@ -88,7 +88,7 @@ public ServerConnectionHelper getHelper() {
}
@Override
- protected void onReceived() {
+ protected void onReceived() throws IOException {
InboundRequest request = (InboundRequest) getMessage().getRequest();
if (getHeaders() != null) {
@@ -121,7 +121,7 @@ protected void onReceived() {
* @param message
* The new message received.
*/
- protected void onReceived(Response message) {
+ protected void onReceived(Response message) throws IOException {
if (message.getRequest() != null) {
// Add it to the helper queue
getHelper().getInboundMessages().add(message);
@@ -155,7 +155,7 @@ public Response getActualMessage() {
}
@Override
- public void onCompleted(boolean endDetected) {
+ public void onCompleted(boolean endDetected) throws IOException {
if (getMessage() != null) {
// Ensure that the request entity has been fully read
Representation requestEntity = getMessage().getRequest()
@@ -331,7 +331,7 @@ public void onClosed() {
* @param endDetected
* Indicates if the end of the socket channel was detected.
*/
- public void onCompleted(boolean endDetected) {
+ public void onCompleted(boolean endDetected) throws IOException {
setIoState(IoState.IDLE);
setMessageState(MessageState.IDLE);
setMessage(null);
@@ -33,6 +33,8 @@
package org.restlet.engine.io;
+import java.io.IOException;
+
/**
* Listener called back upon IO completion.
*
@@ -46,6 +48,6 @@
* @param eofDetected
* Indicates if the end of network connection was detected.
*/
- public void onCompleted(boolean eofDetected);
+ public void onCompleted(boolean eofDetected) throws IOException;
}
@@ -122,7 +122,7 @@ protected boolean isEndReached() {
* @param eofDetected
* Indicates if the end of network connection was detected.
*/
- public void onCompleted(boolean eofDetected) {
+ public void onCompleted(boolean eofDetected) throws IOException {
if (getCompletionListener() != null) {
getCompletionListener().onCompleted(eofDetected);
}
@@ -178,7 +178,7 @@ public int read(ByteBuffer targetBuffer) throws IOException {
* @param endReached
* True if the end of the channel has been reached.
*/
- protected void setEndReached(boolean endReached) {
+ protected void setEndReached(boolean endReached) throws IOException {
this.endReached = endReached;
if (this.endReached) {
@@ -146,7 +146,7 @@ protected void setAvailableSize(long availableSize) {
* @param endDetected
* True if the end of the channel has been detected.
*/
- protected void setEndDetected(boolean endDetected) {
+ protected void setEndDetected(boolean endDetected) throws IOException {
this.endDetected = endDetected;
if (endDetected && (getWrappedChannel() instanceof CompletionListener)) {
@@ -117,7 +117,7 @@ public int onDrain(Buffer buffer, int maxDrained, Object... args)
* The remaining size that should be read from the source
* channel.
*/
- protected void setAvailableSize(long availableSize) {
+ protected void setAvailableSize(long availableSize) throws IOException {
this.availableSize = availableSize;
setEndReached(this.availableSize == 0);
}

0 comments on commit 6a32115

Please sign in to comment.