mirror of
https://github.com/valitydev/msgpack-erlang.git
synced 2024-11-06 00:35:24 +00:00
sample application skeleton
This commit is contained in:
parent
9f4d60171c
commit
1c113f9360
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,6 +1,6 @@
|
||||
.eunit
|
||||
ebin/*.app
|
||||
ebin/*.beam
|
||||
*.beam
|
||||
doc/*.html
|
||||
doc/edoc-info
|
||||
doc/erlang.png
|
||||
|
1
test/sample.app
Normal file
1
test/sample.app
Normal file
@ -0,0 +1 @@
|
||||
|
17
test/sample.erl
Normal file
17
test/sample.erl
Normal file
@ -0,0 +1,17 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% File : sample.erl
|
||||
%%% Author : UENISHI Kota <kuenishi@gmail.com>
|
||||
%%% Description :
|
||||
%%%
|
||||
%%% Created : 5 May 2011 by UENISHI Kota <kuenishi@gmail.com>
|
||||
%%%-------------------------------------------------------------------
|
||||
-module(sample).
|
||||
|
||||
-export([start/0, stop/0]).
|
||||
|
||||
start()->
|
||||
application:start(sample_app).
|
||||
|
||||
stop()->
|
||||
application:stop(sample_app).
|
||||
|
@ -7,18 +7,41 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
-module(sample_app).
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
-behaviour(application).
|
||||
|
||||
%% Application callbacks
|
||||
%-export([start_link/1]).
|
||||
-export([start/2, stop/1]).
|
||||
|
||||
%% start()->
|
||||
%% msgpack_rpc:start(),
|
||||
%% case msgpack_rpc:add_server(sample_srv, [{addr, localhost}]) of
|
||||
%% {ok, _} -> ok;
|
||||
%% Other -> Other
|
||||
%% end.
|
||||
%%====================================================================
|
||||
%% Application callbacks
|
||||
%%====================================================================
|
||||
%%--------------------------------------------------------------------
|
||||
%% Function: start(Type, StartArgs) -> {ok, Pid} |
|
||||
%% {ok, Pid, State} |
|
||||
%% {error, Reason}
|
||||
%% Description: This function is called whenever an application
|
||||
%% is started using application:start/1,2, and should start the processes
|
||||
%% of the application. If the application is structured according to the
|
||||
%% OTP design principles as a supervision tree, this means starting the
|
||||
%% top supervisor of the tree.
|
||||
%%--------------------------------------------------------------------
|
||||
start(_Type, StartArgs) ->
|
||||
case sample_sup:start_link(StartArgs) of
|
||||
{ok, Pid} ->
|
||||
{ok, Pid};
|
||||
Error ->
|
||||
Error
|
||||
end.
|
||||
|
||||
%% stop()->
|
||||
%% msgpack_rpc:del_server(sample_srv),
|
||||
%% msgpack_rpc:stop().
|
||||
%%--------------------------------------------------------------------
|
||||
%% Function: stop(State) -> void()
|
||||
%% Description: This function is called whenever an application
|
||||
%% has stopped. It is intended to be the opposite of Module:start/2 and
|
||||
%% should do any necessary cleaning up. The return value is ignored.
|
||||
%%--------------------------------------------------------------------
|
||||
stop(_State) ->
|
||||
ok.
|
||||
|
||||
%%====================================================================
|
||||
%% Internal functions
|
||||
%%====================================================================
|
||||
|
49
test/sample_sup.erl
Normal file
49
test/sample_sup.erl
Normal file
@ -0,0 +1,49 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% File : sample_sup.erl
|
||||
%%% Author : UENISHI Kota <kuenishi@gmail.com>
|
||||
%%% Description :
|
||||
%%%
|
||||
%%% Created : 5 May 2011 by UENISHI Kota <kuenishi@gmail.com>
|
||||
%%%-------------------------------------------------------------------
|
||||
-module(sample_sup).
|
||||
|
||||
-behaviour(supervisor).
|
||||
|
||||
%% API
|
||||
-export([start_link/0]).
|
||||
|
||||
%% Supervisor callbacks
|
||||
-export([init/1]).
|
||||
|
||||
-define(SERVER, ?MODULE).
|
||||
|
||||
%%====================================================================
|
||||
%% API functions
|
||||
%%====================================================================
|
||||
%%--------------------------------------------------------------------
|
||||
%% Function: start_link() -> {ok,Pid} | ignore | {error,Error}
|
||||
%% Description: Starts the supervisor
|
||||
%%--------------------------------------------------------------------
|
||||
start_link() ->
|
||||
supervisor:start_link({local, ?SERVER}, ?MODULE, []).
|
||||
|
||||
%%====================================================================
|
||||
%% Supervisor callbacks
|
||||
%%====================================================================
|
||||
%%--------------------------------------------------------------------
|
||||
%% Func: init(Args) -> {ok, {SupFlags, [ChildSpec]}} |
|
||||
%% ignore |
|
||||
%% {error, Reason}
|
||||
%% Description: Whenever a supervisor is started using
|
||||
%% supervisor:start_link/[2,3], this function is called by the new process
|
||||
%% to find out about restart strategy, maximum restart frequency and child
|
||||
%% specifications.
|
||||
%%--------------------------------------------------------------------
|
||||
init([]) ->
|
||||
AChild = {'AName',{sample_srv,start_link,[]},
|
||||
permanent,2000,worker,[sample_srv]},
|
||||
{ok,{{one_for_all,0,1}, [AChild]}}.
|
||||
|
||||
%%====================================================================
|
||||
%% Internal functions
|
||||
%%====================================================================
|
30
test/samplectl
Executable file
30
test/samplectl
Executable file
@ -0,0 +1,30 @@
|
||||
#! /bin/sh
|
||||
|
||||
ERL_LIBS=`pwd`
|
||||
erl -make
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
|
||||
echo "Starting SampleApp server" "erl_msgpack_sample"
|
||||
if exec erl -hidden -s sample start -s init stop -noshell -sname sampleapp; then
|
||||
log_end_msg 0
|
||||
else
|
||||
log_end_msg 1
|
||||
fi
|
||||
;;
|
||||
stop)
|
||||
echo "Stopping SampleApp server" "erl_msgpack_sample"
|
||||
if erl -eval 'rpc:call(sampleapp, sample, stop, []).' -noshell -sname sampleapp_ctl ; then
|
||||
log_end_msg 0
|
||||
else
|
||||
log_end_msg 1
|
||||
fi
|
||||
;;
|
||||
|
||||
*)
|
||||
log_action_msg "Usage: samplectl {start|stop}"
|
||||
exit 1
|
||||
esac
|
||||
|
||||
exit 0
|
Loading…
Reference in New Issue
Block a user