Package org.apache.unomi.groovy.actions
Class ScriptMetadata
java.lang.Object
org.apache.unomi.groovy.actions.ScriptMetadata
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 Summary
ConstructorsConstructorDescriptionScriptMetadata(String actionName, String scriptContent, Class<? extends groovy.lang.Script> compiledClass) Constructs a new ScriptMetadata instance. -
Method Summary
Modifier and TypeMethodDescriptionReturns the action name/identifier.Class<? extends groovy.lang.Script>Returns the compiled Groovy script class.Returns the SHA-256 hash of the script content.longReturns the timestamp when this metadata was created.Returns the original script content.booleanhasChanged(String newContent) Determines if the script content has changed compared to new content.
-
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 actionscriptContent- the raw Groovy script contentcompiledClass- the compiled Groovy script class- Throws:
IllegalArgumentException- if any parameter is null
-
-
Method Details
-
hasChanged
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:
trueif content has changed,falseif unchanged- Throws:
IllegalArgumentException- if newContent is null
-
getActionName
Returns the action name/identifier.- Returns:
- the action name, never null
-
getScriptContent
Returns the original script content.- Returns:
- the script content, never null
-
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
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
-