Saturday, 15 October, 2011

Simple textile documentation site

After spending a few hours trying to setup decent sites with Drupal, MediaWiki and a few others, I decided that this time would be better served by creating my own simple site for my needs. I based my work on Play Framework and reused a few lines of their documentation module to create a simple yet powerful developer documentation platform. You can have a look at http://dev.ambientreflex.com/.

Play is a very powerful framework offering development cycles similar to what we may find with scripting languages like PHP, with the power of the Java platform (libraries, tooling, type-safety and more). I started my project yesterday at 11PM (talk about a nice way to spend a friday night!) and completed it this morning. Overall, from idea to production, it took me something like 6 hours of work... not bad! Ok, I already had an EC2 machine, already configured with Play, Gitosis and Lighttpd reverse proxy, but that would have add maybe an extra hour or so.

The resulting workflow is very interesting. I've cloned my Git documentation repo and modify all textile files locally with my text editor. When I push my commits to my server, a post-update hook copy all files to a folder on my server where my Play app load them. This enables easy collaboration where all developers can easily  contribute to the platform documentation, while maintaining a strong integrity, revisions, branching, etc.

I've open sourced the code under the MIT license, so, do whatever you want and try to contribute back if you create useful stuff! Use our installation guide to get started!

Wednesday, 27 July, 2011

Scripting in the cloud

I decided to push a little bit more regarding executing script code in a shared server environment. For our Ambient Vibes platform, we're looking at letting user/developer create pattern sensors that will trigger an action based on certain patterns in a given user Vibes (a stream of business events). Actions may be anything as we dont' want to restrict to specific ones. So, naturally, the solution is to execute a script in the context of the given user. It's working well at the moment, we've selected the Groovy language, which is compatible with our Java VM and offer good support to write high-level DSLs to help users describe what they want to do instead of programming it. 

But the barrier to opening Ambient Vibes to the public, is our incapacity, at the moment, to easily monitor script execution to detect misbehaving scripts and kill them. Of course, scripts run within a very limited sandbox, thanks to the solid security foundation inherited from the Java platform. But, while we may control the classpath, control what code can be executed, what resources may or may not be accessed by the script, we're still pretty open to dumb scripts performing tight loops, allocating tons of memory and other good jokes like these. By the very nature of our system, we let unsecured scripts enter our application space and we have to keep them secure. 

This is why we launch the Kevlar project with the goal to enable easy embedding of Groovy scripts within a monitored and secure environment. Our goal is to let developer configure the Kevlar Groovy shell to listen to specific events (high memory allocation for example) and respond accordingly (prevent the allocation, log a warning, etc).

Our goal is to gradually enhance our protections to include all memory or cpu "attacks" and also add a complete permission system , like Android, to control imports, or access to declared services. Our goal is to inject all indicated resources in the script environment and control its execution. 

For now, you may track the evolution of project Kevlar through this blog. We'll setup a GitHub project soon. 

Monday, 9 May, 2011

JQuery Mobile Ajax Caching

JQuery Mobile is a very good mobile UI framework. I use it for mobile version of web sites or in conjunction with PhoneGap to create portable mobile apps. One interesting aspect of the framework is that you can mix and match local and remote pages. JQM seamlessly loads any remote pages from your server as if it was on the page. It's a cool feature.

By default, the first time the page is loaded but further times, it is cached locally for performance. This is causing issues with dynamic content. For example, I have a Google Maps on a page and it's being shown only the first time. I get old pages with wrong state, pretty annoying.

Documentation state that you may disable ajax loading in mobileinit bootstrap function, but doing this, you disable ALL ajax for all pages, which is not usually what you want.

The real solution was proposed in this post and has been very helpful for me than. Just add this code in your primary HTML page (the one that is initially loaded when you start, index.html?)
      $(function(){  
           $('div').live('pagehide', function (event, ui) {  
             var $this = $(this);  
             if ($this.attr('ID') !== undefined && $this.attr('data-cache') !== undefined && $this.attr('data-cache') == "never") {  
               var page = $this.attr('ID');  
               $(document.getElementById(page)).remove();  
             }  
           });  
      });  

With this code, you can now control caching on a per-page basis by adding data-cache='never' to your page div.

Monday, 14 March, 2011

Upcoming Play Framework 1.2

Those who think Java is dead may not be aware of the wonderful web framework developed by Guillaume Bort and his team: Play! I've been using it for more than one year now and I have to say that this is by far the most productive framework I've seen. I've used all Java frameworks (yes all!) in quest of fast build-cycles, easy testing and a complete yet not closed stack where I could concentrate on generating business value instead of messing with underlying dependencies. Play! is fast to learn (good doc) and you get to find advanced features available, easy to use, well packaged, each time you need something.

In this post on their forum related to the upcoming Play! 1.2, Guillaume advertise a number of asynchronous features with the same user friendliness and nice packaging we've expected from Play! Play was already a nice solution for asynchronous web request processing, but with 1.2, they integrate WebSockets, a better continuation support and various other constructs that will make your life easier and your app incredibly fast and lightweight. 

If you're a Java developer and you need to create a powerful web site (including web services, json, xml and any RESTFul) give Play! a try!

Wednesday, 18 August, 2010

Computing Fragmentation

With the rapid growth of intelligent phones and other mobile computing devices, the Internet is more and more used on the go. Morgan Stanley analysts predict that the mobile web will be bigger than the desktop web by 2015. I think that’s a believable projection, I would even say that it may be even faster.

From the computing side, we need to go farther than the mobile or not concerns and understand what patterns of computing will emerge from this new paradigm. If you look at the computing trends of the past 30 years, people were installing applications and performing all separate tasks in each one. These limitations were often due to the lack of communication capacity and the way applications were distributed. But in the mobile web, people connect to the Internet, get whatever they need for a specific task and jump to the next. Our computing devices are more and more task or activity oriented (like Android), letting people assemble their applications as they need, for the current requirements.

We see the same thing with web sites. You go to google, than google maps, than view photos in Flickr or video in Youtube, get a tips from Yelp and make a reservation using another web site. Web sites are more and more task oriented, integrating for the time of a transaction, to fit the current user needs. For me, this is where computing is going. Our mobile devices will become our assembling tool to create applications on the fly based on the task we want to achieve. We must think of our web applications as components in this big realtime application assembling game. Current mashup technologies are a good start toward supporting this, but they need to improve semantically and they most be extensible and customizable on a transaction basis.

The mobile web is a realtime, personal, task-driven experience. For now, we’re mobile, with a glimpse of task orientation emerging on certain devices.

Monday, 9 August, 2010

ACS Transcode Sample available

Following my post on transcoding media files on the cloud with ACS, I'm happy to announce that you can now download the Transcode sample source code and connect to ACS to transcode M4A files. To build the application, you just need to clone the ACS repository in your workspace using GIT and import acs-protocol, acsclient and transcode in Eclipse (or your preferred IDE). Of course, you need Android SDK and a 2.2 phone or emulator.

You can install the cloud-phone from the cloned GIT repo or simply install the latest production version from the Android market. You will be prompted to create a free account and as soon as your cloud-phone is connected, you're ready to transcode!

Keep in mind that ACS is still pretty young and you may encounter a few failures here and there. Just stop and restart the service from the CloudPhone status activity and tell me what happened!

Mixin in Java using Groovy

I'm a big fan of the Groovy language. There are many new dynamic languages for the JVM, but for me, Groovy is the most natural one, simple yet very powerful. A powerful aspect of Groovy is that, even if you're not coding your classes in Groovy, you can groove your Java code. Have a look at how simple it is to add a mixin to a Java class :

class MyClass { 
  public getVal1() { return 5; }
}

@Category
class ExtraBehavior { 
  private String extra;
  public void setExtra(String extra) { this.extra = extra; }
  public String getExtra() { return "extra"; }
}

Now, you apply Groovy magic : 

DefaultGroovyMethods. mixin( MyClass.class, ExtraBehavior.class); 

After this point, the getExtra method will be available from myClass instances. To set the extra value, just use the metaclass : 

GroovyObjectSupport.class.cast(anyInstance).getMetaClass().setProperty(anyInstance, "extra", "newVal");

When calling anyInstance.getExtra ( using Reflection of course), you'll access the ExtraBehavior getter and internal state. Pretty cool stuff to inject behavior and state at runtime in your Java classes.