aboutsummaryrefslogtreecommitdiff
path: root/lib/octonetcat/server_supervisor.ex
diff options
context:
space:
mode:
authorkballou <kballou@devnulllabs.io>2017-11-24 10:16:06 -0700
committerkballou <kballou@devnulllabs.io>2017-11-24 10:22:44 -0700
commit9bae951c555f9c25876968fa98853253b7007a0f (patch)
tree9bdae36c1344d5c9d4d667bb218b729340d0ed90 /lib/octonetcat/server_supervisor.ex
parent3af086d168975a4122cee80c955da03516f55571 (diff)
downloadoctonetcat-9bae951c555f9c25876968fa98853253b7007a0f.tar.gz
octonetcat-9bae951c555f9c25876968fa98853253b7007a0f.tar.xz
Level up the Echo Server0.3.0
This should enable the upgrade process to retain connections - Replace our simple task supervisor with a custom `simple_one_for_one` supervisor - Upgrade the echo server to use a `GenServer` behaviour
Diffstat (limited to 'lib/octonetcat/server_supervisor.ex')
-rw-r--r--lib/octonetcat/server_supervisor.ex23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/octonetcat/server_supervisor.ex b/lib/octonetcat/server_supervisor.ex
new file mode 100644
index 0000000..7aa8e37
--- /dev/null
+++ b/lib/octonetcat/server_supervisor.ex
@@ -0,0 +1,23 @@
+defmodule Octonetcat.ServerSupervisor do
+ @moduledoc """
+ Simple One-for-One Supervisor for Socket servers
+ """
+
+ use Supervisor
+
+ def start_link do
+ Supervisor.start_link(__MODULE__, :ok, name: __MODULE__)
+ end
+
+ def init(:ok) do
+ children = [
+ worker(Octonetcat.Echo, [], restart: :temporary)
+ ]
+
+ supervise(children, strategy: :simple_one_for_one)
+ end
+
+ def start_server(socket) do
+ Supervisor.start_child(__MODULE__, [socket])
+ end
+end