Hi Sven,

Take out the wrap-reload middleware in your routes.  That's what's causing 
you problems.  You will have to manually call (reset) every time you have a 
code change, but Stuart recommends binding it to a key sequence in you 
editor.

Brendan

On Saturday, August 9, 2014 6:04:03 PM UTC-4, Sven Richter wrote:
>
> Hi,
>
> First I would like to thank everybody for your answers and hints.
>
> I setup a small project you can find here: 
> https://github.com/sveri/component_test
> You can run it with lein repl and then calling (go).
>
> I have three questions/problems for this one:
> 1. Did I separate the handler and the server correctly (I was trying to 
> follow your advices)?
>
> 2. In scheduler.clj I defined a protocol (additionally to the lifecycle 
> protocol) and a record implementing that protocol. I create a new instance 
> of that record and pass it down to the handler and there to the routes. 
> Now, when I open a webpage and go to http://localhost:3000/sched 
> everything works fine.
> Next I edit the add-job function in scheduler.cljs to print something 
> different like this:
> (add-job [this]
>     (println "new sys out"))
> Just a small change is enough. If you go to the webpage again and try to 
> reload it an exception will be thrown:
> Sat Aug 09 23:52:28 CEST 2014 [worker-3] ERROR - GET /sched
> java.lang.IllegalArgumentException: No implementation of method: :add-job 
> of protocol: #'component-test.scheduler/ISched found for class: 
> component_test.schedul
> er.Sched
>         at clojure.core$_cache_protocol_fn.invoke(core_deftype.clj:544)
>         at 
> component_test.scheduler$eval6553$fn__6554$G__6544__6559.invoke(scheduler.clj:6)
>         at component_test.routes$sched_in.invoke(routes.clj:8)
>         at component_test.routes$home_routes$fn__3312.invoke(routes.clj:19)
>         at compojure.core$make_route$fn__2331.invoke(core.clj:99)
>         at compojure.core$if_route$fn__2315.invoke(core.clj:45)
> ...
>
> I dont really understand why that happens and any hints regarding what I 
> am doing wrong would be great. And this leads to my last question.
>
> 3. After having an exception I will usually try to reset the system with: 
> (reset), but in this case (and many different other cases) I will just get 
> another error:
> component-test.user=> (reset)
> :reloading (component-test.scheduler component-test.routes 
> component-test.server component-test.handler component-test.core 
> component-test.user component-test.c
> ore-test)
> ;; Starting HTTP-Kit server on port 3000
>
> BindException Address already in use: bind  sun.nio.ch.Net.bind0 
> (Net.java:-2)
>
> And now all I can do is exit the repl and start it again to get my code 
> running.
>
> This is exactly what I dont want to do all the time and the problem I 
> thought would be solved by the component library, so once more, every hint 
> you have for me will be valuable about what I can do and what not.
>
> Best Regards,
> Sven
>
> Am Freitag, 8. August 2014 13:16:49 UTC+2 schrieb Sven Richter:
>>
>> Hi,
>>
>> I am trying to integrate Stuarts component library into my application. I 
>> am not sure if I use it correctly or do something else wrong or just have a 
>> wrong mindset. So I will explain how I am currently using it and the 
>> problem I see with it.
>>
>> I have three components: database, a scheduler and web application (note 
>> that my example is simplified to get faster to the point). These components 
>> are built like this:
>>
>> (component/system-map
>>       :database (db db-uri)
>>       :scheduler (component/using (scheduler) [:database])
>>       :web-app (component/using (web-app)
>>                                 [:database
>>                                  :scheduler] ))
>>
>> And in my web-app I do something like this:
>>
>> (start [component]
>>     (let [db-conn (get-in web-app [:database :db-conn])]
>>       (assoc component :server
>>                        (run-server (make-handler web-app db-conn) {:port 
>> port}))))
>>
>> And make-handler is a middleware that associates the database component 
>> into the request map.
>>
>> Now as I added the scheduler to my system it occured to me that I will 
>> have to associate the scheduler into the request map too to access it and I 
>> might have to do that for every other component that is coming along the 
>> road.
>> So basically I am tying my web-app to to all these components and I am 
>> tying some components to other components (like scheduler component to the 
>> database component).
>>
>> And by tying this things together this way they do depend on each other 
>> and I cannot move them anymore. This came to my mind as I started thinking 
>> about microservices.
>>
>> So let's say I want to convert the scheduler into a restful microservice, 
>> it's hard to pass in a database connection into it via HTTP, so it seems 
>> like it's not decoupled enough. Does that make sense?
>>
>> Am I using it wrong? Is it ok to pass all kind of dependencies into the 
>> request map and shove it around in the web application? Any other 
>> suggestions / remarks?
>>
>> Best Regards,
>> Sven
>>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to