 (defn clear-registry []
   (reset! registry         {})
   (reset! indexed-registry {}))
-
-;; (clear-registry)
 
 (defn register-listener [listener-name dbname schema-name table-name f]
   (swap! registry assoc listener-name {:dbname dbname

(defn process-row-changes [conf conn]
  ;; obtain mutex, nowait
  ;; TODO: handle failure to get lock (probably an exception)
  (let [dbname        (-> conf :dbconf :subname)]
    (jdbc/transaction
     (if (obtain-mutex conf conn)
       (do

       (log/infof "did not get lock on irmgard.process_log, another process is working with the table."))
     :ok)))

(defn dispatch-notifications [conf conn force-check-table?]
  ;; this select is purely for side-effect
  (exec-sql "SELECT 1" [])
  ;; NB: also, just check the table to see if it contains anything
  (let [dbname        (-> conf :conf :subname)
        notifications (.getNotifications conn)]
    (when (or (not (nil? notifications))
              (and force-check-table?
                   (not (empty? (exec-sql "SELECT * FROM irmgard.row_changes LIMIT 1" [])))))
      (log/infof "dispatch-notifications[%s]: %s notifications" dbname (count notifications))
      (process-row-changes conf conn))))

