1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- This document was generated using DocBuilder 3.3.3 -->
<HTML>
<HEAD>
<TITLE>Included Applications</TITLE>
<SCRIPT type="text/javascript" src="../../doc/erlresolvelinks.js">
</SCRIPT>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#FF00FF"
ALINK="#FF0000">
<CENTER>
<A HREF="http://www.erlang.se"><IMG BORDER=0 ALT="[Ericsson AB]" SRC="min_head.gif"></A>
</CENTER>
<A NAME="8"><!-- Empty --></A>
<H2>8 Included Applications</H2>
<A NAME="8.1"><!-- Empty --></A>
<H3>8.1 Definition</H3>
<P>An application can <STRONG>include</STRONG> other applications.
An <STRONG>included application</STRONG> has its own application directory
and <CODE>.app</CODE> file, but it is started as part of the supervisor
tree of another application.
<P>An application can only be included by one other application.
<P>An included application can include other applications.
<P>An application which is not included by any other application is
called a <STRONG>primary application</STRONG>.
<P>
<CENTER>
<IMG ALT="inclappls" SRC="inclappls.gif"><BR>
<EM><A NAME="inclappls"><!-- Empty --></A>
Primary Application and Included Applications.
</EM>
</CENTER>
<P>The application controller will automatically load any included
applications when loading a primary application, but not start
them. Instead, the top supervisor of the included application
must be started by a supervisor in the including application.
<P>This means that when running, an included application is in fact
part of the primary application and a process in an included
application will consider itself belonging to the primary
application.<A NAME="8.2"><!-- Empty --></A>
<H3>8.2 Specifying Included Applications</H3>
<P>Which applications to include is defined by
the <CODE>included_applications</CODE> key in the <CODE>.app</CODE> file.
<PRE>
{application, prim_app,
[{description, "Tree application"},
{vsn, "1"},
{modules, [prim_app_cb, prim_app_sup, prim_app_server]},
{registered, [prim_app_server]},
{included_applications, [incl_app]},
{applications, [kernel, stdlib, sasl]},
{mod, {prim_app_cb,[]}},
{env, [{file, "/usr/local/log"}]}
]}.
</PRE>
<A NAME="8.3"><!-- Empty --></A>
<H3>8.3 Synchronizing Processes During Startup</H3>
<P>The supervisor tree of an included application is started as
part of the supervisor tree of the including application.
If there is a need for synchronization between processes in
the including and included applications, this can be achieved
by using <STRONG>start phases</STRONG>.
<P>Start phases are defined by the <CODE>start_phases</CODE> key in
the <CODE>.app</CODE> file as a list of tuples <CODE>{Phase,PhaseArgs}</CODE>,
where <CODE>Phase</CODE> is an atom and <CODE>PhaseArgs</CODE> is a term.
Also, the value of the <CODE>mod</CODE> key of the including application
must be set to <CODE>{application_starter,[Module,StartArgs]}</CODE>,
where <CODE>Module</CODE> as usual is the application callback module
and <CODE>StartArgs</CODE> a term provided as argument to the callback
function <CODE>Module:start/2</CODE>.
<PRE>
{application, prim_app,
[{description, "Tree application"},
{vsn, "1"},
{modules, [prim_app_cb, prim_app_sup, prim_app_server]},
{registered, [prim_app_server]},
{included_applications, [incl_app]},
{start_phases, [{init,[]}, {go,[]}]},
{applications, [kernel, stdlib, sasl]},
{mod, {application_starter,[prim_app_cb,[]]}},
{env, [{file, "/usr/local/log"}]}
]}.
{application, incl_app,
[{description, "Included application"},
{vsn, "1"},
{modules, [incl_app_cb, incl_app_sup, incl_app_server]},
{registered, []},
{start_phases, [{go,[]}]},
{applications, [kernel, stdlib, sasl]},
{mod, {incl_app_cb,[]}}
]}.
</PRE>
<P>When starting a primary application with included applications,
the primary application is started the normal way:
The application controller creates an application master for
the application, and the application master calls
<CODE>Module:start(normal, StartArgs)</CODE> to start the top
supervisor.
<P>Then, for the primary application and each included application
in top-down, left-to-right order, the application master calls
<CODE>Module:start_phase(Phase, Type, PhaseArgs)</CODE> for each phase
defined for for the primary application, in that order.
Note that if a phase is not defined for an included application,
the function is not called for this phase and application.
<P>The following requirements apply to the <CODE>.app</CODE> file for
an included application:
<P>
<UL>
<LI>
The <CODE>{mod, {Module,StartArgs}}</CODE> option must be
included. This option is used to find the callback module
<CODE>Module</CODE> of the application. <CODE>StartArgs</CODE> is ignored,
as <CODE>Module:start/2</CODE> is called only for the primary
application.
</LI>
<LI>
If the included application itself contains included
applications, instead the option
<CODE>{mod, {application_starter, [Module,StartArgs]}}</CODE> must be
included.
</LI>
<LI>
The <CODE>{start_phases, [{Phase,PhaseArgs}]}</CODE> option must
be included, and the set of specified phases must be a subset
of the set of phases specified for the primary application.
</LI>
</UL>
<P>When starting <CODE>prim_app</CODE> as defined above, the application
controller will call the following callback functions, before
<CODE>application:start(prim_app)</CODE> returns a value:
<PRE>
application:start(prim_app)
=> prim_app_cb:start(normal, [])
=> prim_app_cb:start_phase(init, normal, [])
=> prim_app_cb:start_phase(go, normal, [])
=> incl_app_cb:start_phase(go, normal, [])
ok
</PRE>
<CENTER>
<HR>
<SMALL>
Copyright © 1991-2006
<A HREF="http://www.erlang.se">Ericsson AB</A><BR>
</SMALL>
</CENTER>
</BODY>
</HTML>
|