Hi Toby:
As we discussed in Clojure google group
we now start working on implementing Cojure support in Vert.x
so far we got some progresses but there is a problem there
there are some states in Verticle e.g.(vertx and context object)
but we cant make this since if we def vertx as global var then it is actually a static variable in Java and may cause conflicts
and also for purely functional programming, we prefer to use pure function so I would suggest to use some functions like start[], start[^Vertx vertx], start[^Vertx vertx ^Context ctx] etc. to simulate the start and stop functions in Verticle/Java just change the input to make functions pure
and we could use Clojure Java api to invoke these methods defined in Clojure namespace so far it works nice
here is the sample code:
(ns com.whitewoodcity.test)
(import
io.vertx.core.Vertx)
(import
io.vertx.core.Context)
(import
io.vertx.core.eventbus.Message)
(defn arities [v]
(-> v meta :arglists))
(def handler0
(reify
io.vertx.core.Handler
(handle [this message]
do
(println (.body message))
(.reply message "got it"))))
(defn handler1 [f]
(reify
io.vertx.core.Handler
(handle [this message]
(f message))))
(defn start [^Vertx vertx ^Context context]
(.consumer (.eventBus vertx) "com.whitewoodcity.test" handler0))
;(def consumer (reify java.util.function.Consumer
; (accept [this t]
; ; here the impl
; )))
(defn get-start-inf [] (count (first (arities #'start))))
public class ClojureTest {
@Test
public void name() {
IFn require = Clojure.var("clojure.core", "require");
require.invoke(Clojure.read("com.whitewoodcity.test"));
IFn startIFn = Clojure.var("com.whitewoodcity.test","get-start-inf");
System.out.println(startIFn.invoke());
IFn inc = Clojure.var("com.whitewoodcity.test", "start");
Vertx vertx = Vertx.vertx();
inc.invoke(vertx, vertx.getOrCreateContext());
vertx.eventBus().send("com.whitewoodcity.test","this is a message",ar->{
System.out.println(ar.result().body());
});
}
}
so actually we could wrap clj namespaces in the Verticle Java code
Is OK we implement the Clojure support in this way?
and use codegen to generate apis like event-bus rather than eventBus, http-client rather than httpClient etc.