Skip to content

Commit

Permalink
Fix handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
mnlipp committed May 6, 2024
1 parent 5b249a7 commit 09fbe05
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions org.jgrapes.http/src/org/jgrapes/http/HttpConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,12 @@ public void onRequest(Request.Out event)
* @throws InterruptedException the interrupted exception
*/
@Handler
@SuppressWarnings("PMD.CompareObjectsWithEquals")
public void onOutput(Output<?> event, WebAppMsgChannel appChannel)
throws InterruptedException {
appChannel.handleAppOutput(event);
if (appChannel.httpConnector() == this) {
appChannel.handleAppOutput(event);
}
}

/**
Expand All @@ -185,7 +188,8 @@ public void onConnected(ClientConnected event,
SocketIOChannel netConnChannel)
throws InterruptedException, IOException {
// Check if this is a response to our request
var appChannel = event.openEvent().associated(WebAppMsgChannel.class);
var appChannel = event.openEvent().associated(WebAppMsgChannel.class)
.filter(c -> c.httpConnector() == this);
if (appChannel.isPresent()) {
appChannel.get().connected(netConnChannel);
}
Expand All @@ -198,12 +202,14 @@ public void onConnected(ClientConnected event,
* @throws IOException Signals that an I/O exception has occurred.
*/
@Handler(channels = NetworkChannel.class)
@SuppressWarnings("PMD.CompareObjectsWithEquals")
public void onIoError(IOError event) throws IOException {
for (Channel channel : event.channels()) {
if (channel instanceof SocketIOChannel netConnChannel) {
// Error while using established network connection
Optional<WebAppMsgChannel> appChannel
= netConnChannel.associated(WebAppMsgChannel.class);
= netConnChannel.associated(WebAppMsgChannel.class)
.filter(c -> c.httpConnector() == this);
if (appChannel.isPresent()) {
// Error while using a network connection
appChannel.get().handleIoError(event, netConnChannel);
Expand All @@ -216,9 +222,10 @@ public void onIoError(IOError event) throws IOException {

// Error while trying to establish the network connection
if (event.event() instanceof OpenSocketConnection connEvent) {
connEvent.associated(WebAppMsgChannel.class).ifPresent(c -> {
c.openError(event);
});
connEvent.associated(WebAppMsgChannel.class)
.filter(c -> c.httpConnector() == this).ifPresent(c -> {
c.openError(event);
});
}
}
}
Expand All @@ -232,10 +239,12 @@ public void onIoError(IOError event) throws IOException {
* @throws ProtocolException if the protocol is violated
*/
@Handler(channels = NetworkChannel.class)
@SuppressWarnings("PMD.CompareObjectsWithEquals")
public void onInput(Input<ByteBuffer> event, SocketIOChannel netConnChannel)
throws InterruptedException, ProtocolException {
Optional<WebAppMsgChannel> appChannel
= netConnChannel.associated(WebAppMsgChannel.class);
= netConnChannel.associated(WebAppMsgChannel.class)
.filter(c -> c.httpConnector() == this);
if (appChannel.isPresent()) {
appChannel.get().handleNetInput(event, netConnChannel);
}
Expand All @@ -249,8 +258,9 @@ public void onInput(Input<ByteBuffer> event, SocketIOChannel netConnChannel)
*/
@Handler(channels = NetworkChannel.class)
public void onClosed(Closed<?> event, SocketIOChannel netConnChannel) {
netConnChannel.associated(WebAppMsgChannel.class).ifPresent(
appChannel -> appChannel.handleClosed(event));
netConnChannel.associated(WebAppMsgChannel.class)
.filter(c -> c.httpConnector() == this).ifPresent(
appChannel -> appChannel.handleClosed(event));
pooled.remove(netConnChannel.remoteAddress(), netConnChannel);
}

Expand All @@ -263,8 +273,11 @@ public void onClosed(Closed<?> event, SocketIOChannel netConnChannel) {
* @param appChannel the application channel
*/
@Handler
@SuppressWarnings("PMD.CompareObjectsWithEquals")
public void onClose(Close event, WebAppMsgChannel appChannel) {
appChannel.handleClose(event);
if (appChannel.httpConnector() == this) {
appChannel.handleClose(event);
}
}

/**
Expand Down Expand Up @@ -337,6 +350,10 @@ public WebAppMsgChannel(Request.Out event)
useSecure ? netSecureChannel : netMainChannel);
}

private HttpConnector httpConnector() {
return HttpConnector.this;
}

/**
* Error in response to trying to open a new TCP connection.
*
Expand Down

0 comments on commit 09fbe05

Please sign in to comment.