Skip to content

Commit

Permalink
Fix event handling (wasn't sufficiently selective).
Browse files Browse the repository at this point in the history
  • Loading branch information
mnlipp committed May 6, 2024
1 parent 09fbe05 commit 9349207
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ public SocketChannelImpl(OpenSocketConnection openEvent,
}, 2)
.setName(channelName + ".downstream.buffers");

// Ready to use
channels.add(this);

// Register with dispatcher
nioChannel.configureBlocking(false);
SocketConnectionManager.this.fire(
Expand Down
5 changes: 3 additions & 2 deletions org.jgrapes.io/src/org/jgrapes/net/SocketConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void onOpenConnection(OpenSocketConnection event) {
try {
@SuppressWarnings("PMD.CloseResource")
SocketChannel socketChannel = SocketChannel.open(event.address());
channels.add(new SocketChannelImpl(event, socketChannel));
new SocketChannelImpl(event, socketChannel);
} catch (ConnectException e) {
fire(new ConnectError(event, "Connection refused.", e));
} catch (IOException e) {
Expand All @@ -93,7 +93,8 @@ public void onOpenConnection(OpenSocketConnection event) {
public void onRegistered(NioRegistration.Completed event)
throws InterruptedException, IOException {
NioHandler handler = event.event().handler();
if (!(handler instanceof SocketChannelImpl)) {
if (!(handler instanceof SocketChannelImpl)
|| !channels.contains(handler)) {
return;
}
if (event.event().get() == null) {
Expand Down
5 changes: 3 additions & 2 deletions org.jgrapes.io/src/org/jgrapes/net/SocketServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,8 @@ public void onRegistered(NioRegistration.Completed event)
fire(new Ready(serverSocketChannel.getLocalAddress()));
return;
}
if (handler instanceof SocketChannelImpl channel) {
if (handler instanceof SocketChannelImpl channel
&& channels.contains(channel)) {
var accepted = new Accepted(channel.nioChannel().getLocalAddress(),
channel.nioChannel().getRemoteAddress(), false,
Collections.emptyList());
Expand Down Expand Up @@ -461,7 +462,7 @@ public void handleOps(int ops) {
}
return;
}
channels.add(new SocketChannelImpl(null, socketChannel));
new SocketChannelImpl(null, socketChannel);
} catch (IOException e) {
fire(new IOError(null, e));
}
Expand Down
8 changes: 7 additions & 1 deletion org.jgrapes.mail/src/org/jgrapes/mail/MailSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,11 @@ public void onOpenMailSender(OpenMailSender event, Channel channel)
* @throws MessagingException the messaging exception
*/
@Handler
@SuppressWarnings("PMD.CompareObjectsWithEquals")
public void onMessage(SendMailMessage event, Channel channel)
throws MessagingException {
if (channel instanceof SenderChannel chan) {
if (channel instanceof SenderChannel chan
&& chan.mailSender() == this) {
chan.sendMessage(event);
} else {
systemChannel.sendMessage(event);
Expand Down Expand Up @@ -208,6 +210,10 @@ public SenderChannel(Event<?> event, Channel mainChannel,
= Components.schedule(timer -> closeConnection(), maxIdleTime);
}

private MailSender mailSender() {
return MailSender.this;
}

/**
* Send the message provided by the event.
*
Expand Down

0 comments on commit 9349207

Please sign in to comment.