Code Monkey home page Code Monkey logo

Comments (9)

weavejester avatar weavejester commented on June 27, 2024

Basically, if I'm understanding correctly by the time .contextDestroyed has been called, it's too late to do anything meaningful - even something as trivial as logging.

Sorry, I'm afraid I'm not following. Why does the listener function care whether or not the servlet exists? It's just a shim for the handler.

from lein-ring.

dpiliouras avatar dpiliouras commented on June 27, 2024

Sorry, I'm afraid I'm not following. Why does the listener function care whether or not the servlet exists? It's just a shim for the handler.

I can't answer that with any form of confidence or authority...all I know, is that the code in our :destroy fns doesn't run on un/re-deploy, and since Friday I also know (from the docs) that the kind of work we're doing (cleanup/persist-state) should be done in the Sevlet::destroy method. I do have a local copy of lein-ring (for #217), so I'm going to try and implement this today, and see what happens. Will keep you posted...

from lein-ring.

dpiliouras avatar dpiliouras commented on June 27, 2024

I can confirm that overriding the .destroy method on the Servlet solves our issue - i.e. all the expected logging is now visible, and each component's state is persisted as well. Here is the modified compile-servlet:

(defn compile-servlet [project]
  (let [servlet-ns  (symbol (servlet-ns project))
        destroy-sym (get-in project [:ring :destroy])]
    (compile-form project servlet-ns
      `(do (ns ~servlet-ns
             (:gen-class
               :extends javax.servlet.http.HttpServlet
               :exposes-methods {~'destroy ~'superDestroy})  ;; <===
             (:import javax.servlet.http.HttpServlet))
           (def ~'service-method)
           (defn ~'-service [servlet# request# response#]
             (~'service-method servlet# request# response#))
           (defn ~'-destroy [this#]     ;; <===
             ~(if destroy-sym
                `(~(generate-resolve destroy-sym)))
             (. this# ~'superDestroy))) ;; <===
      :print-meta true)))

I guess, in an ideal situation lein-ring would offer the following (self-explanatory) options:

  1. servlet-init
  2. servlet-destroy
  3. context-init
  4. context-destroyed (notice the past tense)

Since, I presume that backwards compatibility is desired, and the :init/:destroy keys already refer to the context, realistically the only viable option is to simply add support for :servlet-init/destroy.

from lein-ring.

weavejester avatar weavejester commented on June 27, 2024

Yep, keeping compatibility is the best option. If you're having issues that are solved with overriding destroy, then that's likely reason enough to add a couple more configuration keys to Lein-Ring to override the init and destroy servlet methods.

from lein-ring.

dpiliouras avatar dpiliouras commented on June 27, 2024

Agreed...would you like a PR? I have no problem working on it, but I would prefer that we merge #217 first.

from lein-ring.

weavejester avatar weavejester commented on June 27, 2024

Sure. I had 20 minutes or so spare, so it's now merged.

from lein-ring.

dpiliouras avatar dpiliouras commented on June 27, 2024

Great thanks 👍 . Unfortunately, because of the manual merge, the new PR I want to open shows 16 commits ahead, even though there is a single new commit and file changed (a few lines actually). Will you be ok keeping the last commit only, if I open it like that?

from lein-ring.

weavejester avatar weavejester commented on June 27, 2024

Why not just reset to master and cherry pick the single commit you want?

from lein-ring.

dpiliouras avatar dpiliouras commented on June 27, 2024

Thanks for the idea - see #219

from lein-ring.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.