tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/48-eventmap-problem-in-actorRobotlegs: Discussion 2013-04-28T10:02:48Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/10863112010-02-23T10:26:20Z2010-02-23T10:26:24ZeventMap problem in actor<div><p>Hello,<br>
I have a problem with an eventMap wich doesn't listen my event.<br>
Maybe I use wrong it :<br>
I have a loader:Loader and I try to listen Complete Event from his
contentLoaderInfo in a Service wich extends Actor :<br>
<code>public class LoadModuleService extends Actor implements
ILoadModuleService</code>
<code>eventMap.mapListener(_loader.contentLoaderInfo,
Event.COMPLETE, _moduleLoaded);</code></p>
<p>in my context :<br>
<code>injector.mapClass(ILoadModuleService,
LoadModuleService);</code></p>
<p>The method "_moduleLoaded" is never called.</p>
<p>If I write :<br>
<code>_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
_moduleLoaded);</code> It works !</p>
<p>We can use eventMap on no RL elements or we need use default
addEventListener way ?</p>
<p>For information, I call this service via a Command just after
the startup Complete. If I call it later, it works...</p>
<p>I attach simplified sources.</p>
<p>Thanks !</p></div>myrddintag:robotlegs.tenderapp.com,2009-10-18:Comment/10863112010-02-26T02:10:22Z2010-02-26T02:10:22ZeventMap problem in actor<div><p>Hi,</p>
<p>I've tested this and can't reproduce the problem. I've attached
a simple test application (that is rather silly, but does perform
the actions).</p></div>Joel Hookstag:robotlegs.tenderapp.com,2009-10-18:Comment/10863112010-02-26T02:59:13Z2010-02-26T02:59:13ZeventMap problem in actor<div><p>I was looking in your context:</p>
<p>injector.mapClass(ILoadModuleService, LoadModuleService);</p>
<p>This will load a new instance of the service with every call, is
that intentional? I'd almost guess that you are getting garbage
collected. The reason it gets GC'd is that there is no reference to
the Actor anywhere. It is create the one time in the command and
then gets GC'd. eventMap uses a weak reference, addEventListener is
a GC blocking ref. If you use mapSingletonOf the Injector keeps a
ref. Because you are using mapClass no ref is kept anywhere and you
get fail.</p></div>Joel Hookstag:robotlegs.tenderapp.com,2009-10-18:Comment/10863112010-02-26T08:50:21Z2010-02-26T08:50:24ZeventMap problem in actor<div><p>First, thank you for your answer.<br>
Yes, it is intentional. I understand what you're explaining to
me.<br>
After the command executed, my command and my service are GC'd,
even if my service has not terminated his action.<br>
Either I execute my loading in the command, or I map my service as
a singleton ? What is the better way ?</p></div>myrddintag:robotlegs.tenderapp.com,2009-10-18:Comment/10863112010-02-26T08:56:35Z2010-02-26T08:56:35ZeventMap problem in actor<div><p>Or, option 3, don't use the eventMap and stick with
addEventListener. If you <em>need</em> a unique instance of the
service for every injection and have to use mapClass, then do that.
Otherwise use injector.mapSingletonOf().</p></div>Joel Hooks