Class ServletAsyncSpec


  • @Immutable
    public class ServletAsyncSpec
    extends Object
    This class encapsulates all the parameters necessary to handle asynchronous servlet requests.
    Since:
    8.8.0
    Author:
    Philip Helger
    • Field Detail

      • NO_TIMEOUT

        public static final long NO_TIMEOUT
        The constant defining "no timeout defined"
        See Also:
        Constant Field Values
      • SYNC_SPEC

        public static final ServletAsyncSpec SYNC_SPEC
        The constant for synchronous invocations
    • Constructor Detail

      • ServletAsyncSpec

        protected ServletAsyncSpec​(boolean bAsynchronous,
                                   @CheckForSigned
                                   long nTimeoutMillis,
                                   @Nullable
                                   Iterable<? extends jakarta.servlet.AsyncListener> aAsyncListeners)
        Constructor
        Parameters:
        bAsynchronous - true for asynchronous stuff, false for synchronous spec.
        nTimeoutMillis - The timeout in milliseconds. Must be ≤ 0 for synchronous usage.
        aAsyncListeners - AsyncListeners to be added to the AsyncContext. Must be null for synchronous usage.
    • Method Detail

      • getTimeoutMillis

        @CheckForSigned
        public long getTimeoutMillis()
        Returns:
        The timeout in milliseconds. Only value > 0 are defined. Values ≤ 0 must be ignored.
      • hasTimeoutMillis

        public boolean hasTimeoutMillis()
        Returns:
        true if a timeout is defined, false otherwise. Only asynchronous definitions can have timeouts.
      • isAsynchronous

        public boolean isAsynchronous()
        Returns:
        true for asynchronous, false for synchronous.
      • getAllAsyncListeners

        @Nonnull
        @ReturnsMutableCopy
        public com.helger.commons.collection.impl.ICommonsList<jakarta.servlet.AsyncListener> getAllAsyncListeners()
        Returns:
        A copy of the list of all AsyncListener. Only contains items if this is an asynchronous spec.
      • hasAsyncListeners

        public boolean hasAsyncListeners()
        Returns:
        true if any async listener is present, false otherwise.
      • applyToAsyncContext

        public void applyToAsyncContext​(@Nonnull
                                        jakarta.servlet.AsyncContext aAsyncCtx)
      • createAsync

        @Nonnull
        public static ServletAsyncSpec createAsync​(@CheckForSigned
                                                   long nTimeoutMillis,
                                                   @Nullable
                                                   Iterable<? extends jakarta.servlet.AsyncListener> aAsyncListeners)
        Create an async spec.
        Parameters:
        nTimeoutMillis - Timeout in milliseconds. Only value > 0 are considered.
        aAsyncListeners - The async listeners to use. May be null.
        Returns:
        A new ServletAsyncSpec and never null.
      • createAsyncDefault

        @Nonnull
        public static ServletAsyncSpec createAsyncDefault()
        Create an async spec with 999999 (debug mode) or 30 (production) seconds timeout and no async listeners.
        Returns:
        A new ServletAsyncSpec and never null.