Core I/O components for Eclipse Jetty providing essential I/O utilities, buffer management, and network connection handling
npx @tessl/cli install tessl/maven-org-eclipse-jetty--jetty-io@12.0.0Eclipse Jetty IO is a high-performance, asynchronous I/O library that provides the foundational networking components for the Eclipse Jetty web server and HTTP client. It offers non-blocking I/O abstractions, buffer pooling, content streaming, and SSL/TLS support designed for scalable network applications.
<dependency><groupId>org.eclipse.jetty</groupId><artifactId>jetty-io</artifactId><version>12.0.21</version></dependency>org.eclipse.jetty.ioimport org.eclipse.jetty.io.*;
import org.eclipse.jetty.io.content.*;
import org.eclipse.jetty.io.ssl.*;import org.eclipse.jetty.io.*;
import org.eclipse.jetty.io.content.*;
import org.eclipse.jetty.util.Callback;
import java.nio.ByteBuffer;
// Buffer pooling
ByteBufferPool pool = new ArrayByteBufferPool();
RetainableByteBuffer buffer = pool.acquire(1024, false);
try {
ByteBuffer bb = buffer.getByteBuffer();
// Use buffer for I/O operations
} finally {
buffer.release();
}
// Content handling
Content.Source source = Content.Source.from("Hello World");
Content.Chunk chunk = source.read();
if (chunk != null) {
ByteBuffer data = chunk.getByteBuffer();
// Process data
}
// Async content copying
Content.Source source = Content.Source.from(inputStream);
Content.Sink sink = Content.Sink.asBuffered(outputSink);
Content.copy(source, sink, Callback.NOOP);Jetty IO is built around several key architectural patterns:
Essential interfaces and abstract base classes that define the I/O model, including non-blocking endpoints, connections, and lifecycle management.
interface EndPoint extends Closeable {
int fill(ByteBuffer buffer) throws IOException;
boolean flush(ByteBuffer... buffers) throws IOException;
void fillInterested(Callback callback) throws ReadPendingException;
void write(Callback callback, ByteBuffer... buffers) throws WritePendingException;
Connection getConnection();
void setConnection(Connection connection);
}
interface Connection extends Closeable {
void onOpen();
void onClose(Throwable cause);
EndPoint getEndPoint();
boolean onIdleExpired(TimeoutException timeoutException);
}High-performance buffer pooling and reference-counted buffer management for memory efficiency in high-throughput applications.
interface ByteBufferPool {
RetainableByteBuffer acquire(int size, boolean direct);
void clear();
}
interface RetainableByteBuffer extends Retainable {
ByteBuffer getByteBuffer();
boolean isDirect();
int capacity();
void clear();
}
interface Retainable {
void retain();
boolean release();
boolean canRetain();
}Demand-driven content processing system with support for backpressure, async operations, and integration with reactive streams.
class Content {
interface Source {
Chunk read();
void demand(Runnable demandCallback);
void fail(Throwable failure);
long getLength();
static Source from(ByteBuffer... buffers);
static Source from(Path path);
static Source from(InputStream inputStream);
}
interface Sink {
void write(boolean last, ByteBuffer byteBuffer, Callback callback);
static Sink asBuffered(Sink sink);
static OutputStream asOutputStream(Sink sink);
}
interface Chunk {
ByteBuffer getByteBuffer();
boolean isLast();
boolean hasRemaining();
Throwable getFailure();
}
}Client connection factories, transport abstractions, and connection lifecycle management for establishing and managing network connections.
interface ClientConnectionFactory {
Connection newConnection(EndPoint endPoint, Map<String, Object> context) throws IOException;
}
interface Transport {
boolean isIntrinsicallySecure();
void connect(SocketAddress socketAddress, Map<String, Object> context);
Connection newConnection(EndPoint endPoint, Map<String, Object> context) throws IOException;
}Secure connection implementations with SSL/TLS encryption, handshake management, and ALPN (Application Layer Protocol Negotiation) support.
class SslConnection extends AbstractConnection implements Connection.UpgradeTo {
// SSL connection wrapper
}
interface SslHandshakeListener extends EventListener {
default void handshakeSucceeded(Event event) {}
default void handshakeFailed(Event event, Throwable failure) {}
}
interface ALPNProcessor {
void process(SSLEngine sslEngine, List<String> protocols, String selected);
}Non-blocking I/O management using Java NIO selectors for handling multiple connections efficiently in a single-threaded or thread-pool model.
abstract class SelectorManager extends ContainerLifeCycle {
protected abstract EndPoint newEndPoint(SelectableChannel channel, ManagedSelector selector, SelectionKey key);
protected abstract Connection newConnection(EndPoint endPoint, Object attachment);
}
class ManagedSelector extends AbstractLifeCycle implements Dumpable {
// Single-threaded NIO selector management
}// Exception types
class EofException extends EOFException implements QuietException {
EofException();
EofException(String reason);
EofException(Throwable cause);
}
interface QuietException {
static boolean isQuiet(Throwable throwable);
}
class RuntimeIOException extends RuntimeException {
RuntimeIOException(IOException cause);
}
// Timeout management
interface IdleTimeout {
long getIdleTimeout();
void setIdleTimeout(long idleTimeout);
boolean isIdleTimeoutExpired();
void onIdleExpired(TimeoutException timeout);
}
// Statistics and monitoring
class ConnectionStatistics extends AbstractLifeCycle implements Connection.Listener {
long getConnectionsTotal();
long getConnectionsOpened();
long getConnectionsClosed();
long getMessagesIn();
long getMessagesOut();
long getBytesIn();
long getBytesOut();
}