<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:yt="http://gdata.youtube.com/schemas/2007" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
   <channel>
      <title>Javarants</title>
      <description>Pipes Output</description>
      <link>http://pipes.yahoo.com/pipes/pipe.info?_id=dth0BVnE2xG19PBwrscPhQ</link>
      <atom:link rel="next" href="http://pipes.yahoo.com/pipes/pipe.run?_id=dth0BVnE2xG19PBwrscPhQ&amp;_render=rss&amp;page=2" />
      <pubDate>Sat, 18 May 2013 13:10:35 +0000</pubDate>
      <generator>http://pipes.yahoo.com/pipes/</generator>
      <feedburner:info uri="javarants" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><geo:lat>37.353741</geo:lat><geo:long>-122.087172</geo:long><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://www.javarants.com/rss.xml" /><item>
         <title>Mustache is logic-less but the logic has to go somewhere</title>
         <link>http://feedproxy.google.com/~r/javarants/~3/w-_Vo6ssWoM/</link>
         <description>&lt;p&gt;As the developer of &lt;a rel="nofollow" target="_blank" href="https://github.com/spullara/mustache.java"&gt;mustache.java&lt;/a&gt; I get a lot of feature requests to break the &lt;a rel="nofollow" target="_blank" href="https://github.com/mustache/spec"&gt;mustache language&lt;/a&gt; and add real logic to the templates. In virtually every case the reason the developer wanted the functionality was because they were using mustache with a template backed with a model without an interposed view. Let me give you a common example. Developer has a user object with a few fields:&lt;br /&gt;
&lt;span id="more-1469"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;class User {
  String username;
  long createdAt;
}&lt;/pre&gt;
&lt;p&gt;And they want to show when the user joined in their template:&lt;/p&gt;
&lt;pre&gt;{{#user}}{{username}} joined on {{createdAt}}{{/user}}&lt;/pre&gt;
&lt;p&gt;They look at this and think, &amp;#8220;I need to be able to format longs into dates in the template&amp;#8221;. If you were in .erb or .jsp you might create a helper to do that and call it directly from the template. For mustache, someone will typically suggest changing the language to add filters so you might write the template like this:&lt;/p&gt;
&lt;pre&gt;{{#user}}{{username}} joined on {{createdAt | date}}{{/user}}&lt;/pre&gt;
&lt;p&gt;Then there would be a bunch of date formatters you could use, you might even go so far as to ask to parametrize it in the template because it isn&amp;#8217;t flexible enough with just a name:&lt;/p&gt;
&lt;pre&gt;{{#user}}
  {{username}} joined on {{createdAt | date("DD/mm/YYYY")}}
{{/user}}&lt;/pre&gt;
&lt;p&gt;And you start going down this road where more and more of the view logic is going directly into your template making it hard to internationalize, harder to share between mustache implementations and generally making it harder to maintain and test. However, this isn&amp;#8217;t the way you should use mustache. The best way is to add an additional layer of logic in your chosen host language that is responsible for the view. So for this case, what you would like end up with is something like this view:&lt;/p&gt;
&lt;pre&gt;class UserView {
  String username;
  String joined_date;
  UserView(User user) {
    username = user.username;
    joined_date = new SimpleDateFormat("DD/mm/YYYY")
        .format(new Date(user.createdAt));
  }
}&lt;/pre&gt;
&lt;p&gt;with a template much like the first one:&lt;/p&gt;
&lt;pre&gt;{{#user}}{{username}} joined on {{joined_date}}{{/user}}&lt;/pre&gt;
&lt;p&gt;This allows you in the future to add special internationalization, user specific date formats, maybe a relative timestamp, etc. All without ever changing the template. It is also easier to test since you can independently check that the formatting of the date is correct without having to execute it within the context of the template text.&lt;/p&gt;
&lt;p&gt;This strategy worked great at &lt;a rel="nofollow" target="_blank" href="https://bagcheck.com"&gt;Bagcheck&lt;/a&gt; where there was only myself and a designer and it works great at &lt;a rel="nofollow" target="_blank" href="https://twitter.com/sampullara"&gt;Twitter&lt;/a&gt; where we have tons of engineers and designers working in the code base. It has also made it possible to move between rendering on the client in Javascript to rendering on the server in Ruby to rendering on the server in Scala all with the same set of templates and basically standard mustache implementations.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/javarants?a=w-_Vo6ssWoM:G8Cw3-wvvFk:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/javarants?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/javarants?a=w-_Vo6ssWoM:G8Cw3-wvvFk:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/javarants?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/javarants/~4/w-_Vo6ssWoM" height="1" width="1"/&gt;</description>
         <author>admin</author>
         <guid isPermaLink="false">http://www.javarants.com/?p=1469</guid>
         <pubDate>Sat, 09 Mar 2013 23:21:05 +0000</pubDate>
      <feedburner:origLink>http://www.javarants.com/2013/03/09/mustache-is-logic-less-but-the-logic-has-to-go-somewhere/</feedburner:origLink></item>
      <item>
         <title>What is new and interesting in JDK 7?</title>
         <link>http://feedproxy.google.com/~r/javarants/~3/XXov0W5fLTU/</link>
         <description>&lt;p&gt;I wanted to document the most interesting features of JDK 7 here, for my own gratification and to make a place where you can contribute your great finds:&lt;span id="more-1459"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Invokedynamic bytecode for doing runtime binding of callsites&lt;/li&gt;
&lt;li&gt;Named regular expression groups&lt;/li&gt;
&lt;li&gt;Try with resources / AutoCloseable&lt;/li&gt;
&lt;li&gt;MethodHandles&lt;/li&gt;
&lt;li&gt;BufferPoolMXBean — where did all my memory go?&lt;/li&gt;
&lt;li&gt;SocketOption, ProtocolFamily and NetworkInterface&lt;/li&gt;
&lt;li&gt;Async IO — including filesystem notifications and a new network stack&lt;/li&gt;
&lt;li&gt;ForkJoinPool&lt;/li&gt;
&lt;li&gt;TransferQueue&lt;/li&gt;
&lt;li&gt;Precise exception rethrowing, catching more than one exception type&lt;/li&gt;
&lt;li&gt;Switch on String&lt;/li&gt;
&lt;li&gt;Much better GZIP support&lt;/li&gt;
&lt;li&gt;Global logger and other log management stuff&lt;/li&gt;
&lt;li&gt;ThreadLocalRandom&lt;/li&gt;
&lt;li&gt;Bitset.valueOf() for arrays&lt;/li&gt;
&lt;li&gt;Paths for manipulating file paths&lt;/li&gt;
&lt;li&gt;Files for copying files and streams, etc. Swiss army knife of stuff&lt;/li&gt;
&lt;li&gt;File attributes, ACLs, etc.&lt;/li&gt;
&lt;li&gt;Long.compare — probably caused a lot of bugs&lt;/li&gt;
&lt;li&gt;Tons of Locale / Character updates&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Things I found that are old but new to me:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Scanner &amp;#8211; using all regexes, probably horribly inefficient&lt;/li&gt;
&lt;li&gt;PriorityQueue, Deque&lt;/li&gt;
&lt;li&gt;Atomic*FieldUpdaters&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Am I missing anything?&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/javarants?a=XXov0W5fLTU:7ZjCJqG6mI8:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/javarants?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/javarants?a=XXov0W5fLTU:7ZjCJqG6mI8:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/javarants?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/javarants/~4/XXov0W5fLTU" height="1" width="1"/&gt;</description>
         <author>Sam Pullara</author>
         <guid isPermaLink="false">http://www.javarants.com/?p=1459</guid>
         <pubDate>Mon, 10 Sep 2012 02:12:03 +0000</pubDate>
      <feedburner:origLink>http://www.javarants.com/2012/09/09/what-is-new-and-interesting-in-jdk-7/</feedburner:origLink></item>
      <item>
         <title>New features and extensions in Mustache.java</title>
         <link>http://feedproxy.google.com/~r/javarants/~3/LjNgcV4U4jA/</link>
         <description>&lt;p&gt;Almost a year and a half ago &lt;a rel="nofollow" target="_blank" href="http://www.javarants.com/2010/06/16/building-the-ideal-web-application-template-engine/"&gt;I talked about&lt;/a&gt; my implementation of &lt;a rel="nofollow" target="_blank" href="http://mustache.github.com/"&gt;mustache&lt;/a&gt;, which I call &lt;a rel="nofollow" target="_blank" href="https://github.com/spullara/mustache.java"&gt;mustache.java&lt;/a&gt;. Since then, we used it to develop &lt;a rel="nofollow" target="_blank" href="http://bagcheck.com"&gt;Bagcheck&lt;/a&gt; and it has also been adopted for a variety of use cases by &lt;a rel="nofollow" target="_blank" href="http://netflix.com"&gt;Netflix&lt;/a&gt;, &lt;a rel="nofollow" target="_blank" href="http://twitter.com"&gt;Twitter&lt;/a&gt; and others. In my post I mention that for all intents and purposes, the template engine was &amp;#8216;finished&amp;#8217; and I would say that for the most part, that was accurate. However, there have been a couple of things that have been done since then around optimization and also some interesting extensions that I would like to share with people to get feedback.&lt;span id="more-1440"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;First though, I will shortly recap the biggest differentiating feature of this implementation over other implementations:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Concurrent, streaming template evaluation&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Mustache.java exectutes the template in such a way that partials, loops and even replacement (if you use futures) do not block the further evaluation of the template. This allows you to quickly launch all your I/O (or CPU) bound work for the whole template in context during a quick evaluation and then the engine can do things like flush to the underlying writer incrementally as work completes giving you great client-side and server-side concurrency. You can also use this to defer sections of the page to write them out later, a la &lt;a rel="nofollow" target="_blank" href="https://www.facebook.com/note.php?note_id=389414033919"&gt;Big Pipe&lt;/a&gt;. This has been invaluable to easily maintaining Bagcheck&amp;#8217;s low-latency design. The downside to this is that you need to write your Java code in a functional style, I suggest that you use &lt;a rel="nofollow" target="_blank" href="http://code.google.com/p/guava-libraries/"&gt;Google collections&lt;/a&gt; to do it right. The design of this has remained unchanged since the initial release though recently I added the ability for the template backing code writer to take control of concurrency in order to reduce context switches and garbage creation. This can get you a 5x improvement in template evaluation performance at the cost of developer time and expertise without losing the ability to do concurrent evaluation when necessary.&lt;/p&gt;
&lt;p&gt;Since the first release, the &lt;em&gt;handlebar server&lt;/em&gt; has been included to allow you to easily view mustache templates fully rendered in the browser with only JSON data as your backing code. This lets you quickly iterate on design without having to have the full stack running with enough information for someone to figure what needs to be implemented on the backend when new things are added. Sometimes though it can be painful to get realistic data for new features using production data. In those cases, I had always imagined a method to take a template and rendered content and give you back data would generate that same content in combination with the template. That functionality is now in the master branch (since 0.6-SNAPSHOT). Given any Mustache instance you can now call &lt;em&gt;unexecute(content)&lt;/em&gt; on that instance and if it isn&amp;#8217;t ambiguous or in some other way irreversible you will get back a Scope object that contains the data. Using &lt;em&gt;toJSON()&lt;/em&gt; on that object will provide mock data that can be used with &lt;em&gt;handlebar&lt;/em&gt;. Here is an example:&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt; 
&lt;p&gt;We then take the template and the output and unexecute them using the new method on Mustache objects:&lt;/p&gt;
 
&lt;p&gt;This produces the following JSON (after pretty printing):&lt;/p&gt;
 
&lt;p&gt;What it really does is turn the Mustache language into a look ahead grammar that can be used to read data from content, though that content has to be stringently authored. Another use case that seems reasonable to me is for people to check that their complicated backend code is combining in the right way with their template. Something like an integration test for template processing without having to hard code the non-template interpolated text into your test. Would love to get feedback on this feature as it is still unclear whether it will be useful to a wide audience.&lt;/p&gt;
&lt;p&gt;The most recent feature added is support for Twitter-style functions (_ vs just #) and i18n support. Long ago I had added support for # functions: you can return a Google Guava Function from the value callback and after the engine executes the enclosed template it will call your function to transform the value. This works for simple i18n and caching but fails for more complicated i18n applications. In those cases, you may want to also change the template itself which means you will need a callback before the underlying template is executed. If you need that behavior, you instead return an instance of TemplateFunction which gets called back before evaluation and then compiles the template text that you return from the function invocation. This is most often used to change the order of words or phrases that include things like user names. Here is a simple example from the tests:&lt;/p&gt;
 
&lt;p&gt;The biggest change since the release though is the addition of the &lt;em&gt;MustacheBuilder&lt;/em&gt;. In 0.6 I will be deprecating &lt;em&gt;MustacheCompiler&lt;/em&gt; as not only does the &lt;em&gt;Builder&lt;/em&gt; not require the use of the Java compiler, but it also compiles almost instantly and performs better than the Java compiled versions of the templates. The &lt;em&gt;Builder&lt;/em&gt; also gives us a lot more runtime flexibility that I am going to take advantage of over time for a variety of optimizations that are in the queue. I may return to investigate using &lt;em&gt;ASM&lt;/em&gt; for compilation though in order to take advantage of JDK 7 and &lt;em&gt;invokedynamic&lt;/em&gt; as that becomes the standard JVM in deployment.&lt;/p&gt;
&lt;p&gt;You may not be familiar with some of the things that you can enabled while it is running to make debugging and profiling easier. There are 3 system properties that can be turned on with little documentation:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;mustache.debug: output a warning when a callback is absent or null&lt;/li&gt;
&lt;li&gt;mustache.trace: create a multithreaded trace, use MustacheTrace.setUniqueId() in each thread, output with MustacheTrace.toASCII()&lt;/li&gt;
&lt;li&gt;mustache.profile: time all callbacks, output the top 10 total + average with Scope.report() and then reset the profiler&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now is the time for input. Here are some things that I have on my TODO list:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Full JDK7 invokedynamic support with ASM generated classes&lt;/li&gt;
&lt;li&gt;Extensible templates a la Django templates&lt;/li&gt;
&lt;li&gt;Native Scala support based on Twitter&amp;#8217;s util-core&lt;/li&gt;
&lt;li&gt;Generate scaffolding in a variety of languages for backing code with verification&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;&lt;span style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="line-height:24px;"&gt;Would love to hear from users and prospects. You can either comment here or join the dicsussions on the &lt;a rel="nofollow" target="_blank" href="http://groups.google.com/group/mustachejava"&gt;Mustache.java group&lt;/a&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/javarants?a=LjNgcV4U4jA:J4wSb_Beq4w:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/javarants?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/javarants?a=LjNgcV4U4jA:J4wSb_Beq4w:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/javarants?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/javarants/~4/LjNgcV4U4jA" height="1" width="1"/&gt;</description>
         <author>Sam Pullara</author>
         <guid isPermaLink="false">http://www.javarants.com/?p=1440</guid>
         <pubDate>Sun, 09 Oct 2011 23:29:31 +0000</pubDate>
      <feedburner:origLink>http://www.javarants.com/2011/10/09/new-features-and-extensions-in-mustache-java/</feedburner:origLink></item>
      <item>
         <title>Using Closures, Method Handles and Extension Methods in Java 8 (JSR-335)</title>
         <link>http://feedproxy.google.com/~r/javarants/~3/N0esrUGAYlQ/</link>
         <description>&lt;p&gt;&lt;b&gt;Update:&lt;/b&gt; A bunch of code from hotspot was just integrated into the bsd-port and some of it breaks the build. Use my distribution at the end of this blog post if you want to test the features.&lt;/p&gt;
&lt;p&gt;In December JSR-335 was approved by the JCP and is now starting. I&amp;#8217;ve joined as member of the expert group, but like with most recent JSRs all the real discussion will take place on the public mailing list. A lot of work has already been done in OpenJDK to support the features of this JSR which will ultimately be included in Java 8 if it completes successfully. Here is the &lt;a rel="nofollow" target="_blank" href="http://cr.openjdk.java.net/~briangoetz/lambda/lambda-state-3.html"&gt;current state of the JSR&lt;/a&gt;. Though JDK 8 is when official support would ship, you can already build and execute the draft features of JSR-335 by using the regular OpenJDK 7 build along with some compile-time and run-time tools. Before I go into the guts of how to build them, here are some examples of what you will be able to do:&lt;br /&gt;
&lt;span id="more-1389"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create closures that are converted to Single Abstract Method (SAM) implementations when used in context&lt;/li&gt;
&lt;li&gt;Create interfaces that specify default behavior for methods that are unimplemented by the implementing class&lt;/li&gt;
&lt;li&gt;Reference methods in source and then convert those references to SAM implementations when used in context&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Building OpenJDK 7 on Mac OS X 10.6 (based on &lt;a rel="nofollow" target="_blank" href="http://wikis.sun.com/display/OpenJDK/Darwin10Build"&gt;Darwin10Build&lt;/a&gt;):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Install mecurial:&lt;br /&gt;
&lt;code&gt;sudo port install mercurial&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Install hg-forest:&lt;br /&gt;
&lt;code&gt;sudo port install hg-forest&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Install &lt;a rel="nofollow" target="_blank" href="http://hg.bikemonkey.org/archive/javasrc_1_6_jrl_darwin/soylatte16-i386-1.0.3.tar.bz2"&gt;soylatte&lt;/a&gt; to /usr/local/soylatte16-i386-1.0.3&lt;/li&gt;
&lt;li&gt;Clone bsd-port:&lt;br /&gt;
&lt;code&gt;hg fclone http://hg.openjdk.java.net/bsd-port/bsd-port&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;export OPENJDK_ROOT=`pwd`&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Grab build script:&lt;br /&gt;
&lt;code&gt;cd bsd-port; curl -O "https://gist.github.com/raw/617451/d4862a41b07a1196d5149efc1c40406f8bb77dc1/update.sh"&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;mkdir ALT_COMPILER_PATH;cd ALT_COMPILER_PATH;&lt;br /&gt;
ln -s /usr/bin .SOURCE;ln -s .SOURCE/g++-4.0 g++;&lt;br /&gt;
ln -s .SOURCE/gcc-4.0 gcc;cd ..&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;unset JAVA_HOME&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Edit hotspot/make/bsd/makefiles/defs.make and change ifeq ($(ARCH), amd64) to ifeq($(ARCH), x86_64)&lt;/li&gt;
&lt;li&gt;Update sources and build (on a fast machine will take 15m):&lt;br /&gt;
&lt;code&gt;sh update.sh&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now you should have a fully working OpenJDK 7 64-bit distribution:&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
macpro:bsd-port sam$ ./build/bsd-amd64/j2sdk-image/bin/java -version&lt;br /&gt;
openjdk version "1.7.0-internal"&lt;br /&gt;
OpenJDK Runtime Environment (build 1.7.0-internal-sam_2011_01_22_16_40-b00)&lt;br /&gt;
OpenJDK 64-Bit Server VM (build 20.0-b03, mixed mode)&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
Now we want to build the Lambda compiler and runtime support:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Grab the source:&lt;br /&gt;
&lt;code&gt;cd $OPENJDK_ROOT; hg clone http://hg.openjdk.java.net/lambda/lambda/langtools&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Build the tools:&lt;br /&gt;
&lt;code&gt;cd $OPENJDK_ROOT/langtools; ant -Dboot.java.home=../bsd-port/build/bsd-amd64/j2sdk-image -f make/build.xml&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;OpenJDK 7 doesn&amp;#8217;t actually support everything that we need to run code generated for Lambda though. We need to also build a java agent that will modify the bytecodes in classes as they are loaded to run on the older VM for some features. Here is how you do that:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Grab the source:&lt;br /&gt;
&lt;code&gt;cd $OPENJDK_ROOT; svn checkout http://jsr335-lambda.googlecode.com/svn/trunk/ jsr335-lambda&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;export JAVA_HOME=$OPENJDK_ROOT/bsd-port/build/bsd-amd64/j2sdk-image&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Build the agent:&lt;br /&gt;
&lt;code&gt;cd jsr335-lambda/agent; ant jar&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;export AGENTJAR=$OPENJDK_ROOT/jsr335-lambda/agent/lib/jsr335-agent.jar&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now we can actually build Lambda code and execute it, with a lot of command line options. For example, here is a simple program that we might want to execute:&lt;/p&gt;
&lt;pre&gt;
public class Test {
  public static void main(String[] args) throws InterruptedException {
    Thread t = new Thread(#{ System.out.println("ran"); });
    t.start();
    t.join();
  }
}
&lt;/pre&gt;
&lt;p&gt;Let&amp;#8217;s first compile it:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;export PATH=$JAVA_HOME/bin:$PATH&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;export LANGTOOLS_JAR=$OPENJDK_ROOT/langtools/dist/lib/classes.jar&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;javac -J-Xbootclasspath/p:$LANGTOOLS_JAR -source 8 -target 8 Test.java&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now we have Test.class file that will only work in a VM that supports some of the bytecode that we are using. In this case we don&amp;#8217;t need the transformations so we can execute this code like this:&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
macpro:jsr335 sam$ java -cp . Test&lt;br /&gt;
ran&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
Here is some code that will not run out of the box, that shows you how you can now write extension methods:&lt;/p&gt;
&lt;pre&gt;
public class Test2 {
  interface Trait {
    int inc(int i) default Test2.inc;
  }
  static int inc(Trait t, int i) { return i+1;}
  public static class Test3 implements Trait {}
  public static void main(String[] args) {
    Trait t = new Test3();
    System.out.println(t.inc(1));
  }
}
&lt;/pre&gt;
&lt;p&gt;If you try and run this without the agent you will get this:&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
macpro:jsr335 sam$ java -cp . Test2&lt;br /&gt;
Exception in thread "main" java.lang.AbstractMethodError: Test2$Test3.inc(I)I&lt;br /&gt;
	at Test2.main(Test2.java:9)&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
Now we execute with the agent enabled:&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
macpro:jsr335 sam$ java -javaagent:$AGENTJAR -cp . Test2&lt;br /&gt;
2&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
The last feature that you might want to use, are method handles. Essentially you can convert a method handle into a closure by using it in a SAM context. Here is an example of how they work:&lt;/p&gt;
&lt;pre&gt;
public class Test3 {
    public void test() {
	System.out.println("Test");
    }
    public static void main(String[] args) {
	Test3 t = new Test3();
	Runnable r = t#test;
	r.run();
    }
}
&lt;/pre&gt;
&lt;p&gt;In order to run this we need to enable InvokeDynamic on our VM and include the classes from langtools for some runtime support:&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
macpro:jsr335 sam$ java -XX:+UnlockExperimentalVMOptions -XX:+EnableInvokeDynamic -Xbootclasspath/p:$LANGTOOLS_JAR -javaagent:$AGENTJAR -cp . Test3&lt;br /&gt;
Test&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
That command line has everything you should ever need to execute code generated using the Lamba enhancements so using anything else is probably unnecessary. Now let&amp;#8217;s put all of this together into the final example from the Lambda proposal itself:&lt;/p&gt;
&lt;pre&gt;
import java.util.*;

interface Sortable&amp;lt;T, U extends Comparable&amp;lt;? super U&amp;gt;&amp;gt;  extends List&amp;lt;T&amp;gt;  {
   void sortBy(Extractor&amp;lt;? super T, ? extends U&amp;gt;  e) default Impl.sortBy;
   static class Impl {
       public static&amp;lt;T, U extends Comparable&amp;lt;? super U&amp;gt;&amp;gt;
                 void sortBy(Sortable&amp;lt;T, U&amp;gt;  sortable, final Extractor&amp;lt;? super T, ? extends U&amp;gt;  e) {
           Collections.sort(sortable, #{T a, T b -&amp;gt;  e.extract(a).compareTo(e.extract(b))});
       }
   }
}
interface Extractor&amp;lt;T,U&amp;gt; {
    public U extract(T t);
}

class Person {
    public Person(String firstName, String lastName) {
        this.firstName = firstName;
        this.lastName = lastName;
    }
    private String lastName;
    public String getLastName() { return lastName; }
    private String firstName;
    public String getFirstName() { return firstName;}
    public String toString() {
        return firstName + " " + lastName;
    }
}

public class Test4 {

    public static class SortableList&amp;lt;T, U extends Comparable&amp;lt;? super U&amp;gt;&amp;gt; extends ArrayList&amp;lt;T&amp;gt; implements Sortable&amp;lt;T, U&amp;gt; {}

    public static void main(String[] args) {
        Sortable&amp;lt;Person, String&amp;gt; list = new SortableList&amp;lt;&amp;gt;();
        list.add(new Person("Sam", "Pullara"));
        list.add(new Person("Brian", "Goetz"));
        list.add(new Person("Bob", "Lee"));
        list.sortBy(Person#getLastName);
        System.out.println(list);
    }
}
&lt;/pre&gt;
&lt;p&gt;Which results in:&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
macpro:jsr335 sam$ java Test4&lt;br /&gt;
[Brian Goetz, Bob Lee, Sam Pullara]&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
The punchline is that if you read through all of this you get a bonus: here is the distribution of above build products that you can download and run on your Mac (assuming you are running a 64-bit build of snow leopard):&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_blank" href="http://javarants.com/openjdk7-lambda-macosx-x86_64-01222010.zip"&gt;openjdk7-lambda-macosx-x86_64-01222010.zip&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/javarants?a=N0esrUGAYlQ:e3HKquMG3Lw:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/javarants?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/javarants?a=N0esrUGAYlQ:e3HKquMG3Lw:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/javarants?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/javarants/~4/N0esrUGAYlQ" height="1" width="1"/&gt;</description>
         <author>Sam Pullara</author>
         <guid isPermaLink="false">http://www.javarants.com/?p=1389</guid>
         <pubDate>Sun, 23 Jan 2011 01:57:53 +0000</pubDate>
      <category domain="http://rss.financialcontent.com/stocksymbol">ARCH</category><category domain="http://rss.financialcontent.com/stocksymbol">SAM</category><category domain="http://rss.financialcontent.com/stocksymbol">I</category><feedburner:origLink>http://www.javarants.com/2011/01/22/using-closures-method-handles-and-extension-methods-in-java-8-jsr-335/</feedburner:origLink></item>
      <item>
         <title>Testing out Percona and HandlerSocket with AvroBase</title>
         <link>http://feedproxy.google.com/~r/javarants/~3/dj2CAnSZNAw/</link>
         <description>&lt;p&gt;The great thing about the &lt;a rel="nofollow" target="_blank" href="https://github.com/spullara/havrobase/blob/master/avrobase/src/main/java/avrobase/AvroBase.java"&gt;AvroBase&lt;/a&gt; interface is that it can be used with many different datastores because of its relatively low requirements on those stores. &lt;a rel="nofollow" target="_blank" href="https://github.com/ahiguti/HandlerSocket-Plugin-for-MySQL"&gt;HandlerSocket&lt;/a&gt; is a plugin for MySQL that gives you direct access to the low level APIs that let you do the operations that AvroBase requires without going through the high-level SQL APIs and therefore skip a lot of boilerplate parsing that happens for every single lookup or scan. You can read about the &lt;a rel="nofollow" target="_blank" href="http://yoshinorimatsunobu.blogspot.com/2010/10/using-mysql-as-nosql-story-for.html"&gt;HandlerSocket benchmarks here&lt;/a&gt;. &lt;a rel="nofollow" target="_blank" href="http://www.percona.com/software/percona-server/"&gt;Percona Server&lt;/a&gt; is just a better implementation of MySQL with its own modified InnoDB engine called XtraDB. In combination you should be able to get even higher numbers of transactions per second for individual servers in a cluster. Building it on the Mac (or any unix system) is pretty straight-forward.&lt;br /&gt;
&lt;span id="more-1386"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
cd /Users/sam/Software/Percona-Server-5.1.53/&lt;br /&gt;
./configure --prefix=/Users/sam/usr&lt;br /&gt;
make &amp;amp;&amp;amp; make install&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
Similarly, download the HandlerSocket source via Git and then build it:&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
git clone https://github.com/ahiguti/HandlerSocket-Plugin-for-MySQL.git&lt;br /&gt;
cd HandlerSocket-Plugin-for-MySQL/&lt;br /&gt;
sh autogen.sh&lt;br /&gt;
./configure --prefix=/users/sam/usr --with-mysql-source=/Users/sam/Software/Percona-Server-5.1.53 --with-mysql-bindir=/users/sam/usr/bin --with-mysql-plugindir=/users/sam/usr/lib/mysql/plugin&lt;br /&gt;
make &amp;amp;&amp;amp; make install&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
You then need to make some changes to the my.cnf file:&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
[mysqld]&lt;br /&gt;
user = sam&lt;br /&gt;
port = 3406&lt;br /&gt;
loose_handlersocket_port = 9998&lt;br /&gt;
loose_handlersocket_port_wr = 9999&lt;br /&gt;
loose_handlersocket_threads = 16&lt;br /&gt;
loose_handlersocket_threads_wr = 1&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
Start up mysql for the first time:&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
export PATH=~/usr/bin:$PATH&lt;br /&gt;
mysql_install_db&lt;br /&gt;
cd /Users/sam/usr ; /Users/sam/usr/bin/mysqld_safe &amp;amp;&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
Then connect to mysql and install the plugin:&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
mysql -u root&lt;br /&gt;
install plugin handlersocket soname 'handlersocket.so';&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
For AvroBase I am using the native i/o Java client:&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
svn checkout http://hs4j.googlecode.com/svn/trunk/ hs4j&lt;br /&gt;
mvn install -Dmaven.test.skip=true&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
Haven&amp;#8217;t fully put it through its paces but I expect to do some benchmarking here shortly. Because of the amount of work to deserialize objects vs the database access my guess is that it won&amp;#8217;t make a huge different in terms of qps for a single front-end. However, it will likely let us go to a much higher number of frontends before accessing the database becomes the bottleneck.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/javarants?a=dj2CAnSZNAw:glPhm_OwmLM:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/javarants?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/javarants?a=dj2CAnSZNAw:glPhm_OwmLM:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/javarants?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/javarants/~4/dj2CAnSZNAw" height="1" width="1"/&gt;</description>
         <author>Sam Pullara</author>
         <guid isPermaLink="false">http://www.javarants.com/?p=1386</guid>
         <pubDate>Mon, 20 Dec 2010 21:34:00 +0000</pubDate>
      <feedburner:origLink>http://www.javarants.com/2010/12/20/testing-out-percona-and-handlersocket-with-avrobase/</feedburner:origLink></item>
      <item>
         <title>What does the Facebook security thing mean to users?</title>
         <link>http://feedproxy.google.com/~r/javarants/~3/o5daTKbgFvg/</link>
         <description>&lt;p&gt;You might have read a lot about the Facebook issue over the last couple of days. The technical description of this is pretty complicated but the implications are pretty clear. When you use applications on Facebook and they use a technology called &amp;#8216;iframes&amp;#8217; to host their application (like Farmville) and then partner with other companies for advertising it is possible that your UID gets passed all the way from Facebook to the third-party advertising sites. This happens because of the details of how browsers work with referrers, third party javascript includes and iframes. At that point they could take that UID and set a cookie on your browser so that whenever they see you, wherever you are on the web, they know that it is you and can lookup your public Facebook information and use that information to target ads, customize content, etc.&lt;br /&gt;
&lt;span id="more-1375"&gt;&lt;/span&gt;&lt;br /&gt;
People can argue that this information is public, however, the fact that the information is tied to your browser and can be accessed anywhere that the advertiser has an ad makes it especially powerful. For example, I could use the information to create advertisements on another website (not Facebook) that includes photos of you and your friends. I could address you by name in the ad, use the names of your parents or children, whatever you might have made available on Facebook to the world at large. My Facebook account is pretty tied down, however there is a certain base level of publicness about Facebook that makes the possibility of creating very creepy, misleading ads across the internet.&lt;/p&gt;
&lt;p&gt;Here is what I can discover about myself using only my UID and publicly accessible URLs via the Facebook Open Graph API:&lt;/p&gt;
&lt;p&gt;Name: Sam Pullara&lt;br /&gt;
First Name: Sam&lt;br /&gt;
Last Name: Pullara&lt;br /&gt;
Link: http://www.facebook.com/spullara&lt;br /&gt;
Gender: Male&lt;br /&gt;
Locale: en_US&lt;br /&gt;
Picture: &lt;img src="http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs267.snc3/23103_2410418_4027_q.jpg" alt=""/&gt;&lt;/p&gt;
&lt;p&gt;If you want to do the same and see what is available for you, start here https://graph.facebook.com/[your uid]?metadata=1 and try each of the links in the connections subsection to see what is easily available.&lt;/p&gt;
&lt;p&gt;Using web scraping, I can discover even more information about me:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://dl.dropbox.com/u/3924269/Screenshots/8.png"&gt;&lt;/p&gt;
&lt;p&gt;It is a good thing for Facebook to not allow this kind of UID transfer to third parties with whom you have no connection, especially when cookies are involved. Other large scale internet services go to great lengths to avoid this kind of data transfer. Facebook should fix the URLs so it isn&amp;#8217;t inadvertently transferred from their application partners to the application partner&amp;#8217;s advertisers.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/javarants?a=o5daTKbgFvg:HTtKpiR0Il4:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/javarants?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/javarants?a=o5daTKbgFvg:HTtKpiR0Il4:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/javarants?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/javarants/~4/o5daTKbgFvg" height="1" width="1"/&gt;</description>
         <author>Sam Pullara</author>
         <guid isPermaLink="false">http://www.javarants.com/?p=1375</guid>
         <pubDate>Tue, 19 Oct 2010 17:53:37 +0000</pubDate>
      <feedburner:origLink>http://www.javarants.com/2010/10/19/what-does-the-facebook-security-thing-mean-to-users/</feedburner:origLink></item>
      <item>
         <title>HAvroBase: a searchable, evolvable entity store on top of HBase and Solr</title>
         <link>http://feedproxy.google.com/~r/javarants/~3/O1uhoW5Doms/</link>
         <description>&lt;p&gt;Building out a social consumer internet product that could change quickly and evolve over time puts special requirements on the underlying data store. You need to be prepared for scale but not investing too much too early, your business may need to pivot in different directions so data models can&amp;#8217;t be set in stone and you need to be able to search that data to enable many of the features users expect from an online social product. I have the additional requirement that I wanted all the entities in the system, regardless of where they are stored, to be accessed the same way and be described by the same data description language for consistency and maintainability. I&amp;#8217;ve created what I think to be a novel solution to these requirements in the form of &lt;a rel="nofollow" target="_blank" href="http://github.com/spullara/havrobase"&gt;HAvroBase&lt;/a&gt;.&lt;span id="more-1349"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;The first choice you have to make against these requirements is which data definition language are you going to use? Instead of depending on the native format of the storage system I&amp;#8217;ve decided to use &lt;a rel="nofollow" target="_blank" href="http://github.com/apache/avro"&gt;Avro&lt;/a&gt;. Similar to &lt;a rel="nofollow" target="_blank" href="http://code.google.com/p/protobuf/"&gt;Protocol Buffers&lt;/a&gt; and &lt;a rel="nofollow" target="_blank" href="http://incubator.apache.org/thrift/"&gt;Thrift&lt;/a&gt;, Avro lets you define your entities using schemas and store them efficiently in a binary format. Additionally, as long as you have the original schema available you can load old data into a new schema. This will let you evolve your stored rows lazily and not have to completely update your storage system when a new field is added or a field is removed.&lt;/p&gt;
&lt;p&gt;Whereas the data definition choice is basically commodity at this point and your choice can be somewhat arbitrary, the choice of storage technology will likely be something that has more trade-offs to consider. After looking at the features and communities of a variety of projects including &lt;a rel="nofollow" target="_blank" href="http://hbase.apache.org/"&gt;HBase&lt;/a&gt;, &lt;a rel="nofollow" target="_blank" href="http://cassandra.apache.org/"&gt;Cassandra&lt;/a&gt;, &lt;a rel="nofollow" target="_blank" href="http://code.google.com/p/redis/"&gt;Redis&lt;/a&gt;, &lt;a rel="nofollow" target="_blank" href="https://wiki.basho.com/display/RIAK/Riak"&gt;Riak&lt;/a&gt;, &lt;a rel="nofollow" target="_blank" href="http://mysql.com"&gt;MySQL&lt;/a&gt;, &lt;a rel="nofollow" target="_blank" href="http://www.northscale.com/products/membase_server.html"&gt;Membase&lt;/a&gt;, &lt;a rel="nofollow" target="_blank" href="http://www.terracotta.org/"&gt;Terracotta&lt;/a&gt;, etc. I finally chose HBase for a few reasons that may not be that important to you. First I settled on a &lt;a rel="nofollow" target="_blank" href="http://labs.google.com/papers/bigtable.html"&gt;BigTable&lt;/a&gt; type choice based on the data model. That left HBase and Cassandra as contenders. There also a few things I think are advantages:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;multiple tables&lt;/li&gt;
&lt;li&gt;better ordered key support&lt;/li&gt;
&lt;li&gt;Zookeeper and HDFS were already in my solution&lt;/li&gt;
&lt;li&gt;Hive and Hadoop support against the native data format&lt;/li&gt;
&lt;li&gt;consistency&lt;/li&gt;
&lt;li&gt;compare and set&lt;/li&gt;
&lt;li&gt;atomic increment&lt;/li&gt;
&lt;li&gt;versioning&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span style="font-family:Georgia, 'Bitstream Charter', serif;line-height:24px;font-size:16px;"&gt;Cassandra definitely has its own advantages that didn&amp;#8217;t out-weigh the other considerations including&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;performance&lt;/li&gt;
&lt;li&gt;simple deployment&lt;/li&gt;
&lt;li&gt;always writable&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span style="font-size:medium;"&gt;&lt;span style="line-height:24px;"&gt;You might make different tradeoffs or even use both solutions for different problems. I&amp;#8217;m also biased somewhat as I am sharing an office with &lt;a rel="nofollow" target="_blank" href="http://cloudera.com/"&gt;Cloudera&lt;/a&gt; and get top notch support at a moments notice.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:medium;"&gt;&lt;span style="line-height:24px;"&gt;Whether I chose HBase or Cassandra the implementation would have been much the same and with the HAvroBase framework you can have multiple independent storage systems. The framework does somewhat shield you from this decision, at least in your code.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:medium;"&gt;&lt;span style="line-height:24px;"&gt;When it comes to text search you really don&amp;#8217;t get better than &lt;a rel="nofollow" target="_blank" href="http://lucene.apache.org/"&gt;Lucene&lt;/a&gt; in open source and the features that &lt;a rel="nofollow" target="_blank" href="http://wiki.apache.org/solr/FrontPage"&gt;Solr&lt;/a&gt; builds on top of Lucene make it even better. I don&amp;#8217;t think there is reasonable argument for using something besides Solr at this point. Especially with their support for sharding and replication that comes with &lt;a rel="nofollow" target="_blank" href="http://wiki.apache.org/solr/SolrCloud"&gt;Solr Cloud&lt;/a&gt;. It also has the nice benefit that it supports multiple tables, like HBase, so I can efficiently separate entities and allow them to scale independently without managing an additional system.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:medium;"&gt;&lt;span style="line-height:24px;"&gt;The last choice that I made was runtime configuration. There are a few solutions including &lt;a rel="nofollow" target="_blank" href="http://www.springsource.org/"&gt;Spring&lt;/a&gt;, &lt;a rel="nofollow" target="_blank" href="http://code.google.com/p/google-guice/"&gt;Guice&lt;/a&gt; and rolling my own and I finally landed on the side of Guice. I just like typed, programmatic configuration better than XML files and since that is the focus of Guice, I think it is the best solution for that.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:medium;"&gt;&lt;span style="line-height:24px;"&gt;The first thing that you need to do to use the system is to define an entity in Avro:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size:small;"&gt;&lt;span style="font-size:medium;"&gt;&lt;span style="line-height:24px;"&gt;You can use the Avro compiler (or the Maven plugin) to convert that definition to classes (HAvroBase requires this). Then you do the typical things in code to setup your HBase connection but within a Guice module and set some of the configuration parameters for HAB:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size:small;"&gt;&lt;span style="font-size:medium;"&gt;&lt;span style="line-height:24px;"&gt;That configuration can then be used to instantiate an instance of the HAB class that implements the connection to HBase like this:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size:small;"&gt;&lt;span style="font-size:medium;"&gt;&lt;span style="line-height:24px;"&gt;You&amp;#8217;ll notice that configuration is somewhat split between things that the base system needs to know and things that the HAB needs to know. For example, what table the schema is store in isn&amp;#8217;t relevant to the base system as an implementer is free to store schemas however they like. But the assumption is that every system will have the concept of a table and a column family in order to separate entities in the underlying storage system. The Solr support is pretty elegant I think. Rather than specifying in more than one place which fields should be indexed, instead at runtime it queries the Solr core&amp;#8217;s schema.xml that defines them and then when you put an entity in the system it automatically indexes those fields.  Here is an example of using some of the APIs:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
This example creates a new User, puts it into the HAvroBase, looks it up by row and then searches for it by field that is indexed and finally deletes it. In any fully implemented AvroBase system this should work identically. You&amp;#8217;ll notice in the memcached implementation that only put/get/delete are implemented and it doesn&amp;#8217;t support scan or search at all. I&amp;#8217;ve considered breaking out that functionality into separate interfaces but haven&amp;#8217;t done that yet.&lt;/p&gt;
&lt;p&gt;If you are unhappy with the way the default Avro compiler generates code you can use my &lt;a rel="nofollow" target="_blank" href="http://github.com/spullara/avrocompiler"&gt;templated Avro compiler&lt;/a&gt; that lets you change the generated code. I have done that for my project to make them a little more developer friendly.&lt;/p&gt;
&lt;p&gt;Things left to do:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;implement guarantees around indexing&lt;/li&gt;
&lt;li&gt;optimize schema keys (use an abbrev table instead of a hex sha-256 key)&lt;/li&gt;
&lt;li&gt;indexing nested fields and arrays in Solr&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I&amp;#8217;m sure there are more things left undone but those are some of the more obvious issues.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/javarants?a=O1uhoW5Doms:IchZAvOm4-E:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/javarants?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/javarants?a=O1uhoW5Doms:IchZAvOm4-E:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/javarants?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/javarants/~4/O1uhoW5Doms" height="1" width="1"/&gt;</description>
         <author>Sam Pullara</author>
         <guid isPermaLink="false">http://www.javarants.com/?p=1349</guid>
         <pubDate>Wed, 30 Jun 2010 19:55:44 +0000</pubDate>
      <feedburner:origLink>http://www.javarants.com/2010/06/30/havrobase-a-searchable-evolvable-entity-store-on-top-of-hbase-and-solr/</feedburner:origLink></item>
      <item>
         <title>Static-typing is a powerful metadata database, exploit it!</title>
         <link>http://feedproxy.google.com/~r/javarants/~3/FA0il2dID6U/</link>
         <description>&lt;p&gt;Today someone decided to pretend they knew something about how a modern statically typed language developer works.  Perhaps they are big emacs fans or something because they felt that static-types leading to autocomplete in an IDE was somehow a feature in the language FOR THE IDE.  The IDE gets no benefit, in fact, editors like emacs and TextMate are much simpler. But I can tell you that the developer gets a tremendous benefit by having this metadata database not only present in the code and easily queryable but heavily exploited by her tools.  What is amazing about this metadata database is that it is actually populated by that same IDE.  There are very few times that I even type a Type &amp;#8212; 90% of those times are when declaring a new Type &amp;#8212; the rest of the time the IDE is very patiently maintaining and leveraging that database for me.  Even better, when someone else is looking at the source code, or even using the library, they instantly get 80% of the documentation. All that is left are the semantics of the calls. Perhaps we need to have some sort of meetup where we look over each others shoulders and actually understand how someone who is on the other side really works rather than dynamic-typing language people assuming that the programmer is maintaining the huge metadata database present in the static-typing language developers code.  And on the otherside that static-typers are assuming that the dynamic-typing language developer is memorizing all kinds of arcane method call names, argument shapes and the shapes of all the libraries they are using. Do you really memorize all that trivia?&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/javarants?a=FA0il2dID6U:53wNw1m9unc:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/javarants?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/javarants?a=FA0il2dID6U:53wNw1m9unc:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/javarants?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/javarants/~4/FA0il2dID6U" height="1" width="1"/&gt;</description>
         <author>admin</author>
         <guid isPermaLink="false">http://www.javarants.com/?p=1331</guid>
         <pubDate>Thu, 17 Jun 2010 00:20:47 +0000</pubDate>
      <feedburner:origLink>http://www.javarants.com/2010/06/16/static-typing-is-a-powerful-metadata-database-exploit-it/</feedburner:origLink></item>
      <item>
         <title>Building the ideal web application template engine</title>
         <link>http://feedproxy.google.com/~r/javarants/~3/ffXAypmocUs/</link>
         <description>&lt;p&gt;A month and a half ago I had put out a call for what I was calling the &amp;#8216;&lt;a rel="nofollow" target="_blank" href="http://www.javarants.com/2010/05/03/the-ideal-web-application-templating-system/"&gt;ideal web application template engine&lt;/a&gt;&amp;#8216; along with a list of requirements that I thought would be present in such a system.  Since then I looked a bunch of them and decided that I like the simple markup that &lt;a rel="nofollow" target="_blank" href="http://mustache.github.com/"&gt;mustache&lt;/a&gt; defined but none of the implementations were up to doing what I wanted.  This led me to embark on building a new engine with for that markup for my chosen platform, Java, which I called creatively, &lt;a rel="nofollow" target="_blank" href="http://github.com/spullara/mustache.java"&gt;mustache.java&lt;/a&gt;.  Though it claims to be &amp;#8216;logic-less&amp;#8217; I would say that it has some amount of logic. It will loop over a set of objects and it will check booleans, but I think it is about as close to logic-less as you would want to be in a template language.  So, let&amp;#8217;s look at each of the requirements and how I ended up implementing them:&lt;br /&gt;
&lt;span id="more-1327"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Works well with HTML5/CSS3 progressive enhancement&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This one is straight-forward.  Because I put no limitations on the generated text you can actually generate almost anything with mustach.java, in fact, I am using it in another &lt;a rel="nofollow" target="_blank" href="http://github.com/spullara/avrocompiler"&gt;project&lt;/a&gt; to generate Java source for Avro objects.  It is really overkill for that project but it is so easy to use that I used it anyway.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Allows mock data within the template that is replaced at runtime&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Client-side version that leverages the mock data for shift-reload debugging&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These I implemented somewhat differently from the requirement because the mustache template language is not tag based.  I have actually thought about whether it might make sense to make it tag-based and get the full requirement, but I digress.  What I did get to is a system that is easy for a frontend developer or designer to use without having the whole system running on their machine.  Included with mustache.java is a mini-server (called &lt;strong&gt;handlebar&lt;/strong&gt;, thanks for the name &lt;a rel="nofollow" target="_blank" href="http://lukew.com"&gt;Luke&lt;/a&gt;) that combines mock json data with mustache.java templates. This lets them view a fully rendered version of the page they are working on with the required templating information that will be used in production but without running a big production system. In fact, because mustache.java dynamically generates and compiles Java code, they can fire up &lt;strong&gt;handlebar&lt;/strong&gt; in directory along with their mock data and just keep reloading the page to see the effect of changes they make.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt; Composable components, not monolithic pages&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;em&gt;Very little or no business logic in the templates&lt;/em&gt;&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The choice of mustache as a base template language ensured that this would be the case.  Including a partial within a template is easy and makes pages very easy to compose. I still miss the Django template style &lt;em&gt;extends/block&lt;/em&gt; system and may extend mustache to support it. Having to remember to include things like the header and footer on every page doesn&amp;#8217;t seem necessary.  As I said above, I think that mustache has the minimum reasonable logic.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Concurrent evaluation possible&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This one was very important to me from a performance perspective. My implementation makes every effort to be as low latency as possible for the end user.  At every possible point in template evaluation things are actually executed in separate threads or purely asynchronously in the case of external I/O like HTTP requests to other services.  The one last thing I am going to do here is to allow not only a straight-line evaluation of the template but the possibility of specifying a timeout so that you can return different markup if evaluation doesn&amp;#8217;t return in time. It may be unnecessary to have this in the base template engine though, still looking at the design of the feature.&lt;/p&gt;
&lt;p&gt;So how easy is using the template system?  I think I can answer that question by looking at the relevant portions of the &lt;a rel="nofollow" target="_blank" href="http://github.com/spullara/mustache.java/blob/master/handlebar/src/main/java/com/sampullara/mustache/Handlebar.java"&gt;implementation of &lt;/a&gt;&lt;strong&gt;&lt;a rel="nofollow" target="_blank" href="http://github.com/spullara/mustache.java/blob/master/handlebar/src/main/java/com/sampullara/mustache/Handlebar.java"&gt;handlebar&lt;/a&gt;:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;final MustacheCompiler mc = new MustacheCompiler(new File("."));
....
Mustache mustache = mc.compile(new BufferedReader(new FileReader(filename)));
FutureWriter fw = new FutureWriter(res.getWriter());
File file = new File(mocks, base + ".json");
if (file.exists()) {
  BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
  JsonParser parser = jf.createJsonParser(bis);
  JsonNode json = parser.readValueAsTree();
  mustache.execute(fw, new Scope(json));
} else {
  mustache.execute(fw, new Scope());
}
fw.flush();&lt;/pre&gt;
&lt;p&gt;The most interesting part of this is the FutureWriter. The future writer lets mustache write evaluated templates completed out of order in template order.  The scope is essentially a sophisticated context object that knows how to pull data from Java objects of various types, including raw object fields and methods, Maps and Json objects. Conveniently, you can also store values in it directly. There are some things I would like to extend at some point, however, for all practical purposes the template system is finished.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/javarants?a=ffXAypmocUs:a0eMg2wIURQ:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/javarants?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/javarants?a=ffXAypmocUs:a0eMg2wIURQ:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/javarants?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/javarants/~4/ffXAypmocUs" height="1" width="1"/&gt;</description>
         <author>admin</author>
         <guid isPermaLink="false">http://www.javarants.com/?p=1327</guid>
         <pubDate>Wed, 16 Jun 2010 18:02:03 +0000</pubDate>
      <feedburner:origLink>http://www.javarants.com/2010/06/16/building-the-ideal-web-application-template-engine/</feedburner:origLink></item>
      <item>
         <title>Android Dalvik VM performance is a threat to the iPhone</title>
         <link>http://feedproxy.google.com/~r/javarants/~3/rI8vAQSHZBc/</link>
         <description>&lt;p&gt;One of the peculiarities of Apple is that they have set themselves down a path where every Apple developer needs to learn Objective-C (and C/C++) to build applications for their platform.  The biggest characteristic of Objective-C vs Java is dynamic dispatch. At runtime Objective-C can send arbitrary messages to objects and they may or may not respond to them.  This has the nice property that you can write code that is very dynamic and loosely bound but it also has the property that method calls in Objective-C are very slow and the more code that you write in Objective-C instead of in C/C++ the slower your codebase becomes.  Up until Android 2.2 (Froyo) the JVM (really a &lt;a rel="nofollow" target="_blank" href="http://en.wikipedia.org/wiki/Dalvik_(software)"&gt;Dalvik JVM&lt;/a&gt; for licensing reasons) on the Android platform was playing with one hand tied behind its back.  Different from desktop/server Java, the JVM was still an interpreter, like the original JVM back in the Java 1.0 days.  It was very efficient interpreter but an interpreter none-the-less and was not creating native code from the Dalvik bytecodes that it uses.  As of Android 2.2 they have added a JIT, a just-in-time compiler, to the stack that translates the Dalvik bytecode into much more efficient machine code much like a C/C++ compiler.  You can see the results of this in the benchmarks of Froyo which &lt;a rel="nofollow" target="_blank" href="http://crave.cnet.co.uk/mobiles/0,39029453,49305763,00.htm"&gt;show a 2-5x improvement&lt;/a&gt;.  As they add more and more JIT and GC features that have appeared in HotSpot, JRockit, etc, you will likely see even more improvements over time &amp;#8212; without having to change or recompile the 3rd party developed software.&lt;/p&gt;
&lt;p&gt;&lt;span id="more-1311"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;This wouldn&amp;#8217;t be that big a deal if Android software wasn&amp;#8217;t already approaching the speed of the Apple iPhone even when running its applications through the interpreter (see the HTC EVO 4G running 2.1).  This is likely going to mean that 3rd party developer applications created for Android, running on the same hardware, is going to be faster than the same code written against the Objective-C libraries that Apple provides for the iPhone.  You&amp;#8217;ll be able to get more done, have smoother user interfaces and all around build more powerful applications easier.  A better experience for the user and the developer on Android is a bad thing for Apple.&lt;/p&gt;
&lt;p&gt;The final issue that Apple has is that far more people know and need  to know Java than Objective-C.  Except for their platform, there is no need to ever learn it.  The tool chain is much more robust, information is much easier to come by, garbage collection is available, and there are thousands more libraries written in Java than Objective-C and far more portable libraries than are written for C/C++.  You might argue that you can always drop down to C/C++ code to make up for the lost performance of using Objective-C (at a significant cost development-wise).  You can do that, except places where you need to make a call into Apple&amp;#8217;s Objective-C runtime libraries or where you want to write callbacks from those libraries. Those are mostly Objective-C libraries and use the dynamic dispatch mechanism which &lt;a rel="nofollow" target="_blank" href="http://www.javarants.com/2004/05/04/looks-like-apple-should-switch/"&gt;I showed in 2004 was very much slower than Java&lt;/a&gt;.  I&amp;#8217;d really love to see the whole &lt;a rel="nofollow" target="_blank" href="http://shootout.alioth.debian.org/"&gt;computer language shootout&lt;/a&gt; written with Objective-C calling conventions just to show how much slower it is at that level.&lt;/p&gt;
&lt;p&gt;Obviously performance is not the only consideration, but it is a big one.  Android has other issues like a fragmented operating system base, hardware feature base and a more complicated user experience.  All those things will conspire to hold it back but I think we can see the writing on the wall that Android is going to dominate iPhone market-share wise which will eventually make it a more attractive platform business-wise.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update: &lt;/strong&gt;Just so people don&amp;#8217;t get the wrong idea, I am a rabid iPhone user and develop for the iPhone first.  This blog entry is to call out a threat that Apple should take seriously.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update 2: &lt;/strong&gt;Alright, you win. Don&amp;#8217;t worry about competing with Google &amp;amp; Android on performance. It probably doesn&amp;#8217;t matter that much for the user experience.  Especially don&amp;#8217;t fix obj_msgSend() with a JIT/LLVM, that would be crazy.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/javarants?a=rI8vAQSHZBc:RwDfZ-ftOrI:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/javarants?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/javarants?a=rI8vAQSHZBc:RwDfZ-ftOrI:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/javarants?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/javarants/~4/rI8vAQSHZBc" height="1" width="1"/&gt;</description>
         <author>Sam Pullara</author>
         <guid isPermaLink="false">http://www.javarants.com/?p=1311</guid>
         <pubDate>Wed, 26 May 2010 16:29:57 +0000</pubDate>
      <feedburner:origLink>http://www.javarants.com/2010/05/26/android-dalvik-vm-performance-is-a-threat-to-the-iphone/</feedburner:origLink></item>
   </channel>
</rss><!-- fe3.yql.bf1.yahoo.com compressed/chunked Sat May 18 13:10:33 UTC 2013 -->
