Record Class TimeLimitControl

java.lang.Object
java.lang.Record
org.dellroad.javabox.control.TimeLimitControl
Record Components:
timeLimit - the maximum execution time allowed
All Implemented Interfaces:
Control

public record TimeLimitControl(Duration timeLimit) extends Record implements Control
A JavaBox Control that limits the amount of time that a script snippet may execute.

This class works by adding time checks to method entry points and backward branches. Therefore, it only works when the executing thread is actually executing (i.e., not blocked).

  • Constructor Details

  • Method Details

    • modifyBytecode

      public byte[] modifyBytecode(ClassDesc name, byte[] bytes)
      Adds time limit checks to the bytecode.
      Specified by:
      modifyBytecode in interface Control
      Parameters:
      name - the name of the class being added
      bytes - the Java bytecode of the class being added
      Returns:
      replacement java bytecode; must not be null
    • startExecution

      public Long startExecution(Control.ContainerContext context)
      Description copied from interface: Control
      Notification that the execution of a script snippet has started.

      This method should initialize this control for the new execution and return any associated private context.

      This method should also perform any required per-execution initialization, for example, initializing resource counters, etc.

      The current thread will be the thread that is actually executing the script snippet. A Control.ExecutionContext will be created using the returned private context and made available in this thread via JavaBox.executionContextFor(), and also provided to finishExecution().

      The default implementation in Control returns null.

      Specified by:
      startExecution in interface Control
      Parameters:
      context - the container context for this control
    • check

      public static void check()
    • 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. All components in this record class are compared with Objects::equals(Object,Object).
      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.
    • timeLimit

      public Duration timeLimit()
      Returns the value of the timeLimit record component.
      Returns:
      the value of the timeLimit record component