Interface GroovyActionsService
-
- All Known Implementing Classes:
GroovyActionsServiceImpl
public interface GroovyActionsServiceService interface for managing Groovy action scripts.This service provides functionality to load, compile, cache, and execute Groovy scripts as actions within the Apache Unomi framework. It implements optimized compilation and caching strategies to achieve high performance.
Key features:
- Pre-compilation of scripts at startup
- Hash-based change detection for selective recompilation
- Thread-safe compilation and execution
- Unified caching architecture for compiled scripts
Thread Safety: Implementations must be thread-safe as this service is accessed concurrently during script execution.
- Since:
- 2.7.0
- See Also:
GroovyAction,ScriptMetadata
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Class<? extends groovy.lang.Script>getCompiledScript(String actionName)Retrieves a pre-compiled script class from cache.ScriptMetadatagetScriptMetadata(String actionName)Retrieves script metadata for monitoring and change detection.voidremove(String actionName)Removes a Groovy action and all associated metadata.voidsave(String actionName, String groovyScript)Saves a Groovy action script with compilation and validation.
-
-
-
Method Detail
-
save
void save(String actionName, String groovyScript)
Saves a Groovy action script with compilation and validation.This method compiles the script, validates it has the required annotations, persists it, and updates the internal cache. If the script content hasn't changed, recompilation is skipped.
- Parameters:
actionName- the unique identifier for the actiongroovyScript- the Groovy script source code- Throws:
IllegalArgumentException- if actionName or groovyScript is nullRuntimeException- if compilation or persistence fails
-
remove
void remove(String actionName)
Removes a Groovy action and all associated metadata.This method removes the action from both the cache and persistent storage, and cleans up any registered action types in the definitions service.
- Parameters:
actionName- the unique identifier of the action to remove- Throws:
IllegalArgumentException- if id is null
-
getCompiledScript
Class<? extends groovy.lang.Script> getCompiledScript(String actionName)
Retrieves a pre-compiled script class from cache.This is the preferred method for script execution as it returns pre-compiled classes without any compilation overhead. Returns
nullif the script is not found in the cache.- Parameters:
actionName- the unique identifier of the action- Returns:
- the compiled script class, or
nullif not found in cache - Throws:
IllegalArgumentException- if id is null
-
getScriptMetadata
ScriptMetadata getScriptMetadata(String actionName)
Retrieves script metadata for monitoring and change detection.The returned metadata includes content hash, compilation timestamp, and the compiled class reference. This is useful for monitoring tools and debugging.
- Parameters:
actionName- the unique identifier of the action- Returns:
- the script metadata, or
nullif not found - Throws:
IllegalArgumentException- if actionName is null
-
-