Class GroovyActionsServiceImpl

java.lang.Object
org.apache.unomi.groovy.actions.services.impl.GroovyActionsServiceImpl
All Implemented Interfaces:
GroovyActionsService

public class GroovyActionsServiceImpl extends Object implements GroovyActionsService
High-performance GroovyActionsService implementation with pre-compilation, hash-based change detection, and thread-safe execution.
  • Constructor Details

    • GroovyActionsServiceImpl

      public GroovyActionsServiceImpl()
  • Method Details

    • setDefinitionsService

      public void setDefinitionsService(DefinitionsService definitionsService)
    • setPersistenceService

      public void setPersistenceService(PersistenceService persistenceService)
    • setSchedulerService

      public void setSchedulerService(SchedulerService schedulerService)
    • start

      public void start(GroovyActionsServiceImpl.GroovyActionsServiceConfig config, org.osgi.framework.BundleContext bundleContext)
    • onDestroy

      public void onDestroy()
    • save

      public 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. Implementation performs hash-based change detection to skip unnecessary recompilation.

      Specified by:
      save in interface GroovyActionsService
      Parameters:
      actionName - the unique identifier for the action
      groovyScript - the Groovy script source code
    • remove

      public 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.

      Specified by:
      remove in interface GroovyActionsService
      Parameters:
      actionName - the unique identifier of the action to remove
    • getCompiledScript

      public Class<? extends groovy.lang.Script> getCompiledScript(String id)
      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.

      Specified by:
      getCompiledScript in interface GroovyActionsService
      Parameters:
      id - the unique identifier of the action
      Returns:
      the compiled script class, or null if not found in cache
    • getScriptMetadata

      public 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.

      Specified by:
      getScriptMetadata in interface GroovyActionsService
      Parameters:
      actionName - the unique identifier of the action
      Returns:
      the script metadata, or null if not found