logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

application - Generic OTP application functions

Callback Module

       The following functions are to be exported from an application callback module.

Data Types

start_type() =
           normal |
           {takeover, Node :: node()} |
           {failover, Node :: node()}

       restart_type() = permanent | transient | temporary

       tuple_of(T)

              A tuple where the elements are of type T.

Description

       In OTP, application denotes a component implementing some specific functionality, that can be started and
       stopped  as  a  unit,  and  that  can  be reused in other systems. This module interacts with applicationcontroller, a process started at  every  Erlang  runtime  system.  This  module  contains  functions  for
       controlling  applications  (for  example,  starting  and  stopping applications), and functions to access
       information about applications (for example, configuration parameters).

       An application is defined by an applicationspecification. The specification is normally  located  in  an
       applicationresourcefile named Application.app, where Application is the application name. For details
       about the application specification, see app(5).

       This module can also be viewed as a behaviour for an application implemented according to the OTP  design
       principles as a supervision tree. The definition of how to start and stop the tree is to be located in an
       applicationcallbackmodule, exporting a predefined set of functions.

       For details about applications and behaviours, see OTP Design Principles.

Exports

Module:start(StartType,StartArgs)->{ok,Pid}|{ok,Pid,State}|{error,Reason}

              Types:

                 StartType = start_type()
                 StartArgs = term()
                 Pid = pid()
                 State = term()

              This  function  is  called whenever an application is started using start/1,2, and is to 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.

              StartType defines the type of start:

                * normal if it is a normal startup.

                * normal  also  if  the  application is distributed and started at the current node because of a
                  failover from another node, and the application specification key start_phases==undefined.

                * {takeover,Node} if the application is distributed and started at the current node because of a
                  takeover from Node, either because takeover/2 has been called or because the current node  has
                  higher priority than Node.

                * {failover,Node} if the application is distributed and started at the current node because of a
                  failover from Node, and the application specification key start_phases/=undefined.

              StartArgs is the StartArgs argument defined by the application specification key mod.

              The  function  is to return {ok,Pid} or {ok,Pid,State}, where Pid is the pid of the top supervisor
              and State is any term. If omitted, State defaults to []. If  the  application  is  stopped  later,
              State is passed to Module:prep_stop/1.

       Module:start_phase(Phase,StartType,PhaseArgs)->ok|{error,Reason}

              Types:

                 Phase = atom()
                 StartType = start_type()
                 PhaseArgs = term()
                 Pid = pid()
                 State = state()

              Starts an application with included applications, when synchronization is needed between processes
              in the different applications during startup.

              The   start   phases   are   defined   by   the  application  specification  key  start_phases==[{Phase,PhaseArgs}]. For included applications, the set of phases must be a subset of the  set  of
              phases defined for the including application.

              The  function  is  called  for  each  start phase (as defined for the primary application) for the
              primary application and all included applications, for which the start phase is defined.

              For a description of StartType, see Module:start/2.

       Module:prep_stop(State)->NewState

              Types:

                 State = NewState = term()

              This function is called when an application is about to  be  stopped,  before  shutting  down  the
              processes of the application.

              State  is  the state returned from Module:start/2, or [] if no state was returned. NewState is any
              term and is passed to Module:stop/1.

              The function  is  optional.  If  it  is  not  defined,  the  processes  are  terminated  and  then
              Module:stop(State) is called.

       Module:stop(State)

              Types:

                 State = term()

              This  function is called whenever an application has stopped. It is intended to be the opposite of
              Module:start/2 and is to do any necessary cleaning up. The return value is ignored.

              State is the return value of Module:prep_stop/1, if such a function  exists.  Otherwise  State  is
              taken from the return value of Module:start/2.

       Module:config_change(Changed,New,Removed)->ok

              Types:

                 Changed = [{Par,Val}]
                 New = [{Par,Val}]
                 Removed = [Par]
                  Par = atom()
                  Val = term()

              This  function  is  called  by  an  application  after  a  code  replacement, if the configuration
              parameters have changed.

              Changed is a list of parameter-value tuples including all configuration  parameters  with  changed
              values.

              New is a list of parameter-value tuples including all added configuration parameters.

              Removed is a list of all removed parameters.

Name

       application - Generic OTP application functions

See Also

       OTP Design Principles, kernel(7), app(5)

Ericsson AB                                        kernel 8.2                                  application(3erl)

See Also