Package io.bytestreams.exchange.core
Class Acceptor
java.lang.Object
io.bytestreams.exchange.core.Acceptor
Accepts transports from a
TransportFactory and creates channels for each.
A virtual thread runs the accept loop, calling TransportFactory.create() repeatedly.
Each returned transport is passed to the channel factory, which creates and starts a channel.
Accepted channels are tracked and automatically closed when the acceptor shuts down.
Error strategy: if the channel factory throws, the accepted transport is closed, the error is logged (via span event), and the accept loop continues.
Example with TCP sockets:
ServerSocketTransportFactory transportFactory =
ServerSocketTransportFactory.builder(8080).build();
Acceptor acceptor = Acceptor.builder(transportFactory)
.channelFactory(transport -> ServerChannel.builder()
.transport(transport)
.requestReader(reader)
.responseWriter(writer)
.requestHandler(handler)
.build())
.build();
acceptor.start();
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic Acceptor.Builderbuilder(TransportFactory transportFactory) close()Closes the acceptor, the transport factory (ifCloseable), and all tracked channels.voidstart()Starts the accept loop on a virtual thread.
-
Method Details
-
builder
-
start
public void start()Starts the accept loop on a virtual thread. -
close
Closes the acceptor, the transport factory (ifCloseable), and all tracked channels.- Returns:
- a future that completes when all channels are closed
-
closeFuture
-