I have a Tapestry application in which I am attempting to use hivemind
for some startup and shutdown handling. Basically starting some
services when loaded, and then cleaning up after them when the
application is undeployed or shutdown.
As a simple test, I have added the following to my hivemodule.xml:
<service-point id="Cleaner" interface="Cleaner">
<invoke-factory model="singleton">
<construct class="Cleaner">
<event-listener
service-id="hivemind.ShutdownCoordinator"/>
</construct>
</invoke-factory>
</service-point>
<contribution configuration-id="hivemind.EagerLoad">
<load service-id="Cleaner"/>
</contribution>
And the following class to my project:
public class Cleaner implements RegistryShutdownListener {
public static int c;
public Cleaner( ) {
c = c + 1;
System.out.println("Cleaner constructed! (" + String.valueOf(c) + ")");
}
public void registryDidShutdown() {
System.out.println("The registry has shutdown! (" + String.valueOf(c) + ")" );
c = c - 1;
}
}
Oddly, when I go through the process of starting up and shutting down, I see the following:
Cleaner constructed! (1)
Cleaner constructed! (2)
The registry has shutdown! (2)
The registry has shutdown! (1)
It appears that two instances of the Cleaner class are being
constructed, when what I really want is a singleton that gets created
one time on startup, and then gets called a single time at
shutdown. From the messages it appears that the problem is with
the startup portion of the code, because if two instances were not
created, then there would be only one instance registered for the
shutdown event.
Where is hivemind being instructed to construct the second instance, and how could I prevent it from happening?
Thanks in Advance,
Spencer
- Multiple Instances of Singleton Constructed? Spencer Crissman
- RE: Multiple Instances of Singleton Constructed? James Carman
- Re: Multiple Instances of Singleton Constructed? Spencer Crissman
- RE: Multiple Instances of Singleton Construc... James Carman
- Re: Multiple Instances of Singleton Cons... Spencer Crissman
- RE: Multiple Instances of Singleton... James Carman
- Re: Multiple Instances of Singl... Spencer Crissman
