aerial.utils.misc
General utility functions and macros. Basically these resources
are fairly general and intended to be usable on most any part of
most any project
catch-all
macro
(catch-all & forms)
FORMS wrapped by handlers and last ditch try/catch for standard exceptions.
For conditions, the condition info meta data map is returned. For exceptions,
the exception is converted to a string representation and that is returned.
cpu-use
(cpu-use & {:keys [info], :or {info :idle}})
Obtain and return cpu utilization. Requires the 'top' command is
available, and takes the second of two samplings (first samples
from top are typically inaccurate). INFO indicates the type of
information returned:
:idle, just the avg % idle, this is the default
:used, just the avg % used
:both, both idle and used
In all cases uses aggregate cpu utilization over SMP systems.
Values are returned as Doubles, or for :both, a two element vector
of Doubles [idle used].
defnk
macro
(defnk name & args-body)
defparameter
macro
(defparameter sym val)
(defparameter mmap sym val)
def with auto declaration of symbol SYM to be dynamic
gen-kwuid
(gen-kwuid)
Generates a unique keyword id whose name is the str of gen-uid
gen-uid
(gen-uid)
Generates a unique integer ID based on universal time.
getenv
(getenv ev)
(getenv)
Return the value of the environment variable EV (a string).
Optionally, (no argument variant) return a map of all the
environment variables.
handler-case
macro
(handler-case form & cases)
Hide some try+ details. Form is the expression that is exception
protected. Cases are handler arms of the form [c e & body]. Where
c is the predicate for the case arm (with out preceding 'catch'), e
is the variable (symbol) to hold the exception object and body is
the set of forms to execute. Within body, the captured symbol
contextMap is holds the exception context map.
host-dns-name
(host-dns-name)
host-ipaddress
(host-ipaddress)
Obtain the host IP addresses (:inet4 and :inet6) for the machine on
which we are running. Returns a map of interfaces filtered for
being up, non virtual, and not the loopback, and their associated
vector of inet6 and inet4 addresses. For example:
{:eth0 {:inet6 ["fe80:0:0:0:225:90ff:fe21:66d2%2"],
:inet4 ["136.167.54.82"]}}
name-with-attrs
(name-with-attrs name macro-args)
raise
macro
(raise & args)
Wraps throw+ for throwing a map object. Ensures that (count args)
is even, then places pairs into a map which is given to throw+
runx
(runx program & args)
RUNs an eXternal program PROGRAM (a string naming the program executable),
passing it the (typically, _command line_) arguments ARGS. ARGS is either
a single vector or list of the arguments, or a sequential list of the
arguments given to the function as further arguments after the program.
self-process-id
(self-process-id)
Return the process id of the running JVM. Uses ManagementFactory
getRuntimeMXBean, which has a getName method. The getName method
will _likely_ return name as: <pid>@<host-name>, as a string. This
method then pulls off the pid from this and returns it as a string.
str-date
(str-date)
(str-date fm)
(str-date d fm)
sys-properties
(sys-properties)
sys-property
(sys-property prop-name)
timefn
(timefn f & args)
Time the application of F (a function) to ARGS (any set of args as
expected by f. Returns a two element vector [ret time] where,
ret is the return value of f
time is the time f took to compute ret in milliseconds
with-ckd
macro
(with-ckd & forms)
FORMS wrapped by handlers and last ditch try/catch for standard exceptions.
For conditions, the condition info meta data map is returned. For exceptions,
the exception is converted to a string representation and that is returned.
with-handled
macro
(with-handled form & conditions)
Wraps FORM in a slingshot try+ with catch arms for each condition
in CONDITIONS. Each handle arm catches the condition C and prints a
stack trace for it. Hence, while this catches the conditions, it
stops execution. For catch and continue see CATCH-ALL