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)
How is the second object getting created, when the model is set to
singleton?
This is close to accomplishing what I need to do, but I need to be sure that
instantiation is happening only once on startup.
Thanks for any pointers.
On 11/3/05, Mark Shead <[EMAIL PROTECTED]> wrote:
>
> I believe the hivemind example apps talk about some ways of doing this.
>
> You might check here:
> http://jakarta.apache.org/hivemind/hivemind-examples/panorama.html
>
> --Mark
>
> -----Original Message-----
> From: Spencer Crissman [mailto:[EMAIL PROTECTED]
> Sent: Thursday, November 03, 2005 5:01 PM
> To: [email protected]
> Subject: Re: How to initialize object/service properly?
>
> No one has any best practices or suggestions regarding this?
>
> -------------------
>
> When my application starts up, I want it to do some configuration from
> .properties files, then setup an in memory hsqldb. When it is shutdown,
> I
>
> need to perform some shutdown/cleanup, and at some point might want to
> flush the db contents to disk.
>
> I'm am unsure of the proper method of doing this within the whole
> Hivemind/Tapestry world. It seems like I could do this several ways, and
> I
>
> don't know what is best, and why:
>
> 1) Create a new java class that performs the startup logic, and then
> create a service point for it in the hivemodule.xml file. I can't figure
> out how I could make sure this happens prior to the app starting up, and
> it doesn't
>
> seem like there is any way of handling the shutdown. I believe access to
> the object could then be injected to the page.
>
> 2) Define an application object with the scope of "application" which
> would
>
> then get constructed via hivemind, in the application specification
> file.
> What is the difference between this and 1? I don't see any.
>
> 3) Create classes to act as web context listeners, and make the
> appropriate
>
> entries in the web.xml file. If I do this, I'm not sure how to access
> the objects within the tapestry pages, as this doesn't go through
> hivemind.
>
> 4) Other methods?
>
> Can someone offer insights between the differences of these methods? I
> am
>
> leaning toward 1 or 2, so that if I ever create an application form of
> the webapp, I can leverage hivemind to do the setup/teardown of that and
> basically keep all that code.
>
> Thanks for the feedback,
>
>
> Spencer
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>