221V 3 лет назад
Родитель
Сommit
5d0462d076
6 измененных файлов с 85 добавлено и 40 удалено
  1. 3 3
      ebin/n4u.app
  2. 0 9
      src/n2o.app.src
  3. 2 28
      src/n2o.erl
  4. 9 0
      src/n4u.app.src
  5. 15 0
      src/n4u_app.erl
  6. 56 0
      src/n4u_sup.erl

+ 3 - 3
ebin/n4u.app

@@ -2,8 +2,8 @@
   {description, "N2O WebSocket Application Server"},
   {vsn, "4.4.20"},
   {applications, [kernel, stdlib, asn1, public_key, ssl, crypto, ranch, cowboy, fs, active, sh, gproc, nitro]},
-  {modules, [n2o, n2o_async, n2o_xhr, n2o_cx, n2o_cowboy, n2o_multipart, n2o_static, n2o_stream, n2o_document, n2o_proto, n2o_relay, n2o_error, n2o_io, n2o_log, n2o_mq, n2o_pickle, n2o_query, n2o_secret, n2o_session, n2o_syn, n2o_client, n2o_file, n2o_heart, n2o_http, n2o_nitrogen, n2o_text, wf, wf_convert, wf_utils]},
-  {registered, [n2o]},
-  {mod, {n2o, []}},
+  {modules, [n2o, n4u_app, n4u_sup, n2o_async, n2o_xhr, n2o_cx, n2o_cowboy, n2o_multipart, n2o_static, n2o_stream, n2o_document, n2o_proto, n2o_relay, n2o_error, n2o_io, n2o_log, n2o_mq, n2o_pickle, n2o_query, n2o_secret, n2o_session, n2o_syn, n2o_client, n2o_file, n2o_heart, n2o_http, n2o_nitrogen, n2o_text, wf, wf_convert, wf_utils]},
+  {registered, [n4u_sup]},
+  {mod, {n4u_app, []}},
   {env, []}
 ]}.

+ 0 - 9
src/n2o.app.src

@@ -1,9 +0,0 @@
-{application, n2o, [
-    {description,  "N2O WebSocket Application Server"},
-    {vsn,          "4.4.20"},
-    {applications, [kernel, stdlib, cowboy]},
-    {modules, []},
-    {registered,   [n2o]},
-    {mod, { n2o,   []}},
-    {env, []}
-]}.

+ 2 - 28
src/n2o.erl

@@ -1,31 +1,5 @@
 -module(n2o).
--description('N2O OTP Application Server').
--behaviour(supervisor).
 -include_lib("n4u/include/wf.hrl").
--behaviour(application).
--export([start/2, stop/1, init/1, proc/2]).
+-export([test/0]).
 
-tables()   -> [ cookies, actions, globals, caching ].
-opt()      -> [ set, named_table, { keypos, 1 }, public ].
-start(_,_) -> X = supervisor:start_link({local,n2o},n2o,[]),
-              n2o_async:start(#handler{module=?MODULE,class=system,group=n2o,state=[],name="timer"}),
-              X.
-stop(_)    -> ok.
-init([])   -> [ ets:new(T,opt()) || T <- tables() ],
-              case wf:config(n2o,mq) of n2o_syn -> syn:init(); _ -> ok end,
-              { ok, { { one_for_one, 5, 10 }, [] } }.
-
-proc(init,#handler{}=Async) ->
-    wf:info(?MODULE,"Proc Init: ~p~n",[init]),
-    Timer = timer_restart(ping()),
-    {ok,Async#handler{state=Timer}};
-
-proc({timer,ping},#handler{state=Timer}=Async) ->
-    case Timer of undefined -> skip; _ -> erlang:cancel_timer(Timer) end,
-    wf:info(?MODULE,"N2O Timer: ~p~n",[ping]),
-    (wf:config(n2o,session,n2o_session)):invalidate_sessions(),
-    wf:invalidate_cache(),
-    {reply,ok,Async#handler{state=timer_restart(ping())}}.
-
-timer_restart(Diff) -> {X,Y,Z} = Diff, erlang:send_after(1000*(Z+60*Y+60*60*X),self(),{timer,ping}).
-ping() -> application:get_env(n2o,timer,{0,10,0}).
+test() -> ok.

+ 9 - 0
src/n4u.app.src

@@ -0,0 +1,9 @@
+{application, n4u,
+ [{description, "N2O WebSocket Application Server"},
+  {vsn, "4.4.20"},
+  {applications, [kernel, stdlib, cowboy]},
+  {modules, []},
+  {registered, [n4u_sup]},
+  {mod, {n4u_app, []}},
+  {env, []}
+]}.

+ 15 - 0
src/n4u_app.erl

@@ -0,0 +1,15 @@
+-module(n4u_app).
+
+-behaviour(application).
+
+-export([start/2, stop/1]).
+
+
+start(_Type, _Args) ->
+  {ok, _} = application:ensure_all_started(ranch),
+  {ok, _} = application:ensure_all_started(cowboy),
+  
+  n4u_sup:start_link().
+
+
+stop(_State) -> ok.

+ 56 - 0
src/n4u_sup.erl

@@ -0,0 +1,56 @@
+-module(n4u_sup).
+
+-behaviour(supervisor).
+
+-include_lib("n4u/include/wf.hrl").
+
+-export([start_link/0, init/1]).
+-export([proc/2]).
+
+
+ets_tables() -> [ cookies, actions, globals, caching ].
+ets_tables_opts() -> [ set, named_table, { keypos, 1 }, public ].
+
+
+start_link() ->
+  A = supervisor:start_link({local, ?MODULE}, ?MODULE, []),
+  n2o_async:start(#handler{module=?MODULE, class=system, group=?MODULE, state=[], name="timer"}),
+  A.
+
+
+init([]) ->
+  [ ets:new(T, ets_tables_opts()) || T <- ets_tables() ],
+  
+  case application:get_env(n2o, mq, "") of
+    n2o_syn -> syn:init();
+    _ -> ok
+  end,
+  
+  Procs = [],
+  {ok, {{one_for_one, 10, 10}, Procs}}.
+
+
+
+% proc handler for n2o_async:start on line 17
+timer_restart(Diff) ->
+  {X, Y, Z} = Diff,
+  erlang:send_after(1000 * (Z + 60 * Y + 60 * 60 * X), erlang:self(), {timer, ping}).
+
+
+ping() -> application:get_env(n2o, timer, {0, 10, 0}).
+
+
+proc(init, #handler{}=Async) ->
+  wf:info(?MODULE, "Proc Init: ~p~n", [init]),
+  Timer = timer_restart(ping()),
+  {ok, Async#handler{state=Timer}};
+
+proc({timer, ping}, #handler{state=Timer}=Async) ->
+  case Timer of
+    undefined -> skip;
+    _ -> erlang:cancel_timer(Timer)
+  end,
+  wf:info(?MODULE, "n2o Timer: ~p~n", [ping]),
+  (application:get_env(n2o, session, n2o_session)):invalidate_sessions(),
+  wf:invalidate_cache(),
+  {reply, ok, Async#handler{state=timer_restart(ping())}}.