Package io.modelcontextprotocol.util
Class KeepAliveScheduler
java.lang.Object
io.modelcontextprotocol.util.KeepAliveScheduler
A utility class for scheduling regular keep-alive calls to maintain connections. It
sends periodic keep-alive, ping, messages to connected mcp clients to prevent idle
timeouts.
The pings are sent to all active mcp sessions at regular intervals.
- Author:
- Christian Tzolov
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder class for creating KeepAliveScheduler instances with fluent API. -
Method Summary
Modifier and TypeMethodDescriptionstatic KeepAliveScheduler.Builderbuilder(Supplier<reactor.core.publisher.Flux<McpSession>> mcpSessions) Creates a new Builder instance for constructing KeepAliveScheduler.booleanChecks if the scheduler is currently running.voidshutdown()Shuts down the scheduler and releases resources.reactor.core.Disposablestart()Starts regular keepAlive calls with sessions supplier.voidstop()Stops the currently running keepAlive scheduler.
-
Method Details
-
builder
public static KeepAliveScheduler.Builder builder(Supplier<reactor.core.publisher.Flux<McpSession>> mcpSessions) Creates a new Builder instance for constructing KeepAliveScheduler.- Returns:
- A new Builder instance
-
start
public reactor.core.Disposable start()Starts regular keepAlive calls with sessions supplier.- Returns:
- Disposable to control the scheduled execution
-
stop
public void stop()Stops the currently running keepAlive scheduler. -
isRunning
public boolean isRunning()Checks if the scheduler is currently running.- Returns:
- true if running, false otherwise
-
shutdown
public void shutdown()Shuts down the scheduler and releases resources.
-