diff --git a/apps/htoad/rebar.config b/apps/htoad/rebar.config index e14b5d6..012f24b 100644 --- a/apps/htoad/rebar.config +++ b/apps/htoad/rebar.config @@ -2,7 +2,7 @@ [ {lager, ".*", {git, "https://github.com/basho/lager.git", {branch, "master"}}}, {esupervisor, ".*", {git, "https://github.com/spawngrid/esupervisor.git", {branch, "master"}}}, - {seresye, ".*", {git, "https://github.com/spawngrid/seresye.git", {branch, "alterline"}}}, + {seresye, ".*", {git, "https://github.com/afiniate/seresye.git", {branch, "master"}}}, {getopt, ".*", {git, "https://github.com/jcomellas/getopt.git", {branch, "master"}}}, {dynamic_compile, ".*", {git, "https://github.com/spawngrid/dynamic_compile", {branch, "master"}}}, {erlydtl, ".*", {git, "https://github.com/evanmiller/erlydtl.git", {branch, "master"}}}, diff --git a/apps/htoad/src/htoad.app.src b/apps/htoad/src/htoad.app.src index 9d952d0..1a9cb57 100644 --- a/apps/htoad/src/htoad.app.src +++ b/apps/htoad/src/htoad.app.src @@ -19,7 +19,8 @@ ]}, {mod, { htoad_app, []}}, {env, [ - {trace, [{htoad_trace_ets, []}]}, + {engine_dump, "data/engine"}, + {trace, [{htoad_trace_ets, []}, {htoad_engine_dump, []}]}, {modules, [ htoad_base, diff --git a/apps/htoad/src/htoad_engine_dump.erl b/apps/htoad/src/htoad_engine_dump.erl new file mode 100644 index 0000000..9e6a291 --- /dev/null +++ b/apps/htoad/src/htoad_engine_dump.erl @@ -0,0 +1,109 @@ +-module(htoad_engine_dump). + +-behaviour(gen_event). + +%% gen_event callbacks +-export([init/1, handle_event/2, handle_call/2, + handle_info/2, terminate/2, code_change/3]). + +-define(SERVER, ?MODULE). + +-record(state, { filename }). + +%%%=================================================================== +%%% gen_event callbacks +%%%=================================================================== + +%%-------------------------------------------------------------------- +%% @private +%% @doc +%% Whenever a new event handler is added to an event manager, +%% this function is called to initialize the event handler. +%% +%% @spec init(Args) -> {ok, State} +%% @end +%%-------------------------------------------------------------------- +init([]) -> + {ok, EngineDump} = application:get_env(htoad, engine_dump), + Filename = EngineDump ++ "." ++ atom_to_list(node()), + {ok, #state{ filename = Filename }}. + +%%-------------------------------------------------------------------- +%% @private +%% @doc +%% Whenever an event manager receives an event sent using +%% gen_event:notify/2 or gen_event:sync_notify/2, this function is +%% called for each installed event handler to handle the event. +%% +%% @spec handle_event(Event, State) -> +%% {ok, State} | +%% {swap_handler, Args1, State1, Mod2, Args2} | +%% remove_handler +%% @end +%%-------------------------------------------------------------------- +handle_event({rule, Engine, _Fun, _Args}, #state{ filename = Filename } = State) -> + Bin = term_to_binary(seresye_engine:serialize(Engine)), + file:write_file(Filename, Bin), + {ok, State}; +handle_event(_, #state{} = State) -> + {ok, State}. +%%-------------------------------------------------------------------- +%% @private +%% @doc +%% Whenever an event manager receives a request sent using +%% gen_event:call/3,4, this function is called for the specified +%% event handler to handle the request. +%% +%% @spec handle_call(Request, State) -> +%% {ok, Reply, State} | +%% {swap_handler, Reply, Args1, State1, Mod2, Args2} | +%% {remove_handler, Reply} +%% @end +%%-------------------------------------------------------------------- +handle_call(_Request, State) -> + Reply = ok, + {ok, Reply, State}. + +%%-------------------------------------------------------------------- +%% @private +%% @doc +%% This function is called for each installed event handler when +%% an event manager receives any other message than an event or a +%% synchronous request (or a system message). +%% +%% @spec handle_info(Info, State) -> +%% {ok, State} | +%% {swap_handler, Args1, State1, Mod2, Args2} | +%% remove_handler +%% @end +%%-------------------------------------------------------------------- +handle_info(_Info, State) -> + {ok, State}. + +%%-------------------------------------------------------------------- +%% @private +%% @doc +%% Whenever an event handler is deleted from an event manager, this +%% function is called. It should be the opposite of Module:init/1 and +%% do any necessary cleaning up. +%% +%% @spec terminate(Reason, State) -> void() +%% @end +%%-------------------------------------------------------------------- +terminate(_Reason, _State) -> + ok. + +%%-------------------------------------------------------------------- +%% @private +%% @doc +%% Convert process state when code is changed +%% +%% @spec code_change(OldVsn, State, Extra) -> {ok, NewState} +%% @end +%%-------------------------------------------------------------------- +code_change(_OldVsn, State, _Extra) -> + {ok, State}. + +%%%=================================================================== +%%% Internal functions +%%%=================================================================== diff --git a/apps/htoad/src/htoad_sup.erl b/apps/htoad/src/htoad_sup.erl index 05296c0..7eb617d 100644 --- a/apps/htoad/src/htoad_sup.erl +++ b/apps/htoad/src/htoad_sup.erl @@ -18,7 +18,16 @@ start_link(Args) -> esupervisor:start_link({local, ?MODULE}, ?MODULE, [Args]). start_seresye() -> - {ok, Pid} = seresye:start(?ENGINE), + {ok, EngineDump} = application:get_env(htoad, engine_dump), + EngineFilename = EngineDump ++ "." ++ atom_to_list(node()), + case filelib:is_regular(EngineFilename) of + true -> + lager:debug("Restoring engine from ~s", [EngineFilename]), + {ok, B} = file:read_file(EngineFilename), + {ok, Pid} = seresye:start(?ENGINE, binary_to_term(B)); + false -> + {ok, Pid} = seresye:start(?ENGINE) + end, seresye:set_hooks(?ENGINE,[{before_rule, fun htoad_trace:rule/3}]), {ok, Pid}. diff --git a/deps/dynamic_compile/ebin/dynamic_compile.beam b/deps/dynamic_compile/ebin/dynamic_compile.beam new file mode 100644 index 0000000..1b5f9b0 Binary files /dev/null and b/deps/dynamic_compile/ebin/dynamic_compile.beam differ diff --git a/deps/erlware_commons/ebin/ec_assoc_list.beam b/deps/erlware_commons/ebin/ec_assoc_list.beam new file mode 100644 index 0000000..e5e9f6b Binary files /dev/null and b/deps/erlware_commons/ebin/ec_assoc_list.beam differ diff --git a/deps/erlware_commons/ebin/ec_date.beam b/deps/erlware_commons/ebin/ec_date.beam new file mode 100644 index 0000000..cbe7021 Binary files /dev/null and b/deps/erlware_commons/ebin/ec_date.beam differ diff --git a/deps/erlware_commons/ebin/ec_dict.beam b/deps/erlware_commons/ebin/ec_dict.beam new file mode 100644 index 0000000..b2eb3a6 Binary files /dev/null and b/deps/erlware_commons/ebin/ec_dict.beam differ diff --git a/deps/erlware_commons/ebin/ec_dictionary.beam b/deps/erlware_commons/ebin/ec_dictionary.beam new file mode 100644 index 0000000..0acaa4b Binary files /dev/null and b/deps/erlware_commons/ebin/ec_dictionary.beam differ diff --git a/deps/erlware_commons/ebin/ec_file.beam b/deps/erlware_commons/ebin/ec_file.beam new file mode 100644 index 0000000..4a8ccb8 Binary files /dev/null and b/deps/erlware_commons/ebin/ec_file.beam differ diff --git a/deps/erlware_commons/ebin/ec_gb_trees.beam b/deps/erlware_commons/ebin/ec_gb_trees.beam new file mode 100644 index 0000000..625d0c0 Binary files /dev/null and b/deps/erlware_commons/ebin/ec_gb_trees.beam differ diff --git a/deps/erlware_commons/ebin/ec_lists.beam b/deps/erlware_commons/ebin/ec_lists.beam new file mode 100644 index 0000000..55fa63e Binary files /dev/null and b/deps/erlware_commons/ebin/ec_lists.beam differ diff --git a/deps/erlware_commons/ebin/ec_orddict.beam b/deps/erlware_commons/ebin/ec_orddict.beam new file mode 100644 index 0000000..656486c Binary files /dev/null and b/deps/erlware_commons/ebin/ec_orddict.beam differ diff --git a/deps/erlware_commons/ebin/ec_plists.beam b/deps/erlware_commons/ebin/ec_plists.beam new file mode 100644 index 0000000..e37fd95 Binary files /dev/null and b/deps/erlware_commons/ebin/ec_plists.beam differ diff --git a/deps/erlware_commons/ebin/ec_rbdict.beam b/deps/erlware_commons/ebin/ec_rbdict.beam new file mode 100644 index 0000000..0eb4c96 Binary files /dev/null and b/deps/erlware_commons/ebin/ec_rbdict.beam differ diff --git a/deps/erlware_commons/ebin/ec_semver.beam b/deps/erlware_commons/ebin/ec_semver.beam new file mode 100644 index 0000000..7006849 Binary files /dev/null and b/deps/erlware_commons/ebin/ec_semver.beam differ diff --git a/deps/erlware_commons/ebin/ec_string.beam b/deps/erlware_commons/ebin/ec_string.beam new file mode 100644 index 0000000..1c6c5d5 Binary files /dev/null and b/deps/erlware_commons/ebin/ec_string.beam differ diff --git a/deps/erlware_commons/ebin/ec_talk.beam b/deps/erlware_commons/ebin/ec_talk.beam new file mode 100644 index 0000000..6a808c4 Binary files /dev/null and b/deps/erlware_commons/ebin/ec_talk.beam differ diff --git a/deps/getopt/ebin/getopt.app b/deps/getopt/ebin/getopt.app new file mode 100644 index 0000000..3b4eecb --- /dev/null +++ b/deps/getopt/ebin/getopt.app @@ -0,0 +1,6 @@ +{application,getopt, + [{description,"Command-line options parser for Erlang"}, + {vsn,"0.4.3"}, + {modules,[getopt]}, + {registered,[]}, + {applications,[kernel,stdlib]}]}. diff --git a/deps/seresye/src/seresye.erl b/deps/seresye/src/seresye.erl index fdb42b6..e13ed75 100644 --- a/deps/seresye/src/seresye.erl +++ b/deps/seresye/src/seresye.erl @@ -102,7 +102,7 @@ start_link(Name) when is_atom(Name) -> start_link(ClientState) when not is_atom(ClientState) -> gen_server:start_link(?MODULE, [ClientState], []). -start_link(ClientState, Name) when is_atom(Name) -> +start_link(Name, ClientState) when is_atom(Name) -> gen_server:start_link({local, Name}, ?MODULE, [ClientState], []). diff --git a/rel/reltool.config b/rel/reltool.config index f2805b9..5f15a54 100644 --- a/rel/reltool.config +++ b/rel/reltool.config @@ -26,6 +26,7 @@ {overlay, [ {mkdir, "log/sasl"}, + {mkdir, "data"}, {copy, "files/erl", "\{\{erts_vsn\}\}/bin/erl"}, {copy, "files/nodetool", "\{\{erts_vsn\}\}/bin/nodetool"}, {copy, "files/htoad", "bin/htoad"},