hivemind-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Spencer Crissman <>
Subject Multiple Instances of Singleton Constructed?
Date Mon, 07 Nov 2005 13:54:08 GMT
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"/>

<contribution configuration-id="hivemind.EagerLoad">
<load service-id="Cleaner"/>

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,


View raw message