Maintain lease vitality with KeepAlive services
mainTo prevent leases from expiring, jetcd provides background services to automatically send keep-alive requests to etcd.
KeepAlive Lifecycle
- Starting the Service: Calling
startKeepAliveServiceinitializes a background scheduler (keepAliveSchedule) and aScheduledExecutorService. This service manages two primary tasks:keepAliveExecutor: Periodically scans registered leases and sends keep-alive requests via aStreamObserverwhen thenextKeepAliveTimeis reached.deadLineExecutor: Periodically scans leases and removes them from the internal map once theirDeadLineis reached, triggering expiration logic.
- Using
keepAlive: ThekeepAlivefunction creates akeepAliveobject, adds it to the internal tracking map, and schedules it for automatic renewal. - Stopping the Service: Use
closeKeepAliveServiceto terminate the background scheduler and close theStreamObserverconnection to etcd.