Fork me on GitHub
#clojure
<
2022-07-20
>
Colin P. Hill13:07:24

Cloistered JVM dev here: On the non-JVM hosts of Clojure, are there concepts parallel to system properties? Is there a platform-agnostic alternative to System/getProperty? EDIT: Fell prey to the X Y problem. What I really want to know is: Is there a runtime-agnostic way to get the name of the logged in (OS) user?

Colin P. Hill13:07:23

Maybe I should specify further that I'm fetching "user.name".

jumar13:07:09

Nothing in Clojure that I know about. This is deeply specific to the runtime

Ed15:07:44

On a UNIX system the USER env var will probably contain the name of the user the process is running as.

👍 1
Colin P. Hill15:07:23

I think, given a dilemma between them, I'll prefer OS-agnostic over runtime-agnostic

jumar15:07:35

Then System/getProperty :)

dsp14:07:18

Hi folks. I'm trying to include an external jar dependency via lein uberjar, so I can run with java -jar, and it does not seem to work despite it working fine with lein repl. Am including via:

:resource-paths ["resources/openrq-3.3.2.jar"]
Compilation proceeds fine.
❯ unzip -l standalone.jar|grep openrq
   283205  2021-12-08 06:32   openrq-3.3.2.jar
However, when running with java -jar standalone.jar I receive a stacktrace, with:
Caused by: java.lang.ClassNotFoundException: net.fec.openrq.OpenRQ
Any ideas of what I'm doing wrong?

rolt15:07:34

you're putting a jar in a jar, shouldn't you be adding the content of the jar (the class files) ?

dsp15:07:30

I don't know. I just type lein uberjar. Works fine with repl as I said, do I need special configuration beyond what I already have above?

dsp16:07:00

(it is lein uberjar that is adding the resource in btw)

dsp16:07:01

With resource-paths it's plenty to work with at repl, just wondered what else I need. Googling starts talking about local maven repositories and other such magic but I suspect there must be a simpler path.

rolt16:07:20

i can think of 2 ways to do it: using a local maven repo or copying the content of the jar in the uberjar (there may be some files to skip)

rolt16:07:18

i don't think there is a simpler path, but maybe some lein plugins already exist for that

dsp16:07:10

Thanks, I'll take a look and have a go later.

emccue18:07:53

deps.edn supports this

dsp23:07:52

Adding the jar contents manually worked. Thanks! I'll see if I can find some way to automate it. Proper deps.edn knowledge still on my todo-list (my legacy projects are all still lein)

mwolf20:07:13

apparently I misunderstand refs and STM. I have two streams of key/value records that are being processed by separate threads, and each thread has a simple cache (ref {}) associated with it. if a thread reads a record that isn't in the other thread's cache, it stores the key/value pair in its cache and returns []. if the key is found in the other thread's cache, that entry is removed and [v v2] is returned, where v is this thread's value and v2 is the value from the other cache. (the idea is to process two potentially unordered streams in parallel to determine where they match/don't match.) the test code I hacked up is, as usually happens when writing async code, inconsistent: sometimes one thread returns both values, other times a value ends up in one cache. here's the code:

(let [k :k
        v "value"]
    (defn check
      [cache k v other-cache]
      (dosync
       (if (contains? @other-cache k)
         (let [v2 (get @other-cache k)]
           (alter other-cache dissoc k)
           [v v2])
         (do
           (alter cache assoc k v)
           []))))
    (let [cache1 (ref {})
          ch1 (chan)
          cache2 (ref {})
          ch2 (chan)]
      (go (>! ch1 (check cache1 k v cache2)))
      (go (>! ch2 (check cache2 k v cache1)))
      {:cache1 @cache1 :result1 (<!! ch1) :cache2 @cache2 :result2 (<!! ch2)}))
since both threads are processing the same key/value, this hack should consistently return cache1 and cache2 empty and either result1 or result2 should be ["value" "value"] .... but that's not happening. any ideas on what I'm borking up?

hiredman20:07:42

you need to use ensure instead of deref

mwolf20:07:05

checking that ...

hiredman20:07:06

I don't use the stm much, but if I recall deref in a transaction is stable, in that multiple derefs of the same ref in a transaction will always return the in transaction value of the ref, but at the point the transaction commits, a deref that would have gotten a different value at that point in time will not cause the transaction to retry

hiredman20:07:40

this can cause one of the skews, maybe read skew?

mwolf20:07:17

I suspected there might be something up with the STM machinery not correctly recognizing the @cache read or something similar.

hiredman20:07:30

for what it is worth, I would use a single atom for this

hiredman20:07:51

(which is why I don't end up using the stm much)

mwolf20:07:49

I thought about atoms, but stm/refs seemed like a better fit with two threads banging on two separate data structures. if ensure works, then all is cool, otherwise atoms are an option -- this isn't long-term production code, just a hack to monitor streams during system migration to a new data center. thanks --

hiredman20:07:25

if your transaction always includes the refs "from" both threads, then you've gone from 2 threads banging on one atom, to two threads banging on two refs