hivemind-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hensley, Richard" <Richard.Hens...@McKesson.com>
Subject RegistryShutdownListener
Date Thu, 28 Apr 2005 17:59:26 GMT
I found the following documentation which seems to imply that if an class
implements the RegistryShutdownListener, the instance will be notified when
the registry shutsdown.

"A core service implementation may also implement the
RegistryShutdownListener  interface. When a Registry is shutdown, the
registryDidShutdown() method is invoked on all services (and many other
objects, such as proxies). The order in which these notifications occur is
not defined. A service may release any resources it may hold at this time.
It should not invoke methods on other service interfaces."

However, I'm finding that my registryDidShutdown() method is only called if
I add an <event-listener ...> to my configuration. Am I missing something?

I'm using hivemind-1.1-alpha3

Here is a test that shows the problem.

File shutdown-test.xml:

<?xml version="1.0"?>
<module id="test" version="1.0.0"
package="org.apache.hivemind.test.registry">
    <service-point id="Works" interface="MyInterface">
        <invoke-factory service-id="hivemind.BuilderFactory">
            <construct class="MyClass">
                <event-listener service-id="hivemind.ShutdownCoordinator" />
            </construct>
        </invoke-factory>
    </service-point>

    <service-point id="Broken" interface="MyInterface">
        <invoke-factory service-id="hivemind.BuilderFactory">
            <construct class="MyClass">
            </construct>
        </invoke-factory>
    </service-point>
</module>

File: MyInterface.java

package org.apache.hivemind.test.registry;
public interface MyInterface {
    public void method();
}

File: MyClass.java

package org.apache.hivemind.test.registry;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hivemind.events.RegistryShutdownListener;

public class MyClass implements MyInterface, RegistryShutdownListener {

    private static final Log LOG = LogFactory.getLog(MyClass.class);

    public void method() {
    }

    public void registryDidShutdown() {
        LOG.debug("MyClass.registryDidShutdown");
    }
}

File: ShutdownTest.java

package org.apache.hivemind.test.registry;
import org.apache.hivemind.Registry;
import org.apache.hivemind.test.HiveMindTestCase;
public class ShutdownTest extends HiveMindTestCase {
    public void testWorks() throws Exception {
        interceptLogging(MyClass.class.getName());
        Registry r = buildFrameworkRegistry("shutdown-test.xml");
        MyInterface m = (MyInterface) r.getService("test.Works",
            MyInterface.class);
        m.method();
        r.shutdown();
        assertLoggedMessage("MyClass.registryDidShutdown");
    }
    public void testTestClass() {
        MyClass tc = new MyClass();
        interceptLogging(MyClass.class.getName());
        tc.registryDidShutdown();
        assertLoggedMessage("MyClass.registryDidShutdown");
    }
    public void testBroken() throws Exception {
        interceptLogging(MyClass.class.getName());
        Registry r = buildFrameworkRegistry("shutdown-test.xml");
        MyInterface m = (MyInterface) r.getService("test.Broken",
            MyInterface.class);
        m.method();
        r.shutdown();
        assertLoggedMessage("MyClass.registryDidShutdown");
    }
}


---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-user-help@jakarta.apache.org


Mime
View raw message