Skip to content

Commit

Permalink
Make WebSocketUpgradeHandler extensible in a controlled manner (via p…
Browse files Browse the repository at this point in the history
…rotected template methods) (#1446)
  • Loading branch information
thabach authored and slandelle committed Aug 3, 2017
1 parent 591ccee commit 2674166
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,42 @@ public class WebSocketUpgradeHandler implements AsyncHandler<NettyWebSocket> {
public WebSocketUpgradeHandler(List<WebSocketListener> listeners) {
this.listeners = listeners;
}

protected void setWebSocket0(NettyWebSocket webSocket) {}
protected void onStatusReceived0(HttpResponseStatus responseStatus) throws Exception {}
protected void onHeadersReceived0(HttpHeaders headers) throws Exception {}
protected void onBodyPartReceived0(HttpResponseBodyPart bodyPart) throws Exception {}
protected void onCompleted0() throws Exception {}
protected void onThrowable0(Throwable t) {}
protected void onOpen0() {}

@Override
public final State onStatusReceived(HttpResponseStatus responseStatus) throws Exception {
onStatusReceived0(responseStatus);
return responseStatus.getStatusCode() == SWITCHING_PROTOCOLS ? State.CONTINUE : State.ABORT;
}

@Override
public final State onHeadersReceived(HttpHeaders headers) throws Exception {
onHeadersReceived0(headers);
return State.CONTINUE;
}

@Override
public final State onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception {
onBodyPartReceived0(bodyPart);
return State.CONTINUE;
}

@Override
public final NettyWebSocket onCompleted() throws Exception {
onCompleted0();
return webSocket;
}

@Override
public final void onThrowable(Throwable t) {
onThrowable0(t);
for (WebSocketListener listener : listeners) {
if (webSocket != null) {
webSocket.addWebSocketListener(listener);
Expand All @@ -69,9 +82,11 @@ public final void onThrowable(Throwable t) {

public final void setWebSocket(NettyWebSocket webSocket) {
this.webSocket = webSocket;
setWebSocket0(this.webSocket);
}

public final void onOpen() {
onOpen0();
for (WebSocketListener listener : listeners) {
webSocket.addWebSocketListener(listener);
listener.onOpen(webSocket);
Expand Down

0 comments on commit 2674166

Please sign in to comment.