Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

wip

  • Loading branch information...
commit 8d28ea0b0ca00017e6771d912cd148b2da8558de 1 parent 2d784db
@hiredman authored
View
19 clojurebot-legacy/module.xml
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<module xmlns="urn:jboss:module:1.1" name="clojurebot.legacy">
- <main-class name="clojurebot.legacy" />
- <resources>
- <resource-root
- path="clojurebot-legacy-1.0.0-SNAPSHOT-standalone.jar"/>
- </resources>
- <dependencies>
- <system>
- <paths>
- <path name="org/xml/sax" />
- <path name="org/xml/sax/helpers" />
- <path name="javax/xml/parsers" />
- <path name="javax/transaction/xa" />
- <!-- <path name="java/**" /> -->
- </paths>
- </system>
- </dependencies>
-</module>
View
4 clojurebot-legacy/project.clj
@@ -2,5 +2,7 @@
:description "FIXME: write description"
:dependencies [[org.clojure/clojure "1.2.0"]
[org.clojars.hiredman/fnparse "2.2.4"]
- [vespa-crabro "1.0.0-SNAPSHOT"]]
+ [org.clojure/java.jmx "0.2.0"]
+ [org.clojure/clojure-contrib "1.2.0"]]
+ :clean-non-project-classes false
:main clojurebot.legacy)
View
39 clojurebot-legacy/src/clojurebot/legacy.clj
@@ -1,23 +1,24 @@
(ns clojurebot.legacy
- (:require [vespa.crabro :as vc]
- [vespa.protocols :as vp])
+ (:require [clojure.java.jmx :as jmx])
+ (:import (java.util.concurrent LinkedBlockingQueue))
(:gen-class))
(defn -main [& args]
- (with-open [mb (vc/message-bus)]
- (while true
- (try
- (vp/receive-from
- mb
- "fnparse"
- (fn [msg]
- (let [{:keys [payload reply-to]} (read-string msg)]
- (vc/send-to mb
- reply-to
- (pr-str
- (try
- {:good (eval payload)}
- (catch Throwable t
- {:error (print-str t)})))))))
- (catch Throwable t
- (prn t))))))
+ (let [queue (LinkedBlockingQueue.)]
+ (jmx/register-mbean
+ (jmx/create-bean (atom {:inbox queue}))
+ "clojurebot.legacy:name=Eval")
+ (future
+ (while true
+ (let [{:keys [body reply-to tag]} (read-string (.take queue))]
+ (when reply-to
+ (let [reply-queue (jmx/read reply-to :inbox)]
+ (.put reply-queue
+ (pr-str (try
+ {:good (eval body) :tag tag}
+ (catch Throwable t
+ {:bad (print-str t)
+ :tag tag}))))))
+ (try
+ (eval body)
+ (catch Throwable _)))))))
View
11 example-config.clj
@@ -23,4 +23,13 @@
;; :logging-plugins #{clojurebot.indexing/index}
:on-invite :join
:clojure-jar "/Users/hiredman/src/clojure/clojure.jar"
- :swank 8888}
+ :swank 8888
+
+ :connections #{{:type :irc
+ :server "irc.freenode.net"
+ :port 6667
+ :nick "clojurebotIII"
+ :channels ["#clojurebot"]
+ :tag :clojurebot }}
+
+ }
View
7 project.clj
@@ -14,7 +14,8 @@
[cheshire "4.0.0"]
[clj-http "0.4.1"]
[swank-clojure "1.3.2"]
- [org.jboss.modules/jboss-modules "1.1.2.GA"]
- [clj-wallhack "1.0"]]
- :main clojurebot.core
+ [clj-wallhack "1.0"]
+ [polycosm "0.0.2-SNAPSHOT"]
+ [org.clojure/java.jmx "0.2.0"]]
+ :main clojurebot.boot
:clean-non-project-classes false)
View
94 src/clojurebot/boot.clj
@@ -1,49 +1,55 @@
(ns clojurebot.boot
- (:require [wall.hack :as wh]
- [clojure.java.io :as io]
- [vespa.crabro :as vc]
- [vespa.protocols :as vp])
- (:import (org.jboss.modules LocalModuleLoader
- ModuleIdentifier)
- (java.io File)))
+ (:require [vespa.crabro :as vc]
+ [vespa.protocols :as vp]
+ [clojurebot.boot.legacy :as legacy])
+ (:gen-class))
-(defn loader []
- (LocalModuleLoader.
- (into-array File
- [(io/file (System/getProperty "user.dir")
- "modules")])))
+(defn context []
+ (let [c (atom ())]
+ (reify
+ clojure.lang.IDeref
+ (deref [_]
+ c)
+ java.io.Closeable
+ (close [_]
+ (doseq [thing @c]
+ (try
+ (.close thing)
+ (catch Exception e
+ (prn e))))))))
-(defonce server (vc/create-server))
+(defn load-transport [{:keys [type]}]
+ (require (symbol (str "transports." (name type)))))
-(defn f []
- (future
- (let [l (loader)
- m (.loadModule l (ModuleIdentifier/create "clojurebot.legacy" "main"))
- cl (.getClassLoader m)]
- (let [old-cl (.getContextClassLoader (Thread/currentThread))]
- (try
- (.setContextClassLoader (Thread/currentThread) cl)
- (.run m nil)
- (finally
- (.setContextClassLoader (Thread/currentThread) old-cl)))))))
+(defn boot-transport [{:keys [type] :as con} in out]
+ ((resolve (symbol (str "transports." (name type)) "init"))
+ con in out))
+
+(defonce server (delay (vc/create-server)))
-(defmacro remote-do [& forms]
- (let [reply-queue (name (gensym 'reply))]
- `(future
- (let [result# (promise)]
- (with-open [mb# (vc/message-bus)]
- (future
- (try
- (with-open [mb# (vc/message-bus)]
- (vp/receive-from mb# ~reply-queue result#))
- (catch Throwable t#
- (result# {:bad (pr-str t#)}))))
- (vc/send-to mb# "fnparse"
- ~(pr-str
- {:reply-to reply-queue
- :payload (cons 'do forms)})))
- (let [{good# :good
- bad# :bad} (read-string @result#)]
- (if bad#
- (throw (Exception. bad#))
- good#))))))
+(defn -main [& [config-file]]
+ (let [config (read-string (slurp config-file))
+ in-queue (:in-queue config "clojurebot.in")
+ out-queue (:out-queue config "clojurebot.out")
+ exit-queue (:exit-queue config "clojurebot.exit")]
+ (with-open [context (context)]
+ (swap! @context conj @server)
+ (legacy/boot)
+ (doseq [con (:connections config)
+ :let [mb (vc/message-bus)]]
+ (swap! @context conj mb)
+ (vp/declare-broadcast mb in-queue)
+ (vp/declare-broadcast mb out-queue)
+ (load-transport con)
+ (boot-transport con
+ (partial vc/send-to mb in-queue)
+ (partial vp/receive-from mb out-queue)))
+ (future
+ (try
+ (with-open [mb (vc/message-bus)]
+ (while true
+ (vp/receive-from mb in-queue prn)))
+ (catch Exception e
+ (.printStackTrace e))))
+ (with-open [mb (vc/message-bus)]
+ (vp/receive-from mb exit-queue prn)))))
Please sign in to comment.
Something went wrong with that request. Please try again.