Record Class ResourceLimits

java.lang.Object
java.lang.Record
com.tnsai.quality.sandbox.ResourceLimits
Record Components:
cpuShares - fractional CPU shares (1.0 = one full core, 0.5 = half a core). Must be > 0.
memoryMb - RAM cap in mebibytes. Must be > 0.
diskMb - writable scratch-disk cap in mebibytes. 0 means "no scratch space" (sandbox is read-only).
timeout - wall-clock cap on a single Sandbox.execute(com.tnsai.quality.sandbox.Command) call. Must be positive.
maxProcesses - maximum concurrent processes the sandbox may spawn. 0 = no limit.
maxOutputBytes - combined stdout+stderr capture cap on the host heap. Must be > 0. Exceeding it kills the process and marks the result truncated.

public record ResourceLimits(double cpuShares, long memoryMb, long diskMb, Duration timeout, int maxProcesses, long maxOutputBytes) extends Record
Per-sandbox resource caps (TNS-296). Enforced by the backend at sandbox creation: backends that can't honour a cap reject the spec at SandboxFactory.create(com.tnsai.quality.sandbox.SandboxSpec) time rather than silently relaxing it.
Since:
0.10.0 (TNS-296)
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
    Host-heap capture default when the 5-arg constructor is used.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ResourceLimits(double cpuShares, long memoryMb, long diskMb, Duration timeout, int maxProcesses)
    Source-compatible 5-arg constructor.
    ResourceLimits(double cpuShares, long memoryMb, long diskMb, Duration timeout, int maxProcesses, long maxOutputBytes)
    Creates an instance of a ResourceLimits record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Returns the value of the cpuShares record component.
    long
    Returns the value of the diskMb record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    long
    Returns the value of the maxOutputBytes record component.
    int
    Returns the value of the maxProcesses record component.
    long
    Returns the value of the memoryMb record component.
    Tight budget for short, low-cost executions (e.g. policy checks, regex evaluation).
    of(double cpuShares, long memoryMb, long timeoutSec)
    Convenience for the common (cpu, mem, timeoutSec) shape.
    Default budget for typical code-exec (Python/Node REPL, formatter, single-file runner).
    Returns the value of the timeout record component.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • DEFAULT_MAX_OUTPUT_BYTES

      public static final long DEFAULT_MAX_OUTPUT_BYTES
      Host-heap capture default when the 5-arg constructor is used.
      See Also:
  • Constructor Details

    • ResourceLimits

      public ResourceLimits(double cpuShares, long memoryMb, long diskMb, Duration timeout, int maxProcesses, long maxOutputBytes)
      Creates an instance of a ResourceLimits record class.
      Parameters:
      cpuShares - the value for the cpuShares record component
      memoryMb - the value for the memoryMb record component
      diskMb - the value for the diskMb record component
      timeout - the value for the timeout record component
      maxProcesses - the value for the maxProcesses record component
      maxOutputBytes - the value for the maxOutputBytes record component
    • ResourceLimits

      public ResourceLimits(double cpuShares, long memoryMb, long diskMb, Duration timeout, int maxProcesses)
      Source-compatible 5-arg constructor. Uses DEFAULT_MAX_OUTPUT_BYTES for the host-heap capture cap.
  • Method Details

    • of

      public static ResourceLimits of(double cpuShares, long memoryMb, long timeoutSec)
      Convenience for the common (cpu, mem, timeoutSec) shape.
    • minimal

      public static ResourceLimits minimal()
      Tight budget for short, low-cost executions (e.g. policy checks, regex evaluation).
    • standard

      public static ResourceLimits standard()
      Default budget for typical code-exec (Python/Node REPL, formatter, single-file runner).
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • cpuShares

      public double cpuShares()
      Returns the value of the cpuShares record component.
      Returns:
      the value of the cpuShares record component
    • memoryMb

      public long memoryMb()
      Returns the value of the memoryMb record component.
      Returns:
      the value of the memoryMb record component
    • diskMb

      public long diskMb()
      Returns the value of the diskMb record component.
      Returns:
      the value of the diskMb record component
    • timeout

      public Duration timeout()
      Returns the value of the timeout record component.
      Returns:
      the value of the timeout record component
    • maxProcesses

      public int maxProcesses()
      Returns the value of the maxProcesses record component.
      Returns:
      the value of the maxProcesses record component
    • maxOutputBytes

      public long maxOutputBytes()
      Returns the value of the maxOutputBytes record component.
      Returns:
      the value of the maxOutputBytes record component