<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hello Ivan,<div><br></div><div>I had a similar issue that you have. </div><div>I've done a small library <a href="https://github.com/fogfish/pts">https://github.com/fogfish/pts</a></div><div>The library is similar to gproc but it also it brings data owner/consumer interaction. E.g. you can build key/val storage over my_lamb processes. </div><div><br></div><div>The usage is very simple, please see pts_cache.erl for example. You have to hook pts with my_lamb after that process can be resolved via pns:whereis(N, Uid)</div><div><br></div><div><pre style="margin: 0px; padding: 0px; border: 0px; font-size: 12px; font-family: Consolas, 'Liberation Mono', Courier, monospace; color: rgb(51, 51, 51); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 16px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div class="line" id="LC36" style="margin: 0px; padding: 0px 0px 0px 10px; border: 0px; "><span class="c" style="margin: 0px; padding: 0px; border: 0px; color: rgb(153, 153, 136); font-style: italic; ">%%</span></div><div class="line" id="LC37" style="margin: 0px; padding: 0px 0px 0px 10px; border: 0px; "><span class="c" style="margin: 0px; padding: 0px; border: 0px; color: rgb(153, 153, 136); font-style: italic; ">%%</span></div><div class="line" id="LC38" style="margin: 0px; padding: 0px 0px 0px 10px; border: 0px; "><span class="nf" style="margin: 0px; padding: 0px; border: 0px; color: rgb(153, 0, 0); font-weight: bold; ">start_link</span><span class="p" style="margin: 0px; padding: 0px; border: 0px; ">(</span><span class="nv" style="margin: 0px; padding: 0px; border: 0px; color: rgb(0, 128, 128); ">Ns</span><span class="p" style="margin: 0px; padding: 0px; border: 0px; ">,</span> <span class="nv" style="margin: 0px; padding: 0px; border: 0px; color: rgb(0, 128, 128); ">Uid</span><span class="p" style="margin: 0px; padding: 0px; border: 0px; ">)</span> <span class="o" style="margin: 0px; padding: 0px; border: 0px; font-weight: bold; ">-></span></div><div class="line" id="LC39" style="margin: 0px; padding: 0px 0px 0px 10px; border: 0px; "> <span class="nn" style="margin: 0px; padding: 0px; border: 0px; color: rgb(85, 85, 85); ">gen_server</span><span class="p" style="margin: 0px; padding: 0px; border: 0px; ">:</span><span class="n" style="margin: 0px; padding: 0px; border: 0px; ">start_link</span><span class="p" style="margin: 0px; padding: 0px; border: 0px; ">(</span><span class="o" style="margin: 0px; padding: 0px; border: 0px; font-weight: bold; ">?</span><span class="nv" style="margin: 0px; padding: 0px; border: 0px; color: rgb(0, 128, 128); ">MODULE</span><span class="p" style="margin: 0px; padding: 0px; border: 0px; ">,</span> <span class="p" style="margin: 0px; padding: 0px; border: 0px; ">[</span><span class="nv" style="margin: 0px; padding: 0px; border: 0px; color: rgb(0, 128, 128); ">Ns</span><span class="p" style="margin: 0px; padding: 0px; border: 0px; ">,</span> <span class="nv" style="margin: 0px; padding: 0px; border: 0px; color: rgb(0, 128, 128); ">Uid</span><span class="p" style="margin: 0px; padding: 0px; border: 0px; ">],</span> <span class="p" style="margin: 0px; padding: 0px; border: 0px; ">[]).</span></div><div class="line" id="LC40" style="margin: 0px; padding: 0px 0px 0px 10px; border: 0px; "> </div><div class="line" id="LC41" style="margin: 0px; padding: 0px 0px 0px 10px; border: 0px; "><span class="nf" style="margin: 0px; padding: 0px; border: 0px; color: rgb(153, 0, 0); font-weight: bold; ">init</span><span class="p" style="margin: 0px; padding: 0px; border: 0px; ">([</span><span class="nv" style="margin: 0px; padding: 0px; border: 0px; color: rgb(0, 128, 128); ">Ns</span><span class="p" style="margin: 0px; padding: 0px; border: 0px; ">,</span> <span class="nv" style="margin: 0px; padding: 0px; border: 0px; color: rgb(0, 128, 128); ">Uid</span><span class="p" style="margin: 0px; padding: 0px; border: 0px; ">])</span> <span class="o" style="margin: 0px; padding: 0px; border: 0px; font-weight: bold; ">-></span></div><div class="line" id="LC42" style="margin: 0px; padding: 0px 0px 0px 10px; border: 0px; "> <span class="nn" style="margin: 0px; padding: 0px; border: 0px; color: rgb(85, 85, 85); ">pns</span><span class="p" style="margin: 0px; padding: 0px; border: 0px; ">:</span><span class="nb" style="margin: 0px; padding: 0px; border: 0px; color: rgb(0, 134, 179); ">register</span><span class="p" style="margin: 0px; padding: 0px; border: 0px; ">(</span><span class="nv" style="margin: 0px; padding: 0px; border: 0px; color: rgb(0, 128, 128); ">Ns</span><span class="p" style="margin: 0px; padding: 0px; border: 0px; ">,</span> <span class="nv" style="margin: 0px; padding: 0px; border: 0px; color: rgb(0, 128, 128); ">Uid</span><span class="p" style="margin: 0px; padding: 0px; border: 0px; ">),</span></div><div class="line" id="LC44" style="margin: 0px; padding: 0px 0px 0px 10px; border: 0px; "> <span class="p" style="margin: 0px; padding: 0px; border: 0px; ">{</span><span class="n" style="margin: 0px; padding: 0px; border: 0px; ">ok</span><span class="p" style="margin: 0px; padding: 0px; border: 0px; ">,</span> <span class="nl" style="margin: 0px; padding: 0px; border: 0px; ">#srv</span><span class="p" style="margin: 0px; padding: 0px; border: 0px; ">{</span><span class="n" style="margin: 0px; padding: 0px; border: 0px; ">ns</span><span class="o" style="margin: 0px; padding: 0px; border: 0px; font-weight: bold; ">=</span><span class="nv" style="margin: 0px; padding: 0px; border: 0px; color: rgb(0, 128, 128); ">Ns</span><span class="p" style="margin: 0px; padding: 0px; border: 0px; ">,</span> <span class="n" style="margin: 0px; padding: 0px; border: 0px; ">uid</span><span class="o" style="margin: 0px; padding: 0px; border: 0px; font-weight: bold; ">=</span><span class="nv" style="margin: 0px; padding: 0px; border: 0px; color: rgb(0, 128, 128); ">Uid</span><span class="p" style="margin: 0px; padding: 0px; border: 0px; ">}}.</span> </div></pre><div><br></div></div><div><pre style="margin: 0px; padding: 0px; border: 0px; font-size: 12px; font-family: Consolas, 'Liberation Mono', Courier, monospace; color: rgb(51, 51, 51); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 16px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div class="line" id="LC75" style="margin: 0px; padding: 0px 0px 0px 10px; border: 0px; "><span class="nf" style="margin: 0px; padding: 0px; border: 0px; color: rgb(153, 0, 0); font-weight: bold; ">terminate</span><span class="p" style="margin: 0px; padding: 0px; border: 0px; ">(_</span><span class="nv" style="margin: 0px; padding: 0px; border: 0px; color: rgb(0, 128, 128); ">Reason</span><span class="p" style="margin: 0px; padding: 0px; border: 0px; ">,</span> <span class="nl" style="margin: 0px; padding: 0px; border: 0px; ">#srv</span><span class="p" style="margin: 0px; padding: 0px; border: 0px; ">{</span><span class="n" style="margin: 0px; padding: 0px; border: 0px; ">ns</span><span class="o" style="margin: 0px; padding: 0px; border: 0px; font-weight: bold; ">=</span><span class="nv" style="margin: 0px; padding: 0px; border: 0px; color: rgb(0, 128, 128); ">Ns</span><span class="p" style="margin: 0px; padding: 0px; border: 0px; ">,</span> <span class="n" style="margin: 0px; padding: 0px; border: 0px; ">uid</span><span class="o" style="margin: 0px; padding: 0px; border: 0px; font-weight: bold; ">=</span><span class="nv" style="margin: 0px; padding: 0px; border: 0px; color: rgb(0, 128, 128); ">Uid</span><span class="p" style="margin: 0px; padding: 0px; border: 0px; ">})</span> <span class="o" style="margin: 0px; padding: 0px; border: 0px; font-weight: bold; ">-></span></div><div class="line" id="LC76" style="margin: 0px; padding: 0px 0px 0px 10px; border: 0px; "> <span class="nn" style="margin: 0px; padding: 0px; border: 0px; color: rgb(85, 85, 85); ">pns</span><span class="p" style="margin: 0px; padding: 0px; border: 0px; ">:</span><span class="nb" style="margin: 0px; padding: 0px; border: 0px; color: rgb(0, 134, 179); ">unregister</span><span class="p" style="margin: 0px; padding: 0px; border: 0px; ">(</span><span class="nv" style="margin: 0px; padding: 0px; border: 0px; color: rgb(0, 128, 128); ">Ns</span><span class="p" style="margin: 0px; padding: 0px; border: 0px; ">,</span> <span class="nv" style="margin: 0px; padding: 0px; border: 0px; color: rgb(0, 128, 128); ">Uid</span><span class="p" style="margin: 0px; padding: 0px; border: 0px; ">),</span></div><div class="line" id="LC77" style="margin: 0px; padding: 0px 0px 0px 10px; border: 0px; "> <span class="n" style="margin: 0px; padding: 0px; border: 0px; ">ok</span><span class="p" style="margin: 0px; padding: 0px; border: 0px; ">.</span></div><div><span class="p" style="margin: 0px; padding: 0px; border: 0px; "><br></span></div><div><span class="p" style="margin: 0px; padding: 0px; border: 0px; ">Of course library does not preserve state ove crash but it keep {Ns, Uid} mapping to process is consistent manner even if process crashes. BTW, if you start to use either pts or gproc then my_lambs process becomes unnecessary overhead.</span></div><div><span class="p" style="margin: 0px; padding: 0px; border: 0px; "><br></span></div></pre></div><div>- Dmitry</div><div><br></div><div><br><div><div>On Oct 19, 2012, at 6:03 PM, Ivan Uemlianin wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Dear All<br><br>I have an erlang/OTP application consisting mostly of gen_servers. One repeated pattern is having a gateway/aggregate gen_server process that provides access (and other management) to individual gen_server processes, e.g.:<br><br> my_sup<br> |<br> my_lambs<br> / \ \<br> my_lamb my_lamb my_lamb ...<br><br>my_lambs' state variable holds a dictionary {LambName: LambPid} and among other functions it allows me to call lambs by name instead of my Pid.<br><br>If my_lambs terminates normally --- e.g., if the whole application is closing down --- its terminate/s function can call my:lamb:stop for each of the processes in its care.<br><br>However, if my_lambs terminates abnormally, and is restarted by my_sup, I think I'd like to preserve its state variable --- at least the Pids of the my_lamb processes --- so that it can be passed on to the new version of my_lambs.<br><br>I'd like to avoid losing all of the my_lamb processes, if the my_lambs process crashes.<br><br>Can state be passed to the supervisor, to be used when it restarts its child?<br><br>Could I park the state variable in some kind of holding process, so that the new my_lambs can retrieve it?<br><br>Or is there another way of doing this?<br><br>With thanks and best wishes<br><br>Ivan<br><br><br><br>-- <br>============================================================<br>Ivan A. Uemlianin PhD<br>Llaisdy<br>Speech Technology Research and Development<br><br> <a href="mailto:ivan@llaisdy.com">ivan@llaisdy.com</a><br> <a href="http://www.llaisdy.com">www.llaisdy.com</a><br> <a href="http://llaisdy.wordpress.com">llaisdy.wordpress.com</a><br> <a href="http://github.com/llaisdy">github.com/llaisdy</a><br> <a href="http://www.linkedin.com/in/ivanuemlianin">www.linkedin.com/in/ivanuemlianin</a><br><br> "hilaritas excessum habere nequit"<br> (Spinoza, Ethica, IV, XLII)<br>============================================================<br>_______________________________________________<br>erlang-questions mailing list<br><a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>http://erlang.org/mailman/listinfo/erlang-questions<br></div></blockquote></div><br></div></body></html>