Skip to content

Commit c05eb42

Browse files
authored
RSocketFactory wrapping constructors (#788)
Allow RSocketFactory to be created with a pre-created instance of RSocketConnector or RSocketServer. This helps higher level frameworks to support both old and current APIs. Signed-off-by: Rossen Stoyanchev <rstoyanchev@pivotal.io>
1 parent cf3bf11 commit c05eb42

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

rsocket-core/src/main/java/io/rsocket/RSocketFactory.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,22 @@ default <T extends Closeable> Start<T> transport(ServerTransport<T> transport) {
9797

9898
/** Factory to create and configure an RSocket client, and connect to a server. */
9999
public static class ClientRSocketFactory implements ClientTransportAcceptor {
100-
private final RSocketConnector connector = RSocketConnector.create();
100+
private final RSocketConnector connector;
101101

102102
private Duration tickPeriod = Duration.ofSeconds(20);
103103
private Duration ackTimeout = Duration.ofSeconds(30);
104104
private int missedAcks = 3;
105105

106106
private Resume resume;
107107

108+
public ClientRSocketFactory() {
109+
this(RSocketConnector.create());
110+
}
111+
112+
public ClientRSocketFactory(RSocketConnector connector) {
113+
this.connector = connector;
114+
}
115+
108116
public ClientRSocketFactory byteBufAllocator(ByteBufAllocator allocator) {
109117
connector.byteBufAllocator(allocator);
110118
return this;
@@ -375,10 +383,18 @@ public ClientRSocketFactory frameDecoder(PayloadDecoder payloadDecoder) {
375383

376384
/** Factory to create, configure, and start an RSocket server. */
377385
public static class ServerRSocketFactory implements ServerTransportAcceptor {
378-
private final RSocketServer server = RSocketServer.create();
386+
private final RSocketServer server;
379387

380388
private Resume resume;
381389

390+
public ServerRSocketFactory() {
391+
this(RSocketServer.create());
392+
}
393+
394+
public ServerRSocketFactory(RSocketServer server) {
395+
this.server = server;
396+
}
397+
382398
public ServerRSocketFactory byteBufAllocator(ByteBufAllocator allocator) {
383399
server.byteBufAllocator(allocator);
384400
return this;

0 commit comments

Comments
 (0)