Skip to content
Permalink
Browse files

Trigger onClose handler when underlying http channel is closed [IMMUT…

…ANT-573]
  • Loading branch information...
tobias committed Jul 29, 2015
1 parent 5228f64 commit 433a0a91a7ac62aae2eb8fcd32795515e96934bb
@@ -17,6 +17,7 @@
package org.projectodd.wunderboss.web.undertow.async;

import io.undertow.server.HttpServerExchange;
import io.undertow.server.ServerConnection;
import org.projectodd.wunderboss.web.async.OutputStreamHttpChannel;

import java.io.OutputStream;
@@ -28,6 +29,12 @@ public UndertowHttpChannel(final HttpServerExchange exchange,
final OnClose onClose) {
super(onOpen, onError, onClose);
this.exchange = exchange.setPersistent(true).dispatch();
this.exchange.getConnection().addCloseListener(new ServerConnection.CloseListener() {
@Override
public void closed(ServerConnection _) {
notifyClose();
}
});
}

@Override
@@ -67,6 +67,14 @@ public void notifyError(Throwable error) {
}
}

protected void notifyClose() {
if (!closeNotified &&
this.onClose != null) {
this.onClose.handle(this, null, null);
}
closeNotified = true;
}

@Override
public boolean isOpen() {
return this.open;
@@ -189,9 +197,7 @@ public void close() throws IOException {
this.stream.close();
this.open = false;

if (this.onClose != null) {
this.onClose.handle(this, null, null);
}
notifyClose();
}

protected Runnable closer = new Runnable() {
@@ -209,6 +215,7 @@ public void run() {
private boolean open = false;
private boolean sendQueued = false;
private boolean headersSent = false;
private boolean closeNotified = false;
private OutputStream stream;
private final OnOpen onOpen;
private final OnError onError;

0 comments on commit 433a0a9

Please sign in to comment.
You can’t perform that action at this time.