On Fri, Mar 7, 2008 at 1:09 PM, John D. Mitchell <[EMAIL PROTECTED]> wrote: > On Thu, Mar 6, 2008 at 11:28 AM, Aaron Crow <[EMAIL PROTECTED]> wrote: > > Is it ok to shut down a Restlet server using Unix kill? > > Depends on your application's specifics. > > For example, the oldest Restlet-based production code that I have is > an authentication gateway that I would just kill outright.
We in SmartFrog, http://smartfrog.org/ are assing support for Restlet deployments as manageable components, but I don't consider the stuff stable yet. I've finally got all my tests with S3 working, with through-firewall communications and the ability to set the access rights with custom http headers. That's the client done, so the server comes next; Jetty is something we've supported for ages. > > > > What does Restlet do in this case? > > Unless something has been changed in the v1.1+ world, nothing. The > JRE receives the signal and dies and the Restlet infrastructure > doesn't do anything about it. > > > > > And does anyone have any good advice on what the application > > code might do to handle this event properly? > > You can register a shutdown hook: > > http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Runtime.html#addShutdownHook(java.lang.Thread) > BUT! Be clear that your shutdown hook thread may or may not ever get > invoked -- it depends on things like which signal is being sent. > -you can register signal handlers, though the JVM tells you off for it. This is even lower level than a shutdown hook. http://smartfrog.svn.sourceforge.net/viewvc/smartfrog/trunk/core/smartfrog/src/org/smartfrog/sfcore/processcompound/InterruptHandlerImpl.java?view=markup Sun's IDEs/compilers now view importing sun.misc.SignalHandler and sun.misc.Signal as forbidden, and OSS JVMs dont implement them. You need to do tricks to enable your code to compile/run on alternate JVMs. > So, it's best to presume that your Java application may be killed at > anytime. I.e., make sure that your code deals appropriately with the > error conditions that that may cause in some reasonable way given your > application's semantics. > See Crash Only Software : http://crash.stanford.edu/ No matter how well you design handlers in your app, you cant stop the VM the OS runs in being killed without warning, you can't stop the laptop power failing. Stop treating unannounced termination as an unusual event and your software meets reality more accurately. -steve