RE: how to terminate components
"Goldsack, Patrick" <[email protected]>
| Newsgroups | gmane.comp.java.smartfrog.user |
|---|---|
| Message-ID | <[email protected]> |
Another reason for using a terminator thread when terminating in a lifecycle method is to ensure that the synchronization of the methods is respected even if everything is on one host. Otherwise it is possible for the termiantion code to be run before the lifecycle method has completed - not a good idea. As Julio points out, when components are spread across several hosts, not using a termiantor thread in a lifecycle method can (generally will) cause lock-ups. As Julio points out, generally throwing an exception in sfStart() or sfDeploy() is the easiest way to safely terminate - so long as you want abnormal termination. Only use sfTerminate() directly if you are in a thread you have started within one of the lifecycle methods, for example in some monitoring thread... And of course never call sfTerminateWith() yourself (a common, and invariably fatal, error!). We are looking at ways of improving the threading model to make it easier for the end-user... But this will be for SmartFrog 4.* Patrick -----Original Message----- From: smartfrog-support-admin-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org [mailto:smartfrog-support-admin-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org] On Behalf Of Guijarro, Julio Sent: 26 July 2005 11:22 To: Andreas Unterkircher; smartfrog-support-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org Subject: RE: [Smartfrog-support] how to terminate components Hi Andreas, > -----Original Message----- > From: smartfrog-support-admin-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org [mailto:smartfrog- > [email protected]] On Behalf Of Andreas Unterkircher > Sent: 26 July 2005 10:20 > To: smartfrog-support-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org > Subject: [Smartfrog-support] how to terminate components > > > Hello, > > I'm wondering which is the "best" way to asynchronously terminate a > component. To terminate a component asynchronously the best way is to use the TerminatorThread with the right Termination Record properly configured. Ex. TerminatorThread terminator = new TerminatorThread(targetComponent, excp, componentId).quietly(); // start the thead terminator.start(); Or TerminatorThread terminator = new TerminatorThread(primTarget, terminationRecord).detach(); Termainator.start(); Say I have > some failure within sfStart and I want to terminate the component > immediately. I could call sfTerminate(...). But then I found out that I > have to make the subsequent executing lines of sfStart dependent on > sfIsTerminating(). So far I understand sfTerminate starts a > TerminatorThread thus termination is not "immediately" [1] Standard sfTerminate() does not use any TerminatorThread but Compound will terminate its children asynchronously unless otherwise specified. This is because the complete shutdown of a distributed system when an error happened can be very tricky. If you add the attribute "sfSyncTerminate true;" before calling sfTerminate() then the termination of its children will be synchronous. Be aware that there is no termination watchdog in Compound and therefore, the termination can be locked down if any of its children does not complete termination. >. On the other hand > I could > throw a SmartFrog exception. But this does not seem appropiate. > I understand that SF exceptions are for SF inherent errors and not for > components failing for other reasons. What does throwing an SF exception > mean ? Would it also terminate other Compounds resp. components then the > one which threw the exception ? If you throw an exception the Termination Record used will be tagged: ABNORMAL. Abnormal termination means and error happened and Sequence and Parallel, for example, will clean up. For a Sequence to progress normally, its children have to terminate normally. > > To sum up: I want to terminate a component immediately on some failure > encountered during sfStart. Therefore I use sfTerminate in conjuntion with > sfIsTerminating(). Is this the right way to do this ? If you want to initiate termination from inside a lifecycle method, you must use a TerminatorThread. Lifecycle methods are synchronized and calling sfTerminate directly could cause a deadlock in certain circumstances (ex. remote parent). See [1] above for synchronous termition. It you throw and exception then the exception will be trapped, the component terminated appropriately and "abnormal" termination reported. Then is up to its parent lifecycle to determine what happens next. As I said before, Compound, Sequence and Parallel will clean up because it is assumed that something went wrong. Julio > > Thanks for your advice, > Andreas > > > > ------------------------------------------------------- > SF.Net email is sponsored by: Discover Easy Linux Migration Strategies > from IBM. Find simple to follow Roadmaps, straightforward articles, > informative Webcasts and more! Get everything you need to get up to > speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click > _______________________________________________ > Smartfrog-support mailing list > Smartfrog-support-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org > https://lists.sourceforge.net/lists/listinfo/smartfrog-sup ------------------------------------------------------- SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id492&op=ick _______________________________________________ Smartfrog-support mailing list Smartfrog-support-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org https://lists.sourceforge.net/lists/listinfo/smartfrog-support ------------------------------------------------------- SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id492&op=click