Return-Path: Delivered-To: apmail-jakarta-hivemind-user-archive@www.apache.org Received: (qmail 72761 invoked from network); 7 Nov 2005 19:23:18 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 7 Nov 2005 19:23:18 -0000 Received: (qmail 42731 invoked by uid 500); 7 Nov 2005 19:23:17 -0000 Delivered-To: apmail-jakarta-hivemind-user-archive@jakarta.apache.org Received: (qmail 42578 invoked by uid 500); 7 Nov 2005 19:23:15 -0000 Mailing-List: contact hivemind-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: hivemind-user@jakarta.apache.org List-Id: Delivered-To: mailing list hivemind-user@jakarta.apache.org Received: (qmail 42460 invoked by uid 99); 7 Nov 2005 19:23:14 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 07 Nov 2005 11:23:13 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of spencer.crissman@gmail.com designates 66.249.82.199 as permitted sender) Received: from [66.249.82.199] (HELO xproxy.gmail.com) (66.249.82.199) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 07 Nov 2005 11:23:06 -0800 Received: by xproxy.gmail.com with SMTP id t13so460879wxc for ; Mon, 07 Nov 2005 11:22:51 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=JvGvE62m0fX0cWtIWXNh+1+0G5/Lc+DBGoqGu24o/1oLVCtZwAoPUzFKGFpxNLLMN8X7Rm8yGUdGxfb0Wi8tFcI5FgQtGtiqo0+D9oc6BpynVZP0VOzc+xMD9VG7INTP7atKSqvbCuf/N0HEz29FislVHpgrCi2vxjNLy3WJuCc= Received: by 10.65.230.6 with SMTP id h6mr5659007qbr; Mon, 07 Nov 2005 11:22:50 -0800 (PST) Received: by 10.65.38.19 with HTTP; Mon, 7 Nov 2005 11:22:50 -0800 (PST) Message-ID: <8518d4f50511071122l4e6e4dfdga07da93260f9eed5@mail.gmail.com> Date: Mon, 7 Nov 2005 14:22:50 -0500 From: Spencer Crissman To: hivemind-user@jakarta.apache.org Subject: Re: Multiple Instances of Singleton Constructed? In-Reply-To: <004801c5e3cc$aec189c0$6701a8c0@CARMANI9300> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_80665_30672091.1131391370618" References: <8518d4f50511070655k6d2ef809p36e935049b11d7e2@mail.gmail.com> <004801c5e3cc$aec189c0$6701a8c0@CARMANI9300> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N ------=_Part_80665_30672091.1131391370618 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline I'm using 1.1. That's a good pointer about the automatic registration. I need the setup and shutdown code to occur once and only once per startup/shutdown. When I supplied the class as the interface to the service= , the code was getting called twice, once when the proxy object was created, and once when the actual object was instanciated, based upon what you had said in your email. So, in order to do away with the call that was being performed by the proxy class, I created the empty interface, implemented it in the class, and supplied the interface as the service interface. Since th= e proxy class wasn't generated, the call occurs only once. In a real app, the interface probably wouldn't be empty(?). It seems to be working as far as I can tell, but does the reasoning make sense? I want some code to be called once and only once on startup, and som= e additional code called once and only once on shutdown. I don't know what th= e best practice would be using hivemind, but this seems reasonable. This is just some test code to try to get my mind around hivemind prior to putting it to use in my next tapestry app. On 11/7/05, James Carman wrote: > > No problem! What version of HiveMind are you using? If you're using 1.1, > you don't have to manually register your implementation object as a shutd= own > listener They will be registered for you automatically ( > http://issues.apache.org/jira/browse/HIVEMIND-103) if the implementation > class implements RegistryShutdownListener. > > Also, what purpose would an empty service interface serve? Are you just > trying to perform some operations upon registry shutdown? I'm just trying= to > figure out what a use case would be for that scenario. Of course, you cou= ld > just be playing around with HiveMind's features too! :-) Anyway, glad we > could help. Enjoy! > > ------------------------------ > > *From:* Spencer Crissman [mailto:spencer.crissman@gmail.com] > *Sent:* Monday, November 07, 2005 9:55 AM > *To:* hivemind-user@jakarta.apache.org > *Subject:* Re: Multiple Instances of Singleton Constructed? > > Thank you! This was very helpful. Creating an empty interface ICleaner > and having Cleaner implement it resulting in the expected behavior (singl= e > constructed and shutdown message). > > > On 11/7/05, *James Carman* wrote: > > This happens because the actual proxy object is an instance of a subclass > of Cleaner. You are not proxying via an interface, so HiveMind is generat= ing > a subclass to do the proxying. > > ------------------------------ > > *From:* Spencer Crissman [mailto:spencer.crissman@gmail.com] > *Sent:* Monday, November 07, 2005 8:54 AM > *To:* hivemind-user@jakarta.apache.org > *Subject:* Multiple Instances of Singleton Constructed? > > 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: > > > > > > > > > > > > > And the following class to my project: > > public class Cleaner implements RegistryShutdownListener { > > public static int c; > > public Cleaner( ) { > c =3D c + 1; > System.out.println("Cleaner constructed! (" + String.valueOf(c) + ")"); > } > > public void registryDidShutdown() { > System.out.println("The registry has shutdown! (" + String.valueOf(c) + > ")" ); > c =3D 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 message= s > it appears that the problem is with the startup portion of the code, beca= use > 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 > > ------=_Part_80665_30672091.1131391370618 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline I'm using 1.1.  That's a good pointer about the automatic registration= .

I need the setup and shutdown code to occur once and only once per startup/shutdown.  When I supplied the class as the interface to the service, the code was getting called twice, once when the proxy object was created, and once when the actual object was instanciated, based upon what you had said in your email.  So, in order to do away with the call that was being performed by the proxy class, I created the empty interface, implemented it in the class, and supplied the interface as the service interface.  Since the proxy class wasn't generated, the call occurs only once.  In a real app, the interface probably wouldn't be empty(?).

It seems to be working as far as I can tell, but does the reasoning make sense?  I want some code to be called once and only once on startup, and some additional code called once and only once on shutdown.  I don't know what the best practice would be using hivemind, but this seems reasonable. 

This is just some test code to try to get my mind around hivemind prior to = putting it to use in my next tapestry app.




On 11/7/05, James Carman <jame= s@carmanconsulting.com> wrote:

No problem!  What version of = HiveMind are you using?  If you're using 1.1, you don't have to manually register your implementation object as a shutdown listener  They will = be registered for you automatically (http://issues.apache.org/jira/browse/HIVEMIND-103) if the implementation class implements RegistryShutdownListener.  =

 

 

Also, what purpose would an empty = service interface serve?  Are you just trying to perform some operations upon registry shutdown?  I'm just trying to figure out what a use case would be for that scenario.  Of course, you could just be playing around with HiveMind's features too! :-)  Anyway, glad we could help.  Enjoy!

 


From: Spencer Crissman [mailto:spencer.cris= sman@gmail.com]
Sent: Monday, November 07,= 2005 9:55 AM
To: hivemind-user@jakarta.apache.org
Subject: Re: Multiple Inst= ances of Singleton Constructed?

=  

Th= ank you!  This was very helpful.  Creating an empty interface ICleaner and having Cleaner implement it resulting in th= e expected behavior (single constructed and shutdown message).


On 11/7/05, James Carman < james@carmanconsulting.com> wrote:

Th= is happens because the actual proxy object is an instance of a subclass of Cleaner.  You are = not proxying via an interface, so HiveMind is generating a subclass to do the proxying.

&n= bsp;


From: Spencer Crissman [mailto:spencer.cris= sman@gmail.com]
Sent: Monday, November 07,= 2005 8:54 AM
To: hivemind-user@jakarta.apache.org
Subject: Multiple Instance= s of Singleton Constructed?

 

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 th= e application is undeployed or shutdown. 

As a simple test, I have added the following to my hivemodule.xml:
   <service-point id=3D"Cleaner" interface=3D"Cleaner">
        <invoke-factory model=3D"singleton">
            <construct class=3D"Cleaner">
                <event-listener service-id=3D"hivemind.ShutdownCoordinator"/&g= t;
            </construct>=
        </invoke-factory>
   </service-point>

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

And the following class to my project:

public class Cleaner implements RegistryShutdownListener {

    public static int c;

    public Cleaner( ) {
        c =3D c + 1;
        System.out.println("Cleaner constructed! (" + String.valueOf(c) + ")");
    }

    public void registryDidShutdown() {
        System.out.println("The registry has shutdown! (" + String.valueOf(c) + ")" );
        c =3D c - 1;
    }
}


Oddly, when I go through the process of starting up and shutting down, I se= e 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, w= hen what I really want is a singleton that gets created one time on startup, an= d then gets called a single time at shutdown.  From the messages it appe= ars 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 registere= d for the shutdown event.

Where is hivemind being instructed to construct the second instance, and ho= w could I prevent it from happening?

Thanks in Advance,

Spencer

=  


------=_Part_80665_30672091.1131391370618--