/
epmd.clj
94 lines (83 loc) · 2.49 KB
/
epmd.clj
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
(ns clojang.epmd
(:require [clojang.caller :refer [call call!]]
[clojure.java.shell :as shell]
[jiface.epmd :as ji-epmd]
[dire.core :refer [with-handler!]]
[potemkin :refer [import-vars]]))
(defn -epmd-parse-args
[[k v]]
(let [str-val (str v)]
(case k
:debug ["-debug"]
:package-timeout ["-packet_timeout" str-val]
:delay-accept ["-delay_accept" str-val]
:delay-write ["-delay_write" str-val]
:address ["-address" (clojure.string/join "," v)]
:port ["-port" str-val]
:daemon ["-daemon"]
:relaxed-command-check ["-relaxed_command_check"]
:names ["-names"]
:kill ["-kill"]
:stop ["-stop" str-val])))
(defn epmd
"Either start or interact with the Erlang Port Mapper Daemon external (OS)
process needed by JInterface for creating nodes and communicating with other
nodes.
Usage based on documentation here:
* http://erlang.org/doc/man/epmd.html#debug_flags
Notes:
* Single-valued command line arguments expect a `true` value in this
function
* Command line arguments with underscores are keywords with dashes in this
function
Example usage:
```
clojang.dev=> (epmd :names true)
epmd: up and running on port 4369 with data:
name clojang at port 33681
name clojang-lfe at port 40968
name rabbit at port 25672
:ok
```"
[& {:as args}]
(->> args
(map -epmd-parse-args)
(flatten)
(cons "epmd")
(apply shell/sh)
:out
(print))
:ok)
(defn- -parse-name
[result]
(->> result
(re-matches #"name (.*) at port (.*)")
(#(vector (get % 1) (Integer/parseInt (get % 2))))))
(defn- -parse-names [results]
(->> results
(map -parse-name)
vec))
(defn lookup-names
([]
(->> (call ji-epmd/lookup-names)
(-parse-names)))
([inet-addr-str]
(->> (java.net.InetAddress/getByName inet-addr-str)
(call ji-epmd/lookup-names)
(-parse-names)))
([inet-addr-str transport]
(->> (java.net.InetAddress/getByName inet-addr-str)
(into [transport])
(call ji-epmd/lookup-names)
(-parse-names))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Aliases ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(import-vars
[ji-epmd
;; epmd
;; lookup-names -- see above
lookup-port
publish-port
unpublish-port
use-port])