-
Notifications
You must be signed in to change notification settings - Fork 0
/
abcl-gearman.lisp
35 lines (28 loc) · 1.61 KB
/
abcl-gearman.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
;;;; abcl-gearman.lisp
(in-package #:abcl-gearman)
(let ((gearman-java-jar (asdf:system-relative-pathname "abcl-gearman" "lib/java-gearman-service-0.7.0-SNAPSHOT-jar-with-dependencies.jar")))
(java:add-to-classpath gearman-java-jar))
(defun create-running-worker (function-name
&key (hostname "localhost") (port 4730)
(worker-function (lambda (function data callback)
(declare (ignore function callback))
(print "Worker returning ...")
data)))
"Creates a worker linked to a server in HOST and PORT"
(let* ((gearman (java:jstatic "createGearman" "org.gearman.Gearman"))
(worker (java:jcall "createGearmanWorker" gearman))
(server (java:jcall "createGearmanServer" gearman hostname port)))
(java:jcall "addServer" worker server)
(java:jcall "addFunction" worker function-name
(java:jinterface-implementation "org.gearman.GearmanFunction" "work" worker-function))))
(defun submit-job (function-name &key (hostname "localhost") (port 4730)
(data (java:jnew-array-from-list "byte" '(1 2))))
(let* ((gearman (java:jstatic "createGearman" "org.gearman.Gearman"))
(client (java:jcall "createGearmanClient" gearman))
(server (java:jcall "createGearmanServer" gearman hostname port)))
(java:jcall "addServer" client server)
(java:jcall "submitJob" client function-name data)))
#+nil
(create-running-worker "reverse")
#+nil
(submit-job "reverse")