Class TransportFactory
java.lang.Object
express.mvp.myra.transport.TransportFactory
Factory for creating transport instances and related components.
This factory abstracts the construction of transports, backends, and buffer pools, handling backend selection and fallback logic automatically.
Backend Selection
The factory attempts to create the requested backend type. If unavailable, it falls back gracefully:
- IO_URING: Preferred on Linux 5.1+. Falls back to NIO if liburing is not available.
- NIO: Always available as the baseline implementation.
- XDP/DPDK: Experimental, not yet implemented.
Usage Example
TransportConfig config = TransportConfig.builder()
.backendType(BackendType.IO_URING)
.registeredBuffers(RegisteredBuffersConfig.builder()
.numBuffers(256)
.bufferSize(65536)
.build())
.build();
InetSocketAddress remote = new InetSocketAddress("example.com", 8080);
try (Transport transport = TransportFactory.create(config, remote)) {
transport.start(handler);
// Use transport...
}
Thread Safety
This factory is thread-safe. Multiple threads can create transports concurrently.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic Transportcreate(TransportConfig config, SocketAddress remoteAddress) Creates a new transport with the given configuration.static TransportBackendcreateBackend(TransportConfig config) Creates an I/O backend based on the configuration.static RegisteredBufferPoolcreateBufferPool(TransportConfig config) Creates a registered buffer pool with the configured parameters.static ConnectionPoolcreatePool(TransportConfig config) Creates a connection pool for managing multiple connections.
-
Method Details
-
create
Creates a new transport with the given configuration.This method creates and initializes all required components:
- Creates a buffer pool with the configured size
- Creates the I/O backend (io_uring or NIO)
- Initializes the backend with configuration
- Registers the buffer pool with the backend
- Creates the TCP transport wrapper
- Parameters:
config- the transport configurationremoteAddress- the remote endpoint to connect to- Returns:
- a new transport instance ready for use
- Throws:
TransportException- if initialization failsIllegalArgumentException- if registered buffers are disabled in config
-
createPool
Creates a connection pool for managing multiple connections.- Parameters:
config- the transport configuration- Returns:
- a new connection pool instance
-
createBufferPool
Creates a registered buffer pool with the configured parameters.The buffer pool allocates off-heap memory and prepares it for registration with the I/O backend.
- Parameters:
config- the transport configuration containing buffer settings- Returns:
- a new buffer pool
- Throws:
IllegalArgumentException- if registered buffers are disabled
-
createBackend
Creates an I/O backend based on the configuration.This method handles backend selection with automatic fallback:
- IO_URING: Attempts to load io_uring backend. If liburing is not installed or linked, falls back to NIO with a warning.
- NIO: Uses standard Java NIO (always available).
- XDP/DPDK: Throws UnsupportedOperationException (not yet implemented).
- Parameters:
config- the transport configuration- Returns:
- a new backend instance (not yet initialized)
- Throws:
UnsupportedOperationException- if XDP or DPDK is requestedIllegalArgumentException- if backend type is unknown
-