Class SandboxLimits

java.lang.Object
org.codehaus.commons.compiler.sandbox.SandboxLimits

public final class SandboxLimits extends Object
The resource limits for one execution of sandboxed code by a SandboxExecutor. Whereas a SandboxPolicy determines what code may do, the limits determine how much of it.

A SandboxLimits object is immutable; use a SandboxLimits.Builder to create one:

    SandboxLimits limits = SandboxLimits.builder()
        .timeout(2, TimeUnit.SECONDS)
        .maxTicks(10_000_000)
        .maxAllocatedBytes(64L << 20)
        .build();

All limits are optional; a limit that is not set is not enforced.

  • Field Details

    • UNLIMITED

      public static final long UNLIMITED
      The value of a limit that is not set.
      See Also:
  • Method Details

    • isMemoryLimitSupported

      public static boolean isMemoryLimitSupported()
      Returns:
      Whether this JVM can measure the memory that a thread allocates; if not, then SandboxLimits.Builder.maxAllocatedBytes(long) is not enforced
    • builder

      public static SandboxLimits.Builder builder()
      Returns:
      A new builder for limits that initially limit nothing
    • getTimeoutNanos

      public long getTimeoutNanos()
      Returns:
      The timeout in nanoseconds, or UNLIMITED
    • getMaxTicks

      public long getMaxTicks()
      Returns:
      The maximum number of ticks, or UNLIMITED
      See Also:
    • getMaxAllocatedBytes

      public long getMaxAllocatedBytes()
      Returns:
      The maximum number of bytes that the executing thread may allocate, or UNLIMITED
    • toString

      public String toString()
      Overrides:
      toString in class Object