Class Acceptor

java.lang.Object
io.bytestreams.exchange.core.Acceptor

public class Acceptor extends Object
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();
 
  • Method Details