Skip to content

Commit

Permalink
implement prod and num_prods, add num_prods to gen_server state, bump…
Browse files Browse the repository at this point in the history
… to ver 3
  • Loading branch information
RJ committed Mar 16, 2011
1 parent 8e859ba commit e48a96a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 23 deletions.
11 changes: 11 additions & 0 deletions apps/dummy_app/ebin/dummy_app.appup
@@ -1,3 +1,14 @@
{"3",
%% Upgrade instructions
[{"2", [
{update,dummy_app_server,{advanced,[from2to3]}}
]}],
%% Downgrade instructions
[{"2",[
{update,dummy_app_server,{advanced,[from3to2]}}
]}]
}.

{"2",
%% Upgrade instructions from 1 to 2
[{"1", [
Expand Down
2 changes: 1 addition & 1 deletion apps/dummy_app/src/dummy_app.app.src
@@ -1,7 +1,7 @@
{application, dummy_app,
[
{description, "Dummy project to test release process"},
{vsn, "2"},
{vsn, "3"},
{registered, []},
{applications, [
kernel,
Expand Down
60 changes: 39 additions & 21 deletions apps/dummy_app/src/dummy_app_server.erl
Expand Up @@ -3,26 +3,35 @@
-behaviour(gen_server).

%% API
-export([start_link/0, poke/0, num_pokes/0, poke_twice/0]).
%% API
-export([ start_link/0
, poke/0
, poke/1
, poke_twice/0
, num_pokes/0
, prod/0
, prod/1
, num_prods/0
]).

%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).

-record(state, {num_pokes = 0}).
-record(state, {num_pokes = 0, num_prods = 0}).

%% API
start_link() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
start_link() -> gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).

poke() ->
gen_server:call(?MODULE, poke).
poke() -> poke(1).
poke_twice() -> poke(2).
poke(N) -> gen_server:call(?MODULE, {poke, N}).

poke_twice() ->
gen_server:call(?MODULE, poke_twice).
prod() -> prod(1).
prod(N) -> gen_server:call(?MODULE, {prod, N}).

num_pokes() ->
gen_server:call(?MODULE, num_pokes).
num_pokes() -> gen_server:call(?MODULE, num_pokes).
num_prods() -> gen_server:call(?MODULE, num_prods).


%% gen_server callbacks
Expand All @@ -32,14 +41,17 @@ init([]) ->
handle_call(num_pokes, _From, State = #state{ num_pokes = PokeCount }) ->
{reply, PokeCount, State};

handle_call(poke_twice, _From, State) ->
NewPokeCount = State#state.num_pokes + 2,
NewState = State#state{num_pokes = NewPokeCount},
Reply = {ok, NewPokeCount},
handle_call(num_prods, _From, State = #state{ num_prods = ProdCount }) ->
{reply, ProdCount, State};

handle_call({prod, N}, _From, State) ->
NewProdCount = State#state.num_prods + N,
NewState = State#state{num_prods = NewProdCount},
Reply = {ok, NewProdCount},
{reply, Reply, NewState};

handle_call(poke, _From, State) ->
NewPokeCount = State#state.num_pokes + 1,
handle_call({poke, N}, _From, State) ->
NewPokeCount = State#state.num_pokes + N,
NewState = State#state{num_pokes = NewPokeCount},
Reply = {ok, NewPokeCount},
{reply, Reply, NewState}.
Expand All @@ -53,9 +65,15 @@ handle_info(_Info, State) ->
terminate(_Reason, _State) ->
ok.

code_change(OldVsn, State, Extra) ->
error_logger:info_msg("code_change, oldvsn:~p state:~p extra:~p~n",
[OldVsn, State, Extra]),
{ok, State}.
%% Upgrade from 2
code_change(_OldVsn, State, [from2to3]) ->
error_logger:info_msg("CODE_CHANGE from 2~n"),
{state, NumPokes} = State, %% State here is the 'old' format, with 1 field
NewState = #state{num_pokes=NumPokes}, %% will assume default for num_prods
{ok, NewState}.

%% Note downgrade code_change not implemented



%%% Internal functions
%%% Internal functions
2 changes: 1 addition & 1 deletion rel/reltool.config
@@ -1,6 +1,6 @@
{sys, [
{lib_dirs, ["../apps"]},
{rel, "dummy", "2",
{rel, "dummy", "3",
[
kernel,
stdlib,
Expand Down

0 comments on commit e48a96a

Please sign in to comment.