You may consider writing a "generic" monitor, and then interface-specific callback handlers.<div><br></div><div>eg, dev_mon and then you tell it "if1_event1 call handle_event_if1_event1"</div><div><br></div>
<div>In this case you separate out the "handling logic" from the "monitoring logic."  You will need to maintain multiple sets of handlers (one per interface) but then you're not duplicating the routing/monitoring parts.</div>
<div><br></div><div>Also, and I've done this, is to have a "default handler" and all messages which don't match the specific handler get shunted to the default handler.</div><div><br></div><div>eg, </div>
<div><br></div><div>event received -> lookup/match to specific handler -> route to if1_handler  -> no_match -> route to default_handler -> drop on floor/throw error/whatever for a no-match condition.</div><div>
<br></div><div>This works well for putting in "global catchall handlers" and also works for "overriding handlers."  (eg, if1_handler -> subclass_handler -> class_handler -> default_handler)</div>
<div><br></div><div>-mox<br><br><div class="gmail_quote">On Mon, Sep 24, 2012 at 8:54 AM, Matthew Evans <span dir="ltr"><<a href="mailto:mattevans123@hotmail.com" target="_blank">mattevans123@hotmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<div><div dir="ltr">
Hi,<div><br></div><div>I have an application (let's call it dev_mon) that is responsible for listening to, processing and emitting events on a hardware interface. This application contains 3 supervisors and many registered gen_server processes. Currently we have a single interface that requires supervision.</div>
<div><br></div><div>Future hardware revisions will expose multiple interfaces that requires dev_mon to monitor. Obviously I can handle this in the code, however I believe a better solution would be to have multiple instances of dev_mon for each interface.</div>
<div><br></div><div>In this case I would have application dev_mon_if1, dev_mon_if2, dev_mon_if3 etc. </div><div><br></div><div>The only way I can think of to implement this is to write 3 separate application files (in their own directories) along with their associated Erlang app files. For example:</div>
<div><br></div><div>dev_mon_if1/ebin/dev_mon_if1.erl</div><div>dev_mon_if1/ebin/dev_mon_if1.app</div><div><br></div><div><div>dev_mon_if2/ebin/dev_mon_if2.erl</div><div>dev_mon_if2/ebin/dev_mon_if2.app</div></div><div><br>
</div><div>dev_mon_if/ebin/..all the other beam files shared between all instances..</div><div><br></div><div>The ".app" file would contain an env property that ensures the registered supervisors and gen_servers are unique (e.g. if1, if2 etc).</div>
<div><br></div><div>i.e. not do:</div><div><br></div><div>







<p>start_link() <span>-></span></p>
<p><span style="font-size:10pt">    gen_server:start_link({local, </span><span style="font-size:10pt">?MODULE</span><span style="font-size:10pt">}, </span><span style="font-size:10pt">?MODULE</span><span style="font-size:10pt">, [], []).</span></p>
<p><br></p><p>Instead to:</p><p><br></p><p></p><p>start_link(RegName) <span>-></span></p><p><span style="font-size:10pt">    gen_server:start_link({local, </span><span style="font-size:10pt">RegName</span><span style="font-size:10pt">}, </span><span style="font-size:10pt">?MODULE</span><span style="font-size:10pt">, [], []).</span></p>
<p></p><p><br></p><p>Where RegName is an atom like 'if1_monitorapp'.</p><p><br></p><p>Question: Is there a better way to do this?</p><p><br></p><p>Thanks</p><p><br></p><p>Matt</p><p><br></p></div>                                          </div>
</div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>