Open deas opened 8 years ago
Oddly enough, I was just playing around myself with embedding Gorilla in a Java application! I changed the build so it generates a main class in the jar (see 75e6435d08366428acadf725b86b7e1c8220cd4e) and it seems to work ok.
What changes are you thinking?
Decoupling it from httpkit, Feeding the repl using a javax.websocket.server.ServerEndpoint, adding a Servlet class (dispatching to the compojure handler) to be dropped in using a web-fragment.xml, allowing configuration of handler paths, and allowing an externally configured nrepl server.
Guess the difference of my embedding approach is that I don't want it to bring it's own server (jetty) or nrepl and want to use what's already there. Using your own port (in production) may also have the drawback that it won't be reachable due to firewalls and things along those lines.
Got most of that working. The last missing piece seems to be a nrepl transport dispatching from the ServerEndpoint to the repl. Somewhat similar to the current httpkit based relaying code.
I see, that sounds interesting. I'm generally quite conservative as I like to keep the code simple, and my initial thought is that this might add quite a bit of extra complexity. But if there's a way we can break it out so that Gorilla itself stays simple but offers up some extension points for embedding then it would be a good thing.
Don't worry. The changes that "should" go in gorilla repl are fairly small and do imho even improve the code by separating out concerns such as httpkit which one might want to :exclude if you are embedding in another app.
If we want to provide an aotd Ring Servlet, its web-fragment.xml and @ServerEndpoint along with gorilla-repl might be debatable. Personally, I am aiming for a generic "uberjar drop-in" allowing you to "inject" gorilla-repl in virtually any webapp, but I don't have to drop "all" the code in here. :)
Not strictly an embedding issue, but I also replaced the connection atom and bypass the network layer when calling into nrepl.
Sounds good. Do you want to put up a PR with these changes in for discussion when ready?
I am just writing a blogpost about it. Will let you know about it. And will get back with more PRs for sure!
Any plan on implementing this?
I am just poking around with gorilla-repl and its seems it is not far away from being "cleanly" embeddable.
Would you be interested to see a PR with those changes?