summaryrefslogtreecommitdiff
path: root/src/io
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2018-04-10 13:01:12 +0200
committernsensfel <SpamShield0@noot-noot.org>2018-04-10 13:01:12 +0200
commit1001c3f6cfefd880c1721f2b80c1795197d05365 (patch)
tree8696137b5684547b80129d308bc854a7e74fa0b0 /src/io
parentd7032b408c5f66a3cb62c44cf0953abe48c39ef9 (diff)
Changing how the server services are organized...
Diffstat (limited to 'src/io')
-rw-r--r--src/io/security.erl33
-rw-r--r--src/io/timed_cache.erl130
-rw-r--r--src/io/timed_caches_manager.erl152
3 files changed, 0 insertions, 315 deletions
diff --git a/src/io/security.erl b/src/io/security.erl
deleted file mode 100644
index 60f6661..0000000
--- a/src/io/security.erl
+++ /dev/null
@@ -1,33 +0,0 @@
--module(security).
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--export
-(
- [
- assert_identity/2,
- lock_queries/1,
- unlock_queries/1
- ]
-).
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--spec assert_identity (any(), any()) -> 'unimplemented'.
-assert_identity (_PlayerID, _SessionToken) -> unimplemented.
-
--spec lock_queries (any()) -> 'unimplemented'.
-lock_queries (_PlayerID) -> unimplemented.
-
--spec unlock_queries (any()) -> 'unimplemented'.
-unlock_queries (_PlayerID) -> unimplemented.
diff --git a/src/io/timed_cache.erl b/src/io/timed_cache.erl
deleted file mode 100644
index 52b98d6..0000000
--- a/src/io/timed_cache.erl
+++ /dev/null
@@ -1,130 +0,0 @@
--module(timed_cache).
--behavior(gen_server).
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%% 'gen_server' Exports
--export
-(
- [
- init/1,
- handle_cast/2,
- handle_call/3, %% No reply will ever be given.
- terminate/2,
- code_change/3,
- format_status/2,
- handle_info/2
- ]
-).
-
-%%%% Actual Interface
--export
-(
- [
- fetch/3,
- update/4,
- invalidate/3
- ]
-).
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--spec add_to_cache (atom(), any(), any()) -> any().
-add_to_cache (DB, Owner, ObjectID) ->
- {ok, TimerPID} = gen_server:start(?MODULE, {DB, {Owner, ObjectID}}, []),
- {ok, Data} = database_shim:fetch(DB, ObjectID),
- ets:insert(DB, {{Owner, ObjectID}, TimerPID, Data}),
- Data.
-
--spec add_update_to_cache (atom(), any(), any(), any()) -> 'ok'.
-add_update_to_cache (DB, Owner, ObjectID, Data) ->
- {ok, TimerPID} = gen_server:start(?MODULE, {DB, {Owner, ObjectID}}, []),
- ets:insert(DB, {{Owner, ObjectID}, TimerPID, Data}),
- ok.
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%% 'gen_server' functions
-init ({DB, ObjectID}) ->
- io:format("~nCache entry added: ~p.~n", [{DB, ObjectID}]),
- {ok, {DB, ObjectID}, timed_caches_manager:get_timeout()}.
-
-handle_call (invalidate, _, State) ->
- {stop, normal, State};
-handle_call (ping, _, State) ->
- {noreply, State, timed_caches_manager:get_timeout()}.
-
-handle_cast (invalidate, State) ->
- {stop, normal, State};
-handle_cast (ping, State) ->
- {noreply, State, timed_caches_manager:get_timeout()}.
-
-terminate (_, {DB, ObjectID}) ->
- io:format
- (
- "~nCache entry timed out or was invalidated: ~p.~n",
- [{DB, ObjectID}]
- ),
- ets:delete(DB, ObjectID).
-
-code_change (_, State, _) ->
- {ok, State}.
-
-format_status (_, [_, State]) ->
- [{data, [{"State", State}]}].
-
-handle_info(timeout, State) ->
- {stop, normal, State};
-handle_info(_, {DB, ObjectID}) ->
- {noreply, {DB, ObjectID}, timed_caches_manager:get_timeout()}.
-
-%%%% Interface Functions
--spec fetch (atom(), any(), any()) -> any().
-fetch (DB, Owner, ObjectID) ->
- io:format("~nfetch from cache: ~p.~n", [{DB, {Owner, ObjectID}}]),
- case ets:lookup(DB, {Owner, ObjectID}) of
- [] -> add_to_cache(DB, Owner, ObjectID);
-
- [{_, TimerPID, Data}] ->
- gen_server:cast(TimerPID, ping),
- Data
- end.
-
--spec update (atom(), any(), any(), any()) -> 'ok'.
-update (DB, Owner, ObjectID, Data) ->
- io:format("~nUpdating cache: ~p.~n", [{DB, {Owner, ObjectID}}]),
- case ets:lookup(DB, {Owner, ObjectID}) of
- [] -> ok;
-
- [{_OwnerID, TimerPID, _Data}] ->
- gen_server:stop(TimerPID)
- end,
- add_update_to_cache(DB, Owner, ObjectID, Data).
-
--spec invalidate (atom(), any(), any()) -> 'ok'.
-invalidate (DB, Owner, ObjectID) ->
- case ets:lookup(DB, {Owner, ObjectID}) of
- [] ->
- io:format
- (
- "~nInvalidation request on non-stored entry: ~p.~n",
- [{DB, Owner, ObjectID}]
- ),
- ok;
-
- [{_, TimerPID, _}] ->
- io:format
- (
- "~nInvalidation request on stored entry: ~p.~n",
- [{DB, Owner, ObjectID}]
- ),
- gen_server:stop(TimerPID),
- ok
- end.
diff --git a/src/io/timed_caches_manager.erl b/src/io/timed_caches_manager.erl
deleted file mode 100644
index 5901964..0000000
--- a/src/io/timed_caches_manager.erl
+++ /dev/null
@@ -1,152 +0,0 @@
--module(timed_caches_manager).
--behavior(gen_server).
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%% 'gen_server' Exports
--export(
- [
- init/1,
- handle_cast/2,
- handle_call/3,
- terminate/2,
- code_change/3,
- format_status/2,
- handle_info/2
- ]
-).
-
-%%%% Actual Interface
--export(
- [
- start/0,
- new_cache/3,
- delete_cache/2,
- get_timeout/0
- ]
-)
-.
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-remove_cache (DB) ->
- ets:delete(DB).
-
-add_cache (DB, none) ->
- io:format("~nTimed Caches Manager added a new cache. ~n"),
- ets:new(
- DB,
- [
- set,
- public,
- named_table,
- {keypos, 1},
- {read_concurrency, true},
- {heir, none}
- ]
- );
-add_cache (DB, Heir) ->
- io:format("~nTimed Caches Manager added a new cache. ~n"),
- ets:new(
- DB,
- [
- set,
- public,
- named_table,
- {keypos, 1},
- {read_concurrency, true},
- {heir, Heir, DB}
- ]
- ).
-
-inherit_cache (CacheList, DB, Heir) ->
- case lists:member(DB, CacheList) of
- true ->
- ets:setopts(DB, {heir, Heir, DB}),
- CacheList;
-
- false ->
- [DB|CacheList]
- end.
-
-remove_cache (CacheList, DB) ->
- case lists:member(DB, CacheList) of
- true ->
- remove_cache(DB),
- lists:delete(DB, CacheList);
- false ->
- CacheList
- end.
-
-add_cache (CacheList, DB, Heir) ->
- case lists:member(DB, CacheList) of
- true when (Heir =:= none) ->
- CacheList;
-
- true ->
- ets:setopts(DB, {heir, Heir, DB}),
- CacheList;
-
- false ->
- add_cache(DB, Heir),
- [DB|CacheList]
- end.
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%% 'gen_server' functions
-init (CacheList) ->
- io:format("~nStarting Timed Caches Manager..."),
- {ok, CacheList}.
-
-handle_call ({remove, CacheName}, _Caller, State) ->
- {noreply, remove_cache(State, CacheName)};
-handle_call ({add, CacheName, Heir}, _Caller, State)->
- {noreply, add_cache(State, CacheName, Heir)};
-handle_call ({inherit, CacheName, Heir}, _Caller, State)->
- {noreply, inherit_cache(State, CacheName, Heir)};
-handle_call (terminate, _, State) ->
- {stop, normal, State}.
-
-handle_cast ({remove, CacheName}, State) ->
- {noreply, remove_cache(State, CacheName)};
-handle_cast ({add, CacheName, Heir}, State)->
- {noreply, add_cache(State, CacheName, Heir)};
-handle_cast ({inherit, CacheName, Heir}, State)->
- {noreply, inherit_cache(State, CacheName, Heir)};
-handle_cast (terminate, State) ->
- {stop, normal, State}.
-
-terminate (_Reason, []) ->
- ok;
-terminate (Reason, [CacheName|OtherCaches]) ->
- remove_cache(CacheName),
- terminate(Reason, OtherCaches).
-
-code_change (_, State, _) ->
- {ok, State}.
-
-format_status (_, [_, State]) ->
- [{data, [{"State", State}]}].
-
-handle_info(_, State) ->
- {noreply, State}.
-
-%%%% Interface Functions
-start () ->
- gen_server:start(timed_caches_manager, [], []).
-
-new_cache (ManagerPid, DB, Heir) ->
- gen_server:cast(ManagerPid, {add, DB, Heir}).
-
-delete_cache (ManagerPid, DB) ->
- gen_server:cast(ManagerPid, {remove, DB}).
-
-get_timeout () ->
- 120000. % 2min.