Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

Reply To: How to get into OTP

#39865
hercules
Guest

there are lots of thing about it, maybeyou can consult some sweden company about it!

here I can show you some things that may be helpful!

gen server
Erlang Module
A behaviour module for implementing the server of a client-server relation. A generic
server process (gen server) implemented using this module will have a standard set of
interface functions and include functionality for tracing and error reporting. It will also
fit into an OTP supervision tree. Refer to OTP Design Principles for more information.
A gen server assumes all specific parts to be located in a callback module exporting a
pre-defined set of functions. The relationship between the behaviour functions and the
callback functions can be illustrated as follows:
gen server module /Callback module
—————– —————
gen server:start —–> Module:init/1
gen server:call
gen server:multi call —–> Module:handle call/3
gen server:cast
gen server:abcast —–> Module:handle cast/2
– —–> Module:handle info/2
– —–> Module:terminate/2
– —–> Module:code change/3
If a callback function fails or returns a bad value, the gen server will terminate.
The sys module can be used for debugging a gen server.
Note that a gen server does not trap exit signals automatically, this must be explicitly
initiated in the callback module.
Unless otherwise stated, all functions in this module fail if the specified gen server does
not exist or if bad arguments are given.
Exports
start(Module, Args, Options) -> Result
start(ServerName, Module, Args, Options) -> Result
start link(Module, Args, Options) -> Result
start link(ServerName, Module, Args, Options) -> Result
Types:
_ ServerName = flocal,Nameg | fglobal,Nameg

_ Name = atom()
_ Module = atom()
_ Args = term()
_ Options = [Option]
_ Option = fdebug,Dbgsg | ftimeout,Timeg | fspawn opt,SOptsg
_ Dbgs = [Dbg]
_ Dbg = trace | log | statistics | flog to file,FileNameg | finstall,fFunc,FuncStategg
_ SOpts = [term()]
_ Result = fok,Pidg | ignore | ferror,Errorg
_ Pid = pid()
_ Error = falready started,Pidg | term()
Creates a gen server process which calls Module:init/1 to initialize. To ensure a
synchronized start-up procedure, this function does not return until Module:init/1 has
returned.
A gen server started using start link is linked to the calling process, this function
must be used if the gen server is included in a supervision tree. A gen server started
using start is not linked to the calling process.
If ServerName=flocal,Nameg the gen server is registered locally as Name using
register/2. If ServerName=fglobal,Nameg the gen server is registered globally as
Name using global:register name/2. If no name is provided, the gen server is not
registered.
Module is the name of the callback module.
Args is an arbitrary term which is passed as the argument to Module:init/1.
If the option ftimeout,Timeg is present, the gen server is allowed to spend Time
milliseconds initializing or it will be terminated and the start function will return
ferror,timeoutg.
If the option fdebug,Dbgsg is present, the corresponding sys function will be called for
each item in Dbgs. Refer to sys(3) for more information.
If the option fspawn opt,SOptsg is present, SOpts will be passed as option list to the
spawn opt BIF which is used to spawn the gen server. Refer to erlang(3) for
information about the spawn opt options.
If the gen server is successfully created and initialized the function returns fok,Pidg,
where Pid is the pid of the gen server. If there already exists a process with the
specified ServerName the function returns ferror,falready started,Pidgg, where
Pid is the pid of that process.
If Module:init/1 fails with Reason, the function returns ferror,Reasong. If
Module:init/1 returns fstop,Reasong or ignore, the process is terminated and the
function returns ferror,Reasong or ignore, respectively.
call(ServerRef, Request) -> Reply
call(ServerRef, Request, Timeout) -> Reply
Types:
_ ServerRef = Name | fName,Nodeg | fglobal,Nameg | pid()
_ Name = Node = atom()
_ Request = term()
_ Timeout = int()>0 | infinit
_ Reply = term()
Makes a synchronous call to the gen server ServerRef by sending a request and waiting
until a reply arrives or a timout occurs. The gen server will call Module:handle call/3
to handle the request.
ServerRef can be:
_ the pid,
_ Name, if the gen server is locally registered,
_ fName,Nodeg, if the gen server is locally registered at another node, or
_ fglobal,Nameg, if the gen server is globally registered.
Request is an arbitrary term which is passed as one of the arguments to
Module:handle call/3.