jvm.protocol
extension points for loaders, artifacts, and class sources
Implement the small protocols and multimethods used by jvm.classloader and jvm.artifact to support new loader or source types.
1 Overview
ILoader defines URL inspection and mutation. The -load-class, -rep, and -artifact multimethods provide open dispatch for class sources and artifact representations.
2 Walkthrough
2.1 Adapt a loader
(require '[jvm.protocol :as protocol])
(extend-type ExampleLoader
protocol/ILoader
(-has-url? [loader path]
(contains? (:paths loader) path))
(-get-url [loader path]
(get (:urls loader) path))
(-all-urls [loader]
(vals (:urls loader)))
(-add-url [loader path]
(add-path loader path))
(-remove-url [loader path]
(remove-path loader path)))
2.2 Support another artifact input
(defmethod protocol/-rep ExampleCoordinate
[coordinate]
(example-coordinate->rep coordinate))
(defmethod protocol/-artifact :example
[_ value]
(rep->example value))
2.3 Support another class source
(defmethod protocol/-load-class
[ExampleSource clojure.lang.DynamicClassLoader]
[source loader opts]
(define-example-class source loader opts))