Interface AgentProcessCallback

  • All Implemented Interfaces:

    
    public interface AgentProcessCallback
    
                        

    Callback interface for interleaving logic with the lifecycle of an AgentProcess and its actions.

    This is particularly useful for ConcurrentAgentProcess, where launched actions run in their own threads and may, for example, need a Spring Security context proliferated to the thread in which the action runs:

    @Component
    @Scope("prototype")
    class SecurityContextAgentProcessCallback : AgentProcessCallback {
        var securityContext: SecurityContext? = null
    
        override fun beforeActionLaunched(process: AgentProcess) {
            securityContext = SecurityContextHolder.getContext()
        }
    
        override fun onActionLaunched(
            process: AgentProcess,
            action: Action,
        ) {
            securityContext?.let {
                SecurityContextHolder.setContext(it)
            }
        }
    
        override fun onActionCompleted(
            process: AgentProcess,
            action: Action,
        ) {
            SecurityContextHolder.clearContext()
        }
    }
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description