Interface GroovyActionsService

All Known Implementing Classes:
GroovyActionsServiceImpl

public interface GroovyActionsService
Service 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:
  • Method Summary

    Modifier and Type
    Method
    Description
    Class<? extends groovy.lang.Script>
    Retrieves a pre-compiled script class from cache.
    Retrieves script metadata for monitoring and change detection.
    void
    remove(String actionName)
    Removes a Groovy action and all associated metadata.
    void
    save(String actionName, String groovyScript)
    Saves a Groovy action script with compilation and validation.
  • Method Details

    • 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 action
      groovyScript - the Groovy script source code
      Throws:
      IllegalArgumentException - if actionName or groovyScript is null
      RuntimeException - 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 null if the script is not found in the cache.

      Parameters:
      actionName - the unique identifier of the action
      Returns:
      the compiled script class, or null if 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 null if not found
      Throws:
      IllegalArgumentException - if actionName is null