<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[spullara - Medium]]></title>
        <description><![CDATA[Technology focused rants - Medium]]></description>
        <link>https://medium.com/spullara?source=rss----cb1f5a3bcba4---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>spullara - Medium</title>
            <link>https://medium.com/spullara?source=rss----cb1f5a3bcba4---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 03:04:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/spullara" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Why your new JVM build tool is making things worse, aka use Maven to execute your build]]></title>
            <link>https://medium.com/spullara/why-your-new-jvm-build-tool-is-making-things-worse-aka-use-maven-to-execute-your-build-a22ef66baa74?source=rss----cb1f5a3bcba4---4</link>
            <guid isPermaLink="false">https://medium.com/p/a22ef66baa74</guid>
            <dc:creator><![CDATA[Sam Pullara]]></dc:creator>
            <pubDate>Tue, 16 Jul 2013 16:54:33 GMT</pubDate>
            <atom:updated>2016-06-21T17:51:01.297Z</atom:updated>
            <content:encoded><![CDATA[<p>There are a few principles that I would like the ecosystem of build tool developers to adopt so we can all get on the same page. Here they are in priority order:</p><ol><li>The build tool should be designed to make it as easy as possible for <strong>other</strong> developers to build your project. The primary consumer of the automated build should not be you. It is your CI machine, it is your fellow developers, and it is your open source users. You could build it with a bespoke shell script much more efficiently.</li><li>There should be a <strong>single style</strong> of dependency management so that all published artifacts are consumable by any build. The bifurcation into Ivy repositories and Maven repositories makes very little sense. NIH is not a reason to make up a new directory structure.</li><li>Innovation in the space should be around tools that sit in front of a <strong>common backend</strong> so that the primary developer doesn’t need to change the ecosystem to make their build configuration less verbose.</li></ol><p>What does this mean in practice? SBT, gradle, pants, Leinegen — I think you are all doing it wrong. There isn’t much innovation in those projects, they mostly are rebuilding what Maven already gives you with a different language on top — but usually leaving out a ton of features, call out to Maven plugins and add scripting (mistake). If each of them had instead decided that their build tool would generate pom.xml under the covers they would have had instant support from the community (IDEs, CI, users, etc) and could focus on making the very best plugin for their language. Instead they reinvent the wheel. At least in some cases people are starting to reuse Aether from Maven to get around the repository bifurcation and in other cases embracing Maven — Typesafe’s zinc compiler plugin. My opinion is that people can’t see the big picture and are only focusing on themselves to the detriment of the JVM ecosystem.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a22ef66baa74" width="1" height="1" alt=""><hr><p><a href="https://medium.com/spullara/why-your-new-jvm-build-tool-is-making-things-worse-aka-use-maven-to-execute-your-build-a22ef66baa74">Why your new JVM build tool is making things worse, aka use Maven to execute your build</a> was originally published in <a href="https://medium.com/spullara">spullara</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mustache is logic-less but the logic has to go somewhere]]></title>
            <link>https://medium.com/spullara/mustache-is-logic-less-but-the-logic-has-to-go-somewhere-3e976b7a49c8?source=rss----cb1f5a3bcba4---4</link>
            <guid isPermaLink="false">https://medium.com/p/3e976b7a49c8</guid>
            <dc:creator><![CDATA[Sam Pullara]]></dc:creator>
            <pubDate>Sat, 09 Mar 2013 23:21:05 GMT</pubDate>
            <atom:updated>2016-06-21T17:51:20.704Z</atom:updated>
            <content:encoded><![CDATA[<p>As the developer of <a href="https://github.com/spullara/mustache.java">mustache.java</a> I get a lot of feature requests to break the <a href="https://github.com/mustache/spec">mustache language</a> 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:</p><pre>class User {<br>  String username;<br>  long createdAt;<br>}</pre><p>And they want to show when the user joined in their template:</p><pre>{{#user}}{{username}} joined on {{createdAt}}{{/user}}</pre><p>They look at this and think, “I need to be able to format longs into dates in the template”. 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:</p><pre>{{#user}}{{username}} joined on {{createdAt | date}}{{/user}}</pre><p>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’t flexible enough with just a name:</p><pre>{{#user}}<br>  {{username}} joined on {{createdAt | date(&quot;DD/mm/YYYY&quot;)}}<br>{{/user}}</pre><p>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’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:</p><pre>class UserView {<br>  String username;<br>  String joined_date;<br>  UserView(User user) {<br>    username = user.username;<br>    joined_date = new SimpleDateFormat(&quot;DD/mm/YYYY&quot;)<br>        .format(new Date(user.createdAt));<br>  }<br>}</pre><p>with a template much like the first one:</p><pre>{{#user}}{{username}} joined on {{joined_date}}{{/user}}</pre><p>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.</p><p>This strategy worked great at <a href="https://bagcheck.com/">Bagcheck</a> where there was only myself and a designer and it works great at <a href="https://twitter.com/sampullara">Twitter</a> 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.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e976b7a49c8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/spullara/mustache-is-logic-less-but-the-logic-has-to-go-somewhere-3e976b7a49c8">Mustache is logic-less but the logic has to go somewhere</a> was originally published in <a href="https://medium.com/spullara">spullara</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is new and interesting in JDK 7?]]></title>
            <link>https://medium.com/spullara/what-is-new-and-interesting-in-jdk-7-fce355e02af3?source=rss----cb1f5a3bcba4---4</link>
            <guid isPermaLink="false">https://medium.com/p/fce355e02af3</guid>
            <dc:creator><![CDATA[Sam Pullara]]></dc:creator>
            <pubDate>Mon, 10 Sep 2012 02:12:03 GMT</pubDate>
            <atom:updated>2016-06-21T17:51:24.257Z</atom:updated>
            <content:encoded><![CDATA[<p>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:</p><ul><li>Invokedynamic bytecode for doing runtime binding of callsites</li><li>Named regular expression groups</li><li>Try with resources / AutoCloseable</li><li>MethodHandles</li><li>BufferPoolMXBean — where did all my memory go?</li><li>SocketOption, ProtocolFamily and NetworkInterface</li><li>Async IO — including filesystem notifications and a new network stack</li><li>ForkJoinPool</li><li>TransferQueue</li><li>Precise exception rethrowing, catching more than one exception type</li><li>Switch on String</li><li>Much better GZIP support</li><li>Global logger and other log management stuff</li><li>ThreadLocalRandom</li><li>Bitset.valueOf() for arrays</li><li>Paths for manipulating file paths</li><li>Files for copying files and streams, etc. Swiss army knife of stuff</li><li>File attributes, ACLs, etc.</li><li>Long.compare — probably caused a lot of bugs</li><li>Tons of Locale / Character updates</li></ul><p>Things I found that are old but new to me:</p><ul><li>Scanner — using all regexes, probably horribly inefficient</li><li>PriorityQueue, Deque</li><li>Atomic*FieldUpdaters</li></ul><p>Am I missing anything?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fce355e02af3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/spullara/what-is-new-and-interesting-in-jdk-7-fce355e02af3">What is new and interesting in JDK 7?</a> was originally published in <a href="https://medium.com/spullara">spullara</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[New features and extensions in Mustache.java]]></title>
            <link>https://medium.com/spullara/new-features-and-extensions-in-mustache-java-ed3d8ac7a05b?source=rss----cb1f5a3bcba4---4</link>
            <guid isPermaLink="false">https://medium.com/p/ed3d8ac7a05b</guid>
            <dc:creator><![CDATA[Sam Pullara]]></dc:creator>
            <pubDate>Sun, 09 Oct 2011 23:29:31 GMT</pubDate>
            <atom:updated>2016-06-21T17:51:24.397Z</atom:updated>
            <content:encoded><![CDATA[<p>Almost a year and a half ago <a href="http://www.javarants.com/2010/06/16/building-the-ideal-web-application-template-engine/">I talked about</a> my implementation of <a href="http://mustache.github.com/">mustache</a>, which I call <a href="https://github.com/spullara/mustache.java">mustache.java</a>. Since then, we used it to develop <a href="http://bagcheck.com/">Bagcheck</a> and it has also been adopted for a variety of use cases by <a href="http://netflix.com/">Netflix</a>, <a href="http://twitter.com/">Twitter</a> and others. In my post I mention that for all intents and purposes, the template engine was ‘finished’ 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.</p><p>First though, I will shortly recap the biggest differentiating feature of this implementation over other implementations:</p><ul><li>Concurrent, streaming template evaluation</li></ul><p>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 <a href="https://www.facebook.com/note.php?note_id=389414033919">Big Pipe</a>. This has been invaluable to easily maintaining Bagcheck’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 <a href="http://code.google.com/p/guava-libraries/">Google collections</a> 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.</p><p>Since the first release, the <em>handlebar server</em> 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 <em>unexecute(content)</em> on that instance and if it isn’t ambiguous or in some other way irreversible you will get back a Scope object that contains the data. Using <em>toJSON()</em> on that object will provide mock data that can be used with <em>handlebar</em>. Here is an example:</p><p>[gist id=1274327]<br>[gist id=1274330]</p><p>We then take the template and the output and unexecute them using the new method on Mustache objects:</p><p>[gist id=1274334]</p><p>This produces the following JSON (after pretty printing):</p><p>[gist id=1274337]</p><p>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.</p><p>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:</p><p>[gist id=1274365]</p><p>The biggest change since the release though is the addition of the <em>MustacheBuilder</em>. In 0.6 I will be deprecating <em>MustacheCompiler</em> as not only does the <em>Builder</em> 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 <em>Builder</em> 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 <em>ASM</em> for compilation though in order to take advantage of JDK 7 and <em>invokedynamic</em> as that becomes the standard JVM in deployment.</p><p>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:</p><ul><li>mustache.debug: output a warning when a callback is absent or null</li><li>mustache.trace: create a multithreaded trace, use MustacheTrace.setUniqueId() in each thread, output with MustacheTrace.toASCII()</li><li>mustache.profile: time all callbacks, output the top 10 total + average with Scope.report() and then reset the profiler</li></ul><p>Now is the time for input. Here are some things that I have on my TODO list:</p><ul><li>Full JDK7 invokedynamic support with ASM generated classes</li><li>Extensible templates a la Django templates</li><li>Native Scala support based on Twitter’s util-core</li><li>Generate scaffolding in a variety of languages for backing code with verification</li></ul><p>Would love to hear from users and prospects. You can either comment here or join the dicsussions on the <a href="http://groups.google.com/group/mustachejava">Mustache.java group</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ed3d8ac7a05b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/spullara/new-features-and-extensions-in-mustache-java-ed3d8ac7a05b">New features and extensions in Mustache.java</a> was originally published in <a href="https://medium.com/spullara">spullara</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Closures, Method Handles and Extension Methods in Java 8 (JSR-335)]]></title>
            <link>https://medium.com/spullara/using-closures-method-handles-and-extension-methods-in-java-8-jsr-335-7c927f4dddde?source=rss----cb1f5a3bcba4---4</link>
            <guid isPermaLink="false">https://medium.com/p/7c927f4dddde</guid>
            <dc:creator><![CDATA[Sam Pullara]]></dc:creator>
            <pubDate>Sun, 23 Jan 2011 01:57:53 GMT</pubDate>
            <atom:updated>2016-06-21T17:51:22.417Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Update:</strong> 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.</p><p>In December JSR-335 was approved by the JCP and is now starting. I’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 <a href="http://cr.openjdk.java.net/~briangoetz/lambda/lambda-state-3.html">current state of the JSR</a>. 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:</p><ul><li>Create closures that are converted to Single Abstract Method (SAM) implementations when used in context</li><li>Create interfaces that specify default behavior for methods that are unimplemented by the implementing class</li><li>Reference methods in source and then convert those references to SAM implementations when used in context</li></ul><p>Building OpenJDK 7 on Mac OS X 10.6 (based on <a href="http://wikis.sun.com/display/OpenJDK/Darwin10Build">Darwin10Build</a>):</p><ul><li>Install mecurial: <br>sudo port install mercurial</li><li>Install hg-forest: <br>sudo port install hg-forest</li><li>Install <a href="http://hg.bikemonkey.org/archive/javasrc_1_6_jrl_darwin/soylatte16-i386-1.0.3.tar.bz2">soylatte</a> to /usr/local/soylatte16-i386–1.0.3</li><li>Clone bsd-port: <br>hg fclone <a href="http://hg.openjdk.java.net/bsd-port/bsd-port">http://hg.openjdk.java.net/bsd-port/bsd-port</a></li><li>export OPENJDK_ROOT=`pwd`</li><li>Grab build script: <br>cd bsd-port; curl -O “https://gist.github.com/raw/617451/d4862a41b07a1196d5149efc1c40406f8bb77dc1/update.sh&quot;</li><li>mkdir ALT_COMPILER_PATH;cd ALT_COMPILER_PATH;<br>ln -s /usr/bin .SOURCE;ln -s .SOURCE/g++-4.0 g++;<br>ln -s .SOURCE/gcc-4.0 gcc;cd ..</li><li>unset JAVA_HOME</li><li>Edit hotspot/make/bsd/makefiles/defs.make and change ifeq ($(ARCH), amd64) to ifeq($(ARCH), x86_64)</li><li>Update sources and build (on a fast machine will take 15m): <br>sh update.sh</li></ul><p>Now you should have a fully working OpenJDK 7 64-bit distribution:<br><br>macpro:bsd-port sam$ ./build/bsd-amd64/j2sdk-image/bin/java -version<br>openjdk version “1.7.0-internal”<br>OpenJDK Runtime Environment (build 1.7.0-internal-sam_2011_01_22_16_40-b00)<br>OpenJDK 64-Bit Server VM (build 20.0-b03, mixed mode)<br><br>Now we want to build the Lambda compiler and runtime support:</p><ul><li>Grab the source: <br>cd $OPENJDK_ROOT; hg clone <a href="http://hg.openjdk.java.net/lambda/lambda/langtools">http://hg.openjdk.java.net/lambda/lambda/langtools</a></li><li>Build the tools: <br>cd $OPENJDK_ROOT/langtools; ant -Dboot.java.home=../bsd-port/build/bsd-amd64/j2sdk-image -f make/build.xml</li></ul><p>OpenJDK 7 doesn’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:</p><ul><li>Grab the source: <br>cd $OPENJDK_ROOT; svn checkout <a href="http://jsr335-lambda.googlecode.com/svn/trunk/">http://jsr335-lambda.googlecode.com/svn/trunk/</a> jsr335-lambda</li><li>export JAVA_HOME=$OPENJDK_ROOT/bsd-port/build/bsd-amd64/j2sdk-image</li><li>Build the agent: <br>cd jsr335-lambda/agent; ant jar</li><li>export AGENTJAR=$OPENJDK_ROOT/jsr335-lambda/agent/lib/jsr335-agent.jar</li></ul><p>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:</p><pre>public class Test {<br>  public static void main(String[] args) throws InterruptedException {<br>    Thread t = new Thread(#{ System.out.println(&quot;ran&quot;); });<br>    t.start();<br>    t.join();<br>  }<br>}</pre><p>Let’s first compile it:</p><ul><li>export PATH=$JAVA_HOME/bin:$PATH</li><li>export LANGTOOLS_JAR=$OPENJDK_ROOT/langtools/dist/lib/classes.jar</li><li>javac -J-Xbootclasspath/p:$LANGTOOLS_JAR -source 8 -target 8 Test.java</li></ul><p>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’t need the transformations so we can execute this code like this:<br><br>macpro:jsr335 sam$ java -cp . Test<br>ran<br><br>Here is some code that will not run out of the box, that shows you how you can now write extension methods:</p><pre>public class Test2 {<br>  interface Trait {<br>    int inc(int i) default Test2.inc;<br>  }<br>  static int inc(Trait t, int i) { return i+1;}<br>  public static class Test3 implements Trait {}<br>  public static void main(String[] args) {<br>    Trait t = new Test3();<br>    System.out.println(t.inc(1));<br>  }<br>}</pre><p>If you try and run this without the agent you will get this:<br><br>macpro:jsr335 sam$ java -cp . Test2<br>Exception in thread “main” java.lang.AbstractMethodError: Test2$Test3.inc(I)I<br> at Test2.main(Test2.java:9)<br><br>Now we execute with the agent enabled:<br><br>macpro:jsr335 sam$ java -javaagent:$AGENTJAR -cp . Test2<br>2<br><br>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:</p><pre>public class Test3 {<br>    public void test() {<br>	System.out.println(&quot;Test&quot;);<br>    }<br>    public static void main(String[] args) {<br>	Test3 t = new Test3();<br>	Runnable r = t#test;<br>	r.run();<br>    }<br>}</pre><p>In order to run this we need to enable InvokeDynamic on our VM and include the classes from langtools for some runtime support:<br><br>macpro:jsr335 sam$ java -XX:+UnlockExperimentalVMOptions -XX:+EnableInvokeDynamic -Xbootclasspath/p:$LANGTOOLS_JAR -javaagent:$AGENTJAR -cp . Test3<br>Test<br><br>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’s put all of this together into the final example from the Lambda proposal itself:</p><pre>import java.util.*;</pre><pre>interface Sortable&lt;T, U extends Comparable&lt;? super U&gt;&gt;  extends List&lt;T&gt;  {<br>   void sortBy(Extractor&lt;? super T, ? extends U&gt;  e) default Impl.sortBy;<br>   static class Impl {<br>       public static&lt;T, U extends Comparable&lt;? super U&gt;&gt;<br>                 void sortBy(Sortable&lt;T, U&gt;  sortable, final Extractor&lt;? super T, ? extends U&gt;  e) {<br>           Collections.sort(sortable, #{T a, T b -&gt;  e.extract(a).compareTo(e.extract(b))});<br>       }<br>   }<br>}<br>interface Extractor&lt;T,U&gt; {<br>    public U extract(T t);<br>}</pre><pre>class Person {<br>    public Person(String firstName, String lastName) {<br>        this.firstName = firstName;<br>        this.lastName = lastName;<br>    }<br>    private String lastName;<br>    public String getLastName() { return lastName; }<br>    private String firstName;<br>    public String getFirstName() { return firstName;}<br>    public String toString() {<br>        return firstName + &quot; &quot; + lastName;<br>    }<br>}</pre><pre>public class Test4 {</pre><pre>public static class SortableList&lt;T, U extends Comparable&lt;? super U&gt;&gt; extends ArrayList&lt;T&gt; implements Sortable&lt;T, U&gt; {}</pre><pre>public static void main(String[] args) {<br>        Sortable&lt;Person, String&gt; list = new SortableList&lt;&gt;();<br>        list.add(new Person(&quot;Sam&quot;, &quot;Pullara&quot;));<br>        list.add(new Person(&quot;Brian&quot;, &quot;Goetz&quot;));<br>        list.add(new Person(&quot;Bob&quot;, &quot;Lee&quot;));<br>        list.sortBy(Person#getLastName);<br>        System.out.println(list);<br>    }<br>}<br><br>Which results in:<br><br>macpro:jsr335 sam$ java Test4<br>[Brian Goetz, Bob Lee, Sam Pullara]<br><br>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):</pre><pre><a href="http://javarants.com/openjdk7-lambda-macosx-x86_64-01222010.zip">openjdk7-lambda-macosx-x86_64-01222010.zip</a></pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7c927f4dddde" width="1" height="1" alt=""><hr><p><a href="https://medium.com/spullara/using-closures-method-handles-and-extension-methods-in-java-8-jsr-335-7c927f4dddde">Using Closures, Method Handles and Extension Methods in Java 8 (JSR-335)</a> was originally published in <a href="https://medium.com/spullara">spullara</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Testing out Percona and HandlerSocket with AvroBase]]></title>
            <link>https://medium.com/spullara/testing-out-percona-and-handlersocket-with-avrobase-d6b00fac0d0?source=rss----cb1f5a3bcba4---4</link>
            <guid isPermaLink="false">https://medium.com/p/d6b00fac0d0</guid>
            <dc:creator><![CDATA[Sam Pullara]]></dc:creator>
            <pubDate>Mon, 20 Dec 2010 21:34:00 GMT</pubDate>
            <atom:updated>2016-06-21T17:51:27.293Z</atom:updated>
            <content:encoded><![CDATA[<p>The great thing about the <a href="https://github.com/spullara/havrobase/blob/master/avrobase/src/main/java/avrobase/AvroBase.java">AvroBase</a> interface is that it can be used with many different datastores because of its relatively low requirements on those stores. <a href="https://github.com/ahiguti/HandlerSocket-Plugin-for-MySQL">HandlerSocket</a> 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 <a href="http://yoshinorimatsunobu.blogspot.com/2010/10/using-mysql-as-nosql-story-for.html">HandlerSocket benchmarks here</a>. <a href="http://www.percona.com/software/percona-server/">Percona Server</a> 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.<br><br><br>cd /Users/sam/Software/Percona-Server-5.1.53/<br>./configure — prefix=/Users/sam/usr<br>make &amp;&amp; make install<br><br>Similarly, download the HandlerSocket source via Git and then build it:<br><br>git clone <a href="https://github.com/ahiguti/HandlerSocket-Plugin-for-MySQL.git">https://github.com/ahiguti/HandlerSocket-Plugin-for-MySQL.git</a><br>cd HandlerSocket-Plugin-for-MySQL/<br>sh autogen.sh<br>./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<br>make &amp;&amp; make install<br><br>You then need to make some changes to the my.cnf file:<br><br>[mysqld]<br>user = sam<br>port = 3406<br>loose_handlersocket_port = 9998<br>loose_handlersocket_port_wr = 9999<br>loose_handlersocket_threads = 16<br>loose_handlersocket_threads_wr = 1<br><br>Start up mysql for the first time:<br><br>export PATH=~/usr/bin:$PATH<br>mysql_install_db<br>cd /Users/sam/usr ; /Users/sam/usr/bin/mysqld_safe &amp;<br><br>Then connect to mysql and install the plugin:<br><br>mysql -u root<br>install plugin handlersocket soname ‘handlersocket.so’;<br><br>For AvroBase I am using the native i/o Java client:<br><br>svn checkout <a href="http://hs4j.googlecode.com/svn/trunk/">http://hs4j.googlecode.com/svn/trunk/</a> hs4j<br>mvn install -Dmaven.test.skip=true<br><br>Haven’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’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.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d6b00fac0d0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/spullara/testing-out-percona-and-handlersocket-with-avrobase-d6b00fac0d0">Testing out Percona and HandlerSocket with AvroBase</a> was originally published in <a href="https://medium.com/spullara">spullara</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What does the Facebook security thing mean to users?]]></title>
            <link>https://medium.com/spullara/what-does-the-facebook-security-thing-mean-to-users-7f7e71ff96fb?source=rss----cb1f5a3bcba4---4</link>
            <guid isPermaLink="false">https://medium.com/p/7f7e71ff96fb</guid>
            <dc:creator><![CDATA[Sam Pullara]]></dc:creator>
            <pubDate>Tue, 19 Oct 2010 17:53:37 GMT</pubDate>
            <atom:updated>2016-06-21T17:51:03.869Z</atom:updated>
            <content:encoded><![CDATA[<p>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 ‘iframes’ 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.<br><br>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.</p><p>Here is what I can discover about myself using only my UID and publicly accessible URLs via the Facebook Open Graph API:</p><p>Name: Sam Pullara<br>First Name: Sam<br>Last Name: Pullara<br>Link: <a href="http://www.facebook.com/spullara">http://www.facebook.com/spullara</a><br>Gender: Male<br>Locale: en_US<br>Picture:</p><p>If you want to do the same and see what is available for you, start here <a href="https://graph.facebook.com/[your">https://graph.facebook.com/[your</a> uid]?metadata=1 and try each of the links in the connections subsection to see what is easily available.</p><p>Using web scraping, I can discover even more information about me:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/0*rp-b51JM3dVn_mUC.png" /></figure><p>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’t inadvertently transferred from their application partners to the application partner’s advertisers.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f7e71ff96fb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/spullara/what-does-the-facebook-security-thing-mean-to-users-7f7e71ff96fb">What does the Facebook security thing mean to users?</a> was originally published in <a href="https://medium.com/spullara">spullara</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HAvroBase: a searchable, evolvable entity store on top of HBase and Solr]]></title>
            <link>https://medium.com/spullara/havrobase-a-searchable-evolvable-entity-store-on-top-of-hbase-and-solr-d305f90a3eaa?source=rss----cb1f5a3bcba4---4</link>
            <guid isPermaLink="false">https://medium.com/p/d305f90a3eaa</guid>
            <dc:creator><![CDATA[Sam Pullara]]></dc:creator>
            <pubDate>Wed, 30 Jun 2010 19:55:44 GMT</pubDate>
            <atom:updated>2016-06-21T17:51:24.584Z</atom:updated>
            <content:encoded><![CDATA[<p>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’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’ve created what I think to be a novel solution to these requirements in the form of <a href="http://github.com/spullara/havrobase">HAvroBase</a>.</p><p>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’ve decided to use <a href="http://github.com/apache/avro">Avro</a>. Similar to <a href="http://code.google.com/p/protobuf/">Protocol Buffers</a> and <a href="http://incubator.apache.org/thrift/">Thrift</a>, 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.</p><p>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 <a href="http://hbase.apache.org/">HBase</a>, <a href="http://cassandra.apache.org/">Cassandra</a>, <a href="http://code.google.com/p/redis/">Redis</a>, <a href="https://wiki.basho.com/display/RIAK/Riak">Riak</a>, <a href="http://mysql.com/">MySQL</a>, <a href="http://www.northscale.com/products/membase_server.html">Membase</a>, <a href="http://www.terracotta.org/">Terracotta</a>, etc. I finally chose HBase for a few reasons that may not be that important to you. First I settled on a <a href="http://labs.google.com/papers/bigtable.html">BigTable</a> type choice based on the data model. That left HBase and Cassandra as contenders. There also a few things I think are advantages:</p><ul><li>multiple tables</li><li>better ordered key support</li><li>Zookeeper and HDFS were already in my solution</li><li>Hive and Hadoop support against the native data format</li><li>consistency</li><li>compare and set</li><li>atomic increment</li><li>versioning</li></ul><p>Cassandra definitely has its own advantages that didn’t out-weigh the other considerations including</p><ul><li>performance</li><li>simple deployment</li><li>always writable</li></ul><p>You might make different tradeoffs or even use both solutions for different problems. I’m also biased somewhat as I am sharing an office with <a href="http://cloudera.com/">Cloudera</a> and get top notch support at a moments notice.</p><p>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.</p><p>When it comes to text search you really don’t get better than <a href="http://lucene.apache.org/">Lucene</a> in open source and the features that <a href="http://wiki.apache.org/solr/FrontPage">Solr</a> builds on top of Lucene make it even better. I don’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 <a href="http://wiki.apache.org/solr/SolrCloud">Solr Cloud</a>. 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.</p><p>The last choice that I made was runtime configuration. There are a few solutions including <a href="http://www.springsource.org/">Spring</a>, <a href="http://code.google.com/p/google-guice/">Guice</a> 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.</p><p>The first thing that you need to do to use the system is to define an entity in Avro:<br>[gist id=484813]<br>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:<br>[gist id=484810]<br>That configuration can then be used to instantiate an instance of the HAB class that implements the connection to HBase like this:<br>[gist id= 484815]<br>You’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’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’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:<br>[gist id= 484816]<br>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’ll notice in the memcached implementation that only put/get/delete are implemented and it doesn’t support scan or search at all. I’ve considered breaking out that functionality into separate interfaces but haven’t done that yet.</p><p>If you are unhappy with the way the default Avro compiler generates code you can use my <a href="http://github.com/spullara/avrocompiler">templated Avro compiler</a> that lets you change the generated code. I have done that for my project to make them a little more developer friendly.</p><p>Things left to do:</p><ul><li>implement guarantees around indexing</li><li>optimize schema keys (use an abbrev table instead of a hex sha-256 key)</li><li>indexing nested fields and arrays in Solr</li></ul><p>I’m sure there are more things left undone but those are some of the more obvious issues.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d305f90a3eaa" width="1" height="1" alt=""><hr><p><a href="https://medium.com/spullara/havrobase-a-searchable-evolvable-entity-store-on-top-of-hbase-and-solr-d305f90a3eaa">HAvroBase: a searchable, evolvable entity store on top of HBase and Solr</a> was originally published in <a href="https://medium.com/spullara">spullara</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Static-typing is a powerful metadata database, exploit it!]]></title>
            <link>https://medium.com/spullara/static-typing-is-a-powerful-metadata-database-exploit-it-7d950c9b4960?source=rss----cb1f5a3bcba4---4</link>
            <guid isPermaLink="false">https://medium.com/p/7d950c9b4960</guid>
            <dc:creator><![CDATA[Sam Pullara]]></dc:creator>
            <pubDate>Thu, 17 Jun 2010 00:20:47 GMT</pubDate>
            <atom:updated>2016-06-21T17:51:11.875Z</atom:updated>
            <content:encoded><![CDATA[<p>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 — 90% of those times are when declaring a new Type — 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?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d950c9b4960" width="1" height="1" alt=""><hr><p><a href="https://medium.com/spullara/static-typing-is-a-powerful-metadata-database-exploit-it-7d950c9b4960">Static-typing is a powerful metadata database, exploit it!</a> was originally published in <a href="https://medium.com/spullara">spullara</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building the ideal web application template engine]]></title>
            <link>https://medium.com/spullara/building-the-ideal-web-application-template-engine-f0d5ae2218ec?source=rss----cb1f5a3bcba4---4</link>
            <guid isPermaLink="false">https://medium.com/p/f0d5ae2218ec</guid>
            <dc:creator><![CDATA[Sam Pullara]]></dc:creator>
            <pubDate>Wed, 16 Jun 2010 18:02:03 GMT</pubDate>
            <atom:updated>2016-06-21T17:50:56.373Z</atom:updated>
            <content:encoded><![CDATA[<p>A month and a half ago I had put out a call for what I was calling the ‘<a href="http://www.javarants.com/2010/05/03/the-ideal-web-application-templating-system/">ideal web application template engine</a>’ 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 <a href="http://mustache.github.com/">mustache</a> 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, <a href="http://github.com/spullara/mustache.java">mustache.java</a>. Though it claims to be ‘logic-less’ 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’s look at each of the requirements and how I ended up implementing them:</p><ul><li><em>Works well with HTML5/CSS3 progressive enhancement</em></li></ul><p>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 <a href="http://github.com/spullara/avrocompiler">project</a> 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.</p><ul><li><em>Allows mock data within the template that is replaced at runtime</em></li><li><em>Client-side version that leverages the mock data for shift-reload debugging</em></li></ul><p>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 <strong>handlebar</strong>, thanks for the name <a href="http://lukew.com/">Luke</a>) 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 <strong>handlebar</strong> in directory along with their mock data and just keep reloading the page to see the effect of changes they make.</p><ul><li><em>Composable components, not monolithic pages</em></li><li><em>Very little or no business logic in the templates</em></li></ul><p>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 <em>extends/block</em> system and may extend mustache to support it. Having to remember to include things like the header and footer on every page doesn’t seem necessary. As I said above, I think that mustache has the minimum reasonable logic.</p><ul><li><em>Concurrent evaluation possible</em></li></ul><p>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’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.</p><p>So how easy is using the template system? I think I can answer that question by looking at the relevant portions of the <a href="http://github.com/spullara/mustache.java/blob/master/handlebar/src/main/java/com/sampullara/mustache/Handlebar.java">implementation of <strong>handlebar</strong></a><strong>:</strong></p><pre>final MustacheCompiler mc = new MustacheCompiler(new File(&quot;.&quot;));<br>....<br>Mustache mustache = mc.compile(new BufferedReader(new FileReader(filename)));<br>FutureWriter fw = new FutureWriter(res.getWriter());<br>File file = new File(mocks, base + &quot;.json&quot;);<br>if (file.exists()) {<br>  BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));<br>  JsonParser parser = jf.createJsonParser(bis);<br>  JsonNode json = parser.readValueAsTree();<br>  mustache.execute(fw, new Scope(json));<br>} else {<br>  mustache.execute(fw, new Scope());<br>}<br>fw.flush();</pre><p>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.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0d5ae2218ec" width="1" height="1" alt=""><hr><p><a href="https://medium.com/spullara/building-the-ideal-web-application-template-engine-f0d5ae2218ec">Building the ideal web application template engine</a> was originally published in <a href="https://medium.com/spullara">spullara</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>