Travelling, and not Arriving http://www.diotalevi.com/weblog Inconclusive rants, half baked ideas Tue, 13 May 2008 09:25:42 +0000 http://wordpress.org/?v=2.3 en Points of view http://www.diotalevi.com/weblog/2008/05/13/points-of-view/ http://www.diotalevi.com/weblog/2008/05/13/points-of-view/#comments Tue, 13 May 2008 09:25:42 +0000 filippo http://www.diotalevi.com/weblog/2008/05/13/points-of-view/

]]>
http://www.diotalevi.com/weblog/2008/05/13/points-of-view/feed/
The hottest Java Web application… ever http://www.diotalevi.com/weblog/2008/05/08/the-hottest-java-web-application-ever/ http://www.diotalevi.com/weblog/2008/05/08/the-hottest-java-web-application-ever/#comments Thu, 08 May 2008 21:30:52 +0000 filippo http://www.diotalevi.com/weblog/2008/05/08/the-hottest-java-web-application-ever/ Well, I’m talking about hot.. deployment, obviously.

In the last months, it happened to me quite a few times to talk with different people about the possibility of being able, in a Java Web Application, to dynamically add/start/stop plugins.

The usual example that comes to my mind is Wordpress: you can download, add and start plugins, and they’re immediately available, without the need of restarting the web server. And if you don’t need a plugin anymore, you can just stop and delete it.
That’s fairly obvious for a HTML/PHP/scripting guy: however, the average Java kid will immediately remark that it’s not doable in a Servlet container, due to the caching mechanisms inside the Java Classloader, and the way Application Servers/Servlet Containers are built.

That’s all true, but technology, even Java technology ;-), advances; and my point in these discussions was that there are now quite a few techniques and tools that should make it possible. And today I took a couple of hours to try to prove it.
I turned out it was extremely simple.

My tool of choice was Apache Felix, an open source implementation of OSGi. As the website states:

…[Apache Felix] is ideally suited for any project that is interested in principles of modularity, component-oriented, and/or service-orientation. OSGi technology combines aspects of these aforementioned principles to define a dynamic service deployment framework that is amenable to remote management. As an example of a simple use case, Felix can be easily embedded into other projects and used as a plugin or dynamic extension mechanism; it serves this purpose much better than other systems that are used for similar purposes, such as Java Management Extensions (JMX).

Simply put, Apache Felix provides the developer a container where services (”bundles”) can be deployed/started/stopped and made available to an application (or to other services). Felix’ API is really simple and clean, and I was able to write a whopping-126-lines-of-code-class-imports-and-logs-included that provides all the basic functionalities to start hot deploying plugins in your web application. That’s the code (disclaimer: I’m not an expert at all. That’s just a code sample built in a couple of hours. If you have any problems, please ask in the project mailing list)

public class OsgiContainer
{
 private static Map map = new StringMap();
 private static List list = new ArrayList();
 private static Felix container;

 public static void start() throws BundleException, InterruptedException,
			InvalidSyntaxException, NoSuchMethodException,
			IllegalAccessException, InvocationTargetException {
    map.put(FelixConstants.EMBEDDED_EXECUTION_PROP, “true”);
    map.put(Constants.FRAMEWORK_SYSTEMPACKAGES,
            “org.osgi.framework; version=1.3.0,” +
            “org.osgi.service.packageadmin; version=1.2.0,” +
            “org.osgi.service.startlevel; version=1.0.0,” +
            “org.osgi.service.url; version=1.0.0,”+
            “com.diotalevi.osgi.felix.interfaces; version=1.0.0″);
    map.put(BundleCache.CACHE_PROFILE_DIR_PROP, “cache”);

    container = new Felix(new Logger(), map, list);
    container.start();
 }

 public static void stop() throws BundleException {
    container.stop();
 }

 public static void installBundle(String filePath) throws BundleException {
    container.getBundleContext().installBundle(filePath);
 }

 public static void startBundle(String filePath) throws BundleException {
    if (container.getBundleContext().getBundles() == null ||
          container.getBundleContext().getBundles().length == 0)
       return;

    for (Bundle b : container.getBundleContext().getBundles())
       if (filePath.equals(b.getLocation()))
          b.start();
 }

 public static void stopBundle(String filePath) throws BundleException {
    if (container.getBundleContext().getBundles() == null ||
          container.getBundleContext().getBundles().length == 0)
       return;

    for (Bundle b : container.getBundleContext().getBundles())
       if (filePath.equals(b.getLocation()))
          b.stop();
 }

 public static <T> List<T> getServices(Class<T> prototype) throws InvalidSyntaxException {
    ServiceReference[] srs = container.getBundleContext().getServiceReferences(prototype.getName(), null);
    ArrayList resultList = new ArrayList();

    if (srs == null || srs.length == 0)
       return resultList;
    else {
       for (ServiceReference sr : srs) {
          if (sr!=null) {
             resultList.add((T)container.getBundleContext().getService(sr));
          }
       }
       return resultList;
    }
 }
}

What else you need? Well, first of all, some Java interfaces to define your services. If you look above in my OsgiContainer class, the “map” configuration map, under the key Constants.FRAMEWORK_SYSTEMPACKAGES, defines a package called “com.diotalevi.osgi.felix.interfaces”. That’s the Java package where I defined the services I want my bundles to implement.

Secondly, I need a way to load my bundles in the web application. I obviously used my beloved Grails to create a CRUD interface to define a bundle and upload it (it’s a jar file).

FirefoxScreenSnapz001.png

FirefoxScreenSnapz002.png

I won’t go into further details on how to create a bundle. It’s, in essence, a regular jar archive with

  • a manifest.mf file defining dependencies and services provided
  • a special Java class, called Activator, implementing the org.osgi.framework.BundleActivator interface

The final result, after these few steps and no more than 120 minutes of coding, is that I can dinamically add jars to my web application, and use the services provided by these jars. All I need to do is to use the OsgiContainer.getServices(Class c) method, passing the Java interface defining the service I need.

And of course I can always start/stop/restart the bundles/jars, or remove them.

And guess what, I can deploy multiple versions of the same bundle! Since bundles are independent on each other, and live in different classloaders, there’re no class name clashes.

What’s next?

Everything it’s easy and clean, working with Java classes; however, I’d like my bundles to have other kind of resources (most importantly: jsps). It’s obviously doable (jsps are, at the end of the day, java classes…), but I’m still wondering what’s the cleaner way to achieve that. I’m sure someone is working in this direction (don’t forget that the new Spring Application Platform is heavily based on OSGi), but still I haven’t had the opportunity to study this topic further.

Finally, I’m looking for examples of web applications using OSGi for dynamic deployments of plugins/services… Google hasn’t helped me much in this research. Any idea?

]]>
http://www.diotalevi.com/weblog/2008/05/08/the-hottest-java-web-application-ever/feed/
Dangerous habits http://www.diotalevi.com/weblog/2008/05/03/dangerous-habits/ http://www.diotalevi.com/weblog/2008/05/03/dangerous-habits/#comments Sat, 03 May 2008 20:51:42 +0000 filippo http://www.diotalevi.com/weblog/2008/05/03/dangerous-habits/

(… having fun with Toonlet ;-) )

]]>
http://www.diotalevi.com/weblog/2008/05/03/dangerous-habits/feed/
Google App Engine opensource porting http://www.diotalevi.com/weblog/2008/04/16/google-app-engine-opensource-porting/ http://www.diotalevi.com/weblog/2008/04/16/google-app-engine-opensource-porting/#comments Wed, 16 Apr 2008 07:08:57 +0000 filippo http://www.diotalevi.com/weblog/2008/04/16/google-app-engine-opensource-porting/ Interesting piece of news this morning

One of the biggest criticisms of Google’s App Engine have been cries of lock-in, that the applications developed for the platform won’t be portable to any other service. This morning, Chris Anderson, the Portland-based cofounder of the Grabb.it MP3 blog service, just released AppDrop — an elegant hack proving that’s not true.

Reed the complete Andy Baio report here and check out the official website.

]]>
http://www.diotalevi.com/weblog/2008/04/16/google-app-engine-opensource-porting/feed/
Fun with Railtrackr http://www.diotalevi.com/weblog/2008/04/14/fun-with-railtrackr/ http://www.diotalevi.com/weblog/2008/04/14/fun-with-railtrackr/#comments Mon, 14 Apr 2008 20:30:51 +0000 filippo http://www.diotalevi.com/weblog/2008/04/14/fun-with-railtrackr/ In these days I’m rediscovering Linkedin to get in touch with old colleagues and do some good-old networking.
So, going through some connections I discovered Railtrackr, a nice and free Flickr visualization tool written in Rails. The author is Riccardo Govoni an italian guy working with Google in Dublin.
Check it out!

railtracker.png

Nice, indeed. That’s my personal page on Railtrackr: as you can see, if you, like me, have a gazillion of photosets, the interface is maybe a bit too crowded :-)

]]>
http://www.diotalevi.com/weblog/2008/04/14/fun-with-railtrackr/feed/
JavaOne: free for students http://www.diotalevi.com/weblog/2008/04/13/javaone-free-for-students/ http://www.diotalevi.com/weblog/2008/04/13/javaone-free-for-students/#comments Sun, 13 Apr 2008 15:26:12 +0000 filippo http://www.diotalevi.com/weblog/2008/04/13/javaone-free-for-students/ JavaOne 2008, the bigger and most spectacular Java conference worldwide (and probably one of the most expensive) is going to be free for students.
If you are interested, check out all the details at developers.sun.com/events/studentprogram/, and don’t miss the opportunity and enroll now. There’s a limited number of free passes.

]]>
http://www.diotalevi.com/weblog/2008/04/13/javaone-free-for-students/feed/
What is a career in Engineering all about? http://www.diotalevi.com/weblog/2008/04/11/what-is-a-career-in-engineering-all-about/ http://www.diotalevi.com/weblog/2008/04/11/what-is-a-career-in-engineering-all-about/#comments Fri, 11 Apr 2008 12:03:39 +0000 filippo http://www.diotalevi.com/weblog/2008/04/11/what-is-a-career-in-engineering-all-about/ A career in Engineering

(Posting here, so you can use it as a future reference)

]]>
http://www.diotalevi.com/weblog/2008/04/11/what-is-a-career-in-engineering-all-about/feed/
:-D http://www.diotalevi.com/weblog/2008/04/10/d/ http://www.diotalevi.com/weblog/2008/04/10/d/#comments Thu, 10 Apr 2008 22:13:24 +0000 filippo http://www.diotalevi.com/weblog/2008/04/10/d/ Picture 1.png

Just found an invitation to join Google App Engine in my mailbox :-D

]]>
http://www.diotalevi.com/weblog/2008/04/10/d/feed/
Google App Engine, or “On the democratization of IT infrastructure” http://www.diotalevi.com/weblog/2008/04/09/google-app-engine-or-on-the-democratization-of-it-infrastructure/ http://www.diotalevi.com/weblog/2008/04/09/google-app-engine-or-on-the-democratization-of-it-infrastructure/#comments Wed, 09 Apr 2008 18:31:44 +0000 filippo http://www.diotalevi.com/weblog/2008/04/09/google-app-engine-or-on-the-democratization-of-it-infrastructure/ Less than 24 hours after the release of App Engine, we already have the first interesting story: HuddleChat, a sample “App Engine Powered” application written by two Google engineers, has been taken down.
HuddleChat down
The reason? The application was too similar to Campfire, the popular web chat created by 37Signals. While it’s not difficult to understand Google’s decision (HuddleChat was, first of all, meant to be a sample application, not a full-fledged product), the story is quite interesting.

Now that the IT infrastructure to make a scalable and reliable website is becoming a commodity (also thanks to Amazon Web Services) how easy will it be to clone successful, established website? With open source software, and free or pay-per-use, unlimitedly scalable infrastructures, the costs to startup a new service are virtually not-existent.

]]>
http://www.diotalevi.com/weblog/2008/04/09/google-app-engine-or-on-the-democratization-of-it-infrastructure/feed/
In case you were living on the Moon… http://www.diotalevi.com/weblog/2008/04/08/in-case-you-were-living-on-the-moon/ http://www.diotalevi.com/weblog/2008/04/08/in-case-you-were-living-on-the-moon/#comments Tue, 08 Apr 2008 18:21:10 +0000 filippo http://www.diotalevi.com/weblog/2008/04/08/in-case-you-were-living-on-the-moon/ … and didn’t hear the noise, Google has just release Google App Engine.
I strongly agree with Dave Winer:

Now, what Google announced is really exciting! I’m not kidding. It’s even better than I hoped. Yes, it’s only Python, but IBM’s PC-DOS was only BASIC and Pascal when it first came out, and it didn’t matter…

Too bad that beta accounts went away in a few hours…

]]>
http://www.diotalevi.com/weblog/2008/04/08/in-case-you-were-living-on-the-moon/feed/

The best free porn.

Free porn

Buy viagra online

buy viagra online