Skip to content

Commit

Permalink
Merge 4be6eb9 into f83dacf
Browse files Browse the repository at this point in the history
  • Loading branch information
albsch authored Sep 30, 2020
2 parents f83dacf + 4be6eb9 commit 3821d11
Show file tree
Hide file tree
Showing 27 changed files with 343 additions and 1,452 deletions.
84 changes: 44 additions & 40 deletions src/gen_fsm_compat.erl
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
%%% start_link(Name, Mod, Args, Options) where:
%%% Name ::= {local, atom()} | {global, term()} | {via, atom(), term()}
%%% Mod ::= atom(), callback module implementing the 'real' fsm
%%% Args ::= term(), init arguments (to Mod:init/1)
%%% Args ::= term(), init arguments (to Module:init/1)
%%% Options ::= [{debug, [Flag]}]
%%% Flag ::= trace | log | {logfile, File} | statistics | debug
%%% (debug == log && statistics)
Expand All @@ -233,8 +233,8 @@ stop(Name, Reason, Timeout) ->

send_event({global, Name}, Event) ->
catch global:send(Name, {'$gen_event', Event}), ok;
send_event({via, Mod, Name}, Event) ->
catch Mod:send(Name, {'$gen_event', Event}), ok;
send_event({via, Module, Name}, Event) ->
catch Module:send(Name, {'$gen_event', Event}), ok;
send_event(Name, Event) ->
Name ! {'$gen_event', Event}, ok.

Expand All @@ -260,8 +260,9 @@ send_all_state_event({global, Name}, Event) ->
catch global:send(Name,
{'$gen_all_state_event', Event}),
ok;
send_all_state_event({via, Mod, Name}, Event) ->
catch Mod:send(Name, {'$gen_all_state_event', Event}),
send_all_state_event({via, Module, Name}, Event) ->
catch Module:send(Name,
{'$gen_all_state_event', Event}),
ok;
send_all_state_event(Name, Event) ->
Name ! {'$gen_all_state_event', Event}, ok.
Expand Down Expand Up @@ -349,25 +350,26 @@ enter_loop(Mod, Options, StateName, StateData,
%%% ---------------------------------------------------
%%% Initiate the new process.
%%% Register the name using the Rfunc function
%%% Calls the Mod:init/Args function.
%%% Calls the Moduleinit/Args function.
%%% Finally an acknowledge is sent to Parent and the main
%%% loop is entered.
%%% ---------------------------------------------------
init_it(Starter, self, Name, Mod, Args, Options) ->
init_it(Starter, self(), Name, Mod, Args, Options);
init_it(Starter, Parent, Name0, Mod, Args, Options) ->
init_it(Starter, Parent, Name0, Module, Args,
Options) ->
Name = gen:name(Name0),
Debug = gen:debug_options(Name, Options),
HibernateAfterTimeout = gen:hibernate_after(Options),
case catch Mod:init(Args) of
case catch Module:init(Args) of
{ok, StateName, StateData} ->
proc_lib:init_ack(Starter, {ok, self()}),
loop(Parent, Name, StateName, StateData, Mod, infinity,
HibernateAfterTimeout, Debug);
loop(Parent, Name, StateName, StateData, Module,
infinity, HibernateAfterTimeout, Debug);
{ok, StateName, StateData, Timeout} ->
proc_lib:init_ack(Starter, {ok, self()}),
loop(Parent, Name, StateName, StateData, Mod, Timeout,
HibernateAfterTimeout, Debug);
loop(Parent, Name, StateName, StateData, Module,
Timeout, HibernateAfterTimeout, Debug);
{stop, Reason} ->
gen:unregister_name(Name0),
proc_lib:init_ack(Starter, {error, Reason}),
Expand Down Expand Up @@ -457,15 +459,15 @@ system_terminate(Reason, _Parent, Debug,
terminate(Reason, Name, [], Mod, StateName, StateData,
Debug).

system_code_change([Name, StateName, StateData, Mod,
system_code_change([Name, StateName, StateData, Module,
Time, HibernateAfterTimeout],
_Module, OldVsn, Extra) ->
case catch Mod:code_change(OldVsn, StateName, StateData,
Extra)
case catch Module:code_change(OldVsn, StateName,
StateData, Extra)
of
{ok, NewStateName, NewStateData} ->
{ok,
[Name, NewStateName, NewStateData, Mod, Time,
[Name, NewStateName, NewStateData, Module, Time,
HibernateAfterTimeout]};
Else -> Else
end.
Expand Down Expand Up @@ -602,27 +604,27 @@ handle_msg(Msg, Parent, Name, StateName, StateData, Mod,
StateName, StateData, Debug)
end.

dispatch({'$gen_event', Event}, Mod, StateName,
dispatch({'$gen_event', Event}, Module, StateName,
StateData) ->
Mod:StateName(Event, StateData);
dispatch({'$gen_all_state_event', Event}, Mod,
Module:StateName(Event, StateData);
dispatch({'$gen_all_state_event', Event}, Module,
StateName, StateData) ->
Mod:handle_event(Event, StateName, StateData);
dispatch({'$gen_sync_event', From, Event}, Mod,
Module:handle_event(Event, StateName, StateData);
dispatch({'$gen_sync_event', From, Event}, Module,
StateName, StateData) ->
Mod:StateName(Event, From, StateData);
Module:StateName(Event, From, StateData);
dispatch({'$gen_sync_all_state_event', From, Event},
Mod, StateName, StateData) ->
Mod:handle_sync_event(Event, From, StateName,
StateData);
dispatch({timeout, Ref, {'$gen_timer', Msg}}, Mod,
Module, StateName, StateData) ->
Module:handle_sync_event(Event, From, StateName,
StateData);
dispatch({timeout, Ref, {'$gen_timer', Msg}}, Module,
StateName, StateData) ->
Mod:StateName({timeout, Ref, Msg}, StateData);
dispatch({timeout, _Ref, {'$gen_event', Event}}, Mod,
Module:StateName({timeout, Ref, Msg}, StateData);
dispatch({timeout, _Ref, {'$gen_event', Event}}, Module,
StateName, StateData) ->
Mod:StateName(Event, StateData);
dispatch(Info, Mod, StateName, StateData) ->
Mod:handle_info(Info, StateName, StateData).
Module:StateName(Event, StateData);
dispatch(Info, Module, StateName, StateData) ->
Module:handle_info(Info, StateName, StateData).

from({'$gen_sync_event', From, _Event}) -> From;
from({'$gen_sync_all_state_event', From, _Event}) ->
Expand All @@ -644,14 +646,15 @@ reply(Name, {To, Tag}, Reply, Debug, StateName) ->
-spec terminate(term(), _, _, atom(), _, _,
_) -> no_return().

terminate(Reason, Name, Msg, Mod, StateName, StateData,
Debug) ->
case erlang:function_exported(Mod, terminate, 3) of
terminate(Reason, Name, Msg, Module, StateName,
StateData, Debug) ->
case erlang:function_exported(Module, terminate, 3) of
true ->
case catch Mod:terminate(Reason, StateName, StateData)
case catch Module:terminate(Reason, StateName,
StateData)
of
{'EXIT', R} ->
FmtStateData = format_status(terminate, Mod, get(),
FmtStateData = format_status(terminate, Module, get(),
StateData),
error_info(R, Name, Msg, StateName, FmtStateData,
Debug),
Expand All @@ -665,7 +668,7 @@ terminate(Reason, Name, Msg, Mod, StateName, StateData,
shutdown -> exit(shutdown);
{shutdown, _} = Shutdown -> exit(Shutdown);
_ ->
FmtStateData1 = format_status(terminate, Mod, get(),
FmtStateData1 = format_status(terminate, Module, get(),
StateData),
error_info(Reason, Name, Msg, StateName, FmtStateData1,
Debug),
Expand Down Expand Up @@ -776,14 +779,15 @@ format_status(Opt, StatusData) ->

-endif.

format_status(Opt, Mod, PDict, State) ->
format_status(Opt, Module, PDict, State) ->
DefStatus = case Opt of
terminate -> State;
_ -> [{data, [{"StateData", State}]}]
end,
case erlang:function_exported(Mod, format_status, 2) of
case erlang:function_exported(Module, format_status, 2)
of
true ->
case catch Mod:format_status(Opt, [PDict, State]) of
case catch Module:format_status(Opt, [PDict, State]) of
{'EXIT', _} -> DefStatus;
Else -> Else
end;
Expand Down
53 changes: 26 additions & 27 deletions src/gen_nb_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -90,37 +90,36 @@
{stop, Reason :: term(),
NewState :: term()}.

%% @spec start_link(CallbackModule, IpAddr, Port, InitParams) -> Result
%% CallbackModule = atom()
%% @spec start_link(Module, IpAddr, Port, InitParams) -> Result
%% Module = atom()
%% IpAddr = string()
%% Port = integer()
%% InitParams = [any()]
%% Result = {ok, pid()} | {error, any()}
%% @doc Start server listening on IpAddr:Port
start_link(CallbackModule, IpAddr, Port, InitParams) ->
start_link(Module, IpAddr, Port, InitParams) ->
gen_server:start_link(?MODULE,
[CallbackModule, IpAddr, Port, InitParams], []).
[Module, IpAddr, Port, InitParams], []).

%% @hidden
init([CallbackModule, IpAddr, Port, InitParams]) ->
case CallbackModule:init(InitParams) of
init([Module, IpAddr, Port, InitParams]) ->
case Module:init(InitParams) of
{ok, ServerState} ->
case listen_on(CallbackModule, IpAddr, Port) of
case listen_on(Module, IpAddr, Port) of
{ok, Sock} ->
{ok,
#state{cb = CallbackModule, sock = Sock,
#state{cb = Module, sock = Sock,
server_state = ServerState}};
Error ->
CallbackModule:terminate(Error, ServerState), Error
Error -> Module:terminate(Error, ServerState), Error
end;
Err -> Err
end.

%% @hidden
handle_call(Request, From,
#state{cb = Callback, server_state = ServerState} =
#state{cb = Module, server_state = ServerState} =
State) ->
case Callback:handle_call(Request, From, ServerState) of
case Module:handle_call(Request, From, ServerState) of
{reply, Reply, NewServerState} ->
{reply, Reply,
State#state{server_state = NewServerState}};
Expand All @@ -144,9 +143,9 @@ handle_call(Request, From,

%% @hidden
handle_cast(Msg,
#state{cb = Callback, server_state = ServerState} =
#state{cb = Module, server_state = ServerState} =
State) ->
case Callback:handle_cast(Msg, ServerState) of
case Module:handle_cast(Msg, ServerState) of
{noreply, NewServerState} ->
{noreply, State#state{server_state = NewServerState}};
{noreply, NewServerState, Arg}
Expand All @@ -161,10 +160,10 @@ handle_cast(Msg,
%% @hidden
handle_info({inet_async, ListSock, _Ref,
{ok, CliSocket}},
#state{cb = Callback, server_state = ServerState} =
#state{cb = Module, server_state = ServerState} =
State) ->
inet_db:register_socket(CliSocket, inet_tcp),
case Callback:new_connection(CliSocket, ServerState) of
case Module:new_connection(CliSocket, ServerState) of
{ok, NewServerState} ->
{ok, _} = prim_inet:async_accept(ListSock, -1),
{noreply, State#state{server_state = NewServerState}};
Expand All @@ -173,9 +172,9 @@ handle_info({inet_async, ListSock, _Ref,
State#state{server_state = NewServerState}}
end;
handle_info(Info,
#state{cb = Callback, server_state = ServerState} =
#state{cb = Module, server_state = ServerState} =
State) ->
case Callback:handle_info(Info, ServerState) of
case Module:handle_info(Info, ServerState) of
{noreply, NewServerState} ->
{noreply, State#state{server_state = NewServerState}};
{noreply, NewServerState, Arg}
Expand All @@ -189,10 +188,10 @@ handle_info(Info,

%% @hidden
terminate(Reason,
#state{cb = Callback, sock = Sock,
#state{cb = Module, sock = Sock,
server_state = ServerState}) ->
gen_tcp:close(Sock),
Callback:terminate(Reason, ServerState),
Module:terminate(Reason, ServerState),
ok.

%% @hidden
Expand All @@ -201,28 +200,28 @@ code_change(_OldVsn, State, _Extra) -> {ok, State}.
%% Internal functions

%% @hidden
%% @spec listen_on(CallbackModule, IpAddr, Port) -> Result
%% CallbackModule = atom()
%% @spec listen_on(Module, IpAddr, Port) -> Result
%% Module = atom()
%% IpAddr = string() | tuple()
%% Port = integer()
%% Result = {ok, port()} | {error, any()}
listen_on(CallbackModule, IpAddr, Port)
listen_on(Module, IpAddr, Port)
when is_tuple(IpAddr) andalso
(8 =:= size(IpAddr) orelse 4 =:= size(IpAddr)) ->
SockOpts = [{ip, IpAddr} | CallbackModule:sock_opts()],
SockOpts = [{ip, IpAddr} | Module:sock_opts()],
case gen_tcp:listen(Port, SockOpts) of
{ok, LSock} ->
{ok, _Ref} = prim_inet:async_accept(LSock, -1),
{ok, LSock};
Err -> Err
end;
listen_on(CallbackModule, IpAddrStr, Port) ->
listen_on(Module, IpAddrStr, Port) ->
case inet_parse:address(IpAddrStr) of
{ok, IpAddr} -> listen_on(CallbackModule, IpAddr, Port);
{ok, IpAddr} -> listen_on(Module, IpAddr, Port);
Err ->
logger:critical("Cannot start listener for ~p\n "
" on invalid address "
"~p:~p",
[CallbackModule, IpAddrStr, Port]),
[Module, IpAddrStr, Port]),
Err
end.
35 changes: 16 additions & 19 deletions src/riak_core.app.src
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
{application,riak_core,
[{description,"Riak Core Lite"},
{application, riak_core,
[{description, "Riak Core Lite"},
{vsn,"0.10.1"},
{applications,
[kernel,stdlib,crypto,os_mon,poolboy]
[kernel, stdlib, crypto, os_mon, poolboy]
},
{mod,{riak_core_app,[]}},
{mod, {riak_core_app, []}},
{env,
[{cluster_name,"default"},
{platform_data_dir,"data"},
{ring_state_dir,"data/ring"},
{ring_creation_size,64},
[{cluster_name, "default"},
{platform_data_dir, "data"},
{ring_state_dir, "data/ring"},
{ring_creation_size, 64},
{gossip_interval, 60000},
{target_n_val,4},
{target_n_val, 4},
{vnode_inactivity_timeout, 60000},
{vnode_check_interval, 5000},
{vnode_overload_threshold, 10000},
{vnode_modules, []},
{vnode_routing, proxy},
{handoff_concurrency,2},
{handoff_concurrency, 2},
{handoff_receive_timeout, 300000}, % 5 minutes TCP timeout
{handoff_receive_vnode_timeout, 60000}, % timeout for vnode to process the hand-off data msg
{default_bucket_props, []},
{handoff_port,8099},
{handoff_ip,"0.0.0.0"},
{bucket_fixups, []},
{bucket_validators, []},
{handoff_port, 8099},
{handoff_ip, "0.0.0.0"},
{stat_mods, []},
{health_checks, []}
]},
{pkg_name,"riak_core_lite"},
{maintainers,["riak_core_lite","Albert Schimpf"]},
{licenses,["Apache"]},
{links,[{"Github","https://github.com/riak-core-lite/riak_core_lite"}]}
{pkg_name, "riak_core_lite"},
{maintainers, ["riak_core_lite", "Albert Schimpf"]},
{licenses, ["Apache"]},
{links, [{"Github", "https://github.com/riak-core-lite/riak_core_lite"}]}
]}.
Loading

0 comments on commit 3821d11

Please sign in to comment.