<div>The problem is in the worker:</div><div><br></div><div><span style="font-size: 12.800000190734863px;">-module(uclient_worker).</span></div><div>...</div><div><div>start_link(Pars) -></div><div> %%file:write_file("/tmp/rabbit.txt", Pars, [append]),</div><div> gen_server:start_link({global, ?MODULE}, ?MODULE, Pars, []).</div></div>
<div><div><br></div><div>?MODULE is expanded to uclient_worker at compile time and registered globally using {global, ?MODULE}, your child is starting twice under {global, uclient_worker}, hence the error. What’s after global, the name of the instance, has to be unique when starting multiple times. Same applies to local.</div><div><br></div><div>What you most likely want to do, is the following:</div><div><br></div><div><div>-define(</div><div> CHILD(Name, Args),</div><div> {Name, {</div><div> uclient_worker, start_link, [{Name, <<"callmgr">> , 3}]</div><div> }, permanent, 5000, worker, []</div><div> }</div><div>).</div></div><div>…</div><div>% use an atom here, not strings...</div><div>Children = [?CHILD(uc1, Address), ?CHILD(uc2, Address)],</div><div><br></div><div>And then, in the worker:</div><div><br></div><div><div>start_link({ Name, Bin, IntArg }) -></div><div> gen_server:start_link({global, Name}, ?MODULE, { Bin, Args }, []).</div></div><div><br></div><div>Hope it makes sense!</div>
<p style="font-family: Helvetica; font-size: 10pt; margin-bottom: 0cm;">
</p><p style="font-family: Helvetica; font-size: 10pt; margin-bottom: 0cm;">
</p><p style="margin-bottom: 0cm;">
</p><p style="margin-bottom: 0cm"><font color="#000000"><font face="Helvetica, sans-serif"><font style="font-size: 9pt">Kind
regards,
<br>Radek
Gruchalski<br>
</font></font></font><font face="Helvetica, sans-serif"><font style="font-size: 9pt"><a href="mailto:radek@gruchalski.com">radek@gruchalski.com</a><a href="mailto:radek@gruchalski.com">
</a></font></font><font color="#0084d1"><font face="Helvetica, sans-serif"><font style="font-size: 9pt"><br></font></font></font><a href="http://de.linkedin.com/in/radgruchalski/"><font color="#0084d1"><font face="Helvetica, sans-serif"><font style="font-size: 9pt">de.linkedin.com/in/radgruchalski/</font></font></font></a><font color="#000000"><font face="Helvetica, sans-serif"><font style="font-size: 9pt"><br><br></font></font></font><font color="#878787"><font face="Helvetica, sans-serif"><font style="font-size: 8pt"><b>Confidentiality:<br></b></font></font></font><font color="#878787"><font face="Helvetica, sans-serif"><font style="font-size: 8pt">This
communication is intended for the above-named person and may be
confidential and/or legally privileged.<br>If it has come to you in
error you must take no action based on it, nor must you copy or show
it to anyone; please delete/destroy and inform the sender
immediately.</font></font></font></p></div>
<p style="color: #A0A0A8;">On Thursday, 26 March 2015 at 17:59, harsha sri wrote:</p>
<blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-left:0px;padding-left:10px;">
<span><div><div><div dir="ltr"><div><div><div><div><div>Hi Rad,<br><br></div>First of all Thank you so much for immediate reply.<br><br></div>uclient worker start method:<br><br><br><br>-module(uclient_worker).<br>-behaviour(gen_server).<br><br><span style="background-color:rgb(0,255,0)">-export([start_link/1]).<br><br>-export([init/1, handle_call/3, handle_cast/2, handle_info/2,<br> terminate/2, code_change/3]).<br><br>-export([fire/0]).<br><br>-export([add_subscriber/4, spawn_subscriber/3]).<br><br>-include_lib("amqp_client/include/amqp_client.hrl").<br><br>-record(state, {channel,java_port :: port(),java_node :: atom(),queuen,nofs}).<br><br>-define(RKFormat,<br> "~4.10.0B.~2.10.0B.~2.10.0B.~1.10.0B.~2.10.0B.~2.10.0B.~2.10.0B").<br><br><br>start_link(Pars) -><br> %%<a href="file:write">file:write</a>_file("/tmp/rabbit.txt", Pars, [append]),<br> gen_server:start_link({global, ?MODULE}, ?MODULE, Pars, []).<br><br>%---------------------------<br>% Gen Server Implementation<br>% --------------------------<br><br>init(Pars) -></span><br><br><br></div>Regarding to CHILD in supervisor:<br><br></div>actually my initial supervisor is :<br>%%%%%%%%<br>-module(uclient_sup).<br><br>-behaviour(supervisor).<br><br>-export([start_link/0, init/1]).<br><br>start_link() -><br> supervisor:start_link({local, ?MODULE}, ?MODULE, _Arg = []).<br><br>init([]) -><br> {ok, {{one_for_one, 1, 10},<br> [{uclient_worker,<br> {uclient_<span style="background-color:rgb(255,255,0)"><span style=""></span></span>worker, start_link, [{<<"callmgr">> , 3}]},<br> permanent,<br> 10,<br> worker,<br> [uclient_worker]}<br> ]}}.<span style="background-color:rgb(0,255,255)"><span style=""></span></span><br><span style="background-color:rgb(243,243,243)"><span style="">%%%%%%%%%%%%%<br><br><br></span></span></div><div><span style="background-color:rgb(243,243,243)"><span style="">But i changed above code for invoking multiple worker under supervisor based on conditions.<br></span></span></div><div><span style="background-color:rgb(243,243,243)"><span style="">In that process i just changed code using CHILD.<br><br></span></span></div><div><span style="background-color:rgb(243,243,243)"><span style="">Regards,<br></span></span></div><div><span style="background-color:rgb(243,243,243)"><span style="">Harsha<br></span></span></div><span style="background-color:rgb(255,255,0)"><span style=""><span style="background-color:rgb(243,243,243)"></span></span></span><div><div><div><span style="background-color:rgb(255,255,0)"><span style=""><br></span></span><div><div><br></div></div></div></div></div></div><div><br><div>On Thu, Mar 26, 2015 at 9:41 PM, Rad Gruchalski <span dir="ltr"><<a href="mailto:radek@gruchalski.com" target="_blank">radek@gruchalski.com</a>></span> wrote:<br><blockquote type="cite"><div>
<div>
Can you show start_link of the <span style="font-size:12.800000190734863px;background-color:rgb(0,255,255)">uclient_worker</span>?</div><div>
<p style="font-family:Helvetica;font-size:10pt;margin-bottom:0cm">
</p><p style="font-family:Helvetica;font-size:10pt;margin-bottom:0cm">
</p><p style="margin-bottom:0cm">
</p><p style="margin-bottom:0cm"><font color="#000000"><font face="Helvetica, sans-serif"><font style="font-size:9pt">Kind
regards,
<br>Radek
Gruchalski<br>
</font></font></font><font face="Helvetica, sans-serif"><font style="font-size:9pt"><a href="mailto:radek@gruchalski.com" target="_blank">radek@gruchalski.com</a><a href="mailto:radek@gruchalski.com" target="_blank">
</a></font></font><font color="#0084d1"><font face="Helvetica, sans-serif"><font style="font-size:9pt"><br></font></font></font><a href="http://de.linkedin.com/in/radgruchalski/" target="_blank"><font color="#0084d1"><font face="Helvetica, sans-serif"><font style="font-size:9pt">de.linkedin.com/in/radgruchalski/</font></font></font></a><font color="#000000"><font face="Helvetica, sans-serif"><font style="font-size:9pt"><br><br></font></font></font><font color="#878787"><font face="Helvetica, sans-serif"><font style="font-size:8pt"><b>Confidentiality:<br></b></font></font></font><font color="#878787"><font face="Helvetica, sans-serif"><font style="font-size:8pt">This
communication is intended for the above-named person and may be
confidential and/or legally privileged.<br>If it has come to you in
error you must take no action based on it, nor must you copy or show
it to anyone; please delete/destroy and inform the sender
immediately.</font></font></font></p></div><div><div>
<p style="color:#a0a0a8">On Thursday, 26 March 2015 at 15:49, harsha sri wrote:</p>
</div></div><blockquote type="cite"><div>
<span><div><div><div><div><div dir="ltr"><div><div><div><div><div><div>Hi,<br><br></div>I am trying to start same worker multiple times in Supervisor but its giving me error.<br></div>Here is my Supervisor:<br><br><br><span style="background-color:rgb(0,255,255)">-module(uclient_sup).<br><br>-behaviour(supervisor).<br><br>-export([start_link/0, init/1]).<br><br>-define(<br> CHILD(Name, Args),<br> {Name, {<br> uclient_worker, start_link, [{<<"callmgr">> , 3}]<br> }, permanent, 5000, worker, []<br> }<br>).<br><br>start_link() -><br> supervisor:start_link({global, ?MODULE}, ?MODULE, _Arg = []).<br><br>init([]) -><br> Children = [?CHILD("uc1", Address), ?CHILD("uc2", Address)],<br> {ok, { {one_for_one, 6, 10}, Children }}.</span><br><br></div>I am getting below error:<br><br>Error: {could_not_start,uclient,<br> {{shutdown,<br> {failed_to_start_child,"uc2",{already_started,<5169.429.0>}}},<br> {uclient,start,[normal,[]]}}}<br><br><br></div>Please help me in solving this issue. I am new to erlang.<br><br></div>Thanks & Regards,<br></div>SriHarsha.<br></div>
</div></div></div><div><div>_______________________________________________</div><div>erlang-questions mailing list</div><div><a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a></div><div><a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a></div></div></div></span>
</div></blockquote><div>
<br>
</div>
</div></blockquote></div><br></div>
</div></div></span>
</blockquote>
<div>
<br>
</div>