Fork me on GitHub
#beginners
<
2016-03-18
>
jonahbenton00:03:55

hey @jreedmoore the issue with those tends to center around the fact that both spring and aspectj go through a bunch of initialization and instance rewiring that isn't directly visible from the usual repl engagement model, which centers around importing classes on the classpath and then instantiating them. You need to be able to get into the instance graph after all the wiring is done. Do you have a way to do that?

jreedmoore00:03:52

oh so I would need to hook into the Spring machinery to pull out an instance of one of these classes?

jreedmoore00:03:10

there's some like applicationContext.get<blah>Bean method that lets me get singletons right

jreedmoore00:03:38

ugh I am so sorry for other people reading this, it's all very anti-simple

jonahbenton00:03:02

yes- it's been some years but asking a global application context for a named bean rings a bell.

jreedmoore00:03:39

yeah so. I have buy in from my manager to potentially rip this subsystem into a separate jar. I think I'm going to do that rather than beat my head against Spring all week

jreedmoore00:03:37

other approachs I've seen while googling around are basically put another Bean in your application context + object graph that starts up an nREPL and sets a var in user to the application context

jonahbenton00:03:50

yeah- you do need a way to start up an nrepl server, and in a spring app that has to be wired into spring

jonahbenton00:03:30

but once you connect to the repl, you should be able to import the applicationcontext singleton class, and then get the beans from it

sd11:03:55

hi, imagine some state (currently an atom) that’s updated by http POSTs. there’s a chance that more than one request will come in at roughly the same time (within a few seconds), but i only want the first one to update the state and ignore the others - any idea on how to do that?

jonahbenton11:03:03

hey @sd presumably prior to the POSTs clients are issuing GETs regarding the resource in question? In that case, an approach to solve for first-one-in-wins is to keep a token, like a UUID, as part of the atom-maintained state and deliver that token to clients in the GET responses. Clients are to return the token with their POSTs. When you receive the POST, compare the received token with the one in the atom, and ignore the POST if the token doesn't match. If it does match, create a new token and include it in the state change of the atom.

sveri11:03:15

@sd I would add an :updated keyword to the atom and use that as a guard. As long as it is false, you can update the atom, if it is true, you cannot. That will also give you the option to set it to false again some time later.

sd11:03:17

gotcha. so something like (if (= current-token token-from-request) (do (swap! …))

sd11:03:19

basically, this is for an online game where there are two teams, and multiple players on each team (but i only want to accept answers from one player at a time). I will probably keep something like :current-team in the atom and use that for the check

sd11:03:39

i was thinking that i might need to a ref with the conditional update inside a dosync but it’ll be less work to stick with an atom

jonahbenton12:03:03

yup- if the moves on each turn are state dependent, then you probably want a token scheme, but if the moves are stateless, then a :current-team should be enough

sd12:03:10

thanks simple_smile

adamkowalski23:03:07

hey what backend stack do you guys recommend to get started with in clojure?

adamkowalski23:03:29

I know that ring seems to be the main thing people use to abstract away http requests and responses

adamkowalski23:03:41

but what other common libraries should I look into