Class AsyncRegistry


  • public final class AsyncRegistry
    extends java.lang.Object
    Async registry for correlating native callbacks with Java CompletableFutures.

    Responsibilities:

    • Maintain a thread-safe mapping from correlation id to the original future
    • Enforce per-client max inflight requests in Java (0 = defer to core default)
    • Perform atomic cleanup on completion to avoid races and leaks
    • Provide batched completion helpers to reduce native call overhead

    Timeouts, backpressure defaults, and concurrency tuning are handled by the Rust core.

    • Constructor Summary

      Constructors 
      Constructor Description
      AsyncRegistry()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void cleanupClient​(long clientHandle)
      Clean up per-client tracking when a client is closed
      static boolean completeCallback​(long correlationId, java.lang.Object result)
      Complete callback with proper race condition handling.
      static boolean completeCallbackWithErrorCode​(long correlationId, int errorTypeCode, java.lang.String errorMessage)
      Complete with error using a structured error code from native layer.
      static int getPendingCount()
      Get current pending operation count
      static <T> long register​(java.util.concurrent.CompletableFuture<T> future, int maxInflightRequests, long clientHandle)
      Register future with client-specific inflight limit and client handle for per-client tracking
      static void removeShutdownHook()
      Remove the automatic shutdown hook, allowing users to manage shutdown manually.
      static void reset()
      Reset all internal state.
      static void shutdown()
      Shutdown cleanup - cancel all pending operations during client shutdown
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AsyncRegistry

        public AsyncRegistry()
    • Method Detail

      • register

        public static <T> long register​(java.util.concurrent.CompletableFuture<T> future,
                                        int maxInflightRequests,
                                        long clientHandle)
        Register future with client-specific inflight limit and client handle for per-client tracking
      • completeCallback

        public static boolean completeCallback​(long correlationId,
                                               java.lang.Object result)
        Complete callback with proper race condition handling. Supports both regular Java objects and DirectByteBuffer for large responses (>16KB).
      • completeCallbackWithErrorCode

        public static boolean completeCallbackWithErrorCode​(long correlationId,
                                                            int errorTypeCode,
                                                            java.lang.String errorMessage)
        Complete with error using a structured error code from native layer. Codes map to glide-core RequestErrorType: 0-Unspecified, 1-ExecAbort, 2-Timeout, 3-Disconnect.
      • getPendingCount

        public static int getPendingCount()
        Get current pending operation count
      • shutdown

        public static void shutdown()
        Shutdown cleanup - cancel all pending operations during client shutdown
      • cleanupClient

        public static void cleanupClient​(long clientHandle)
        Clean up per-client tracking when a client is closed
      • reset

        public static void reset()
        Reset all internal state. Intended for test isolation and client shutdown cleanup.
      • removeShutdownHook

        public static void removeShutdownHook()
        Remove the automatic shutdown hook, allowing users to manage shutdown manually. Call this if you want to control shutdown behavior yourself.