Skip to content
This repository has been archived by the owner on Sep 17, 2021. It is now read-only.

Commit

Permalink
Consolidate clojure.runtime into commander.util
Browse files Browse the repository at this point in the history
  • Loading branch information
Bobby Calderwood committed Nov 24, 2016
1 parent c07b5e3 commit 1f24ff0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 49 deletions.
44 changes: 0 additions & 44 deletions src/com/capitalone/clojure/runtime.clj

This file was deleted.

37 changes: 32 additions & 5 deletions src/com/capitalone/commander/util.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,39 @@

(ns com.capitalone.commander.util
(:require [com.stuartsierra.component :as component]
[io.pedestal.log :as log]
[com.capitalone.clojure.runtime :as runtime])
[io.pedestal.log :as log])
(:import [java.nio ByteBuffer]))

(set! *warn-on-reflection* true)

(def ^:private shutdown-hooks (atom {}))

(defonce ^:private init-shutdown-hook
(delay (.addShutdownHook (Runtime/getRuntime)
(Thread.
#(doseq [f (vals @shutdown-hooks)]
(f))))))

(defn add-shutdown-hook! [k f]
@init-shutdown-hook
(swap! shutdown-hooks assoc k f))

(defn remove-shutdown-hook! [k]
(swap! shutdown-hooks dissoc k))

(defn set-default-uncaught-exception-handler!
"Adds a exception handler, which is a 2-arity function of thread
name and exception."
[f]
(Thread/setDefaultUncaughtExceptionHandler
(reify Thread$UncaughtExceptionHandler
(uncaughtException [_ thread ex]
(f thread ex)))))

(defn unset-default-uncaught-exception-handler!
[]
(Thread/setDefaultUncaughtExceptionHandler nil))

(defn keyword->string
[kw]
(let [sb (StringBuffer.)]
Expand Down Expand Up @@ -46,11 +73,11 @@

(defn run-system!
[system]
(runtime/set-default-uncaught-exception-handler!
(set-default-uncaught-exception-handler!
(fn [thread e]
(log/error :message "Uncaught exception, system exiting." :exception e :thread thread)
(System/exit 1)))
(runtime/add-shutdown-hook! ::stop-system #(do (log/info :message "System exiting, running shutdown hooks.")
(component/stop system)))
(add-shutdown-hook! ::stop-system #(do (log/info :message "System exiting, running shutdown hooks.")
(component/stop system)))
(component/start system)
@(promise))

0 comments on commit 1f24ff0

Please sign in to comment.