Class VSphereConnectionPool
java.lang.Object
org.jenkinsci.plugins.vsphere.tools.VSphereConnectionPool
Maintains a single long-lived vSphere session for one
vSphereCloud instance,
eliminating the per-operation login/logout overhead that occurs when every API call
creates and destroys its own session.
Caller contract:
- Obtain the shared connection via
acquire(). - Use it normally - all public
VSpheremethods work as usual. - Call
VSphere.disconnect()exactly once when done. For pooled connections this releases the borrow back to the pool (seerelease()) rather than logging out directly; the pool controls the real session lifecycle and defers disconnecting an orphaned pool until every outstanding borrow is released.
Background maintenance:
- Health check - if
healthCheckIntervalSecs > 0, a daemon thread periodically issues a lightweightcurrentTime()call and reconnects automatically on failure. - Session age limit - if
sessionMaxAgeSecs > 0, a one-shot timer is armed for the exact moment the session reaches that age, at which point it is proactively restarted (also re-checked defensively on the nextacquire()call) - unlessidleTimeoutSecs > 0and no consumer has acquired the session since it was established, in which case it is disconnected instead of restarted, deferring to the idle policy. Without this, asessionMaxAgeSecssmaller thanidleTimeoutSecswould otherwise reconnect an unused session forever, since each reconnect also resets the idle clock and the idle timeout would never get a chance to win. - Use-count limit - if
sessionMaxUses > 0, the session is restarted on the nextacquire()once that many acquisitions have been made. - Idle timeout - if
idleTimeoutSecs > 0, a one-shot timer is armed for the exact moment the connection has gone unused for that many seconds, at which point it is disconnected (and lazily reconnected on the nextacquire()). The timer is re-armed on everyacquire().
Session age and idle timeout are enforced by dedicated one-shot alarms rather than periodic polling, so they fire at (approximately) the exact configured deadline instead of some time after it.
A value of 0 disables the corresponding feature.
Thread-safe. All mutable state is guarded by this.
-
Constructor Summary
ConstructorsConstructorDescriptionVSphereConnectionPool(VSphereConnectionConfig config, int healthCheckIntervalSecs, int sessionMaxAgeSecs, int sessionMaxUses, int idleTimeoutSecs) VSphereConnectionPool(VSphereConnectionConfig config, Cloud owner, int healthCheckIntervalSecs, int sessionMaxAgeSecs, int sessionMaxUses, int idleTimeoutSecs) -
Method Summary
Modifier and TypeMethodDescriptionacquire()Returns the pooledVSphereconnection, creating or restarting it if necessary.voidshutdown()Shuts down all background threads and, unless the connection is still borrowed by an in-flight caller (seeacquire()/release()), disconnects the current session immediately.
-
Constructor Details
-
VSphereConnectionPool
public VSphereConnectionPool(@NonNull VSphereConnectionConfig config, int healthCheckIntervalSecs, int sessionMaxAgeSecs, int sessionMaxUses, int idleTimeoutSecs) -
VSphereConnectionPool
public VSphereConnectionPool(@NonNull VSphereConnectionConfig config, @CheckForNull Cloud owner, int healthCheckIntervalSecs, int sessionMaxAgeSecs, int sessionMaxUses, int idleTimeoutSecs) - Parameters:
owner- theCloudthis pool belongs to, used only so thatVSphereConnectionPoolRegistrycan detect and shut down pools left behind by a cloud instance that was replaced by reconfiguration (e.g. saving the Jenkins global config). May benull(e.g. in tests), in which case this pool is never auto-reaped as an orphan.
-
-
Method Details
-
acquire
Returns the pooledVSphereconnection, creating or restarting it if necessary. The returned instance is marked as pooled so that callers'VSphere.disconnect()calls release it back to this pool instead of logging out directly. Everyacquire()must eventually be matched by exactly oneVSphere.disconnect()call on the returned instance, so thatshutdown()can tell when it is safe to actually tear down the session - seerelease().- Throws:
VSphereException- if establishing the session fails.
-
shutdown
public void shutdown()Shuts down all background threads and, unless the connection is still borrowed by an in-flight caller (seeacquire()/release()), disconnects the current session immediately. If it is still borrowed, the actual disconnect is deferred until the last borrower releases it, so an in-flight vCenter operation (e.g. a build step that started before this pool's owning cloud was replaced) is not cut off mid-call. After this call the pool must not be used toacquire()further connections.
-