代码之家  ›  专栏  ›  技术社区  ›  Mike5050

Erlang如何设置自包含的主管树应用程序

  •  1
  • Mike5050  · 技术社区  · 9 年前

    我不确定我是否能正确表达我的问题,但我会尽我所能。

    我发现设置管理树(sup、sup tress和其他更复杂的树)的方式很尴尬。

    http://learnyousomeerlang.com/supervisors

    我不喜欢这样的想法:启动我的应用程序(管理树),然后在shell上发送erl命令,让应用程序也按我想要的方式运行。以现场的底部外壳为例:

    1> supervisor:start_child(band_supervisor, [djembe, good]).
    Musician Janet Tennelli, playing the djembe entered the room
    {ok,<0.690.0>}
    2> supervisor:start_child(band_supervisor, [djembe, good]).
    {error,{already_started,<0.690.0>}}
    3> supervisor:start_child(band_supervisor, [drum, good]).
    Musician Arnold Ramon, playing the drum entered the room
    {ok,<0.696.0>}
    3> supervisor:start_child(band_supervisor, [guitar, good]).
    Musician Wanda Perlstein, playing the guitar entered the room
    {ok,<0.698.0>}
    4> supervisor:terminate_child(band_supervisor, djembe).
    {error,simple_one_for_one}
    5> musicians:stop(drum).
    Arnold Ramon left the room (drum)
    ok
    

    举一个真实的例子,比如说我有一个监听器,在这个监听器上,我说我希望总是有100个监听器。他们的工作是监听监管者创建的套接字。考虑到教程(以及其他在线教程),我必须在shell中输入100次才能启动所有的孩子。

    所以,我想我的问题是。。。

    如何在应用程序或管理器中完成这一切(无论您想怎么做),以便在启动beam文件后不必在shell中键入任何内容。

    谢谢你抽出时间。

    1 回复  |  直到 9 年前
        1
  •  2
  •   Pouriya    9 年前

    你有一些选择。

    您可以在中定义一些变量 env of .app file 或在 sys.config file init/1 并返回足够数量的子规范。

    如果子项的数量和其他关于它们的信息来自其他代码,并且它们可能在不同的时间出现,则可以将一个子项命名为 dispatcher

    推荐文章