Packages
mongodb_driver
1.6.4
1.6.4
1.6.3
1.6.2
1.6.1
1.6.0
1.5.6
1.5.5
1.5.4
1.5.2
1.5.1
1.5.0
1.4.1
1.4.0
1.2.1
1.2.0
1.1.0
1.0.3
1.0.2
1.0.1
1.0.0
0.9.2
0.9.1
0.9.0
0.9.0-rc.1
0.9.0-rc.0
0.8.4
0.8.3
0.8.2
0.8.1
0.8.0
0.7.4
0.7.3
0.7.2
0.7.1
0.7.0
0.6.5
0.6.4
0.6.3
0.6.2
0.6.1
0.6.0
0.5.7
0.5.6
0.5.5
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
The MongoDB driver for Elixir
Current section
Files
Jump to
Current section
Files
lib/mongo/event_handler.ex
defmodule Mongo.EventHandler do
@moduledoc false
require Logger
@all [:commands, :topology]
def start(opts \\ [topics: [:commands]]) do
spawn(__MODULE__, :register, [opts])
end
def register(opts) do
with true <-
(opts[:topics] || @all)
|> Enum.map(fn topic -> Registry.register(:events_registry, topic, []) end)
|> Enum.all?(fn
{:ok, _} -> true
_other -> false
end) do
listen(opts)
:ok
end
end
def listen(opts) do
receive do
{:broadcast, :commands, %{command_name: cmd} = message} when cmd != :isMaster and cmd != :hello ->
Logger.info("Received command: " <> inspect(message))
listen(opts)
{:broadcast, :commands, hello} ->
case opts[:is_master] || opts[:hello] do
true -> Logger.info("Received hello:" <> inspect(hello))
_ -> []
end
listen(opts)
{:broadcast, topic, message} ->
Logger.info("Received #{topic}: " <> inspect(message))
listen(opts)
other ->
Logger.info("Stopping EventHandler received unknown message:" <> inspect(other))
end
end
end