Also what if I need to should down services in a specific order ? To shut down the dependents before the dependencies.
On Thu, Oct 6, 2011 at 1:59 AM, Muhammad Gelbana <m.gelb...@gmail.com>wrote: > I don't know but I think I wasn't clear enough ! > > Here is what I'm trying to do. I have a service that implements "* > RegistryShutdownListener*" which has a method called "*registryDidShutdown > *" within which I should have my clean-up logic. > > But to register this service as a "*RegistryShutdownListener*", I should > invoke the "*addRegistryShutdownListener" *method on a "* > RegistryShutdownHub*" instance. I do that by injecting the "* > RegistryShutdownHub*" service in the *AppModule*, and invoking the > mentioned method in a *@Startup* annotated method in my *AppModule* class, > and of course *@Inject*ing "*RegistryShutdownHub*". > > Will it differe if I do this in a *@Startup* annotated method in the * > AppModule* or in a *@PostInjection* annotated method in my service itself > ? > >> Or should *each* injected service that required a clean-up, implement > the "*RegistryShutdownListener*" interface and invoke it's own clean-up > code ? > > I'm currently using a @Startup annotated method and the clean-up code is > executed when tomcat starts to shutdown, it's just that when I try to > reference my services to instruct them to shutdown, I get exceptions because > the registry is already shutdown ! Shouldn't my service's implemented "* > RegistryShutdownListener*.*registryDidShutdown*" method be called *before*the > registry starts to shutdown ? So that I can refer to services I need to > shutdown ?! > > Here is some code to demonstrate what I'm currenlty doing: > * > * > *AppModule.java* > @Inject > private IpkDestroyer ipk; > > @Inject > private RegistryShutdownHub rsh; > > @Startup > public void init(){ > Runnable r = new Runnable() { > public void run() { > ipk.registerRegistryShutdownListener(rsh); > } > }; > Thread t = new Thread(r, "SkyContextListener-Initializing-Thread"); > t.start(); > try { > t.join(); > } catch (InterruptedException e) { > e.printStackTrace(); > } > } > * > * > *IpkDestroyerImpl.java* > public class IpkDestroyerImpl implements RegistryShutdownListener, > IpkDestroyer { > public void registryDidShutdown() { > Runnable r = new Runnable() { > public void run() { > //clean up code referring to tapestry injected > services. This is when an exception is thrown reporting that tapestry's > registry is already closed. > } > public void *registerRegistryShutdownListener*(RegistryShutdownHub > shutdownHub) { > log.info("Service registered as a registry shutdown listener."); > shutdownHub.addRegistryShutdownListener(*this*); > } > } > > *I use threads because each thread will spawn multiple threads and wait > for them to finish. I do that to speed up the process. Then I wait for the > main threads before I return from the current method.* > > Isn't this the right way and as explained in the page mentioned in my first > message ? > @Thiago, Would you please be more specific about what I need to read to do > what I need ? The IoC documentation is huge and time isn't on my side. > @Howard, I have no problem depending on tapestry but I need my core > services to be independent as much as possible. If there is no other way at > the moment then no problem, I have to find out if I have other options or > not. > > Thank you all for your time and help. > > > On Thu, Oct 6, 2011 at 1:08 AM, Howard Lewis Ship <hls...@gmail.com>wrote: > >> There's more than one way to do these things. >> >> A service builder method (see the docs) is fully responsible for >> instantiating a service. Tapestry treats this method as a black box. >> Inside the method, your code can instantiate a class, provided >> dependencies, and do other initializations, such as registering the >> new instance as a listener. >> >> However, most people don't want to have to write a main class and a >> builder method; that's why you can bind the service, and let Tapestry >> instantiate it, set dependencies, and invoke @PostInjection methods to >> do secondary initializations, such as this listener business. >> >> Don't like the annotations? Don't use them ... but you'll write more >> code, since you've deprived Tapestry IoC of the hints it need to >> instantiate your service for you. >> >> On Wed, Oct 5, 2011 at 2:47 PM, Thiago H. de Paula Figueiredo >> <thiag...@gmail.com> wrote: >> > On Wed, 05 Oct 2011 17:23:44 -0300, Muhammad Gelbana < >> m.gelb...@gmail.com> >> > wrote: >> > >> >> I've done everything as directed in the page but the annotation >> >> *@PostInjection *didn't work so I had to invoke the method "public void >> >> startupService(RegistryShutdownHub shutdownHub)" manually at a static >> >> method annotated with @Startup in my "AppModule" class. >> > >> > You mixed two things that are different. You need this method to your >> > AppModule to contribute something to be run at startup: >> > >> > public static void >> contributeRegistryStartup(OrderedConfiguration<Runnable>) >> > { >> > ... >> > } >> > >> > Please read the Tapestry-IoC documentation to understand what this >> method >> > does. >> > >> > For shutdown, inject RegistryShutdownHub and add RegistryShutdownLister >> to >> > it. >> > >> > -- >> > Thiago H. de Paula Figueiredo >> > Independent Java, Apache Tapestry 5 and Hibernate consultant, developer, >> and >> > instructor >> > Owner, Ars Machina Tecnologia da Informação Ltda. >> > http://www.arsmachina.com.br >> > >> > --------------------------------------------------------------------- >> > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org >> > For additional commands, e-mail: users-h...@tapestry.apache.org >> > >> > >> >> >> >> -- >> Howard M. Lewis Ship >> >> Creator of Apache Tapestry >> >> The source for Tapestry training, mentoring and support. Contact me to >> learn how I can get you up and productive in Tapestry fast! >> >> (971) 678-5210 >> http://howardlewisship.com >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org >> For additional commands, e-mail: users-h...@tapestry.apache.org >> >> > > > -- > *Regards,* > *Muhammad Gelbana > Java Developer* > > -- *Regards,* *Muhammad Gelbana Java Developer*