or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

functional-interfaces.mdindex.mdresource-management.mdtype-system.mdutility-classes.md
tile.json

tessl/maven-org-elasticsearch--elasticsearch-core

Core utilities and common classes for Elasticsearch, providing fundamental building blocks like resource management, IO utilities, time handling, and reference counting.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.elasticsearch/elasticsearch-core@9.0.x

To install, run

npx @tessl/cli install tessl/maven-org-elasticsearch--elasticsearch-core@9.0.0

index.mddocs/

Elasticsearch Core

Elasticsearch Core is a foundational Java library providing essential utilities and infrastructure components for the Elasticsearch ecosystem. It offers core building blocks for resource management, I/O operations, time handling, functional programming with checked exceptions, and common data structures. The library is designed to be lightweight and dependency-free, serving as the foundation that other Elasticsearch modules build upon.

Package Information

  • Package Name: org.elasticsearch:elasticsearch-core
  • Package Type: Maven/Gradle
  • Language: Java
  • Installation: implementation 'org.elasticsearch:elasticsearch-core:9.0.3'

Core Imports

import org.elasticsearch.core.*;

Individual imports:

import org.elasticsearch.core.RefCounted;
import org.elasticsearch.core.Releasable;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.core.IOUtils;
import org.elasticsearch.core.CheckedFunction;
import org.elasticsearch.core.Tuple;

Basic Usage

import org.elasticsearch.core.*;
import java.util.concurrent.TimeUnit;

public class Example {
    public void resourceManagement() {
        // Resource management with RefCounted
        RefCounted resource = AbstractRefCounted.of(() -> {
            System.out.println("Resource closed");
        });
        
        resource.incRef(); // Increment reference count
        resource.decRef(); // Decrement reference count (closes when reaches 0)
    }
    
    public void timeOperations() {
        // Time value handling
        TimeValue duration = TimeValue.timeValueSeconds(30);
        TimeValue timeout = new TimeValue(5, TimeUnit.MINUTES);
        
        System.out.println("Duration: " + duration.toString());
        System.out.println("Timeout: " + timeout.toHumanReadableString(2));
    }
    
    public void functionalOperations() throws Exception {
        // Checked functional interfaces
        CheckedFunction<String, Integer, NumberFormatException> parser = 
            Integer::parseInt;
        
        Integer result = parser.apply("42");
        
        CheckedConsumer<String, Exception> printer = System.out::println;
        printer.accept("Hello World");
    }
}

Architecture

Elasticsearch Core is organized around several key design patterns:

  • Resource Management: Consistent lifecycle management through RefCounted and Releasable interfaces
  • Functional Programming: Checked exception variants of standard functional interfaces for safer error handling
  • Utility Pattern: Static utility classes providing common operations without instantiation
  • Type Safety: Strong typing with generic support for compile-time validation
  • Annotation-Driven: Metadata annotations for code analysis and IDE integration

Capabilities

Resource Management

Provides lifecycle management patterns for resources that need explicit cleanup, including reference counting and releasable interfaces.

public interface RefCounted {
    void incRef();
    boolean tryIncRef();
    boolean decRef();
    boolean hasReferences();
    default void mustIncRef();
}

public interface Releasable extends Closeable {
    void close();
}

public abstract class AbstractRefCounted implements RefCounted {
    protected AbstractRefCounted();
    protected abstract void closeInternal();
    public static AbstractRefCounted of(Runnable onClose);
}

Resource Management

Functional Interfaces

Checked exception variants of standard Java functional interfaces, enabling functional programming patterns with proper exception handling.

@FunctionalInterface
public interface CheckedFunction<T, R, E extends Exception> {
    R apply(T t) throws E;
}

@FunctionalInterface
public interface CheckedConsumer<T, E extends Exception> {
    void accept(T t) throws E;
    default CheckedConsumer<T, E> andThen(CheckedConsumer<? super T, E> after);
}

@FunctionalInterface
public interface CheckedSupplier<T, E extends Exception> {
    T get() throws E;
}

@FunctionalInterface
public interface CheckedRunnable<E extends Exception> {
    void run() throws E;
}

Functional Interfaces

Utility Classes

Core utility classes for common operations including I/O, time handling, string processing, and data manipulation.

public final class IOUtils {
    public static void close(Closeable... objects);
    public static void close(@Nullable Closeable closeable);
    public static void closeWhileHandlingException(Closeable... objects);
    public static void fsync(Path fileToSync, boolean isDir);
}

public class TimeValue implements Comparable<TimeValue> {
    public TimeValue(long millis);
    public TimeValue(long duration, TimeUnit timeUnit);
    public static TimeValue timeValueSeconds(long seconds);
    public static TimeValue parseTimeValue(String sValue, String settingName);
}

public record Tuple<V1, V2>(V1 v1, V2 v2) {
    public static <V1, V2> Tuple<V1, V2> tuple(V1 v1, V2 v2);
}

Utility Classes

Type System

Annotations, enums, and type utilities that provide metadata and type manipulation capabilities for the Elasticsearch ecosystem.

@Retention(RetentionPolicy.CLASS)
@Target({ElementType.PARAMETER, ElementType.FIELD, ElementType.METHOD})
public @interface Nullable {
}

@Retention(RetentionPolicy.CLASS) 
@Target({ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD, ElementType.TYPE})
public @interface SuppressForbidden {
    String reason();
}

public enum RestApiVersion {
    V_9(9), V_8(8);
    
    public static RestApiVersion current();
    public static RestApiVersion forMajor(int major);
    public boolean matches(Predicate<RestApiVersion> predicate);
}

Type System