You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hivemind.apache.org by Geoff Hopson <ge...@gmail.com> on 2005/05/25 20:47:05 UTC

[Newbie] Singletons starting twice

Hi,

Probably a FAQ or I´ve done something dumb....

I have an application that starts an embedded Jetty server. However, I
need a service to be started up and initialised before the web server
starts up and is able to receive web service calls - lots of database
initialisation, pre-fetching etc. I cannot do this on receipt of the
first web service call, unfortunately.

So, I saw eagerLoad and tried that. Nice. I can get my service set up
and initialized before the web server starts.

But, when the first request arrives, the service is initialised again!

The first time, the service is initialised through the ´Main´ thread.
When Jetty starts up, the first request initializes my service from
the ´Listener-X´ thread (whichever one responds). Once that
initialisation is done, no more occur (which is what I expect from the
default singleton model).

I guess I am loading the registry twice, but I have no idea why/how.

Any clues? Any other techniques for pre-loading services other than
eagerLoad? What do folks do with embedding Jetty and HiveMind in the
same application?

Thanks for any insights,
Geoff

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


Re: [Newbie] Singletons starting twice

Posted by Geoff Hopson <ge...@gmail.com>.
Thanks for the help so far. Maybe I'm being dumb (again), but here's
what I want.

I have a web services-based application. I need to get some
configuration from a database loaded up BEFORE I receive my first web
srevice request, since connecting to the database, fetching, loading,
rejigging etc takes time I haven't got when I recieve my first web
service call.

Therefore I want my HiveMind service to init BEFORE the web server
starts up, so that all my ducks are in a row before I start receiving
calls.

I have a main in my startup class that starts up the web server (Jetty).

Creating the registry in this main method doesn't work, because the
Jetty listener threads have no idea that the registry has been started
(since I haven't received a request yet, I can't use HiveMindFilter).

Here's a dump of the main chunk of my Main method...

// eagerload my service by constructing registry      
Registry registry = RegistryBuilder.constructDefaultRegistry();
// my service has now been created and inited. Who-hoo...
// now start jetty...
Server server = new Server();
server.addWebApplication("/MyApp", "./context/");
server.setTrace(true);
SocketListener listener = new SocketListener();
listener.setPort(8081); 
listener.setMinThreads(5);
listener.setMaxThreads(250);
server.addListener(listener);
server.start();
// And we are ready to receive our first caller...


Trouble is, the first web service request comes in, and the HiveMind
registry gets reloaded into the first Listener thread that responds,
along with all the initialisation I think I have already done.

Thanks again for any insights.

Geoff

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


RE: [Newbie] Singletons starting twice

Posted by James Carman <ja...@carmanconsulting.com>.
Or, use HiveMindFilter, if you're using the "default" registry anyway.

-----Original Message-----
From: David J. M. Karlsen [mailto:david@davidkarlsen.com] 
Sent: Wednesday, May 25, 2005 7:03 PM
To: hivemind-user@jakarta.apache.org
Subject: Re: [Newbie] Singletons starting twice

Geoff Hopson wrote:

>Thanks for the response.
>
>Not got the code in front of me, but I recall it is using
>createDefaultRegistry. I am attempting to get the registry started
>before I start the web server - I have a main method that attempts to
>start the registry, get my service started, then when everything is
>set up and ready, start the web server.
>
>Regards,
>Geoff
>
>
>On 5/25/05, Achim Huegen <ah...@gmx-topmail.de> wrote:
>  
>
>>How do you initialise the registry?
>>Are you using the HivemindFilter?
>>
>>Achim
>>
>>Am Wed, 25 May 2005 19:47:05 +0100 schrieb Geoff Hopson
<ge...@gmail.com>:
>>
>>    
>>
>>>Hi,
>>>
>>>Probably a FAQ or I´ve done something dumb....
>>>
>>>I have an application that starts an embedded Jetty server. However, I
>>>need a service to be started up and initialised before the web server
>>>starts up and is able to receive web service calls - lots of database
>>>initialisation, pre-fetching etc. I cannot do this on receipt of the
>>>first web service call, unfortunately.
>>>
>>>So, I saw eagerLoad and tried that. Nice. I can get my service set up
>>>and initialized before the web server starts.
>>>
>>>But, when the first request arrives, the service is initialised again!
>>>
>>>The first time, the service is initialised through the ´Main´ thread.
>>>When Jetty starts up, the first request initializes my service from
>>>the ´Listener-X´ thread (whichever one responds). Once that
>>>initialisation is done, no more occur (which is what I expect from the
>>>default singleton model).
>>>
>>>I guess I am loading the registry twice, but I have no idea why/how.
>>>
>>>Any clues? Any other techniques for pre-loading services other than
>>>eagerLoad? What do folks do with embedding Jetty and HiveMind in the
>>>same application?
>>>      
>>>
Maybe you could build the registry in the init() method of the servlet? 
That way you could init the services before the first request - and keep 
the registry within the web-module classloader if it has a separate one.



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


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


Re: [Newbie] Singletons starting twice

Posted by "David J. M. Karlsen" <da...@davidkarlsen.com>.
Geoff Hopson wrote:

>Thanks for the response.
>
>Not got the code in front of me, but I recall it is using
>createDefaultRegistry. I am attempting to get the registry started
>before I start the web server - I have a main method that attempts to
>start the registry, get my service started, then when everything is
>set up and ready, start the web server.
>
>Regards,
>Geoff
>
>
>On 5/25/05, Achim Huegen <ah...@gmx-topmail.de> wrote:
>  
>
>>How do you initialise the registry?
>>Are you using the HivemindFilter?
>>
>>Achim
>>
>>Am Wed, 25 May 2005 19:47:05 +0100 schrieb Geoff Hopson <ge...@gmail.com>:
>>
>>    
>>
>>>Hi,
>>>
>>>Probably a FAQ or I´ve done something dumb....
>>>
>>>I have an application that starts an embedded Jetty server. However, I
>>>need a service to be started up and initialised before the web server
>>>starts up and is able to receive web service calls - lots of database
>>>initialisation, pre-fetching etc. I cannot do this on receipt of the
>>>first web service call, unfortunately.
>>>
>>>So, I saw eagerLoad and tried that. Nice. I can get my service set up
>>>and initialized before the web server starts.
>>>
>>>But, when the first request arrives, the service is initialised again!
>>>
>>>The first time, the service is initialised through the ´Main´ thread.
>>>When Jetty starts up, the first request initializes my service from
>>>the ´Listener-X´ thread (whichever one responds). Once that
>>>initialisation is done, no more occur (which is what I expect from the
>>>default singleton model).
>>>
>>>I guess I am loading the registry twice, but I have no idea why/how.
>>>
>>>Any clues? Any other techniques for pre-loading services other than
>>>eagerLoad? What do folks do with embedding Jetty and HiveMind in the
>>>same application?
>>>      
>>>
Maybe you could build the registry in the init() method of the servlet? 
That way you could init the services before the first request - and keep 
the registry within the web-module classloader if it has a separate one.



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


Re: [Newbie] Singletons starting twice

Posted by Geoff Hopson <ge...@gmail.com>.
Thanks for the response.

Not got the code in front of me, but I recall it is using
createDefaultRegistry. I am attempting to get the registry started
before I start the web server - I have a main method that attempts to
start the registry, get my service started, then when everything is
set up and ready, start the web server.

Regards,
Geoff


On 5/25/05, Achim Huegen <ah...@gmx-topmail.de> wrote:
> How do you initialise the registry?
> Are you using the HivemindFilter?
> 
> Achim
> 
> Am Wed, 25 May 2005 19:47:05 +0100 schrieb Geoff Hopson <ge...@gmail.com>:
> 
> > Hi,
> >
> > Probably a FAQ or I´ve done something dumb....
> >
> > I have an application that starts an embedded Jetty server. However, I
> > need a service to be started up and initialised before the web server
> > starts up and is able to receive web service calls - lots of database
> > initialisation, pre-fetching etc. I cannot do this on receipt of the
> > first web service call, unfortunately.
> >
> > So, I saw eagerLoad and tried that. Nice. I can get my service set up
> > and initialized before the web server starts.
> >
> > But, when the first request arrives, the service is initialised again!
> >
> > The first time, the service is initialised through the ´Main´ thread.
> > When Jetty starts up, the first request initializes my service from
> > the ´Listener-X´ thread (whichever one responds). Once that
> > initialisation is done, no more occur (which is what I expect from the
> > default singleton model).
> >
> > I guess I am loading the registry twice, but I have no idea why/how.
> >
> > Any clues? Any other techniques for pre-loading services other than
> > eagerLoad? What do folks do with embedding Jetty and HiveMind in the
> > same application?
> >
> > Thanks for any insights,
> > Geoff
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: hivemind-user-help@jakarta.apache.org
> >
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: hivemind-user-help@jakarta.apache.org
> 
>

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


Re: [Newbie] Singletons starting twice

Posted by Achim Huegen <ah...@gmx-topmail.de>.
How do you initialise the registry?
Are you using the HivemindFilter?

Achim

Am Wed, 25 May 2005 19:47:05 +0100 schrieb Geoff Hopson <ge...@gmail.com>:

> Hi,
>
> Probably a FAQ or I´ve done something dumb....
>
> I have an application that starts an embedded Jetty server. However, I
> need a service to be started up and initialised before the web server
> starts up and is able to receive web service calls - lots of database
> initialisation, pre-fetching etc. I cannot do this on receipt of the
> first web service call, unfortunately.
>
> So, I saw eagerLoad and tried that. Nice. I can get my service set up
> and initialized before the web server starts.
>
> But, when the first request arrives, the service is initialised again!
>
> The first time, the service is initialised through the ´Main´ thread.
> When Jetty starts up, the first request initializes my service from
> the ´Listener-X´ thread (whichever one responds). Once that
> initialisation is done, no more occur (which is what I expect from the
> default singleton model).
>
> I guess I am loading the registry twice, but I have no idea why/how.
>
> Any clues? Any other techniques for pre-loading services other than
> eagerLoad? What do folks do with embedding Jetty and HiveMind in the
> same application?
>
> Thanks for any insights,
> Geoff
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: hivemind-user-help@jakarta.apache.org
>



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