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()
}
}

Functions

Link copied to clipboard
abstract fun beforeActionLaunched(process: AgentProcess)
Link copied to clipboard
abstract fun onActionCompleted(process: AgentProcess, action: Action)
Link copied to clipboard
abstract fun onActionLaunched(process: AgentProcess, action: Action)