Saturday, 15 March 2008

Dynamic Java Applications

I am investigating best ways of deploying new functionality to my running application at runtime, without having to restart my application.

OSGi framework is the way to go! (Feel free to read other options below, but OSGi seems to be the way to go - if you can)...

- OSGi framework - Have any of the framework implementations been used for any significant sized systems?

OSGi
OSGi Wikipedia

- OSGi implementations

Knopflerfish
Felix
Equinox OSGi
Embeded Server Equinox OSGi



OSGI, SCA and Spring

- Creating/recreating a Classloader. You can do this by hand with Java but I would prefer to not have to play with this. Weblogic 9/10 has a ChangeAwareClassLoader which could be of use, but in general, dropping / recreating the class loader is too heavy weight for my requirements, I just want to make available small units of change, maybe sometimes just a new class or a single code line change ie. to fix a bug. If I ditch the classloader, my calling threads will have to block until the application has sorted itself out.

- Hotswapping (Java Rebel or Weblogic 10.3 has FastSwap)

Much of the motivation behind hotswapping so far appears to be around speeding up development cycles. The hotswapping revolves around deploying your app as (ie. an exploded WAR file and compiling up source directly into the WEB-INF/classes dir where the new class will be picked up.

Weblogic 10 is offering FastSwap, but it only works if weblogic server is running in development mode.

Java Rebel will run in Weblogic 9 and 10 (plus a bunch of other app servers). Java Rebel is not recommended for production use at present though. JavaRebel dev team are aiming for Q4 2008 to getting out a beta version.

So hotswapping, for the time being, does not work reliably for production servers.

- Deploy new service on another server? - I could leverage a SOA principle 'discoverability' to discover a new service on the fly. However, I don't want the overhead of making a remote call (which this would have to be using this approach, unless I was running with SCA and OSGi for example), I still have SLA's on round trip times to support regardless, and making a remote call is not going to help.

- COTS support for adaptability?

IBM bought BowStreet in 2005 who offer an adaptable framework, although I cannot seem to find any info on the product.

- Academic research

There are a few papers written on adaptive middleware platforms. These appear to be largely academic excerices though.

- Java 7

JSR-292 talks about support for dynamic typed languages, specifically scripting languages, but does mention hotswapping as well. JSR-292 The main motivation behind this appears to be for adding support to call scriping languages.

- Beanshell could be used, in fact there are a number of different scripting options available, jython etc.. But I am not sure whether they allow change at runtime and whether they will compile on the fly or whether the scripts are all interpreted?

- Java Assist. There is a nice clean API available for bytecode instrumentation, which will the job, you could even point the classpath to point to a jar file sitting on a remote web server, (although I am sure security would have a thing to say about that!).. Once Java has loaded a class, it will not reoad it (unless running with JPDA switched on), but you can change the class at runtime so this would be fine for my purposes. I could even publish a JMX api with appropriate authentication to allow ops to remotely deploy new classes in a stream. But if OSGi really does the job, I am not sure it is worth rolling my own framework for this.

Source article summarising the current state of play

Weblogic FastAwap

Java Rebel

1 comment:

jakeonfire said...

you could also have a two-node cluster running on Terracotta, which basically clusters at the JVM level, letting you specify data structures to "persist" automatically between the two nodes (e.g. state-related data). Then you can update one node at a time without ever interrupting your app. Might not be as elegant for your purposes, but just wanted to put that out there.

Links