CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-eclipse-jetty--jetty-util

Comprehensive Java utility library providing infrastructure and helper classes for the Eclipse Jetty web server

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

index.mddocs/

Eclipse Jetty Utilities

Eclipse Jetty Utilities is a comprehensive Java utility library that provides essential infrastructure and helper classes for the Eclipse Jetty web server. It offers a wide range of functionality including thread management, data structures, I/O utilities, security components, resource management, and networking utilities designed for high-performance, low-latency web applications.

Package Information

  • Package Name: jetty-util
  • Package Type: maven
  • Language: Java
  • Group ID: org.eclipse.jetty
  • Artifact ID: jetty-util
  • Installation: Add to your Maven dependencies:
<dependency>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-util</artifactId>
    <version>12.0.21</version>
</dependency>

Core Imports

// Core utilities
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.Promise;

// Component lifecycle
import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.util.component.ContainerLifeCycle;

// Threading
import org.eclipse.jetty.util.thread.ThreadPool;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.util.thread.Scheduler;

// Data structures
import org.eclipse.jetty.util.Fields;
import org.eclipse.jetty.util.MultiMap;
import org.eclipse.jetty.util.Pool;
import org.eclipse.jetty.util.ConcurrentPool;

// Resources
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.resource.ResourceFactory;
import org.eclipse.jetty.util.resource.PathResourceFactory;

Basic Usage

Simple Buffer Operations

import org.eclipse.jetty.util.BufferUtil;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;

// Create and manipulate ByteBuffers
ByteBuffer buffer = BufferUtil.allocate(1024);
BufferUtil.append(buffer, "Hello World".getBytes(StandardCharsets.UTF_8));
String content = BufferUtil.toString(buffer, StandardCharsets.UTF_8);

Lifecycle Management

import org.eclipse.jetty.util.component.AbstractLifeCycle;

public class MyComponent extends AbstractLifeCycle {
    @Override
    protected void doStart() throws Exception {
        // Component startup logic
        super.doStart();
    }
    
    @Override
    protected void doStop() throws Exception {
        // Component shutdown logic
        super.doStop();
    }
}

// Usage
MyComponent component = new MyComponent();
component.start();
// ... use component
component.stop();

Thread Pool Usage

import org.eclipse.jetty.util.thread.QueuedThreadPool;

// Create and configure a thread pool
QueuedThreadPool threadPool = new QueuedThreadPool();
threadPool.setMinThreads(5);
threadPool.setMaxThreads(50);
threadPool.start();

// Submit tasks
threadPool.execute(() -> {
    // Task implementation
    System.out.println("Task executing in: " + Thread.currentThread().getName());
});

threadPool.stop();

Asynchronous Operations

import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.FutureCallback;
import org.eclipse.jetty.util.FuturePromise;

// Using callbacks for async operations
public void performAsyncOperation(Callback callback) {
    // Simulate async work
    new Thread(() -> {
        try {
            Thread.sleep(1000);
            callback.succeeded();
        } catch (Exception e) {
            callback.failed(e);
        }
    }).start();
}

// Usage with Future-based callback
FutureCallback callback = new FutureCallback();
performAsyncOperation(callback);
try {
    callback.get(); // Wait for completion
    System.out.println("Operation completed successfully");
} catch (Exception e) {
    System.out.println("Operation failed: " + e.getMessage());
}

Architecture

Eclipse Jetty Utilities is built around several key architectural components:

  • Lifecycle Management: Comprehensive component lifecycle with LifeCycle interface for consistent start/stop semantics
  • Asynchronous Patterns: Rich callback and promise APIs for non-blocking operations with Callback and Promise interfaces
  • Resource Abstraction: Unified resource API supporting files, memory, JARs, and URLs through the Resource interface
  • Thread Management: Sophisticated threading utilities with pluggable execution strategies and virtual thread support
  • Object Pooling: Generic pooling infrastructure for resource reuse with the Pool interface
  • Diagnostics: Consistent diagnostic capabilities through the Dumpable interface for runtime introspection
  • Security Integration: Comprehensive SSL/TLS support and credential management
  • Statistics Collection: Built-in metrics and monitoring capabilities

Capabilities

Core Utilities

Essential utility classes for common operations including buffer manipulation, string processing, URI handling, and I/O operations.

public class BufferUtil {
    public static ByteBuffer allocate(int capacity);
    public static String toString(ByteBuffer buffer, Charset charset);
    public static byte[] toArray(ByteBuffer buffer);
    public static void writeTo(ByteBuffer buffer, OutputStream out) throws IOException;
}

public class StringUtil {
    public static boolean isBlank(String str);
    public static boolean isEmpty(String str);
    public static String[] split(String str, char delimiter);
    public static List<String> csvSplit(String str);
}

Core Utilities

Data Structures

Specialized data structures for high-performance web applications including multi-maps, tries, pools, and concurrent collections.

public class Fields implements Iterable<Fields.Field> {
    public void add(String name, String value);
    public String get(String name);
    public List<String> getValues(String name);
    public boolean remove(String name);
}

public interface Pool<P> {
    Pool.Entry<P> acquire();
    boolean release(Pool.Entry<P> entry);
    int getMaxEntries();
    int size();
}

Data Structures

Asynchronous Operations

Comprehensive callback and promise APIs for building non-blocking, asynchronous applications with various callback implementations.

public interface Callback {
    void succeeded();
    void failed(Throwable x);
    
    static Callback from(Runnable success, Consumer<Throwable> failure);
}

public interface Promise<C> extends Callback {
    void succeeded(C result);
}

public class FuturePromise<C> implements Future<C>, Promise<C> {
    public FuturePromise();
    public C get() throws InterruptedException, ExecutionException;
    public C get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException;
}

Asynchronous Operations

Component Lifecycle

Robust component lifecycle management with container support, event notifications, and graceful shutdown capabilities.

public interface LifeCycle {
    void start() throws Exception;
    void stop() throws Exception;
    boolean isRunning();
    boolean isStarted();
    boolean isStopped();
    boolean isFailed();
    
    void addLifeCycleListener(LifeCycle.Listener listener);
    void removeLifeCycleListener(LifeCycle.Listener listener);
}

Component Lifecycle

Threading

Advanced threading utilities including thread pools, schedulers, execution strategies, and concurrency primitives optimized for server applications.

public interface ThreadPool extends Executor, LifeCycle {
    void join() throws InterruptedException;
    int getThreads();
    int getIdleThreads();
    boolean isLowOnThreads();
}

public interface Scheduler extends LifeCycle {
    Scheduler.Task schedule(Runnable task, long delay, TimeUnit unit);
    Scheduler.Task scheduleWithFixedDelay(Runnable task, long initialDelay, long delay, TimeUnit unit);
}

Threading

Resource Management

Unified resource management API supporting various resource types with automatic cleanup and efficient access patterns.

public interface Resource {
    boolean exists();
    boolean isDirectory();
    boolean isFile();
    Resource resolve(String subUriPath);
    InputStream newInputStream() throws IOException;
    Path getPath();
}

public interface ResourceFactory {
    Resource newResource(String uriOrPath);
    Resource newResource(Path path);
    Resource newResource(URI uri);
}

Resource Management

Security

Comprehensive security utilities including SSL/TLS context management, credential providers, and certificate utilities.

public abstract class SslContextFactory extends AbstractLifeCycle {
    public abstract SSLEngine newSSLEngine();
    public abstract SSLEngine newSSLEngine(String host, int port);
    public abstract void customize(SSLEngine sslEngine);
}

public interface CredentialProvider {
    Credential getCredential(String credential);
}

Security

Statistics

Built-in statistics collection and monitoring capabilities for performance tracking and system diagnostics.

public class CounterStatistic {
    public void increment();
    public void decrement();
    public void add(long value);
    public long getCurrent();
    public long getMax();
    public void reset();
}

Statistics

Types

// Lifecycle states
enum LifeCycle.State {
    STOPPED, STARTING, STARTED, STOPPING, FAILED
}

// Invocation types for threading
enum Invocable.InvocationType {
    BLOCKING, NON_BLOCKING, EITHER
}

// Pool entry interface
interface Pool.Entry<P> {
    P getPooled();
    boolean release();
    boolean remove();
}

// Callback exception handling
class CallbackWrapper implements Callback {
    public CallbackWrapper(Callback callback);
    // Wraps another callback with additional functionality
}

docs

async-operations.md

component-lifecycle.md

core-utilities.md

data-structures.md

index.md

resource-management.md

security.md

statistics.md

threading.md

tile.json