Class ScriptMetadata

java.lang.Object
org.apache.unomi.groovy.actions.ScriptMetadata

public final class ScriptMetadata extends Object
Metadata container for compiled Groovy scripts with hash-based change detection.

This class encapsulates all metadata associated with a compiled Groovy script, including content hash for efficient change detection and the compiled class for direct execution without recompilation.

Thread Safety: This class is immutable and thread-safe. All fields are final and the class provides no methods to modify its state after construction.

Since:
2.7.0
  • Constructor Details

    • ScriptMetadata

      public ScriptMetadata(String actionName, String scriptContent, Class<? extends groovy.lang.Script> compiledClass)
      Constructs a new ScriptMetadata instance.
      Parameters:
      actionName - the unique name/identifier of the action
      scriptContent - the raw Groovy script content
      compiledClass - the compiled Groovy script class
      Throws:
      IllegalArgumentException - if any parameter is null
  • Method Details

    • hasChanged

      public boolean hasChanged(String newContent)
      Determines if the script content has changed compared to new content.

      This method uses SHA-256 hash comparison for efficient change detection without storing or comparing the full script content.

      Parameters:
      newContent - the new script content to compare against
      Returns:
      true if content has changed, false if unchanged
      Throws:
      IllegalArgumentException - if newContent is null
    • getActionName

      public String getActionName()
      Returns the action name/identifier.
      Returns:
      the action name, never null
    • getScriptContent

      public String getScriptContent()
      Returns the original script content.
      Returns:
      the script content, never null
    • getContentHash

      public String getContentHash()
      Returns the SHA-256 hash of the script content.
      Returns:
      Base64 encoded content hash, never null
    • getCreationTime

      public long getCreationTime()
      Returns the timestamp when this metadata was created.
      Returns:
      creation timestamp in milliseconds since epoch
    • getCompiledClass

      public Class<? extends groovy.lang.Script> getCompiledClass()
      Returns the compiled Groovy script class.

      This class can be used to create new script instances for execution without requiring recompilation.

      Returns:
      the compiled script class, never null