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))

3    API



-artifact ^

Added 4.0

multimethod definition for coercing to an artifact type

v 4.0
(defmulti -artifact
  (fn [tag x] tag))
link
-artifact => clojure.lang.MultiFn

-load-class ^

Added 4.0

loads a class from various sources

v 4.0
(defmulti -load-class
  (fn [x loader opts] [(type x) (type loader)]))
link
-load-class => clojure.lang.MultiFn

-rep ^

Added 4.0

multimethod definition for coercing to a rep

v 4.0
(defmulti -rep
  type)
link
-rep => clojure.lang.MultiFn