LoadedBundle

Runtime-managed wrapper around one discovered KSLModelBundle. Holds the bundle's classloader and (when applicable) its source JAR and content hash, and provides on-demand access to each model's ksl.simulation.ModelDescriptor with a three-tier resolution strategy.

Descriptor resolution priority (per descriptorFor):

  1. In-JAR resource at BundleLayout.descriptorPath(modelId). Present when the bundle was processed by kslpkg enrich.

  2. On-disk cache at ~/.ksl/bundle-cache/<jarSha256>/<modelId>.json. Applies only to JAR-backed bundles, not classpath-loaded ones.

  3. Lazy extraction: instantiate the model via its builder and call Model.modelDescriptor(). The result is cached for JAR-backed bundles before returning.

Results are memoized in-memory for the lifetime of this LoadedBundle.

LoadedBundle is AutoCloseable. The ownedResources parameter is the AutoCloseable (if any) whose lifetime this instance manages — typically the URLClassLoader created for a JAR. For classpath-loaded bundles ownedResources is null and close is a no-op.

When several LoadedBundles come from the same BundleLoader.loadJar call (one JAR declaring multiple bundles), they share a classloader; close them as a group, since closing any one of them releases resources that the others depend on.

Properties

Link copied to clipboard

When this bundle was built/packaged: the JAR manifest's Build-Time attribute if present, else the JAR file's last-modified time; null for classpath-loaded bundles. Used to resolve same-(bundleId, version) duplicates newest-wins, so a rebuilt-but-not-reversioned bundle's most recent copy is the one that stays loaded.

Link copied to clipboard
Link copied to clipboard

SHA-256 of the source JAR's bytes, or null for classpath-loaded bundles (which have no backing JAR file). Lets a caller detect that a JAR at a previously-loaded path has been rebuilt — same sourceJar, different content — which is the signal a bundle library uses to decide a reload is warranted rather than a no-op.

Link copied to clipboard

Functions

Link copied to clipboard
open override fun close()

Releases the AutoCloseable resources this instance owns (typically a URLClassLoader); a no-op when ownedResources is null. After close, calls to descriptorFor throw IllegalStateException.

Link copied to clipboard

Returns the ModelDescriptor for the given modelId. Resolves through in-JAR resource, then on-disk cache, then lazy extraction (see class KDoc). The first successful resolution is memoized.