You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Muhammad Gelbana <m....@gmail.com> on 2013/10/13 17:14:46 UTC

Safety check if a service has been initialized

Will many agree with me if I asked for a way to safely check if a service
has been initialized or built ?

Something like RegistryTools.isBuilt(myServiceReference);

*---------------------*
*Muhammad Gelbana*
http://www.linkedin.com/in/mgelbana

Re: Safety check if a service has been initialized

Posted by Muhammad Gelbana <m....@gmail.com>.
@Barry, there are usually tests being carried out killing the server will
leave the database in an inconsistent state. So a graceful shutdown is
needed

@Lance, you are correct, this is a good approach to solve this.

I still think having this around (Checking if a service is built) is an
addition that wouldn't hurt, but will rather offer an extra feature.

*---------------------*
*Muhammad Gelbana*
http://www.linkedin.com/in/mgelbana


On Mon, Oct 14, 2013 at 8:56 PM, Lance Java <la...@googlemail.com>wrote:

> Why not create your own hub which your db services register with when they
> are realized / constructed. You then have a single shutdown listener which
> loops the list in order before finally shutting down the db connection.
>  On 14 Oct 2013 17:38, "Muhammad Gelbana" <m....@gmail.com> wrote:
>
> > This cannot guarantee the order of the shutdown procedure. I need this
> > executed after all services are shutdown. However, I can inject another
> > service instead of *RegistryShutdownHub*, this way I can guarantee the
> > order.
> >
> > To explain, I'll inject a service which will hold a set of database
> > connection services to be shutdown last. This service is contributed in
> a *
> > ShutdownManager* service which registers as a registry shutdown listener.
> >
> > Thanks lance, that's a more Tapestrish and cooler way to do it.
> >
> > *---------------------*
> > *Muhammad Gelbana*
> > http://www.linkedin.com/in/mgelbana
> >
> >
> > On Mon, Oct 14, 2013 at 5:23 PM, Lance Java <lance.java@googlemail.com
> > >wrote:
> >
> > > Why not add the following to your database services:
> > >
> > > @PostInjection
> > > public void addShutdownListener(RegistryShutdownHub shutdownHub) {
> > >     shutdownHub.addRegistryShutdownListener(new Runnable() { … });
> > > }
> > >
> > > The shutdown listener will only fire if the service has been realized
> > > (constructed)
> > >
> >
>

Re: Safety check if a service has been initialized

Posted by Lance Java <la...@googlemail.com>.
Why not create your own hub which your db services register with when they
are realized / constructed. You then have a single shutdown listener which
loops the list in order before finally shutting down the db connection.
 On 14 Oct 2013 17:38, "Muhammad Gelbana" <m....@gmail.com> wrote:

> This cannot guarantee the order of the shutdown procedure. I need this
> executed after all services are shutdown. However, I can inject another
> service instead of *RegistryShutdownHub*, this way I can guarantee the
> order.
>
> To explain, I'll inject a service which will hold a set of database
> connection services to be shutdown last. This service is contributed in a *
> ShutdownManager* service which registers as a registry shutdown listener.
>
> Thanks lance, that's a more Tapestrish and cooler way to do it.
>
> *---------------------*
> *Muhammad Gelbana*
> http://www.linkedin.com/in/mgelbana
>
>
> On Mon, Oct 14, 2013 at 5:23 PM, Lance Java <lance.java@googlemail.com
> >wrote:
>
> > Why not add the following to your database services:
> >
> > @PostInjection
> > public void addShutdownListener(RegistryShutdownHub shutdownHub) {
> >     shutdownHub.addRegistryShutdownListener(new Runnable() { … });
> > }
> >
> > The shutdown listener will only fire if the service has been realized
> > (constructed)
> >
>

Re: Safety check if a service has been initialized

Posted by Barry Books <tr...@gmail.com>.
I would say if you are really relying on an orderly shutdown you might want
to rethink your design. In general you are far more likely to have a crash
than an orderly shutdown. Personally I stop my web servers with

killall -9 java


On Mon, Oct 14, 2013 at 11:37 AM, Muhammad Gelbana <m....@gmail.com>wrote:

> This cannot guarantee the order of the shutdown procedure. I need this
> executed after all services are shutdown. However, I can inject another
> service instead of *RegistryShutdownHub*, this way I can guarantee the
> order.
>
> To explain, I'll inject a service which will hold a set of database
> connection services to be shutdown last. This service is contributed in a *
> ShutdownManager* service which registers as a registry shutdown listener.
>
> Thanks lance, that's a more Tapestrish and cooler way to do it.
>
> *---------------------*
> *Muhammad Gelbana*
> http://www.linkedin.com/in/mgelbana
>
>
> On Mon, Oct 14, 2013 at 5:23 PM, Lance Java <lance.java@googlemail.com
> >wrote:
>
> > Why not add the following to your database services:
> >
> > @PostInjection
> > public void addShutdownListener(RegistryShutdownHub shutdownHub) {
> >     shutdownHub.addRegistryShutdownListener(new Runnable() { … });
> > }
> >
> > The shutdown listener will only fire if the service has been realized
> > (constructed)
> >
>

Re: Safety check if a service has been initialized

Posted by Muhammad Gelbana <m....@gmail.com>.
This cannot guarantee the order of the shutdown procedure. I need this
executed after all services are shutdown. However, I can inject another
service instead of *RegistryShutdownHub*, this way I can guarantee the
order.

To explain, I'll inject a service which will hold a set of database
connection services to be shutdown last. This service is contributed in a *
ShutdownManager* service which registers as a registry shutdown listener.

Thanks lance, that's a more Tapestrish and cooler way to do it.

*---------------------*
*Muhammad Gelbana*
http://www.linkedin.com/in/mgelbana


On Mon, Oct 14, 2013 at 5:23 PM, Lance Java <la...@googlemail.com>wrote:

> Why not add the following to your database services:
>
> @PostInjection
> public void addShutdownListener(RegistryShutdownHub shutdownHub) {
>     shutdownHub.addRegistryShutdownListener(new Runnable() { … });
> }
>
> The shutdown listener will only fire if the service has been realized
> (constructed)
>

Re: Safety check if a service has been initialized

Posted by Lance Java <la...@googlemail.com>.
Why not add the following to your database services:

@PostInjection
public void addShutdownListener(RegistryShutdownHub shutdownHub) {
    shutdownHub.addRegistryShutdownListener(new Runnable() { … });
}

The shutdown listener will only fire if the service has been realized
(constructed)

Re: Safety check if a service has been initialized

Posted by Muhammad Gelbana <m....@gmail.com>.
My core module shuts down 2 database services but I recently deployed a new
application that uses only one schema so when the
*RegisteryShutdownHub *service
calls the shutdown procedure, the idle database connection service is asked
to shutdown by calling *.close()* and this attempts to instantiate it,
which fires an exception because the registry is shutting down already.

This obviously can be addressed in many ways and I've already solved it but
I suppose this is still a good addition. I think if someone, just might use
it for any reason whatsoever, this might give Tapestry the edge over other
frameworks after all.

*---------------------*
*Muhammad Gelbana*
http://www.linkedin.com/in/mgelbana


On Mon, Oct 14, 2013 at 2:31 PM, Lance Java <la...@googlemail.com>wrote:

> The Scoreboard is a ServiceActivityTracker. I've never needed to do it
> myself but I'm sure you can register your own custom tracker.
> On 14 Oct 2013 13:17, "Martin Kersten" <ma...@gmail.com>
> wrote:
>
> > Sometimes it is very important. I for myself need this in some tests to
> > recognize some specials in tear down and set up. And thanks Lance for the
> > hint. I used another way but this Scoreboard is way more cooler. Wasnt
> > aware of this.
> >
> >
> > 2013/10/14 Thiago H de Paula Figueiredo <th...@gmail.com>
> >
> > > On Sun, 13 Oct 2013 12:14:46 -0300, Muhammad Gelbana <
> > m.gelbana@gmail.com>
> > > wrote:
> > >
> > >  Will many agree with me if I asked for a way to safely check if a
> > service
> > >> has been initialized or built ?
> > >>
> > >
> > > Why do you need that? If you invoke a service method, the service will
> be
> > > initialized and ready to use, even if Tapestry-IoC has to initialize it
> > in
> > > the spot. In another words, if you're using a Tapestry-IoC service, you
> > can
> > > always assume it's ready to be used.
> > >
> > > --
> > > Thiago H. de Paula Figueiredo
> > > Tapestry, Java and Hibernate consultant and developer
> > > http://machina.com.br
> > >
> > >
> ------------------------------**------------------------------**---------
> > > To unsubscribe, e-mail: users-unsubscribe@tapestry.**apache.org<
> > users-unsubscribe@tapestry.apache.org>
> > > For additional commands, e-mail: users-help@tapestry.apache.org
> > >
> > >
> >
>

Re: Safety check if a service has been initialized

Posted by Lance Java <la...@googlemail.com>.
The Scoreboard is a ServiceActivityTracker. I've never needed to do it
myself but I'm sure you can register your own custom tracker.
On 14 Oct 2013 13:17, "Martin Kersten" <ma...@gmail.com> wrote:

> Sometimes it is very important. I for myself need this in some tests to
> recognize some specials in tear down and set up. And thanks Lance for the
> hint. I used another way but this Scoreboard is way more cooler. Wasnt
> aware of this.
>
>
> 2013/10/14 Thiago H de Paula Figueiredo <th...@gmail.com>
>
> > On Sun, 13 Oct 2013 12:14:46 -0300, Muhammad Gelbana <
> m.gelbana@gmail.com>
> > wrote:
> >
> >  Will many agree with me if I asked for a way to safely check if a
> service
> >> has been initialized or built ?
> >>
> >
> > Why do you need that? If you invoke a service method, the service will be
> > initialized and ready to use, even if Tapestry-IoC has to initialize it
> in
> > the spot. In another words, if you're using a Tapestry-IoC service, you
> can
> > always assume it's ready to be used.
> >
> > --
> > Thiago H. de Paula Figueiredo
> > Tapestry, Java and Hibernate consultant and developer
> > http://machina.com.br
> >
> > ------------------------------**------------------------------**---------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.**apache.org<
> users-unsubscribe@tapestry.apache.org>
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>

Re: Safety check if a service has been initialized

Posted by Martin Kersten <ma...@gmail.com>.
Sometimes it is very important. I for myself need this in some tests to
recognize some specials in tear down and set up. And thanks Lance for the
hint. I used another way but this Scoreboard is way more cooler. Wasnt
aware of this.


2013/10/14 Thiago H de Paula Figueiredo <th...@gmail.com>

> On Sun, 13 Oct 2013 12:14:46 -0300, Muhammad Gelbana <m....@gmail.com>
> wrote:
>
>  Will many agree with me if I asked for a way to safely check if a service
>> has been initialized or built ?
>>
>
> Why do you need that? If you invoke a service method, the service will be
> initialized and ready to use, even if Tapestry-IoC has to initialize it in
> the spot. In another words, if you're using a Tapestry-IoC service, you can
> always assume it's ready to be used.
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.**apache.org<us...@tapestry.apache.org>
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Safety check if a service has been initialized

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Sun, 13 Oct 2013 12:14:46 -0300, Muhammad Gelbana <m....@gmail.com>  
wrote:

> Will many agree with me if I asked for a way to safely check if a service
> has been initialized or built ?

Why do you need that? If you invoke a service method, the service will be  
initialized and ready to use, even if Tapestry-IoC has to initialize it in  
the spot. In another words, if you're using a Tapestry-IoC service, you  
can always assume it's ready to be used.

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Safety check if a service has been initialized

Posted by Lance Java <la...@googlemail.com>.
Take a look at the built in ServiceStatus page. You can @Inject
ServiceActivityScoreboard and check ServiceActivity.getStatus()