May 2015
Intermediate to advanced
274 pages
5h 11m
English
When the WebSocket is closed, Play automatically stops the actor bound to it. This binding works in two ways: the WebSocket connection is closed when the underlying actor is killed. If there is a need to free any resources once the connection is closed, we can do so by overriding the actor's postStop method. In our example, we have initialized a DBActor within WebSocketChannel. We will need to ensure that it's killed once the WebSocket is closed, since each connection to the WebSocket will lead to the initialization of a DBActor. We can do so by sending it a poison pill, as shown here:
override def postStop() = {
backend ! PoisonPill
}Suppose that an incoming JSON has the same fields for every request, instead ...
Read now
Unlock full access