Skip to content

Commit 000f6da

Browse files
committed
improves BaseDuplexConnection and related subclasses
Signed-off-by: Oleh Dokuka <[email protected]> Signed-off-by: Oleh Dokuka <[email protected]>
1 parent 9804688 commit 000f6da

File tree

3 files changed

+17
-25
lines changed

3 files changed

+17
-25
lines changed

rsocket-core/src/main/java/io/rsocket/internal/BaseDuplexConnection.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void sendFrame(int streamId, ByteBuf frame) {
3939
protected abstract void doOnClose();
4040

4141
@Override
42-
public final Mono<Void> onClose() {
42+
public Mono<Void> onClose() {
4343
return onClose.asMono();
4444
}
4545

rsocket-transport-netty/src/main/java/io/rsocket/transport/netty/TcpDuplexConnection.java

+8-12
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.net.SocketAddress;
2727
import java.util.Objects;
2828
import reactor.core.publisher.Flux;
29+
import reactor.core.publisher.Mono;
2930
import reactor.netty.Connection;
3031

3132
/** An implementation of {@link DuplexConnection} that connects via TCP. */
@@ -67,24 +68,19 @@ protected void doOnClose() {
6768
connection.dispose();
6869
}
6970

71+
@Override
72+
public Mono<Void> onClose() {
73+
return super.onClose().and(connection.onDispose());
74+
}
75+
7076
@Override
7177
public void sendErrorAndClose(RSocketErrorException e) {
7278
final ByteBuf errorFrame = ErrorFrameCodec.encode(alloc(), 0, e);
7379
connection
7480
.outbound()
7581
.sendObject(FrameLengthCodec.encode(alloc(), errorFrame.readableBytes(), errorFrame))
76-
.then()
77-
.subscribe(
78-
null,
79-
t -> onClose.tryEmitError(t),
80-
() -> {
81-
final Throwable cause = e.getCause();
82-
if (cause == null) {
83-
onClose.tryEmitEmpty();
84-
} else {
85-
onClose.tryEmitError(cause);
86-
}
87-
});
82+
.subscribe(connection.disposeSubscriber());
83+
sender.onComplete();
8884
}
8985

9086
@Override

rsocket-transport-netty/src/main/java/io/rsocket/transport/netty/WebsocketDuplexConnection.java

+8-12
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.net.SocketAddress;
2626
import java.util.Objects;
2727
import reactor.core.publisher.Flux;
28+
import reactor.core.publisher.Mono;
2829
import reactor.netty.Connection;
2930

3031
/**
@@ -72,6 +73,11 @@ protected void doOnClose() {
7273
connection.dispose();
7374
}
7475

76+
@Override
77+
public Mono<Void> onClose() {
78+
return super.onClose().and(connection.onDispose());
79+
}
80+
7581
@Override
7682
public Flux<ByteBuf> receive() {
7783
return connection.inbound().receive();
@@ -83,17 +89,7 @@ public void sendErrorAndClose(RSocketErrorException e) {
8389
connection
8490
.outbound()
8591
.sendObject(new BinaryWebSocketFrame(errorFrame))
86-
.then()
87-
.subscribe(
88-
null,
89-
t -> onClose.tryEmitError(t),
90-
() -> {
91-
final Throwable cause = e.getCause();
92-
if (cause == null) {
93-
onClose.tryEmitEmpty();
94-
} else {
95-
onClose.tryEmitError(cause);
96-
}
97-
});
92+
.subscribe(connection.disposeSubscriber());
93+
sender.onComplete();
9894
}
9995
}

0 commit comments

Comments
 (0)