JARModelBuilder

class JARModelBuilder(loader: DynamicJarClassLoader, modelBuilderClassName: String? = null) : ModelBuilderIfc, AutoCloseable(source)

Using the supplied JAR file, this class creates an instance of an object that implements the ModelBuilderIfc interface. The resulting instance can be used to build models as defined by the JAR file classes.

It is much more efficient to supply a class name found within the JAR file that implements the ModelBuilderIfc. If not supplied, the JAR will be searched for the first class that implements the ModelBuilderIfc interface. If no classes are found that implement the interface, then an exception occurs.

The simplest approach is to include a Kotlin object reference declaration that implements the ModelBuilderIfc interface in the compiled code within the JAR file. Then, you supply the name of the object/class as the modelBuilderClassName parameter. If you don't supply an object reference declaration, then there must be one class within the JAR file that implements the ModelBuilderIfc interface, and it must have a public zero argument constructor.

If the required KSLCore release's jar file is on the classpath for the implementation that uses the JARModelBuilder, then the jar file does not need to be a "fat" jar. As long as the jar file has all the necessary user-defined class definitions needed to construct an instance of the desired model, then the necessary KSL classes will be loaded via the class loader's parent through delegation. The parent loader will be the loader required to instantiate this class.

The JARModelBuilder should not be closed until all required models are built. Once the builder is closed, no additional models can be built. It is important to close the builder once all models have been built.

Because of the underlying JAR files and class loading, it is important to not store long-lasting references to the models built from the builder. This could have important memory issues because of how java class loading operates. See this article. for more information.

Parameters

jarPath

the path to the JAR file. The file must be a JAR file and contain a class that implements the ModelBuilderIfc interface.

modelBuilderClassName

the (optional) name of the class within the JAR file that implements the ModelBuilderIfc

Constructors

Link copied to clipboard
constructor(loader: DynamicJarClassLoader, modelBuilderClassName: String? = null)
constructor(jarPath: String, modelBuilderClassName: String? = null)

Constructor for a JAR file

constructor(jarPath: Path, modelBuilderClassName: String? = null)

Constructor for a JAR file

Properties

Link copied to clipboard
Link copied to clipboard

All class names within the loader

Link copied to clipboard
Link copied to clipboard
val jarURL: URL

The list of URL representations for the JAR files

Link copied to clipboard

The class names in the loader that implement the ModelBuilderIfc interface

Functions

Link copied to clipboard
open override fun build(modelConfiguration: Map<String, String>?, experimentRunParameters: ExperimentRunParametersIfc?, defaultKSLDatabaseObserverOption: Boolean): Model

The returned model will have been instantiated by the underlying class loader. Be sure not to store long-lasting references to the model instances because this may have memory implications that prevent garbage collection of the loader and any classes that it loaded.

Link copied to clipboard
open override fun close()

Closes the underlying class loader. Once the loading mechanism is closed, no additional model building is permitted.

Link copied to clipboard
fun initializeBuilder(modelBuilderClassName: String)

Initializes the builder so that model building can occur. This function must be called before the first time build() is called.

Link copied to clipboard
open override fun toString(): String