Compare commits
No commits in common. "ea03dccf53bb7e9dac9e6c8d3aafef1df84874a3" and "8951df42824420cae2464e77f17c63a7651f2d96" have entirely different histories.
ea03dccf53
...
8951df4282
7 changed files with 8 additions and 65 deletions
|
|
@ -11,13 +11,11 @@ defmodule Scopes.CSys.Application do
|
||||||
def start(type, args) do
|
def start(type, args) do
|
||||||
IO.puts("Hello CSys")
|
IO.puts("Hello CSys")
|
||||||
Logger.info(Util.show [type, args])
|
Logger.info(Util.show [type, args])
|
||||||
# input_neurons = Environ.create_input
|
|
||||||
IO.inspect Scopes.CSys.Server.Endpoint.child_spec(input: %{[:csys, :s01] => "dummy"})
|
|
||||||
children = [
|
children = [
|
||||||
#Scopes.CSys.Server.Endpoint
|
#Scopes.Web.Server.Endpoint
|
||||||
{Scopes.CSys.Server.Endpoint, input: %{[:csys, :s01] => "dummy"}}
|
Scopes.CSys.Server.Endpoint
|
||||||
]
|
]
|
||||||
opts = [strategy: :one_for_one, name: Scopes.CSys.Supervisor]
|
opts = [strategy: :one_for_one, name: Scopes.Supervisor]
|
||||||
Supervisor.start_link(children, opts)
|
Supervisor.start_link(children, opts)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,6 @@
|
||||||
defmodule Scopes.CSys.Server.Endpoint do
|
defmodule Scopes.CSys.Server.Endpoint do
|
||||||
use Phoenix.Endpoint, otp_app: :scopes_csys
|
use Phoenix.Endpoint, otp_app: :scopes_csys
|
||||||
|
|
||||||
def init(arg) do
|
|
||||||
IO.inspect(arg)
|
|
||||||
IO.inspect(Process.get())
|
|
||||||
:ignore
|
|
||||||
end
|
|
||||||
|
|
||||||
plug Plug.Static,
|
plug Plug.Static,
|
||||||
at: "/",
|
at: "/",
|
||||||
from: :scopes_csys,
|
from: :scopes_csys,
|
||||||
|
|
@ -21,6 +15,5 @@ defmodule Scopes.CSys.Server.Endpoint do
|
||||||
pass: ["*/*"],
|
pass: ["*/*"],
|
||||||
json_decoder: Phoenix.json_library()
|
json_decoder: Phoenix.json_library()
|
||||||
|
|
||||||
plug Scopes.CSys.Server.Router
|
plug Scopes.Web.Server.Router
|
||||||
#input_neurons: @input
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
defmodule Scopes.CSys.Server.Router do
|
|
||||||
use Scopes.Web.Server, :router
|
|
||||||
|
|
||||||
pipeline :api do
|
|
||||||
plug :accepts, ["json"]
|
|
||||||
end
|
|
||||||
|
|
||||||
scope "/api", Scopes.CSys.Server do
|
|
||||||
pipe_through :api
|
|
||||||
match :*, "/csys/:action/s01/:item", Controller, :index
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
defmodule Scopes.CSys.Server.Controller do
|
|
||||||
use Scopes.Web.Server, :controller
|
|
||||||
|
|
||||||
def index(conn, params) do
|
|
||||||
# input_neuron = Environ.get_input(:csys, :s01)
|
|
||||||
json(conn, params)
|
|
||||||
#render(conn, :index, message: "Hello CSys")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
@ -10,9 +10,6 @@ defmodule Scopes.Core.Actor do
|
||||||
bhv.(msg)
|
bhv.(msg)
|
||||||
loop(bhv)
|
loop(bhv)
|
||||||
{:become, bhv_n} -> loop(bhv_n)
|
{:become, bhv_n} -> loop(bhv_n)
|
||||||
{:register, reg, name, value} ->
|
|
||||||
Registry.register(reg, name, value)
|
|
||||||
loop(bhv)
|
|
||||||
{:quit} -> nil
|
{:quit} -> nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -22,12 +19,6 @@ defmodule Scopes.Core.Actor do
|
||||||
spawn_link(fn -> loop(bhv) end)
|
spawn_link(fn -> loop(bhv) end)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create(bhv, reg, name, value \\ []) do
|
|
||||||
spawn_link(fn ->
|
|
||||||
Registry.register(reg, name, value)
|
|
||||||
loop(bhv) end)
|
|
||||||
end
|
|
||||||
|
|
||||||
def send(ac, msg, delay \\ 0) do
|
def send(ac, msg, delay \\ 0) do
|
||||||
if msg do
|
if msg do
|
||||||
Process.sleep(delay)
|
Process.sleep(delay)
|
||||||
|
|
@ -39,10 +30,6 @@ defmodule Scopes.Core.Actor do
|
||||||
Kernel.send(ac, {:become, bhv})
|
Kernel.send(ac, {:become, bhv})
|
||||||
end
|
end
|
||||||
|
|
||||||
def register(ac, reg, name, value \\ []) do
|
|
||||||
Kernel.send(ac, {:register, reg, name, value})
|
|
||||||
end
|
|
||||||
|
|
||||||
def stop(ac) do
|
def stop(ac) do
|
||||||
Kernel.send(ac, {:quit})
|
Kernel.send(ac, {:quit})
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,8 @@ defmodule Scopes.Web.Server.ErrorJSON do
|
||||||
# By default, Phoenix returns the status message from
|
# By default, Phoenix returns the status message from
|
||||||
# the template name. For example, "404.json" becomes
|
# the template name. For example, "404.json" becomes
|
||||||
# "Not Found".
|
# "Not Found".
|
||||||
def render(template, resp) do
|
def render(template, assigns) do
|
||||||
message = resp.reason.message
|
message = assigns.reason.message
|
||||||
Logger.warning(Util.show [message])
|
Logger.warning(Util.show [message])
|
||||||
%{errors: %{detail: Phoenix.Controller.status_message_from_template(template)}}
|
%{errors: %{detail: Phoenix.Controller.status_message_from_template(template)}}
|
||||||
end
|
end
|
||||||
|
|
|
||||||
7
mix.exs
7
mix.exs
|
|
@ -17,11 +17,8 @@ defmodule Scopes.MixProject do
|
||||||
# Run "mix help compile.app" to learn about applications.
|
# Run "mix help compile.app" to learn about applications.
|
||||||
def application do
|
def application do
|
||||||
[
|
[
|
||||||
mod: {Scopes.Application, []},
|
#mod: {Scopes.Application, []},
|
||||||
extra_applications: [:logger, :runtime_tools],
|
extra_applications: [:logger, :runtime_tools]
|
||||||
env: [
|
|
||||||
serve_endpoints: false
|
|
||||||
]
|
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,19 +4,10 @@ defmodule Scopes.CoreActorTest do
|
||||||
|
|
||||||
describe "actors:" do
|
describe "actors:" do
|
||||||
test "basic-life-cycle" do
|
test "basic-life-cycle" do
|
||||||
Registry.start_link(keys: :unique, name: Actors)
|
|
||||||
this = self()
|
this = self()
|
||||||
|
|
||||||
ac = Actor.create(fn msg -> send(this, msg) end)
|
ac = Actor.create(fn msg -> send(this, msg) end)
|
||||||
Actor.register(ac, Actors, :demo, [])
|
|
||||||
# or: ac = Actor.create(fn msg -> send(this, msg) end, Actors, :demo)
|
|
||||||
|
|
||||||
Actor.send(ac, "Hello Actor!")
|
Actor.send(ac, "Hello Actor!")
|
||||||
assert_receive "Hello Actor!"
|
assert_receive "Hello Actor!"
|
||||||
|
|
||||||
[{pid, _value}] = Registry.lookup(Actors, :demo)
|
|
||||||
assert pid == ac
|
|
||||||
|
|
||||||
Actor.become(ac, fn _msg -> send(this, "Goodbye") end)
|
Actor.become(ac, fn _msg -> send(this, "Goodbye") end)
|
||||||
Actor.send(ac, "Hello Actor!")
|
Actor.send(ac, "Hello Actor!")
|
||||||
Actor.stop(ac)
|
Actor.stop(ac)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue