Permalink
Browse files

Adds seresye_engine:cleanup/1 that will delete engine's ETS tables

  • Loading branch information...
1 parent 2d0c7a2 commit 5d6e626fc83f67e2a20d06ce2902c570277885ee Yurii Rashkovskii committed Mar 4, 2012
Showing with 5 additions and 1 deletion.
  1. +5 −1 src/seresye_engine.erl
View
6 src/seresye_engine.erl
@@ -24,7 +24,7 @@
%% External exports
%%====================================================================
--export([new/0, new/1, serialize/1, restore/1,
+-export([new/0, new/1, serialize/1, restore/1, cleanup/1,
set_hooks/2, get_fired_rule/1,
add_rules/2, add_rule/2, add_rule/3, assert/2, get_kb/1,
get_rules_fired/1, get_client_state/1, set_client_state/2,
@@ -51,6 +51,10 @@ set_client_state(EngineState, NewState) ->
get_client_state(#seresye{client_state=State}) ->
State.
+cleanup(#seresye{ alfa = Alfa0, join = Join0 }) ->
+ [ begin (catch ets:delete(Tab)), Tab end || {_, Tab, _} <- Alfa0 ] ++
+ [ begin (catch ets:delete(Tab)), Tab end || {{Tab, _}, _, _, _, _} <- Join0, is_integer(Tab) ].
+
restore(#seresye{ alfa = Alfa0, join = Join0 } = Engine) ->
TabCache = ets:new(tab_cache, []),
Alfa = [ {Cond, restore_tab(TabCache, Tab), Alfa_fun}

0 comments on commit 5d6e626

Please sign in to comment.