component

2016-04-14T21:08:33.000063Z

hello, I have a system which contains two subsystems as children.. i’d ideally like to pass a common ‘database’ component to both subsystems, which those subsystems will pass into the components they contain.. is there a recommended way to handle that?

sveri 2016-04-14T21:29:59.000064Z

@keeth: Not sure if I understand your question correctly, but I pass my db like this: https://github.com/sveri/closp/blob/master/resources/leiningen/new/closp/clj/components/components.clj you can see the config component passed to two different components. AFAIU you can compose them as you want.

2016-04-14T21:31:43.000066Z

@sveri: thanks the main thing i am trying to avoid is the component being started and stopped more than once

2016-04-14T21:32:54.000067Z

i think i have a solution, producing a System implementation that allows to exclude certain components from being started and stopped by the system

2016-04-14T21:33:59.000068Z

thankfully component/(start|stop)-system lets you override the keys to be stopped/started, so i don’t have to re-implement too much of system

sveri 2016-04-14T21:35:03.000069Z

@keeth: Yea, the thing is, if you cannot restart a component n times, it is not a component anymore (thats my understanding, others may see this different). So you need to find a different solution to it. Out of interest, what is it that cannot be restarted?

2016-04-14T21:35:57.000071Z

it’s not that it can’t be restarted, but if I pass it to two different subsystems as dependencies, (.start db) will be called twice when the app starts up

sveri 2016-04-14T21:37:13.000072Z

I dont grok fully yet what you are doing. But a component, should only be started once, no matter to how many other components you pass it to. Maybe I dont understand what subsystemis in your case?

2016-04-14T21:42:30.000074Z

i have a top-level system whose system map contains two child systems

2016-04-14T21:42:46.000075Z

the top-level system is also responsible for starting/stopping the db component

2016-04-14T21:44:16.000077Z

so at app start, the top-level/parent system should start the db, and inject it into the child systems, and start the child systems after starting the db

2016-04-14T21:45:29.000078Z

but even tho the child systems will have a :database key in their system maps, i don’t want them to try starting it

sveri 2016-04-14T21:47:06.000079Z

Hm...so you have three systems?

2016-04-14T21:47:19.000080Z

yep, one parent with two children

sveri 2016-04-14T21:47:56.000081Z

Interesting, I never tried that. And the db component is started three times?

2016-04-14T21:48:04.000082Z

currently yes

2016-04-14T21:48:13.000083Z

but i think i almost have it fixed

sveri 2016-04-14T21:48:52.000084Z

I am not sure that component supports that, would be interesting to hear what @stuartsierra has to say about it.

sveri 2016-04-14T21:48:56.000085Z

How did you fix it?

sveri 2016-04-14T21:49:03.000086Z

Conditional start / stop?

2016-04-14T21:50:10.000087Z

see snippet above, i’m made a thin system implementation that allows me to exclude a set of keys of components which i do not want the system to start or stop

sveri 2016-04-14T21:51:10.000088Z

Ah ok, you use that one

2016-04-14T21:51:41.000089Z

usage is something like:

(system/system-map-excluding
      {:component1 (component/using (new-component-1) [:database])}
      #{:database})

2016-04-14T21:52:20.000091Z

anyway, will see in a moment if it works 😬

stuartsierra 2016-04-14T21:54:30.000092Z

Nested systems are complicated and usually unnecessary; I recommend against them.

sveri 2016-04-14T21:56:52.000093Z

Thats my feeling too, sounds like over architecturing

2016-04-14T21:58:07.000094Z

thanks for your feedback guys.. ya I guess since systems implement the same protocol as components, I figured they could be composed together as if they were components