stopping servers

296 views
Skip to first unread message

Eric Harris-Braun

unread,
Sep 14, 2011, 6:01:42 PM9/14/11
to Aleph
Hi, I can't figure out from the docs what the correct way to stop a
server is.

in aleph.core I see a def-protocol for stop-server-immediately and
stop-server, but when I call either of those functions for the server
returned by start-http-server, I get:

java.lang.IllegalArgumentException: No implementation of method: :stop-
server-immediately of protocol: #'aleph.core/AlephServer found for
class: aleph.http.server$start_http_server$fn__4882

What am I missing?

Thanks,

-e

ztellman

unread,
Sep 14, 2011, 6:44:56 PM9/14/11
to Aleph
The value returned by start-http-server is a function that can be
called to stop the server.

(def s (start-http-server handler {:port 8080}))
(s) ;; stops the server

In beta2, stop-server-immediately will also work.

Zach

Eric Harris-Braun

unread,
Sep 14, 2011, 10:23:18 PM9/14/11
to Aleph
Thanks!

That's an interesting idea to have the function returned by create-
server be a function that stops the server. Why did you decide to do
that? Is the idea that it could be a generic control function for the
server to which you might send other commands, i.e. like:

(def s (start-http-server handler {:port 8080}))
(s {:cmd :get-statistics})
(s (:cmd :shutdown))
(s {:cmd :pause))

Zach Tellman

unread,
Sep 15, 2011, 2:23:05 PM9/15/11
to alep...@googlegroups.com
It's just a legacy thing. When I first wrote the start-http-server
function, the only thing you could do with the return value was stop
the server, so I just made it a function that stopped the server. You
can do more than one thing now, but the server object still implements
IFn so that invoking it with zero parameters will stop the server.

Zach

Sridhar Ratnakumar (srid)

unread,
Sep 26, 2011, 2:45:23 PM9/26/11
to Aleph


On Sep 14, 3:44 pm, ztellman <ztell...@gmail.com> wrote:
> The value returned by start-http-server is a function that can be
> called to stop the server.
>
>   (def s (start-http-server handler {:port 8080}))
>   (s) ;; stops the server

To make this easy to control from the REPL (where `s` is not always
available), I wrote this:

(def server (atom nil))

(defn initialize []
(if @server
(println "Warning: already initialized")
(do
(println "Starting http://localhost:8080/")
(swap! server (fn [_] (start-http-server
(wrap-ring-handler app-routes)
{:port 8080}))))))

(defn shutdown []
(when @server
(do
(println "Shutting down web server")
(@server)
(swap! server (fn [_] nil)))))

-srid

Juan

unread,
Nov 11, 2011, 1:04:49 AM11/11/11
to Aleph
Thanks,
This code works for starting and stopping http servers, but it doesn't
work when the it uses websockets.
The connection continues to be open even after executing the shutdown
function.
Is there a way to make it work with websocket servers?
Thanks

On Sep 27, 3:45 am, "Sridhar Ratnakumar (srid)"
<sridhar.ra...@gmail.com> wrote:
> On Sep 14, 3:44 pm, ztellman <ztell...@gmail.com> wrote:
>
> > The value returned by start-http-server is a function that can be
> > called to stop the server.
>
> >   (def s (start-http-server handler {:port 8080}))
> >   (s) ;; stops the server
>
> To make this easy to control from the REPL (where `s` is not always
> available), I wrote this:
>
> (def server (atom nil))
>
> (defn initialize []
>   (if @server
>     (println "Warning: already initialized")
>     (do
>       (println "Startinghttp://localhost:8080/")

Zach Tellman

unread,
Nov 12, 2011, 12:11:57 PM11/12/11
to alep...@googlegroups.com
It should work with every kind of server. It's possible this is some
sort of closing handshake issue, what browser are you using?

Zach

Reply all
Reply to author
Forward
0 new messages