Erlang/OTP Forums

Author Message

<  Open Telecom Platform (OTP)  ~  Starting an included application using its own environment

LeHoff
Posted: Wed Sep 05, 2007 9:06 pm Reply with quote
User Joined: 28 Nov 2006 Posts: 38
I have an application simple_app that is started by calling
Code:
simple_sup:start_link({Arg1,Arg2})


Being somewhat tidy at times I have placed the specifics of Arg1 and Arg1 in the env key of the simple_app.app file so that I can build the arguments by looking up values in the environment of the application.

Now I am in the situation that I need to use simple_app as part of a bigger application and looking at the documentation for doing so (http://www.erlang.org/doc/design_principles/included_applications.html#8) it states that...
Quote:
"the top supervisor of the included application must be started by a supervisor in the including application."


This means that the nice and tidy start up I have created in the simple_app:start() function has to be duplicated in the top supervisor of the new application that includes simple_app.

Apart from annoying my natural laziness this "feature" seems to be at odds with normal structuring principles such as re-use and encapsulation.

Should I bite the bullet and - bugger, bugger, bugger Wink - copy the code over to the new top supervisor or is there a neat way out of this predicament?

Cheers,
Torben
View user's profile Send private message
KatolaZ
Posted: Thu Sep 06, 2007 10:51 am Reply with quote
Joined: 04 Jul 2007 Posts: 5
As far as I understand, you include your params in the environment of the application when you start it, right ?

The best way to it when your application is started by another process is setting those values into the application environment *before* starting the application itself. This can be done using application:set_env/3 or application:set_env/4, directly from the supervisor which is in charge of starting your application.

Hope this can help

HND

Enzo
View user's profile Send private message
LeHoff
Posted: Fri Sep 07, 2007 9:02 am Reply with quote
User Joined: 28 Nov 2006 Posts: 38
I think I can see where you are headed.

My specific problem is that I have to start two C ports that I have created and I have created entries in the .app files like this:

Code:

  {env, [{lapd_daemon, "lapd_daemon"},
    {lapd_client_port, "lapd_client_port"}]}


In the .erl file for the application (when started on its own) I then figure out the specific path to the C object files like this:
Code:

PrivDir = code:priv_dir(mps_app),
    DaemonName = case application:get_env(mps_app,lapd_daemon) of
           {ok, DName } -> DName;
           BadD -> exit({bad_config, {mps_app, {lapd_daemon, BadD}}})
       end,
    ClientName = case application:get_env(mps_app,lapd_client_port) of
           {ok, CName } -> CName;
           BadC -> exit({bad_config, {mps_app, {lapd_client_port, BadC}}})
       end,
    Daemon = filename:join([PrivDir, DaemonName]),
    Client = filename:join([PrivDir, ClientName]),
    mps_sup:start_link({Daemon, Client}).


So if I re-factored the last bit of code such that the Daemon and Client were instead put into the environment at start-up (thus getting the right paths to the object files on the target machine) I could then look up, say, lapd_deamon and lapd_client in the environment of that application when it is used as an included application, right?

This seems like a sensible way of putting the right amount of configuration into the .app file and then build the concrete environment when starting up.

I will implement this once I have gotten past the next milestone in our project since I did the nasty code cloning just to get on with the show.

Cheers,
Torben
View user's profile Send private message
timrila
Posted: Tue Jun 12, 2012 9:06 am Reply with quote
User Joined: 28 Mar 2012 Posts: 32
Thank you very much for your post.I enjoy it,A great article. I agree with most of what you’re saying here and the way you’ve presented it is awesome.this post is very encouraging to people who want to know these topics.
Soccer Jerseys
Spain Jersey
Germany Soccer Jersey
Barcelona Jersey
View user's profile Send private message
brandzclothes
Posted: Mon Jun 25, 2012 4:07 pm Reply with quote
Joined: 15 May 2012 Posts: 7 Location: hiphopguccishoes.com
Cheap Louis Vuitton Shoes
cheap gucci shoes
online ysl t-shirts
cheap coogi t-shirts


www.brandsclothesshop.com
Buy China Online YSL T Shirt, Nike Air Max Shoes, Gucci Jeans, LV Clothes
www.hiphopguccishoes.com
Buy Cheap Replica Louis Vuitton Shoes,Cheap Discount Gucci Shoes Clothing,Online Shopping

Coogi Jeans T-Shirts From China
http://www.urbanclothesstore.com/
Shop for the latest styles in fashion shoes and urban clothing. Find top deals on ysl,Prada,

Diesel, Gucci, Baby Phat, Louis Vuitton, Coogi and more.
http://buyclotheschina.com/
Cheap Coogi Louis Vuitton T Shirt,Burberry Clothing,Air Jordan Shoes Online
hi,

_________________
cheap gucci shoes
online ysl t-shirts
cheap coogi t-shirts
View user's profile Send private message Visit poster's website
wuji
Posted: Sat Aug 11, 2012 2:28 am Reply with quote
User Joined: 10 Aug 2012 Posts: 654
than half a century, and a football team's worth of of Cheap Ralph Lauren Shirts of children and grandchildren."He died as he lived. He
hard until the end, stayed positive, thought only of others others replica Christian Louboutin others and constantly reminded everyone of how blessed his life
been. His ambitions were far reaching, but he never never discount designer *beep* never believed he had to leave this Happy Valley to
them. He was a man devoted to his family, family, [h4]designer replica *beep*[/h4] family, his university, his players and his community," Paterno's family
in a statement.While at Penn State's helm, Paterno, who was was [h2]replica designer bags for sale[/h2] was born in Brooklyn, N.Y., led the Nittany Lions to
undefeated seasons and two NCAA championships, had only five losing losing cheap Ralph Lauren Polo losing seasons, was inducted into the College Football Hall of
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum