Class XxlJobAgentScheduler
java.lang.Object
io.agentscope.extensions.scheduler.xxljob.XxlJobAgentScheduler
- All Implemented Interfaces:
io.agentscope.extensions.scheduler.AgentScheduler
public class XxlJobAgentScheduler
extends Object
implements io.agentscope.extensions.scheduler.AgentScheduler
AgentScheduler implementation based on XXL-Job distributed task scheduling platform.
This scheduler integrates with XXL-Job to provide distributed scheduling capabilities for agents. Jobs are registered as JobHandlers in XXL-Job and can be managed through the XXL-Job admin console.
Key Features:
- Distributed scheduling across multiple executor instances
- Centralized management through XXL-Job admin console
- Support for cron expressions, fixed rate, and manual triggers
- Built-in monitoring and logging
- Fault tolerance and automatic failover
Prerequisites:
- XXL-Job admin server must be running and accessible
- XxlJobExecutor must be properly initialized and started
- Jobs must be configured in XXL-Job admin console with matching JobHandler names
Usage Example:
// 1. Initialize XXL-Job executor (typically in Spring Boot configuration)
XxlJobExecutor executor = new XxlJobExecutor();
executor.setAdminAddresses("http://localhost:8080/xxl-job-admin");
executor.setAppname("agentscope-executor");
executor.setPort(9999);
executor.start();
// 2. Create scheduler
AgentScheduler scheduler = new XxlJobAgentScheduler(executor);
// 3. Create agent configuration
AgentConfig agentConfig = AgentConfig.builder()
.name("MyAgent")
.description("My scheduled agent")
.agentFactory(() -> ReActAgent.builder()
.name("MyAgent")
.model(model)
.toolkit(toolkit)
.build())
.build();
// 4. Schedule the agent
ScheduleConfig scheduleConfig = ScheduleConfig.builder().build();
ScheduleAgentTask task = scheduler.schedule(agentConfig, scheduleConfig);
// 5. Configure the job in XXL-Job admin console:
// - JobHandler: MyAgent (same as agent name)
// - Schedule type: CRON
// - Cron expression: 0 0 8 * * ?
// 6. The agent will be executed according to the schedule in XXL-Job
// Each execution will create a fresh Agent instance
Important Notes:
- The agent name from AgentConfig is used as the JobHandler name in XXL-Job
- Each execution creates a fresh Agent instance using the configured factory
- Schedule configuration (cron, fixedRate, fixedDelay) is managed in XXL-Job admin console
- This scheduler only registers the JobHandler; actual scheduling is controlled by XXL-Job
- Pause/resume operations are not directly supported; use XXL-Job admin console instead
- See Also:
-
AgentSchedulerScheduleAgentTask
-
Constructor Summary
ConstructorsConstructorDescriptionXxlJobAgentScheduler(com.xxl.job.core.executor.XxlJobExecutor executor) Constructor for XxlJobAgentScheduler. -
Method Summary
Modifier and TypeMethodDescriptionbooleanCancel a scheduled task.List<io.agentscope.extensions.scheduler.ScheduleAgentTask>Retrieve all scheduled tasks managed by this scheduler.io.agentscope.extensions.scheduler.ScheduleAgentTaskgetScheduledAgent(String name) Retrieve a scheduled task by its name.Get the type identifier of this scheduler implementation.io.agentscope.extensions.scheduler.ScheduleAgentTaskschedule(io.agentscope.extensions.scheduler.config.AgentConfig agentConfig) Schedule an agent with default schedule configuration (NONE mode).io.agentscope.extensions.scheduler.ScheduleAgentTaskschedule(io.agentscope.extensions.scheduler.config.AgentConfig agentConfig, io.agentscope.extensions.scheduler.config.ScheduleConfig scheduleConfig) voidshutdown()Gracefully shutdown the scheduler.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.agentscope.extensions.scheduler.AgentScheduler
schedule
-
Constructor Details
-
XxlJobAgentScheduler
public XxlJobAgentScheduler(com.xxl.job.core.executor.XxlJobExecutor executor) Constructor for XxlJobAgentScheduler.- Parameters:
executor- The XXL-Job executor instance (must be initialized and started)
-
-
Method Details
-
schedule
public io.agentscope.extensions.scheduler.ScheduleAgentTask schedule(io.agentscope.extensions.scheduler.config.AgentConfig agentConfig) Schedule an agent with default schedule configuration (NONE mode).This is a convenience method that uses a default ScheduleConfig with NONE mode. The agent will be registered as a JobHandler in XXL-Job but won't be automatically scheduled. You must configure the schedule in XXL-Job admin console.
- Parameters:
agentConfig- The agent configuration (can be AgentConfig or RuntimeAgentConfig)- Returns:
- The scheduled task
-
schedule
public io.agentscope.extensions.scheduler.ScheduleAgentTask schedule(io.agentscope.extensions.scheduler.config.AgentConfig agentConfig, io.agentscope.extensions.scheduler.config.ScheduleConfig scheduleConfig) - Specified by:
schedulein interfaceio.agentscope.extensions.scheduler.AgentScheduler
-
cancel
Cancel a scheduled task.Note: This operation is not supported by XXL-Job scheduler. To stop a scheduled task, use the XXL-Job admin console to pause or delete the job.
- Specified by:
cancelin interfaceio.agentscope.extensions.scheduler.AgentScheduler- Parameters:
name- The name of the scheduled task to cancel- Returns:
- Never returns, always throws UnsupportedOperationException
- Throws:
UnsupportedOperationException- always, as cancellation is not supported
-
getScheduledAgent
Retrieve a scheduled task by its name.- Specified by:
getScheduledAgentin interfaceio.agentscope.extensions.scheduler.AgentScheduler- Parameters:
name- The name of the scheduled task (same as agent name)- Returns:
- The ScheduleAgentTask if found, or null if not found or name is empty
-
getAllScheduleAgentTasks
Retrieve all scheduled tasks managed by this scheduler.- Specified by:
getAllScheduleAgentTasksin interfaceio.agentscope.extensions.scheduler.AgentScheduler- Returns:
- A list of all ScheduleAgentTask instances registered in this scheduler
-
shutdown
public void shutdown()Gracefully shutdown the scheduler.This operation:
- Destroys the XXL-Job executor
- Removes all registered JobHandlers
- Clears all scheduled agent tasks
After shutdown, no methods on this scheduler should be called.
- Specified by:
shutdownin interfaceio.agentscope.extensions.scheduler.AgentScheduler
-
getSchedulerType
Get the type identifier of this scheduler implementation.- Specified by:
getSchedulerTypein interfaceio.agentscope.extensions.scheduler.AgentScheduler- Returns:
- "xxl-job"
-