Class HookAdapters
- java.lang.Object
-
- pl.gsmservice.gateway.utils.HookAdapters
-
public final class HookAdapters extends java.lang.ObjectUtility class for adapting synchronous hooks to asynchronous hooks.This class provides adapter methods that convert synchronous hook implementations (
Hook.BeforeRequest,Hook.AfterSuccess,Hook.AfterError) to their asynchronous counterparts (AsyncHook.BeforeRequest,AsyncHook.AfterSuccess,AsyncHook.AfterError).Performance Note: The execution of synchronous hooks is offloaded to the global
ForkJoinPool. For better performance in high-throughput scenarios, consider re-implementing hooks using non-blocking I/O (NIO) patterns instead of relying on these adapters.Thread Safety: All adapter methods are thread-safe and can be called concurrently from multiple threads.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static AsyncHook.AfterErrortoAsync(Hook.AfterError afterErrorHook)Adapts a synchronousHook.AfterErrorto an asynchronousAsyncHook.AfterError.static AsyncHook.AfterSuccesstoAsync(Hook.AfterSuccess afterSuccessHook)Adapts a synchronousHook.AfterSuccessto an asynchronousAsyncHook.AfterSuccess.static AsyncHook.BeforeRequesttoAsync(Hook.BeforeRequest beforeRequestHook)Adapts a synchronousHook.BeforeRequestto an asynchronousAsyncHook.BeforeRequest.
-
-
-
Method Detail
-
toAsync
public static AsyncHook.BeforeRequest toAsync(Hook.BeforeRequest beforeRequestHook)
Adapts a synchronousHook.BeforeRequestto an asynchronousAsyncHook.BeforeRequest.The synchronous hook execution is offloaded to the global
ForkJoinPool. Any exceptions thrown by the synchronous hook are wrapped as unchecked exceptions and propagated through the returnedCompletableFuture.Performance Consideration: For high-throughput applications, consider implementing the hook directly using NIO patterns rather than using this adapter, as it avoids thread pool overhead and blocking operations.
- Parameters:
beforeRequestHook- the synchronous before-request hook to adapt- Returns:
- an asynchronous before-request hook that executes the synchronous hook in the global ForkJoinPool
- Throws:
java.lang.NullPointerException- ifbeforeRequestHookisnull
-
toAsync
public static AsyncHook.AfterError toAsync(Hook.AfterError afterErrorHook)
Adapts a synchronousHook.AfterErrorto an asynchronousAsyncHook.AfterError.This method handles the conversion between different response body types:
- Converts
HttpResponse<Blob> toHttpResponse<InputStream> for the synchronous hook - Converts the result back to
HttpResponse<Blob> for the asynchronous interface
The synchronous hook execution is offloaded to the global
ForkJoinPool. Any exceptions thrown by the synchronous hook are wrapped as unchecked exceptions and propagated through the returnedCompletableFuture.Performance Consideration: For high-throughput applications, consider implementing the hook directly using NIO patterns rather than using this adapter, as it avoids thread pool overhead and blocking I/O operations.
- Parameters:
afterErrorHook- the synchronous after-error hook to adapt- Returns:
- an asynchronous after-error hook that executes the synchronous hook in the global ForkJoinPool
- Throws:
java.lang.NullPointerException- ifafterErrorHookisnull
- Converts
-
toAsync
public static AsyncHook.AfterSuccess toAsync(Hook.AfterSuccess afterSuccessHook)
Adapts a synchronousHook.AfterSuccessto an asynchronousAsyncHook.AfterSuccess.This method handles the conversion between different response body types:
- Converts
HttpResponse<Blob> toHttpResponse<InputStream> for the synchronous hook - Converts the result back to
HttpResponse<Blob> for the asynchronous interface
The synchronous hook execution is offloaded to the global
ForkJoinPool. Any exceptions thrown by the synchronous hook are wrapped as unchecked exceptions and propagated through the returnedCompletableFuture.Performance Consideration: For high-throughput applications, consider implementing the hook directly using NIO patterns rather than using this adapter, as it avoids thread pool overhead and blocking I/O operations.
- Parameters:
afterSuccessHook- the synchronous after-success hook to adapt- Returns:
- an asynchronous after-success hook that executes the synchronous hook in the global ForkJoinPool
- Throws:
java.lang.NullPointerException- ifafterSuccessHookisnull
- Converts
-
-