[erlang-questions] Gen supervisor query...

Edwin Fine <>
Mon Sep 22 13:26:37 CEST 2008


Hi Dan

The first thing that comes to mind is, does the generic_tcp_server register
itself? If so, the second one will fail to start. Do you see any error
messages? I find if you start SASL before you run your program, you may get
better error information (application:start(sasl), or -boot sasl on the
command line). Anotyher possibility is, could one of them have died before
you looked in appmon? What does your output/error log look like?

The other thing is, instead of explicitly looking in registered() for your
connection monitor, you coud just use whereis():

case whereis(?CONNCOUNTER) of
    undefined -> % Not registered
        register(?CONNCOUNTER, spawn(fun() -> counter(0, MaxConnections)
end)),
        error_logger:info_msg("TCP server <~p> started TCP connection
monitor.~n", [self()]);
    Pid ->
        error_logger:info_msg(
            "TCP connection monitor (~p) already registered as ~p
...SKIPPING~n",
            [?CONNCOUNTER, Pid]
        )
end

Hope this helps.

2008/9/22 <>

>  Hi all,
>
> I have a simple supervisor setup which is watching two worker processes.
>
> Now I have created the init method as such:
>
>
> init(Args) ->
>
>     [{port,Port},{maxconns, MaxConnections},{sockethandlermod,
> SocketHandlerMod}] = Args,
>
>     Registered = registered(),
>
>     case lists:any(fun(X) -> X =:= ?CONNCOUNTER end, Registered) of
>
>         true ->
>
>             error_logger:info_msg("TCP connection monitor (~p) already
> registered...SKIPPING~n",[?CONNCOUNTER]);
>
>         false ->
>
>             register(?CONNCOUNTER, spawn(fun() -> counter(0,
> MaxConnections) end)),
>
>             error_logger:info_msg("TCP server <~p> started TCP connection
> monitor.~n", [self()])
>
> end,
>
>
>
> GenTcpServer1 =
> {'GenTcpServer1',{generic_tcp_server,start_link,[Port,SocketHandlerMod]},
> permanent,2000,worker,[generic_tcp_server]},
>
> GenTcpServer2 =
> {'GenTcpServer2',{generic_tcp_server,start_link,[Port,SocketHandlerMod]},
> permanent,2000,worker,[generic_tcp_server]},
>
> {ok,{{one_for_one,0,1}, [GenTcpServer1, GenTcpServer2]}}.
>
> N
> othing fancy going on there - I would expect this supervisor to start both GenTcpServer1 AND GenTcpServer2 given two speca have been returned?
>
> For some reason it is only starting one when I look in appmon etc.
>
> Any thoughts?
>
> Many Thanks,
> Dan
>
>
>
> ***********************************************************************************
> The Royal Bank of Scotland plc. Registered in Scotland No 90312. Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB.
> Authorised and regulated by the Financial Services Authority
>
> This e-mail message is confidential and for use by the
> addressee only. If the message is received by anyone other
> than the addressee, please return the message to the sender
> by replying to it and then delete the message from your
> computer. Internet e-mails are not necessarily secure. The
> Royal Bank of Scotland plc does not accept responsibility for
> changes made to this message after it was sent.
>
> Whilst all reasonable care has been taken to avoid the
> transmission of viruses, it is the responsibility of the recipient to
> ensure that the onward transmission, opening or use of this
> message and any attachments will not adversely affect its
> systems or data. No responsibility is accepted by The
> Royal Bank of Scotland plc in this regard and the recipient should carry
> out such virus and other checks as it considers appropriate.
> Visit our websites at: www.rbs.comwww.rbs.com/gbmwww.rbsgc.com
> ***********************************************************************************
>
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080922/b7e39be9/attachment.html>


More information about the erlang-questions mailing list