<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>Draconian Overlord</title>
 <link href="http://draconianoverlord.com/atom.xml" rel="self"/>
 <link href="http://draconianoverlord.com/"/>
 <updated>2011-12-29T10:26:53-08:00</updated>
 <id>http://draconianoverlord.com/</id>
 <author>
   <name>Stephen Haberman</name>
   <email>stephen@exigencecorp.com</email>
 </author>

 
 <entry>
   <title>todomvc in Tessell</title>
   <link href="http://draconianoverlord.com/2011/12/10/todomvc-in-gwt-mpv.html"/>
   <updated>2011-12-10T00:00:00-08:00</updated>
   <id>http://draconianoverlord.com/2011/12/10/todomvc-in-gwt-mpv</id>
   <content type="html">&lt;h1 id='todomvc_in_tessell'&gt;todomvc in Tessell&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Update 2011/12/29:&lt;/strong&gt; This post was originally about the gwt-mpv framework, which has since been rechristened Tessell, see &lt;a href='http://www.tessell.org'&gt;tessell.org&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Recently I came across &lt;a href='https://github.com/addyosmani/todomvc'&gt;todomvc&lt;/a&gt; on HN, a nifty sample application that shows the same &amp;#8220;todo app&amp;#8221; functionality implemented in a number of different JavaScript UI frameworks.&lt;/p&gt;

&lt;p&gt;It is a great way to compare JS frameworks, as &lt;a href='http://jgn.me/'&gt;Jérôme Gravel-Niquet&lt;/a&gt;&amp;#8217;s initial todo application has a great balance of features to lightly tax a framework but not take forever to implement. Kudos to &lt;a href='http://addyosmani.com/'&gt;Addy Osmani&lt;/a&gt; for realizing this and gathering together the various implementations.&lt;/p&gt;

&lt;p&gt;As a &lt;a href='http://code.google.com/webtoolkit/'&gt;GWT&lt;/a&gt; user, I have a slightly different viewpoint on JavaScript application development (eh, it&amp;#8217;s just assembly&amp;#8230;er, &lt;a href='http://blog.izs.me/post/10213512387/javascript-is-not-web-assembly'&gt;C&lt;/a&gt;), but I nonetheless agree with these JS frameworks that intelligently structuring AJAX applications is important.&lt;/p&gt;

&lt;p&gt;In the GWT world, Model View Presenter has been the hot way to do this &lt;a href='http://www.google.com/events/io/2009/sessions/GoogleWebToolkitBestPractices.html'&gt;since 2009&lt;/a&gt;, and I&amp;#8217;ve obliged by hacking on &lt;a href='http://www.tessell.org'&gt;Tessell&lt;/a&gt;, an MVP framework, for various apps we&amp;#8217;re writing at &lt;a href='http://www.bizo.com'&gt;Bizo&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Tessell shares a lot of the same ideas and goals as the todomvc JS frameworks, namely:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;rich, event-driven models&lt;/li&gt;

&lt;li&gt;data-binding models to views declaratively&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So I thought it&amp;#8217;d be fun to port todomvc to Tessell as yet another implementation to compare and contrast with the others.&lt;/p&gt;

&lt;p&gt;In doing so, and doing this writeup, I have two goals:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Show GWT developers that Tessell&amp;#8217;s code generation-driven MVP leads to minimal boilerplate&lt;/li&gt;

&lt;li&gt;Show JavaScript developers that GWT can be a competent choice for rich-client development&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id='demo_and_code'&gt;Demo and Code&lt;/h2&gt;

&lt;p&gt;Although it looks just like the other implementations, the Tessell port&amp;#8217;s code is currently hosted here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='http://todomvc.tessell.org/TodoMvc.html'&gt;http://todomvc.tessell.org/TodoMvc.html&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And if you want to follow along in the source while reading this post, the source is on github:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='https://github.com/stephenh/todomvc-tessell'&gt;https://github.com/stephenh/todomvc-tessell&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id='project_layout'&gt;Project Layout&lt;/h2&gt;

&lt;p&gt;The Tessell todo implementation uses an idiomatic Java/GWT layout. The primary packages are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='https://github.com/stephenh/todomvc-tessell/tree/master/src/main/java/org/tessell/todomvc/client/app'&gt;org.tessell.todomvc.client.app&lt;/a&gt; for presenters,&lt;/li&gt;

&lt;li&gt;&lt;a href='https://github.com/stephenh/todomvc-tessell/tree/master/src/main/java/org/tessell/todomvc/client/model'&gt;org.tessell.todovmc.client.model&lt;/a&gt; for models, and&lt;/li&gt;

&lt;li&gt;&lt;a href='https://github.com/stephenh/todomvc-tessell/tree/master/src/main/java/org/tessell/todomvc/client/views'&gt;org.tessell.todomvc.client.views&lt;/a&gt; for view templates.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For a small application like the todo app, having multiple files is likely harder to follow than the JS implementations, which typically have just one JS file + CSS file. However, this approach works best for GWT and means you already have a good setup if your project grows larger.&lt;/p&gt;

&lt;h2 id='models'&gt;Models&lt;/h2&gt;

&lt;p&gt;To start with, all rich UI frameworks typically define models for the domain objects involved. In Tessell, this is done simply with a &lt;a href='https://github.com/stephenh/todomvc-tessell/blob/master/src/main/java/org/tessell/todomvc/client/model/Todo.java'&gt;Todo&lt;/a&gt; class:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public class Todo {
  public final BooleanProperty done = booleanProperty(&amp;quot;done&amp;quot;, false);
  public final StringProperty name = stringProperty(&amp;quot;name&amp;quot;);

  public Todo(String name) {
    this.name.set(name);
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Instead of traditional Java fields + getters/setters, Tessell models have property objects. Property objects fire events when they change, which allows the rest of the application to react accordingly.&lt;/p&gt;

&lt;p&gt;You can also have lists of model objects, which fire events when items are added/removed to the list, e.g. in &lt;a href='https://github.com/stephenh/todomvc-tessell/blob/master/src/main/java/org/tessell/todomvc/client/model/AppState.java'&gt;AppState&lt;/a&gt;:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public class AppState {
  public final ListProperty&amp;lt;Todo&amp;gt; allTodos = listProperty(&amp;quot;allTodos&amp;quot;);
  public final ListProperty&amp;lt;Todo&amp;gt; doneTodos = listProperty(&amp;quot;doneTodos&amp;quot;);
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;As with the JS frameworks, Tessell also supports derived properties, e.g. in &lt;a href='https://github.com/stephenh/todomvc-tessell/blob/master/src/main/java/org/tessell/todomvc/client/model/AppState.java#L18'&gt;AppState&lt;/a&gt;:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;numberLeft = integerProperty(new DerivedValue&amp;lt;Integer&amp;gt;() {
  public Integer get() {
    return allTodos.get().size() - doneTodos.get().size();
  }
});&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Tessell models can also do validation of properties (required, length checks, etc.), but that wasn&amp;#8217;t needed for the todo application.&lt;/p&gt;

&lt;h2 id='views'&gt;Views&lt;/h2&gt;

&lt;p&gt;Tessell&amp;#8217;s views build on GWT&amp;#8217;s &lt;a href='http://code.google.com/webtoolkit/doc/latest/DevGuideUiBinder.html'&gt;UiBinder&lt;/a&gt;, which uses HTML-like XML to layout your application. The main distinguishing feature of UiBinder is that it lacks any logic (either behavior or data binding) in the view&amp;#8211;there are no &lt;code&gt;&amp;lt;% if (...) %&amp;gt;&lt;/code&gt; tags or &lt;code&gt;data-bind=&amp;quot;...&amp;quot;&lt;/code&gt; attributes.&lt;/p&gt;

&lt;p&gt;For example, &lt;a href='https://github.com/stephenh/todomvc-tessell/blob/master/src/main/java/org/tessell/todomvc/client/views/ListTodoItem.ui.xml#L76'&gt;ListTodoItem.ui.xml&lt;/a&gt;:&lt;/p&gt;

&lt;pre class='brush:html'&gt;&lt;code&gt;&amp;lt;gwt:HTMLPanel ui:field=&amp;quot;li&amp;quot; tag=&amp;quot;li&amp;quot; styleName=&amp;quot;{style.todo}&amp;quot;&amp;gt;
  &amp;lt;div ui:field=&amp;quot;displayPanel&amp;quot;&amp;gt;
    &amp;lt;gwt:CheckBox ui:field=&amp;quot;checkBox&amp;quot; styleName=&amp;quot;{style.check}&amp;quot; /&amp;gt;
    &amp;lt;gwt:Label ui:field=&amp;quot;content&amp;quot; styleName=&amp;quot;{style.todo-content}&amp;quot; /&amp;gt;
    &amp;lt;gwt:Anchor ui:field=&amp;quot;destroyAnchor&amp;quot; styleName=&amp;quot;{style.todo-destroy}&amp;quot; /&amp;gt;
  &amp;lt;/div&amp;gt;
  &amp;lt;div ui:field=&amp;quot;editPanel&amp;quot;&amp;gt;
    &amp;lt;gwt:TextBox ui:field=&amp;quot;editBox&amp;quot; styleName=&amp;quot;{style.editBox}&amp;quot; /&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/gwt:HTMLPanel&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;(If you&amp;#8217;re not familiar with the todo app, it alternates between the &lt;code&gt;displayPanel&lt;/code&gt; when the user is viewing a todo and the &lt;code&gt;editPanel&lt;/code&gt; when a user double-clicks to edit a todo.)&lt;/p&gt;

&lt;p&gt;Some GWT specifics aside (widgets, etc.), this is basically HTML. A few things to note:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The &lt;code&gt;ui:field&lt;/code&gt; attributes expose their annotated elements/widgets to your presentation logic.&lt;/p&gt;

&lt;p&gt;(GWT eschews &lt;code&gt;id&lt;/code&gt; attributes because a template may be included multiple times in the DOM and, ids being global, could collide.)&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;&lt;code&gt;{style.todo}&lt;/code&gt; is a reference to the &lt;code&gt;.todo&lt;/code&gt; CSS class defined inline within the &lt;code&gt;ui.xml&lt;/code&gt; file. This means:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;You have a good place to put per-view CSS (it all ends up bundled into one download in the end), which to me is a much saner alternative than the gigantic CSS files I usually see.&lt;/p&gt;

&lt;p&gt;It&amp;#8217;s a locality principle: if CSS is used only once, it should be as close to that usage point, and none other, as possible.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;The compiler checks all CSS class references&amp;#8211;if &lt;code&gt;.todo&lt;/code&gt; was renamed, you get a compile error.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;The compiler ensures all CSS identifiers are globally unique&amp;#8211;if you use &lt;code&gt;.name&lt;/code&gt; in one &lt;code&gt;ui.xml&lt;/code&gt; or &lt;code&gt;css&lt;/code&gt; file, you don&amp;#8217;t have to worry about it colliding with another &lt;code&gt;.name&lt;/code&gt; in another &lt;code&gt;ui.xml&lt;/code&gt; or &lt;code&gt;css&lt;/code&gt; file.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The main feature that Tessell provides for views is generating derivative artifacts from the &lt;code&gt;ui.xml&lt;/code&gt; files. In the MVP pattern, presenters code against an abstract &lt;code&gt;IsXxxView&lt;/code&gt; interface, and then UiBinder needs a &lt;code&gt;XxxViewImpl&lt;/code&gt; Java class, but Tessell can derive both of these from the &lt;code&gt;ui.xml&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;For an example, the generated &lt;code&gt;IsListTodoItemView&lt;/code&gt; looks like:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;interface IsListTodoItemView extends IsWidget {
  IsHTMLPanel li();
  IsElement displayPanel();
  IsCheckBox checkBox();
  IsLabel content();
  IsAnchor destroyAnchor();
  IsElement editPanel();
  IsTextBox editBox();
  ListTodoItemStyle style();
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Where each &lt;code&gt;ui:field&lt;/code&gt;-annotated element/widget in the &lt;code&gt;ui.xml&lt;/code&gt; file is exposed, but only as an abstract &lt;code&gt;IsXxx&lt;/code&gt; interface which themselves can be substituted for fake DOM-less versions at test time. We&amp;#8217;ll cover this more later when talking about testing.&lt;/p&gt;

&lt;h2 id='presenters'&gt;Presenters&lt;/h2&gt;

&lt;p&gt;Presenters are the glue between your model and view. Ideally presenters simply bind the model and view together; but, if needed, they can also implement more complex logic.&lt;/p&gt;

&lt;p&gt;An extremely simple presenter is &lt;a href='https://github.com/stephenh/todomvc-tessell/blob/master/src/main/java/org/tessell/todomvc/client/app/AppPresenter.java'&gt;AppPresenter&lt;/a&gt;, which just assembles the three separate panels of the application:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public class AppPresenter extends BasicPresenter&amp;lt;IsAppView&amp;gt; {

  private final AppState state = new AppState();
  private final CreateTodoPresenter createTodo = addPresenter(new CreateTodoPresenter(state.allTodos));
  private final StatsTodoPresenter statsTodo = addPresenter(new StatsTodoPresenter(state));
  private final ListTodoPresenter listTodos = addPresenter(new ListTodoPresenter(state));

  public AppPresenter() {
    super(newAppView());
  }

  @Override
  public void onBind() {
    super.onBind();
    view.createPanel().add(createTodo.getView());
    view.listPanel().add(listTodos.getView());
    view.statsPanel().add(statsTodo.getView());
    view.creditsPanel().add(newCreditsView());
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Obviously usually presenters do a bit more; in the todo app, the most busy presenter is the &lt;a href='https://github.com/stephenh/todomvc-tessell/blob/master/src/main/java/org/tessell/todomvc/client/app/ListTodoItemPresenter.java'&gt;ListTodoItemPresenter&lt;/a&gt;, which, amongst other things, binds the &lt;code&gt;todo.name&lt;/code&gt; property to the view:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;binder.bind(todo.name).to(view.editBox());
binder.bind(todo.name).toTextOf(view.content());
binder.bind(todo.done).to(view.checkBox());&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;These three one-liners setup two-way data binding between the model and the view. If &lt;code&gt;todo.name&lt;/code&gt; changes, both &lt;code&gt;view.editBox()&lt;/code&gt; and &lt;code&gt;view.content()&lt;/code&gt; will be updated with the new name. If the user enters a new name into &lt;code&gt;view.editBox()&lt;/code&gt;, it will flow back into &lt;code&gt;todo.name&lt;/code&gt; (and subsequently into &lt;code&gt;view.content()&lt;/code&gt;)).&lt;/p&gt;

&lt;p&gt;Besides just binding fields, the binder DSL can also be used for performing other common view actions on model change, such as showing/hiding or setting/removing CSS classes:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;binder.when(editing).is(true).show(view.editPanel());
binder.when(editing).is(true).hide(view.displayPanel());
binder.when(editing).is(true).set(s.editing()).on(view.li());&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Finally, looking at &lt;a href='https://github.com/stephenh/todomvc-tessell/blob/master/src/main/java/org/tessell/todomvc/client/app/ListTodoPresenter.java'&gt;ListTodoPresenter&lt;/a&gt;, keeping the view&amp;#8217;s &lt;code&gt;ul&lt;/code&gt; list of one-&lt;code&gt;li&lt;/code&gt;-per-todo in sync with the &lt;code&gt;allTodos&lt;/code&gt; list model can also be done with binding:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;binder.bind(state.allTodos).to(this, view.ul(), new ListPresenterFactory&amp;lt;Todo&amp;gt;() {
  public Presenter create(Todo todo) {
    return new ListTodoItemPresenter(state, todo);
  }
});&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Hopefully you can see that, besides view boilerplate reduction, rich models and a fluent binding DSL are the other main strengths Tessell brings to the table to succinctly, declaratively wire together your application&amp;#8217;s behavior.&lt;/p&gt;

&lt;h2 id='testing'&gt;Testing&lt;/h2&gt;

&lt;p&gt;Finally, the reason for the extra abstraction of the Model View Presenter architecture, it is now ridiculously easy to test your model and presenter logic without the DOM.&lt;/p&gt;

&lt;p&gt;For the todomvc port, this means we can test the &amp;#8220;add a new todo&amp;#8221; functionality by:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Setting up a test list model&lt;/li&gt;

&lt;li&gt;Instantiating the presenter to test&lt;/li&gt;

&lt;li&gt;Retrieving the stub (no DOM) view implementation (which is generated by Tessell from the &lt;code&gt;ui.xml&lt;/code&gt; template file) that has fake versions of each of our components&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So a test starts out looking like &lt;a href='https://github.com/stephenh/todomvc-tessell/blob/master/src/test/java/org/tessell/todomvc/client/app/CreateTodoPresenterTest.java'&gt;CreateTodoPresenterTest&lt;/a&gt;:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public class CreateTodoPresenterTest extends AbstractPresenterTest {
  final ListProperty&amp;lt;Todo&amp;gt; todos = listProperty(&amp;quot;todos&amp;quot;);
  final CreateTodoPresenter p = bind(new CreateTodoPresenter(todos));
  final StubCreateTodoView v = (StubCreateTodoView) p.getView();&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And then goes right into testing features:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;@Test
public void enterOnSomeContentCreatesTask() {
  // model starts out empty
  assertThat(todos.get().size(), is(0));
  // user enters a new task, hits enter
  v.newTodo().type(&amp;quot;new task&amp;quot;);
  v.newTodo().keyDown(KeyCodes.KEY_ENTER);
  // model now has a new task with the right name
  assertThat(todos.get().size(), is(1));
  assertThat(todos.get().get(0).getName(), is(&amp;quot;new task&amp;quot;));
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The &lt;code&gt;newTodo().type(...)&lt;/code&gt; method emulates a user typing into the &amp;#8220;new todo&amp;#8221; text box. &lt;code&gt;newTodo().keyDown(...)&lt;/code&gt; is the enter key being pressed. And then we can assert our model was changed, and the new model object created with the right name.&lt;/p&gt;

&lt;p&gt;The Tessell port has ~30 presenter tests like this one. They all run in 1/10th of a second, no selenium, no browser, etc.&lt;/p&gt;

&lt;p&gt;To me, this means its now actually feasible to develop your UI logic in a TDD fashion. Which is a huge win.&lt;/p&gt;

&lt;p&gt;Okay, now the caveats:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Yes, this is a lossy abstraction. It doesn&amp;#8217;t pretend to emulate cross-browser differences. It doesn&amp;#8217;t realize that setting &amp;#8220;display: none&amp;#8221; on a parent makes the children invisible. In practice, that doesn&amp;#8217;t matter for these sorts of tests.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Yes, this can&amp;#8217;t test DOM-heavy logic. That logic should ideally be encapsulated within a component. Then you test the component with &lt;code&gt;GWTTestCase&lt;/code&gt; (which has a DOM) or selenium or whatever, but then let your presenter tests be DOM-less by using a fake version of the component assuming the real one will just work.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Yes, you still need integration tests.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So, it&amp;#8217;s not perfect. But if you had to choose:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;500 unit tests + 50 selenium tests, or&lt;/li&gt;

&lt;li&gt;550 selenium tests&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I think it&amp;#8217;s a fair assertion you&amp;#8217;re much better off with the former.&lt;/p&gt;

&lt;h2 id='comparison_with_js_frameworks'&gt;Comparison with JS Frameworks&lt;/h2&gt;

&lt;p&gt;Reading through the various JS implementations of the todo app, and Tessell&amp;#8217;s implementation, it&amp;#8217;s encouraging to see that they are all trying to do basically the same thing: use event-driven models and views to wire together a rich client.&lt;/p&gt;

&lt;p&gt;I think this approach of declaratively setting up view/model bindings is the key to doing non-trivial AJAX applications without loosing your functionality (or sanity, whichever is less important) to growing balls of spaghetti code. Changing the model should lead to the view updates just working.&lt;/p&gt;

&lt;p&gt;That being said, each framework does things slightly differently. Here I&amp;#8217;ll briefly cover how GWT/Tessell is different.&lt;/p&gt;

&lt;h3 id='templates'&gt;Templates&lt;/h3&gt;

&lt;p&gt;GWT&amp;#8217;s &lt;code&gt;ui.xml&lt;/code&gt; files seem like the most static/most dumb view templates. Whether this is good or bad is personal preference, although I like it because I think it forces as much view logic as possible into the presenter.&lt;/p&gt;

&lt;p&gt;Some JS frameworks, like backbone, use more server-side-style templates:&lt;/p&gt;

&lt;pre class='brush:html'&gt;&lt;code&gt;&amp;lt;script type=&amp;quot;text/template&amp;quot; id=&amp;quot;item-template&amp;quot;&amp;gt;
  &amp;lt;div class=&amp;quot;todo &amp;lt;%= done ? &amp;#39;done&amp;#39; : &amp;#39;&amp;#39; %&amp;gt;&amp;quot;&amp;gt;
    &amp;lt;div class=&amp;quot;display&amp;quot;&amp;gt;
      &amp;lt;input class=&amp;quot;check&amp;quot; type=&amp;quot;checkbox&amp;quot; &amp;lt;%= done ? &amp;#39;checked=&amp;quot;checked&amp;quot;&amp;#39; : &amp;#39;&amp;#39; %&amp;gt; /&amp;gt;
      &amp;lt;div class=&amp;quot;todo-content&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;
      &amp;lt;span class=&amp;quot;todo-destroy&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div class=&amp;quot;edit&amp;quot;&amp;gt;
      &amp;lt;input class=&amp;quot;todo-input&amp;quot; type=&amp;quot;text&amp;quot; value=&amp;quot;&amp;quot; /&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Where others use data-binding attributes, like knockout:&lt;/p&gt;

&lt;pre class='brush:html'&gt;&lt;code&gt;&amp;lt;script id=&amp;quot;todoitemtemplate&amp;quot; type=&amp;quot;text/html&amp;quot;&amp;gt;
  &amp;lt;li data-bind=&amp;quot;css: {editing: editing}&amp;quot;&amp;gt;
    &amp;lt;div data-bind=&amp;quot;attr: { class : done() ? &amp;#39;todo done&amp;#39; : &amp;#39;todo&amp;#39;}&amp;quot;&amp;gt;
      &amp;lt;div class=&amp;quot;display&amp;quot;&amp;gt;
        &amp;lt;input class=&amp;quot;check&amp;quot; type=&amp;quot;checkbox&amp;quot; data-bind=&amp;quot;checked: done&amp;quot; /&amp;gt;
        &amp;lt;div class=&amp;quot;todo-content&amp;quot; data-bind=&amp;quot;text: content, click: edit&amp;quot; style=&amp;quot;cursor: pointer;&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;
        &amp;lt;span class=&amp;quot;todo-destroy&amp;quot; data-bind=&amp;quot;click: viewModel.remove&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;div class=&amp;quot;edit&amp;quot;&amp;gt;
        &amp;lt;input class=&amp;quot;todo-input&amp;quot; type=&amp;quot;text&amp;quot; data-bind=&amp;quot;value: content, event: { keyup: editkeyup, blur: stopEditing }&amp;quot;/&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/li&amp;gt;
&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;These approaches typically require rendering the DOM elements to test the view logic. I generally think this is a bad thing, although I was surprised to learn that, if you avoid the traditional Selenium/etc., approaches, in-browser DOM testing can be &lt;a href='http://tinnedfruit.com/2011/04/26/testing-backbone-apps-with-jasmine-sinon-3.html'&gt;quite fast&lt;/a&gt; these days.&lt;/p&gt;

&lt;p&gt;Also with templates, in GWT you rarely re-render parts of the page to show changes, instead you just mutate the existing DOM (&amp;#8230;unless using GWT&amp;#8217;s Cell widgets, which are for bulk display for tables/lists, but are exceptions). Some JS frameworks re-render, some don&amp;#8217;t, but in general I&amp;#8217;m a fan of not re-rendering.&lt;/p&gt;

&lt;p&gt;Avoiding re-rending is, in my opinion, more amenable to a rich, component-based UI because then your components (which have state) aren&amp;#8217;t having their underlying DOM elements constantly swept out from under them.&lt;/p&gt;

&lt;p&gt;This may not be an issue when re-rendering tiny, leaf parts of the DOM, but as you work your way up in the DOM of a complex app, I think it would become harder to remember all the state needed to faithfully re-render things from scratch (like the checked state in the above backbone example).&lt;/p&gt;

&lt;p&gt;I can see where the sentiment of &amp;#8220;eh, just re-render&amp;#8221; comes from. Having been a server-side web developer, I certainly miss the simplicity of the &amp;#8220;each response is a clean slate&amp;#8221; model. And re-rendering entire parts of the page certainly worked well for Rails, albeit it was still doing rendering on the server-side. However, I don&amp;#8217;t think it is as good of a conceptual fit on a stateful client.&lt;/p&gt;

&lt;h3 id='no_selectors'&gt;No Selectors&lt;/h3&gt;

&lt;p&gt;In GWT, you typically already have references to the DOM objects you want to mutate (albeit usually encapsulated by widgets), so you rarely, if ever, need selectors.&lt;/p&gt;

&lt;p&gt;The is different than most of the JS frameworks. For example, in the backbone implementation, to update a list item&amp;#8217;s text when it changes, the code uses a selector to reach out and grab the text box:&lt;/p&gt;

&lt;pre class='brush:jscript'&gt;&lt;code&gt;this.$(&amp;#39;.todo-content&amp;#39;).text(content);&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Where as in the &lt;a href='https://github.com/stephenh/todomvc-tessell/blob/master/src/main/java/org/tessell/todomvc/client/app/ListTodoItemPresenter.java#L66'&gt;ListTodoItemPresenter&lt;/a&gt;, the view kept a reference to the DOM element while building itself (done by UiBinder), so now we can just call it directly:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;view.content().setText(view.editBox().getText());&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;(The &lt;code&gt;content()&lt;/code&gt; method is just a getter than returns the view&amp;#8217;s &lt;code&gt;content&lt;/code&gt; field, which is a GWT Label component, which just wraps a DOM &lt;code&gt;div&lt;/code&gt; tag.)&lt;/p&gt;

&lt;p&gt;Several of the JS frameworks also like to use selectors for event handling, again backbone:&lt;/p&gt;

&lt;pre class='brush:jscript'&gt;&lt;code&gt;events: {
  &amp;quot;click .check&amp;quot;              : &amp;quot;toggleDone&amp;quot;,
  &amp;quot;dblclick div.todo-content&amp;quot; : &amp;quot;edit&amp;quot;,
  &amp;quot;click span.todo-destroy&amp;quot;   : &amp;quot;clear&amp;quot;,
  &amp;quot;keypress .todo-input&amp;quot;      : &amp;quot;updateOnEnter&amp;quot;
},&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Where as GWT typically uses old-school anonymous inner classes:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;view.newTodo().addKeyDownHandler(new KeyDownHandler() {
  public void onKeyDown(KeyDownEvent event) {
    // ...
  }
});&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Although if you&amp;#8217;re just updating a model, this can be cleaned up by using the binder DSL:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;binder.bind(done).to(view.checkBox());&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Even though anonymous inner classes are not the most awesome thing ever, avoiding selectors has a few up-shots:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Your code more exactly denotes the elements it will change.&lt;/p&gt;

&lt;p&gt;This is a lot like dynamic vs. static typing; selectors are dynamic, deferring the binding of the selector to underlying elements until execution time, while GWT&amp;#8217;s known-references approach has a stronger assertion about which elements it will change.&lt;/p&gt;

&lt;p&gt;And so if you refactor the HTML in your &lt;code&gt;ui.xml&lt;/code&gt; file, your view interface changes, and any presenter logic that was depending on it may now break, vs. the magic selector string just silently not matching.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Your application doesn&amp;#8217;t have to worry about selectors from various components overlapping each other.&lt;/p&gt;

&lt;p&gt;Naive DOM selectors will select against the global DOM, which in a large, complex application is less-than-ideal. Better selectors will start with the component&amp;#8217;s subtree of the DOM, and even better selectors will not continue searching within the component&amp;#8217;s nested children components.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Testing is easier because you don&amp;#8217;t need a fake DOM to run the selectors against. More on testing below, but if your code mutates explicit references, it&amp;#8217;s easier for tests to fake these references out at test time.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Personally, I think selectors are leftover baggage from the Web 1.0 days. When people first started doing AJAX, 95%+ of the page was rendered server-side, so of course you don&amp;#8217;t have JavaScript references to the things you want to change, the elements all came down in one big string of HTML. So selectors were a great way to reach back into a DOM you didn&amp;#8217;t create and get at them.&lt;/p&gt;

&lt;p&gt;However, for full-page AJAX applications, when 95%+ of the page is rendered client-side, the very act of rendering provides the perfect opportunity to grab explicit references to the DOM objects as they are created and hold on to them within your application logic (in widgets, components, etc.). In my experience, this negates any need for selectors.&lt;/p&gt;

&lt;h2 id='disclaimers'&gt;Disclaimers&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Per my earlier link to Ray Ryan&amp;#8217;s 2009 Google I/O talk, I can&amp;#8217;t take credit for the DOM-less testing approach. Tessell, and several other frameworks within the GWT sphere, are just running with a great idea.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;In the todo application, I used a global &lt;a href='https://github.com/stephenh/todomvc-tessell/blob/master/src/main/java/org/tessell/todomvc/client/model/AppState.java'&gt;AppState&lt;/a&gt; class to share the &lt;code&gt;ListProperty&lt;/code&gt;s across presenters. Some GWT developers would probably lobby for even more decoupling by passing messages on an &lt;code&gt;EventBus&lt;/code&gt;, but that seemed like overkill for this app.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;The original CSS was in one massive file, and I may have butchered it when moving it into each component. It looks fine in Chrome, but YMMV.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Yes, Java isn&amp;#8217;t cool anymore, but &lt;a href='http://scalagwt.github.com/'&gt;scala-gwt&lt;/a&gt; will make everything more awesome and terse when it ships.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;</content>
 </entry>
 
 <entry>
   <title>Sane AJAX Testing in Selenium</title>
   <link href="http://draconianoverlord.com/2011/10/14/sane-selenium-testing.html"/>
   <updated>2011-10-14T00:00:00-07:00</updated>
   <id>http://draconianoverlord.com/2011/10/14/sane-selenium-testing</id>
   <content type="html">&lt;h1 id='sane_ajax_testing_in_selenium'&gt;Sane AJAX Testing in Selenium&lt;/h1&gt;

&lt;p&gt;Let&amp;#8217;s cut to the chase: testing AJAX applications can suck.&lt;/p&gt;

&lt;p&gt;Selenium is great for Web 1.0 applications, which involve a page load after each significant user action. Selenium knows to block until the page is done loading, and so the page load provides an implicit &amp;#8220;wait until crap is done&amp;#8221; barrier to keep your test from getting ahead of the browser.&lt;/p&gt;

&lt;p&gt;But that goes away in AJAX applications&amp;#8211;no page load. There are a variety of ways to compensate, most of which are what I call pre-assertion waiting&amp;#8211;before asserting &amp;#8220;did X happen&amp;#8221; poll for a little bit to ensure &amp;#8220;X&amp;#8221; is there. E.g.:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;ajaxSubmit.click();
waitForErrorToShowUp();
assertErrorIs(...);&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In my experience, pre-assertion waiting in tests is not ideal. They&amp;#8217;re verbose, often fickle, and at a higher risk of rotting when the application is refactored (&amp;#8220;Is this wait really needed? Better leave it in, just in case.&amp;#8221;).&lt;/p&gt;

&lt;p&gt;Instead, I think a good goal for functional UI tests is to &lt;strong&gt;never have explicit wait lines&lt;/strong&gt; in your test methods. If you can pull this off, I think the resulting tests will be more readable, more reliable, and more resilient to change.&lt;/p&gt;

&lt;p&gt;To accomplish this, I&amp;#8217;ve been using two tricks that, in tandem, work really well:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Reintroduce the concept of &amp;#8220;page loading&amp;#8221;&lt;/li&gt;

&lt;li&gt;Use post-action waiting instead of pre-assertion waiting&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And also a heavy dose of &lt;a href='http://code.google.com/p/selenium/wiki/PageObjects'&gt;Page Objects&lt;/a&gt; abstraction.&lt;/p&gt;

&lt;p&gt;So, let&amp;#8217;s see what this looks like.&lt;/p&gt;

&lt;h2 id='reintroduce_page_loading'&gt;Reintroduce &amp;#8220;page loading&amp;#8221;&lt;/h2&gt;

&lt;p&gt;First: reintroduce page loading. Not real page loading, obviously. But what was Web 1.0 page loading useful for? Knowing when the browser is waiting on the server. AJAX calls are the same thing&amp;#8211;talking to the server. We just need to make it explicit and visible to Selenium.&lt;/p&gt;

&lt;p&gt;There are a variety of ways of doing this, but you basically need a choke point in your application where all AJAX requests go through. Then:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Before any AJAX request goes out, increment an &lt;code&gt;outstanding&lt;/code&gt; variable&lt;/li&gt;

&lt;li&gt;Put the value of &lt;code&gt;outstanding&lt;/code&gt; into a hidden &lt;code&gt;div&lt;/code&gt; tag&lt;/li&gt;

&lt;li&gt;When the AJAX response comes back, decrement &lt;code&gt;outstanding&lt;/code&gt; variable&lt;/li&gt;

&lt;li&gt;Again put the value of &lt;code&gt;outstanding&lt;/code&gt; into the hidden &lt;code&gt;div&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now Selenium has the ability to see the application&amp;#8217;s &amp;#8220;loading&amp;#8221; state:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If &lt;code&gt;outstanding.innerText == &amp;quot;0&amp;quot;&lt;/code&gt;, all things are good, continue the test&lt;/li&gt;

&lt;li&gt;If &lt;code&gt;outstanding.innerText != &amp;quot;0&amp;quot;&lt;/code&gt;, the application is waiting, block the test&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I don&amp;#8217;t have any JavaScript code to show how this works, as I do all my client-side programming in GWT, so use a &lt;a href='http://code.google.com/p/gwt-dispatch/'&gt;gwt-dispatch&lt;/a&gt;-style approach that broadcasts AJAX events on an &lt;code&gt;EventBus&lt;/code&gt;, which then &lt;a href='https://github.com/stephenh/tessell/blob/master/user/src/main/java/org/tessell/util/OutstandingWatcher.java'&gt;OutstandingWatcher&lt;/a&gt; listens for and maintains the &lt;code&gt;outstanding&lt;/code&gt; div appropriately.&lt;/p&gt;

&lt;p&gt;For JQuery/etc., something in &lt;a href='http://api.jquery.com/extending-ajax/'&gt;Extending AJAX&lt;/a&gt; would probably work. It&amp;#8217;s probably 10-20 lines of code.&lt;/p&gt;

&lt;p&gt;Anyway, once you have this in place, you&amp;#8217;ve basically got page loads back&amp;#8211;any time an AJAX request is in-flight, Selenium can know about it by watching if &lt;code&gt;outstanding != 0&lt;/code&gt;. E.g. with Selenium&amp;#8217;s new &lt;code&gt;ExpectedConditions&lt;/code&gt; API, it might look like:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;/** Waits until all async calls are complete. */
public static ExpectedCondition&amp;lt;Boolean&amp;gt; outstanding() {
  return new ExpectedCondition&amp;lt;Boolean&amp;gt;() {
    public Boolean apply(final WebDriver from) {
      final String outstanding = from
        .findElement(By.id(&amp;quot;outstanding&amp;quot;))
        .getText();
      return &amp;quot;0&amp;quot;.equals(outstanding);
    }
  };
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So, then you could use this in a test like:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;ajaxSubmit.click();
WebDriverUtil.waitFor(outstanding());
assertErrorIs(...);&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id='postaction_waiting'&gt;Post-Action Waiting&lt;/h2&gt;

&lt;p&gt;Which brings us right to the second trick: the test is now doing &lt;strong&gt;post-action&lt;/strong&gt; waiting. And not only is it post-action, but it&amp;#8217;s &lt;strong&gt;generic waiting&lt;/strong&gt;. This has several nice benefits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;It doesn&amp;#8217;t matter whatever the application was doing while the request was in-flight&amp;#8211;spinning a wheel for the user, doing nothing at all, whatever&amp;#8211;Selenium can always look for &lt;code&gt;outstanding != 0&lt;/code&gt; and just work.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;It doesn&amp;#8217;t matter what the test is going to assert after this, so we don&amp;#8217;t need to worry about all of our tests&amp;#8217; wait logic breaking if we change the application&amp;#8217;s behavior.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Basically, we&amp;#8217;re back to the convenience of Web 1.0 applications&amp;#8211;we have an automatic, reliable way of keeping the browser and test in sync with each other.&lt;/p&gt;

&lt;h2 id='page_objects'&gt;Page Objects&lt;/h2&gt;

&lt;p&gt;So, that&amp;#8217;s the core of the approach. I think this just by itself will work quite well and, in my opinion, better than pre-assertion/per-assertion waiting approaches.&lt;/p&gt;

&lt;p&gt;However, I&amp;#8217;ve also been going one step further and, with my &lt;a href='https://github.com/stephenh/pageobjects'&gt;pageobjects&lt;/a&gt; implementation, centralizing the waiting declarations within the page objects themselves. So, I might have:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;// each page/fragment in the app has an XxxPage class
class EmployeePage extends AbstractPageObject {
  // each element on the page has a field of XxxObject
  public TextBoxObect name = new TextBoxObect(&amp;quot;employeeName&amp;quot;);

  // fluently add `outstanding` to submit
  public ButtonObject submit = new ButtonObject(&amp;quot;submit&amp;quot;)
    .afterClickWaitFor(outstanding());

  // cstr, other fields...
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The &lt;code&gt;afterClickWaitFor&lt;/code&gt; means there is just &lt;em&gt;one place&lt;/em&gt; in all of the functional tests that says &amp;#8220;after this button is clicked, we will probably have to wait for the server&amp;#8221;.&lt;/p&gt;

&lt;p&gt;So the test can now look even simpler, with no mention of waiting:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;employeePage.submit.click();
assertErrorIs(...);&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And if you&amp;#8217;re extra spiffy, you might even encapsulate the error gathering logic into the &lt;code&gt;EmployeePage&lt;/code&gt; as well, so then you&amp;#8217;re test is:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;employeePage.submit.click();
assertThat(employeePage.getErrors(), contains(&amp;quot;...&amp;quot;));&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To me, this is a pretty nice test to read. No explicit waiting, pretty high level (the ids/lookup logic are encapsulated in the page objects). It&amp;#8217;s probably not as flowing as a &lt;a href='http://www.growing-object-oriented-software.com/'&gt;GooS&lt;/a&gt;-style functional tests, which are awesome, but personally I find this level of abstraction to be a sweet spot in the trade off between effort and benefit.&lt;/p&gt;

&lt;h2 id='disclaimer'&gt;Disclaimer&lt;/h2&gt;

&lt;p&gt;The one large disclaimer to this approach is that I haven&amp;#8217;t had to deal with a lot of animation&amp;#8211;all of my waiting really is on the server, and then things in the UI are generally displayed right away (within the same event loop that services the AJAX response).&lt;/p&gt;

&lt;p&gt;If you&amp;#8217;re doing anything with &lt;code&gt;setTimeout&lt;/code&gt;, e.g. animation or progressive calculations, then you&amp;#8217;ll probably have to fall back to pre-assertion waiting. Although hopefully you could find a wait to encapsulate it into a page object, perhaps some sort of &lt;code&gt;beforeAssertionWaitFor&lt;/code&gt; method (which doesn&amp;#8217;t exist yet).&lt;/p&gt;

&lt;p&gt;Anyway, that disclaimer aside, I&amp;#8217;ve found this approach to be very successful. My last few projects have had much more most robust Selenium tests than previous ones (that doesn&amp;#8217;t mean perfect; but definitely much better). Part of that is likely due to the kick ass job the Selenium developers are doing, but I think the outstanding + post-action waiting approach has a large part to do with it as well.&lt;/p&gt;

&lt;p&gt;If you try it out, I hope you find it useful. Feel free to download &lt;a href='https://github.com/stephenh/pageobjects'&gt;pageobjects&lt;/a&gt;, play around, and drop me an email/Github message if you run in to anything.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Why No One Uses Scala's Structural Typing</title>
   <link href="http://draconianoverlord.com/2011/10/04/why-no-one-uses-scala-structural-typing.html"/>
   <updated>2011-10-04T00:00:00-07:00</updated>
   <id>http://draconianoverlord.com/2011/10/04/why-no-one-uses-scala-structural-typing</id>
   <content type="html">&lt;h1 id='why_no_one_uses_scalas_structural_typing'&gt;Why No One Uses Scala&amp;#8217;s Structural Typing&lt;/h1&gt;

&lt;p&gt;Recently I heard some Scala enthusiasts note that, anecdotally, not very many projects actually use Scala&amp;#8217;s structural typing support.&lt;/p&gt;

&lt;p&gt;In the subset of the Scala library that &lt;a href='http://scalagwt.github.com/'&gt;scalagwt&lt;/a&gt; supports (which is most of it), structural typing was only used once, and that turned out to be a &lt;a href='https://issues.scala-lang.org/browse/SI-4791'&gt;bug&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Why is this? Aren&amp;#8217;t structural types supposed to be awesome? The safety of static type checking, without the annoyance of manually adapting types?&lt;/p&gt;

&lt;p&gt;To me, the reason is fairly obvious: Scala&amp;#8217;s structural types are implemented on the declaration-side.&lt;/p&gt;

&lt;p&gt;This means that, when declaring a method, you decide then whether or not &lt;em&gt;all&lt;/em&gt; callers will use regular or structural typing. For example:&lt;/p&gt;

&lt;pre class='brush:scala'&gt;&lt;code&gt;class SomeApi {
  // regular typing method, takes Foo, callers
  // can only pass a Foo, normal typing
  def regularMethod(foo: Foo) {
    // regular dispatching
    foo.doFoo()
  }

  // structural typing method, callers can pass
  // any type that has a &amp;quot;doFoo&amp;quot; method
  def structuralMethod(foo: { def doFoo(): Unit }) {
    // structural dispatching (reflection)
    foo.doFoo()
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Okay, so what?&lt;/p&gt;

&lt;p&gt;To think about this, let&amp;#8217;s introduce two developers: the API designer and the API user:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The API designer codes &lt;code&gt;someMethod&lt;/code&gt; and decides regular vs. structural typing.&lt;/li&gt;

&lt;li&gt;The API user calls &lt;code&gt;someMethod&lt;/code&gt; and has to go with whatever the designer chose.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now think, who needs structural typing?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The API designer does not need structural typing&amp;#8211;he, by virtue of being the designer, controls the API and related codebase. If he needs &lt;code&gt;someMethod&lt;/code&gt; to accept two separate types, he very likely controls each type, or at least controls &lt;code&gt;someMethod&lt;/code&gt;, so, most of the time, can make his scenario work with regular types (having &lt;code&gt;TypeA&lt;/code&gt; also extend &lt;code&gt;TypeB&lt;/code&gt; or vice versa).&lt;/p&gt;

&lt;p&gt;(Besides API designers, I think this also covers a programmer making any calls internally within a codebase&amp;#8211;you just change the types of the methods/arguments to match what you&amp;#8217;re trying to do with normal typing rules.)&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;The API user &lt;em&gt;does&lt;/em&gt; need structural typing&amp;#8211;not being in control of the API, he is most likely to have types that wouldn&amp;#8217;t satisfy &lt;code&gt;someMethod&lt;/code&gt; using normal typing, but would with structural typing.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And there&amp;#8217;s the rub: structural typing&amp;#8217;s forte, in my opinion, is calling APIs you don&amp;#8217;t control; but that same lack of control means, in Scala, you won&amp;#8217;t be able to actually use it.&lt;/p&gt;

&lt;p&gt;Think of the API designer: it&amp;#8217;s unlikely they&amp;#8217;ll anticipate when API users will/will not want to use structural typing. And it&amp;#8217;s unlikely that API designers will use structural typing for the &lt;em&gt;entire&lt;/em&gt; API, just in case. So, in practice, it&amp;#8217;s used for none.&lt;/p&gt;

&lt;p&gt;So, what of structural typing then? Is it all for naught?&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m not sure. Previously, I mulled about how some languages do &lt;a href='http://draconianoverlord.com/2010/01/17/caller-side-structural-typing.html'&gt;Caller-Side Structural Typing&lt;/a&gt;, which moves the decision of &amp;#8220;do I use structural typing here?&amp;#8221; to the caller side, where I think it&amp;#8217;s much more likely to be used. E.g. &lt;a href='http://code.google.com/p/heron-language'&gt;Heron&lt;/a&gt;&amp;#8217;s &lt;a href='http://drdobbs.com/blogs/architecture-and-design/228701413'&gt;&lt;code&gt;as&lt;/code&gt; keyword&lt;/a&gt;:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;interface Foo {
  doFoo();
}

// doesn&amp;#39;t implement Foo
class LikeFoo {
  void doFoo() { ... }
}

// as generates a delegate that
// implements Foo for LikeFoo
takesFoo(new LikeFoo() as Foo);&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;However, these approaches (on a pre-&lt;a href='http://openjdk.java.net/projects/mlvm/subprojects.html#InterfaceInjection'&gt;interface-injection&lt;/a&gt; JVM anyway), usually just end up as the compiler/JVM auto-writing the adaptor for you (and can only be used for interfaces). Which is cool, but may/may not be structural typing anymore.&lt;/p&gt;

&lt;p&gt;A colleague pointed out that Scala&amp;#8217;s structural typing actually came about serendipitously, as a side effect of simplifying the Scala language spec (from &lt;a href='http://www.infoq.com/interviews/martin-odersky-scala-future'&gt;this interview&lt;/a&gt; with Martin Odersky). I&amp;#8217;m not an expert on the OO types vs. functional modules aspect Martin was talking about. But since my personal use case of &amp;#8220;calling APIs you don&amp;#8217;t control&amp;#8221; doesn&amp;#8217;t seem to be what Scala&amp;#8217;s structural typing was introduced for, it makes sense that it doesn&amp;#8217;t solve it very well.&lt;/p&gt;

&lt;p&gt;My suspicion is that structural types may just never be a big hit on the JVM, due to the assumptions it makes about types being non-structural. Unless &lt;code&gt;invokedynamic&lt;/code&gt; magic makes it possible; I have no idea. And I don&amp;#8217;t have enough experience with a non-JVM/true structural language like Go to really comment any further, so I&amp;#8217;ll leave it at that.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m sure others have more insightful thoughts on this; if so, please leave them, or links to them, in the comments.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>A GWT Developer's Reaction to Dart</title>
   <link href="http://draconianoverlord.com/2011/10/03/reaction-to-dart.html"/>
   <updated>2011-10-03T00:00:00-07:00</updated>
   <id>http://draconianoverlord.com/2011/10/03/reaction-to-dart</id>
   <content type="html">&lt;h1 id='a_gwt_developers_reaction_to_dart'&gt;A GWT Developer&amp;#8217;s Reaction to Dart&lt;/h1&gt;

&lt;p&gt;The scheduled &lt;a href='http://gotocon.com/aarhus-2011/presentation/Opening%20Keynote:%20Dart,%20a%20new%20programming%20language%20for%20structured%20web%20programming'&gt;Dart keynote&lt;/a&gt; announcement made the rounds a week ago or so. If you didn&amp;#8217;t catch it, Google wants to replace JavaScript, with a dual static/dynamic language named Dart.&lt;/p&gt;

&lt;p&gt;&lt;a href='http://markmail.org/message/uro3jtoitlmq6x7t'&gt;This post&lt;/a&gt; has more details, but basically Google wants to combine its two primary tool chains, &lt;a href='http://code.google.com/closure/'&gt;Closure&lt;/a&gt; (JavaScript-based) and &lt;a href='http://code.google.com/webtoolkit/'&gt;GWT&lt;/a&gt; (Java-based) into a single project. This makes sense, as both tools have (AFAIK) separate teams within Google supporting them, and both share the same goal of making it easier for developer&amp;#8217;s to build large, complex, browser-based applications.&lt;/p&gt;

&lt;p&gt;While I&amp;#8217;m not yet a front-end developer extraordinaire, GWT is my tool of choice for rich-client browser applications, and this means it&amp;#8217;s been effectively deprecated.&lt;/p&gt;

&lt;p&gt;Which, after my initial reaction (&amp;#8220;What?! GWT rulez!11!!&amp;#8221;), I realized, this is actually pretty damn cool. This post is my brief explanation of why.&lt;/p&gt;

&lt;h2 id='typing_and_tools'&gt;Typing and Tools&lt;/h2&gt;

&lt;p&gt;To explain, here are the four primary reasons why I like GWT in the first place:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;I&amp;#8217;m a &lt;a href='http://draconianoverlord.com/2010/11/24/why-im-a-static-typing-bigot.html'&gt;static typing bigot&lt;/a&gt;.&lt;/li&gt;

&lt;li&gt;I&amp;#8217;m addicted to Eclipse and not ashamed of it (although &lt;a href='http://www.viplugin.com/viplugin/'&gt;vi bindings&lt;/a&gt; FTW).&lt;/li&gt;

&lt;li&gt;I like GWT&amp;#8217;s components-based approach to widgets/UI.&lt;/li&gt;

&lt;li&gt;I like GWT&amp;#8217;s integrated &amp;#8220;toolkit&amp;#8221; approach of doing most things you&amp;#8217;ll need (minification, spriting, i18n, browser tweaks, etc.) out of the box.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now, if you cast each of these reasons to apply to Dart:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Static typing? Eh, optional, but, okay, good enough. Check.&lt;/li&gt;

&lt;li&gt;Eclipse? With static types, JDT-level Eclipse integration should be doable; Google has an Eclipse plugin team, so hopefully they&amp;#8217;ll have this sooner rather than later. Check.&lt;/li&gt;

&lt;li&gt;Components? UI components aren&amp;#8217;t, AFAIK, Dart-/language-specific, so I assume GWT&amp;#8217;s Dart-based successor will follow a similar approach. Check.&lt;/li&gt;

&lt;li&gt;Toolkit? Same thing as 3. Check.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;They all hold up. Dart is still a language I would prefer using over JavaScript, which is primarily why I&amp;#8217;m in GWT anyway. &lt;em&gt;Plus&lt;/em&gt; Dart will be browser-based.&lt;/p&gt;

&lt;h2 id='a_better_devmode'&gt;A Better DevMode&lt;/h2&gt;

&lt;p&gt;Also, stepping back, I realize that GWT, at some level, is a huge hack. Not because it trans-compiles Java to JavaScript (CoffeeScript does the same sort of thing), but because of its implementation of Developer Mode. (Developer Mode is where you run your webapp locally and can debug it in Eclipse.)&lt;/p&gt;

&lt;p&gt;To do this, GWT performs some browser/extension magic to force your browser to talk back and forth with a running JVM (where your code actually runs as regular Java code, so Eclipse can see/debug it), often times in a very chatty manner.&lt;/p&gt;

&lt;p&gt;Surprisingly, this normally works quite well. However, it also means you are paying an RPC cost for every cross browser/JVM call (anytime your Java code touches the DOM and vice versa), and that can add up to a less-than-fast developer experience.&lt;/p&gt;

&lt;p&gt;If only GWT could run your statically-typed code directly in the browser&amp;#8230;&lt;/p&gt;

&lt;p&gt;&amp;#8230;which is exactly what Dart will do. Nice!&lt;/p&gt;

&lt;h2 id='a_better_gwt'&gt;A Better GWT&lt;/h2&gt;

&lt;p&gt;So, I&amp;#8217;m optimistic: &lt;strong&gt;I see Dart as a way of getting an even better GWT&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Obviously, I&amp;#8217;m speculating a lot since the keynote hasn&amp;#8217;t happened yet, but, in a bit of naive projecting, I would assume the GWT users/developers within Google feel the same way I do. If you can provide a GWT-like experience, with less hacks and cruft, that sounds like a good thing to me.&lt;/p&gt;

&lt;h3 id='disclaimers'&gt;Disclaimers&lt;/h3&gt;

&lt;p&gt;That being said, a few thoughts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Just because it&amp;#8217;s from Google doesn&amp;#8217;t mean the language is going to rock; see Go. I&amp;#8217;d be really surprised if this is the case with Dart, if only because the memo suggests a non-trivial amount of people are working on the project.&lt;/p&gt;

&lt;p&gt;That being said, &lt;a href='http://scalagwt.github.com/'&gt;scala-gwt&lt;/a&gt; has made some great progress, so perhaps a &lt;code&gt;scala-dart&lt;/code&gt; project could be started if the syntax is less-than-ideal.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Even if the other browsers don&amp;#8217;t adopt Dart, I don&amp;#8217;t care.&lt;/strong&gt; If I can use Dart+GWT-next-gen to develop webapps in Chrome with a kick-ass developer experience, and fall back on old-school Developer Mode and JavaScript trans-compiling for the others, I&amp;#8217;d be perfectly happy with that choice.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;I&amp;#8217;m really surprised the Dart VM will be for front-end servers as well; I assumed the JVM was king here and they&amp;#8217;d stay with it. I&amp;#8217;m unlikely to give up the JVM on the server-side, given the various libraries and APIs, all JVM-based, it uses to do its thing.&lt;/p&gt;

&lt;p&gt;Which, while in theory the &amp;#8220;same language on both client/server&amp;#8221; sounded great, in practice I&amp;#8217;ve rarely had a significant amount of code that could reused across each. Other than trivial validation, most code makes a surprising amount of assumptions based on the environment it&amp;#8217;s in.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, I&amp;#8217;m looking forward to the Dart keynote. It&amp;#8217;ll be interesting to see what it looks like, what the current progress is, and if/when real working prototypes will be available. As a GWT developer, it will also be interesting to see if any announcements are made about GWT next-gen, either in the keynote itself or by the GWT team afterwards.&lt;/p&gt;

&lt;p&gt;Given the amount of GWT code Google itself has internally, and the amount of GWT code in other companies, I&amp;#8217;m not worried about the GWT ecosystem dying on Oct 11th. Instead, depending on the GWT next-gen migration path/timeline, it might be a pretty happening place (well, as an introvert, I have a very loose definition of &amp;#8220;happening&amp;#8221;).&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Modern Code Generation Talk</title>
   <link href="http://draconianoverlord.com/2011/04/21/modern-code-generation-talk.html"/>
   <updated>2011-04-21T00:00:00-07:00</updated>
   <id>http://draconianoverlord.com/2011/04/21/modern-code-generation-talk</id>
   <content type="html">&lt;h1 id='modern_code_generation_talk'&gt;Modern Code Generation Talk&lt;/h1&gt;

&lt;p&gt;I did a talk this week for the local &lt;a href='http://www.ojug.org'&gt;JUG&lt;/a&gt; on Modern Code Generation.&lt;/p&gt;

&lt;p&gt;My main assertion is that old-school, generating-&lt;code&gt;.java&lt;/code&gt;-file code generation has been out of favor by the community for fancier alternatives (runtime CGLIB/ASM bytecode generation), and this isn&amp;#8217;t necessarily a good thing.&lt;/p&gt;

&lt;p&gt;Unlike my usual talks, I actually prepared for this one, and ended up with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;A &lt;a href='https://docs.google.com/present/edit?id=0AQJbluyXBq3ZZGQ0dDRuemtfMWZ3ZmN2bmNy&amp;amp;hl=en&amp;amp;authkey=COrBsM8I'&gt;slide show&lt;/a&gt; (tada!), and&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Several &lt;a href='http://github.com/stephenh/modern-code-generation'&gt;example projects&lt;/a&gt; on github&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The discussion during the talk was lively (always a good sign), and even wandered into discussing whether Java&amp;#8217;s static typing inherently leads to the boilerplate common on many Java projects.&lt;/p&gt;

&lt;p&gt;All in all, a lot of fun. Always curious why more professional programmers don&amp;#8217;t go to/talk at these sort of things.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Command Query Responsibility Segregation with S3 and JSON</title>
   <link href="http://draconianoverlord.com/2011/04/15/cqrs-with-s3-and-json.html"/>
   <updated>2011-04-15T00:00:00-07:00</updated>
   <id>http://draconianoverlord.com/2011/04/15/cqrs-with-s3-and-json</id>
   <content type="html">&lt;h2 id='command_query_responsibility_segregation_with_s3_and_json'&gt;Command Query Responsibility Segregation with S3 and JSON&lt;/h2&gt;

&lt;p&gt;We recently tackled a problem at &lt;a href='http://www.bizo.com'&gt;Bizo&lt;/a&gt; where we wanted to decouple our high-volume servers from our MySQL database.&lt;/p&gt;

&lt;p&gt;While considering different options (NoSQL vs. MySQL, etc.), in retrospect we ended up implementing a SOA-version of the &lt;a href='http://en.wikipedia.org/wiki/Command-query_separation'&gt;Command Query Separation&lt;/a&gt; pattern (or &lt;a href='http://codebetter.com/gregyoung/2009/08/13/command-query-separation/'&gt;Command Query Responsibility Segregation&lt;/a&gt;, which is services/messaging-specific).&lt;/p&gt;

&lt;p&gt;Briefly, in our new approach, queries (reads) use an in-memory cache that is bulk loaded and periodically reloaded from a snapshot of the data stored as JSON in S3. Commands (writes) are HTTP calls to a remote JSON API service. MySQL is still the authoritative database, we just added a layer of decoupling for both reads and writes.&lt;/p&gt;

&lt;p&gt;This meant our high-volume servers now have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No reliance on MySQL availability or schema&lt;/li&gt;

&lt;li&gt;No wire calls blocking the request thread (except a few special requests)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The rest of this post explains our context and elaborates on the approach.&lt;/p&gt;

&lt;h3 id='prior_approach_cached_jpa_calls'&gt;Prior Approach: Cached JPA Calls&lt;/h3&gt;

&lt;p&gt;For context, our high-volume servers rely on configuration data that is stored in a MySQL database. Of course, the configuration data that doesn&amp;#8217;t have to be absolutely fresh, so we&amp;#8217;d already been using caching to avoid constantly pounding the database for data that rarely changes.&lt;/p&gt;
&lt;img src='/images/remote-api-before.png' style='width: 400px; margin: auto; display: block;' /&gt;
&lt;p&gt;There were several things we liked about this approach:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;We use &lt;a href='http://aws.amazon.com/rds/'&gt;Amazon RDS&lt;/a&gt; for the MySQL instance, which provides out-of-the-box backups, master/slave configuration, etc., and is generally a pleasure to use. We enjoy not running our own database servers.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;We also have several low-volume internal and customer-facing web applications that maintain the same data and are perfectly happy talking to a SQL database. They are normal, chatty CRUD applications for which the tool support and ACID-sanity of a SQL database make life a lot easier.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That being said, we wanted to tweak a few things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Reduce the high-volume servers&amp;#8217; reliance on MySQL for seeding their cache.&lt;/p&gt;

&lt;p&gt;Although RDS is great, and definitely more stable than our own self-maintained instances would be, there are nonetheless limits on its capacity. Especially if one of our other application misbehaves (which has never happened&amp;#8230;&lt;em&gt;cough&lt;/em&gt;), it can degrade the MySQL instance to the point of negatively affecting the high-volume servers.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Reduce cache misses that block the request thread.&lt;/p&gt;

&lt;p&gt;Previously, configuration data (keyed by a pre-request configuration id) was not pulled into cache until it was needed. The first request (after every cache flush) would reload the data for it&amp;#8217;s configuration id from MySQL and repopulate the cache.&lt;/p&gt;

&lt;p&gt;While not initially a big deal, as Bizo has grown, we&amp;#8217;re now running in multiple AWS regions, and cache misses require a cross-region JDBC call to fetch their data from the MySQL server running in us-east.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Illustrated in code, our approach had, very simplified, been:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;class TheServlet {
  public void doGet() {
    int configId = request.getParameter(&amp;quot;configId&amp;quot;);
    Config config = configService.getConfig(configId);
    // continue processing with config settings
  }
}

class ConfigService {
  // actually thread-safe/ehcache-managed, flushed every 30m
  Map&amp;lt;Integer, Config&amp;gt; cached = new HashMap&amp;lt;Integer, Config&amp;gt;();

  public Config getConfig(int configId) {
    Config config = cached.get(configId);
    if (config == null) {
      // hit mysql for the data, blocks the request thread
      config = configJpaRepository.find(configId);
      // cache it
      cached.put(configId, config);
    }
    return config;
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id='potential_big_data_approaches'&gt;Potential &amp;#8220;Big Data&amp;#8221; Approaches&lt;/h3&gt;

&lt;p&gt;Given our primary concern was MySQL being a single point of failure, we considered moving to a new database platform, e.g. SimpleDB, Cassandra, or the like, all of which can scale out across machines.&lt;/p&gt;

&lt;p&gt;Of course, RDS&amp;#8217;s master/slave MySQL setup already reduces its risk of single machine point of failure, but the RDS master/slave cluster as a whole is still, using the term loosely, a &amp;#8220;single point&amp;#8221;. Granted, with this very loose definition, there will always be some &amp;#8220;point&amp;#8221; you rely on&amp;#8211;we just wanted one that we felt more comfortable with than MySQL.&lt;/p&gt;

&lt;p&gt;Anyway, for NoSQL options, we couldn&amp;#8217;t get over the cons of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Having to run our own clusters (except for SimpleDB).&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Having to migrate our low-volume CRUD webapps over to the new, potentially slow (SimpleDB), potentially eventually-consistent (Cassandra) NoSQL back-end.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Still having cache misses result in request threads blocking on wire calls.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Because of these cons, we did not put a lot of effort into researching NoSQL approaches for this problem&amp;#8211;we felt it was fairly apparent they weren&amp;#8217;t necessary.&lt;/p&gt;

&lt;h3 id='realization_mysql_is_fine_fix_the_cache'&gt;Realization: MySQL is Fine, Fix the Cache&lt;/h3&gt;

&lt;p&gt;Of course, we really didn&amp;#8217;t have a Big Data problem (well, we do &lt;a href='http://hadoop.apache.org/'&gt;have&lt;/a&gt; &lt;a href='http://wiki.apache.org/hadoop/Hive'&gt;a&lt;/a&gt; &lt;a href='http://aws.amazon.com/elasticmapreduce/'&gt;lot&lt;/a&gt; of &lt;a href='http://en.wikipedia.org/wiki/OLAP_cube'&gt;those&lt;/a&gt;, but not for this problem).&lt;/p&gt;

&lt;p&gt;We just had a cache seeding problem. Specifically:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;All of our configuration data can fit in RAM, so we should be able to bulk-load all of it at once&amp;#8211;no more expensive, blocking wire calls on cache misses (basically there are no cache misses anymore).&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;We can load the data from a more reliable, non-authoritative, non-MySQL data store&amp;#8211;e.g. an S3 snapshot (&lt;code&gt;config.json.gz&lt;/code&gt;) of the configuration data.&lt;/p&gt;

&lt;p&gt;The S3 file then basically becomes our alternative &amp;#8220;query&amp;#8221; database in the CQRS pattern.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When these are put together, a solution emerges where we can have a in-memory, always-populated cache of the configuration data that is refreshed by a background thread and results in request threads never blocking.&lt;/p&gt;

&lt;p&gt;In code, this looks like:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;class TheServlet {
  public void doGet() {
    // note: no changes from before, which made migrating easy
    int configId = request.getParameter(&amp;quot;configId&amp;quot;);
    Config config = configService.getConfig(configId);
    // continue processing with config settings
  }
}

class ConfigService {
  // the current cache of all of the config data
  AtomicReference&amp;lt;Map&amp;gt; cached = new AtomicReference();

  public void init() {
    // use java.util.Timer to refresh the cache
    // on a background thread
    new Timer(true).schedule(new TimerTask() {
      public void run() {
        Map newCache = reloadFromS3(&amp;quot;bucket/config.json.gz&amp;quot;);
        cached.set(newCache);
      }
    }, 0, TimeUnit.MINUTES.toMillis(30));
  }

  public Config getConfig(int configId) {
    // now always return whatever is in the cache--if a
    // configId isn&amp;#39;t present, that means it was not in
    // the last S3 file and is treated the same as it
    // not being in the MySQL database previously
    Map currentCache = cached.get();
    if (currentCache == null) {
      return null; // data hasn&amp;#39;t been loaded yet
    } else {
      return currentCache.get(configId);
    }
  }

  private Map reloadFromS3(String path) {
    // uses AWS SDK to load the data from S3
    // and Jackson to deserialize it to a map
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id='a_few_wrinkles_realtime_reads_and_writes'&gt;A Few Wrinkles: Real-Time Reads and Writes&lt;/h3&gt;

&lt;p&gt;So far I&amp;#8217;ve only talked about the cached query/reads side of the new approach. We also had two more requirements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Very (very) infrequently, a high-volume server will need real-time configuration data to handle a special request.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;The high-volume servers occasionally write configuration/usage stats back to the MySQL database.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While we could have continued using a MySQL/JDBC connection for these few requests, this also provided the opportunity to build a JSON API in front of the MySQL database. This was desirable for two main reasons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;It decoupled our high-volume services from our MySQL schema. By still honoring the JSON API, we could upgrade the MySQL schema and the JSON API server at the same time with a much smaller, much less complicated downtime window than with the high-volume services talking directly to the MySQL schema.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;The MySQL instance is no longer being accessed across AWS regions, so can have much tighter firewall rules, which only allow the JSON API server (that is within its same us-east region) access it.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The new setup looks basically like:&lt;/p&gt;
&lt;img src='/images/remote-api-after.png' style='width: 400px; margin: auto; display: block;' /&gt;
&lt;h3 id='scalatra_servlet_example'&gt;Scalatra Servlet Example&lt;/h3&gt;

&lt;p&gt;With &lt;a href='http://jackson.codehaus.org/'&gt;Jackson&lt;/a&gt; and &lt;a href='https://github.com/scalatra/scalatra'&gt;Scalatra&lt;/a&gt;, the JSON API server was trivial to build, especially since it could reuse the same JSON DTO objects that are also serialized in the &lt;code&gt;config.json.gz&lt;/code&gt; file in S3.&lt;/p&gt;

&lt;p&gt;As an example for how simple Jackson and Scalatra made writing the JSON API, here is the code for serving real-time request requests:&lt;/p&gt;

&lt;pre class='brush:scala'&gt;&lt;code&gt;class JsonApiService extends ScalatraServlet {
  get(&amp;quot;/getConfig&amp;quot;) {
    // config is the domain object fresh from MySQL
    val config = configRepo.find(params(&amp;quot;configId&amp;quot;).toLong)
    // configDto is just the data we want to serialize
    val configDto = ConfigMapper.toDto(configDto)
    // jackson magic to make json
    val json = jackson.writeValueAsString(configDto)
    json
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id='background_writes'&gt;Background Writes&lt;/h3&gt;

&lt;p&gt;The final optimization was realizing that, when the high-volume servers have requests that trigger stats to be written to MySQL, for our requirements, these writes aren&amp;#8217;t critical.&lt;/p&gt;

&lt;p&gt;This means there is no need to perform them on the request-serving thread. Instead, we can push the writes onto a queue and have it fulfilled by a background thread.&lt;/p&gt;

&lt;p&gt;This generally looks like:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;class ConfigWriteService {
  // create a background thread pool of (for now) size 1
  private ExecutorService executor = new ThreadPoolExector(...);

  // called by the request thread, won&amp;#39;t block
  public void writeUsage(int configId, int usage) {
    offer(&amp;quot;https://json-api-service/writeUsage?configId=&amp;quot; +
      configId +
      &amp;quot;&amp;amp;usage=&amp;quot; +
      usage);
    }
  }

  private void offer(String url) {
    try {
      executor.submit(new BackgroundWrite(url));
    } catch (RejectedExecutionException ree) {
      // queue full, writes aren&amp;#39;t critical, so ignore
    }
  }

  private static class BackgroundWrite implements Runnable {
    private String url;

    private BackgroundWrite(String url) {
      this.url = url;
    }

    public void run() {
      // make call using commons-http to url
    }
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id='tldr_we_implemented_command_query_responsibility_segregation'&gt;tl;dr We Implemented Command Query Responsibility Segregation&lt;/h3&gt;

&lt;p&gt;With changing only a minimal amount of code in our high-volume servers, we were able to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Have queries (most reads) use cached, always-loaded data is that periodically reloaded from data snapshots in S3 (a more reliable source than MySQL)&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Have commands (writes) sent from a background-thread to a JSON API that saves the data to MySQL and hides JDBC schema changes.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For this configuration data, and our current requirements, MySQL, augmented with a more aggressive, Command Query Separation-style caching schema, has and continues to work well.&lt;/p&gt;

&lt;p&gt;For more reading on CQS/CQRS, I suggest:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Both the &lt;a href='http://en.wikipedia.org/wiki/Command-query_separation'&gt;Wikipedia&lt;/a&gt; article and Martin Fowler&amp;#8217;s &lt;a href='http://www.martinfowler.com/bliki/CommandQuerySeparation.html'&gt;CommandQuerySeparation&lt;/a&gt;, however they focus on CQS as applied to OO, e.g. side-effect free vs. mutating method calls.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;For CQS applied to services, e.g. CQRS, &lt;a href='http://www.udidahan.com/2009/12/09/clarified-cqrs/'&gt;Udi Dahan&lt;/a&gt; seems to be one of the first advocates of the term. Since then, CQRS even seems to have its own &lt;a href='http://cqrsinfo.com/'&gt;site&lt;/a&gt; and &lt;a href='http://groups.google.com/group/dddcqrs'&gt;google group&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;(Note: this post was also cross-posted on the Bizo &lt;a href='http://dev.bizo.com'&gt;dev blog&lt;/a&gt;. If you&amp;#8217;re interested in more posts on AWS/Java/Scala problems, you should check it out.)&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Framework-less Dependency Injection</title>
   <link href="http://draconianoverlord.com/2011/03/17/frameworkless-di.html"/>
   <updated>2011-03-17T00:00:00-07:00</updated>
   <id>http://draconianoverlord.com/2011/03/17/frameworkless-di</id>
   <content type="html">&lt;h1 id='frameworkless_dependency_injection'&gt;Framework-less Dependency Injection&lt;/h1&gt;

&lt;h2 id='overview'&gt;Overview&lt;/h2&gt;

&lt;p&gt;I&amp;#8217;d like to present an alternative to framework-based DI that allows you to still have clean, decoupled, testable code without handing over control of every non-trivial object&amp;#8217;s instantiation to a DI framework.&lt;/p&gt;

&lt;p&gt;The key idea is to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Make a single interface for retrieving all application-wide shared objects&lt;/li&gt;

&lt;li&gt;Pass an instance of this interface around in your application&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That&amp;#8217;s it. This basically combines Fowler&amp;#8217;s old school &lt;a href='http://martinfowler.com/eaaCatalog/registry.html'&gt;Registry&lt;/a&gt; pattern with the DI hipness of constructor injection. I don&amp;#8217;t claim this is anything novel, nor perfect; but I&amp;#8217;m surprised I haven&amp;#8217;t seen it being used more.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;ve been using this approach for awhile now (since my &lt;a href='/2010/01/15/changing-my-style.html'&gt;Changing My Style&lt;/a&gt; post from a year ago) and it has been working out quite well.&lt;/p&gt;

&lt;p&gt;There are pros and cons, but first an example.&lt;/p&gt;

&lt;h2 id='example'&gt;Example&lt;/h2&gt;

&lt;p&gt;To frame the example, let&amp;#8217;s setup three class that respond to a user request. Something like:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public class Servlet {
  private Handlers handlers = new Handlers();

  // called when user hits the service
  public void handle(HttpRequest request) {
    handlers.handle(request);
  }
}

public class Handlers {
  public void handle(HttpRequest request) {
    // dispatches request to the right handler for the request type
    if (&amp;quot;bar&amp;quot;.equals(request.getParameter(&amp;quot;type&amp;quot;))) {
      new BarHandler(request).handle();
    }
  }
}

// instantiated per request
public class BarHandler {
  private final HttpRequest request;
  
  public BarHandler(HttpRequest request) {
    this.request = request;
  }

  public void handle() {
    databaseRepo.lookupId(...);
    emailRepo.sendAnEmail();
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This is completely made-up, but the idea is that we have several objects involved in servicing the request. Some of them are stateless (&lt;code&gt;Servlet&lt;/code&gt; and &lt;code&gt;Handlers&lt;/code&gt;) but some are stateful (&lt;code&gt;BarHandler&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;The problem then is how to get the &lt;code&gt;databaseRepo&lt;/code&gt; and &lt;code&gt;emailRepo&lt;/code&gt; dependencies passed down into the &lt;code&gt;BarHandler&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id='potential_approaches'&gt;Potential Approaches&lt;/h2&gt;

&lt;p&gt;Throwing out possibilities, we could:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Instantiate &lt;code&gt;databaseRepo&lt;/code&gt; and &lt;code&gt;emailRepo&lt;/code&gt; in &lt;code&gt;Servlet&lt;/code&gt; and pass them to &lt;code&gt;Handlers&lt;/code&gt;&amp;#8217;s constructor, which &lt;code&gt;Handlers&lt;/code&gt; can then pass to &lt;code&gt;BarHandler&lt;/code&gt;. However, with more than a few application-scoped variables, this would become quite tedious, especially for intermediary classes like &lt;code&gt;Handlers&lt;/code&gt; which wouldn&amp;#8217;t use the dependencies but just pass them on.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Create a &lt;code&gt;DatabaseRepo.getInstance()&lt;/code&gt; static singleton method, but we add coupling and lose easy testability.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Use a DI framework to inject &lt;code&gt;DatabaseRepo&lt;/code&gt; and &lt;code&gt;EmailRepo&lt;/code&gt; into &lt;code&gt;BarHandler&lt;/code&gt;. This would mean no longer being able to call &lt;code&gt;new BarHandler&lt;/code&gt;, so our &lt;code&gt;Handlers&lt;/code&gt; class would have to be passed a &lt;code&gt;Provider&amp;lt;BarHandler&amp;gt;&lt;/code&gt; in it&amp;#8217;s constructor. Which means &lt;code&gt;Handlers&lt;/code&gt; also needs to be instantiated by the DI framework, etc.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I&amp;#8217;m sure there are other potential approaches I&amp;#8217;m missing, but I think these are the most common. Per the comments with each approach above, I wasn&amp;#8217;t satisfied with any of these and so was looking for something else.&lt;/p&gt;

&lt;h2 id='appregistry_approach'&gt;AppRegistry Approach&lt;/h2&gt;

&lt;p&gt;The approach I&amp;#8217;ve settled on lately is based around an &lt;code&gt;AppRegistry&lt;/code&gt; interface. All of the shared, application-scoped objects (&lt;code&gt;DatabaseRepo&lt;/code&gt;, &lt;code&gt;EmailRepo&lt;/code&gt;) go into this interface:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public interface AppRegistry {
  DatabaseRepo getDatabaseRepo();

  EmailRepo getEmailRepo();
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I use the term &lt;code&gt;Registry&lt;/code&gt; in deference to Fowler&amp;#8217;s pattern, but you could just as well call it &lt;code&gt;AppContext&lt;/code&gt;, which is more Spring-like. Which, speaking of Spring, you can basically think of &lt;code&gt;AppRegistry&lt;/code&gt; as making a plain, strongly-typed interface with a &lt;code&gt;getXxx&lt;/code&gt; method for each bean in your Spring config file.&lt;/p&gt;

&lt;p&gt;And now we just create a new instance of it and pass it around:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public class Servlet {
  // registry can potentially be shared via the ServletContext
  private AppRegistry registry = new AppRegistryInstance();
  private Handlers handlers = new Handlers(registry);

  // called when user hits the service
  public void handle(HttpRequest request) {
    handlers.handle(request);
  }
}

public class Handlers {
  private final AppRegistry registry;
  
  public Handlers(AppRegistry registry) {
    this.registry = registry;
  }

  public void handle(HttpRequest request) {
    // dispatches request to the right handler for the request type
    if (&amp;quot;bar&amp;quot;.equals(request.getParameter(&amp;quot;type&amp;quot;))) {
      new BarHandler(registry, request).handle();
    }
  }
}

// instantiated per request
public class BarHandler {
  private final DatabaseRepo databaseRepo;
  private final EmailRepo emailRepo;
  private final HttpRequest request;
  
  public BarHandler(AppRegistry registry, HttpRequest request) {
    this.databaseRepo = registry.getDatabaseRepo();
    this.emailRepo = registry.getEmailRepo();
    this.request = request;
  }

  public void handle() {
    databaseRepo.lookupId(...);
    emailRepo.sendAnEmail();
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And that&amp;#8217;s it. Pros/cons are discussed next, but the short of it is that we can still test the &lt;code&gt;BarHandler&lt;/code&gt; class&amp;#8211;a fake (stub or mock, but, no, really, &lt;a href='/2010/07/09/why-i-dont-like-mocks.html'&gt;use a stub&lt;/a&gt;) &lt;code&gt;AppRegistry&lt;/code&gt; can be passed into &lt;code&gt;BarHandler&lt;/code&gt; with whatever fake versions of the dependencies you want to use for the test.&lt;/p&gt;

&lt;p&gt;Briefly, the &lt;code&gt;AppRegistryInstance&lt;/code&gt; class just instantiates the dependencies and holds on to them:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public class AppRegistryInstance implements AppRegistry {
  private final DatabaseRepo databaseRepo;
  private final EmailRepo emailRepo;

  public AppRegistryInstance() {
    databaseRepo = new DatabaseRepo(...settings...);
    emailRepo = new EmailRepo(...settings...);
  }

  public DatabaseRepo getDatabaseRepo() {
    return databaseRepo;
  }

  public EmailRepo getEmailRepo() {
    return emailRepo;
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And you could just as well create a &lt;code&gt;StubAppRegistryInstance&lt;/code&gt; for all of your tests to reuse:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public clas StubAppRegistryInstance implements AppRegistry {
  private final DummyDatabaseRepo databaseRepo = new DummyDatabaseRepo();
  private final DummyEmailRepo emailRepo = new DummyEmailRepo();

  public DummyDatabaseRepo getDatabaseRepo() {
    return databaseRepo;
  }

  public DummyEmailRepo getEmailRepo() {
    return emailRepo;
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So that now instead of copy/paste setting up a lot of mock expectations/results, your test can pass a &lt;code&gt;StubAppRegistryInstance&lt;/code&gt; to the &lt;code&gt;BarHandler&lt;/code&gt; under test and then assert against the side affects that &lt;code&gt;BarHandler&lt;/code&gt; makes to &lt;code&gt;DummyDatabaseRepo&lt;/code&gt; and &lt;code&gt;DummyEmailRepo&lt;/code&gt;.&lt;/p&gt;

&lt;h1 id='proscons'&gt;Pros/Cons&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Pro: No auto-wiring DI framework. No magic.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Pro: Intermediary classes (e.g. &lt;code&gt;Handlers&lt;/code&gt;) don&amp;#8217;t have to know about each individual app-wide dependency of the classes it instantiates (either directly or indirectly). &lt;code&gt;new&lt;/code&gt; calls stay clean, with at most the extra &lt;code&gt;AppRegistry&lt;/code&gt; parameter passed.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Pro: Only classes that require app-wide sharing are in the &lt;code&gt;AppRegistry&lt;/code&gt; interface&amp;#8211;unlike auto-wiring DI, if a class is not going to be doubled out (like &lt;code&gt;BarHandler&lt;/code&gt;, which there is only ever one implementation of), we can just use &lt;code&gt;new&lt;/code&gt; and not worry about a DI library/&lt;code&gt;Provider&lt;/code&gt; creating it for us.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Pro: &lt;code&gt;AppRegistryInstance&lt;/code&gt; is regular Java code, so can freely use configuration files, system properties, even &lt;code&gt;if&lt;/code&gt; statements to configure the implementations of &lt;code&gt;DatabaseRepo&lt;/code&gt; and &lt;code&gt;EmailRepo&lt;/code&gt; appropriately.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Pro: &amp;#8220;scopes&amp;#8221; become a lot less confusing&amp;#8211;where as DI frameworks will, to the client, arbitrarily return shared (singleton) or new (prototype) instances, everything in &lt;code&gt;AppRegistry&lt;/code&gt; is by definition application scoped. If you need a &amp;#8220;prototype&amp;#8221; instance, just call &lt;code&gt;new&lt;/code&gt;. If you need a request scope, make a new &lt;code&gt;RequestRegistry&lt;/code&gt; (or &lt;code&gt;RequestContext&lt;/code&gt;) interface that follows the same &lt;code&gt;AppRegistry&lt;/code&gt; pattern and explicitly models the request-scoped dependencies.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Con: &lt;code&gt;BarHandler&lt;/code&gt;&amp;#8217;s constructor signature only declares that it&amp;#8217;s dependency is the &lt;code&gt;AppRegistry&lt;/code&gt; (meaning some number of application-scoped beans). This is not as clear or self-documenting as a traditional DI constructor signature which would specify each direct dependency as a separate parameter (e.g.&lt;code&gt;DatabaseRepo&lt;/code&gt; and &lt;code&gt;EmailRepo&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Con: You give up the DI container&amp;#8217;s &amp;#8220;more than just DI&amp;#8221; features (like Spring&amp;#8217;s automatic transaction management, aspect/proxy features, etc.). Although, personally, I don&amp;#8217;t consider this a huge loss anyway.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id='other_alternatives'&gt;Other Alternatives&lt;/h1&gt;

&lt;p&gt;There is a (at least one) variation of this &amp;#8220;make an interface for your dependencies&amp;#8221; approach.&lt;/p&gt;

&lt;p&gt;&lt;a href='http://sonymathew.blogspot.com/2009/11/context-ioc-revisited-i-wrote-about.html'&gt;Context IoC&lt;/a&gt; is a pattern than uses per-class interfaces instead of per-scope interfaces. Which addresses the con listed above of &lt;code&gt;BarHandler&lt;/code&gt;&amp;#8217;s explicit dependencies not being apparent from the API.&lt;/p&gt;

&lt;p&gt;E.g. Context IoC would have a &lt;code&gt;BarHandler.Context&lt;/code&gt; interface that declared the explicit &lt;code&gt;DatabaseRepo&lt;/code&gt; and &lt;code&gt;EmailRepo&lt;/code&gt; dependencies, plus extended the corresponding &lt;code&gt;Xxx.Context&lt;/code&gt; interface of each object that &lt;code&gt;BarHandler&lt;/code&gt; instantiated (so that &lt;code&gt;BarHandler.Context&lt;/code&gt; could be used for constructing those instances as well).&lt;/p&gt;

&lt;p&gt;I think the Context IoC approach is quite novel, but it leads to a lot of extra interfaces and so is a bit excessive in my opinion.&lt;/p&gt;

&lt;h1 id='conclusion'&gt;Conclusion&lt;/h1&gt;

&lt;p&gt;For me, this pattern has worked out very well to test-enable my code. I can switch out dependencies as needed without giving up the &lt;code&gt;new&lt;/code&gt; operator and without making object instantiation so painful that only a DI framework can do it.&lt;/p&gt;

&lt;p&gt;So I can apply &amp;#8220;YAGNI&amp;#8221; to a DI framework and stay with the simplicity of regular Java.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Preferred Build Setup</title>
   <link href="http://draconianoverlord.com/2011/02/28/preferred-build-setup.html"/>
   <updated>2011-02-28T00:00:00-08:00</updated>
   <id>http://draconianoverlord.com/2011/02/28/preferred-build-setup</id>
   <content type="html">&lt;h1 id='preferred_build_setup'&gt;Preferred Build Setup&lt;/h1&gt;

&lt;p&gt;I&amp;#8217;m settling in to a build setup (for Java projects) that I&amp;#8217;m reasonably comfortable with.&lt;/p&gt;

&lt;p&gt;My current preference is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An &lt;a href='http://ant.apache.org/ivy/'&gt;Ivy&lt;/a&gt; file to express dependencies&lt;/li&gt;

&lt;li&gt;&lt;a href='http://buildr.apache.org'&gt;Buildr&lt;/a&gt; with &lt;a href='https://github.com/klaas1979/ivy4r'&gt;ivy4r&lt;/a&gt; to do command line builds&lt;/li&gt;

&lt;li&gt;Eclipse with &lt;a href='http://ant.apache.org/ivy/ivyde/'&gt;IvyDE&lt;/a&gt; for Eclipse builds&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id='requirements'&gt;Requirements&lt;/h2&gt;

&lt;p&gt;This satisfies my four key requirements:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Not be Maven&lt;/p&gt;

&lt;p&gt;This is self-explanatory.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Pull dependencies from a Maven repository&lt;/p&gt;

&lt;p&gt;As I&amp;#8217;ve &lt;a href='http://www.draconianoverlord.com/2010/07/18/publishing-to-maven-repos-with-ivy.html'&gt;admitted before&lt;/a&gt;, I dislike Maven, but it&amp;#8217;s repo concept has been awesome for the Java community. Except for initially screwing up the group ids (&lt;code&gt;commons-lang/commons-lang&lt;/code&gt;), they did good.&lt;/p&gt;

&lt;p&gt;While I think Ivy is generally over-engineered (every setting, repo layout, etc., is super extensible), I like having one file (&lt;code&gt;ivy.xml&lt;/code&gt;) that is for dependencies, and &lt;em&gt;only&lt;/em&gt; dependencies, that both a CLI tool and an Eclipse plugin can read in.&lt;/p&gt;

&lt;p&gt;(I.e. I don&amp;#8217;t like encoding my dependencies directly in Buildr&amp;#8217;s &lt;code&gt;buildfile&lt;/code&gt;, because then they can&amp;#8217;t be leveraged by an &amp;#8220;in-workspace resolution&amp;#8221;-capable Eclipse plugin.)&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Publish artifacts to a Maven repository&lt;/p&gt;

&lt;p&gt;Buildr publishes very nicely to Maven repositories&amp;#8211;with pure Ivy, this took &lt;a href='http://www.draconianoverlord.com/2010/07/18/publishing-to-maven-repos-with-ivy.html'&gt;some ugly hacks&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Eclipse &amp;#8220;in-workspace&amp;#8221; dependency resolution&lt;/p&gt;

&lt;p&gt;This is my must-have feature. If project Foo depends on project Bar, and I have both of them open in Eclipse, Foo should not be using bar.jar, but should instead have the Bar project&amp;#8217;s class files directly on it&amp;#8217;s classpath. That way I don&amp;#8217;t have to re-jar Bar each time I want to test the latest changes in Foo.&lt;/p&gt;

&lt;p&gt;This is the primary flaw with any build solution that generates static &lt;code&gt;.eclipse&lt;/code&gt; files (e.g. Buildr&amp;#8217;s out of the box eclipse integration, or the old-school &lt;code&gt;mvn eclipse:eclipse&lt;/code&gt; integration). An Eclipse plugin can tell which projects it does/does not have open, and update each project&amp;#8217;s cross-project dependencies on the fly.&lt;/p&gt;

&lt;p&gt;Admittedly, the &lt;a href='http://m2eclipse.sonatype.org/'&gt;m2eclipse&lt;/a&gt; plugin does this well for Maven. And it seems more solid than IvyDE. Kudos, it&amp;#8217;s a great feature. But it&amp;#8217;s still Maven.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id='ant_vs_buildr'&gt;Ant vs. Buildr&lt;/h2&gt;

&lt;p&gt;I used to have all of this working with Ant, but it was terribly verbose and involved a lot of copy/paste for each new project. That being said, it was simple and &amp;#8220;just worked&amp;#8221;, so I lived with it for quiet awhile.&lt;/p&gt;

&lt;p&gt;However, after using Buildr for a few projects, I&amp;#8217;ve been very pleased with it.&lt;/p&gt;

&lt;p&gt;In my opinion, Buildr does an good job of having sane &amp;#8220;Standard Java project&amp;#8221; defaults that you can tweak when needed. Basically it&amp;#8217;s a better Maven.&lt;/p&gt;

&lt;p&gt;My two complaints with Buildr are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Being an embedded DSL in a dynamic language, I find it hard to discover how to do new things. Once you know the right &lt;code&gt;method_missing&lt;/code&gt;/whatever-backed incantation, it makes sense. But, personally, I think it is too flexible. I&amp;#8217;d be willing to sacrifice some succinctness for a less magical DSL. (Of course, I&amp;#8217;m a Java programmer.)&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;It has (currently) half-baked dependencies support&amp;#8211;the pom it generates for you won&amp;#8217;t contain any dependencies, making it useless. However, this isn&amp;#8217;t a big deal since I use &lt;code&gt;ivy4r&lt;/code&gt; to leverage the external &lt;code&gt;ivy.xml&lt;/code&gt; file anyway. It&amp;#8217;d just be nice if this was supported as a first-class setup.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id='aether_possibilities'&gt;Aether Possibilities&lt;/h2&gt;

&lt;p&gt;I really like the looks of &lt;a href='http://aether.sonatype.org/'&gt;Aether&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;d love to see someone build a &lt;code&gt;m2eclipse&lt;/code&gt;-lite Eclipse plugin that read in a minimal, &lt;code&gt;ivy.xml&lt;/code&gt;-type file (not a huge &lt;code&gt;pom.xml&lt;/code&gt;), and could replace the admittedly fickle IvyDE.&lt;/p&gt;

&lt;p&gt;Buildr is &lt;a href='https://github.com/mguymon/buildr-resolver'&gt;also potentially getting Aether support&lt;/a&gt;. Granted, it&amp;#8217;d use the &lt;code&gt;buildfile&lt;/code&gt;-based dependencies and not an external XML file.&lt;/p&gt;

&lt;p&gt;But if it did, and this &lt;code&gt;m2eclipse&lt;/code&gt;-lite plugin showed up, I would switch.&lt;/p&gt;

&lt;h2 id='example'&gt;Example&lt;/h2&gt;

&lt;p&gt;This is the build setup for my &lt;a href='https://github.com/stephenh/pageobjects'&gt;pageobjects&lt;/a&gt; project. It uses buildr/ivy, and is small and simple, so should be a good example.&lt;/p&gt;

&lt;h3 id='id7'&gt;&lt;code&gt;ivy.xml&lt;/code&gt;&lt;/h3&gt;

&lt;p&gt;This is where dependencies are declared. The Ivy confs are a lot like Maven&amp;#8217;s scopes, so you can differentiate compile-time vs. build-time dependencies.&lt;/p&gt;

&lt;pre class='brush:xml'&gt;&lt;code&gt;&amp;lt;ivy-module version=&amp;quot;2.0&amp;quot;&amp;gt;
  &amp;lt;info organisation=&amp;quot;com.bizo&amp;quot; module=&amp;quot;pageobjects&amp;quot; revision=&amp;quot;${version}&amp;quot;/&amp;gt;
  &amp;lt;configurations&amp;gt;
    &amp;lt;conf name=&amp;quot;default&amp;quot; extends=&amp;quot;compile&amp;quot;/&amp;gt;
    &amp;lt;conf name=&amp;quot;compile&amp;quot;/&amp;gt;
    &amp;lt;conf name=&amp;quot;sources&amp;quot;/&amp;gt;
  &amp;lt;/configurations&amp;gt;
  &amp;lt;dependencies defaultconfmapping=&amp;quot;%-&amp;gt;default;sources-&amp;gt;sources()&amp;quot;&amp;gt;
    &amp;lt;dependency org=&amp;quot;org.seleniumhq.selenium&amp;quot; name=&amp;quot;selenium&amp;quot; rev=&amp;quot;r9790&amp;quot; conf=&amp;quot;compile;sources&amp;quot; /&amp;gt;
    &amp;lt;dependency org=&amp;quot;junit&amp;quot; name=&amp;quot;junit&amp;quot; rev=&amp;quot;4.8.1&amp;quot; conf=&amp;quot;compile;sources&amp;quot; /&amp;gt;
  &amp;lt;/dependencies&amp;gt;
&amp;lt;/ivy-module&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Things to note:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;For your dependencies, use &lt;code&gt;conf&lt;/code&gt; names that map to Maven scope names, so that the Ivy-generated &lt;code&gt;pom.xml&lt;/code&gt; (for uploading to a Maven repo) maps your dependencies correctly.&lt;/p&gt;

&lt;p&gt;Otherwise your dependencies will all be listed as &lt;code&gt;&amp;lt;optional&amp;gt;true&amp;lt;/optional&amp;gt;&lt;/code&gt;, which is terribly annoying.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id='id8'&gt;&lt;code&gt;ivysettings.xml&lt;/code&gt;&lt;/h3&gt;

&lt;p&gt;Ivy uses a separate file to configure, among other things, the repositories you want to pull artifacts from. The &lt;code&gt;ibiblio&lt;/code&gt; resolver works great for any Maven repository.&lt;/p&gt;

&lt;pre class='brush:xml'&gt;&lt;code&gt;&amp;lt;ivysettings&amp;gt;
  &amp;lt;settings defaultResolver=&amp;quot;default&amp;quot;/&amp;gt;
  &amp;lt;include url=&amp;quot;${ivy.default.settings.dir}/ivysettings-public.xml&amp;quot;/&amp;gt;
  &amp;lt;property name=&amp;quot;version&amp;quot; value=&amp;quot;SNAPSHOT&amp;quot; override=&amp;quot;false&amp;quot;/&amp;gt;
  &amp;lt;resolvers&amp;gt;
    &amp;lt;ibiblio name=&amp;quot;local-m2&amp;quot; m2compatible=&amp;quot;true&amp;quot; root=&amp;quot;file://${user.home}/.m2/repository&amp;quot; changingPattern=&amp;quot;.*SNAPSHOT&amp;quot;/&amp;gt;
    &amp;lt;ibiblio name=&amp;quot;joist-m2&amp;quot; m2compatible=&amp;quot;true&amp;quot; root=&amp;quot;http://repo.joist.ws&amp;quot;/&amp;gt;
    &amp;lt;chain name=&amp;quot;default&amp;quot; changingPattern=&amp;quot;.*SNAPSHOT&amp;quot;&amp;gt;
      &amp;lt;resolver ref=&amp;quot;public&amp;quot;/&amp;gt;
      &amp;lt;resolver ref=&amp;quot;local-m2&amp;quot;/&amp;gt;
      &amp;lt;resolver ref=&amp;quot;joist-m2&amp;quot;/&amp;gt;
    &amp;lt;/chain&amp;gt;
  &amp;lt;/resolvers&amp;gt;
&amp;lt;/ivysettings&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Things to note:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;changingPattern&lt;/code&gt; is required for snapshots&lt;/p&gt;

&lt;p&gt;I always set this for at least my &lt;code&gt;local-m2&lt;/code&gt; resolver so that I can test local builds of other projects. Other than that, I&amp;#8217;ve been using mostly timestamped jars of projects instead of snapshots.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id='id9'&gt;&lt;code&gt;.classpath&lt;/code&gt;&lt;/h3&gt;

&lt;p&gt;This, of course, is the Eclipse classpath file.&lt;/p&gt;

&lt;pre class='brush:xml'&gt;&lt;code&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;
&amp;lt;classpath&amp;gt;
  &amp;lt;classpathentry kind=&amp;quot;src&amp;quot; path=&amp;quot;src/main/java&amp;quot;/&amp;gt;
  &amp;lt;classpathentry kind=&amp;quot;con&amp;quot; path=&amp;quot;org.eclipse.jdt.launching.JRE_CONTAINER&amp;quot;/&amp;gt;
  &amp;lt;classpathentry kind=&amp;quot;con&amp;quot; path=&amp;quot;org.apache.ivyde.eclipse.cpcontainer.IVYDE_CONTAINER/?ivyXmlPath=ivy.xml&amp;amp;amp;confs=*&amp;amp;amp;ivySettingsPath=%24%7Bworkspace_loc%3Apageobjects%2Fivysettings.xml%7D&amp;amp;amp;loadSettingsOnDemand=false&amp;amp;amp;propertyFiles=&amp;quot;/&amp;gt;
  &amp;lt;classpathentry kind=&amp;quot;output&amp;quot; path=&amp;quot;target/eclipse&amp;quot;/&amp;gt;
&amp;lt;/classpath&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Things to note:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Thanks to the &lt;code&gt;IVYDE_CONTAINER&lt;/code&gt; line, this file is nice and short and won&amp;#8217;t change any time you add/remove a dependency&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id='id10'&gt;&lt;code&gt;buildfile&lt;/code&gt;&lt;/h3&gt;

&lt;p&gt;This is what drives the Buildr build. It&amp;#8217;s like a &lt;code&gt;build.xml&lt;/code&gt; file, but written in Ruby, and baked by &lt;a href='http://rake.rubyforge.org/'&gt;Rake&lt;/a&gt;:&lt;/p&gt;

&lt;pre class='brush:ruby'&gt;&lt;code&gt;require &amp;#39;buildr/ivy_extension&amp;#39;

VERSION_NUMBER = ENV[&amp;#39;version&amp;#39;] || &amp;#39;SNAPSHOT&amp;#39;

repositories.remote &amp;lt;&amp;lt; &amp;quot;http://www.ibiblio.org/maven2/&amp;quot;
repositories.release_to = &amp;#39;sftp://joist.ws/var/joist.repo&amp;#39;
repositories.release_to[:permissions] = 0644

# to resolve the ${version} in the ivy.xml
Java.java.lang.System.setProperty(&amp;quot;version&amp;quot;, VERSION_NUMBER)

define &amp;quot;pageobjects&amp;quot; do
  project.version = VERSION_NUMBER
  project.group = &amp;#39;com.bizo&amp;#39;
  ivy.compile_conf(&amp;#39;compile&amp;#39;)

  package_with_sources

  package(:jar).pom.tap do |pom|
    pom.enhance [task(&amp;#39;ivy:makepom&amp;#39;)]
    pom.from &amp;#39;target/pom.xml&amp;#39;
  end
end&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Things to note:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;You pass in the version number with an environment variable, e.g. &lt;code&gt;version=x.y buildr upload&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;The line &lt;code&gt;repositories.remote &amp;lt;&amp;lt; ...&lt;/code&gt; is there because even though we use Ivy to get the project&amp;#8217;s actual dependencies, Buildr still needs the standard Maven repo to bootstrap dependencies from.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;&lt;code&gt;ivy.compile_conf(&amp;#39;compile&amp;#39;)&lt;/code&gt; is what glues the Ivy-fetched dependencies into Buildr&amp;#8217;s compile classpath. There is also a &lt;code&gt;test_conf&lt;/code&gt; method, e.g. &lt;code&gt;ivy.test_conf(&amp;#39;test&amp;#39;)&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;&lt;code&gt;package(:jar).pom.tap&lt;/code&gt; is a small 4-line hack to tell Buildr to run &lt;code&gt;ivy:makepom&lt;/code&gt; and that it&amp;#8217;s output (&lt;code&gt;target/pom.xml&lt;/code&gt;) will override Buildr&amp;#8217;s default pom file for our project&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id='thats_it'&gt;That&amp;#8217;s It&lt;/h2&gt;

&lt;p&gt;So, that is what is working well for me these days. I particularly like that my standard Buildr &lt;code&gt;buildfile&lt;/code&gt; is only ~20 lines long.&lt;/p&gt;

&lt;p&gt;For my &lt;a href='http://joist.ws'&gt;joist&lt;/a&gt; ORM project, I was able to use a ~50-line &lt;code&gt;buildfile&lt;/code&gt; to replace ~1200 lines of extremely boilerplate, copy/pasted Ant XML code.&lt;/p&gt;

&lt;p&gt;That was quite gratifying&amp;#8211;although, in retrospect, somewhat embarrassing that I had let that much Ant code accumulate and was still deluding myself that it was an acceptable setup.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Why I'm a Static Typing Bigot</title>
   <link href="http://draconianoverlord.com/2010/11/24/why-im-a-static-typing-bigot.html"/>
   <updated>2010-11-24T00:00:00-08:00</updated>
   <id>http://draconianoverlord.com/2010/11/24/why-im-a-static-typing-bigot</id>
   <content type="html">&lt;h1 id='why_im_a_static_typing_bigot'&gt;Why I&amp;#8217;m a Static Typing Bigot&lt;/h1&gt;

&lt;p&gt;As most anyone who has had a conversation about programming languages with me knows, I&amp;#8217;m a static typing bigot.&lt;/p&gt;

&lt;p&gt;Briefly, here&amp;#8217;s why.&lt;/p&gt;

&lt;h2 id='what_i_like_about_static_typing'&gt;What I Like About Static Typing&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Types act as documentation.&lt;/p&gt;

&lt;p&gt;When I read dynamically typed code, I feel completely lost looking at untyped variables and untyped method calls. What methods can I call on this variable? What does this method require of it&amp;#8217;s parameters? What exactly is this parameter going to be? A map? An object? An int?&lt;/p&gt;

&lt;p&gt;Granted, you can sometimes infer what it is based on the method calls made against it. For example, only the &lt;code&gt;Employee&lt;/code&gt; class has a &lt;code&gt;isFired&lt;/code&gt; method. However, this works well only in small, simple methods that are unfortunately rare in a lot of code.&lt;/p&gt;

&lt;p&gt;This programmer-time type inference also requires mental overhead. Glancing up to a type declaration (or hovering for inferred types) tells you right away.&lt;/p&gt;

&lt;p&gt;I do not buy the assertion that I should not care what the types of variables are&amp;#8211;that, like Smalltalk, objects will react to whatever messages I send them and I shouldn&amp;#8217;t care beyond that. While &lt;code&gt;method_missing&lt;/code&gt; is occasionally very handy, in the majority of cases, simple method resolution semantics are going to be happen (&lt;code&gt;foo.bar()&lt;/code&gt; calls the &lt;code&gt;Foo.bar&lt;/code&gt; method), so the language might as well clue me when when this extremely common/simple case applies.&lt;/p&gt;

&lt;p&gt;(Admittedly, I do pine for the static equivalent of &lt;code&gt;method_missing&lt;/code&gt;&amp;#8211;some sort of AST transformation or compile-time &lt;code&gt;method_missing&lt;/code&gt; hook.)&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;A type system provides free, blazing-fast, pre-unit tests.&lt;/p&gt;

&lt;p&gt;Of course you still need real unit tests. Just like having unit tests doesn&amp;#8217;t not absolve you from having acceptance tests, having type check tests does not absolve you from having unit tests.&lt;/p&gt;

&lt;p&gt;That being said, it&amp;#8217;s all about quick feedback. No matter how fast my unit tests are, a compiler can follow me along and more quickly check for trivial errors. In a mature IDE like Eclipse&amp;#8217;s JDT, this happens as you type, which is pretty darn quick.&lt;/p&gt;

&lt;p&gt;Assuming the type tests check, then you proceed to unit tests. Just like after unit tests check, you proceed to integration tests. Gradually progressing to slower, but more encompassing levels of tests.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Deep down all programmers want the features of a type-aware IDE.&lt;/p&gt;

&lt;p&gt;Look at IntelliJ&amp;#8217;s &lt;a href='http://www.jetbrains.com/ruby/'&gt;RubyMine&lt;/a&gt; and Spring&amp;#8217;s &lt;a href='http://www.springsource.com/developer/grails'&gt;STS&lt;/a&gt; for Groovy. They make programmers who&amp;#8217;ve been using dynamic languages drool with their (inferred) type-aware hints, navigation, and refactoring.&lt;/p&gt;

&lt;p&gt;My assertion is that, if bolted-on type inference is such an awesome thing, shouldn&amp;#8217;t it just be spec&amp;#8217;d as part of the language, instead of leaving it up to ad hoc IDE implementations?&lt;/p&gt;

&lt;p&gt;Furthermore, if type inference (and meta-programming, per my next point) was part of the language, then the type-aware IDE could check your entire program, not just the parts that were normal/bland enough (no &lt;code&gt;instance_eval&lt;/code&gt;) for the IDE-based type inferencer to figure out.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Most dynamic meta programming is done relatively immediately at program startup time, and then things settle down and start to look more static in nature&amp;#8211;hence most of it could just as well be done at compile-time.&lt;/p&gt;

&lt;p&gt;To explain, I think a generic timeline for meta-programming is:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The programmer types input-program&lt;/li&gt;

&lt;li&gt;Meta-programming magic transforms input-program to result-program&lt;/li&gt;

&lt;li&gt;The result-program runs&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In dynamic languages, 2 is done at runtime, so is very coupled with 3, to where people consider them the same thing&amp;#8211;because they are. However, I naively think that 2 could run just as well at compile-time, after the programmer types, via compile-time meta-programming (AST transformations).&lt;/p&gt;

&lt;p&gt;For example, I think it is unlikely that, after ActiveRecord adds database columns to a model class, and ActiveSupport opens up String to add helper methods, after two weeks of uptime, there will suddenly be new methods popping up in &lt;code&gt;Employee&lt;/code&gt;, &lt;code&gt;String&lt;/code&gt;, or other classes.&lt;/p&gt;

&lt;p&gt;Furthermore, if meta-programming is done at compile-time, then the result-program is also available at compile-time. So now the compiler/type-aware IDE can type check your entire program, not just the parts that don&amp;#8217;t use runtime &lt;code&gt;method_missing&lt;/code&gt;, &lt;code&gt;instance_eval&lt;/code&gt; magic.&lt;/p&gt;

&lt;p&gt;(Note: I still think on-the-fly changing of code, e.g. via a console/debugger, etc., is a good thing, see the &amp;#8220;Other Notes&amp;#8221; section below.)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; This &lt;a href='http://gnuu.org/2010/12/13/too-lazy-to-type/'&gt;blog post&lt;/a&gt; by Loren Segal states this point much better than I do and includes links to papers/profiling results that back up the assertion.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id='what_i_dont_like_about_static_typing'&gt;What I Don&amp;#8217;t Like About Static Typing&lt;/h2&gt;

&lt;p&gt;However, even in my bigotry, I will definitely concede static languages have their downsides:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Type-aware IDEs (Eclipse plugins, IntelliJ, etc.) are hard and become barriers to entry.&lt;/p&gt;

&lt;p&gt;Compilers themselves, for either static or dynamic languages. are a very well-known, basically solved problem&amp;#8211;lots of books, parser libraries, etc. The compilation environment is a very static: take input text X and transform it into output code Y.&lt;/p&gt;

&lt;p&gt;IDEs, however, are really hard. The compilation environment is no longer static&amp;#8211;the IDE still transforms X to Y, but while transforming X to Y, it also has to put errors on the right line, squiggles under the right words, pop ups at the right place, cache the entire program&amp;#8217;s type data to provide instant navigation, and all while the user is flying around the source file changing things and trying to make the IDE developer&amp;#8217;s life a nightmare.&lt;/p&gt;

&lt;p&gt;Supposedly JVM-based languages can leverage Eclipse&amp;#8217;s existing IDE infrastructure. But from looking at the Groovy and Scala IDE plugin histories, it still takes a really long time to get solid, quick integration with the Eclipse JDT.&lt;/p&gt;

&lt;p&gt;Type-aware IDEs also stifle innovation as they become a barrier to entry for new languages. Designers of new languages can&amp;#8217;t just have a great language, with a great library, with a great community&amp;#8211;they also need to invest a very non-trivial amount of time into an Eclipse plugin.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Type systems are hard.&lt;/p&gt;

&lt;p&gt;Type theory is a very academic field. You don&amp;#8217;t see hobbyists sitting down and writing a new type system for their language over the weekend. But you see plenty of hobbyists sitting down and writing a new syntax for their language over the weekend.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Consequently, static languages always lag behind dynamic languages. Especially with regards to syntax.&lt;/p&gt;

&lt;p&gt;I wish static languages evolved at the rate that dynamic ones do, as I like shiny new things as much as the next programmer.&lt;/p&gt;

&lt;p&gt;This is mostly why I pine so much for compile-time meta-programming&amp;#8211;that it would hopefully allow similar, programmer-driven productivity enhancements without having to build a new language each time.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Type systems can be too constraining. I&amp;#8217;ll accept that they occasionally need to be circumvented for the better good.&lt;/p&gt;

&lt;p&gt;(However, I don&amp;#8217;t think needing to circumvent the type system maybe 5% (if that) of the time in your application means that the other, more normal, bland 95% of your program needs to also give up type checking.)&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Compile-time meta programming is still a fringe technique.&lt;/p&gt;

&lt;p&gt;Much to my chagrin, compile-time meta programming is not going to be in a mainstream static language anytime soon. Despite promising alternatives (&lt;a href='http://boo.codehaus.org'&gt;boo&lt;/a&gt;, &lt;a href='http://nemerle.org'&gt;nemerle&lt;/a&gt;, &lt;a href='http://projectlombok.org'&gt;lombok&lt;/a&gt;, &lt;a href='http://code.google.com/p/groovypptest'&gt;groovy++&lt;/a&gt;), it&amp;#8217;s lacking from more leading &amp;#8220;Java next&amp;#8221; contenders like &lt;a href='http://www.scala-lang.org'&gt;Scala&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id='other_notes'&gt;Other Notes&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Dynamic languages are well-known for their &amp;#8220;reload on the fly&amp;#8221; productivity. Code can be changed without restarting a process, leading to a faster feedback loop for developers.&lt;/p&gt;

&lt;p&gt;I think this is a great thing&amp;#8211;and that static languages really should be able to do this as well. Unfortunately, for the JVM anyway, until this &lt;a href='http://wikis.sun.com/display/mlvm/HotSwap'&gt;OpenJDK patch&lt;/a&gt; lands, you need &lt;a href='http://www.zeroturnaround.com/jrebel'&gt;JRebel&lt;/a&gt; or framework-level classloader gymnastics to get more than the JVM&amp;#8217;s default &amp;#8220;only method contents can be updated&amp;#8221; behavior. Yeah, this is unfortunate, but a &lt;em&gt;cough&lt;/em&gt; temporary &lt;em&gt;cough&lt;/em&gt; limitation.&lt;/p&gt;

&lt;p&gt;For static languages, applying the type changes, especially if any compile-time meta-programming is involved, likely means using an IDE debugger to change running types, instead of the &amp;#8220;just retype the function in a console&amp;#8221; approach some dynamic languages can use. But I think the effect is the same.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Dynamic languages often have better designed libraries.&lt;/p&gt;

&lt;p&gt;Java in particular is known for it&amp;#8217;s ugly APIs. However, very often, the problem is just that an API lacks higher levels of abstraction, and is not related an inherent language flaw.&lt;/p&gt;

&lt;p&gt;For example, besides the typical Apache &lt;a href='http://commons.apache.org/io/api-1.4/org/apache/commons/io/FileUtils.html'&gt;commons-io&lt;/a&gt; library, Rickard has an elegant alternative &lt;a href='http://www.jroller.com/rickard/entry/a_generic_input_output_api'&gt;I/O API&lt;/a&gt; to the frequently-cited &amp;#8220;I can&amp;#8217;t succinctly read a file from Java&amp;#8221; problem.&lt;/p&gt;

&lt;p&gt;Perhaps there is a larger reason why dynamic languages have nice APIs, though my cop out assertion is just that their language designers are better at API design.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Language implementation choice is a very minor factor in resulting code quality.&lt;/p&gt;

&lt;p&gt;Perhaps I should have written this up-front as a disclaimer, but I&amp;#8217;ve read very good, good, bad, and very (very) bad code in both dynamic and static languages.&lt;/p&gt;

&lt;p&gt;So, admittedly, the type checks, IDE tooling, etc. is quibbling, because a good programmer should be able to produce good code in either type of language.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id='over_emphasis'&gt;Over Emphasis&lt;/h2&gt;

&lt;p&gt;I don&amp;#8217;t think I have added anything interesting to the dynamic vs. static debate, though that wasn&amp;#8217;t my intent&amp;#8211;I just wanted to codify my opinion.&lt;/p&gt;

&lt;p&gt;I do have a gnawing suspicion that most users of dynamic languages would, without realizing it now, prefer a static language, if there existed a sufficiently robust static language with a syntax, type system, and runtime that would allow them to keep their current style of development.&lt;/p&gt;

&lt;p&gt;That being said, there are several developers I respect who are more self-aware than this, and still love dynamic languages.&lt;/p&gt;

&lt;p&gt;Which probably just means I put too much emphasis on static vs. dynamic typing debates.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>GWT Handler Registrations</title>
   <link href="http://draconianoverlord.com/2010/11/23/gwt-handlers.html"/>
   <updated>2010-11-23T00:00:00-08:00</updated>
   <id>http://draconianoverlord.com/2010/11/23/gwt-handlers</id>
   <content type="html">&lt;h1 id='gwt_handler_registrations'&gt;GWT Handler Registrations&lt;/h1&gt;

&lt;p&gt;Being a fat-client technology, GWT involves a lot of event listeners. The idiom for using them is pretty simple:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;widget.addValueChangeHandler(
  new ValueChangeHandler&amp;lt;String&amp;gt;() {
    public void onValueChange(ValueChangeEvent&amp;lt;String&amp;gt; event) {
      // do logic here
    }
  }
);&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;One interesting question is what to do with the &lt;code&gt;HandlerRegistration&lt;/code&gt; return value of the &lt;code&gt;addValueChangeHandler&lt;/code&gt; method:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;HandlerRegistration r = widget.addValueChangeHandler(
  new ValueChangeHandler&amp;lt;String&amp;gt;() {
    public void onValueChange(ValueChangeEvent&amp;lt;String&amp;gt; event) {
      // do logic here
    }
  }
);
// when do you call this?
r.removeHandler();&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id='is_calling__required'&gt;Is Calling &lt;code&gt;removeHandler()&lt;/code&gt; Required?&lt;/h2&gt;

&lt;p&gt;There are two relative points about calling &lt;code&gt;removeHandler()&lt;/code&gt; on a &lt;code&gt;HandlerRegistration&lt;/code&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;removeHandler&lt;/code&gt; is never required to avoid DOM-/browser-level memory leaks.&lt;/p&gt;

&lt;p&gt;Per &lt;a href='http://code.google.com/p/google-web-toolkit/wiki/UnderstandingMemoryLeaks'&gt;UnderstandingMemoryLeaks&lt;/a&gt; in the GWT docs, GWT&amp;#8217;s event system ensures that you&amp;#8217;ll never end up with circular references between your event handlers and unattached DOM elements.&lt;/p&gt;

&lt;p&gt;In either &lt;code&gt;Widget.onDetach&lt;/code&gt; or page unload, GWT will clean up the DOM event listeners so that garbage collections can happen.&lt;/p&gt;

&lt;p&gt;So, it&amp;#8217;s tempting to think &lt;code&gt;removeHandler&lt;/code&gt; is a quaint but unnecessary capability. However:&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;&lt;code&gt;removeHandler&lt;/code&gt; is required to avoid application-level memory leaks.&lt;/p&gt;

&lt;p&gt;If you have a &amp;#8220;global&amp;#8221; event source, like an always-visible navigation bar widget or an application-wide &lt;code&gt;EventBus&lt;/code&gt;, and you have a transient event listener, like a presenter listening for events, the presenter&amp;#8217;s event handler will keep it from being garbage collected until the &lt;code&gt;EventBus&lt;/code&gt; is also garbage collected.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For example, if you have a &lt;code&gt;FooPlacePresenter&lt;/code&gt; in a framework like &lt;a href='http://www.tessell.org'&gt;Tessell&lt;/a&gt;:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public class FooPlacePresenter {
  public void onBind() {
    super.onBind();
    eventBus.addHandler(
      BlahEvent.getType(),
      new BlahEventHandler() { ... });
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Each time the user visits the &lt;code&gt;#foo&lt;/code&gt; place, a new instance of &lt;code&gt;FooPlacePresenter&lt;/code&gt; will get created and it will start listening for &lt;code&gt;BlahEvent&lt;/code&gt;s on the application-wide &lt;code&gt;EventBus&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;When the user navigates away from &lt;code&gt;#foo&lt;/code&gt;, the &lt;code&gt;FooPlacePresenter&lt;/code&gt; instance should be garbage collected, so that the memory is freed up for the next place in your application the user visits.&lt;/p&gt;

&lt;p&gt;However, because of &lt;code&gt;FooPlacePresenter&lt;/code&gt;&amp;#8217;s &lt;code&gt;BlahEventHandler&lt;/code&gt; that did not get unregistered, the &lt;code&gt;EventBus&lt;/code&gt; still thinks &lt;code&gt;FooPlacePresenter&lt;/code&gt; is interested in &lt;code&gt;BlahEvent&lt;/code&gt;s, and so the presenter instance will not be garbage collected.&lt;/p&gt;

&lt;p&gt;After a while of in-application navigation, you could potentially have a lot of presenter instances kept in memory due to their handlers listening on the application-wide event bus.&lt;/p&gt;

&lt;h2 id='what_to_think_about'&gt;What To Think About&lt;/h2&gt;

&lt;p&gt;To avoid application-level memory leaks, when adding event handlers, you need to think about:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What is the scope of the event source (the widget or the &lt;code&gt;EventBus&lt;/code&gt;)?&lt;/li&gt;

&lt;li&gt;What is the scope of the event handler (the presenter)?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And then:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If the scopes are the same: you can ignore the &lt;code&gt;HandlerRegistration&lt;/code&gt; and trust that GWT/the garbage collection will clean things up for you.&lt;/li&gt;

&lt;li&gt;If the handler scope is longer-lived than the source scope: the handler would keep the source in memory, so you need to call &lt;code&gt;removeHandler()&lt;/code&gt; when appropriate.&lt;/li&gt;

&lt;li&gt;If the source scope is longer-lived than the handler scope: the source would keep the handler in memory, so you also need to call &lt;code&gt;removeHandler()&lt;/code&gt; when appropriate.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id='be_proactive'&gt;Be Proactive&lt;/h2&gt;

&lt;p&gt;You should also take steps to pro-actively avoid application-level memory leaks.&lt;/p&gt;

&lt;p&gt;The best way to do this is to avoid directly exposing application-scoped event sources to place-scoped presenters. If place-scoped code is unable to attach directly to applicate-scoped sources, it will be impossible for place handlers to stay in memory longer than they should.&lt;/p&gt;

&lt;p&gt;For example, GWT 2.1 uses this in its &lt;code&gt;ActivityManager&lt;/code&gt; implementation. Instead of handing the application-wide &lt;code&gt;EventBus&lt;/code&gt; directly to an activity, it wraps the &lt;code&gt;EventBus&lt;/code&gt; in a &lt;code&gt;ResettableEventBus&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ResettableEventBus&lt;/code&gt; keeps tracks of any handlers the current activity registers, and then when that activity is done, the &lt;code&gt;ActivityManager&lt;/code&gt; calls &lt;code&gt;ResettableEventBus&lt;/code&gt; &lt;code&gt;removeHandlers()&lt;/code&gt; to forcibly remove the old activity&amp;#8217;s handlers from the &lt;code&gt;EventBus&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now the activity doesn&amp;#8217;t have to worry about calling &lt;code&gt;removeHandler()&lt;/code&gt; on either its widgets or the &lt;code&gt;EventBus&lt;/code&gt;, so it&amp;#8217;s much less boilerplate and not as prone to programmer error. Both are big wins.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Doubting GMail-style Loading Indicators</title>
   <link href="http://draconianoverlord.com/2010/08/30/doubting-gmail-style-indicators.html"/>
   <updated>2010-08-30T00:00:00-07:00</updated>
   <id>http://draconianoverlord.com/2010/08/30/doubting-gmail-style-indicators</id>
   <content type="html">&lt;h1 id='doubting_gmailstyle_loading_indicators'&gt;Doubting GMail-style Loading Indicators&lt;/h1&gt;

&lt;p&gt;While building &lt;a href='http://www.bizo.com'&gt;Bizo&lt;/a&gt;&amp;#8217;s &lt;a href='http://bizads.bizo.com'&gt;Bizads&lt;/a&gt; application, I occasionally looked to other AJAX applications for UI styles and patterns to reuse. I am not a UI/UX expert, so searching out best practice seemed like a pragmatic approach.&lt;/p&gt;

&lt;p&gt;One pattern that seemed like a sure thing was the GMail-style orange &amp;#8220;Loading&amp;#8230;&amp;#8221; box that pops in/out at the top of the page in GMail while you&amp;#8217;re switching labels. It also shows up in Google Reader when switching feeds.&lt;/p&gt;

&lt;p&gt;For Bizads, it ended up looking like:&lt;/p&gt;
&lt;img src='/images/screenshot-loggingIn.png' style='border: 1px solid black; margin-left: auto; margin-right: auto; width: 600px; display: block;' /&gt;
&lt;p&gt;I was originally attracted to it for a few reasons:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;It gives the user a single &amp;#8220;the app is doing stuff&amp;#8221; place to look&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;It gives the dev a single &amp;#8220;the app is doing stuff&amp;#8221; place to implement.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So I implemented the global indicator in Bizads, asserting to myself that &amp;#8220;oh, yes, this is for the user&amp;#8217;s benefit&amp;#8211;GMail does it, they&amp;#8217;ll know the convention&amp;#8221;.&lt;/p&gt;

&lt;p&gt;However, I think in reality what attracted me most to the pattern was really the second reason&amp;#8211;it made life easier for me as a developer.&lt;/p&gt;

&lt;p&gt;With the global indicator, I no longer had to code boilerplate loading/spinning indicator logic for every button in the app. Which, given I was brand new to AJAX development, I&amp;#8217;d been doing in kind of an ad hoc way.&lt;/p&gt;

&lt;p&gt;Better yet, using &lt;a href='http://code.google.com/p/gwt-dispatch/'&gt;gwt-dispatch&lt;/a&gt;-style RPC commands, and &lt;a href='http://www.tessell.org'&gt;Tessell&lt;/a&gt;&amp;#8217;s &lt;a href='http://github.com/stephenh/tessell/tree/master/user/src/main/java/org/tessell/dispatch/client/events/'&gt;DispatchXxx&lt;/a&gt; events, I had one centralized class that, by listening to the event bus, could automatically handle &amp;#8220;command went out, show indicator&amp;#8221; and then &amp;#8220;response came back, hide indicator&amp;#8221;. One place, done.&lt;/p&gt;

&lt;p&gt;It was really nice as it let me be lazy and stop thinking about indicators all the time.&lt;/p&gt;

&lt;p&gt;That being said, I think it was the wrong choice. In retrospect, I have three complaints about a global indicator:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;It jars the user&amp;#8217;s focus away from where they are expecting the action to occur.&lt;/p&gt;

&lt;p&gt;In GMail, you click &amp;#8220;Inbox&amp;#8221;, your eyes jump to that section of the page in anticipation&amp;#8211;having loading elsewhere on the screen is not what you expected.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;The global indicator is hard to get right&amp;#8211;a naive implementation will show/hide it as soon as RPC/AJAX calls go out/come back. This results in a harsh flashing that, besides distracting the user, risks that most non-tech-savvy users will not even see it.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;The global indicator pattern breaks down as soon as you have multiple activities happening at the same time.&lt;/p&gt;

&lt;p&gt;If you let the user have some sort of multi-document/multi-view in your application, you could legitimately have multiple outstanding AJAX calls. To have these both queue up in the global indicator seems confusing and would potentially become bulky.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;All of these problems, I think, can be solved by keeping the loading indicator in context.&lt;/p&gt;

&lt;p&gt;If a button press led to the action, the indicator should go by that button. If a table is loading its rows, the indicator should be in the table table (which is what the GWT 2.1 &lt;code&gt;CellTable&lt;/code&gt; does).&lt;/p&gt;

&lt;p&gt;This might be more work for the developer, but I think it would end up being pretty simple once higher levels of abstraction are applied. E.g. the button widget should be a composite that automatically knows how to show/hide its indicator while work is being done.&lt;/p&gt;

&lt;p&gt;I have not flushed these abstractions out yet, so I can&amp;#8217;t be sure how elegant they will end up being. But so far I&amp;#8217;m optimistic.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Joist Tip&ndash;Fast Database Resets</title>
   <link href="http://draconianoverlord.com/2010/08/22/joist-tip-fast-database-resets.html"/>
   <updated>2010-08-22T00:00:00-07:00</updated>
   <id>http://draconianoverlord.com/2010/08/22/joist-tip-fast-database-resets</id>
   <content type="html">&lt;h1 id='joist_tipfast_database_resets'&gt;Joist Tip&amp;#8211;Fast Database Resets&lt;/h1&gt;

&lt;p&gt;I reread parts of &lt;a href='http://www.amazon.com/Growing-Object-Oriented-Software-Guided-Tests/dp/0321503627'&gt;Growing Object-Oriented Software, Guided by Tests&lt;/a&gt; (GOOS) today. The verbose name aside, it&amp;#8217;s a great book.&lt;/p&gt;

&lt;p&gt;I also like it because they share my opinion that persistence tests must commit to the database to be worthwhile. Yes!&lt;/p&gt;

&lt;h2 id='abusing_transactions_for_resetting_test_data'&gt;Abusing Transactions for Resetting Test Data&lt;/h2&gt;

&lt;p&gt;Ruby on Rails, as nice as it is, seems to have popularized this notion that you can leverage transactions to get relatively quick database tests&amp;#8211;instead of having to delete data after each test, you run the each test in its own transaction, and then roll the transaction back before continuing on to the next test.&lt;/p&gt;

&lt;p&gt;This allows each test to have a clean database&amp;#8211;which is very good for test independence and reproducibility. And rolling back uncommitted data is, admittedly, really fast.&lt;/p&gt;

&lt;p&gt;But it also means that any commit-time persistence logic is being skipped&amp;#8211;foreign key constraints, unique constraints, etc. Which, unless you&amp;#8217;re just testing queries, is kind of the point of the test being a persistence test.&lt;/p&gt;

&lt;p&gt;This approach also assumes that your test is not exercising any code that does its own transaction management. Depending on the feature/architecture, this may/may not be a good assumption&amp;#8211;but it is definitely not always true.&lt;/p&gt;

&lt;p&gt;So we need to find another way to get a clean database, preferably as quickly as possible.&lt;/p&gt;

&lt;h2 id='domainlevel_resetting_test_data'&gt;Domain-Level Resetting Test Data&lt;/h2&gt;

&lt;p&gt;What GOOS suggests is a pretty common pattern of allowing each test to commit its data, and then in &lt;code&gt;setUp&lt;/code&gt;, iterating over your domain objects to explicitly delete them:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;for (Class domainClass : someListOfDomainClasses) {
  persistenceLayer.deleteAll(domainClass);
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This can be a little tricky as you don&amp;#8217;t want to trigger any foreign key constraints if you, say, delete the &lt;code&gt;FooParent&lt;/code&gt; rows before the &lt;code&gt;FooChild&lt;/code&gt; rows that have foreign keys to them. The usual hack is something like &lt;code&gt;set foreign_key_constraints=0&lt;/code&gt; for MySQL or deferred key constraints for PostgreSQL.&lt;/p&gt;

&lt;p&gt;A large system I worked on used this technique, and it works well. However, as the system grew, things started to slow down. With 500+ tables, calling &lt;code&gt;delete * from table&lt;/code&gt; for each table, before each test, adds up to a lot of SQL statements going over the wire.&lt;/p&gt;

&lt;h2 id='databaselevel_resetting_test_data'&gt;Database-Level Resetting Test Data&lt;/h2&gt;

&lt;p&gt;To minimize the amount of SQL calls involved in a reset, we can go a level closer to the data and use a stored procedure to do database-level resetting of test data.&lt;/p&gt;

&lt;p&gt;While I&amp;#8217;m not usually a fan of stored procedures, in this case, it makes sense&amp;#8211;there is 1 SQL call to kick off a slew of database operations:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;// postgres
execute(&amp;quot;select * from flush_test_database()&amp;quot;);

// mysql
execute(&amp;quot;call flush_test_database()&amp;quot;);&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The stored procedure then executes the 500+ &lt;code&gt;delete&lt;/code&gt; calls directly against the database.&lt;/p&gt;

&lt;p&gt;This is pretty easy to setup, especially if you generate the stored procedure an at opportune time in the developer&amp;#8217;s workflow.&lt;/p&gt;

&lt;p&gt;For example, &lt;a href='http://joist.ws'&gt;Joist&lt;/a&gt; is an ORM purpose-built for large schemas. It already has a build-time code generator that generates the boilerplate aspects of domain objects by introspecting the database schema. After doing so, it is easy to add a final step that also creates the &lt;code&gt;flush_test_database&lt;/code&gt; stored procedure.&lt;/p&gt;

&lt;h2 id='postgres_implementation'&gt;Postgres Implementation&lt;/h2&gt;

&lt;p&gt;The stored procedure for Postgres looks like:&lt;/p&gt;

&lt;pre class='brush:sql'&gt;&lt;code&gt;CREATE OR REPLACE FUNCTION flush_test_database() RETURNS integer AS
$BODY$
BEGIN
SET CONSTRAINTS ALL DEFERRED;
-- repeated for each domain class
ALTER SEQUENCE domain_table RESTART WITH 1 INCREMENT BY 1;
DELETE FROM domain_table;
RETURN 0;
END;
$BODY$
  LANGUAGE &amp;#39;plpgsql&amp;#39; VOLATILE
  COST 100;
ALTER FUNCTION flush_test_database() SECURITY DEFINER;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Note that the &lt;code&gt;SECURITY DEFINER&lt;/code&gt; part is important as it will allow callers of the stored procedure (e.g. your application&amp;#8217;s database user) to alter sequences that it does not own (e.g. because they are owned by the root &lt;code&gt;postgres&lt;/code&gt; user).&lt;/p&gt;

&lt;p&gt;See &lt;a href='http://github.com/stephenh/joist/blob/master/migrations/src/main/java/joist/codegen/passes/GenerateFlushFunction.java'&gt;GenerateFlushFunction.java&lt;/a&gt; for the exact code.&lt;/p&gt;

&lt;h2 id='mysql_implementation'&gt;MySQL Implementation&lt;/h2&gt;

&lt;p&gt;MySQL is even easier as &lt;code&gt;TRUNCATE TABLE&lt;/code&gt; resets the auto increment column:&lt;/p&gt;

&lt;pre class='brush:sql'&gt;&lt;code&gt;CREATE PROCEDURE flush_test_database()
BEGIN
SET FOREIGN_KEY_CHECKS=0;
-- repeated for each domain class
TRUNCATE TABLE domain_table;
SET FOREIGN_KEY_CHECKS=1;
SELECT 1;
END&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Again, you can see &lt;a href='http://github.com/stephenh/joist/blob/master/migrations/src/main/java/joist/codegen/passes/GenerateFlushFunction.java'&gt;GenerateFlushFunction.java&lt;/a&gt; for the exact code.&lt;/p&gt;

&lt;h2 id='time_savings'&gt;Time Savings&lt;/h2&gt;

&lt;p&gt;On a 500+ table schema, domain-level resetting with 1-call-per-table takes ~200ms.&lt;/p&gt;

&lt;p&gt;Against the same schema, database-level resetting with just 1 call takes ~5ms.&lt;/p&gt;

&lt;p&gt;So we save ~1/5th of a second. This is not a lot&amp;#8211;until you have a huge test suite. If you have 5000 persistence tests, that&amp;#8217;s ~16 minutes saved off your test suite runtime.&lt;/p&gt;

&lt;h2 id='limited_applicability'&gt;Limited Applicability&lt;/h2&gt;

&lt;p&gt;Thankfully, few projects get big enough to need this level of optimization. And, pessimistically, if they do, shaving 15 minutes off their build time is usually the least of their concerns. :-)&lt;/p&gt;

&lt;p&gt;Nonetheless, &lt;a href='http://joist.ws'&gt;Joist&lt;/a&gt; tries to get things like this right, to make your next enterprise project that much less painful.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>git workshop</title>
   <link href="http://draconianoverlord.com/2010/08/21/git-workshop.html"/>
   <updated>2010-08-21T00:00:00-07:00</updated>
   <id>http://draconianoverlord.com/2010/08/21/git-workshop</id>
   <content type="html">&lt;h1 id='git_workshop'&gt;git workshop&lt;/h1&gt;

&lt;p&gt;A few weeks ago I helped out with a git workshop at the &lt;a href='http://jays.net/wiki/ODynUG'&gt;Omaha Dynamic Languages User Group&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The format was a &amp;#8220;hands on lab&amp;#8221; where people installed git on their local machines and ran through a series of &lt;a href='http://www.draconianoverlord.com/git-workshop.html'&gt;canned scenarios&lt;/a&gt; to introduce them to the various git commands. &lt;code&gt;add&lt;/code&gt;, &lt;code&gt;diff&lt;/code&gt;, &lt;code&gt;reset&lt;/code&gt;, &lt;code&gt;merge&lt;/code&gt;, &lt;code&gt;rebase&lt;/code&gt;, etc.&lt;/p&gt;

&lt;p&gt;Jay Hannah said a few members had suggested the lab format, and I think it went really well.&lt;/p&gt;

&lt;p&gt;I have a tendency to try and explain things from the high/theoretical level, but sometimes it&amp;#8217;s better to just ignore that and simply use a tool or practice for awhile. Then after you have some experience and context to work from, the high/theoretical level is much easier to grasp.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Joist vs. Hibernate SQL</title>
   <link href="http://draconianoverlord.com/2010/08/15/joist-vs-hibernate-sql.html"/>
   <updated>2010-08-15T00:00:00-07:00</updated>
   <id>http://draconianoverlord.com/2010/08/15/joist-vs-hibernate-sql</id>
   <content type="html">&lt;h1 id='joist_vs_hibernate_sql'&gt;Joist vs. Hibernate SQL&lt;/h1&gt;

&lt;p&gt;Lately I&amp;#8217;ve been mulling how/whether to implement &lt;a href='http://www.draconianoverlord.com/2010/07/16/orm-prefetching.html'&gt;prefetching&lt;/a&gt; in &lt;a href='http://joist.ws/orm.html'&gt;Joist&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To explore the idea, I tried out Hibernate&amp;#8217;s subselect prefetching functionality, and it works really well.&lt;/p&gt;

&lt;p&gt;But I&amp;#8217;ve been using Joist for long enough now that I had forgotten what Hibernate&amp;#8217;s SQL looks like. And how I&amp;#8217;ve tweaked Joist to, out-of-the-box, just do things intelligently (especially for Postgres).&lt;/p&gt;

&lt;p&gt;For example, my test case was inputting 1 parent, 2 children, and 4 grandchildren in an object graph, to see what the SELECTs would look like.&lt;/p&gt;

&lt;p&gt;Here&amp;#8217;s Hibernate (using &lt;code&gt;hibernate.show_sql=true&lt;/code&gt;):&lt;/p&gt;

&lt;pre class='brush:sql'&gt;&lt;code&gt;select nextval (&amp;#39;parent_id_seq&amp;#39;)
select nextval (&amp;#39;child_id_seq&amp;#39;)
select nextval (&amp;#39;grand_child_id_seq&amp;#39;)
select nextval (&amp;#39;grand_child_id_seq&amp;#39;)
select nextval (&amp;#39;child_id_seq&amp;#39;)
select nextval (&amp;#39;grand_child_id_seq&amp;#39;)
select nextval (&amp;#39;grand_child_id_seq&amp;#39;)
insert into &amp;quot;parent&amp;quot; (version, &amp;quot;name&amp;quot;, id) values (?, ?, ?)
insert into &amp;quot;child&amp;quot; (version, &amp;quot;parent_id&amp;quot;, &amp;quot;name&amp;quot;, id) values (?, ?, ?, ?)
insert into &amp;quot;grand_child&amp;quot; (version, &amp;quot;child_id&amp;quot;, &amp;quot;name&amp;quot;, id) values (?, ?, ?, ?)
insert into &amp;quot;grand_child&amp;quot; (version, &amp;quot;child_id&amp;quot;, &amp;quot;name&amp;quot;, id) values (?, ?, ?, ?)
insert into &amp;quot;child&amp;quot; (version, &amp;quot;parent_id&amp;quot;, &amp;quot;name&amp;quot;, id) values (?, ?, ?, ?)
insert into &amp;quot;grand_child&amp;quot; (version, &amp;quot;child_id&amp;quot;, &amp;quot;name&amp;quot;, id) values (?, ?, ?, ?)
insert into &amp;quot;grand_child&amp;quot; (version, &amp;quot;child_id&amp;quot;, &amp;quot;name&amp;quot;, id) values (?, ?, ?, ?)
select
   parent0_.id as id0_0_,
   parent0_.version as version0_0_,
   parent0_.&amp;quot;name&amp;quot; as name3_0_0_
   from &amp;quot;parent&amp;quot; parent0_
   where parent0_.id=?
select
  childs0_.parent_id as parent3_1_,
  childs0_.id as id1_,
  childs0_.id as id1_0_,
  childs0_.version as version1_0_,
  childs0_.&amp;quot;parent_id&amp;quot; as parent3_1_0_,
  childs0_.&amp;quot;name&amp;quot; as name4_1_0_
  from &amp;quot;child&amp;quot; childs0_
  where childs0_.parent_id=?
select
  grandchild0_.child_id as child3_1_,
  grandchild0_.id as id1_,
  grandchild0_.id as id2_0_,
  grandchild0_.version as version2_0_,
  grandchild0_.&amp;quot;child_id&amp;quot; as child3_2_0_,
  grandchild0_.&amp;quot;name&amp;quot; as name4_2_0_
  from &amp;quot;grand_child&amp;quot; grandchild0_
  where grandchild0_.child_id in (
    select childs0_.id
    from &amp;quot;child&amp;quot; childs0_
    where childs0_.parent_id=?
  )&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And here&amp;#8217;s joist (using &lt;code&gt;joist.jdbc=TRACE&lt;/code&gt;):&lt;/p&gt;

&lt;pre class='brush:sql'&gt;&lt;code&gt;select nextval(&amp;#39;parent_id_seq&amp;#39;)
  UNION ALL select nextval(&amp;#39;child_id_seq&amp;#39;)
  UNION ALL select nextval(&amp;#39;child_id_seq&amp;#39;)
  UNION ALL select nextval(&amp;#39;grand_child_id_seq&amp;#39;)
  UNION ALL select nextval(&amp;#39;grand_child_id_seq&amp;#39;)
  UNION ALL select nextval(&amp;#39;grand_child_id_seq&amp;#39;)
  UNION ALL select nextval(&amp;#39;grand_child_id_seq&amp;#39;)
  UNION ALL select nextval(&amp;#39;grand_child_id_seq&amp;#39;)
  UNION ALL select nextval(&amp;#39;grand_child_id_seq&amp;#39;)
INSERT INTO &amp;quot;parent&amp;quot; (&amp;quot;id&amp;quot;, &amp;quot;name&amp;quot;, &amp;quot;version&amp;quot;) VALUES (?, ?, ?)
  -- [TRACE] parameters = [1, p, 0]
INSERT INTO &amp;quot;child&amp;quot; (&amp;quot;id&amp;quot;, &amp;quot;name&amp;quot;, &amp;quot;version&amp;quot;, &amp;quot;parent_id&amp;quot;) VALUES (?, ?, ?, ?)
  -- [TRACE] parameters = [1, child.0, 0, 1]
  -- [TRACE] parameters = [2, child.1, 0, 1]
INSERT INTO &amp;quot;grand_child&amp;quot; (&amp;quot;id&amp;quot;, &amp;quot;name&amp;quot;, &amp;quot;version&amp;quot;, &amp;quot;child_id&amp;quot;) VALUES (?, ?, ?, ?)
  -- [TRACE] parameters = [1, grandchild.0.0, 0, 1]
  -- [TRACE] parameters = [2, grandchild.0.1, 0, 1]
  -- [TRACE] parameters = [3, grandchild.0.2, 0, 1]
  -- [TRACE] parameters = [4, grandchild.1.0, 0, 2]
  -- [TRACE] parameters = [5, grandchild.1.1, 0, 2]
  -- [TRACE] parameters = [6, grandchild.1.2, 0, 2]
SELECT p.id, p.name, p.version
  FROM &amp;quot;parent&amp;quot; p
  WHERE p.id = ?
SELECT c.id, c.name, c.version, c.parent_id
  FROM &amp;quot;child&amp;quot; c
  WHERE c.parent_id = ?
  ORDER BY c.id
SELECT gc.id, gc.name, gc.version, gc.child_id
  FROM &amp;quot;grand_child&amp;quot; gc
  WHERE gc.child_id = ?
  ORDER BY gc.id
SELECT gc.id, gc.name, gc.version, gc.child_id
  FROM &amp;quot;grand_child&amp;quot; gc
  WHERE gc.child_id = ?
  ORDER BY gc.id&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So, Hibernate had 17 SQL statements, Joist had 8 SQL statements, ~50% less.&lt;/p&gt;

&lt;p&gt;This can be a big difference since each SQL statement is typically another over-the-wire network call to the database server.&lt;/p&gt;

&lt;p&gt;Granted, this is just Joist taking advantage of Postgres&amp;#8217;s sequences and so batch-assigning and batch-inserting new instances. (Although Joist does a similar optimization with MySQL, batching inserts and using &lt;code&gt;getGeneratedKeys&lt;/code&gt; to return all of the new ids).&lt;/p&gt;

&lt;p&gt;The other difference is that Joist&amp;#8217;s SQL is purposefully as much &amp;#8220;like-a-human-wrote-it&amp;#8221; as possible. Some of Hibernate&amp;#8217;s generated SQL is just odd&amp;#8211;select both &lt;code&gt;child.id&lt;/code&gt; and &lt;code&gt;child.parent_id&lt;/code&gt; twice in the same &lt;code&gt;ResultSet&lt;/code&gt; for instance. Nothing that would really affect anything, but still odd.&lt;/p&gt;

&lt;p&gt;At the end though, Hibernate uses prefetching to reload all of the grandchildren with 1 SQL statement, where as Joist has to issue 2 separate &lt;code&gt;FROM grand_child&lt;/code&gt; queries for each &lt;code&gt;child_id&lt;/code&gt;. Per above, I don&amp;#8217;t have that implemented yet.&lt;/p&gt;

&lt;p&gt;Joist can definitely never win feature-wise against Hibernate&amp;#8211;the crazy thing does about anything you could possibly want from an ORM. But the idea is that Joist can pick an opinionated subset of functionality, and do that really well. And so far that has been working out (for my subset, of course).&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Collecting User Actions with GWT</title>
   <link href="http://draconianoverlord.com/2010/08/13/gwt-user-actions.html"/>
   <updated>2010-08-13T00:00:00-07:00</updated>
   <id>http://draconianoverlord.com/2010/08/13/gwt-user-actions</id>
   <content type="html">&lt;h1 id='collecting_user_actions_with_gwt'&gt;Collecting User Actions with GWT&lt;/h1&gt;

&lt;p&gt;(Cross-posted from the Bizo &lt;a href='http://dev.bizo.com/2010/08/collecting-user-actions-with-gwt.html'&gt;dev blog&lt;/a&gt;.)&lt;/p&gt;

&lt;p&gt;While I was at one of the &lt;a href='http://code.google.com/events/io/2010/'&gt;Google I/O&lt;/a&gt; GWT sessions (courtesy of &lt;a href='http://www.bizo.com'&gt;Bizo&lt;/a&gt;), a Google presenter mentioned how one of their internal GWT applications tracks user actions.&lt;/p&gt;

&lt;p&gt;The idea is really just a souped-up, AJAX version of server-side access logs: capturing, buffering, and sending fine-grained user actions up to the server for later analysis.&lt;/p&gt;

&lt;p&gt;The Google team was using this data to make A/B-testing-style decisions about features&amp;#8211;which ones were being used, &lt;em&gt;not&lt;/em&gt; being used, tripping users up, etc.&lt;/p&gt;

&lt;p&gt;I thought the idea was pretty nifty, so I flushed out an initial implementation in &lt;a href='http://bizads.bizo.com'&gt;BizAds&lt;/a&gt; for &lt;a href='http://www.bizo.com'&gt;Bizo&amp;#8217;s&lt;/a&gt; recent hack day. And now I am documenting my wild success for &lt;a href='http://www.bizo.com'&gt;Bizo&amp;#8217;s&lt;/a&gt; first post-hack-day &amp;#8220;beer &amp;amp; blogs&amp;#8221; day.&lt;/p&gt;

&lt;h2 id='no_access_logs'&gt;No Access Logs&lt;/h2&gt;

&lt;p&gt;Traditional, page-based web sites typically use access logs for site analytics. For example, the user was on &lt;code&gt;a.html&lt;/code&gt;, then &lt;code&gt;b.html&lt;/code&gt;. Services like &lt;a href='http://www.google.com/analytics'&gt;Google Analytics&lt;/a&gt; can then slice and dice your logs to tell you interesting things.&lt;/p&gt;

&lt;p&gt;However, desktop-style one-page webapps don&amp;#8217;t generate these access logs&amp;#8211;the user is always on the first page&amp;#8211;so they must rely on something else.&lt;/p&gt;

&lt;p&gt;This is pretty normal for AJAX apps, and Google Analytics already supports it via its asynchronous API.&lt;/p&gt;

&lt;p&gt;We had already been doing this from GWT with code like:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public native void trackInGA(final String pageName) /*-{
  $wnd._gaq.push([&amp;#39;_trackPageview&amp;#39;, pageName]);
}-*/;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And since we&amp;#8217;re using a MVP/places-style architecture (see &lt;a href='http://www.tessell.org'&gt;Tessell&lt;/a&gt;), we just call this on each place change. Done.&lt;/p&gt;

&lt;p&gt;Google Analytics is back in action, not a big deal.&lt;/p&gt;

&lt;h2 id='beyond_access_logs'&gt;Beyond Access Logs&lt;/h2&gt;

&lt;p&gt;What was novel, to me, about this internal Google application&amp;#8217;s approach was how the tracked user actions were much more fine-grained than just &amp;#8220;page&amp;#8221; level.&lt;/p&gt;

&lt;p&gt;For example, which buttons the user hovers over. Which ones they click (even if it doesn&amp;#8217;t lead to a page load). What client-side validation messages are tripping them up. Any number of small &amp;#8220;intra-page&amp;#8221; things that are nonetheless useful to know.&lt;/p&gt;

&lt;p&gt;Obviously there are a few challenges, mostly around not wanting to detract from the user experience:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;How much data is too much?&lt;/p&gt;

&lt;p&gt;Tracking the mouse over of every element would be excessive. But the mouse over of key elements? Should be okay.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;How often to send the data?&lt;/p&gt;

&lt;p&gt;If you wait too long while buffering user actions before uploading them to the server, the user may leave the page and you&amp;#8217;ll lose them. (Unless you use a page unload hook, and the browser hasn&amp;#8217;t crashed.)&lt;/p&gt;

&lt;p&gt;If you send data too often, the user might get annoyed.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The key to doing this right is having metrics in place to know whether you&amp;#8217;re prohibitively affecting the user experience.&lt;/p&gt;

&lt;p&gt;The internal Google team had these metrics for their application, and that allowed them to start out batch uploading actions every 30 seconds, then every 20 seconds, and finally every 3 seconds. Each time they could tell the users&amp;#8217; experience was not adversely affected.&lt;/p&gt;

&lt;p&gt;Unfortunately, I don&amp;#8217;t know what exactly this metric was (I should have asked), but I imagine it&amp;#8217;s fairly application-specific&amp;#8211;think of GMail and average emails read/minute or something like that.&lt;/p&gt;

&lt;h2 id='implementation'&gt;Implementation&lt;/h2&gt;

&lt;p&gt;I was able to implement this concept rather easily, mostly by reusing existing infrastructure our GWT application already had.&lt;/p&gt;

&lt;p&gt;When interesting actions occur, I have the presenters fire a generic &lt;code&gt;UserActionEvent&lt;/code&gt;, which is generated using &lt;a href='http://github.com/stephenh/tessell/apt'&gt;tessell-apt&lt;/a&gt; from this spec:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;@GenEvent
public class UserActionEventSpec {
  @Param(1)
  String name;
  @Param(2)
  String value;
  @Param(3)
  boolean flushNow;
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Initiating the tracking an action is now just as simple as firing an event:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;UserActionEvent.fire(
   eventBus,
   &amp;quot;someAction&amp;quot;,
   &amp;quot;someValue&amp;quot;,
   false);&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I have a separate, decoupled &lt;code&gt;UserActionUploader&lt;/code&gt;, which is listening for these events and buffers them into a client-side list of &lt;code&gt;UserAction&lt;/code&gt; DTOs:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;private class OnUserAction implements UserActionHandler {
  public void onUserAction(final UserActionEvent event) {
    UserAction action = new UserAction();
    action.user = defaultString(getEmailAddress(), &amp;quot;unknown&amp;quot;);
    action.name = event.getName();
    action.value = event.getValue();
    actions.add(action);
    if (event.getFlushNow()) {
      flush();
    }
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;code&gt;UserActionUploader&lt;/code&gt; sets a timer that every 3 seconds calls &lt;code&gt;flush&lt;/code&gt;:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;private void flush() {
  if (actions.size() == 0) {
    return;
  }
  ArrayList&amp;lt;UserAction&amp;gt; copy =
    new ArrayList&amp;lt;UserAction&amp;gt;(actions);
  actions.clear();
  async.execute(
    new SaveUserActionAction(copy),
    new OnSaveUserActionResult());
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The &lt;code&gt;flush&lt;/code&gt; method uses &lt;a href='http://code.google.com/p/gwt-dispatch/'&gt;gwt-dispatch&lt;/a&gt;-style action/result classes, also generated by &lt;a href='http://github.com/stephenh/tessell/apt'&gt;tessell-apt&lt;/a&gt;, to the server via GWT-RPC:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;@GenDispatch
public class SaveUserActionSpec {
  @In(1)
  ArrayList&amp;lt;UserAction&amp;gt; actions;
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This results in &lt;code&gt;SaveUserActionAction&lt;/code&gt; (okay, bad name) and &lt;code&gt;SaveUserActionResult&lt;/code&gt; DTOs getting generated, with nice constructors, getters, setters, etc.&lt;/p&gt;

&lt;p&gt;On the server-side, I was able to reuse an excellent &lt;code&gt;DatalogManager&lt;/code&gt; class from one of my &lt;a href='http://www.bizo.com'&gt;Bizo&lt;/a&gt; colleagues (unfortunately not open source (yet?)) that buffers the actions data on the server&amp;#8217;s hard disk and then periodically uploads the files to Amazon&amp;#8217;s S3.&lt;/p&gt;

&lt;p&gt;Once the data is in S3, it&amp;#8217;s pretty routine to setup a Hive job to read it, do any fancy reporting (grouping/etc.), and drop it into a CSV file. For now I&amp;#8217;m just listing raw actions:&lt;/p&gt;

&lt;pre class='brush:sql'&gt;&lt;code&gt;-- Pick up the DatalogManager files in S3
drop table dlm_actions;
create external table dlm_actions (
    d map&amp;lt;string, string&amp;gt;
)
partitioned by (dt string comment &amp;#39;yyyyddmmhh&amp;#39;)
row format delimited
fields terminated by &amp;#39;\n&amp;#39; collection items terminated by &amp;#39;\001&amp;#39; map keys terminated by &amp;#39;\002&amp;#39;
location &amp;#39;s3://&amp;lt;actions-dlm-bucket&amp;gt;/&amp;lt;folder&amp;gt;/&amp;#39;
;

alter table dlm_actions recover partitions;

-- Make a csv destination also in S3
create external table csv_actions (
    user string,
    action string,
    value string
)
row format delimited fields terminated by &amp;#39;,&amp;#39;
location &amp;#39;s3://&amp;lt;actions-report-bucket/${START}-${END}/parts&amp;#39;
;

-- Move the data over (nothing intelligent yet)
insert overwrite table csv_actions
select dlm.d[&amp;quot;USER&amp;quot;], dlm.d[&amp;quot;ACTION&amp;quot;], dlm.d[&amp;quot;VALUE&amp;quot;]
from dlm_actions dlm
where
    dlm.dt &amp;gt;= &amp;#39;${START}00&amp;#39; and dlm.dt &amp;lt; &amp;#39;${END}00&amp;#39;
;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then we use Hudson as a cron-with-a-GUI to run this Hive script as an Amazon Elastic Map Reduce job once per day.&lt;/p&gt;

&lt;h2 id='testing'&gt;Testing&lt;/h2&gt;

&lt;p&gt;Thanks to the awesomeness of &lt;a href='http://www.tessell.org'&gt;Tessell&lt;/a&gt;, the usual GWT widgets, GWT-RPC, etc., can be doubled-out and testing with pure-Java unit tests.&lt;/p&gt;

&lt;p&gt;For example, a method from &lt;code&gt;UserActionUploaderTest&lt;/code&gt;:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;UserActionUploader uploader = new UserActionUploader(registry);
StubTimer timer = (StubTimer) uploader.getTimer();

@Test
public void uploadIsBuffered() {
  eventBus.fireEvent(new UserActionEvent(&amp;quot;someaction&amp;quot;, &amp;quot;value1&amp;quot;, false));
  eventBus.fireEvent(new UserActionEvent(&amp;quot;someaction&amp;quot;, &amp;quot;value2&amp;quot;, false));
  assertThat(async.getOutstanding().size(), is(0)); // buffered

  timer.run();
  final SaveUserActionAction a1 = async.getAction(SaveUserActionAction.class);
  assertThat(a1.getActions().size(), is(2));
  assertAction(a1, 0, &amp;quot;anonymous&amp;quot;, &amp;quot;someaction&amp;quot;, &amp;quot;value1&amp;quot;);
  assertAction(a1, 1, &amp;quot;anonymous&amp;quot;, &amp;quot;someaction&amp;quot;, &amp;quot;value2&amp;quot;);
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The usual GWT timers are stubbed out by a &lt;code&gt;StubTimer&lt;/code&gt;, which we can manually tick via &lt;code&gt;timer.run()&lt;/code&gt; to deterministically test timer-delayed business logic.&lt;/p&gt;

&lt;h2 id='thats_it'&gt;That&amp;#8217;s It&lt;/h2&gt;

&lt;p&gt;I can&amp;#8217;t say we have made any feature-altering decisions for &lt;a href='http://bizads.bizo.com'&gt;BizAds&lt;/a&gt; based on the data gathered from this approach yet&amp;#8211;technically its not live yet. But it&amp;#8217;s so amazing that surely we will. Ask me about it sometime in the future.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Dammit, MySQL</title>
   <link href="http://draconianoverlord.com/2010/07/22/dammit-mysql.html"/>
   <updated>2010-07-22T00:00:00-07:00</updated>
   <id>http://draconianoverlord.com/2010/07/22/dammit-mysql</id>
   <content type="html">&lt;h1 id='dammit_mysql'&gt;Dammit, MySQL&lt;/h1&gt;

&lt;p&gt;After being a happy PostgreSQL user for years, I&amp;#8217;ve finally had to use MySQL for the last 6+ months.&lt;/p&gt;

&lt;p&gt;I have to admit, I was starting to think it wasn&amp;#8217;t all that bad&amp;#8211;that the &amp;#8220;MySQL is a toy&amp;#8221; line was outdated.&lt;/p&gt;

&lt;p&gt;It&amp;#8217;s not.&lt;/p&gt;

&lt;p&gt;Here is my current laundry list of &amp;#8220;dammit, MySQL&amp;#8221; complaints:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;DDL Doesn&amp;#8217;t Respect Transactions&lt;/li&gt;

&lt;li&gt;No Deferred Foreign Key Constraints&lt;/li&gt;

&lt;li&gt;No Deferred Unique Key Constraints&lt;/li&gt;

&lt;li&gt;ANSI Mode Defaults Off&lt;/li&gt;

&lt;li&gt;Not Really Not Nulls&lt;/li&gt;

&lt;li&gt;Auto-Changing Timestamps&lt;/li&gt;

&lt;li&gt;Crappy Error Messages&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id='ddl_doesnt_respect_transactions'&gt;DDL Doesn&amp;#8217;t Respect Transactions&lt;/h2&gt;

&lt;p&gt;My biggest complaint is that MySQL&amp;#8217;s DDL operations (&lt;code&gt;CREATE TABLE&lt;/code&gt;, &lt;code&gt;ADD COLUMN&lt;/code&gt;, etc.) do not occur within transactions.&lt;/p&gt;

&lt;p&gt;Well, probably&amp;#8211;in typical MySQL fashion, you can execute &lt;code&gt;CREATE TABLE&lt;/code&gt;/etc. within a transaction (e.g. after a &lt;code&gt;BEGIN&lt;/code&gt;) and, instead of failing, MySQL will blithely commit all existing work in your transaction, create the table, and then let you continue on your merry way.&lt;/p&gt;

&lt;p&gt;This makes deployments a crap shoot&amp;#8211;whether you&amp;#8217;re using &lt;a href='http://joist.ws/ormMigrations.html'&gt;migrations&lt;/a&gt; or a hand-coded SQL upgrade script, you better hope the whole thing applies cleanly, because if your script blows up halfway through, you&amp;#8217;re stuck with a schema that is somewhere between versions.&lt;/p&gt;

&lt;p&gt;Getting back to a deployable state, or even one where you can rerun the fixed upgrade script, means either manually teasing the schema back to the old version, or reverting to a snapshot and starting all over.&lt;/p&gt;

&lt;p&gt;And this isn&amp;#8217;t just MyISAM&amp;#8211;this is the InnoDB engine as well.&lt;/p&gt;

&lt;p&gt;&lt;a href='http://www.postgresql.org'&gt;PostgreSQL&lt;/a&gt;, on the other hand, executes all DDL within a real transaction, and if one &lt;code&gt;CREATE TABLE&lt;/code&gt;/&lt;code&gt;ADD COLUMN&lt;/code&gt; fails, from experience, I know the entire schema rolls back to the prior state.&lt;/p&gt;

&lt;h2 id='no_deferred_foreign_key_constraints'&gt;No Deferred Foreign Key Constraints&lt;/h2&gt;

&lt;p&gt;Deferred foreign key constraints mean you can do:&lt;/p&gt;

&lt;pre class='brush:sql'&gt;&lt;code&gt;BEGIN;
INSERT INTO child (id, parent_id, name) VALUES (2, 1, &amp;#39;child&amp;#39;);
INSERT INTO parent (id, name) VALUES (1, &amp;#39;parent&amp;#39;);
COMMIT;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Note that technically we&amp;#8217;ve inserted &lt;code&gt;child.parent_id=1&lt;/code&gt;, but &lt;code&gt;parent.id=1&lt;/code&gt; is not in the database yet.&lt;/p&gt;

&lt;p&gt;Having deferred foreign key constraints means this is okay as long as the &lt;code&gt;parent.id=1&lt;/code&gt; row shows up before the transaction commits.&lt;/p&gt;

&lt;p&gt;Not having deferred foreign key constraints means &lt;code&gt;INSERT INTO child&lt;/code&gt; blows up right away. You instead have to ensure &lt;code&gt;INSERT INTO parent&lt;/code&gt; comes first.&lt;/p&gt;

&lt;p&gt;While this doesn&amp;#8217;t seem to be a big deal, the ability to defer foreign keys and freely order &lt;code&gt;INSERTs&lt;/code&gt; within a transaction makes technologies like ORMs much simpler.&lt;/p&gt;

&lt;p&gt;It also becomes crucial if you have a two-way relationship between rows, e.g.:&lt;/p&gt;

&lt;pre class='brush:sql'&gt;&lt;code&gt;BEGIN;
INSERT INTO child (id, parent_id, name) VALUES (2, 1, &amp;#39;child&amp;#39;);
INSERT INTO parent (id, name, current_child_id) VALUES (1, &amp;#39;parent&amp;#39;, 1);
COMMIT;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Both statements depend on the other&amp;#8211;there is no way to execute these two statements if you lack deferred foreign key constraints.&lt;/p&gt;

&lt;p&gt;You are reduced to making one of them &lt;code&gt;nullable&lt;/code&gt;, e.g. &lt;code&gt;parent.current_child_id&lt;/code&gt;, and then creating a partially-valid &lt;code&gt;Parent&lt;/code&gt; and fully-valid &lt;code&gt;Child&lt;/code&gt;, forcing your ORM to flush to SQL, then going back and updating &lt;code&gt;Parent&lt;/code&gt; to point to the new &lt;code&gt;Child&lt;/code&gt;, and doing a final flush+commit.&lt;/p&gt;

&lt;p&gt;&lt;a href='http://www.mysql.com'&gt;MySQL&lt;/a&gt; still doesn&amp;#8217;t have deferred foreign key constraints, &lt;a href='http://www.postgresql.org'&gt;PostgreSQL&lt;/a&gt; has had them for as long as I&amp;#8217;ve used it. Even SQLite &lt;a href='http://www.sqlite.org/foreignkeys.html#fk_deferred'&gt;has&lt;/a&gt; deferred foreign keys constraints.&lt;/p&gt;

&lt;h2 id='no_deferred_unique_key_constraints'&gt;No Deferred Unique Key Constraints&lt;/h2&gt;

&lt;p&gt;Deferred unique constraints are similar, but mean you can temporarily violate a unique constraint, as long as you clean things up before the transaction commits. E.g.:&lt;/p&gt;

&lt;pre class='brush:sql'&gt;&lt;code&gt;BEGIN;
INSERT INTO user (id, username) VALUES (1, &amp;#39;bob&amp;#39;);
INSERT INTO user (id, username) VALUES (2, &amp;#39;fred&amp;#39;);
COMMIT;

-- want to change bob-&amp;gt;fred, fred-&amp;gt;bob
BEGIN;
UPDATE user SET username = &amp;#39;fred&amp;#39; WHERE id = 1;
UPDATE user SET username = &amp;#39;bob&amp;#39; WHERE id = 2;
COMMIT;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Without deferred unique constraints, changing &lt;code&gt;bob -&amp;gt; fred&lt;/code&gt; would blow up immediately. Instead you have to dance around the issue by using a temporary value, e.g.:&lt;/p&gt;

&lt;pre class='brush:sql'&gt;&lt;code&gt;BEGIN;
UPDATE user SET username = &amp;#39;temp&amp;#39; WHERE id = 1;
UPDATE user SET username = &amp;#39;bob&amp;#39; WHERE id = 2;
UPDATE user SET username = &amp;#39;fred&amp;#39; WHERE id = 1;
COMMIT;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Like foreign key constraints, this extra hoop means two explicit unit of work flushes as you change &lt;code&gt;User1&lt;/code&gt; to a temp value, flush, change &lt;code&gt;User2&lt;/code&gt; to the right value, flush, and finally change &lt;code&gt;User1&lt;/code&gt; to the right value, flush and commit.&lt;/p&gt;

&lt;p&gt;With deferred unique constraints, it is very simple to set &lt;code&gt;User1&lt;/code&gt; to the new value, set &lt;code&gt;User2&lt;/code&gt; to the new value, and have your ORM auto-flush. It will just work.&lt;/p&gt;

&lt;p&gt;&lt;a href='http://www.mysql.com'&gt;MySQL&lt;/a&gt; doesn&amp;#8217;t have deferred unique constraints, &lt;a href='http://www.postgresql.org'&gt;PostgreSQL&lt;/a&gt; just got them in (the nearly released) 9.0.&lt;/p&gt;

&lt;h2 id='ansi_mode_defaults_off'&gt;ANSI Mode Defaults Off&lt;/h2&gt;

&lt;p&gt;I was dumbfounded to learn about MySQL&amp;#8217;s &lt;a href='http://dev.mysql.com/doc/refman/5.1/en/server-sql-mode.html'&gt;sql-mode&lt;/a&gt; option.&lt;/p&gt;

&lt;p&gt;What kind of product:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Lets users &lt;em&gt;disable standards compliance&lt;/em&gt; as a feature?&lt;/li&gt;

&lt;li&gt;Sets the default mode to &lt;strong&gt;not standards complaint&lt;/strong&gt;?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;With MySQL, you can use &lt;code&gt;ANSI&lt;/code&gt; mode, which affects such non-trivial things as &lt;em&gt;it actually uses the same escape character as the SQL standard&lt;/em&gt;. Amazing!&lt;/p&gt;

&lt;p&gt;&lt;a href='http://www.postgresql.org'&gt;PostgreSQL&lt;/a&gt; doesn&amp;#8217;t screw around like this, it just always implements the standard.&lt;/p&gt;

&lt;h2 id='not_really_not_nulls'&gt;Not Really Not Nulls&lt;/h2&gt;

&lt;p&gt;Also hidden in the &lt;a href='http://dev.mysql.com/doc/refman/5.1/en/server-sql-mode.html'&gt;sql-mode&lt;/a&gt; docs was an option to make &lt;code&gt;NOT NULL&lt;/code&gt; actually mean &lt;code&gt;NOT NULL&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For example, adding the &lt;code&gt;TRADITIONAL&lt;/code&gt; SQL mode restores the sanity:&lt;/p&gt;

&lt;pre class='brush:sql'&gt;&lt;code&gt;mysql&amp;gt; create table user (username varchar(50) not null);
Query OK, 0 rows affected (0.00 sec)

-- this works when it really should not
mysql&amp;gt; insert into user () values ();
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql&amp;gt; set sql_mode=&amp;#39;ANSI&amp;#39;;
Query OK, 0 rows affected (0.00 sec)

mysql&amp;gt; insert into user () values ();
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql&amp;gt; set sql_mode=&amp;#39;ANSI,TRADITIONAL&amp;#39;;
Query OK, 0 rows affected (0.00 sec)

-- finally, it blows up
mysql&amp;gt; insert into user () values ();
ERROR 1364 (HY000): Field &amp;#39;username&amp;#39; doesn&amp;#39;t have a default value&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So, does your MySQL database have some &lt;code&gt;NOT NULL&lt;/code&gt; columns? Are you really sure they don&amp;#8217;t have &lt;code&gt;null&lt;/code&gt; values in them? Have you checked your SQL mode?&lt;/p&gt;

&lt;p&gt;If you use &lt;a href='http://www.postgresql.org'&gt;PostgreSQL&lt;/a&gt;, you can be sure that your &lt;code&gt;NOT NULL&lt;/code&gt; columns do not have &lt;code&gt;null&lt;/code&gt; values in them.&lt;/p&gt;

&lt;p&gt;(&lt;strong&gt;Update:&lt;/strong&gt; I was wrong&amp;#8211;MySQL will not insert &lt;code&gt;null&lt;/code&gt;, but instead insert a default value, e.g. 0 for int or empty-string for strings. Personally, since I did not include a &lt;code&gt;DEFAULT&lt;/code&gt; clause in my DDL, I did not expect the database to add a &lt;code&gt;DEFAULT&lt;/code&gt; value for me.)&lt;/p&gt;

&lt;h2 id='autochanging_timestamps'&gt;Auto-Changing Timestamps&lt;/h2&gt;

&lt;p&gt;What would most developers assume happens if today you run:&lt;/p&gt;

&lt;pre class='brush:sql'&gt;&lt;code&gt;CREATE TABLE employee (
  id int,
  name varchar(50),
  created timestamp
);
INSERT INTO employee (id, name, timestamp) (1, &amp;#39;bob&amp;#39;, NOW());&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then tomorrow you do:&lt;/p&gt;

&lt;pre class='brush:sql'&gt;&lt;code&gt;UPDATE employee SET name = &amp;#39;fred&amp;#39;;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Quick, what&amp;#8217;s &lt;code&gt;created&lt;/code&gt;? Yesterday, right? Ah ha! No. It&amp;#8217;s &lt;a href='http://dev.mysql.com/doc/refman/5.0/en/timestamp.html'&gt;today&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&amp;#8220;With neither DEFAULT nor ON UPDATE clauses, it is the same as DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP.&amp;#8221;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;See that &lt;code&gt;ON UPDATE CURRENT_TIMESTAMP&lt;/code&gt;? That means MySQL &lt;strong&gt;changes the column value each time you update the row&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;What MySQL developer ever thought that this was a good default behavior? I&amp;#8217;m trying to think if this is the worst offender of &amp;#8220;least surprise&amp;#8221; or the if &lt;code&gt;NOT REALLY NOT NULL&lt;/code&gt; is worse. It&amp;#8217;s close.&lt;/p&gt;

&lt;h2 id='crappy_error_messages'&gt;Crappy Error Messages&lt;/h2&gt;

&lt;p&gt;To top it all off, MySQL error messages are a joke. This beauty:&lt;/p&gt;

&lt;pre class='brush:plain'&gt;&lt;code&gt;Can&amp;#39;t create table &amp;#39;foo.#sql-338_90&amp;#39; (errno: 150)&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Simply means &amp;#8220;you tried to reference a non-existent table&amp;#8221;.&lt;/p&gt;

&lt;p&gt;For as long as MySQL has been around, and how many countless users have run into this issue, you&amp;#8217;d think they&amp;#8217;d consider displaying a better error message.&lt;/p&gt;

&lt;p&gt;Even &lt;a href='http://www.git-scm.org'&gt;git&lt;/a&gt; is better at fixing its ease-of-use issues than MySQL.&lt;/p&gt;

&lt;p&gt;More often than not, &lt;a href='http://www.postgresql.org'&gt;PostgreSQL&lt;/a&gt; errors say plainly what really went wrong.&lt;/p&gt;

&lt;h2 id='dammit_aws'&gt;Dammit, AWS&lt;/h2&gt;

&lt;p&gt;Unfortunately, &lt;a href='http://aws.amazon.com/rds/'&gt;RDS&lt;/a&gt; is awesome, and RDS uses MySQL.&lt;/p&gt;

&lt;p&gt;I, and &lt;a href='http://developer.amazonwebservices.com/connect/thread.jspa?threadID=37834'&gt;many others&lt;/a&gt;, are pulling for Amazon to add PostgreSQL support. Maybe with the first-class replication in the 9.0 release, it will happen sooner rather than later. I can hope.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Publishing to Maven Repos with Ivy</title>
   <link href="http://draconianoverlord.com/2010/07/18/publishing-to-maven-repos-with-ivy.html"/>
   <updated>2010-07-18T00:00:00-07:00</updated>
   <id>http://draconianoverlord.com/2010/07/18/publishing-to-maven-repos-with-ivy</id>
   <content type="html">&lt;h1 id='publishing_to_maven_repos_with_ivy'&gt;Publishing to Maven Repos with Ivy&lt;/h1&gt;

&lt;p&gt;Publishing to Maven repositories is a fact of life for projects in the Java community.&lt;/p&gt;

&lt;p&gt;While I am not a fan of Maven itself, I readily admit that the standard shared repository/transitive-metadata approach they have driven has been a great thing for the community. While I was initially skeptical, downloading dependencies and keeping them out of source code repos is a good thing.&lt;/p&gt;

&lt;h2 id='using_ivy'&gt;Using Ivy&lt;/h2&gt;

&lt;p&gt;That being said, I prefer to leverage Maven repositories from a safe, arms length distance via the excellent &lt;a href='http://ant.apache.org/ivy'&gt;Ivy&lt;/a&gt; (and &lt;a href='http://ant.apache.org/ivy/ivyde/'&gt;IvyDE&lt;/a&gt;) tool which, besides other features, can understand the Maven repository format both as a source for dependencies and destination for publishing projects.&lt;/p&gt;

&lt;p&gt;While Ivy-to-Maven works well, it did take me a few tries to get it right, so here are the various settings/files that so far are doing the job.&lt;/p&gt;

&lt;h2 id='id4'&gt;&lt;code&gt;ivysettings.xml&lt;/code&gt;&lt;/h2&gt;

&lt;p&gt;This is the &lt;a href='http://github.com/stephenh/gwt-mpv/tree/master/dev/ivysettings.xml'&gt;gwt-mpv-dev &lt;code&gt;ivysettings.xml&lt;/code&gt;&lt;/a&gt;, with comments added.&lt;/p&gt;

&lt;pre class='brush:xml'&gt;&lt;code&gt;&amp;lt;ivysettings&amp;gt;
  &amp;lt;!--
    This property is used later in the ivy.xml file to set
    the project&amp;#39;s revision. Unless overridden, it defaults
    to the Maven SNAPSHOT convention, as that it works well
    for publishing local test builds to ~/.m2/repository.
  --&amp;gt;
  &amp;lt;property name=&amp;quot;revision&amp;quot; value=&amp;quot;SNAPSHOT&amp;quot; override=&amp;quot;false&amp;quot;/&amp;gt;

  &amp;lt;!-- &amp;quot;default&amp;quot; is defined later in the file. --&amp;gt;
  &amp;lt;settings defaultResolver=&amp;quot;default&amp;quot;/&amp;gt;

  &amp;lt;!-- Pulls in the &amp;quot;public&amp;quot; resolver for ibiblio-hosted jars. --&amp;gt;
  &amp;lt;include url=&amp;quot;${ivy.default.settings.dir}/ivysettings-public.xml&amp;quot;/&amp;gt;

  &amp;lt;resolvers&amp;gt;
    &amp;lt;!-- add any 3rd-party maven repos here... --&amp;gt;
    &amp;lt;ibiblio name=&amp;quot;joist&amp;quot; m2compatible=&amp;quot;true&amp;quot; root=&amp;quot;http://repo.joist.ws&amp;quot;/&amp;gt;

    &amp;lt;!--
      for *retrieving* artifacts for local testing builds,
      we&amp;#39;ll use maven&amp;#39;s own .m2/repository.
    --&amp;gt;
    &amp;lt;ibiblio
      name=&amp;quot;local-m2&amp;quot;
      m2compatible=&amp;quot;true&amp;quot;
      root=&amp;quot;file://${user.home}/.m2/repository&amp;quot;/
      changingPattern=&amp;quot;.*SNAPSHOT&amp;quot;&amp;gt;

    &amp;lt;!--
      for *publishing* artifacts for local testing builds,
      as the previous ibiblio resolver does not support
      publishing
    --&amp;gt;
    &amp;lt;filesystem name=&amp;quot;local-m2-publish&amp;quot; m2compatible=&amp;quot;true&amp;quot;&amp;gt;
      &amp;lt;artifact pattern=&amp;quot;${user.home}/.m2/repository/[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]&amp;quot;/&amp;gt;
    &amp;lt;/filesystem&amp;gt;

    &amp;lt;!--
      for publishing release artifacts via an sshfs-mounted share
    --&amp;gt;
    &amp;lt;filesystem name=&amp;quot;share-m2&amp;quot; m2compatible=&amp;quot;true&amp;quot;&amp;gt;
      &amp;lt;artifact pattern=&amp;quot;${user.home}/repo/[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]&amp;quot;/&amp;gt;
    &amp;lt;filesystem&amp;gt;

    &amp;lt;!-- strings the separate resolvers all together --&amp;gt;
    &amp;lt;chain name=&amp;quot;default&amp;quot; changingPattern=&amp;quot;.*SNAPSHOT&amp;quot;&amp;gt;
      &amp;lt;resolver ref=&amp;quot;public&amp;quot;/&amp;gt;
      &amp;lt;resolver ref=&amp;quot;joist&amp;quot;/&amp;gt;
      &amp;lt;!--
        Potential gotcha: you want your local-m2 to be last, or at least
        after the public repo. Otherwise maven proper might partially
        download a project into ~/.m2, but not include sources, and if
        local-m2 is first, ivy will pull the artifacts out of ~/.m2 and
        cache the partially-downloaded view of the repo (i.e. no sources).
        If public is first, ivy will always try to get artifacts from their
        canonical source.
      --&amp;gt;
      &amp;lt;resolver ref=&amp;quot;local-m2&amp;quot;/&amp;gt;
    &amp;lt;/chain&amp;gt;
  &amp;lt;/resolvers&amp;gt;
&amp;lt;/ivysettings&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The primary gotcha in this &lt;code&gt;ivysettings.xml&lt;/code&gt; was having to use two separate resolvers for the same &lt;code&gt;~/.m2/repository&lt;/code&gt;. This is because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Only the &lt;code&gt;ibiblio&lt;/code&gt; resolver will parse poms and follow the pom&amp;#8217;s transitive dependencies.&lt;/p&gt;

&lt;p&gt;(Technically the &lt;code&gt;filesystem&lt;/code&gt; or &lt;code&gt;url&lt;/code&gt; resolvers could retrieve jars with a Maven-ish artifact pattern, but the pom dependencies would be skipped.)&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;The &lt;code&gt;ibiblio&lt;/code&gt; resolver does not support publishing, so we have to fall back to the &lt;code&gt;filesystem&lt;/code&gt; resolver with a Maven-ish artifact pattern to publish.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, with the current Ivy 2.1.0 capabilities, it takes two resolvers for a single Maven repo if you want to both retrieve from and publish to it.&lt;/p&gt;

&lt;h2 id='id5'&gt;&lt;code&gt;ivy.xml&lt;/code&gt;&lt;/h2&gt;

&lt;p&gt;This is the &lt;a href='http://github.com/stephenh/gwt-mpv/tree/master/dev/ivy.xml'&gt;gwt-mpv-dev &lt;code&gt;ivy.xml&lt;/code&gt;&lt;/a&gt;, again with comments.&lt;/p&gt;

&lt;pre class='brush:xml'&gt;&lt;code&gt;&amp;lt;ivy-module version=&amp;quot;2.0&amp;quot; xmlns:m=&amp;quot;http://ant.apache.org/ivy/maven&amp;quot;&amp;gt;
  &amp;lt;!--
    We set the revision to the revision property from
    ivysettings.xml, which defaults to SNAPSHOT. This
    is overriden when publishing.
  --&amp;gt;
  &amp;lt;info organisation=&amp;quot;org.gwtmpv&amp;quot; module=&amp;quot;gwt-mpv-dev&amp;quot; revision=&amp;quot;${revision}&amp;quot;/&amp;gt;

  &amp;lt;!--
    I&amp;#39;m not a huge fan of a separate sources conf,
    but that is how Ivy&amp;#39;s ibiblio resolver converts
    poms, so we&amp;#39;ll stay consistent with that.
  --&amp;gt;
  &amp;lt;configurations&amp;gt;
    &amp;lt;conf name=&amp;quot;default&amp;quot;/&amp;gt;
    &amp;lt;conf name=&amp;quot;sources&amp;quot;/&amp;gt;
  &amp;lt;/configurations&amp;gt;

  &amp;lt;publications&amp;gt;
    &amp;lt;!--
      We explicitly list a pom as an artifact of our
      project. This way the Ivy publish task will
      upload the pom to the maven repo, along with
      the jars and sources.
    --&amp;gt;
    &amp;lt;artifact type=&amp;quot;pom&amp;quot; ext=&amp;quot;pom&amp;quot; conf=&amp;quot;default&amp;quot;/&amp;gt;

    &amp;lt;!--
      This is the main jar, nothing special.
    --&amp;gt;
    &amp;lt;artifact type=&amp;quot;jar&amp;quot; ext=&amp;quot;jar&amp;quot; conf=&amp;quot;default&amp;quot;/&amp;gt;

    &amp;lt;!--
      To publish sources to a maven repo, the
      m:classifier=&amp;quot;sources&amp;quot; is required.
    --&amp;gt;
    &amp;lt;artifact type=&amp;quot;source&amp;quot; ext=&amp;quot;jar&amp;quot; conf=&amp;quot;sources&amp;quot; m:classifier=&amp;quot;sources&amp;quot;/&amp;gt;
  &amp;lt;/publications&amp;gt;

  &amp;lt;!--
    defaultconf == we want the jars + sources for our dependencies
    defaultconfmapping == unless specified otherwise, our confs map
      to default for our dependencies
  --&amp;gt;
  &amp;lt;dependencies defaultconfmapping=&amp;quot;sources-&amp;gt;sources(),%-&amp;gt;default&amp;quot; defaultconf=&amp;quot;default,sources&amp;quot;&amp;gt;
    &amp;lt;!--
      gwt-mpv-user is published simultaneously with
      gwt-mpv-dev, so depend on the same exact revision.
    --&amp;gt;
    &amp;lt;dependency org=&amp;quot;org.gwtmpv&amp;quot; name=&amp;quot;gwt-mpv-user&amp;quot; rev=&amp;quot;${revision}&amp;quot; conf=&amp;quot;default&amp;quot;/&amp;gt;

    &amp;lt;!-- other dependencies --&amp;gt;
    &amp;lt;dependency org=&amp;quot;com.google.gwt&amp;quot; name=&amp;quot;gwt-dev&amp;quot; rev=&amp;quot;2.1.0.M1&amp;quot; conf=&amp;quot;default&amp;quot;/&amp;gt;
  &amp;lt;/dependencies&amp;gt;
&amp;lt;/ivy-module&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id='id6'&gt;&lt;code&gt;build.xml&lt;/code&gt;&lt;/h2&gt;

&lt;p&gt;Finally, here is the Ivy-related part of the &lt;a href='http://github.com/stephenh/gwt-mpv/tree/master/dev/build.xml'&gt;gwt-mpv-dev &lt;code&gt;build.xml&lt;/code&gt;&lt;/a&gt;:&lt;/p&gt;

&lt;pre class='brush:xml'&gt;&lt;code&gt;&amp;lt;property name=&amp;quot;ivy.jar.version&amp;quot; value=&amp;quot;2.1.0&amp;quot;/&amp;gt;
&amp;lt;property name=&amp;quot;ivy.jar.name&amp;quot; value=&amp;quot;ivy-${ivy.jar.version}.jar&amp;quot;/&amp;gt;
&amp;lt;property name=&amp;quot;ivy.home&amp;quot; value=&amp;quot;${user.home}/.ivy2&amp;quot;/&amp;gt;
&amp;lt;available property=&amp;quot;ivy.installed&amp;quot; file=&amp;quot;${ivy.home}/${ivy.jar.name}&amp;quot;/&amp;gt;

&amp;lt;!-- 
  this is called once and auto-installs the ivy jar into
  ~/.ivy2 so that users only have to have ant to build.
--&amp;gt;
&amp;lt;target name=&amp;quot;ivy-install&amp;quot; unless=&amp;quot;ivy.installed&amp;quot;&amp;gt;
  &amp;lt;mkdir dir=&amp;quot;${ivy.home}&amp;quot;/&amp;gt;
  &amp;lt;get src=&amp;quot;http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.jar.version}/${ivy.jar.name}&amp;quot; dest=&amp;quot;${ivy.home}/${ivy.jar.name}&amp;quot;/&amp;gt;
&amp;lt;/target&amp;gt;

&amp;lt;!--
  this is called automatically and just inits ivy
--&amp;gt;
&amp;lt;target name=&amp;quot;ivy-init&amp;quot; depends=&amp;quot;ivy-install&amp;quot;&amp;gt;
  &amp;lt;taskdef resource=&amp;quot;org/apache/ivy/ant/antlib.xml&amp;quot; uri=&amp;quot;antlib:org.apache.ivy.ant&amp;quot; classpath=&amp;quot;${ivy.home}/${ivy.jar.name}&amp;quot;/&amp;gt;
  &amp;lt;ivy:resolve/&amp;gt;
&amp;lt;/target&amp;gt;

&amp;lt;!--
  called by the user to download jars into bin/lib/
--&amp;gt;
&amp;lt;target name=&amp;quot;ivy-retrieve&amp;quot; depends=&amp;quot;ivy-init&amp;quot; description=&amp;quot;downloads jars for the project&amp;quot;&amp;gt;
  &amp;lt;ivy:retrieve pattern=&amp;quot;bin/lib/[conf]/[type]s/[artifact].[ext]&amp;quot; conf=&amp;quot;*&amp;quot; type=&amp;quot;*&amp;quot;/&amp;gt;
&amp;lt;/target&amp;gt;

&amp;lt;!--
  makes a pom for the project based off the ivy.xml file
--&amp;gt;
&amp;lt;target name=&amp;quot;gen-pom&amp;quot; depends=&amp;quot;ivy-init&amp;quot;&amp;gt;
  &amp;lt;ivy:makepom ivyfile=&amp;quot;ivy.xml&amp;quot; pomfile=&amp;quot;bin/poms/${ant.project.name}.pom&amp;quot;&amp;gt;
    &amp;lt;!--
      Mapping confs to scopes is important, otherwise
      unmapped confs are included as optional. If you
      have private confs, the best option seems to
      be marking them as provided or system. See
      IVY-1201 for an ehancement request.
    --&amp;gt;
    &amp;lt;mapping conf=&amp;quot;default&amp;quot; scope=&amp;quot;compile&amp;quot;/&amp;gt;
  &amp;lt;/ivy:makepom&amp;gt;
&amp;lt;/target&amp;gt;

&amp;lt;!--
  publishes to ~/.m2/repository so that other testing
  builds on our local machine can see it
--&amp;gt;
&amp;lt;target name=&amp;quot;ivy-publish-local&amp;quot; depends=&amp;quot;jar,ivy-init,gen-pom&amp;quot; description=&amp;quot;publish jar/source to maven repo mounted at ~/.m2/repository&amp;quot;&amp;gt;
  &amp;lt;ivy:publish resolver=&amp;quot;local-m2-publish&amp;quot; forcedeliver=&amp;quot;true&amp;quot; overwrite=&amp;quot;true&amp;quot; publishivy=&amp;quot;false&amp;quot;&amp;gt;
    &amp;lt;artifacts pattern=&amp;quot;bin/[type]s/[artifact].[ext]&amp;quot;/&amp;gt;
  &amp;lt;/ivy:publish&amp;gt;
&amp;lt;/target&amp;gt;

&amp;lt;!--
  pubishes to the ~/repo directory, which should be something
  like an sshfs-mount of the public maven repository you are
  publishing to
--&amp;gt;
&amp;lt;target name=&amp;quot;ivy-publish-share&amp;quot; depends=&amp;quot;jar,ivy-init,gen-pom&amp;quot; description=&amp;quot;publish jar/source to maven repo mounted at ~/repo&amp;quot;&amp;gt;
  &amp;lt;ivy:publish resolver=&amp;quot;share-m2&amp;quot; forcedeliver=&amp;quot;true&amp;quot; overwrite=&amp;quot;true&amp;quot; publishivy=&amp;quot;false&amp;quot;&amp;gt;
    &amp;lt;artifacts pattern=&amp;quot;bin/[type]s/[artifact].[ext]&amp;quot; /&amp;gt;
  &amp;lt;/ivy:publish&amp;gt;
&amp;lt;/target&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id='making_poms'&gt;Making Poms&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;build.xml&lt;/code&gt; file above uses Ivy&amp;#8217;s &lt;code&gt;makepom&lt;/code&gt; Ant task to convert our project&amp;#8217;s &lt;code&gt;ivy.xml&lt;/code&gt; into a &lt;code&gt;project.pom&lt;/code&gt; before uploading it to the Maven repository.&lt;/p&gt;

&lt;p&gt;This is generally acceptable, insofar as Ivy will get all of the dependencies translated correctly, but you&amp;#8217;ll end up with a very minimal pom.&lt;/p&gt;

&lt;p&gt;So if you want to add more elements to the pom, it is probably easiest to just hand-maintain a &lt;code&gt;project.pom.template&lt;/code&gt; and use a simple Ant filter to update the version on each build before being uploaded.&lt;/p&gt;

&lt;p&gt;For example, &lt;a href='http://repo.joist.ws/org/gwtmpv/gwt-mpv-dev/0.1/gwt-mpv-dev-0.1.pom'&gt;gwt-mpv-dev-0.1.pom&lt;/a&gt; was built automatically by &lt;code&gt;makepom&lt;/code&gt;, while &lt;a href='http://repo.joist.ws/org/gwtmpv/gwt-mpv-apt/1.3/gwt-mpv-apt-1.3.pom'&gt;gwt-mpv-apt-1.3.pom&lt;/a&gt; was built from a hand-maintained template.&lt;/p&gt;

&lt;h2 id='local_testing_builds'&gt;Local Testing Builds&lt;/h2&gt;

&lt;p&gt;So far I have not published &lt;code&gt;SNAPSHOT&lt;/code&gt; versions publicly, but they are very handy for sharing in-development changes between projects on your local machine. Just doing:&lt;/p&gt;

&lt;pre class='brush:plain'&gt;&lt;code&gt;ant ivy-publish-local&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Will publish a jar to &lt;code&gt;~/.m2&lt;/code&gt; for other local projects to pull in your latest/uncommitted changes.&lt;/p&gt;

&lt;p&gt;Since we&amp;#8217;re going through the &lt;code&gt;local-m2&lt;/code&gt; &lt;code&gt;&amp;lt;ibiblio/&amp;gt;&lt;/code&gt; resolver, Ivy automatically handles latest-&lt;code&gt;SNAPSHOT&lt;/code&gt; checking and we don&amp;#8217;t have to bother with any &lt;code&gt;~/.ivy2/cache&lt;/code&gt;-busting tricks like I talked about in &lt;a href='/2009/04/23/ivy-is-useful.html'&gt;Ivy Is Useful&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Though if you&amp;#8217;re using &lt;a href='http://ant.apache.org/ivy/ivyde/'&gt;IvyDE&lt;/a&gt; and workspace resolution of dependencies, Eclipse should setup all of the cross-project references correctly and you won&amp;#8217;t have to constantly publish &lt;code&gt;SNAPSHOT&lt;/code&gt; jars just for local consumption each time you make a change.&lt;/p&gt;

&lt;h2 id='doing_releases'&gt;Doing Releases&lt;/h2&gt;

&lt;p&gt;With the above setup, I can now publish &lt;code&gt;gwt-mpv&lt;/code&gt; to the &lt;a href='http://repo.joist.ws/org/gwtmpv'&gt;joist repo&lt;/a&gt; via:&lt;/p&gt;

&lt;pre class='brush:plain'&gt;&lt;code&gt;ant -Drevision=x.y ivy-publish-share&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id='it_works'&gt;It Works&lt;/h2&gt;

&lt;p&gt;While this looks like a lot of code, my inline comments added a lot&amp;#8211;it is generally ~50 lines of &lt;code&gt;ivysettings.xml&lt;/code&gt; and &lt;code&gt;ivy.xml&lt;/code&gt; per-project and then ~50 lines of straight-forward &lt;code&gt;build.xml&lt;/code&gt; Ant code.&lt;/p&gt;

&lt;p&gt;While this is more than, say, 10 LOC, it hasn&amp;#8217;t been burdensome enough for me to investigate anything else, e.g. &lt;a href='http://buildr.apache.org'&gt;Buildr&lt;/a&gt;, or even near burdensome enough to consider using Maven itself.&lt;/p&gt;

&lt;p&gt;I should probably throw the common files into a shared git repository and then git submodule them around instead of being reduced to copy/paste. But I haven&amp;#8217;t gotten around to it yet, and it seems like each project always has some tweak here or there that would be annoying to generalize.&lt;/p&gt;

&lt;p&gt;Nonetheless, this has been working well for me. If I made any errors or omissions, please let me know.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update 08/03/2010&lt;/strong&gt;: Add gotcha about the &lt;code&gt;local-m2&lt;/code&gt; resolver being chained after &lt;code&gt;public&lt;/code&gt; resolvers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update 01/13/2011&lt;/strong&gt;: Add &lt;code&gt;changingPattern=&amp;quot;true&amp;quot;&lt;/code&gt; to &lt;code&gt;local-m2&lt;/code&gt; and &lt;code&gt;default&lt;/code&gt; resolvers so that snapshots work without having Ant manually flushing the cache.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>ORM Prefetching</title>
   <link href="http://draconianoverlord.com/2010/07/16/orm-prefetching.html"/>
   <updated>2010-07-16T00:00:00-07:00</updated>
   <id>http://draconianoverlord.com/2010/07/16/orm-prefetching</id>
   <content type="html">&lt;h1 id='orm_prefetching'&gt;ORM Prefetching&lt;/h1&gt;

&lt;p&gt;Prefetching is pretty well-known technique for optimizing ORM/database access. However, I was surprised at how much thought and cool stuff people are doing with it.&lt;/p&gt;

&lt;h2 id='_selects'&gt;&lt;code&gt;n+1&lt;/code&gt; Selects&lt;/h2&gt;

&lt;p&gt;The problem prefetching solves is known as &lt;code&gt;n+1&lt;/code&gt; selects. It is best seen by a code example:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;Blog blog = loadBlog(1); // load from somewhere
for (Post post : blog.getPosts()) {
    for (Comment comment : post.getComments()) {
        render(comment);
    }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This usage almost always means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1 query of &lt;code&gt;SELECT * FROM blog WHERE id = 1&lt;/code&gt;&amp;#8211;loads 1 blog&lt;/li&gt;

&lt;li&gt;1 query of &lt;code&gt;SELECT * FROM post WHERE blog_id = 1&lt;/code&gt;&amp;#8211;loads N posts&lt;/li&gt;

&lt;li&gt;N queries of &lt;code&gt;SELECT * FROM comment WHERE post_id = x&lt;/code&gt;&amp;#8211;loads 1 comment, repeatedly for each post&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you have 20 blogs, you&amp;#8217;ll end up with 22 SQL calls back/forth to the database. Each call is a network trip, so this can quickly slow down your application.&lt;/p&gt;

&lt;p&gt;The goal of prefetching is to load the entire blog/posts/comments object graph with as few SQL calls as possible. Depending on the approach, you can have as few as 1 SQL call, which is a huge savings and will result in very real performance improvements.&lt;/p&gt;

&lt;h2 id='explicit_prefetching'&gt;Explicit Pre-Fetching&lt;/h2&gt;

&lt;p&gt;Traditionally, ORMs required explicit custom queries to prefetch an entire object graph.&lt;/p&gt;

&lt;p&gt;For example, with Hibernate you&amp;#8217;d do &lt;a href='http://docs.jboss.org/hibernate/stable/core/reference/en/html_single/#querycriteria-dynamicfetching'&gt;something like&lt;/a&gt;:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public Blog loadViaCustomQuery(int id) {
  List blogs = sess.createCriteria(Blog.class)
    .add(Restrictions.equal(&amp;quot;id&amp;quot;, id))
    .setFetchMode(&amp;quot;posts&amp;quot;, FetchMode.EAGER)
    .list();
  return blogs.get(0);
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The code then becomes:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;Blog blog = loadViaCustomQuery(1);
for (Post post : blog.getPosts()) {
    for (Comment comment : post.getComments()) {
        render(comment);
    }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This usage means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1 query of &lt;code&gt;SELECT b.*, p.* FROM blog b, LEFT OUTER JOIN posts p ON b.id = p.blog_id WHERE b.id = 1&lt;/code&gt;&amp;#8211;loads 1 blog plus &lt;code&gt;n&lt;/code&gt; posts&lt;/li&gt;

&lt;li&gt;&lt;code&gt;n&lt;/code&gt; queries of &lt;code&gt;SELECT * FROM comment WHERE post_id = x&lt;/code&gt;&amp;#8211;loads 1 comment, repeatedly for each post&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So we removed 1 extra query, going from 22 calls to 21 calls, but we really we haven&amp;#8217;t avoided the &lt;code&gt;n+1&lt;/code&gt; problem&amp;#8211;I&amp;#8217;m still poking around Hibernate docs to see if you can bring back sub-sub-collections via prefetching.&lt;/p&gt;

&lt;p&gt;(&lt;strong&gt;Disclaimer&lt;/strong&gt;: I don&amp;#8217;t have an active Hibernate setup right now&amp;#8211;I&amp;#8217;ll come back and update this if I ever get it figured out, but until then, please correct any of the technical points I have wrong.)&lt;/p&gt;

&lt;p&gt;Even so, there are several problems with explicit prefetching:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It requires up-front developer effort to write a custom query with correct prefetch semantics&lt;/li&gt;

&lt;li&gt;It requires on-going developer effort to update the custom query as the code changes what parts of the object graph it does/does not need&amp;#8211;performance could actually end up degraded if the wrong data is being prefetched&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id='implicit_prefetching'&gt;Implicit Pre-Fetching&lt;/h2&gt;

&lt;p&gt;What seems more novel to me is eschewing custom queries and the ORM just being more intelligent about its usage.&lt;/p&gt;

&lt;p&gt;One trick that Hibernate actually already implements is &lt;a href='http://docs.jboss.org/hibernate/stable/core/reference/en/html_single/#performance-fetching-subselect'&gt;subselect fetching&lt;/a&gt;. The idea is that when you&amp;#8217;re mapping your &lt;code&gt;Post&lt;/code&gt; class, you set &lt;code&gt;fetch=subselect&lt;/code&gt; on the &lt;code&gt;comments&lt;/code&gt; element:&lt;/p&gt;

&lt;pre class='brush:xml'&gt;&lt;code&gt;&amp;lt;class name=&amp;quot;Post&amp;quot;&amp;gt;
    &amp;lt;!-- ... other mappings ... --&amp;gt;
    &amp;lt;set name=&amp;quot;comments&amp;quot; fetch=&amp;quot;subselect&amp;quot;&amp;gt;
        &amp;lt;key column=&amp;quot;post_id&amp;quot; not-null=&amp;quot;true&amp;quot;/&amp;gt;
        &amp;lt;one-to-many class=&amp;quot;Comment&amp;quot;/&amp;gt;
    &amp;lt;/set&amp;gt;
&amp;lt;/class&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now our original code snippet:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;Blog blog = loadBlog(1); // load from somewhere
for (Post post : blog.getPosts()) {
    for (Comment comment : post.getComments()) {
        render(comment);
    }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Will result in these queries:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1 query on &lt;code&gt;loadBlog(1)&lt;/code&gt; of &lt;code&gt;SELECT * FROM blog WHERE id = 1&lt;/code&gt;&amp;#8211;loads 1 blog&lt;/li&gt;

&lt;li&gt;1 query on &lt;code&gt;blog.getPosts()&lt;/code&gt; of &lt;code&gt;SELECT * FROM post WHERE blog_id = 1&lt;/code&gt;&amp;#8211;loads &lt;code&gt;n&lt;/code&gt; posts&lt;/li&gt;

&lt;li&gt;1 query on the 1st &lt;code&gt;post.getComments()&lt;/code&gt; of &lt;code&gt;SELECT * FROM comment WHERE post_id IN (N post ids)&lt;/code&gt;&amp;#8211;loads &lt;code&gt;m&lt;/code&gt; comments&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;: I reproduced this behavior in a project with &lt;code&gt;Parent&lt;/code&gt;/&lt;code&gt;Child&lt;/code&gt;/&lt;code&gt;GrandChild&lt;/code&gt;, here is SQL Hibernate generated:&lt;/p&gt;

&lt;pre class='brush:sql'&gt;&lt;code&gt;select
  parent0_.id as id0_0_,
  parent0_.version as version0_0_,
  parent0_.&amp;quot;name&amp;quot; as name3_0_0_
  from &amp;quot;parent&amp;quot; parent0_
  where parent0_.id=?
select
  childs0_.parent_id as parent3_1_,
  childs0_.id as id1_,
  childs0_.id as id1_0_,
  childs0_.version as version1_0_,
  childs0_.&amp;quot;parent_id&amp;quot; as parent3_1_0_,
  childs0_.&amp;quot;name&amp;quot; as name4_1_0_
  from &amp;quot;child&amp;quot; childs0_
  where childs0_.parent_id=?
select
  grandchild0_.child_id as child3_1_,
  grandchild0_.id as id1_,
  grandchild0_.id as id2_0_,
  grandchild0_.version as version2_0_,
  grandchild0_.&amp;quot;child_id&amp;quot; as child3_2_0_,
  grandchild0_.&amp;quot;name&amp;quot; as name4_2_0_
  from &amp;quot;grand_child&amp;quot; grandchild0_
  where grandchild0_.child_id in (
    select childs0_.id
    from &amp;quot;child&amp;quot; childs0_
    where childs0_.parent_id=?
  )&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;What happened is that Hibernate applied a heuristic of saying: &amp;#8220;okay, you have &lt;code&gt;Post A&lt;/code&gt;, and you want its &lt;code&gt;Comments&lt;/code&gt;&amp;#8230;but you also have &lt;code&gt;Post B&lt;/code&gt;, &lt;code&gt;Post C&lt;/code&gt;, etc., in your session, I&amp;#8217;m going to go ahead and get the &lt;code&gt;Comments&lt;/code&gt; for all of those &lt;code&gt;Posts&lt;/code&gt; at the same time.&amp;#8221;&lt;/p&gt;

&lt;p&gt;From my perspective, this seems like a pretty sweet optimization.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;It dramatically reduces the SQL queries&amp;#8211;not all the way down to 1 query, but 3 is still a lot better than 22 (or whatever &lt;code&gt;n&lt;/code&gt; is)&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;It&amp;#8217;s automatic, and so requires no extra initial/on-going thought from the developers to maintain.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;You risk over-fetching data, however I think this is not a big deal because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You&amp;#8217;re already making a SQL call, which is dominated by the wire-call/latency&lt;/li&gt;

&lt;li&gt;The &lt;code&gt;WHERE post_id IN (N posts ids)&lt;/code&gt; is still a very simple query&amp;#8211;no outer left joins which can lead to data duplication&amp;#8211;so should return very fast even if slightly more data is coming back than you need&lt;/li&gt;

&lt;li&gt;Extremely large collections that would ruin this approach should probably not be mapped via implicit object graph navigation anyway&amp;#8211;as soon as a parent has &amp;gt;100-500 children, you probably don&amp;#8217;t want to load them in a single UnitOfWork anyway and so should not map &lt;code&gt;parent.getChildren()&lt;/code&gt; to prevent developers from accidentally causing session size bloat&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id='optimized_implicit_prefetching'&gt;Optimized Implicit Prefetching&lt;/h2&gt;

&lt;p&gt;What is even cooler than implicit prefetching, is &lt;em&gt;profiled&lt;/em&gt; implicit prefetching.&lt;/p&gt;

&lt;p&gt;I came across the paper &lt;a href='http://userweb.cs.utexas.edu/~wcook/papers/AutoFetch/autofetch.pdf'&gt;Automatic Prefetching by Traversal Profiling in Object Persistence&lt;/a&gt;, where the authors extend Hibernate 3.1 to keep live statistics about the application&amp;#8217;s object graph navigation.&lt;/p&gt;

&lt;p&gt;So, initially you&amp;#8217;ll get the worst case &lt;code&gt;n+1&lt;/code&gt; selects, but after a few iterations, their AutoFetch algorithm recognizes that, given the line number/stack trace of the &lt;code&gt;loadBlog(1)&lt;/code&gt; line, it will soon need all of the posts and comments, so issues a single:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;1 query of:&lt;/p&gt;

&lt;pre class='brush:sql'&gt;&lt;code&gt;SELECT b.*, p.*, c.*
FROM blog b
LEFT OUTER JOIN posts p ON b.id = p.blog_id
LEFT OUTER JOIN comments c ON p.id = c.post_id
WHERE b.id = 1&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That loads the entire blog/posts/comments object graph&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is pretty magically awesome.&lt;/p&gt;

&lt;p&gt;I think the only downside is that technically that many outer joins in 1 query will lead to potentially large data duplication due to it being a cross product. I do not know how much of an issue this would be in real-world usage.&lt;/p&gt;

&lt;p&gt;They might be better off sending a trio 3 simple statements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;SELECT * FROM blog WHERE id = 1&lt;/code&gt;&lt;/li&gt;

&lt;li&gt;&lt;code&gt;SELECT * FROM post WHERE blog_id = 1&lt;/code&gt;&lt;/li&gt;

&lt;li&gt;&lt;code&gt;SELECT * FROM comment WHERE post_id IN (SELECT id FROM post WHERE blog_id = 1)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Across the wire all the same time, then getting back 3 separate result sets. This would avoid the nested &lt;code&gt;LEFT OUTER JOIN&lt;/code&gt;s, but still get all the data in a single wire call.&lt;/p&gt;

&lt;p&gt;However, I really have no idea how well multi-statement result sets are supported in JDBC and the various databases that Hibernate supports.&lt;/p&gt;

&lt;h2 id='active_research'&gt;Active Research&lt;/h2&gt;

&lt;p&gt;What is most surprising to me is that ORM techniques are an active area of academic research. For example, the AutoFetch paper came out of the University of Texas at Austin and was supported by a National Science Foundation.&lt;/p&gt;

&lt;p&gt;I never would have guessed that federal academic funding was going into such a real-world/everyday technology like ORMs.&lt;/p&gt;

&lt;p&gt;Besides the AutoFetch algorithm, the AutoFetch paper is also interesting as it cites several other ORM papers that seem worth tracking down and reading. I definitely suggest anyone else interested in the ORM problem try and do the same.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Code Generation Is Not Evil</title>
   <link href="http://draconianoverlord.com/2010/07/15/code-generation-is-not-evil.html"/>
   <updated>2010-07-15T00:00:00-07:00</updated>
   <id>http://draconianoverlord.com/2010/07/15/code-generation-is-not-evil</id>
   <content type="html">&lt;h1 id='code_generation_is_not_evil'&gt;Code Generation Is Not Evil&lt;/h1&gt;

&lt;p&gt;I&amp;#8217;m a big fan of code generation (see &lt;a href='http://joist.ws/orm.html'&gt;joist&lt;/a&gt;, &lt;a href='http://bindgen.org'&gt;bindgen&lt;/a&gt;, &lt;a href='http://www.tessell.org/viewgeneration.html'&gt;Tessell&lt;/a&gt;, and &lt;a href='http://github.com/stephenh/interfacegen'&gt;interfacegen&lt;/a&gt;. I think active code generation can go a long way towards reducing boilerplate in a project.&lt;/p&gt;

&lt;h2 id='bad_reputation'&gt;Bad Reputation&lt;/h2&gt;

&lt;p&gt;However, it seems like code generation has a bad reputation these days. Especially in the Java community, most projects (&lt;a href='http://www.hibernate.org'&gt;Hibernate&lt;/a&gt;, etc.) have long preferred runtime byte code generation.&lt;/p&gt;

&lt;p&gt;I will readily admit that most of code generation&amp;#8217;s reputation is well-deserved, as done incorrectly it can be ugly and painful.&lt;/p&gt;

&lt;p&gt;For example, this snippet from the &lt;a href='http://db.apache.org/torque'&gt;Torque&amp;#8217;s&lt;/a&gt; ORM &lt;a href='http://svn.apache.org/viewvc/db/torque/templates/trunk/src/templates/om/bean/Bean.vm?revision=524492&amp;amp;view=markup'&gt;templates&lt;/a&gt;:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;#if ($objectIsCaching)
  #foreach ($fk in $table.Referrers)
    #set ( $tblFK = $fk.Table )
    #if ( !($tblFK.Name.equals($table.Name)) )
      #set ( $className = $tblFK.JavaName )
      #set ( $relatedByCol = &amp;quot;&amp;quot; )
      #foreach ($columnName in $fk.LocalColumns)
        #set ( $column = $tblFK.getColumn($columnName) )
        #if ($column.isMultipleFK())
          #set ($relatedByCol= &amp;quot;$relatedByCol$column.JavaName&amp;quot;)
        #end
      #end

      #if ($relatedByCol == &amp;quot;&amp;quot;)
        #set ( $relCol = &amp;quot;${className}${beanSuffix}s&amp;quot; )
      #else
        #set ( $relCol= &amp;quot;${className}${beanSuffix}sRelatedBy$relatedByCol&amp;quot; )
      #end
      #set ( $collName = &amp;quot;coll$relCol&amp;quot; )

  protected List#if($enableJava5Features)&amp;lt;${className}${beanSuffix}&amp;gt;#end $collName;

  public List#if($enableJava5Features)&amp;lt;${className}${beanSuffix}&amp;gt;#end get${relCol}()
  {
      return $collName;
  }

  public void set${relCol}(List#if($enableJava5Features)&amp;lt;${className}${beanSuffix}&amp;gt;#end list)
  {
      if (list == null)
      {
          $collName = null;
      }
      else
      {
          $collName = new ArrayList#if($enableJava5Features)&amp;lt;${className}${beanSuffix}&amp;gt;#end(list);
      }
  }

  #end
#end&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Complex templates like this make both the initial development and long-term maintenance of code generators painful.&lt;/p&gt;

&lt;p&gt;Another example is this generated output from &lt;a href='http://code.google.com/p/gxp/'&gt;GXP&lt;/a&gt;:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;package com.bizo.selfservice.services.email.templates;

import com.google.gxp.base.*; // causes unused warning
import com.google.gxp.css.*; // causes unused warning
import com.google.gxp.html.*; // causes unused warning
import com.google.gxp.js.*; // causes unused warning
import com.google.gxp.text.*; // causes unused warning

public class FooEmail extends com.google.gxp.base.GxpTemplate {

  private static final String GXP$MESSAGE_SOURCE = &amp;quot;com.foo.templates&amp;quot;; // causes unused warning

  public static void write(final java.lang.Appendable gxp$out, final com.google.gxp.base.GxpContext gxp_context) throws java.io.IOException {
    final java.util.Locale gxp_locale = gxp_context.getLocale(); // caused unused warning
    // ...more generated output...
  }&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Ugly, warning-filled output makes developers turn up their noses when they invariably glance at the generated output as they use it.&lt;/p&gt;

&lt;p&gt;I don&amp;#8217;t mean to pick on either project&amp;#8211;Torque was awesome for its time, and I really like the idea of GXP. But neither necessarily endears users to code generation.&lt;/p&gt;

&lt;p&gt;However, that does not mean the entire approach is flawed. With some effort and good techniques, code generation can be done well.&lt;/p&gt;

&lt;h2 id='benefits'&gt;Benefits&lt;/h2&gt;

&lt;p&gt;Code generation has several benefits, for example making a program faster at runtime by performing logic at build-time, which projects like &lt;a href='http://code.google.com/webtoolkit'&gt;GWT&lt;/a&gt; excel at.&lt;/p&gt;

&lt;p&gt;However, the biggest benefit from my perspective is that code generation excels at producing in-language abstractions (e.g. Java classes) from external primary source artifacts (e.g. some XML, a spec, etc.). Done well, it is a great way to percolate knowledge from source artifacts throughout the rest of your project &lt;a href='http://www.c2.com/cgi/wiki?DontRepeatYourself'&gt;without manual drudergy&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This is by no means a new idea&amp;#8211;the first I&amp;#8217;d read of it was in &lt;a href='http://www.pragprog.com/the-pragmatic-programmer'&gt;The Pragmatic Programmer&lt;/a&gt;, and that is probably just because I&amp;#8217;m not old enough to have read about it in anything else.&lt;/p&gt;

&lt;p&gt;This percolation becomes extra nice in IDEs like Eclipse/IntelliJ/etc., which see the build-time output of code generation. The IDE&amp;#8217;s type-awareness can then guide the programmer while programming code that interacts with the external resources.&lt;/p&gt;

&lt;p&gt;Good examples of this are &lt;a href='http://joist.ws/orm.html'&gt;joist&lt;/a&gt; making types that the mirror database schema so developers can write type-safe queries:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public Child findByName(String name) {  
  // the ChildAlias class is generated and contains fields (c.name)
  // for each column in the db. If the db changes, the fields change,
  // and this query would no longer compile
  ChildAlias c = new ChildAlias(&amp;quot;c&amp;quot;);  
  return Select.from(c).where(c.name.equals(name)).unique();  
}  &lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Or &lt;a href='http://www.tessell.org/viewgeneration.html'&gt;Tessell&lt;/a&gt; making boilerplate Java classes based on HTML-like XML UI templates:&lt;/p&gt;

&lt;pre class='brush:xml'&gt;&lt;code&gt;&amp;lt;ui:UiBinder ...&amp;gt;
  &amp;lt;gwt:HTMLPanel&amp;gt;
    &amp;lt;h2 ui:field=&amp;quot;heading&amp;quot;&amp;gt;Client&amp;lt;/h2&amp;gt;
    &amp;lt;gwt:TextBox ui:field=&amp;quot;name&amp;quot;/&amp;gt;&amp;lt;br/&amp;gt;
    &amp;lt;gwt:TextBox ui:field=&amp;quot;description&amp;quot;/&amp;gt;
    &amp;lt;div&amp;gt;&amp;lt;gwt:SubmitButton ui:field=&amp;quot;submit&amp;quot; text=&amp;quot;Submit&amp;quot;/&amp;gt;&amp;lt;/div&amp;gt;
  &amp;lt;/gwt:HTMLPanel&amp;gt;
&amp;lt;/ui:UiBinder&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That is turned into, among other things, an interface for the developer to code against:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public interface IsClientView {
  IsElement heading();
  IsTextBox name();
  IsTextBox description();
  IsSubmitButton submit();
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Or any of the SOAP/RPC projects like &lt;a href='http://ws.apache.org/axis/'&gt;Axis&lt;/a&gt;, &lt;a href='http://incubator.apache.org/thrift/'&gt;Thrift&lt;/a&gt;, or &lt;a href='http://code.google.com/p/protobuf/'&gt;protobuf&lt;/a&gt; creating in-language DTOs for cross-process communications.&lt;/p&gt;

&lt;p&gt;In all of these instances, the main goal of code generation is to cater to a static-typing bigot&amp;#8217;s preference for a compile-time sanity check, while avoiding the manual grunt work of copy/pasting non-Java-source artifacts (database schemas, XML documents) into their equivalent Java-source form.&lt;/p&gt;

&lt;h2 id='done_well'&gt;Done Well&lt;/h2&gt;

&lt;p&gt;To get the benefits of code generation without the flaws that led to its reputation, I think good code generation should strive for:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Be &lt;a href='http://c2.com/cgi/wiki?ActiveCodeGeneration'&gt;active&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Whatever a code generator&amp;#8217;s source artifact is (XML, a schema, etc.), it is pretty much guaranteed to change during the course of a project. When it does, updating the originally generated output should not be a manual process, which is tedious and error prone. Simply re-running the code generator should be quick, simple, and not overwrite any existing custom code that has been written.&lt;/p&gt;

&lt;p&gt;Active code generators can be especially cool when run automatically by IDEs. For example, in Eclipse both &lt;a href='http://download.oracle.com/docs/cd/E17476_01/javase/1.5.0/docs/guide/apt/GettingStarted.html'&gt;Java annotation processors&lt;/a&gt; and &lt;a href='http://www.springsource.org/roo'&gt;Spring Roo&lt;/a&gt; will run as soon as a programmer hits Save. The updated output is recognized within seconds and any new artifacts/compile-time errors are immediately available to the developer.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Easy to read output&lt;/p&gt;

&lt;p&gt;Even though it is generated, developers will inevitably look at the artifacts that code generation produces during the course of programming/debugging/etc. Opening up generated files should not cause their eyes to burn.&lt;/p&gt;

&lt;p&gt;Generated output should have good formating, no warnings, and be generally as hand-written as possible. This will gradually reduce the &amp;#8220;oh god no generated code&amp;#8221; feeling that most developers have picked up.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Easy to read templates&lt;/p&gt;

&lt;p&gt;Just like any code that developers write, code generation templates will have to be maintained. They should be easy to read, refactor, and test.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Abstraction in the templates&lt;/p&gt;

&lt;p&gt;Part of having easy to read templates is being able to apply abstraction.&lt;/p&gt;

&lt;p&gt;The previously cited Torque code snippet suffered from this: the template was a single pass &amp;#8220;all decisions must be made inline and linearly&amp;#8221;. While I&amp;#8217;m normally a huge fan of Velocity, it purposefully works best on simple templates&amp;#8211;too much complexity and things can get ugly.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Very little logic in the generated output&lt;/p&gt;

&lt;p&gt;In my experience, code generation works best to flush out simple scaffolding. Not Rails-style throw-away/&lt;a href='http://c2.com/cgi/wiki?PassiveCodeGeneration'&gt;passive&lt;/a&gt; scaffolding, but active scaffolding that can be rerun as needed but is simple nonetheless.&lt;/p&gt;

&lt;p&gt;The basic getters/setters/collections for an ORM a great example. Anything more complex than, say, a &lt;code&gt;not null&lt;/code&gt; check should be left to the programmer to write via a hook. This keeps the code generation logic from getting out of hand and overly complex.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id='id3'&gt;&lt;code&gt;sourcegen&lt;/code&gt;&lt;/h2&gt;

&lt;p&gt;Over the last few years, I&amp;#8217;ve embodied/stumbled upon these principles while working on a Java code generation library called, imaginatively, &lt;code&gt;sourcegen&lt;/code&gt;. It is currently hidden away in the &lt;a href='http://joist.ws'&gt;joist-util&lt;/a&gt; subproject, but is likely worth promoting to its own project.&lt;/p&gt;

&lt;p&gt;The idea behind &lt;code&gt;sourcegen&lt;/code&gt; is to break away from Velocity-style templates and apply some abstraction. Such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Any program generating Java code is going to have declare classes, fields, and methods. These should be easy to add these without worrying about boilerplate grouping, spacing, indentation, new lines, etc.&lt;/p&gt;

&lt;p&gt;For example, implementing an interface with some methods is done via simple, DSL-ish calls:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;outputClass.implementsInterface(List.class);

outputClass.addField(&amp;quot;foo&amp;quot;).type(String.class);
outputClass.addMethod(&amp;quot;getFoo&amp;quot;).returnType(String.class).body.line(&amp;quot;return foo;&amp;quot;);

outputClass.addField(&amp;quot;bar&amp;quot;).type(Integer.class);
outputClass.addMethod(&amp;quot;getBar&amp;quot;).returnType(Integer.class).body.line(&amp;quot;return bar;&amp;quot;);&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;code&gt;sourcegen&lt;/code&gt; will then output the class declaration boilerplate:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;import java.util.List;

public class Foo implements List {
  private String foo; // private by default
  private Integer bar;

  public String getFoo() {
    return foo;
  }

  public Integer getBar() {
    return bar;
  }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Any program generating Java code is going to have to handle imports. Instead of pessimistically including any possible import a template might need at the start of the file (e.g. single pass, and resulting in a slew of detested &amp;#8220;Unused import&amp;#8221; warnings), a program should be able to say half-way through the file &amp;#8220;btw, I need &lt;code&gt;foo.bar.Zaz&lt;/code&gt; imported&amp;#8221;.&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;// we&amp;#39;ve already added methods/fields/etc. to outputClass
// but now we hit a conditional and need Zaz as well
outputClass.addImports(Zaz.class);&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;(&lt;code&gt;sourcegen&lt;/code&gt; actually goes further and implements auto-import&amp;#8211;if you add a field of type &lt;code&gt;foo.bar.Zaz&lt;/code&gt;, &lt;code&gt;sourcegen&lt;/code&gt; will change the type to just &lt;code&gt;Zaz&lt;/code&gt; in the output if a) you are already in the &lt;code&gt;foo.bar&lt;/code&gt; package or b) the &lt;code&gt;Zaz&lt;/code&gt; class does not clash with an existing import.)&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With this internal DSL in place, code generation can now read like regular programs. For example, this snippet from joist&amp;#8217;s getter/setter/collection generation:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public void pass(Codegen codegen) {
  // Entity is a DTO for the domain object information sucked in from the schema
  for (Entity entity : codegen.getEntities().values()) {
      if (entity.isCodeEntity()) {
         continue;
      }

      // domainCodegen is the base class where we put all the
      // getters and setters, e.g. entity Employee will get
      // EmployeeCodegen. Real hand-written code can then go
      // in the Employee class, which extends EmployeeCodegen.
      GClass domainCodegen = codegen.getOutputCodegenDirectory().getClass(entity.getFullCodegenClassName());
      domainCodegen.setAbstract();
      domainCodegen.baseClassName(entity.getParentClassName());

      domainCodegen.getConstructor().setProtected().body.line(&amp;quot;this.addExtraRules();&amp;quot;);
      domainCodegen.getMethod(&amp;quot;addExtraRules&amp;quot;).setPrivate();

      this.addQueries(domainCodegen, entity);
      this.primitiveProperties(domainCodegen, entity);
      this.manyToOneProperties(domainCodegen, entity);
      this.oneToManyProperties(domainCodegen, entity);
      this.manyToManyProperties(domainCodegen, entity);
      this.changed(domainCodegen, entity);
      this.clearAssociations(domainCodegen, entity);
    }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now instead of one huge template, code generation can be broken into discrete chunks, e.g. &lt;code&gt;this.manyToOneProperties&lt;/code&gt;, and at the end all of the classes/methods/fields can be output at once via a single &lt;code&gt;toCode()&lt;/code&gt; call.&lt;/p&gt;

&lt;h2 id='when_applicable'&gt;When Applicable&lt;/h2&gt;

&lt;p&gt;Of course, code generation is like any other technique&amp;#8211;it is not always applicable and will be painful if misused in a situation where it doesn&amp;#8217;t make sense.&lt;/p&gt;

&lt;p&gt;But, if you do have an appropriate situation, and can hopefully follow a good approach, code generation can be a powerful approach to building well-designed, easy-to-maintain systems.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Why I Don't Like Mocks</title>
   <link href="http://draconianoverlord.com/2010/07/09/why-i-dont-like-mocks.html"/>
   <updated>2010-07-09T00:00:00-07:00</updated>
   <id>http://draconianoverlord.com/2010/07/09/why-i-dont-like-mocks</id>
   <content type="html">&lt;h2&gt;Why I Don't Like Mocks&lt;/h2&gt;&lt;hr /&gt;
&lt;p&gt;I am not particularly fond of mock objects. This gets me a few raised eye brows, given how wide spread their usage is these days.&lt;/p&gt;

&lt;p&gt;The best I can do is link to Fowler&amp;#8217;s &lt;a href='http://martinfowler.com/articles/mocksArentStubs.html'&gt;Mocks Aren&amp;#8217;t Stubs&lt;/a&gt; which does a great job of explaining state verification (stubs) vs. behavior verification (mocks) and the pros/cons of each. Typical Fowler, he does a great job of articulating what seems obvious in retrospect.&lt;/p&gt;

&lt;p&gt;Nonetheless, I&amp;#8217;ll reiterate a few things.&lt;/p&gt;

&lt;h2 id='state_vs_behavior'&gt;State vs. Behavior&lt;/h2&gt;

&lt;p&gt;For tests, I care more about state than behavior.&lt;/p&gt;

&lt;p&gt;If during &lt;code&gt;SomeFooTest&lt;/code&gt;, method &lt;code&gt;foo(1, 2)&lt;/code&gt; got called or &lt;code&gt;fooBar(3, 4)&lt;/code&gt; got called, I don&amp;#8217;t think the test should care as long as the desired output/state was reached.&lt;/p&gt;

&lt;p&gt;This will result in a test that is less brittle to refactoring, as typically any given test&amp;#8217;s input/output conditions won&amp;#8217;t change (think of them as requirements, stable, at least while refactoring), but how your program derived the output will.&lt;/p&gt;

&lt;p&gt;I read once of an XP project that was extreme about unit tests, but that they&amp;#8217;d reached a point where their tests were a burden. Always breaking and requiring lots of effort to refactor. My jumping-to-conclusions, probably-wrong, but I&amp;#8217;ll throw it out anyway, hunch is that they had mock tested lots of the small, detailed behavioral interactions between classes. So each time the big picture changed (a new feature was implemented), they had myriads of nit-picky behavioral tests to go fix.&lt;/p&gt;

&lt;h2 id='higher_level_of_testing'&gt;Higher Level of Testing&lt;/h2&gt;

&lt;p&gt;This leads to another point, that stubs allow you to test at a higher, courser level of detail than mocks.&lt;/p&gt;

&lt;p&gt;This pushes your unit tests towards being more like integration tests. Which, as long as speed is not sacrificed, I find preferable because then your unit tests are closer to testing customer-specified input/output conditions, and not just the implementation details of your current class design&amp;#8217;s approach.&lt;/p&gt;

&lt;p&gt;In Fowler&amp;#8217;s words:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;&amp;#8220;In essence classic xunit tests are not just unit tests, but also mini-integration tests. As a result many people like the fact that client tests may catch errors that the main tests for an object may have missed, particularly probing areas where classes interact. Mockist tests lose that quality. In addition you also run the risk that expectations on mockist tests can be incorrect, resulting in unit tests that run green but mask inherent errors.&amp;#8221;&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The primary reason stubs facilitate higher-level testing is that mocks, in my opinion, become too complex, verbose, and repetitive to setup and verify scenarios that are not trivial, 1-level of calls.&lt;/p&gt;

&lt;p&gt;For example, say you have a &lt;code&gt;IClient&lt;/code&gt;, and need to get an &lt;code&gt;IEmployee&lt;/code&gt; from that and then a &lt;code&gt;IAccount&lt;/code&gt; from that.&lt;/p&gt;

&lt;p&gt;This would look something like:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;IClient client = mock(IClient.class);
IEmployee ee = mock(IEmployee.class);
IAccount a = mock(IAccount.class);
when(client.getEmployee(1)).thenReturn(ee);
when(ee.getAccount(2)).thenReturn(a);&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Contrast this with a stub (+ builder) approach of:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;StubRepo repo = new StubRepo();
repo.addClientWithEmployeeAndAccount(1, 2);&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Granted, domain objects are not usually a target for mocking (&lt;a href='http://www.qi4j.org/'&gt;usually&lt;/a&gt;), but this is first example of an &lt;code&gt;n&lt;/code&gt;-layer object graph that came to mind. Eh, I should come up with a better example.&lt;/p&gt;

&lt;p&gt;Anyway, at first, it may seem like the mock is preferable. It is simpler, especially to get started, as it is just a few inline &lt;code&gt;mock&lt;/code&gt;/&lt;code&gt;when&lt;/code&gt; calls. Contrast this with the &lt;code&gt;StubRepo&lt;/code&gt; which is a separate class and needs a separate &lt;code&gt;addClientWithEmployeeAndAccount&lt;/code&gt; builder method. The stub requires some infrastructure.&lt;/p&gt;

&lt;p&gt;However, the key is scale&amp;#8211;as a project grows, the stub can be reused over and over in many different tests. The investment in building a stub pays off as soon as 5, 10, 100 tests are using it.&lt;/p&gt;

&lt;p&gt;In contrast, the &lt;code&gt;mock&lt;/code&gt;/&lt;code&gt;when&lt;/code&gt;/etc. methods typically are not abstracted out and, in my experience, end up being repeated in each test.&lt;/p&gt;

&lt;p&gt;This is just my opinion, of course&amp;#8211;Fowler&amp;#8217;s article points out I&amp;#8217;m like showing my classicist bias:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;&amp;#8220;As a result I&amp;#8217;ve heard both styles accuse the other of being too much work. Mockists say that creating the fixtures is a lot of effort, but classicists say that this is reused but you have to create mocks with every test.&amp;#8221;&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id='dummy_behavior_scales'&gt;Dummy Behavior Scales&lt;/h2&gt;

&lt;p&gt;Stubs also scale better than mocks because they can contain dummy/default behavior that mocks otherwise to have to repeat in each test.&lt;/p&gt;

&lt;p&gt;For example, take an &lt;code&gt;HttpServletRequest&lt;/code&gt; and wanting to mock out the &lt;code&gt;getAttribute&lt;/code&gt;/&lt;code&gt;setAttribute&lt;/code&gt; methods.&lt;/p&gt;

&lt;p&gt;With a mock, each time any business logic wants to use attributes, your test is going to have to contain setup code for each attribute involved in the test:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;HttpServletRequest req = mock(HttpServletRequest.class);
when(req.getAttribute(&amp;quot;foo&amp;quot;)).thenReturn(&amp;quot;bar&amp;quot;);
doBusinessLogic(req);&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And, if you have verify an attribute is being set via &lt;code&gt;setAttribute&lt;/code&gt;, something like:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;ArgumentCapture&amp;lt;String&amp;gt; key = ArgumentCapture.forClass(String.class);
ArgumentCapture&amp;lt;Object&amp;gt; value = ArgumentCapture.forClass(Object.class);
verify(req).setAttribute(key.capture(), value.capture());
assertThat(key.getValue(), is(&amp;quot;foo&amp;quot;));
assertThat(value.getValue(), is(&amp;quot;bar2&amp;quot;));&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;With a stub, you can have one class &lt;code&gt;StubRequest&lt;/code&gt; which uses a map to implement simple &lt;code&gt;getAttribute&lt;/code&gt;/&lt;code&gt;setAttribute&lt;/code&gt; methods. Now all of your tests can use it:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;StubRequest req = new StubRequest();
req.put(&amp;quot;foo&amp;quot;, &amp;quot;bar&amp;quot;);
doBusinessLogic(req);
assertThat(req.get(&amp;quot;foo&amp;quot;), is(&amp;quot;bar2&amp;quot;));&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Besides just the &lt;code&gt;&amp;quot;foo&amp;quot;&lt;/code&gt; attribute, if the business logic under test was setting its own attributes that it later wanted to retrieve, the stub&amp;#8217;s dummy map implementation scales even better as our test is encapsulated from those implementation details.&lt;/p&gt;

&lt;p&gt;Spring even realized this, as they intelligently include for testing a &lt;a href='http://static.springsource.org/spring/docs/2.0.x/api/org/springframework/mock/web/MockHttpServletRequest.html'&gt;MockHttpServletRequest&lt;/a&gt; that is actually a stub, though I can understand if they named it before the terminology of mocks/stubs/doubles had been settled.&lt;/p&gt;

&lt;h2 id='too_many_interfaces'&gt;Too Many Interfaces&lt;/h2&gt;

&lt;p&gt;Mocking encourages testing behavioral interfaces between classes, e.g. &lt;a href='http://martinfowler.com/bliki/RoleInterface.html'&gt;role interfaces&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;However, I personally prefer to use real objects in tests as long as possible, and only create interfaces as a last resort when doubling is required. Otherwise I think you end up with the anti-pattern of interfaces that have only 1 implementation.&lt;/p&gt;

&lt;p&gt;To me, these 1-implementation interfaces just clutter a code base and make life more tedious for the developer as they copy/paste the same method definitions, etc., between the two. (See &lt;a href='http://github.com/stephenh/interfacegen'&gt;interfacegen&lt;/a&gt; for my begrudging hack to help with these scenarios).&lt;/p&gt;

&lt;p&gt;Fowler asserts that mockists actually like these extra interfaces:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;&amp;#8220;Mockists favor role interfaces and assert that using this style of testing encourages more role interfaces, since each collaboration is mocked separately and is thus more likely to be turned into a role interface.&amp;#8221;&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Which, in my current style, I just don&amp;#8217;t see the benefit of.&lt;/p&gt;

&lt;p&gt;Lately I don&amp;#8217;t any more consulting-related project-hopping, so perhaps my data points are few/stale, but two of the worst &amp;#8220;wtf were the architects thinking&amp;#8221; systems I&amp;#8217;ve seen involved 1-implementation/role interfaces. So until I see a convincing example otherwise, I consider them a bad thing.&lt;/p&gt;

&lt;h2 id='conclusion'&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;So, that&amp;#8217;s my take. I&amp;#8217;ve &lt;a href='http://www.draconianoverlord.com/2010/01/15/changing-my-style.html'&gt;changed my style&lt;/a&gt; before, so we&amp;#8217;ll see if I end up being a mockist a few years from now. But for now I&amp;#8217;m a classicist.&lt;/p&gt;

&lt;p&gt;(Nothing like some good labels to throw around.)&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>GWT Seamless Deployments</title>
   <link href="http://draconianoverlord.com/2010/07/07/gwt-seamless-upgrades.html"/>
   <updated>2010-07-07T00:00:00-07:00</updated>
   <id>http://draconianoverlord.com/2010/07/07/gwt-seamless-upgrades</id>
   <content type="html">&lt;h2&gt;GWT Seamless Deployments&lt;/h2&gt;&lt;hr /&gt;
&lt;p&gt;I&amp;#8217;m deploying a GWT app on Amazon&amp;#8217;s EC2 architecture behind an ELB and wanted to ensure the best experience for users while pushing out new code updates.&lt;/p&gt;

&lt;p&gt;This is a short review of my most-likely-accurate findings. It is not well organized and basically a public mind dump vs. a private mind dump to my other team members.&lt;/p&gt;

&lt;h2 id='rpc_key_points'&gt;RPC Key Points&lt;/h2&gt;

&lt;p&gt;I&amp;#8217;m not going to review GWT RPC in detail, but the basic points for us are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;GWT automatically serializes Java objects to/from JavaScript objects&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;GWT on the server-side will serialize/deserialize:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Anything that implements GWT&amp;#8217;s &lt;code&gt;IsSerializable&lt;/code&gt; marker interface&lt;/li&gt;

&lt;li&gt;Anything that implements Java&amp;#8217;s &lt;code&gt;Serializable&lt;/code&gt; &lt;em&gt;and&lt;/em&gt; is in a serialization policy file (see this &lt;a href='http://code.google.com/webtoolkit/doc/latest/FAQ_Server.html#Does_the_GWT_RPC_system_support_the_use_of_java.io.Serializable'&gt;faq entry&lt;/a&gt; for more details)&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;GWT on the client-side will serialize/deserialize any type it knew about at compile-time&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id='a_typical_rpc_request'&gt;A Typical RPC Request&lt;/h2&gt;

&lt;p&gt;Here&amp;#8217;s what a typical RPC request might look like:&lt;/p&gt;

&lt;pre class='brush:plain'&gt;&lt;code&gt;POST https://app.com/gwtapp/dispatch
Content-Type: text/x-gwt-rpc; charset=UTF-8
Origin: https://app.com
Referer: https://app.com/gwtapp/361924868514EB67231B0C48DC4B136A.cache.html
X-GWT-Module-Base: https://app.com/gwtapp/
X-GWT-Permutation: 361924868514EB67231B0C48DC4B136A

&amp;lt;serialized-objects-here&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The interesting thing to notice is the &lt;code&gt;X-GWT-Permutation&lt;/code&gt; header&amp;#8211;this is the strong name (hash) of the browser/locale/etc. code base the client is currently running.&lt;/p&gt;

&lt;h2 id='case_1_old_client_new_server'&gt;Case 1: Old Client, New Server&lt;/h2&gt;

&lt;p&gt;When an old client sends an RPC request to a new server, we would ideally like to fulfill it as long as we haven&amp;#8217;t changed the contract of the RPC service it&amp;#8217;s interacting with.&lt;/p&gt;

&lt;p&gt;GWT&amp;#8217;s deserialization execution flow for an old request is something like:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Read in the &lt;code&gt;X-GWT-Permutation&lt;/code&gt; header&lt;/li&gt;

&lt;li&gt;Try to load the serialization policy file based on the permutation header&amp;#8211;&lt;em&gt;however,&lt;/em&gt; this will fail because this is a new server that does not have the old serialization policy file&lt;/li&gt;

&lt;li&gt;Fall back on &lt;code&gt;LegacySerializationPolicy&lt;/code&gt; where only &lt;code&gt;IsSerializable&lt;/code&gt; can be deserialized&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For this reason, it&amp;#8217;s important to still use the old &lt;code&gt;IsSerializable&lt;/code&gt; marker interface even though GWT now supports Java&amp;#8217;s &lt;code&gt;Serializable&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Also, type name elision cannot be used because it also relies on the serialization policy file.&lt;/p&gt;

&lt;p&gt;Then, assuming the RPC contract is the same, everything should still work.&lt;/p&gt;

&lt;p&gt;If the RPC contract does change, i.e. the old client tries to use changed/removed functionality, they will get an &lt;a href='http://google-web-toolkit.googlecode.com/svn/javadoc/2.0/com/google/gwt/user/client/rpc/IncompatibleRemoteServiceException.html'&gt;IncompatibleRemoteServiceException&lt;/a&gt; which the GWT client-side code should handle and prompt the user to reload the application.&lt;/p&gt;

&lt;p&gt;One additional wrinkle is code split points. If an old client tries to load part of the application it does not have yet, it will use the old code base name, which is no longer on the new server. The client-side &lt;code&gt;GWT.runAsync&lt;/code&gt; will fail with a 404 and the application should prompt the user to reload. (See &lt;a href='https://android.git.kernel.org/?p=tools/gerrit.git;a=blob;f=gerrit-gwtui/src/main/java/com/google/gerrit/client/Dispatcher.java;h=7db92ad17911eb52e9b078c127906adaaa74f3dc;hb=HEAD#l375'&gt;AsyncSplit&lt;/a&gt; for how gerrit handles this.)&lt;/p&gt;

&lt;h2 id='case_2_new_client_old_server'&gt;Case 2: New Client, Old Server&lt;/h2&gt;

&lt;p&gt;The same scenario above can happen here, when the client has a newer serialization policy strong name than the old server, so the old server falls back to the &lt;code&gt;LegacySerializationPolicy&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;However, an added wrinkle is the application bootstrapping process.&lt;/p&gt;

&lt;p&gt;A client might:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Request &lt;code&gt;/app.html&lt;/code&gt; and get served by either a new or old server (fine so far)&lt;/li&gt;

&lt;li&gt;Request &lt;code&gt;/app/module.nocache.js&lt;/code&gt; and get served by a new server&amp;#8211;this is the GWT bootstrapping code and, based on the user&amp;#8217;s browser/locale/etc. combination, it tells the browser to load &lt;code&gt;new-permutation-name.cache.html&lt;/code&gt;&lt;/li&gt;

&lt;li&gt;Request &lt;code&gt;/app/new-permuation-name.cache.html&lt;/code&gt;, &lt;em&gt;however&lt;/em&gt;, this request gets served by an old server that only has the old application files&lt;/li&gt;

&lt;li&gt;Client gets a &lt;code&gt;404&lt;/code&gt; and the application bootstrapping stops&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I currently know of no way to recover from this scenario. Because the error happens in between the GWT bootstrapping code and your application code, there is not a way for your application code to detect what has happened and recover.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; Thanks for Sripathi Krishnan for pointing out the &lt;a href='http://groups.google.com/group/google-web-toolkit/browse_thread/thread/2dafc6fd50e622a4'&gt;&lt;code&gt;gwt:onLoadErrorFn&lt;/code&gt;&lt;/a&gt; function where you can prompt the user to reload their browser to recover from this scenario.&lt;/p&gt;

&lt;p&gt;For this reason, it&amp;#8217;s very important to have a clean switch from old to new versions&amp;#8211;no old servers should be serving requests once new servers have come online.&lt;/p&gt;

&lt;h2 id='summarizing'&gt;Summarizing&lt;/h2&gt;

&lt;p&gt;Based on my current understanding, to service both old and new clients during a GWT upgrade as elegantly as possible, you should:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;IsSerializable&lt;/code&gt; and no type name elision in the RPC DTOs&lt;/li&gt;

&lt;li&gt;Handle &lt;code&gt;IncompatibleRemoteServiceException&lt;/code&gt; in the RPC &lt;code&gt;AsyncCallback&lt;/code&gt;s&lt;/li&gt;

&lt;li&gt;Handle 404&amp;#8217;s in the &lt;code&gt;runAsync&lt;/code&gt; &lt;code&gt;onFailures&lt;/code&gt;&lt;/li&gt;

&lt;li&gt;Minimize/eliminate the window when both old and new servers are available&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Any corrections, feedback, etc., is appreciated.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>gwt-mpv-apt 1.1</title>
   <link href="http://draconianoverlord.com/2010/06/28/gwt-mpv-apt-1.1.html"/>
   <updated>2010-06-28T00:00:00-07:00</updated>
   <id>http://draconianoverlord.com/2010/06/28/gwt-mpv-apt-1.1</id>
   <content type="html">&lt;h2&gt;gwt-mpv-apt 1.1&lt;/h2&gt;&lt;hr /&gt;
&lt;p&gt;&lt;strong&gt;Update 2011/12/29:&lt;/strong&gt; This post was originally about the &lt;code&gt;gwt-mpv-apt&lt;/code&gt; project, which has since been merged into/rechristened Tessell, see &lt;a href='http://www.tessell.org'&gt;tessell.org&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;gwt-mpv-apt&lt;/code&gt; is a annotation processor (natively supported by Eclipse and &lt;code&gt;javac&lt;/code&gt;) that generates &lt;code&gt;gwt-dispatch&lt;/code&gt; and &lt;code&gt;GwtEvents&lt;/code&gt; for GWT projects.&lt;/p&gt;

&lt;p&gt;The benefit is &lt;strong&gt;a 10x decrease in boilerplate code&lt;/strong&gt;, which is something every GWT project needs.&lt;/p&gt;

&lt;p&gt;The &lt;a href='http://github.com/stephenh/gwt-mpv-apt'&gt;github page&lt;/a&gt; is pretty self-explanatory, but the basic idea is that &lt;code&gt;gwt-mpv-apt&lt;/code&gt; can generate both your Action and Result command-pattern DTOs and then also your GWT event DTOs from &amp;#8220;spec&amp;#8221; classes that contain only the minimal amount of information needed to derive the resulting DTOs.&lt;/p&gt;

&lt;h2 id='manually_creating_actionresult_dtos'&gt;Manually Creating Action/Result DTOs&lt;/h2&gt;

&lt;p&gt;Let&amp;#8217;s start out without &lt;code&gt;gwt-mpv-apt&lt;/code&gt; and see how things typically work.&lt;/p&gt;

&lt;p&gt;For example, if you were writing a &lt;code&gt;gwt-dispatch&lt;/code&gt; Action/Result by hand for creating a new &lt;code&gt;User&lt;/code&gt;, you&amp;#8217;d have to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Make a &lt;code&gt;NewUserAction&lt;/code&gt; class&lt;/li&gt;

&lt;li&gt;Have it implement the &lt;code&gt;Action&amp;lt;NewUserResult&amp;gt;&lt;/code&gt; interface&lt;/li&gt;

&lt;li&gt;Add a field/getter/setter for &lt;code&gt;String username&lt;/code&gt;&lt;/li&gt;

&lt;li&gt;Add a protected &lt;code&gt;NewUserAction&lt;/code&gt; constructor for serialization&lt;/li&gt;

&lt;li&gt;Add a public constructor for &lt;code&gt;NewUserAction(String username)&lt;/code&gt; for real usage&lt;/li&gt;

&lt;li&gt;Add a default &lt;code&gt;serialVersionUID&lt;/code&gt; to avoid the Eclipse warning (assuming the warning is enabled)&lt;/li&gt;

&lt;li&gt;Make a &lt;code&gt;NewUserResult&lt;/code&gt; class&lt;/li&gt;

&lt;li&gt;Have it implement the &lt;code&gt;Result&lt;/code&gt; interface&lt;/li&gt;

&lt;li&gt;Add a field/getter/setter for &lt;code&gt;boolean success&lt;/code&gt;, and &lt;code&gt;Integer newUserId&lt;/code&gt;&lt;/li&gt;

&lt;li&gt;Add a protected &lt;code&gt;NewUserResult&lt;/code&gt; constructor for serialization&lt;/li&gt;

&lt;li&gt;Add a public constructor for &lt;code&gt;NewUserResult(boolean success, Integer newUserId)&lt;/code&gt; for real usage&lt;/li&gt;

&lt;li&gt;Add a default &lt;code&gt;serialVersionUID&lt;/code&gt; to avoid the Eclipse warning (assuming the warning is enabled)&lt;/li&gt;

&lt;li&gt;If you want caching add &lt;code&gt;hashCode/equals&lt;/code&gt; to &lt;code&gt;NewUserAction&lt;/code&gt;&lt;/li&gt;

&lt;li&gt;If you want nice debugging add &lt;code&gt;toString&lt;/code&gt; to &lt;code&gt;NewUserAction&lt;/code&gt;&lt;/li&gt;

&lt;li&gt;If you want nice debugging add &lt;code&gt;toString&lt;/code&gt; to &lt;code&gt;NewUserResult&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In the end, you&amp;#8217;ll end up with something like:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public class NewUserAction implements Action&amp;lt;NewUserResult&amp;gt; {
  private static final long serialVersionUID = 1L;
  private String username;

  public NewUserAction(String username) {
    this.username = username;
  }

  protected NewUserAction() {
  }

  public String getUsername() {
    return this.username;
  }

  @Override
  public int hashCode() {
      int hashCode = 23;
      hashCode = (hashCode * 37) + getClass().hashCode();
      hashCode = (hashCode * 37) + (username == null ? 1 : username.hashCode());
      return hashCode;
  }

  @Override
  public boolean equals(Object other) {
      if (other != null &amp;amp;&amp;amp; other.getClass().equals(this.getClass())) {
          NewUserAction o = (NewUserAction) other;
          return (o.username == null &amp;amp;&amp;amp; this.username == null)
                 || (o.username != null &amp;amp;&amp;amp; o.username.equals(this.username));
      }
      return false;
  }

  @Override
  public String toString() {
      return &amp;quot;NewUserAction[&amp;quot; + username + &amp;quot;]&amp;quot;;
  }
}

public class NewUserResult implements Result {
  private static final long serialVersionUID = 1L;
  private boolean success;
  private Integer newUserId;

  public NewUserResult(boolean success, Integer newUserId) {
    this.success = success;
    this.newUserId = newUserId;
  }

  protected NewUserResult() {
  }

  public boolean getSuccess() {
    return this.success;
  }

  public Integer getNewUserId() {
    return this.newUserId;
  }


  @Override
  public String toString() {
      return &amp;quot;NewUserResult[&amp;quot; + success + &amp;quot;,&amp;quot; + newUserId + &amp;quot;]&amp;quot;;
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So, roughly 15 steps leading to 60 LOC.&lt;/p&gt;

&lt;p&gt;Which isn&amp;#8217;t necessarily a big deal, until you have to repeat it for every Action/Result pair in your project.&lt;/p&gt;

&lt;h2 id='generating_actionresult_dtos'&gt;Generating Action/Result DTOs&lt;/h2&gt;

&lt;p&gt;So, let&amp;#8217;s try this again. If we think about it, what are we really trying to do?&lt;/p&gt;

&lt;p&gt;We have 1 operation: creating a new user. We know it should take 1 input parameter (&lt;code&gt;username&lt;/code&gt;) and return two output parameters (&lt;code&gt;success&lt;/code&gt; and &lt;code&gt;newUserId&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;With &lt;code&gt;gwt-mpv-apt&lt;/code&gt;, we can specify this directly by:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Make a new &lt;code&gt;NewUserSpec&lt;/code&gt; class&lt;/li&gt;

&lt;li&gt;Add a &lt;code&gt;String in1username&lt;/code&gt; field (&lt;code&gt;in1&lt;/code&gt; == first input parameter)&lt;/li&gt;

&lt;li&gt;Add a &lt;code&gt;boolean out1success&lt;/code&gt; field (&lt;code&gt;out1&lt;/code&gt; == first output parameter)&lt;/li&gt;

&lt;li&gt;Add a &lt;code&gt;Integer out2newUserId&lt;/code&gt; field (&lt;code&gt;out2&lt;/code&gt; == second output parameter)&lt;/li&gt;

&lt;li&gt;Add a &lt;code&gt;GenDispatch&lt;/code&gt; annotation&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So, it while look like:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;@GenDispatch
public class NewUserSpec {
  String in1username;
  boolean out1success;
  Integer out2newUserId;
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And that&amp;#8217;s it.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;gwt-mpv-apt&lt;/code&gt; will step in (if you&amp;#8217;re in Eclipse &lt;strong&gt;as soon as you hit Save&lt;/strong&gt;), and generate the &lt;code&gt;NewUserAction&lt;/code&gt; and &lt;code&gt;NewUserResult&lt;/code&gt; classes that look exactly like the ~60 lines of boilerplate above from this 6 lines of spec.&lt;/p&gt;

&lt;p&gt;That&amp;#8217;s an &lt;strong&gt;order of magnitude&lt;/strong&gt; decrease in LOC (60 -&amp;gt; 6) and a &lt;strong&gt;3x decrease in manual steps&lt;/strong&gt; (15 -&amp;gt; 5).&lt;/p&gt;

&lt;h2 id='adding_up_the_savings'&gt;Adding Up The Savings&lt;/h2&gt;

&lt;p&gt;Saving ~50 LOC for one example is good. But, even better, this savings is applied to every command &lt;code&gt;Action/Result&lt;/code&gt; in your project.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m currently writing what I consider a small project, and it has 20 command patterns. So, 50 LOC &lt;code&gt;x&lt;/code&gt; 20 commands = 1,000 LOC I didn&amp;#8217;t have to write.&lt;/p&gt;

&lt;p&gt;So, pretty quickly, we&amp;#8217;re talking about real LOC that &lt;code&gt;gwt-mpv-apt&lt;/code&gt; should save you.&lt;/p&gt;

&lt;h2 id='events_too'&gt;Events Too&lt;/h2&gt;

&lt;p&gt;I&amp;#8217;ll do another post sometime with the details of &lt;code&gt;gwt-mpv-apt&lt;/code&gt;&amp;#8217;s GWT event support, but for now I&amp;#8217;ll leave you with a short of example:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;@GenEvent
public class FooChangedEventSpec {
  Foo p1foo;
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That will generate a &lt;code&gt;FooChangedEvent&lt;/code&gt;, &lt;code&gt;FooChangedHandler&lt;/code&gt;, and all sorts of other boilerplate that, if you&amp;#8217;ve written GWT events before, you&amp;#8217;ll know is a PITA to type out each time.&lt;/p&gt;

&lt;h2 id='getting_'&gt;Getting &lt;code&gt;gwt-mpv-apt&lt;/code&gt;&lt;/h2&gt;

&lt;p&gt;The &lt;a href='http://github.com/stephenh/gwt-mpv-apt'&gt;github page&lt;/a&gt; is the best place to go.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>GWT View Generation</title>
   <link href="http://draconianoverlord.com/2010/04/07/gwt-view-generation.html"/>
   <updated>2010-04-07T00:00:00-07:00</updated>
   <id>http://draconianoverlord.com/2010/04/07/gwt-view-generation</id>
   <content type="html">&lt;h2&gt;GWT View Generation&lt;/h2&gt;&lt;hr /&gt;
&lt;p&gt;This will be brief, but lately I&amp;#8217;ve been on a crusade to reduce the boilerplate in GWT MVP projects.&lt;/p&gt;

&lt;p&gt;My current target has been the trio of &lt;code&gt;FooView.ui.xml&lt;/code&gt;, &lt;code&gt;FooPresenter.Display&lt;/code&gt;, and &lt;code&gt;FooView&lt;/code&gt;, all of which are intrinsically linked. You end up making changes in one (usually &lt;code&gt;FooView.ui.xml&lt;/code&gt;) and then dutifully percolating those changes to the other two.&lt;/p&gt;

&lt;p&gt;Or other three, as in my case I throw in a &lt;code&gt;StubFooView&lt;/code&gt; for testing (I find, after two or three uses, mocks get old and stubs are more pragmatic).&lt;/p&gt;

&lt;p&gt;So, I did a short spike for the last two mornings and am becoming convinced I can generate everything from the single &lt;code&gt;FooView.ui.xml&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;The steps are basically:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Scan &lt;code&gt;FooView.ui.xml&lt;/code&gt; for &lt;code&gt;ui:field&lt;/code&gt; declarations, record their type+name&lt;/li&gt;

&lt;li&gt;For each &lt;code&gt;ui:field&lt;/code&gt;, come up with its &lt;code&gt;HasXxx&lt;/code&gt; (or really &lt;code&gt;IsXxx&lt;/code&gt;, see later)&lt;/li&gt;

&lt;li&gt;Create &lt;code&gt;IFooView&lt;/code&gt; with a method &lt;code&gt;HasXxx&lt;/code&gt; for each &lt;code&gt;ui:field&lt;/code&gt;&lt;/li&gt;

&lt;li&gt;Create &lt;code&gt;FooView&lt;/code&gt; with a &lt;code&gt;@UiField&lt;/code&gt;-annotated field + method for each &lt;code&gt;ui:field&lt;/code&gt;&lt;/li&gt;

&lt;li&gt;Create &lt;code&gt;StubFooView&lt;/code&gt; with the stub version of each &lt;code&gt;ui:field&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I have this all basically working. It means for each presenter/view in your project, instead of 4+ hand-written files (presenter, &lt;code&gt;ui.xml&lt;/code&gt;, interface, view, stub), you have just 2 (presenter, &lt;code&gt;ui.xml&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;For me, this would make GWT MVP drastically less painful.&lt;/p&gt;

&lt;h2 id='_vs_'&gt;&lt;code&gt;HasXxx&lt;/code&gt; vs. &lt;code&gt;IsXxx&lt;/code&gt;&lt;/h2&gt;

&lt;p&gt;Mapping a &lt;code&gt;ui:field&lt;/code&gt; to a single &lt;code&gt;HasXxx&lt;/code&gt; interface is problematic because each widget has multiple &lt;code&gt;HasXxx&lt;/code&gt; interfaces. For example, &lt;code&gt;Anchor&lt;/code&gt; has &lt;code&gt;HasClickHandlers&lt;/code&gt;, &lt;code&gt;HasAllFocusHandlers&lt;/code&gt;, &lt;code&gt;HasName&lt;/code&gt;, &lt;code&gt;HasHTML&lt;/code&gt;, etc.&lt;/p&gt;

&lt;p&gt;If you put a &lt;code&gt;gwt:Anchor&lt;/code&gt; in your &lt;code&gt;ui.xml&lt;/code&gt;, which &lt;code&gt;HasXxx&lt;/code&gt; should we expose to the presenter? What if the presenter needs more than one?&lt;/p&gt;

&lt;p&gt;My answer is to introduce a new interface, &lt;code&gt;IsAnchor&lt;/code&gt;, that extends all of these interfaces and, by returning just the one &lt;code&gt;IsAnchor&lt;/code&gt; type, your presenter has access to all of its constituent &lt;code&gt;HasClickHandlers&lt;/code&gt;/etc. methods.&lt;/p&gt;

&lt;p&gt;To me this makes a lot of sense anyway, as I was always annoyed with having to return the same &lt;code&gt;Anchor&lt;/code&gt; field multiple times in my view implementation, once for each &lt;code&gt;HasXxx&lt;/code&gt; interface I needed for it.&lt;/p&gt;

&lt;h2 id='the_problem'&gt;The Problem&lt;/h2&gt;

&lt;p&gt;Turns out &lt;code&gt;Anchor&lt;/code&gt; doesn&amp;#8217;t actually implement &lt;code&gt;IsAnchor&lt;/code&gt;. Of course, given &lt;code&gt;IsAnchor&lt;/code&gt; is our own interface.&lt;/p&gt;

&lt;p&gt;So, we have several options:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Composition: make a new class &lt;code&gt;GwtAnchor implements IsAnchor&lt;/code&gt;, with a constructor &lt;code&gt;GwtAnchor(Anchor anchor)&lt;/code&gt;, then you implement a whole bunch of delegate methods in &lt;code&gt;GwtAnchor&lt;/code&gt; that just call &lt;code&gt;anchor.xxx&lt;/code&gt;.&lt;/li&gt;

&lt;li&gt;Inheritance: make a new class &lt;code&gt;GwtAnchor extends Anchor implements IsAnchor&lt;/code&gt; and your mostly done, though now your &lt;code&gt;ui.xml&lt;/code&gt; file will have to have a &lt;code&gt;foo:GwtAnchor&lt;/code&gt; declaration instead of the regular &lt;code&gt;gwt:Anchor&lt;/code&gt;.&lt;/li&gt;

&lt;li&gt;Forking: Add &lt;code&gt;IsAnchor&lt;/code&gt; to the GWT code base and just make the real &lt;code&gt;Anchor&lt;/code&gt; implement &lt;code&gt;IsAnchor&lt;/code&gt;. Done.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I started out with composition only because I&amp;#8217;ve only done a few minor widgets. But it involves a whole lot of boilerplate. Inheritance is probably what I should try next. But forking is awfully tempting because it, for the most part, just makes the problem go away.&lt;/p&gt;

&lt;p&gt;Of course, even with forking, I&amp;#8217;ll still have to implement a &lt;code&gt;StubIsAnchor&lt;/code&gt; for testing. Hopefully that won&amp;#8217;t be too bad. It is definitely an up-front investment, but I&amp;#8217;m convinced the stub will pay off over the long term vs. mocking.&lt;/p&gt;

&lt;p&gt;My &lt;code&gt;ViewGenerator&lt;/code&gt; spike is currently 200 lines. Pretty simple really, it will not get much larger. The hard part is surgically inserting the &lt;code&gt;IsXxx&lt;/code&gt; interfaces into the multitude of GWT widgets. Which is not so much hard, but potentially very time consuming to get full coverage of all of the widget.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>GWT MVP Tables</title>
   <link href="http://draconianoverlord.com/2010/03/31/gwt-mvp-tables.html"/>
   <updated>2010-03-31T00:00:00-07:00</updated>
   <id>http://draconianoverlord.com/2010/03/31/gwt-mvp-tables</id>
   <content type="html">&lt;h2&gt;GWT MVP Tables&lt;/h2&gt;&lt;hr /&gt;
&lt;p&gt;&lt;strong&gt;Update 2011/12/29:&lt;/strong&gt; This post was originally about the gwt-mpv framework, which has since been rechristened Tessell, see &lt;a href='http://www.tessell.org'&gt;tessell.org&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update 2010/11/30&lt;/strong&gt;: I&amp;#8217;ve added docs for these two approaches to GWT MVP tables: &lt;a href='http://www.tessell.org/rowtable.html'&gt;row tables&lt;/a&gt; and &lt;a href='http://www.tessell.org/celltable.html'&gt;cell tables&lt;/a&gt; in Tessell. (&lt;a href='http://www.tessell.org'&gt;Tessell&lt;/a&gt; is a framework to reduce the MVP boilerplate I talked about in this post.)&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m building a GWT application and, per the latest &lt;a href='http://code.google.com/events/io/2009/sessions/GoogleWebToolkitBestPractices.html'&gt;best practices&lt;/a&gt;, using a MVP (model view presenter) approach.&lt;/p&gt;

&lt;p&gt;For awhile I was confused about how to build non-trivial views. For example, a dashboard-type table where each row is not just strings of text but an interactive unit.&lt;/p&gt;

&lt;p&gt;Last week I finally found an approach that I like: per-row presenters. The trick with complex views seems to be searching for a sweet spot in the decomposition of your presenter/view pairs that is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;fine-grained enough to facilitate easy implementation and testing, but&lt;/li&gt;

&lt;li&gt;not so fine-grained that it buries you in MVP/DI boilerplate.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I&amp;#8217;ll add the disclaimer that if there is anything GWT is not, it is not succinct. Boilerplate seems to be the norm for GWT, and especially the MVP approach. I think the assertion is that, for large AJAX applications/codebases, you should be willing to accept some boilerplate as a tradeoff for gaining compile-time checking of type-safety and mockable views for extremely fast/non-browser-based test suites.&lt;/p&gt;

&lt;h2 id='mvp_review'&gt;MVP Review&lt;/h2&gt;

&lt;p&gt;So, just to be on the same page, GWT MVP exists primarily to divorce your AJAX application&amp;#8217;s business logic from the GWT UI widgets. This is imperative because, unfortunately, the widget are all concrete classes that rely on browser-provided behavior and will not run in a pure-Java unit test.&lt;/p&gt;

&lt;p&gt;Since GWT itself does not put interfaces between your code and the browser, GWT MVP is how you by convention put interfaces between your code and the browser. With these interfaces in place, you can mock/stub them out and test your logic in a fast, browser-less unit test.&lt;/p&gt;

&lt;p&gt;To show an example, a regular form that would edit a &lt;code&gt;Foo&lt;/code&gt; object in GWT MVP is usually a &lt;code&gt;FooPresenter&lt;/code&gt;/&lt;code&gt;FooView&lt;/code&gt; pair that looks something like:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public class FooPresenter extends BasicPresenter&amp;lt;Display&amp;gt; {
  // inner-interface defines the UI contract
  // our FooPresenter modifies
  public interface Display {
    // these HasXxx are all interfaces
    HasValue nameField();
    HasValue descriptionField();
    HasClickHandlers saveButton();
  }

  private final Foo foo;

  public FooPresenter(Display display, Foo foo) {
    // display is an implementation of our view, either
    // provided by the real view that uses GWT widgets
    // (typically named FooView) or a mock/stub
    super(display);
    this.foo = foo;
  }

  // Called when the page/tab for our foo loads
  public void onBind() {
    // hook up business logic to the display&amp;#39;s
    // HasXxx interfaces
    display.nameField().setText(foo.getName());
    display.nameField().addValueChangeHandler(new OnNameChanged());
    display.descriptionField().setText(foo.getDescription());
    display.descriptionField().addValueChangeHandler(new OnDescriptionChanged());
  }

  private class OnNameChanged implements ValueChangedHandler&amp;lt;String&amp;gt; {
    public void onChange(String newValue) {
      foo.setName(newValue);
    }
  }

  private class OnDescriptionChanged implements ValueChangedHandler&amp;lt;String&amp;gt; {
    // etc.
  }
}

public class FooView implements FooPresenter.Display {
  // uibinder code...
  @UiField
  TextBox nameField;

  public nameField() {
    return nameField;
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The idea is that the &lt;code&gt;Display&lt;/code&gt; interface is easily mockable, so you can write a &lt;code&gt;FooPresenterTest&lt;/code&gt; that creates a mock &lt;code&gt;Display&lt;/code&gt;, with mock &lt;code&gt;HasValue&lt;/code&gt;/etc., and test all of your &lt;code&gt;FooPresenter&lt;/code&gt; business logic without actually using any GWT widgets that would require running in a browser environment (like &lt;code&gt;GWTTestCase&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;So, that was the review, on to tables.&lt;/p&gt;

&lt;h2 id='gwt_tables'&gt;GWT Tables&lt;/h2&gt;

&lt;p&gt;To me, it was not immediately obvious how to implement tables in GWT MVP. There is no &lt;code&gt;HasTable&lt;/code&gt; interface that holds your hand like &lt;code&gt;HasText&lt;/code&gt;/&lt;code&gt;HasValue&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;GWT tables are also complicated by the fact that UiBinder only does static templating&amp;#8211;unlike nearly every other HTML rendering library out there, it lacks any notion of iteration or &lt;code&gt;for&lt;/code&gt; loops or even &lt;code&gt;if&lt;/code&gt; statements. You cannot just &lt;code&gt;#for($row in $rows) &amp;lt;tr&amp;gt;row HTML goes here&amp;lt;/tr&amp;gt;&lt;/code&gt; like you would in Velocity/JSP/etc.&lt;/p&gt;

&lt;h2 id='table_models'&gt;Table Models&lt;/h2&gt;

&lt;p&gt;Instead, the usual MVP approach is to use a &lt;code&gt;TableModel&lt;/code&gt;. The presenter gathers the domain objects (or creates an interface that can load domain objects on demand) and puts them into a &lt;code&gt;TableModel&lt;/code&gt; instance. It then pushes the model into the view, which iterates over the model and creates widgets as needed.&lt;/p&gt;

&lt;p&gt;One of the GWT examples uses a &lt;code&gt;List&amp;lt;String[]&amp;gt;&lt;/code&gt; as a very naive &lt;code&gt;TableModel&lt;/code&gt;, but it works well to show the basic idea:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;// displays a parent and its list of Foo children
public class ParentPresenter extends BasicPresenter&amp;lt;Display&amp;gt; {
  public interface Display {
    void setData(List&amp;lt;String[]&amp;gt; model);
  }

  private final Parent parent; // set by constructor

  // Called when the page/tab for our parent loads
  public void onBind() {
    List&amp;lt;String[]&amp;gt; model = new ArrayList&amp;lt;String[]&amp;gt;();
    for (Foo foo : parent.getFoos()) {
      model.add(newLine(foo));
    }
    display.setData(model);
  }

  // translate Foo domain object into strings for each cell
  private String[] newLine(Foo foo) {
    return new String[] { foo.getName(), foo.getDescription() };
  }
}

public class ParentView implements ParentPresenter.Display {
  // uibinder code...
  @UiField
  HTMLTable table;
  public void setData(List&amp;lt;String[]&amp;gt; model) {
    table.resizeRows(model.size());
    int i = 0;
    for (String[] row : model) {
      table.setText(i, 0, row[0]);
      table.setText(i, 1, row[1]);
      i++;
    }
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The GWT incubator has a much more powerful, elaborate &lt;code&gt;TableModel&lt;/code&gt; for their &lt;a href='http://code.google.com/p/google-web-toolkit-incubator/wiki/PagingScrollTable'&gt;&lt;code&gt;PagingScrollTable&lt;/code&gt;&lt;/a&gt; that is worth checking out if this approach works for you.&lt;/p&gt;

&lt;p&gt;But, the basic idea here is that we&amp;#8217;re shoving data into the view and pretty much stopping there.&lt;/p&gt;

&lt;h2 id='where_table_models_work'&gt;Where Table Models Work&lt;/h2&gt;

&lt;p&gt;I think it works very well if your presenter can pre-format everything into basic &lt;code&gt;String&lt;/code&gt;s, which makes the view logic very dumb.&lt;/p&gt;

&lt;p&gt;The GWT incubator &lt;code&gt;TableModel&lt;/code&gt; certainly looks very nice if your auto-loading-on-scroll 100s/1000s of rows. They have a &lt;code&gt;CachedTableModel&lt;/code&gt; wrapper that will ensure you only fetch rows from the server that you really need. Pretty neat.&lt;/p&gt;

&lt;p&gt;However, I do start to get a little hesitant when the view interface starts looking more like &lt;code&gt;setData(List&amp;lt;Foo&amp;gt; model)&lt;/code&gt; (or &lt;code&gt;TableModel&amp;lt;Foo&amp;gt;&lt;/code&gt;) and the view starts interrogating domain objects directly, as this is more complex logic that won&amp;#8217;t be under unit tests. But it&amp;#8217;s not that big of a deal.&lt;/p&gt;

&lt;h2 id='where_table_models_dont_work'&gt;Where Table Models Don&amp;#8217;t Work&lt;/h2&gt;

&lt;p&gt;The main problem I see with &lt;code&gt;TableModel&lt;/code&gt;s is that there is not an obvious way for the presenter that calls &lt;code&gt;display.setData(model)&lt;/code&gt; to get back out &lt;code&gt;HasXxx&lt;/code&gt; interfaces for each of the widgets the view creates.&lt;/p&gt;

&lt;p&gt;For example, for a &amp;#8220;dashboard&amp;#8221;-style table, each row doesn&amp;#8217;t have just read-only data, but interactive features where a user can start/stop/pause each row&amp;#8217;s domain object, which then causes various row-specific style/images changes that are best performed and tested against &lt;code&gt;HasXxx&lt;/code&gt; interfaces.&lt;/p&gt;

&lt;p&gt;I looked at &lt;a href='http://james.apache.org/hupa/index.html'&gt;Hupa&lt;/a&gt; and others, but did not find anyone using a &lt;code&gt;TableModel&lt;/code&gt; and then pushing per-row/per-cell &lt;code&gt;HasXxx&lt;/code&gt; interfaces back into a presenter. Perhaps I just missed it, in which case please correct me.&lt;/p&gt;

&lt;p&gt;There is an idiom where you can attach a listener to the entire table, and then ask the view to derive which element it is for:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public class ParentPresenter extends BasicPresenter&amp;lt;Display&amp;gt; {
  public interface Display {
    // fired for any click anywhere in the table
    HasClickHandlers tableClicked();
    // translate event -&amp;gt; int
    int getRowForClick(ClickEvent event);
    // then any changing row method requires an int
    changeStyle(int row, String otherParams);
  }

  public void onBind() {
    display.tableClicked().addClickHandler(new OnTableClick());
  }

  private class OnTableClick implements ClickHandler {
    public void onClick(ClickEvent event) {
      int row = display.getRowForClick(event);
      if (row != -1) {
        // perform action against row
        display.changeStyle(row, &amp;quot;foo&amp;quot;);
      }
    }
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;However this seems less than ideal to me. The view becomes more complicated, and the presenter no longer has concrete &lt;code&gt;HasXxx&lt;/code&gt; interfaces that are easy to wire up and stub out. There is also no clear place to store per-cell/per-row state, except perhaps in maps or other fields in the parent presenter.&lt;/p&gt;

&lt;h2 id='first_attempt_percell_presenters'&gt;First Attempt: Per-Cell Presenters&lt;/h2&gt;

&lt;p&gt;My initial thoughts were that I wanted each cell to have its own presenter instance. This seems awfully intuitive, as the presenter would have its own view with the &lt;code&gt;HasXxx&lt;/code&gt; interfaces for its cell.&lt;/p&gt;

&lt;p&gt;It also fits very nicely with the GWT &lt;code&gt;HTMLTable&lt;/code&gt; API, which is all about cells (e.g. the method &lt;code&gt;setWidget(int row, int column, Widget widget)&lt;/code&gt; and friends).&lt;/p&gt;

&lt;p&gt;This approach would look something like:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public class ParentPresenter extends BasicPresenter&amp;lt;Display&amp;gt; {
  public interface Display {
    void setCell(int row, int column, WidgetDisplay display);
  }

  public void onBind() {
    int i = 0;
    for (Foo foo : parent.getFoos()) {
      display.setCell(i, 0, new CellOnePresenter(foo).getDisplay());
      display.setCell(i, 1, new CellTwoPresenter(foo).getDisplay());
      i++;
    }
  }
}

public class ParentView implements ParentPresenter.Display {
  // uibinder code...
  @UiField
  HTMLTable fooTable;
  public void setCell(int row, int column, WidgetDisplay display) {
    fooTable.setWidget(row, column, display.asWidget());
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Just looking at this example, it doesn&amp;#8217;t seem that bad. I thought it&amp;#8217;d work out nicely.&lt;/p&gt;

&lt;p&gt;However, several folks on the &lt;a href='http://code.google.com/p/gwt-presenter/'&gt;gwt-presenter&lt;/a&gt; mailing list warned me against going this route. And turns out they were exactly right.&lt;/p&gt;

&lt;p&gt;The overhead of having a separate presenter-view pair for every table column was just too much boilerplate. After &lt;code&gt;CellOnePresenter&lt;/code&gt;, &lt;code&gt;CellOneView&lt;/code&gt;, &lt;code&gt;CellOneView.ui.xml&lt;/code&gt;, &lt;code&gt;CellTwoPresenter&lt;/code&gt;, and &lt;code&gt;CellTwoView&lt;/code&gt;, I just couldn&amp;#8217;t bring myself to implement the rest of the columns.&lt;/p&gt;

&lt;h2 id='second_attempt_perrow_presenters'&gt;Second Attempt: Per-Row Presenters&lt;/h2&gt;

&lt;p&gt;After much complaining, I finally realized that the combination of &lt;code&gt;HTMLTable&lt;/code&gt;&amp;#8217;s per-cell API and my assumption that &amp;#8220;this is a table because there is a &lt;code&gt;&amp;lt;table&amp;gt;&lt;/code&gt; tag&amp;#8221; was leading me astray.&lt;/p&gt;

&lt;p&gt;A dashboard-style table is not really a table&amp;#8211;it&amp;#8217;s a vertical listing of per-row views. That the HTML code uses &lt;code&gt;&amp;lt;table&amp;gt;&lt;/code&gt; tags is purely an implementation detail.&lt;/p&gt;

&lt;p&gt;A per-row presenter, with its parent presenter as well, would look like:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public interace HasRows {
  void addRow(WidgetDisplay display);
}

// this is the parent presenter which
// has the dashboard on its page
public class ParentPresenter extends BasicPresenter&amp;lt;Display&amp;gt; {
  public interface Display {
    HasRows dashboard();
  }
  public void onBind() {
    for (Foo foo : parent.getFoos()) {
      FooRowPresenter p = new FooRowPresenter(foo);
      display.dashboard().addRow(p.getDisplay());
    }
  }
}

// this is the per-row presenter that will be instantiated once-per-Foo
// and have its view added to the parent&amp;#39;s dashboard table
public class FooRowPresenter extends BasicPresenter&amp;lt;Display&amp;gt; {
  // here are the per-row HasXxx interfaces
  public interface Display {
    HasCss columnCss();
    HasText nameCellText();
    HasText descriptionCellText();
    HasClickHandlers actionFooLink();
  }
  private final Foo foo; // set by constructor
  public void onBind() {
    // finally here is our per-row business logic
    display.nameCellText().setText(foo.getName());
    display.descriptionCellText().setText(foo.getDescription());
    display.actionFooLink().addClickHandler(new OnActionClick());
  }
  private class OnActionClick implements ClickHandler {
    public void onClick(ClickEvent click) {
      // hit server, etc.
      display.columnCss().addStyleName(&amp;quot;nowRed&amp;quot;);
    }
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;As far as how each row&amp;#8217;s concrete view class is implemented, I did some hacking so that the entire row has its own UiBinder file. E.g. &lt;code&gt;FooRowView.ui.xml&lt;/code&gt; might look like:&lt;/p&gt;

&lt;pre class='brush:xml'&gt;&lt;code&gt;&amp;lt;ui:UiBinder xmlns:ui=&amp;#39;urn:ui:com.google.gwt.uibinder&amp;#39; xmlns:gwt=&amp;#39;urn:import:com.google.gwt.user.client.ui&amp;#39;&amp;gt;
  &amp;lt;gwt:HTMLPanel tag=&amp;quot;table&amp;quot;&amp;gt;
    &amp;lt;tr ui:field=&amp;quot;column&amp;quot;&amp;gt;
      &amp;lt;td ui:field=&amp;quot;nameCell&amp;quot; /&amp;gt;
      &amp;lt;td ui:field=&amp;quot;descriptionCell&amp;quot; /&amp;gt;
      &amp;lt;td&amp;gt;&amp;lt;gwt:Anchor ui:field=&amp;quot;actionFoo&amp;quot;/&amp;gt;&amp;lt;/td&amp;gt;
    &amp;lt;/tr&amp;gt;
  &amp;lt;/gwt:HTMLPanel&amp;gt;
&amp;lt;/ui:UiBinder&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This &lt;code&gt;ui.xml&lt;/code&gt; file initially looks a little odd because each row has its own &lt;code&gt;&amp;lt;table&amp;gt;&lt;/code&gt; tag&amp;#8211;however, this is just a necessary hack because &lt;code&gt;HTMLPanel&lt;/code&gt; does not like its &lt;code&gt;tag&lt;/code&gt; attribute to be set to &lt;code&gt;tr&lt;/code&gt;. I guess when browsers do &lt;code&gt;innerHTML&lt;/code&gt;, they don&amp;#8217;t like a &lt;code&gt;tr&lt;/code&gt; running around without its parent &lt;code&gt;table&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So, to get around this, plus &lt;code&gt;HTMLTable&lt;/code&gt;&amp;#8217;s lack of a per-row API, I wrote a &lt;code&gt;RowTable&lt;/code&gt; widget that knows how to assemble rows (not cells) of content:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public class RowTable extends Panel implements HasRows {
  // copy/paste some boilerplate from HTMLTable

  // here is the key method--display is the HTMLPanel
  // with tag=table from FooRowView.ui.xml
  public void addRow(final WidgetDisplay display) {
    // get actual widget from the view interface
    Widget widget = display.asWidget();
    // Detaches if necessary
    widget.removeFromParent();
    // Logical attach
    rows.add(widget);
    // Physical attach (all TRs)
    final NodeList&amp;lt;Element&amp;gt; nodes = widget.getElement().getElementsByTagName(&amp;quot;TR&amp;quot;);
    for (int i = 0; i &amp;lt; nodes.getLength(); i++) {
      bodyElement.appendChild(nodes.getItem(i));
    }
    // Adopt
    adopt(widget);
  }&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So, we logically attach the entire &lt;code&gt;HTMLPanel&lt;/code&gt; widget (to get the usual &lt;code&gt;Widget&lt;/code&gt;/&lt;code&gt;attach&lt;/code&gt; magic), but for physically attaching we raid the &lt;code&gt;HTMLPanel&lt;/code&gt;&amp;#8217;s table element of all of its &lt;code&gt;TR&lt;/code&gt; elements (which should be just one given this display is for one row) and append them to our own &lt;code&gt;bodyElement&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id='any_downsides'&gt;Any Downsides?&lt;/h2&gt;

&lt;p&gt;So far, the only downside to per-row presenters is that it&amp;#8217;ll require another presenter/view pair, each with its own class, DI entry, etc. This can be considered boilerplate, but, per my disclaimer, that is pretty much the name of the game for GWT.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m also implementing the table&amp;#8217;s header row as its own presenter/view pair, meaning for one dashboard table I&amp;#8217;ll have 4 classes: &lt;code&gt;FooHeaderPresenter&lt;/code&gt;, &lt;code&gt;FooHeaderView&lt;/code&gt;, &lt;code&gt;FooRowPresenter&lt;/code&gt;, and &lt;code&gt;FooRowView&lt;/code&gt;. I would not mind avoiding the extra header presenter/view, but so far it has been the simplest to get working with the &lt;code&gt;RowTable&lt;/code&gt; (&lt;code&gt;HasRows&lt;/code&gt; actually has two methods, &lt;code&gt;addRow&lt;/code&gt; and &lt;code&gt;addHeader&lt;/code&gt; for adding to &lt;code&gt;tbody&lt;/code&gt; and &lt;code&gt;thead&lt;/code&gt; respectively).&lt;/p&gt;

&lt;p&gt;And, just to be clear, I&amp;#8217;m not advocating per-row presenters for any and every table in a GWT app. E.g. I would stick with &lt;code&gt;TabelModel&lt;/code&gt; and &lt;code&gt;TableBulkRenderer&lt;/code&gt; for more typical &amp;#8220;data&amp;#8221; tables&amp;#8211;hundreds/thousands of rows that are read-only (or near-read-only).&lt;/p&gt;

&lt;h2 id='wrapping_up'&gt;Wrapping Up&lt;/h2&gt;

&lt;p&gt;That&amp;#8217;s about it. I&amp;#8217;ve been very pleased with how things are going with this approach so far.&lt;/p&gt;

&lt;p&gt;By stepping back and realizing the row was really its own view&amp;#8211;finding the presenter/view decomposition sweet spot&amp;#8211;I&amp;#8217;m now able to unit test the in-row interactions on their own without even setting them up in the parent table.&lt;/p&gt;

&lt;p&gt;The per-row display interfaces, so far, have been awfully simple and just as easy to stub out as the usual form-style name/description examples that make MVP look easy.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Lift Templating is a Joke</title>
   <link href="http://draconianoverlord.com/2010/03/10/lift-templating.html"/>
   <updated>2010-03-10T00:00:00-08:00</updated>
   <id>http://draconianoverlord.com/2010/03/10/lift-templating</id>
   <content type="html">&lt;h1 id='lift_templating_is_a_joke'&gt;Lift Templating is a Joke&lt;/h1&gt;

&lt;p&gt;I want to like &lt;a href='http://liftweb.net'&gt;Lift&lt;/a&gt;. I like &lt;a href='http://scala-lang.org'&gt;Scala&lt;/a&gt; and Lift seems like the goto Scala web framework for now.&lt;/p&gt;

&lt;p&gt;I have several nitpicks with it, the one I&amp;#8217;ll rant about now is its templating syntax.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disclaimer:&lt;/strong&gt; I know &amp;#8220;joke&amp;#8221; is a harsh word&amp;#8211;but given the combination of the author&amp;#8217;s superior attitude towards other frameworks plus his own solution missing the very goals he sets forth, I felt compelled to respond in kind.&lt;/p&gt;

&lt;h2 id='lifts_lofty_goal'&gt;Lift&amp;#8217;s Lofty Goal&lt;/h2&gt;

&lt;p&gt;First, let&amp;#8217;s start with the author waxing poetic about his design goals in Lift&amp;#8217;s &lt;a href='http://liftweb.net/docs/getting_started/mod_master.html'&gt;Getting Started&lt;/a&gt;.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;&lt;em&gt;My first design goal with Lift was to make sure that no programming logic and no programming symbols make it into the static display templates.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;ERB and JSP and ASP all have the fatal flaw of allowing code in the view. This is bad for a bunch of reasons. First, it makes editing the templates difficult with HTML layout tools unless those tools are familiar with the syntax being used. Second, there are “foreign” symbols in the layout, which tends to be less than optimal for the HTML designers.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;So, the static templates in Lift are strictly for display only. They can be manipulated with standard design tools (e.g., Dreamweaver). They can never contain program logic.&lt;/em&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;So, cool, I can agree with that. Good goals.&lt;/p&gt;

&lt;h2 id='falling_short'&gt;Falling Short&lt;/h2&gt;

&lt;p&gt;But then you see the implementation:&lt;/p&gt;

&lt;pre class='brush:html'&gt;&lt;code&gt;&amp;lt;html&amp;gt; 
... 
&amp;lt;lift:Show.myForm form=&amp;quot;POST&amp;quot;&amp;gt; 
&amp;lt;tr&amp;gt; 
  &amp;lt;td&amp;gt;Name&amp;lt;/td&amp;gt; 
  &amp;lt;td&amp;gt;&amp;lt;f:name&amp;gt;&amp;lt;input type=&amp;quot;text&amp;quot;/&amp;gt;&amp;lt;/f:name&amp;gt;&amp;lt;/td&amp;gt; 
&amp;lt;/tr&amp;gt; 
&amp;lt;tr&amp;gt; 
  &amp;lt;td&amp;gt;Birthyear&amp;lt;/td&amp;gt; 
  &amp;lt;td&amp;gt;&amp;lt;f:year&amp;gt; 
      &amp;lt;select&amp;gt;&amp;lt;option&amp;gt;2007&amp;lt;/option&amp;gt;&amp;lt;/select&amp;gt; 
  &amp;lt;/f:year&amp;gt;&amp;lt;/td&amp;gt; 
&amp;lt;/tr&amp;gt; 
&amp;lt;tr&amp;gt; 
  &amp;lt;td&amp;gt;&amp;amp;nbsp;&amp;lt;/td&amp;gt; 
  &amp;lt;td&amp;gt;&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Add&amp;quot;/&amp;gt;&amp;lt;/td&amp;gt; 
&amp;lt;/tr&amp;gt; 
&amp;lt;/lift:Show.myForm&amp;gt; 
&amp;lt;/html&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And&amp;#8230;what? What happened to no separation? Designer friendly? Is Dreamweaver really going to like that &lt;code&gt;&amp;lt;tr&amp;gt;&lt;/code&gt; tag coming after a &lt;code&gt;&amp;lt;left:Show.myForm&amp;gt;&lt;/code&gt; tag instead of a &lt;code&gt;&amp;lt;table&amp;gt;&lt;/code&gt; tag?&lt;/p&gt;

&lt;p&gt;I don&amp;#8217;t see how this achieves the design goal of &amp;#8220;no programming logic&amp;#8221;. I consider the &lt;code&gt;&amp;lt;lift:xxx&amp;gt;&lt;/code&gt; tags to be programming symbols just as much as curly braces.&lt;/p&gt;

&lt;p&gt;Yeah, okay, they are tags, but they are not native HTML tags that any designer/web design tool will have seen before. They are programming symbols.&lt;/p&gt;

&lt;p&gt;I wouldn&amp;#8217;t care about the &lt;code&gt;&amp;lt;lift:xxx&amp;gt;&lt;/code&gt; syntax that much&amp;#8211;other projects take this approach as well, e.g. &lt;a href='http://code.google.com/webtoolkit/'&gt;GWT&lt;/a&gt; off the top of my head.&lt;/p&gt;

&lt;p&gt;But since Lift goes out of its way to assert, repeatedly, how designer friendly it is, when it&amp;#8217;s not, just annoys me.&lt;/p&gt;

&lt;h2 id='pure_rocks'&gt;Pure Rocks&lt;/h2&gt;

&lt;p&gt;The Lift crowd needs to look at &lt;a href='http://beebole.com/pure/'&gt;pure&lt;/a&gt; instead.&lt;/p&gt;

&lt;p&gt;If you look at the &lt;a href='http://beebole.com/pure/demos/'&gt;demos&lt;/a&gt;, one of pure&amp;#8217;s table examples is:&lt;/p&gt;

&lt;pre class='brush:html'&gt;&lt;code&gt;&amp;lt;table class=&amp;quot;playerList&amp;quot;&amp;gt;
  &amp;lt;thead&amp;gt;
    &amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Player&amp;lt;/th&amp;gt;&amp;lt;/tr&amp;gt;
  &amp;lt;/thead&amp;gt;
  &amp;lt;tbody&amp;gt;
    &amp;lt;tr class=&amp;quot;player&amp;quot;&amp;gt;
     &amp;lt;td&amp;gt;Chloe&amp;lt;/td&amp;gt;
   &amp;lt;/tr&amp;gt;
  &amp;lt;/tbody&amp;gt;
&amp;lt;/table&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now &lt;strong&gt;this&lt;/strong&gt; is designer friendly. There really are no programming symbols in this.&lt;/p&gt;

&lt;p&gt;Now, admittedly, pure requires a few hoops for the programmer to jump through, e.g. this directive:&lt;/p&gt;

&lt;pre class='brush:jscript'&gt;&lt;code&gt;{
  &amp;quot;tbody tr&amp;quot;: {
    &amp;quot;player&amp;lt;-players&amp;quot;: {
      &amp;quot;td&amp;quot;: &amp;quot;player&amp;quot;,
      &amp;quot;td@style&amp;quot;: &amp;quot;\&amp;quot;cursor:pointer\&amp;quot;&amp;quot;,
      &amp;quot;td@onclick&amp;quot;: &amp;quot;\&amp;quot;clickLine(this);\&amp;quot;&amp;quot;
    }
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And this could probably be cleaned up.&lt;/p&gt;

&lt;p&gt;Even if the templating was driven entirely off of HTML &lt;code&gt;id&lt;/code&gt; attributes, I think you&amp;#8217;d have a usable solution.&lt;/p&gt;

&lt;p&gt;I admit I haven&amp;#8217;t fully thought it through, but I&amp;#8217;m optimistic.&lt;/p&gt;

&lt;h2 id='code_generation'&gt;Code Generation&lt;/h2&gt;

&lt;p&gt;While I&amp;#8217;m on the topic of templating, I like how GWT parses its templates at compile-time and ensures they type-safely match your usage of the templates.&lt;/p&gt;

&lt;p&gt;What I don&amp;#8217;t get is why this has to happen during the already-time-consuming GWT startup phase.&lt;/p&gt;

&lt;p&gt;Even a project like Lift could build a code generator that, after parsing your templates at &lt;strong&gt;build-time&lt;/strong&gt;, creates an &lt;code&gt;XxxTemplate.scala&lt;/code&gt; class with type-safe elements for you to program against.&lt;/p&gt;

&lt;p&gt;For example, take something like &lt;code&gt;foo.html&lt;/code&gt;:&lt;/p&gt;

&lt;pre class='brush:html'&gt;&lt;code&gt;&amp;lt;table id=&amp;quot;playerList&amp;quot;&amp;gt;
  ...
&amp;lt;/table&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And after running &lt;code&gt;lift generate-templates&lt;/code&gt; on the command line (ideally ran automatically each time your HTML files change), Lift would spit out a class:&lt;/p&gt;

&lt;pre class='brush:scala'&gt;&lt;code&gt;object FooHtml {
  val playerList = new TableElement(&amp;quot;playerList&amp;quot;)
  // other elements/etc.
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This output may get somewhat ugly, but its basically going to be the same code Lift is interpreting at runtime (or, in the case of joys like &lt;a href='http://tapestry.apache.org/'&gt;Tapestry&lt;/a&gt;, are bytecode compiling at runtime).&lt;/p&gt;

&lt;p&gt;All of Lift&amp;#8217;s &lt;code&gt;bind&lt;/code&gt; calls could then be made again, you know, actual objects instead of the String keys.&lt;/p&gt;

&lt;h2 id='magic_strings'&gt;Magic Strings&lt;/h2&gt;

&lt;p&gt;Which again is ironic given how Lift just ragged on &lt;code&gt;HttpSession&lt;/code&gt;, again from their &lt;a href='http://liftweb.net/docs/getting_started/mod_master.html'&gt;Getting Started&lt;/a&gt;:&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;&lt;em&gt;Lift has a type-safe mechanism for storing variables during the scope of a given session.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;In Java, you would do something like casting a value retrieved from the &lt;code&gt;HttpSession&lt;/code&gt;. For example: &lt;code&gt;String myString = (String) httpSession.getAttribute(“Something”)&lt;/code&gt;; The problem with this code is that a developer may not remember that Something is support to be a &lt;code&gt;String&lt;/code&gt; and put a &lt;code&gt;String[]&lt;/code&gt; in it. Additionally, there&amp;#8217;s no well defined logic for creating a default value for the attribute.&lt;/em&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Well, good for you, Lift, you avoid magic Strings in session usage&amp;#8211;but then go right back to magic Strings all over your templating layer.&lt;/p&gt;

&lt;pre class='brush:scala'&gt;&lt;code&gt;private def doList(reDraw: () =&amp;gt; JsCmd)(html: NodeSeq): NodeSeq = 
  toShow.flatMap(td =&amp;gt; 
    bind(&amp;quot;todo&amp;quot;, html, 
      &amp;quot;check&amp;quot; -&amp;gt; ajaxCheckbox(
              td.done, 
              v =&amp;gt; {td.done(v).save; reDraw()}), 
      &amp;quot;priority&amp;quot; -&amp;gt; ajaxSelect(
              ToDo.priorityList, Full(td.priority.toString), 
              v =&amp;gt; {td.priority(v.toInt).save; reDraw()}), 
      &amp;quot;desc&amp;quot; -&amp;gt; desc(td, reDraw) 
  ))&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;See &lt;code&gt;&amp;quot;todo&amp;quot;&lt;/code&gt;, &lt;code&gt;&amp;quot;check&amp;quot;&lt;/code&gt;, &lt;code&gt;&amp;quot;priority&amp;quot;&lt;/code&gt;, etc.&amp;#8211;all untyped, magic strings.&lt;/p&gt;

&lt;p&gt;And, again, I wouldn&amp;#8217;t care so much had they just not touted their &lt;code&gt;SessionVar&lt;/code&gt;, and, also making the wording such that &amp;#8220;oh, you&amp;#8217;d do this crappy approach &lt;em&gt;in Java&lt;/em&gt;&amp;#8221;, when, no, Java can have a &lt;code&gt;SessionVar&lt;/code&gt; abstraction just as well as Scala/Lift can.&lt;/p&gt;

&lt;p&gt;I don&amp;#8217;t mention this because I have a chip on my shoulder about Scala. I actually really like Scala. But I do have a chip on my shoulder about the last 10 years of people bitching about how crappy Java is when really the problem with Java is not some inherent flaw but instead the self-inflicted complexity J2EE devs love foisting on their projects.&lt;/p&gt;

&lt;p&gt;Anyway, build-time code generation really isn&amp;#8217;t that bad. It just needs to be easy to run (automatic if possible), fast, and not produce crap code.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;d love to see Lift, or some other Java/Scala project, pick up this approach and run with it.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Moving an existing git repo into svn</title>
   <link href="http://draconianoverlord.com/2010/03/05/existing-git-into-svn.html"/>
   <updated>2010-03-05T00:00:00-08:00</updated>
   <id>http://draconianoverlord.com/2010/03/05/existing-git-into-svn</id>
   <content type="html">&lt;h2&gt;Moving an existing git repo into svn&lt;/h2&gt;&lt;hr /&gt;
&lt;p&gt;I&amp;#8217;ve found myself lately making local git repositories to prototype things that I later need to promote into &lt;a href='http://www.bizo.com'&gt;Bizo&lt;/a&gt;&amp;#8217;s internal Subversion repository.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git-svn&lt;/code&gt; supports this really well, with just a slight variation on the usual &lt;code&gt;git svn clone&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Instead of the standard &lt;code&gt;project/trunk|branches|tags&lt;/code&gt; we use a slightly different &lt;code&gt;parent/trunk|branches|tags/project&lt;/code&gt; so you&amp;#8217;ll see I specify the &lt;code&gt;-T/-t/-b&lt;/code&gt; flags.&lt;/p&gt;

&lt;h2 id='git_svn_init'&gt;git svn init&lt;/h2&gt;

&lt;p&gt;Here is what I do, from the existing local git repo:&lt;/p&gt;

&lt;pre class='brush:bash'&gt;&lt;code&gt;# Create the project directory in subversion
$ /usr/bin/svn mkdir https://foo.com/svn/parent/trunk/project -m &amp;quot;Make project directory.&amp;quot;
Committed revision 200.

# Initialize git-svn, doesn&amp;#39;t fetch anything yet
$ git svn init https://foo.com/svn/ -T parent/trunk/project -t parent/tags/project -b parent/branches/project --prefix=svn/

# Set authors so we get prettier authors
$ git config svn.authorsfile ../authors

# Now pull down the svn commits
$ git svn fetch
W: Ignoring error from SVN, path probably does not exist: Filesystem has no item: File not found: revision 100, path &amp;#39;/parent&amp;#39;
W: Do not be alarmed at the above message git-svn is just searching aggressively for old history.
This may take a while on large repositories
r200 = (guid) (refs/remotes/svn/trunk)

# We should now see our svn trunk setup under our svn remote
$ git branch -av
* master            c3a7161 The latest git commit.
  remotes/svn/trunk 3b7fed6 Make project directory.

# Now we want to take all of our local commits and rebase them on top of the new svn/trunk
$ git rebase svn/trunk
First, rewinding head to replay your work on top of it...
Applying: First git commit
Applying: The latest git commit

# Now we should see our local commits applied on top of svn/trunk
$ git lg
* 52b7977 (HEAD, master) The latest git commit
* a34e162 First git commit
* 3b7fed6 (svn/trunk) Make project directory.

# Everything is cool, push it back to svn
$ git svn dcommit
Committing to https://foo.com/svn/parent/trunk/project
...&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id='prefixsvn'&gt;&amp;#8211;prefix=svn&lt;/h2&gt;

&lt;p&gt;One flag I especially like lately, which you can also use with &lt;code&gt;git svn clone&lt;/code&gt;, is &lt;code&gt;--prefix=svn/&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This will prefix all of your tracking branches of the remote Subversion branches, tags, and trunk with &lt;code&gt;svn/&lt;/code&gt;, making it look a whole lot like the usual &lt;code&gt;origin/&lt;/code&gt; idiom used by regular git remotes.&lt;/p&gt;

&lt;p&gt;With the tracking branches having a prefix, you can also use them as local branch names, e.g.:&lt;/p&gt;

&lt;pre class='brush:bash'&gt;&lt;code&gt;# Name your copy of svn/trunk &amp;quot;trunk&amp;quot; instead of &amp;quot;master&amp;quot;
$ git checkout -b trunk master
Switched to a new branch &amp;#39;trunk&amp;#39;

$ git branch -d master
Deleted branch master (was 33c3136).

$ git branch -av
* trunk             33c3136 Latest svn commit
* remotes/svn/trunk 33c3136 Latest svn commit&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then if you have other branches you want to track:&lt;/p&gt;

&lt;pre class='brush:bash'&gt;&lt;code&gt;$ git checkout -b featurea svn/featurea&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id='almost_really_sweet'&gt;Almost Really Sweet&lt;/h2&gt;

&lt;p&gt;Overly, I&amp;#8217;ve been very pleased with &lt;code&gt;git-svn&lt;/code&gt; over the last few years I&amp;#8217;ve been using it.&lt;/p&gt;

&lt;p&gt;My one regret is that &lt;code&gt;git-svn&lt;/code&gt; will not push merges back to &lt;code&gt;svn&lt;/code&gt;, so I have to break down and use the &lt;code&gt;svn&lt;/code&gt; command line client to do that.&lt;/p&gt;

&lt;p&gt;Surprisingly, Bazaar actually &lt;a href='http://wiki.bazaar.canonical.com/BzrForeignBranches/Subversion'&gt;writes back svn:mergeinfo&lt;/a&gt;, which I&amp;#8217;m very jealous of. Assuming it works well, it&amp;#8217;s pretty nifty.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>git config</title>
   <link href="http://draconianoverlord.com/2010/03/04/git-config.html"/>
   <updated>2010-03-04T00:00:00-08:00</updated>
   <id>http://draconianoverlord.com/2010/03/04/git-config</id>
   <content type="html">&lt;h2&gt;git config&lt;/h2&gt;
&lt;p&gt;I&amp;#8217;ve got an enjoyable git environment set up, with various &lt;code&gt;.gitconfig&lt;/code&gt;/etc. hacks. This is just a post to document those for my future self and others.&lt;/p&gt;

&lt;p&gt;First, you should start with &lt;a href='http://github.com/rtomayko/git-sh'&gt;git-sh&lt;/a&gt;. It adds some bash shell customizations like a nice &lt;code&gt;PS1&lt;/code&gt; prompt, tab completion, and incredibly short git-specific aliases. I&amp;#8217;ll cover some of the aliases later, but this is the thing that started me down the &amp;#8220;how cool can I get my git environment&amp;#8221; path.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;ve included commented versions of my &lt;code&gt;.gitconfig&lt;/code&gt; and &lt;code&gt;.gitshrc&lt;/code&gt;, but you can get the raw versions &lt;a href='/files/gitconfig'&gt;here&lt;/a&gt; and &lt;a href='/files/gitshrc'&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id='example_shell_session'&gt;Example Shell Session&lt;/h2&gt;

&lt;p&gt;A lot of my customizations are around aliases, so this is a quick overview, and then the aliases are defined/explained below.&lt;/p&gt;

&lt;p&gt;Here is a made up example bash session with some of the commands:&lt;/p&gt;

&lt;pre class='brush:bash'&gt;&lt;code&gt;# show we&amp;#39;re in a basic java/whatever project
$ ls
src/ tests/

# start git-sh to get into a git-specific bash environment
$ git sh

# change some things
$ echo &amp;quot;file1&amp;quot; &amp;gt; src/package1/file1
$ echo &amp;quot;file2&amp;quot; &amp;gt; src/package2/file2
$ echo &amp;quot;file3&amp;quot; &amp;gt; src/package3/file2

# see all of our changes
$ d
# runs: git diff

# see only the changes in package1
$ dg package1
# runs: git diff src/package1/file1

# stage any path with &amp;#39;package&amp;#39; in it
$ ag package
# runs: git add src/package1/file1 src/package2/file2 src/package3/file3

# we only wanted package1, reset package2 and package3
$ rsg package2
# runs: git reset src/package2/file2
$ rsg package3
# runs: git reset src/package3/file3

# see what we have staged now (only package1)
$ p
# runs: git diff --cached

# commit it
$ commit -m &amp;quot;Changed stuff in package1&amp;quot;
# runs: git commit -m &amp;quot;...&amp;quot;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That is the basic idea.&lt;/p&gt;

&lt;p&gt;Most of the magic is from the &lt;code&gt;[alias]&lt;/code&gt; section of &lt;code&gt;.gitconfig&lt;/code&gt;, along with my &lt;code&gt;.gitshrc&lt;/code&gt; allowing the &lt;code&gt;git &lt;/code&gt; prefix to be dropped.&lt;/p&gt;

&lt;h2 id='id1'&gt;&lt;code&gt;.gitconfig&lt;/code&gt;&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;.gitconfig&lt;/code&gt; file is in your home directory and is for user-wide settings.&lt;/p&gt;

&lt;p&gt;Here is my current &lt;code&gt;.gitconfig&lt;/code&gt; with comments:&lt;/p&gt;

&lt;pre class='brush:plain'&gt;&lt;code&gt;[user]
  name = Stephen Haberman
  email = stephen@exigencecorp.com
[alias]
  # &amp;#39;add all&amp;#39; stages all new+changed+deleted files
  aa = !git ls-files -d | xargs -r git rm &amp;amp;&amp;amp; git ls-files -m -o --exclude-standard | xargs -r git add

  # &amp;#39;add grep&amp;#39; stages all new+changed that match $1
  ag = &amp;quot;!sh -c &amp;#39;git ls-files -m -o --exclude-standard | grep $1 | xargs -r git add&amp;#39; -&amp;quot;

  # &amp;#39;checkout grep&amp;#39; checkouts any files that match $1
  cg = &amp;quot;!sh -c &amp;#39;git ls-files -m | grep $1 | xargs -r git checkout&amp;#39; -&amp;quot;

  # &amp;#39;diff grep&amp;#39; diffs any files that match $1
  dg = &amp;quot;!sh -c &amp;#39;git ls-files -m | grep $1 | xargs -r git diff&amp;#39; -&amp;quot;

  # &amp;#39;patch grep&amp;#39; diff --cached any files that match $1
  pg = &amp;quot;!sh -c &amp;#39;git ls-files -m | grep $1 | xargs -r git diff --cached&amp;#39; -&amp;quot;

  # &amp;#39;remove grep&amp;#39; remove any files that match $1
  rmg = &amp;quot;!sh -c &amp;#39;git ls-files -d | grep $1 | xargs -r git rm&amp;#39; -&amp;quot;

  # &amp;#39;reset grep&amp;#39; reset any files that match $1
  rsg = &amp;quot;!sh -c &amp;#39;git ls-files -c --with-tree=HEAD | grep $1 | xargs -r git reset HEAD -- &amp;#39; -&amp;quot;

  # nice log output
  lg = log --graph --pretty=oneline --abbrev-commit --decorate

  # rerun svn show-ignore -&amp;gt; exclude
  si = !git svn show-ignore &amp;gt; .git/info/exclude

  # start git-sh
  sh = !git-sh
[color]
  # turn on color
  diff = auto
  status = auto
  branch = auto
  interactive = auto
  ui = auto
[color &amp;quot;branch&amp;quot;]
  # good looking colors i copy/pasted from somewhere
  current = green bold
  local = green
  remote = red bold
[color &amp;quot;diff&amp;quot;]
  # good looking colors i copy/pasted from somewhere
  meta = yellow bold
  frag = magenta bold
  old = red bold
  new = green bold
[color &amp;quot;status&amp;quot;]
  # good looking colors i copy/pasted from somewhere
  added = green bold
  changed = yellow bold
  untracked = red
[color &amp;quot;sh&amp;quot;]
  branch = yellow
[core]
  excludesfile = /home/stephen/.gitignore
  # two-space tabs
  pager = less -FXRS -x2
[push]
  # &amp;#39;git push&amp;#39; should only do the current branch, not all
  default = current
[branch]
  # always setup &amp;#39;git pull&amp;#39; to rebase instead of merge
  autosetuprebase = always
[diff]
  renames = copies
  mnemonicprefix = true
[svn]
  # push empty directory removals back to svn at directory deletes
  rmdir = true&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id='id2'&gt;&lt;code&gt;.gitshrc&lt;/code&gt;&lt;/h2&gt;

&lt;p&gt;This is my &lt;code&gt;.gitshrc&lt;/code&gt; file, heavily based off Ryan Tomayko&amp;#8217;s original.&lt;/p&gt;

&lt;p&gt;Ryan&amp;#8217;s original comments are prefixed with &lt;code&gt;#&lt;/code&gt;, I&amp;#8217;ll prefix my additions with &lt;code&gt;###&lt;/code&gt;, most of which are aliases to my &lt;code&gt;[alias]&lt;/code&gt; entries above and some &lt;code&gt;git-svn&lt;/code&gt; aliases.&lt;/p&gt;

&lt;pre class='brush:bash'&gt;&lt;code&gt;#!/bin/bash
# rtomayko&amp;#39;s ~/.gitshrc file
### With additions from stephenh

# git commit
gitalias commit=&amp;#39;git commit --verbose&amp;#39;
gitalias amend=&amp;#39;git commit --verbose --amend&amp;#39;
gitalias ci=&amp;#39;git commit --verbose&amp;#39;
gitalias ca=&amp;#39;git commit --verbose --all&amp;#39;
gitalias  n=&amp;#39;git commit --verbose --amend&amp;#39;

# git branch and remote
gitalias  b=&amp;#39;git branch -av&amp;#39; ### Added -av parameter
gitalias rv=&amp;#39;git remote -v&amp;#39;

# git add
gitalias  a=&amp;#39;git add&amp;#39;
gitalias au=&amp;#39;git add --update&amp;#39;
gitalias ap=&amp;#39;git add --patch&amp;#39;
### Added entries for my .gitconfig aliases
alias aa=&amp;#39;git aa&amp;#39; # add all updated/new/deleted
alias ag=&amp;#39;git ag&amp;#39; # add with grep
alias agp=&amp;#39;git agp&amp;#39; # add with grep -p
alias cg=&amp;#39;git cg&amp;#39; # checkout with grep
alias dg=&amp;#39;git dg&amp;#39; # diff with grep
alias pg=&amp;#39;git pg&amp;#39; # patch with grep
alias rsg=&amp;#39;git rsg&amp;#39; # reset with grep
alias rmg=&amp;#39;git rmg&amp;#39; # remove with grep

# git checkout
gitalias c=&amp;#39;git checkout&amp;#39;

# git fetch
gitalias f=&amp;#39;git fetch&amp;#39;

# basic interactive rebase of last 10 commits
gitalias r=&amp;#39;git rebase --interactive HEAD~10&amp;#39;
alias cont=&amp;#39;git rebase --continue&amp;#39;

# git diff
gitalias d=&amp;#39;git diff&amp;#39;
gitalias p=&amp;#39;git diff --cached&amp;#39;   # mnemonic: &amp;quot;patch&amp;quot;

# git ls-files
### Added o to list other files that aren&amp;#39;t ignored
gitalias o=&amp;#39;git ls-files -o --exclude-standard&amp;#39;    # &amp;quot;other&amp;quot;

# git status
alias  s=&amp;#39;git status&amp;#39;

# git log
gitalias  L=&amp;#39;git log&amp;#39;
# gitalias l=&amp;#39;git log --graph --pretty=oneline --abbrev-commit --decorate&amp;#39;
gitalias  l=&amp;quot;git log --graph --pretty=format:&amp;#39;%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset&amp;#39; --abbrev-commit --date=relative&amp;quot;
gitalias ll=&amp;#39;git log --pretty=oneline --abbrev-commit --max-count=15&amp;#39;

# misc
gitalias pick=&amp;#39;git cherry-pick&amp;#39;

# experimental
gitalias mirror=&amp;#39;git reset --hard&amp;#39;
gitalias stage=&amp;#39;git add&amp;#39;
gitalias unstage=&amp;#39;git reset HEAD&amp;#39;
gitalias pop=&amp;#39;git reset --soft HEAD^&amp;#39;
gitalias review=&amp;#39;git log -p --max-count=1&amp;#39;

### Added git svn asliases
gitalias si=&amp;#39;git si&amp;#39; # update svn ignore &amp;gt; exclude
gitalias sr=&amp;#39;git svn rebase&amp;#39;
gitalias sp=&amp;#39;git svn dcommit&amp;#39;
gitalias sf=&amp;#39;git svn fetch&amp;#39;

### Added call to git-wtf tool
gitalias wtf=&amp;#39;git-wtf&amp;#39;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Since I defined most of the interesting aliases in the &lt;code&gt;.gitconfig&lt;/code&gt; &lt;code&gt;[alias]&lt;/code&gt; section, it means they&amp;#8217;re all usable via &lt;code&gt;git xxx&lt;/code&gt;, e.g. &lt;code&gt;git ag foo&lt;/code&gt;, but listing &lt;code&gt;alias ag=&amp;#39;git ag&amp;#39;&lt;/code&gt; in &lt;code&gt;.gitshrc&lt;/code&gt; means you can also just use &lt;code&gt;ag foo&lt;/code&gt;, assuming you&amp;#8217;ve started the &lt;code&gt;git-sh&lt;/code&gt; environment.&lt;/p&gt;

&lt;p&gt;It results in some duplication, but means they&amp;#8217;re usable from both inside and outside of &lt;code&gt;git-sh&lt;/code&gt;, which I think is useful.&lt;/p&gt;

&lt;h2 id='thats_it'&gt;That&amp;#8217;s It&lt;/h2&gt;

&lt;p&gt;Leave comments if you have any similar hacks/links/etc.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Caller-Side Structural Typing</title>
   <link href="http://draconianoverlord.com/2010/01/17/caller-side-structural-typing.html"/>
   <updated>2010-01-17T00:00:00-08:00</updated>
   <id>http://draconianoverlord.com/2010/01/17/caller-side-structural-typing</id>
   <content type="html">&lt;h2&gt;Caller-Side Structural Typing&lt;/h2&gt;
&lt;h2 id='intro'&gt;Intro&lt;/h2&gt;

&lt;p&gt;Structural typing is an interesting approach to static typing that I&amp;#8217;ve been thinking more about lately.&lt;/p&gt;

&lt;p&gt;The basic gist of structural typing is that type names don&amp;#8217;t matter&amp;#8211;only type structures matter.&lt;/p&gt;

&lt;p&gt;Though first a disclaimer: being a JVM guy, I&amp;#8217;m mostly interesting in hacking structural types into the JVM environment. If you&amp;#8217;re in a language like Go, which has native structural typing, then my points are moot.&lt;/p&gt;

&lt;h2 id='in_java'&gt;In Java&lt;/h2&gt;

&lt;p&gt;I think structural types are best explained with an example. Let&amp;#8217;s start with Java. Say you define an interface &lt;code&gt;Closeable&lt;/code&gt;:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public interface Closeable {
  public void close();
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And then you write some nifty library routines for working with &lt;code&gt;Closeable&lt;/code&gt;s:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public class YourLibrary {
  public static void doClose(Closeable closeable) {
    // other nifty stuff
    closeable.close();
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now, let&amp;#8217;s say somebody else wants to use your &lt;code&gt;doClose&lt;/code&gt; method, e.g. they have a class:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public class SomeClass {
  public void close() {
    // want this to be called by doClose
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;With traditional static typing, they cannot pass instances of &lt;code&gt;SomeClass&lt;/code&gt; to your &lt;code&gt;doClose&lt;/code&gt; useless &lt;code&gt;SomeClass&lt;/code&gt; explicitly has an &lt;code&gt;implements Closeable&lt;/code&gt; declaration.&lt;/p&gt;

&lt;p&gt;Which, okay, yeah, most of the time its fairly easily to add this line.&lt;/p&gt;

&lt;p&gt;But, sometimes, it gets annoying&amp;#8211;and this is where structural typing steps in.&lt;/p&gt;

&lt;p&gt;Let&amp;#8217;s say you try to call:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;SomeClass s = new SomeClass();
// stuff
YourLibrary.doClose(s); // usually a compile error&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Structural typing notices that &lt;code&gt;doClose&lt;/code&gt; wants a &lt;code&gt;Closeable&lt;/code&gt;, and while &lt;code&gt;SomeClass&lt;/code&gt; does not directly implement &lt;code&gt;Closeable&lt;/code&gt;, it does have all of the methods required (specifically &lt;code&gt;void close()&lt;/code&gt;) to meet the &lt;em&gt;structural&lt;/em&gt; requirements of implementing &lt;code&gt;Closeable&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So, the idea is that this is good enough, and you should be able to go ahead and pass an almost-&lt;code&gt;Closeable&lt;/code&gt; &lt;code&gt;SomeClass&lt;/code&gt; to &lt;code&gt;doClose&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Obviously Java doesn&amp;#8217;t do this today, but Scala and a few other languages do, so let&amp;#8217;s look at what they do.&lt;/p&gt;

&lt;h2 id='in_scala'&gt;In Scala&lt;/h2&gt;

&lt;p&gt;Scala&amp;#8217;s approach to structural typing doesn&amp;#8217;t quite work like my above description. It requires you do declare up-front what types are structural. E.g. if you define a method:&lt;/p&gt;

&lt;pre class='brush:scala'&gt;&lt;code&gt;object YourLibrary {
  def doClose(closeable: { def close(): Unit }) = {
    // other nifty stuff
    closeable.close()
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The type of the argument &lt;code&gt;closeable&lt;/code&gt; does not an have an explicitly named type. The &lt;code&gt;{ def close(): Unit }&lt;/code&gt; is Scala&amp;#8217;s syntax for inline structural types. It means &amp;#8220;any type that has a &lt;code&gt;close&lt;/code&gt; method on it&amp;#8221;.&lt;/p&gt;

&lt;p&gt;Also note that if you don&amp;#8217;t like the inline syntax, or need to reuse the &lt;code&gt;closeable&lt;/code&gt; structural type a lot, you can define a type alias like so:&lt;/p&gt;

&lt;pre class='brush:scala'&gt;&lt;code&gt;object YourLibrary {
  // this is a type alias for the structural type
  type Closeable = {
    def close(): Unit
  }
  // now use &amp;#39;: Closeable&amp;#39; like regular syntax, but its still
  // a structural &amp;quot;anything that has close on it&amp;quot; type
  def doClose(closeable: Closeable) = {
    // other nifty stuff
    closeable.close()
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Since the Scala compiler understands structural types, per our Java example above, you can now do:&lt;/p&gt;

&lt;pre class='brush:scala'&gt;&lt;code&gt;val s = new SomeClass()
// stuff
// compiles because SomeClose.close matches structurally
YourLibrary.doClose(s)&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Without explicitly declaring &lt;code&gt;SomeClass extends Closeable&lt;/code&gt;. So, this is it, we&amp;#8217;ve got structural typing.&lt;/p&gt;

&lt;p&gt;However, this is just compile-time. At runtime, Scala now has to cater to the JVM and figure out how to pass &amp;#8220;any-type-that-is-basically-Closeable-but-not-really&amp;#8221; to &lt;code&gt;doClose&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To the JVM, &lt;code&gt;doClose&lt;/code&gt; has to accept &amp;#8220;any-type&amp;#8221;, because there is no single interface/class name we could put here without forcing our callers to implement that type&amp;#8211;which is exactly what we&amp;#8217;re trying to avoid.&lt;/p&gt;

&lt;p&gt;So, in the class file, the &lt;code&gt;YourLibrary.doClose&lt;/code&gt;&amp;#8217;s &lt;code&gt;closeable&lt;/code&gt; argument is actually a plain &lt;code&gt;java.lang.Object&lt;/code&gt;. Then inside of &lt;code&gt;doClose&lt;/code&gt;, Scala uses cached reflection grab the &lt;code&gt;closeable&lt;/code&gt; argument&amp;#8217;s &lt;code&gt;close&lt;/code&gt; method and invoke it.&lt;/p&gt;

&lt;p&gt;So your code at runtime basically becomes:&lt;/p&gt;

&lt;pre class='brush:scala'&gt;&lt;code&gt;// Runtime view
object YourLibrary {
  def doClose(closeable: Object) = {
    Method m = getMethodWithFancyCaching(closeable, &amp;quot;close&amp;quot;);
    m.invoke();
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Note that while the reflection side of things looks a lot like Ruby/Groovy-style dynamic language duck typing, the compiler (assuming you stay within Scala) still statically enforces that any types you pass to &lt;code&gt;doClose&lt;/code&gt; do actually have the &lt;code&gt;close()&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;So the &lt;code&gt;getMethod&lt;/code&gt; call is guaranteed to work, it just happens to be reflectively-dispatched at runtime to hack around the JVM&amp;#8217;s lack of native structural typing.&lt;/p&gt;

&lt;p&gt;Summarizing, Scala has definition-side structural typing (I&amp;#8217;m blatantly making up terms here). You declare what types/arguments in your library you wish to be structural and it becomes statically-checked compiler syntax sugar for runtime reflection calls.&lt;/p&gt;

&lt;h2 id='in_whiteoak'&gt;In Whiteoak&lt;/h2&gt;

&lt;p&gt;&lt;a href='http://ssdl-wiki.cs.technion.ac.il/wiki/images/6/61/Wo-0608.pdf'&gt;Whiteoak&lt;/a&gt; is an extension of Java that adds structural typing. Syntactically, their approach is very similar to Scala&amp;#8217;s&amp;#8211;explicit, definition-side declaration of structural types.&lt;/p&gt;

&lt;p&gt;The syntax looks something like:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public class YourLibrary {
  // they introduce a &amp;#39;struct&amp;#39; keyword for &amp;#39;structural&amp;#39;
  struct Closeable {
    void close();
  }
  public static void doClose(Closeable closeable) {
    // do stuff
    closeable.close()
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So, at compile-time, it looks very much like using interfaces.&lt;/p&gt;

&lt;p&gt;However, just like Scala, at runtime it has to jump through some hoops to satisfy the JVM and accept non-&lt;code&gt;Closeable&lt;/code&gt; arguments to the &lt;code&gt;doClose&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;To do this, Whiteoak uses the same approach as Scala&amp;#8211;structurally typed arguments become &lt;code&gt;java.lang.Object&lt;/code&gt;s in the class file. However, unlike Scala, Whiteoak generates cached adaptor classes at runtime.&lt;/p&gt;

&lt;p&gt;So your code at runtime basically becomes:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;// Runtime version
public class YourLibrary {
  // Closeable gets an interface
  interface ICloseable {
    void close();
  }
  // doClose takes an Object but, like Scala, any argument has been
  // compile-time checked to structurally have a close method
  public static void doClose(Object closeable) {
    ICloseable c = Whiteoak.make(closeable, ICloseable.class);
    c.close();
  }
}

// Whiteoak.make looks at closeable, and ifs its SomeClass, uses
// runtime bytecode generation to make a class like:
public class GeneratedSomeClass {
  private SomeClass contents;
  public SomeClass(Object contents) {
    this.contents = (SomeClass) contents;
  }
  public void close() {
    contents.close();
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You&amp;#8217;ll end up with a separate &lt;code&gt;GeneratedXxx&lt;/code&gt; adaptor class for each type you pass in to &lt;code&gt;doClose&lt;/code&gt;. However, like Scala caching for reflection, Whiteoak uses caching to avoid re-generating the class on each &lt;code&gt;make&lt;/code&gt; call.&lt;/p&gt;

&lt;p&gt;Between the two, I don&amp;#8217;t consider Scala&amp;#8217;s cached-reflection vs. Whiteoak&amp;#8217;s cached-adaptors to be that large of a difference. The paper &lt;a href='http://portal.acm.org/citation.cfm?id=1565829&amp;amp;dl=GUIDE&amp;amp;coll=GUIDE&amp;amp;CFID=73421715&amp;amp;CFTOKEN=28828316'&gt;Compiling structural types on the JVM&lt;/a&gt; goes into more detail and also benchmarks the two approaches.&lt;/p&gt;

&lt;p&gt;However, essentially, they both treat structural types as a definition-side concern and consider it &lt;code&gt;doClose&lt;/code&gt;&amp;#8217;s responsibility to take a &lt;code&gt;java.lang.Object&lt;/code&gt; and know how to do the right thing with it to get &lt;code&gt;close&lt;/code&gt; called.&lt;/p&gt;

&lt;h2 id='in_heron'&gt;In Heron&lt;/h2&gt;

&lt;p&gt;&lt;a href='http://code.google.com/p/heron-language/'&gt;Heron&lt;/a&gt; is an interesting language that takes a caller-side approach to structural typing. It is not actually a JVM language, but his caller-side approach is something I like, so I thought I&amp;#8217;d include it.&lt;/p&gt;

&lt;p&gt;The author of Heron also wrote a very good article, &lt;a href='http://drdobbs.com/blogs/architecture-and-design/228701413'&gt;Explicit Structural Typing&lt;/a&gt;, that covers these same structural typing ideas and terminology better than I do.&lt;/p&gt;

&lt;p&gt;So, Heron implements &lt;em&gt;explicit&lt;/em&gt; &lt;em&gt;caller-side&lt;/em&gt; structural typing. You can see the explicit syntax in its &lt;a href='http://code.google.com/p/heron-language/source/browse/trunk/HeronEngine/tests/TestDuckTyping.heron'&gt;unit test&lt;/a&gt;, or, in our example, it looks like:&lt;/p&gt;

&lt;pre class='brush:scala'&gt;&lt;code&gt; // define Closeable as a regular interface
 // define YourLibrary.doClose as a regular method taking Closeable
 var s = new SomeClass()
 // compiles because `as Closeable` suffix
 YourLibrary.doClose(s as Closeable)&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The &lt;code&gt;as Closeable&lt;/code&gt; directive ensures &lt;code&gt;s&lt;/code&gt; structurally complies with &lt;code&gt;Closeable&lt;/code&gt; and then lets the call happen.&lt;/p&gt;

&lt;p&gt;At least I think it does the structural check at compile time. He mentions a runtime check also occurring and then what I assume to be a Whiteoak-like adaptor object being made at runtime as well.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m a little fuzzy on the details as I just came across the language, but the key thing is that Heron moves structural typing to be something you as a caller decide you want to use. The declaration-side, the &lt;code&gt;doClose&lt;/code&gt; implementation, is none the wiser.&lt;/p&gt;

&lt;h2 id='implicit_callerside'&gt;Implicit Caller-Side&lt;/h2&gt;

&lt;p&gt;In my look-ma-I&amp;#8217;m-a-language-designer opinion, I like Heron&amp;#8217;s approach, but I think Scala should do one better and support &lt;em&gt;implicit&lt;/em&gt; caller-side structural typing. As in you don&amp;#8217;t need the &lt;code&gt;as Closeable&lt;/code&gt;, the compiler just notices this should happen and makes it so.&lt;/p&gt;

&lt;p&gt;With this approach, you can write library/API code and be blithely unaware of whether your callers are passing in real-conforming or structurally-conforming arguments.&lt;/p&gt;

&lt;p&gt;So, it&amp;#8217;d look like:&lt;/p&gt;

&lt;pre class='brush:scala'&gt;&lt;code&gt;object YourLibrary {
  // regular trait/interface
  trait Closeable {
    def close(): Unit
  }
  def doClose(closeable: Closeable) = {
    // other nifty stuff
    closeable.close()
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So far, this is all straight, &amp;#8220;non-structural&amp;#8221; Scala code. But then, when the compiler notices the caller passing in a &lt;code&gt;SomeClass&lt;/code&gt; argument that is not actually a &lt;code&gt;Closeable&lt;/code&gt;, do one of two things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Generate, at compile-time, a adaptor class that implements &lt;code&gt;Closeable&lt;/code&gt;. E.g. something like:&lt;/p&gt;

&lt;pre class='brush:scala'&gt;&lt;code&gt;class SomeClassAsCloseable(val c: Closeable) extends Closeable {
  def close() = c.close()
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And automatically transform the caller&amp;#8217;s call into:&lt;/p&gt;

&lt;pre class='brush:scala'&gt;&lt;code&gt;val s = new SomeClass()
YourLibrary.doClose(new SomeClassAsCloseable(s))&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Points:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pro: Everything is plain Java at runtime&amp;#8211;&lt;code&gt;doClose&lt;/code&gt; still takes a regular &lt;code&gt;Closeable&lt;/code&gt; interface and there is no reflection/bytecode generation&lt;/li&gt;

&lt;li&gt;Pro: Conversion semantics are similar to Scala&amp;#8217;s views/implicit conversions, which are used extensively&lt;/li&gt;

&lt;li&gt;Pro: Doable now&amp;#8211;doesn&amp;#8217;t rely on new JDK features (see option 2)&lt;/li&gt;

&lt;li&gt;Con: Object identity is broken&amp;#8211;if &lt;code&gt;doClose&lt;/code&gt; does any identity comparison of its argument, it will do so against the &lt;code&gt;SomeClassAsCloseable&lt;/code&gt; adaptor instance instead of &lt;code&gt;SomeClass&lt;/code&gt; itself. (I don&amp;#8217;t consider this a huge deal given how much proxies are used in Java and implicit views in Scala.)&lt;/li&gt;

&lt;li&gt;Con: Generates an extra adaptor class for each caller-side type (like Whiteoak, except generation is at compile-time, so there is no runtime hit)&lt;/li&gt;

&lt;li&gt;Con: Generates an extra adaptor instance (&lt;code&gt;new SomeClassAsCloseable&lt;/code&gt;) for each &lt;code&gt;Closeable&lt;/code&gt; call (though perhaps this could be cached somewhere, e.g. on &lt;code&gt;SomeClass.asCloseable&lt;/code&gt; if &lt;code&gt;SomeClass&lt;/code&gt; was a class we controlled)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Use &lt;a href='http://blogs.sun.com/jrose/entry/interface_injection_in_the_vm'&gt;Interface Injection&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is a JDK7 feature, but the idea is that there will be a way to, at runtime, dynamically add &lt;code&gt;Closeable&lt;/code&gt; to the list of interfaces that &lt;code&gt;SomeClass&lt;/code&gt; implements. This is like reaching into the &lt;code&gt;SomeClass&lt;/code&gt; class declaration line and saying &amp;#8220;oh, yeah, you meant to add &lt;code&gt;implements Closeable&lt;/code&gt;, let me do that for you&amp;#8221;.&lt;/p&gt;

&lt;p&gt;I think this is the best option for JVM-based structural typing, it just sucks that it is not available yet.&lt;/p&gt;

&lt;p&gt;Points:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pro: Object identity is not broken&amp;#8211;there is no proxy/adaptor instance hiding the real &lt;code&gt;SomeClass&lt;/code&gt; instance in the background&lt;/li&gt;

&lt;li&gt;Con: Relies on a JDK7 feature that is at least 6-12 months away from release. Even then, it is doubtful Scala would use such a cutting edge feature and limit its target-able runtimes.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id='concerns_about_implicit_conversion'&gt;Concerns About Implicit Conversion&lt;/h2&gt;

&lt;p&gt;A few articles on structural typing have mentioned structural typing in and of itself is potentially a bad thing&amp;#8211;the assertion is that a named interface entails a documented protocol across the entire set of methods, not just a grab bag of disparate methods that can be called willy nilly.&lt;/p&gt;

&lt;p&gt;For example, let&amp;#8217;s say &lt;code&gt;SomeClass.close()&lt;/code&gt; was actually part of &lt;code&gt;SomeClass&lt;/code&gt; implementing this other interface &lt;code&gt;IResource&lt;/code&gt;. And part of &lt;code&gt;IResource&lt;/code&gt;&amp;#8217;s contract is that clients must call &lt;code&gt;open()&lt;/code&gt; before calling &lt;code&gt;close()&lt;/code&gt; or else bad things happen. And so &lt;code&gt;SomeClass&lt;/code&gt; is implemented with this contract in mind.&lt;/p&gt;

&lt;p&gt;But now you pass &lt;code&gt;SomeClass&lt;/code&gt; to &lt;code&gt;doClose&lt;/code&gt;, and the compiler magically turns it into a &lt;code&gt;ICloseable&lt;/code&gt; for you. However, &lt;code&gt;ICloseable&lt;/code&gt; has no documented &amp;#8220;call &lt;code&gt;open()&lt;/code&gt; first&amp;#8221; contract, and so now the &lt;code&gt;doClose&lt;/code&gt; method will start violating &lt;code&gt;SomeClass.close&lt;/code&gt;&amp;#8217;s semantics without knowing any better.&lt;/p&gt;

&lt;p&gt;This is not a bad point. And, perhaps by making structural types an explicit/definition-side concern, Scala and Whiteoak were purposefully setting out to say library/API designers need to explicitly note that they are okay with getting a &amp;#8220;grab bag of methods&amp;#8221;.&lt;/p&gt;

&lt;p&gt;Certainly making structural typing an implicit, caller-side implementation as I&amp;#8217;m proposing will increase the chances of semantics being unintentionally violated.&lt;/p&gt;

&lt;p&gt;However, foregoing the &amp;#8220;lack of documented protocol&amp;#8221; concern is how Google&amp;#8217;s Go implements structural typing, so it will be interesting to see if that plays out well and if &amp;#8220;willy nilly&amp;#8221; structural typing gains either popularity or notoriety.&lt;/p&gt;

&lt;h2 id='wrapping_up'&gt;Wrapping Up&lt;/h2&gt;

&lt;p&gt;I ended up talking more about how other languages implement structural typing more than I intended to. Well, besides the fact that I avoided the big one, Google&amp;#8217;s Go, which I haven&amp;#8217;t looked in to enough yet.&lt;/p&gt;

&lt;p&gt;My main assertion is that Scala&amp;#8217;s structural typing seems like it would integrate better with the JVM if it used caller-side/compile-time adaptor hacks. Basically in the same vein of how Scala 2.8&amp;#8217;s default/named arguments also use caller-side/compile-time hacks. And, as an added bonus, this would mean structural typing could be used anywhere that takes existing regular traits/interfaces instead of only those picked to accept structural types.&lt;/p&gt;

&lt;p&gt;Of course, declaration-side structural typing still gets the job done and I&amp;#8217;ll definitely use it, assuming I control the library/API implementation and foresee the needed flexibility.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Changing My Style</title>
   <link href="http://draconianoverlord.com/2010/01/15/changing-my-style.html"/>
   <updated>2010-01-15T00:00:00-08:00</updated>
   <id>http://draconianoverlord.com/2010/01/15/changing-my-style</id>
   <content type="html">&lt;h1 id='changing_my_style'&gt;Changing My Style&lt;/h1&gt;

&lt;p&gt;Lately I&amp;#8217;ve been reconsidering my approach with regard to statics.&lt;/p&gt;

&lt;p&gt;Basically, less of them.&lt;/p&gt;

&lt;h2 id='di_with_manual_wiring'&gt;DI With Manual Wiring&lt;/h2&gt;

&lt;p&gt;Yeah, I know I&amp;#8217;m late to the game here, what with DI taking over the Java world, what, 10 years ago.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;ve always liked the class-design side of DI. I noticed early on that DI-style projects were much easier to integrate with than others. Pre-DI, projects would typically look at their own proprietary configuration files and then take off running, and not let you easily change things.&lt;/p&gt;

&lt;p&gt;Post-DI, integration was much easier, even though I would still manually wire together our DI-enabled dependencies.&lt;/p&gt;

&lt;p&gt;Which brings me to the crux of my issue with standard DI: auto-wiring bugs me.&lt;/p&gt;

&lt;p&gt;In three ways:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Spring auto-wiring still involves XML configuration files that are easily hundreds of lines long.&lt;/p&gt;

&lt;p&gt;This is confusing because the service objects being wired together are usually the ones most likely to be driven by application-level configuration parameters, environment checks, etc. And XML is pretty much the most static place you can put stuff. No ifs, whiles, logic, abstractions, etc.&lt;/p&gt;

&lt;p&gt;Supposedly Java-based configuration for Spring is available, but I&amp;#8217;ve yet to see a project actually use it. I&amp;#8217;m not sure why.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Leaving auto-wiring to a framework foregoes static typing of your service object dependencies.&lt;/p&gt;

&lt;p&gt;Spring&amp;#8217;s XML is especially bad at this, being just a grab bag of fun that you get to wait until runtime to see what happens with it.&lt;/p&gt;

&lt;p&gt;But even Guice, which asserts to &amp;#8220;embrace Java&amp;#8217;s type safe nature&amp;#8221;, can really only ensure that you bind the right type of implementation to an interface.&lt;/p&gt;

&lt;p&gt;Which is fine, but what they cannot check is whether you&amp;#8217;ve added the binding at all in the first place. E.g. you&amp;#8217;re going to have to wait until runtime to make sure all of your @Inject constructors just magically work.&lt;/p&gt;

&lt;p&gt;Contrast this with manual wiring where, if you&amp;#8217;re missing a constructor parameter, you&amp;#8217;ll know it immediately at compile time.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Manual wiring shouldn&amp;#8217;t be that hard.&lt;/p&gt;

&lt;p&gt;Lex Spoon &lt;a href='http://blog.lexspoon.org/2009/02/why-not-inject-dependencies-manually.html'&gt;says it very well&lt;/a&gt;, that DI propaganda picks on &lt;code&gt;XxxFactory&lt;/code&gt; as why you need auto-wiring when really the &lt;code&gt;XxxFactory&lt;/code&gt; is an anti-pattern in and of itself and just needs a dose of good implementation and abstraction.&lt;/p&gt;

&lt;p&gt;(Note I&amp;#8217;m working on this&amp;#8211;slowly. Nothing awesome yet.)&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id='joist_example'&gt;Joist Example&lt;/h2&gt;

&lt;p&gt;Anyway, when building &lt;a href='http://joist.ws'&gt;Joist&lt;/a&gt;, I wasn&amp;#8217;t as anti-static as I am becoming, so I&amp;#8217;d have code that looks like:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public class SomeBusinessLogic {
  public void doSomeBusinessLogic(final Integer fooId) {
    // UoW is a static that reaches out and starts a transaction
    UoW.go(new Block() {
      public void go() {
        // Foo.queries is another static that reaches out for a FoodQueries instance
        final Foo foo = Foo.queries.findById(fooId);
        // do stuff with foo
      }
    });
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I think I would write this now as:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public class SomeBusinessLogic {
  private final Repository repo;

  public SomeBusinessLogic(final Repository repo) {
    this.repo = repo;
  }

  public void doSomeBusinessLogic(final Integer fooId) {
    repo.go(new Block() {
      public void go() {
        final Foo foo = repo.getFooQueries().findById(fooId);
        // do stuff with foo
      }
    });
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The odd thing is that I don&amp;#8217;t know how useful this would actually be.&lt;/p&gt;

&lt;p&gt;Part of my historical anti-DI stance is that some semantics, like the transactional semantics of a database-backed unit of work, just cannot be mocked/stubbed out very effectively.&lt;/p&gt;

&lt;p&gt;E.g. with the real unit of work, if you get an instance of &lt;code&gt;Foo&lt;/code&gt;, change some properties, but then an exception happens, those changes are lost.&lt;/p&gt;

&lt;p&gt;However, most any mock/stub repository is going to hand you an instance of &lt;code&gt;Foo&lt;/code&gt;, let you change some properties, and when an exception happens, leave &lt;code&gt;Foo&lt;/code&gt; just as it is. It&amp;#8217;s a mock/stub&amp;#8211;it&amp;#8217;s not smart enough to actually track/rollback object changes.&lt;/p&gt;

&lt;p&gt;So, my opinion with Joist was &amp;#8220;why bother?&amp;#8221; and so I typically have just stuck with integration tests for anything that touches a unit of work/database.&lt;/p&gt;

&lt;p&gt;And I still subscribe to this view, e.g. I don&amp;#8217;t see myself mocking out &lt;code&gt;getFooQueries&lt;/code&gt; any time soon.&lt;/p&gt;

&lt;p&gt;But what I find odd is that my style has changed such that now even looking at the statics makes me uncomfortable.&lt;/p&gt;

&lt;h2 id='registries_example'&gt;Registries Example&lt;/h2&gt;

&lt;p&gt;I&amp;#8217;m also moving away from a static-based &lt;a href='http://martinfowler.com/eaaCatalog/registry.html'&gt;Registry&lt;/a&gt;, to an interface-based one.&lt;/p&gt;

&lt;p&gt;I still like Fowler&amp;#8217;s pattern of the Registry being the one singleton in the application. It matches the Spring/Guice semantics of having one application context or application module that is tucked away in a static/thread local/servlet filter somewhere.&lt;/p&gt;

&lt;p&gt;So, even though my previous Registries were the only singleton, I still exposed their resources via static getter methods, e.g.:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public class Registry {
  public static ResourceA getResourceA() { ... }
  public static ResourceB getResourceB() { ... }
}

public class Client {
  public void doStuffWith() {
    Registry.getResourceB().doStuff();
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;But now, yeah, the static &lt;code&gt;Registry.getResourceB()&lt;/code&gt; call hurts and I&amp;#8217;m changing to something like:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public interface Registry {
  ResourceA getResourceA();
  ResourceB getResourceB();
}

public class RegistryInstance implements Registry {
  public static Registry get() { ... }
}

public class Client {
  private final Registry registry;

  // Ideally use this constructor when you&amp;#39;ve got a registry
  // on hand already
  public Client(final Registry registry) {
    this.registry = registry;
  }

  // Only use the default constructor if you don&amp;#39;t control
  // class instantation, e.g. a servlet or domain object
  public Client() {
    this(RegistryInstance.get());
  }

  public void doStuffWith() {
    registry.getResourceA().doStuff();
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Such that now &lt;code&gt;Registry&lt;/code&gt; can be mocked/stubbed out.&lt;/p&gt;

&lt;p&gt;Which, yeah, is obvious in this day and age.&lt;/p&gt;

&lt;p&gt;But, I still like the &lt;code&gt;Registry&lt;/code&gt; as a pure-Java/typed version of your Spring application context or Guice client module. I get to strongly declare the dependencies my application has.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;ll add the caveat that I haven&amp;#8217;t used this new approach in a huge system yet. I don&amp;#8217;t intend on the &lt;code&gt;Registry&lt;/code&gt; context being passed around through layer after layer. Hopefully good design, or a few strategic &lt;code&gt;RegistryInstance.get()&lt;/code&gt; calls, will avoid that.&lt;/p&gt;

&lt;p&gt;And I&amp;#8217;m not too worried about the occasional &lt;code&gt;RegistryInstance.get()&lt;/code&gt; call, especially if used in a default constructor that then defers to a mockable constructor. Spring apps have do the same thing now and then, reach out to a thread-local/etc. application context.&lt;/p&gt;

&lt;h2 id='innerclass_dependency_interfaces'&gt;Inner-Class Dependency Interfaces&lt;/h2&gt;

&lt;p&gt;One approach I want to play more with is using a GWT MVP-style dependency declaration. E.g. instead of service components being in an application-wide &lt;code&gt;Registry&lt;/code&gt; interface, or a huge list of constructor arguments, I think an inner-interface would be interesting:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public class SomeBusinessLogic {
  public interface Deps {
    Repository getRepository()
  }

  private final Deps deps;

  public SomeBusinessLogic(Deps deps) {
    this.deps = deps;
  }
}

// off in your Registry
public interface Registry extends SomeBusinessLogic, ... {
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;What I like about this is that each class gets its own declaration of the dependencies it requires. For very common dependencies, you could use inheritance, e.g.:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public class SomeBusinessLogic {
  public interface Deps extends CommonAppDeps {
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;But, without some structural typing tricks, your &lt;code&gt;Registry&lt;/code&gt; interface is going to have an explosion of &lt;code&gt;extends XxxLogic, YyyLogic, etc&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Which, ironically, verbosity is one of my complaints about GWT MVP&amp;#8217;s use of inner-interfaces as well.&lt;/p&gt;

&lt;p&gt;So, perhaps it is not such a great idea.&lt;/p&gt;

&lt;h2 id='thanks'&gt;Thanks&lt;/h2&gt;

&lt;p&gt;Also, I wanted to thank to my coworkers at &lt;a href='http://www.bizo.com'&gt;Bizo&lt;/a&gt; for influencing my style lately. It&amp;#8217;s fun to still be learning.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Sprunge And Dropbox</title>
   <link href="http://draconianoverlord.com/2009/12/13/sprunge-and-dropbox.html"/>
   <updated>2009-12-13T00:00:00-08:00</updated>
   <id>http://draconianoverlord.com/2009/12/13/sprunge-and-dropbox</id>
   <content type="html">&lt;h1 id='sprunge_and_dropbox'&gt;Sprunge And Dropbox&lt;/h1&gt;

&lt;p&gt;Just a quick post on &lt;a href='http://sprunge.us'&gt;Sprunge&lt;/a&gt; and &lt;a href='http://dropbox.com'&gt;Dropbox&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id='sprunge_rocks'&gt;Sprunge Rocks&lt;/h2&gt;

&lt;p&gt;If you haven&amp;#8217;t used it yet, &lt;a href='http://sprunge.us'&gt;sprunge.us&lt;/a&gt; rocks.&lt;/p&gt;

&lt;p&gt;It&amp;#8217;s a CLI-friendly paste bin.&lt;/p&gt;

&lt;p&gt;So, say you have some log file/snippet/whatever, off on your headless server, and you&amp;#8217;d like your coworkers to take a look at it. Assuming you don&amp;#8217;t have sensitive information in it, Sprunge makes this trivial:&lt;/p&gt;

&lt;pre class='brush:bash'&gt;&lt;code&gt;curl -F &amp;#39;sprunge=@somefile.txt&amp;#39; sprunge.us&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This uses &lt;code&gt;curl&lt;/code&gt; to do an HTTP POST to &lt;code&gt;http://sprunge.us&lt;/code&gt; with a multi-part form containing &lt;code&gt;sprunge=&amp;lt;the contents of somefile.txt&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In the response, Sprunge will give you a unique URL that you can then send to your coworkers for them to check out (e.g. something like &lt;a href='http://sprunge.us/IdhX'&gt;http://sprunge.us/IdhX&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Note if you don&amp;#8217;t want all of &lt;code&gt;somefile.txt&lt;/code&gt;, you can also use &lt;code&gt;stdin&lt;/code&gt;, e.g.:&lt;/p&gt;

&lt;pre class='brush:bash'&gt;&lt;code&gt;cat somefile.txt | grep ERROR | curl -F &amp;#39;sprunge=&amp;amp;lt;-&amp;#39; sprunge.us&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Being CLI-friendly is Sprunge&amp;#8217;s main act&amp;#8211;it doesn&amp;#8217;t have much else, e.g. no syntax highlighting, commenting, whatever. But for what I&amp;#8217;ve used it for, sharing snippets of files, it works just great.&lt;/p&gt;

&lt;p&gt;Speaking of which&amp;#8230;&lt;/p&gt;

&lt;h2 id='dropbox_cli_upload'&gt;Dropbox CLI Upload&lt;/h2&gt;

&lt;p&gt;I can&amp;#8217;t give Dropbox too much crap, because I only have a free account, but I wanted to get a file from a headless server into their system today and finally gave up.&lt;/p&gt;

&lt;p&gt;To their credit, they have a Linux &lt;a href='https://www.dropbox.com/downloading?os=lnx'&gt;download&lt;/a&gt;, but it involves running a proprietary daemon plus an open source Nautilus extension.&lt;/p&gt;

&lt;p&gt;Which I&amp;#8217;m sure is exactly what you want for 2-way sync, normal Dropbox awesomeness, but it really sucks when all I want to do is drop a backup file up there and be done with it.&lt;/p&gt;

&lt;p&gt;So, riffing on Sprunge, I&amp;#8217;d like to be able to do:&lt;/p&gt;

&lt;pre class='brush:bash'&gt;&lt;code&gt;curl -F &amp;#39;data=@somefile.bin&amp;#39; -F &amp;#39;name=myfolder/somefile.bin&amp;#39; -u me:password https://dropbox.com&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This would use basic auth to identify me, but that&amp;#8217;s fine given the connection is over HTTPS anyway.&lt;/p&gt;

&lt;p&gt;This command may not be something users could type off the top of their head, but it&amp;#8217;d be easy to script for automating uploads/backups/etc.&lt;/p&gt;

&lt;p&gt;So, for now I&amp;#8217;ll continue with a manual &lt;code&gt;scp&lt;/code&gt; download to my laptop and then use a browser to upload the file back into Dropbox. It&amp;#8217;s nothing too important/frequent, so it&amp;#8217;ll be fine for now.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Running ScalaTest Spec Tests from Eclipse</title>
   <link href="http://draconianoverlord.com/2009/09/10/scalatest-spec-from-eclipse.html"/>
   <updated>2009-09-10T00:00:00-07:00</updated>
   <id>http://draconianoverlord.com/2009/09/10/scalatest-spec-from-eclipse</id>
   <content type="html">&lt;h1 id='running_scalatest_spec_tests_from_eclipse'&gt;Running ScalaTest Spec Tests from Eclipse&lt;/h1&gt;

&lt;p&gt;&lt;a href='http://www.artima.com/scalatest/'&gt;ScalaTest&lt;/a&gt; is pretty cool. I&amp;#8217;ve been playing with the &amp;#8220;spec&amp;#8221; way of writing tests&amp;#8211;for the most part, I have nothing against traditional JUnit 3 &lt;code&gt;testXxx&lt;/code&gt; methods, other than having string-based test names is pretty darn cool from a readability perspective.&lt;/p&gt;

&lt;p&gt;The big con, however, is that ScalaTest doesn&amp;#8217;t have its own Eclipse plugin, so if you move away from the JUnit 3 &lt;code&gt;testXxx&lt;/code&gt; methods, you don&amp;#8217;t get the nice &lt;code&gt;Alt-Shift-X + T&lt;/code&gt; test-running capabilities directly within Eclipse.&lt;/p&gt;

&lt;p&gt;I started fiddling with ways of tricking Eclipse into running spec-type ScalaTests and came up with a workable approach.&lt;/p&gt;

&lt;h2 id='a_sample_test'&gt;A Sample Test&lt;/h2&gt;

&lt;p&gt;So, here&amp;#8217;s a sample spec-based test that we&amp;#8217;d like to run with Eclipse:&lt;/p&gt;

&lt;pre class='brush:scala'&gt;&lt;code&gt;import org.junit.runner.RunWith
import org.scalatest.Spec
import org.scalatest.matchers.MustMatchers

@RunWith(classOf[JUnit4Runner])
class ZazTest extends Spec with MustMatchers {
  describe(&amp;quot;something&amp;quot;) {
    it(&amp;quot;should do something fancy&amp;quot;) {
      println(&amp;quot;fancy&amp;quot;)
    }
    it (&amp;quot;should do something plain&amp;quot;) {
      println(&amp;quot;plain&amp;quot;)
    }
    it (&amp;quot;should also fail&amp;quot;) {
      println(&amp;quot;fail&amp;quot;)
      1 must equal (2)
    }
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Note the &lt;code&gt;&amp;quot;should do something fancy&amp;quot;&lt;/code&gt; test names that JUnit really isn&amp;#8217;t going to understand (because they are not methods, they&amp;#8217;re anonymous inner classes ScalaTest keeps track of in an internal data structure).&lt;/p&gt;

&lt;h2 id='how_to_get_eclipse_to_run_this_test'&gt;How To Get Eclipse To Run This Test&lt;/h2&gt;

&lt;p&gt;The key thing I&amp;#8217;ve added above is a &lt;code&gt;RunWith&lt;/code&gt; annotation that uses a &lt;code&gt;JUnit4Runner&lt;/code&gt; I wrote. When you hit &lt;code&gt;Alt-Shift-X + T&lt;/code&gt; in Eclipse, even though &lt;code&gt;ZazTest&lt;/code&gt; doesn&amp;#8217;t extend &lt;code&gt;TestCase&lt;/code&gt; or have any &lt;code&gt;@Test&lt;/code&gt; annotations, the Eclipse JUnit 4 runner seems the &lt;code&gt;RunWith&lt;/code&gt; annotation and hands over control to it.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;JUnit4Runner&lt;/code&gt; then just has to translate a JUnit run into something the Spec suite can handle.&lt;/p&gt;

&lt;p&gt;This turned out to be not that bad:&lt;/p&gt;

&lt;pre class='brush:scala'&gt;&lt;code&gt;import org.junit.runner.{Description =&amp;gt; JuDescription}
import org.junit.runner.{Runner =&amp;gt; JuRunner}
import org.junit.runner.notification.{Failure =&amp;gt; JuFailure}
import org.junit.runner.notification.{RunNotifier =&amp;gt; JuRunNotifer}
import org.junit.runners.{Suite =&amp;gt; JuSuite}
import org.scalatest.{Filter =&amp;gt; StFilter}
import org.scalatest.{Reporter =&amp;gt; StReporter}
import org.scalatest.{Stopper =&amp;gt; StStopper}
import org.scalatest.{Suite =&amp;gt; StSuite}
import org.scalatest.{Tracker =&amp;gt; StTracker}
import org.scalatest.events._

class JUnit4Runner(val testClass: Class[_]) extends JuSuite(testClass, new java.util.ArrayList[JuRunner]()) {
  val suite = testClass.newInstance.asInstanceOf[StSuite]
  suite.testNames.foreach((testName) =&amp;gt; getChildren.add(new TestAdapter(this, testName)))
}

class TestAdapter(runner: JUnit4Runner, testName: String) extends JuRunner {
  override def run(notifier: JuRunNotifer): Unit = {
    val reporter = new ReporterAdapter(this, notifier)
    val stopper = new StopperAdapter
    val filter = new StFilter(None, Set())
    val tracker = new StTracker()
    runner.suite.run(Some(testName), reporter, stopper, filter, Map(), None, tracker)
  }
  override def getDescription() = JuDescription.createTestDescription(runner.testClass, testName)
}

class ReporterAdapter(test: TestAdapter, notifier: JuRunNotifer) extends StReporter {
  override def apply(event: Event): Unit = {
    event match {
      case e: TestStarting =&amp;gt; notifier.fireTestStarted(test.getDescription)
      case e: TestSucceeded =&amp;gt; notifier.fireTestFinished(test.getDescription)
      case e: TestFailed =&amp;gt; notifier.fireTestFailure(new JuFailure(test.getDescription, e.throwable.get))
      case e: InfoProvided =&amp;gt; // ignore
      case e =&amp;gt; println(e)
    }
  }
}

class StopperAdapter extends StStopper {
  override def apply = false
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It basically just translates ScalaTest &lt;code&gt;Events&lt;/code&gt; into JUnit &lt;code&gt;RunNotifier&lt;/code&gt; events.&lt;/p&gt;

&lt;h2 id='the_results'&gt;The Results&lt;/h2&gt;

&lt;p&gt;Here&amp;#8217;s a screenshot:&lt;/p&gt;
&lt;a href='/images/screenshot-scalatest.png' border='0'&gt;
  &lt;img src='/images/screenshot-scalatest.png' border='0' width='500' /&gt;
&lt;/a&gt;
&lt;p&gt;What&amp;#8217;s really cool is that, in typical JUnit fashion, no existing Run Configuration needs to be setup. E.g. I don&amp;#8217;t have to manually create a run configuration for each spec-based ScalaTest&amp;#8211;just hitting &lt;code&gt;Alt-Shift-X + T&lt;/code&gt; will make a new JUnit run configuration and fire off the tests.&lt;/p&gt;

&lt;h2 id='the_downside'&gt;The Downside&lt;/h2&gt;

&lt;p&gt;The Eclipse JUnit UI still assumes &amp;#8220;something should do something fancy&amp;#8221; is a method name, so if you double click on it, it will fail to find it and just take you to the &lt;code&gt;ZazTest&lt;/code&gt; class. So it&amp;#8217;s not as easy to jump right to failures.&lt;/p&gt;

&lt;h2 id='bonus'&gt;Bonus&lt;/h2&gt;

&lt;p&gt;Turns out you can right click and run individual &lt;code&gt;it&lt;/code&gt; tests too. I have no idea how that is working&amp;#8211;and it doesn&amp;#8217;t seem to be just a UI trick, because the console output from the other tests doesn&amp;#8217;t show up either. Weird&amp;#8230;but cool.&lt;/p&gt;

&lt;p&gt;Anyway, I haven&amp;#8217;t decided if I&amp;#8217;ll completely jump ship on traditional &lt;code&gt;TestCase&lt;/code&gt;-extending tests for Scala projects. There is a warm familiarity that I like about it. But if I do start writing more spec-based ScalaTests, this &lt;code&gt;RunWith&lt;/code&gt; hack will be very handy.&lt;/p&gt;

&lt;h2 id='update'&gt;&lt;strong&gt;Update&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Turns out this feature &lt;a href='http://www.artima.com/forums/flat.jsp?forum=284&amp;amp;thread=254074'&gt;already exists&lt;/a&gt; in ScalaTest &lt;a href='https://scalatest.dev.java.net/source/browse/scalatest/trunk/app/src/main/scala/org/scalatest/junit/JUnitRunner.scala?rev=1789&amp;amp;view=markup'&gt;trunk&lt;/a&gt; and should be in the next release as &lt;code&gt;org.scalatest.junit.JUnitRunner&lt;/code&gt;.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Port 80 to Port 8080</title>
   <link href="http://draconianoverlord.com/2009/08/23/port80to8080.html"/>
   <updated>2009-08-23T00:00:00-07:00</updated>
   <id>http://draconianoverlord.com/2009/08/23/port80to8080</id>
   <content type="html">&lt;h1 id='serving_port_80_from_8080'&gt;Serving Port 80 from 8080&lt;/h1&gt;

&lt;p&gt;Several times lately I&amp;#8217;ve wanted to run a Jetty instance on port 8080 but have it available via port 80.&lt;/p&gt;

&lt;p&gt;On Unix boxes, this usually involves running as root, or at least starting as root and dropping down to a lower-privileged user.&lt;/p&gt;

&lt;p&gt;Given I wanted to quickly start/stop Jetty test instances from within Eclipse, I really wanted to keep running Jetty on 8080 but have it show up on 80.&lt;/p&gt;

&lt;p&gt;What ended up being easiest for my Ubuntu 9.04 box was two firewall rules:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;/etc/network/if-up.d/port80to8080&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#!/bin/sh
[ &amp;quot;$IFACE&amp;quot; != &amp;quot;lo&amp;quot; ] || exit 0;
iptables -t nat -A PREROUTING --src 0/0 --dest 127.0.0.1 -p tcp --dport http -j REDIRECT --to-ports 8080
iptables -t nat -A OUTPUT     --src 0/0 --dest 127.0.0.1 -p tcp --dport http -j REDIRECT --to-ports 8080&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;code&gt;/etc/network/if-down.d/port80to8080&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#!/bin/sh
[ &amp;quot;$IFACE&amp;quot; ! &amp;quot;lo&amp;quot; ] || exit 0;
iptables -t nat -D PREROUTING --src 0/0 --dest 127.0.0.1 -p tcp --dport http -j REDIRECT --to-ports 8080
iptables -t nat -D OUTPUT     --src 0/0 --dest 127.0.0.1 -p tcp --dport http -j REDIRECT --to-ports 8080&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Make sure to &lt;code&gt;chmod 744&lt;/code&gt; and &lt;code&gt;chown root:root&lt;/code&gt; both files.&lt;/p&gt;

&lt;p&gt;These &lt;code&gt;iptables&lt;/code&gt; rules catch all incoming (&lt;code&gt;PREROUTING&lt;/code&gt;, others hitting your box) and outgoing (&lt;code&gt;OUTPUT&lt;/code&gt;, you hitting your box) requests going to 127.0.0.1:80 and shunt it over to 8080.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m not enough of a sysadmin to know the pros/cons of using this approach in production, but for my dev box it works great.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Bindgen 2.0 Released</title>
   <link href="http://draconianoverlord.com/2009/07/21/bindgen-2.0-released.html"/>
   <updated>2009-07-21T00:00:00-07:00</updated>
   <id>http://draconianoverlord.com/2009/07/21/bindgen-2.0-released</id>
   <content type="html">&lt;h1 id='bindgen_20_released'&gt;Bindgen 2.0 Released&lt;/h1&gt;

&lt;p&gt;My hobby project &lt;a href='http://github.com/stephenh/bindgen'&gt;bindgen&lt;/a&gt; just got a new release: 2.0.&lt;/p&gt;

&lt;p&gt;bindgen provides expression language-like capabilities, but with type-safe method calls instead of opaque strings like OGNL.&lt;/p&gt;

&lt;h2 id='stateless_bindings'&gt;Stateless Bindings&lt;/h2&gt;

&lt;p&gt;The biggest change is that bindings can now be stateless.&lt;/p&gt;

&lt;p&gt;Previously, a binding could only be bound to 1 instance at a time, making them not safe for use across multiple threads. You could reuse them within a thread, with a &lt;code&gt;set(instance)&lt;/code&gt;-based idiom like:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;FooBinding fb = new FooBinding();
StringBinding nb = fb.name(); // could be more complex, e.g. fb.bar().name()

Foo foo = new Foo(&amp;quot;foo&amp;quot;);
fb.set(foo); // binds fb to the foo instance
nb.get(); // returns &amp;quot;foo&amp;quot;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;But the gap between &lt;code&gt;fb.set&lt;/code&gt; and &lt;code&gt;nb.get()&lt;/code&gt; meant another thread could step in and interleave a &lt;code&gt;set&lt;/code&gt; behind your back.&lt;/p&gt;

&lt;p&gt;Now there are &lt;code&gt;getWithRoot&lt;/code&gt; and &lt;code&gt;setWithRoot&lt;/code&gt; methods that are stateless and so thread-safe:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;FooBinding fb = new FooBinding();
StringBinding nb = fb.name();

Foo foo = new Foo(&amp;quot;foo&amp;quot;);
nb.getWithRoot(foo); // returns &amp;quot;foo&amp;quot;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This means you can instantiate a binding just once and reuse it across many instances/threads.&lt;/p&gt;

&lt;p&gt;&lt;a href='http://joist.ws'&gt;Joist&lt;/a&gt; is starting to use these stateless bindings for its validation rules. The iterative nature (e.g. &lt;code&gt;foo.employer().name()&lt;/code&gt;) of bindgen is more flexible than Joist&amp;#8217;s previous approach.&lt;/p&gt;

&lt;h2 id='links'&gt;Links&lt;/h2&gt;

&lt;p&gt;Checkout more at:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href='http://github.com/stephenh/bindgen'&gt;github&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Joist&amp;#8217;s bindgen pages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='http://joist.ws/bindgenExamples.html'&gt;Examples&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href='http://joist.ws/bindgenPerformance.html'&gt;Performance&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href='http://joist.ws/bindgenScreencasts.html'&gt;Screencasts&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href='http://joist.ws/bindgenSetup.html'&gt;Setup&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;</content>
 </entry>
 
 <entry>
   <title>Validation with Objects Instead Of Annotations</title>
   <link href="http://draconianoverlord.com/2009/07/14/validation-with-objects.html"/>
   <updated>2009-07-14T00:00:00-07:00</updated>
   <id>http://draconianoverlord.com/2009/07/14/validation-with-objects</id>
   <content type="html">&lt;h1 id='validation_with_objects_instead_of_annotations'&gt;Validation With Objects Instead Of Annotations&lt;/h1&gt;

&lt;h2 id='intro'&gt;Intro&lt;/h2&gt;

&lt;p&gt;Annotations are really popular these days for marking up validation rules.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m forcing myself to go through a Seam tutorial, and their example is fairly representative:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public class FooDomainObject {
    @NotNull @Length(max=100)
    public String getTitle() {
        return title;
    }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I cringe every time I see this&amp;#8211;annotations are not inherently bad, but I see the annotation-hammer as having replaced the XML-hammer is the Java world. Specifying validation rules as annotations has its strength, but also its weaknesses, which I think are not always evaluated.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;ve had success with a pure-OO approach I&amp;#8217;ll describe here.&lt;/p&gt;

&lt;p&gt;But first let&amp;#8217;s look at the annotations approach.&lt;/p&gt;

&lt;h2 id='the_pros_of_annotations'&gt;The Pros of Annotations&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;You get to type-safely add rules on an attribute-by-attribute basis.&lt;/p&gt;

&lt;p&gt;This is of course the huge win over XML&amp;#8211;you don&amp;#8217;t have to retype an attribute name in an XML file and brave typos due to repetition that is not compile-checked.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Very clean, succinct declarations.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id='the_cons_of_annotations'&gt;The Cons of Annotations&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Annotations are static&amp;#8211;you have no way of adding/removes rules as needed.&lt;/p&gt;

&lt;p&gt;One app I worked on had non-trivial validation rules&amp;#8211;they were closer to business constraints than low-level &amp;#8220;not null&amp;#8221; checks. Which was good because it kept the data sane and caught bugs before the Unit of Work was committed. But, real life being what it is, we needed to occasionally turn them off. Especially if we had legacy data that we knew wouldn&amp;#8217;t conform to the new business rules.&lt;/p&gt;

&lt;p&gt;Obviously you want disabling rules to be a very one-off thing&amp;#8211;I&amp;#8217;d be worried if it become habitual. But it is handy when needed.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Annotations cannot cross multiple attributes&amp;#8211;often times rules want to bind across multiple parameters (e.g. stop/end for date ranges).&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Annotations seem harder to customize&amp;#8211;most frameworks seem to have boilerplate not null/column length rules, but the real power of validation is when you start adding business-specific rules. It is not incredibly clear to me whether the annotation-based validation frameworks allow easy addition of your own custom annotations.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id='a_java_alternative'&gt;A Java Alternative&lt;/h2&gt;

&lt;p&gt;I&amp;#8217;ve had success with each domain object having its own list of &lt;code&gt;Rule&lt;/code&gt; objects. Rules can be added/removed as needed, and, being just POJOs themselves, are easy to create your own, business-specific rules.&lt;/p&gt;

&lt;p&gt;For type-safety, this approach leverages &lt;a href='http://joist.ws/bindgen.html'&gt;bindgen&lt;/a&gt;. Instead of bindgen, it can also work by passing OGNL expressions to the rules (instead of bindgen&amp;#8217;s &lt;code&gt;Binding&lt;/code&gt; objects), but then you give up type-safety.&lt;/p&gt;

&lt;p&gt;So, an example of a domain object would be:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public class FooDomainObject extends BaseClassWithAddRulesEtc {
  public FooDomainObject() {
      this.addExtraRules();
  }

  private void addExtraRules() {
      FooDomainObjectBinding b = new FooDomainObjectBinding(this);
      this.addRule(new NotNullRule(b.title()));
      this.addRule(new SaneDateRule(b.start(), b.stop()));
  }

  // ... title, start, stop getters &amp;amp;amp; setters ...

  // ... in the base class:
  public ValidationErrors validate() {
      ValidationErrors errors = new ValidationErrors();
      for (Rule rule : this.getRules()) {
          rule.validate(errors, this);
      }
      return errors;
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This first alternative has a few trade-offs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;All rules are within the &lt;code&gt;addExtraRules&lt;/code&gt; method instead of alongside their getter/setter.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;It is more verbose, having to repeat &lt;code&gt;b.title()&lt;/code&gt; in the &lt;code&gt;addRule&lt;/code&gt; clause. But this only gets really annoying if you need a &lt;code&gt;private static&lt;/code&gt; reference to a rule for later removal.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;It is simpler from an implementation perspective&amp;#8211;just iterating over rules and calling &lt;code&gt;validate&lt;/code&gt;. Annotations usually involve non-trivial lookup/storage/etc. that means delegating to a heavier-weight framework to handle.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Turning off rules requires promoting rules to a static field, as in this 2nd example:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public class FooDomainObject {

    private static FooDomainObjectBinding b = new FooDomainObjectBinding();
    private static Rule titleNotNull = new NotNullRule(b.title());
    private static Rule saneDateRule = new SaneDateRule(b.start(), b.end());

    public FooDomainObject() {
        this.addExtraRules();
    }

    private void addExtraRules() {
        this.addRule(FooDomainObject.titleNotNull);
        this.addRule(FooDomainObject.saneDateRule);
    }

    public void disableTitleRule() {
        this.removeRule(FooDomainObject.titleNotNull);
    }

    // ... title, start, stop getters &amp;amp;amp; setters ...
}

// ... sometime later ...
fooDomainObject.disableTitleRule();&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A variation of this theme would be to kill the &lt;code&gt;addExtraRules&lt;/code&gt; and use a list utility in the declarations:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public class FooDomainObject {

    private static FooDomainObjectBinding b = new FooDomainObjectBinding();
    private static DefaultRules rules = new DefaultRules();
    private static Rule titleNotNull = rules.ref(new NotNullRule(b.title()));
    private static Rule saneDateRule = rules.ref(new SaneDateRule(b.start(), b.end()));

    public FooDomainObject() {
        FooDomainObject.rules.copyTo(this);
    }

    public void disableTitleRule() {
        this.removeRule(FooDomainObject.titleNotNull);
    }

    // ... title, start, stop getters &amp;amp;amp; setters ...
}

// ... sometime later ...
fooDomainObject.disableTitleRule();&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Adds another static variable (&lt;code&gt;rules&lt;/code&gt;)&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Makes the rule declaration longer as we pass the rule reference through the &lt;code&gt;ref&lt;/code&gt; method to keep track of it&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But, nicely:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Removes the &lt;code&gt;addExtraRules&lt;/code&gt; and rules being referenced in multiple places&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id='a_scala_alternative'&gt;A Scala Alternative&lt;/h2&gt;

&lt;p&gt;And, actually, since two-way binding is not required, Scala&amp;#8217;s call-by-name functionality would work here:&lt;/p&gt;

&lt;pre class='brush:scala'&gt;&lt;code&gt;class FooDomainObject {
  addRule(new NotNullRule(title))

  // ... title ...
}

class NotNullRule[T](value: =&amp;gt; AnyRef) implements Rule[T] {
  def validate(T instance) = {
    if (value == null) {
      // ... add error ...
    }
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;However, this has one major trade-off:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Passing &lt;code&gt;title&lt;/code&gt; as call-by-name only lets us get the value&amp;#8211;both annotations and bindgen also allow access to the name of the property for inclusion in error messages (e.g. &amp;#8220;title is required&amp;#8221;&amp;#8211;with call-by-name, you don&amp;#8217;t actually know it&amp;#8217;s called &amp;#8220;title&amp;#8221;).&lt;/p&gt;

&lt;p&gt;I think having the attribute name is required, so we&amp;#8217;d have to pass another string parameter:&lt;/p&gt;

&lt;pre class='brush:scala'&gt;&lt;code&gt;class FooDomainObject extends BaseClassWithAddRulesEtc {
  addRule(new NotNullRule(&amp;quot;title&amp;quot;, title))
}&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But, even then, that&amp;#8217;s pretty slick and lightweight. If scala&amp;#8217;s call-by-name had something like &amp;#8220;set-by-name&amp;#8221; to make it two-way, and perhaps throw in a &lt;code&gt;getName()&lt;/code&gt; for good measure, it would easily trump the need for &lt;a href='http://joist.ws/bindgen.html'&gt;bindgen&lt;/a&gt;-like hacks.&lt;/p&gt;

&lt;h2 id='wrapping_up'&gt;Wrapping Up&lt;/h2&gt;

&lt;p&gt;I&amp;#8217;ve been coming around on annotations. But I do like to be contrary and just highlight that they are not the only solution for specifying business rules against domain objects. Having had the success with it in the past, I&amp;#8217;m currently partial to staying with object-based approaches to validation rules.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Scala Per-Instance Singletons</title>
   <link href="http://draconianoverlord.com/2009/07/13/scala-per-instance-singletons.html"/>
   <updated>2009-07-13T00:00:00-07:00</updated>
   <id>http://draconianoverlord.com/2009/07/13/scala-per-instance-singletons</id>
   <content type="html">&lt;h1 id='scala_perinstance_singletons'&gt;Scala Per-Instance Singletons&lt;/h1&gt;

&lt;p&gt;I was reading about &lt;a href='http://liftweb.com'&gt;Lift&lt;/a&gt; and came across a funky scala syntax:&lt;/p&gt;

&lt;pre class='brush:scala'&gt;&lt;code&gt;class Foo {
  object bar {
    val name = &amp;quot;bob&amp;quot;
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Declares a &lt;code&gt;Foo.bar&lt;/code&gt; field&lt;/li&gt;

&lt;li&gt;Declares a &lt;code&gt;bar&lt;/code&gt; inner class&lt;/li&gt;

&lt;li&gt;Adds a &lt;code&gt;Foo.bar()&lt;/code&gt; method that lazy-instantiates a single instance of the &lt;code&gt;bar&lt;/code&gt; inner class for each &lt;code&gt;Foo&lt;/code&gt; instance&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Looking at the decompiled code, it makes more sense:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;import java.rmi.RemoteException;
import scala.ScalaObject;

public class Foo implements ScalaObject {
    private bar. bar$module;

    public Foo() {
    }

    public final bar. bar() {
        class bar. implements ScalaObject {
            private final String name = &amp;quot;bob&amp;quot;;
            public bar.() {
                super();
            }
            public String name() {
                return name;
            }
            public int $tag() throws RemoteException {
                return scala.ScalaObject.class.$tag(this);
            }
        }
        if(bar$module == null)
            bar$module = new bar.();
        return bar$module;
    }

    public int $tag() throws RemoteException {
        return scala.ScalaObject.class.$tag(this);
    }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;My one curiosity is the lack of synchronization in the lazy initialization. I don&amp;#8217;t know about the official Scala docs, but Lift insinuated an &amp;#8220;inner object&amp;#8221; declaration was a singleton, not a singleton-unless-you-have-lots-of-threads.&lt;/p&gt;

&lt;p&gt;If you use top-level &lt;code&gt;object&lt;/code&gt; declarations, it seems to make more sense:&lt;/p&gt;

&lt;pre class='brush:scala'&gt;&lt;code&gt;object Bar {
  def zaz() = {
    println(&amp;quot;hi&amp;quot;)
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;As this is decompiled to:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public final class Bar {
  public static final void zaz() {
    Bar..MODULE$.zaz();
  }

  public static final int $tag() throws RemoteException {
    return Bar..MODULE$.$tag();
  }
}

public final class Bar$ implements ScalaObject {
  public static final Bar$ MODULE$;

  static {
    new Bar$();
  }

  public Bar$() {
    MODULE$ = this;
  }

  public void zaz() {
    Predef..MODULE$.println(&amp;quot;hi&amp;quot;);
  }

  public int $tag() throws RemoteException {
    return ScalaObject.class.$tag(this);
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This uses the &lt;code&gt;Bar$&lt;/code&gt; static initializer to ensure there is just one instance of &lt;code&gt;Bar$&lt;/code&gt;. Which works great.&lt;/p&gt;

&lt;p&gt;&amp;#8220;Inner&amp;#8221; object declarations not being true singletons is probably not a big deal, it was just something I was curious about.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Achieving Durability</title>
   <link href="http://draconianoverlord.com/2009/06/24/achieving-durability.html"/>
   <updated>2009-06-24T00:00:00-07:00</updated>
   <id>http://draconianoverlord.com/2009/06/24/achieving-durability</id>
   <content type="html">&lt;h1 id='achieving_durability'&gt;Achieving Durability&lt;/h1&gt;

&lt;h2 id='introduction'&gt;Introduction&lt;/h2&gt;

&lt;p&gt;At one of my last gigs, building a claims system for an employee benefits 3rd-party administrator, nightly batch processes were a way of life. Yeah, batch processes aren&amp;#8217;t sexy, but when you need to mail out thousands of checks every morning, you don&amp;#8217;t generate the PDFs from within the user&amp;#8217;s rich client Air application.&lt;/p&gt;

&lt;p&gt;The durability of these processes was important, and we achieved it by simply leveraging our existing database.&lt;/p&gt;

&lt;p&gt;Durability was important because if something happened (which it always does), things should just work. Power/network/whatever went out? Just restart the process. A vendor sent data that we&amp;#8217;ve never seen before? The process continues and just tries the funky data again tomorrow.&lt;/p&gt;

&lt;p&gt;Previously, these types of events would cause mini-catastrophes that required immediate attention from a developer. Developers would have to hand-edit the file to only retry the &amp;#8220;bad&amp;#8221; transactions, figure out where a process died and jury rig it to start from there, and just generally do a lot of manual leg-work and hand-holding for the system.&lt;/p&gt;

&lt;p&gt;Instead of constantly fighting fires, the goal was to expect failures, handle them gracefully, and continue on to the next task, either immediately if the error was recoverable or, at worst, after a system restart. This would free up resources from day-to-day fire-fighting and let devs focus on just fixing bugs, not fixing bugs while also finessing the system back into a good state.&lt;/p&gt;

&lt;p&gt;Of course, it is unlikely you&amp;#8217;ll have the time/desire to make the entire system fault tolerant to the Nth degree, but some basics will still take you a long way, in my experience.&lt;/p&gt;

&lt;h2 id='atomicity'&gt;Atomicity&lt;/h2&gt;

&lt;p&gt;One fundamental concept to durability is atomicity&amp;#8211;if you want to continue where you left off before, you can&amp;#8217;t redo previous work.&lt;/p&gt;

&lt;p&gt;If your tasks are idempotent, you&amp;#8217;re in luck. Being idempotent means you can &amp;#8220;retry&amp;#8221; a task as many times as you want, and the task is smart enough to not cause funky behavior (like double-/triple-processing). For example, it&amp;#8217;s a transaction with a unique id that, if you find the id already in your system, you know not to enter it again. If your tasks are idempotent, you can just retry everything and what was already done will not cause duplicates.&lt;/p&gt;

&lt;p&gt;However, if your tasks are not idempotent, you&amp;#8217;ll have to explicitly mark tasks as pending and then as done.&lt;/p&gt;

&lt;p&gt;Marking tasks as done is pretty easy with in-memory lists/etc.&amp;#8211;but its neither atomic nor durable. Your process can&amp;#8217;t be:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Make an ArrayList of tasks&lt;/li&gt;

&lt;li&gt;Do task A&lt;/li&gt;

&lt;li&gt;Remove task A from the list&lt;/li&gt;

&lt;li&gt;Repeat until list is empty&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There are two bad scenarios here:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Failure happens between 2 and 3&amp;#8211;you&amp;#8217;ve done a task but not yet marked it done.&lt;/li&gt;

&lt;li&gt;Failure happens after N tasks&amp;#8211;on restart, the ArrayList will have those first N items in it again.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The key to scenario 1) is atomicity&amp;#8211;you can&amp;#8217;t have a two step &amp;#8220;do A&amp;#8221; then &amp;#8220;mark A done&amp;#8221;, because if the box goes down in between those two, you&amp;#8217;re going to redo &amp;#8220;A&amp;#8221; when you come back up.&lt;/p&gt;

&lt;p&gt;The key to scenario 2) is to make your lookup of tasks take into account those that are already done.&lt;/p&gt;

&lt;h2 id='embrace_acid'&gt;Embrace ACID&lt;/h2&gt;

&lt;p&gt;The easiest way I&amp;#8217;ve found to achieve durability is to realize you have an awesomely-durable resource at your disposal and you should leverage/abuse it as much as possible: your relational database server.&lt;/p&gt;

&lt;p&gt;The key is to perform the business logic of the task &lt;em&gt;and&lt;/em&gt; mark the task as done within the same transaction.&lt;/p&gt;

&lt;p&gt;This means embedding in-progress data in your primary database instead of the JVM process (see the examples for details). A con is that if your database is already your bottleneck, even this small extra load may not be welcome. However, in the enterprise apps I&amp;#8217;ve worked on, this was not the case. Also, a pro is that the in-progress data will be easily available for dashboards to report against.&lt;/p&gt;

&lt;p&gt;So now scenario 1) is solved. Your database does all of the hard work ensuring that both task + marking either happen or not happen.&lt;/p&gt;

&lt;p&gt;Solving scenario 2) is fairly problem specific, so I&amp;#8217;ll defer to the examples, particularly the &lt;code&gt;DocumentCursor.line&lt;/code&gt; attribute.&lt;/p&gt;

&lt;h2 id='examples'&gt;Examples&lt;/h2&gt;

&lt;p&gt;Two examples of adding durability into a system are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sending emails&lt;/li&gt;

&lt;li&gt;Processing 3rd party data files.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both can run into problems that you want to have handled nicely.&lt;/p&gt;

&lt;h2 id='sending_email'&gt;Sending Email&lt;/h2&gt;

&lt;p&gt;The first time I wrote email processing for the client&amp;#8217;s app, it felt dirty&amp;#8211;here within a nice Unit Of Work, doing some business logic, was an ugly &lt;code&gt;Transport.send&lt;/code&gt; dropping an email onto the wire. Who knew what that would do if it failed. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The email goes out because the &lt;code&gt;Transport.send&lt;/code&gt; succeeds, but the transaction fails to commit&amp;#8211;we&amp;#8217;ve told the user about some action we thought we performed but didn&amp;#8217;t actually get committed.&lt;/li&gt;

&lt;li&gt;The &lt;code&gt;Transport.send&lt;/code&gt; fails because our mail server is being dumb, but then the entire Unit Of Work fails and we don&amp;#8217;t get any work done for the day until the mail server is back up.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There ended up being an obvious solution&amp;#8211;a partner firm was storing their generated email in the database for CRM purposes (knowing what you&amp;#8217;ve sent users), but I realized this was also the perfect way to solve the &lt;code&gt;Transport.send&lt;/code&gt; problem&amp;#8211;decouple generation of the email content within the business process from the actual sending of the email content out onto the network.&lt;/p&gt;

&lt;p&gt;So, now:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A business process has 1 Unit Of Work that: does business logic and saves a &lt;code&gt;Email&lt;/code&gt; object to the database&amp;#8211;both either succeed or fail atomically.&lt;/li&gt;

&lt;li&gt;An infrastructure process polls the email table and, after seeing newly-committed emails, drops them onto the wire. If errors occur, it tries again after 5 minutes. If it succeeds, it updates the row&amp;#8217;s &amp;#8220;sent&amp;#8221; column.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now email server funkiness will not disrupt the business process from its core work of performing business logic and generating emails. And business process funkiness will not result in &amp;#8220;leaked&amp;#8221; emails.&lt;/p&gt;

&lt;p&gt;Note that we still have a window of opportunity for failure in the infrastructure process&amp;#8211;again between the &lt;code&gt;Transport.send&lt;/code&gt; and the &lt;code&gt;UoW.commit&lt;/code&gt;, but it&amp;#8217;s much smaller window given we&amp;#8217;re only updating the &lt;code&gt;sent&lt;/code&gt; column and not performing the complex business logic that lead to the creation of the email (and could have triggered non-trivial validation rules that would have to all pass before committing). This is where, if you wanted to go to the Nth degree, you&amp;#8217;d implement some sort of API with your mail server to see if the current message id had already been sent.&lt;/p&gt;

&lt;h2 id='processing_data_files'&gt;Processing Data Files&lt;/h2&gt;

&lt;p&gt;Processing nightly batch files from one of the client&amp;#8217;s vendors was another big win for durability. The vendor has a history of sending new and interesting transactions on a semi-regular basis. Not enough to be really annoying, but enough to burn a day screwing around with recovery every few months or so.&lt;/p&gt;

&lt;p&gt;The original approach would retry entire files, and attempted to leverage an almost-idempotent transaction id. However, there was a heuristic involved that was not always accurate.&lt;/p&gt;

&lt;p&gt;So, when we were changing how the system handled files anyway, I refactored the process to be durable:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Upon finding a file, a &lt;code&gt;Document&lt;/code&gt; is saved to the database, and then a &lt;code&gt;DocumentCursor&lt;/code&gt; with &lt;code&gt;cursor.line=0&lt;/code&gt; is stored as well.&lt;/li&gt;

&lt;li&gt;An atomic parser then finds all open cursors in the database, and starts reading over their documents. It skips to line &lt;code&gt;x&lt;/code&gt; if &lt;code&gt;line != 0&lt;/code&gt;, so if a file is 80% done, it jumps right to the last 20%.&lt;/li&gt;

&lt;li&gt;Each line is processed in its own transaction&amp;#8211;if the business logic succeeds, the cursor&amp;#8217;s &lt;code&gt;line&lt;/code&gt; is ticked within the same transaction.&lt;/li&gt;

&lt;li&gt;If a line&amp;#8217;s transaction fails due to faulty parsing/business rules, the &lt;code&gt;DocumentCursor&lt;/code&gt; is given a new &lt;code&gt;FailedLine&lt;/code&gt; child row that stores that line&amp;#8217;s number. This will cause the cursor to stay open, and the &lt;code&gt;FailedLine&lt;/code&gt; will be retried on the next process run (e.g. tomorrow). The idea is to keep retrying every morning until the line succeeds. If a fix is required, the line will be automatically retried and should work the morning after the fix is released to production.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also, the cursor logic can work against multiple types of documents&amp;#8211;it was later used to handle another vendor&amp;#8217;s incoming files with non-idempotent lines, so the durability was again necessary to avoid double processing in failure scenarios.&lt;/p&gt;

&lt;h2 id='keep_things_simple_one_datasource'&gt;Keep Things Simple: One Datasource&lt;/h2&gt;

&lt;p&gt;The thing that made all of this doable was keeping business data and temporary in-progress data in the same database.&lt;/p&gt;

&lt;p&gt;At first, I hesitated to do this, and was initially considering jury rigging some sort of two-phase commit with the primary database and a separate embedded/temporary database for the in-progress data. But, frankly, it&amp;#8217;s so much simpler to avoid JTA and just use 1 transaction that, empirically, the one-datasource approach has won me over.&lt;/p&gt;

&lt;p&gt;Having easy benefits like this with a single ACID data source makes me curious about how people handle similar scenarios with DHTs. I love the sexiness of scaling to Amazon-size as much as the next guy, but doing recovery scenarios in application code on top of a DHT seems complex&amp;#8211;wouldn&amp;#8217;t it devolve into manual two-phase commit? I&amp;#8217;m not sure. Intra-source resolution (e.g. &amp;#8220;merge carts&amp;#8221;) makes sense, but it is inter-source resolution that I haven&amp;#8217;t puzzled through yet (e.g. &amp;#8220;book order reduced in inventory + book removed from cart&amp;#8221;).&lt;/p&gt;

&lt;p&gt;I favor starting with a RDBMS for your first few versions and only switching to DHTs when it becomes painfully obvious you need it. Yes, this is going to involve a massive refactoring of your code to deal with the completely different semantics of a DHT, but I think that is worth the simpler development you&amp;#8217;ll get up-front. And, who knows, you may never need the DHT.&lt;/p&gt;

&lt;h2 id='testing_for_failures'&gt;Testing For Failures&lt;/h2&gt;

&lt;p&gt;I don&amp;#8217;t trust myself to get failure scenarios correct the first time, so I also developed a way to test the most likely points of failure. A different approach was required to solve two pain points of traditional approaches, such as setting up bad data or using mock objects:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Causing business logic to purposefully fail was difficult because our domain model had lots of validation rules to keep invalid data from getting into the database. Making invalid vendor files was easy, but setting up bad data within the database required ugly hacks to turn off validation rules or do manual &lt;code&gt;INSERTs&lt;/code&gt;/etc.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Mock objects can only fail when going across API boundaries, e.g. into the email API. Several of the durability scenarios require testing what happens within an API boundary&amp;#8211;e.g. you&amp;#8217;re in the middle of a method in the &lt;code&gt;CursorProcessor&lt;/code&gt; class and the power goes out.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;My solution was a class, &lt;code&gt;TestBreaker&lt;/code&gt;, that we made explicit calls to from specific vulnerability points in the production code. The &lt;code&gt;TestBreakers&lt;/code&gt; calls did nothing in production, and in test would throw an exception if explicitly enabled by a unit test.&lt;/p&gt;

&lt;p&gt;So, the &lt;code&gt;CursorProcessor&lt;/code&gt; had several of these &lt;code&gt;TestBreakers&lt;/code&gt; declared as constants:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public static final TestBreaker BREAK_AFTER_CURSOR = new TestBreaker();
public static final TestBreaker BREAK_INSIDE_LINE_RETRY = new TestBreaker();
public static final TestBreaker BREAK_AFTER_LINE_ATTEMPT = new TestBreaker();
public static final TestBreaker BREAK_INSIDE_LINE_ATTEMPT = new TestBreaker();&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then at vulnerable points in the code path, we&amp;#8217;d put an explicit call:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;// some important code that could break
CursorProcessor.BREAK_AFTER_CURSOR.ifSetFor(cursorId);&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In production, this is a no-op. But in test, it will throw an exception if we&amp;#8217;re on a certain cursor. This allows us to test the scenario of one cursor completely blowing up, but verifying that the process continues on to the next cursor.&lt;/p&gt;

&lt;p&gt;A JUnit test can then explicitly trigger the breakage:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public void testOneCursorFailingOutsideLineContinuesOnToTheNext() {
    // data setup
    CursorProcessor.BREAK_AFTER_CURSOR.setFor(2);
    // run process
    // assertions
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Showing my bias, I also love that &lt;code&gt;BREAK_AFTER_CURSOR&lt;/code&gt; is a static constant, because just I did a &lt;code&gt;Ctrl-Shift-G&lt;/code&gt; on the constant in Eclipse and immediately saw which one test out of thousands was referencing it to trigger than failure condition. I&amp;#8217;m not an IoC expert, but I anticipate you would lose this capability with dependency injection.&lt;/p&gt;

&lt;h2 id='conclusion'&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;I&amp;#8217;ve shown several examples of leveraging your RDBMS to achieve business process durability. The approach has worked very well for me and I anticipate using it again in the future.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m also interested in other approaches, e.g. when you can&amp;#8217;t leverage a single data source. I have done some googling on the topic, but I haven&amp;#8217;t found much yet. If you have pointers to different ways of solving this sort of problem, I&amp;#8217;d appreciate links in the comments.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Dynamic Keywords</title>
   <link href="http://draconianoverlord.com/2009/05/12/dynamic-keywords.html"/>
   <updated>2009-05-12T00:00:00-07:00</updated>
   <id>http://draconianoverlord.com/2009/05/12/dynamic-keywords</id>
   <content type="html">&lt;h1 id='dynamic_keywords'&gt;Dynamic Keywords&lt;/h1&gt;

&lt;p&gt;One of the things I love about &lt;a href='http://boo.codehaus.org'&gt;boo&lt;/a&gt; are its &lt;a href='http://boo.codehaus.org/Syntactic+Macros'&gt;macros&lt;/a&gt; that allow you to rewrite the AST at compile time.&lt;/p&gt;

&lt;p&gt;This makes a lot of sense. All of malleability that people loves in dynamic languages like Ruby and Groovy, screwing with classes at runtime, etc., to me, should be done at compile time.&lt;/p&gt;

&lt;p&gt;Typically, meta-programming in dynamic languages is only performed at load time anyway, when the interpreter first loads a file&amp;#8230;it is not like after being deployed for 2 weeks, the Employee object suddenly gets another attribute added to it. At least I hope not.&lt;/p&gt;

&lt;p&gt;Historically it has not been possible to plug into the compiler of type-safe languages, so it was easier to go with dynamic languages that let you screw with their types. I&amp;#8217;ve seen Scala making some progress towards type-safe compiler plugins, but they seem non-trivial to write. Though, granted, I have no real experience other than glancing at them and thinking &amp;#8220;wow, looks hard.&amp;#8221;&lt;/p&gt;

&lt;p&gt;Anyway, back to boo, what I find intriguing is if a language was macros all the way down&amp;#8230;i.e. even basic constructs like &lt;code&gt;class&lt;/code&gt;, &lt;code&gt;method&lt;/code&gt;, and &lt;code&gt;if&lt;/code&gt; were not baked into the syntax, but just macros that ship by default and that you could override/add to as needed.&lt;/p&gt;

&lt;p&gt;I think the result would end up looking something like &lt;a href='http://www.iolanguage.com/'&gt;io&lt;/a&gt;, albeit with the magic happening at compile-time instead of runtime.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;ve been typing out a syntax:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class Foo extends(Object) implements(Bar)
    field name

    method bar param(p1, String) param(p2, String)
        ...
    end
end&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Where &lt;code&gt;class&lt;/code&gt; is a shipped macro. &lt;code&gt;extends&lt;/code&gt; and &lt;code&gt;implements&lt;/code&gt; are&amp;#8230;additive-macros? I dunno, either options baked into the &lt;code&gt;class&lt;/code&gt; macro itself, or, ideally, layered onto the &lt;code&gt;class&lt;/code&gt; macro. So, conceptually, you could add your own extensions, e.g. &lt;code&gt;class Foo mixin(Bar)&lt;/code&gt; or what not.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;field name&lt;/code&gt; and &lt;code&gt;method bar&lt;/code&gt; lines are a little jarring at first&amp;#8211;in C-based languages, the field-ness/method-ness is taken for granted by being baked into the syntax, so you don&amp;#8217;t have to explicitly say &amp;#8221;I&amp;#8217;m doing a field now&amp;#8221;, &amp;#8221;I&amp;#8217;m doing a method now&amp;#8221;.&lt;/p&gt;

&lt;p&gt;What I don&amp;#8217;t have an intelligent answer for is how to differentiate between regular runtime method calls and AST-mucking compile-time macro calls.&lt;/p&gt;

&lt;p&gt;Maybe something silly like prefixes, e.g. &lt;code&gt;$class Foo&lt;/code&gt; or &lt;code&gt;@class Foo&lt;/code&gt;. A little too Perl for my liking. I also thought of suffixes, e.g. &lt;code&gt;class: Foo&lt;/code&gt;, &lt;code&gt;field: name&lt;/code&gt;, which seems better.&lt;/p&gt;

&lt;p&gt;There is a risk of ending up too fancy&amp;#8211;a mailing list discussion recently made the comment that Java hits a sweet spot of being simple enough to just glance at and understand, without having to know all of the concise DSL-enabling syntax tricks of Ruby/Groovy.&lt;/p&gt;

&lt;p&gt;Nonetheless, if done right, I think macros all the way down would be very cool.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>The IBM JDK is Awesome</title>
   <link href="http://draconianoverlord.com/2009/04/29/the-ibm-jdk-is-awesome.html"/>
   <updated>2009-04-29T00:00:00-07:00</updated>
   <id>http://draconianoverlord.com/2009/04/29/the-ibm-jdk-is-awesome</id>
   <content type="html">&lt;h1 id='the_ibm_jdk_is_awesome'&gt;The IBM JDK is Awesome&lt;/h1&gt;

&lt;p&gt;Insofar as its &lt;a href='http://en.wikipedia.org/wiki/IBM_J9'&gt;J9&lt;/a&gt; JRE supports adding methods to classes at runtime. For me, this is a real boon for productivity.&lt;/p&gt;

&lt;p&gt;(Edit: To clarify, I&amp;#8217;m talking about editing source code while debugging and having changes applied by &amp;#8220;hot swapping&amp;#8221; classes in the running JVM without having to restart. Not the Ruby-style meta-programming of modifying classes at runtime.)&lt;/p&gt;

&lt;p&gt;I don&amp;#8217;t understand why Sun has not fixed this in their JREs, see bug &lt;a href='http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4910812'&gt;4910812&lt;/a&gt;, to bring Java development that much closer to the Smalltalk &amp;#8220;always-running&amp;#8221; ideal I&amp;#8217;ve heard Smalltalkers wax poetic about.&lt;/p&gt;

&lt;p&gt;If you haven&amp;#8217;t voted for 4910812, please go do so. It has only 379 votes, which seems surprisingly low for the number of developers whose productivity would be positively effected by it being implemented. I remember seeing a &amp;#8220;vote 4910812&amp;#8221; meme go around awhile ago, but it must not have caught on.&lt;/p&gt;

&lt;p&gt;Compared to the IBM JDK, I generally prefer the Sun JDK because it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Seams less finicky (which is very subjective, I know)&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Ships with the source code for its Java class library (which IBM&amp;#8217;s JDK does not)&amp;#8211;not that I read Java class library source code all day, but I flinch every time the &amp;#8220;unattached source&amp;#8221; view pops up in Eclipse&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Is faster than the J9 JRE in the one micro benchmark I ran&amp;#8211;while recording stats for bindgen, I was confused about why it was suddenly so slow, but it turned out I had switched my workspace preferences to the IBM JDK. Switching back to the Sun JDK restored the performance numbers to their previous values.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But I can deal with these in my development environment to get the awesomeness of the J9 JRE adding methods without restarting.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;ve tried other JDKs, like BEA/Oracle&amp;#8217;s JRockit, Apache&amp;#8217;s Harmony, but none of them do hot method adding like IBM&amp;#8217;s J9. I was surprised because I&amp;#8217;ve always heard good things about JRockit, and Harmony has some sort of access to J9, but neither have pulled it off yet.&lt;/p&gt;

&lt;p&gt;I added small entry about the IBM JDK to Joist&amp;#8217;s &lt;a href='http://joist.ws/eclipseTips.html'&gt;Eclipse Tips&lt;/a&gt; page if you&amp;#8217;re interested in how to get it/set it up, though it is pretty easy.&lt;/p&gt;

&lt;p&gt;One of these days I&amp;#8217;ll play with &lt;a href='http://www.zeroturnaround.com/'&gt;ZeroTurnaround&lt;/a&gt;, but having the JRE support it natively just seems cleaner.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Ivy is Useful</title>
   <link href="http://draconianoverlord.com/2009/04/23/ivy-is-useful.html"/>
   <updated>2009-04-23T00:00:00-07:00</updated>
   <id>http://draconianoverlord.com/2009/04/23/ivy-is-useful</id>
   <content type="html">&lt;h1 id='ivy_is_useful'&gt;Ivy is Useful&lt;/h1&gt;

&lt;p&gt;After being burned by Maven, I&amp;#8217;ve shunned any sort of dependency management solution that is not just checking jars into the SCM.&lt;/p&gt;

&lt;p&gt;However, I finally ran into a &amp;#8220;parent-with-sub-project&amp;#8221; type of arrangement in &lt;a href='http://joist.ws'&gt;Joist&lt;/a&gt;, and so needed a way to locally publish SNAPSHOT/in-progress jars for the subsequent builds to find them.&lt;/p&gt;

&lt;p&gt;After hacking around with my own Ant-based home directory jar cache, I decided to kick Ivy&amp;#8217;s tires, and I&amp;#8217;ve been quite pleased.&lt;/p&gt;

&lt;p&gt;Here&amp;#8217;s a few things I&amp;#8217;ve learned:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href='http://ant.apache.org/ivy/ivyde/'&gt;IvyDE&lt;/a&gt; rocks, especially being able to recognize other open Eclipse projects and put them on the classpath instead of the cached SNAPSHOT jars, so now you can just hit save and not have to worry about updating jars.&lt;/p&gt;

&lt;p&gt;You have to enable this in Java Build Path, Libraries, &lt;code&gt;ivy.xml&lt;/code&gt;, Advanced, check Resolve dependencies in workspace.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;&lt;a href='http://ant.apache.org/ivy/ivyde/'&gt;IvyDE&lt;/a&gt; is still immature&amp;#8211;the &lt;code&gt;ivy.xml&lt;/code&gt; has to resolve of its dependencies perfectly or else you are kind of screwed. It&amp;#8217;s best to get you &lt;code&gt;ivy.xml&lt;/code&gt;, &lt;code&gt;ivysettings.xml&lt;/code&gt; working with Ant first, then try Eclipse and IvyDE.&lt;/p&gt;

&lt;p&gt;Opening/closing the Eclipse project seems like the best way to get IvyDE to &amp;#8220;try again&amp;#8221;.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;I use a small variation of the Ivy documentation&amp;#8217;s bootstrapping logic to auto-install Ivy (and JSch) into &lt;code&gt;~/.ivy2&lt;/code&gt; so that Ant users do not need to download it by hand&lt;/p&gt;

&lt;pre class='brush:xml'&gt;&lt;code&gt;&amp;lt;project name=&amp;quot;ivybootstrap&amp;quot; xmlns:ivy=&amp;quot;antlib:org.apache.ivy.ant&amp;quot;&amp;gt;
  &amp;lt;!--
  The &amp;quot;ivy.bootstrap&amp;quot; target ensures ivy and JSCH are downloaded and installed
  in the user&amp;#39;s $HOME/.ivy2 directory so we can implicitly taskdef them into
  this ant context without messing with the $ANT_HOME/lib directory or
  otherwise having the user explicitly go download ivy.
  --&amp;gt;

  &amp;lt;property name=&amp;quot;ivy.jar.version&amp;quot; value=&amp;quot;2.0.0&amp;quot;/&amp;gt;
  &amp;lt;property name=&amp;quot;ivy.jar.name&amp;quot; value=&amp;quot;ivy-${ivy.jar.version}.jar&amp;quot;/&amp;gt;
  &amp;lt;property name=&amp;quot;ivy.home&amp;quot; value=&amp;quot;${user.home}/.ivy2&amp;quot;/&amp;gt;
  &amp;lt;available property=&amp;quot;ivy.installed&amp;quot; file=&amp;quot;${ivy.home}/${ivy.jar.name}&amp;quot;/&amp;gt;

  &amp;lt;property name=&amp;quot;jsch.jar.version&amp;quot; value=&amp;quot;0.1.29&amp;quot;/&amp;gt;
  &amp;lt;property name=&amp;quot;jsch.jar.name&amp;quot; value=&amp;quot;jsch-${jsch.jar.version}.jar&amp;quot;/&amp;gt;
  &amp;lt;available property=&amp;quot;jsch.installed&amp;quot; file=&amp;quot;${ivy.home}/${jsch.jar.name}&amp;quot;/&amp;gt;

  &amp;lt;target name=&amp;quot;ivy.install&amp;quot; unless=&amp;quot;ivy.installed&amp;quot;&amp;gt;
    &amp;lt;mkdir dir=&amp;quot;${ivy.home}&amp;quot;/&amp;gt;
    &amp;lt;get src=&amp;quot;http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.jar.version}/${ivy.jar.name}&amp;quot; dest=&amp;quot;${ivy.home}/${ivy.jar.name}&amp;quot;/&amp;gt;
  &amp;lt;/target&amp;gt;

  &amp;lt;target name=&amp;quot;jsch.install&amp;quot; unless=&amp;quot;jsch.installed&amp;quot;&amp;gt;
    &amp;lt;get src=&amp;quot;http://repo1.maven.org/maven2/jsch/jsch/${jsch.jar.version}/${jsch.jar.name}&amp;quot; dest=&amp;quot;${ivy.home}/${jsch.jar.name}&amp;quot;/&amp;gt;
  &amp;lt;/target&amp;gt;

  &amp;lt;target name=&amp;quot;ivy.bootstrap&amp;quot; depends=&amp;quot;ivy.install,jsch.install&amp;quot; unless=&amp;quot;ivy.bootstrapped&amp;quot;&amp;gt;
    &amp;lt;taskdef resource=&amp;quot;org/apache/ivy/ant/antlib.xml&amp;quot; uri=&amp;quot;antlib:org.apache.ivy.ant&amp;quot; classpath=&amp;quot;${ivy.home}/${ivy.jar.name};${ivy.home}/${jsch.jar.name}&amp;quot;/&amp;gt;
    &amp;lt;property name=&amp;quot;ivy.bootstrapped&amp;quot; value=&amp;quot;true&amp;quot;/&amp;gt; &amp;lt;!-- Avoid re-bootstrapping because it causes classloader issues. --&amp;gt;
  &amp;lt;/target&amp;gt;
&amp;lt;/project&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;The default settings gave me a fit trying to get SNAPSHOTs to work&amp;#8211;Ivy is pretty insistent about caching as much as it possibly can.&lt;/p&gt;

&lt;p&gt;Which is cool, but it grew annoying when it would not check the &lt;em&gt;local&lt;/em&gt; repo, &lt;code&gt;~/.ivy2/local&lt;/code&gt;, for a newly-published SNAPSHOT just because a SNAPSHOT already existed in the cache, &lt;code&gt;~/.ivy2/cache&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I ended up using a &lt;code&gt;local-snapshot&lt;/code&gt; resolver to bust through:&lt;/p&gt;

&lt;pre class='brush:xml'&gt;&lt;code&gt;&amp;lt;ivysettings&amp;gt;
  &amp;lt;settings defaultResolver=&amp;quot;default&amp;quot;/&amp;gt;
  &amp;lt;include url=&amp;quot;${ivy.default.settings.dir}/ivysettings-public.xml&amp;quot;/&amp;gt;
  &amp;lt;include url=&amp;quot;${ivy.default.settings.dir}/ivysettings-local.xml&amp;quot;/&amp;gt;
  &amp;lt;resolvers&amp;gt;
    &amp;lt;!-- Copy/paste from ivysettings-local.xml with with changingPattern to bust the cache for snapshots. --&amp;gt;
    &amp;lt;filesystem name=&amp;quot;local-snapshot&amp;quot; changingPattern=&amp;quot;.*SNAPSHOT&amp;quot;&amp;gt;
      &amp;lt;ivy pattern=&amp;quot;${ivy.local.default.root}/${ivy.local.default.ivy.pattern}&amp;quot; /&amp;gt;
      &amp;lt;artifact pattern=&amp;quot;${ivy.local.default.root}/${ivy.local.default.artifact.pattern}&amp;quot; /&amp;gt;
    &amp;lt;/filesystem&amp;gt;

    &amp;lt;!-- Repeating the changingPattern incantation here is very important. --&amp;gt;
    &amp;lt;chain name=&amp;quot;default&amp;quot; changingPattern=&amp;quot;.*SNAPSHOT&amp;quot;&amp;gt;
      &amp;lt;resolver ref=&amp;quot;local-snapshot&amp;quot;/&amp;gt;
      &amp;lt;resolver ref=&amp;quot;public&amp;quot;/&amp;gt;
    &amp;lt;/chain&amp;gt;
  &amp;lt;/resolvers&amp;gt;
&amp;lt;/ivysettings&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; I previously had &lt;code&gt;checkmodified=true&lt;/code&gt; set on both &lt;code&gt;localhost-snapshot&lt;/code&gt; and &lt;code&gt;chain&lt;/code&gt; resolvers, however, I don&amp;#8217;t believe this is required.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Overall I&amp;#8217;ve found Ivy pleasant and look forward to future releases, especially of IvyDE.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Old School Bell Trick</title>
   <link href="http://draconianoverlord.com/2009/02/19/old-school-bell-trick.html"/>
   <updated>2009-02-19T00:00:00-08:00</updated>
   <id>http://draconianoverlord.com/2009/02/19/old-school-bell-trick</id>
   <content type="html">&lt;h2&gt;Old School Bell Trick&lt;/h2&gt;
&lt;p&gt;I&amp;#8217;m running test cases from the console a lot lately. Besides missing Eclipse, my productivity has dropped as I&amp;#8217;ll task switch to something else while the tests run, and I typically only notice the tests have completed after my other supposedly-parallel task hits an interrupt.&lt;/p&gt;

&lt;p&gt;To help with this, I&amp;#8217;m using an old &lt;code&gt;bell&lt;/code&gt; script I had laying around. I came across it awhile ago, and it is pretty simple, but I thought it might be worth rehashing the trick for others finding themselves on the command line lately.&lt;/p&gt;

&lt;p&gt;It looks like:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#!/bin/sh
echo ^G&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Where &lt;code&gt;^G&lt;/code&gt; is not two literal characters &lt;code&gt;^&lt;/code&gt; and &lt;code&gt;G&lt;/code&gt;, but a single &lt;a href='http://www.bo.infn.it/alice/alice-doc/mll-doc/linux/vi-ex/node15.html'&gt;control character&lt;/a&gt; &lt;code&gt;BEL&lt;/code&gt;. How you enter &lt;code&gt;BEL&lt;/code&gt; depends on your editor&amp;#8211;in &lt;code&gt;vim&lt;/code&gt;, you do &lt;code&gt;Ctrl-V Ctrl-G&lt;/code&gt; in insert mode.&lt;/p&gt;

&lt;p&gt;If you &lt;code&gt;chmod u+x bell&lt;/code&gt; and then just run &lt;code&gt;bell&lt;/code&gt; from the command line, you should hear a &amp;#8220;ding&amp;#8221; system bell.&lt;/p&gt;

&lt;p&gt;Now when running tests, I do:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;grails test-app ; bell&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Switch away, and then I can come back immediately when I hear the &amp;#8220;ding&amp;#8221;. The pre-emptive task switch makes me feel more productive anyway.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Grails Stacktraces</title>
   <link href="http://draconianoverlord.com/2009/02/16/grails-stacktraces.html"/>
   <updated>2009-02-16T00:00:00-08:00</updated>
   <id>http://draconianoverlord.com/2009/02/16/grails-stacktraces</id>
   <content type="html">&lt;h2&gt;Grails Stacktraces&lt;/h2&gt;
&lt;p&gt;One of the many joys of working in Grails is the stack traces.&lt;/p&gt;

&lt;p&gt;The first is 590 lines. The second is 597 lines. However, the second cheats and includes 59 lines of &amp;#8220;caused by&amp;#8221; stack traces. From a purity standpoint, the first is all just one stack, so is the current winner.&lt;/p&gt;

&lt;p&gt;The solution to each?&lt;/p&gt;

&lt;p&gt;Clean and restart.&lt;/p&gt;

&lt;p&gt;In that regard, Grails exceptions are nicer than Spring exceptions&amp;#8211;Spring exceptions don&amp;#8217;t go away after a clean/restart.&lt;/p&gt;

&lt;pre class='brush:plain'&gt;&lt;code&gt;[253826] mortbay.log Nested in org.springframework.beans.factory.access.BootstrapException: Error executing bootstraps; nested exception is org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.NullPointerException: Cannot invoke method count() on null object:
java.lang.NullPointerException: Cannot invoke method count() on null object
    at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:77)
    at org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:743)
    at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:720)
    at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:17)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:43)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
    at BootStrap$_populateBootstrapData_closure490.doCall(BootStrap.groovy:788)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.Closure.call(Closure.java:279)
    at org.codehaus.groovy.runtime.DefaultGroovyMethods.callClosureForMapEntry(DefaultGroovyMethods.java:1911)
    at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:1184)
    at org.codehaus.groovy.runtime.dgm$88.invoke(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:270)
    at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
    at BootStrap.populateBootstrapData(BootStrap.groovy:786)
    at BootStrap.this$2$populateBootstrapData(BootStrap.groovy)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1009)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:146)
    at BootStrap$_closure1.doCall(BootStrap.groovy:9)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.Closure.call(Closure.java:279)
    at org.codehaus.groovy.grails.commons.DefaultGrailsBootstrapClass.callInit(DefaultGrailsBootstrapClass.java:43)
    at org.codehaus.groovy.grails.web.context.GrailsConfigUtils.executeGrailsBootstraps(GrailsConfigUtils.java:64)
    at org.codehaus.groovy.grails.web.context.GrailsContextLoader.createWebApplicationContext(GrailsContextLoader.java:69)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
    at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:548)
    at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1234)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:460)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
    at org.mortbay.jetty.Server.doStart(Server.java:222)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:229)
    at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
    at org.codehaus.groovy.grails.web.container.JettyServer.startServer(JettyServer.groovy:146)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:266)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:51)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:150)
    at org.codehaus.groovy.grails.web.container.JettyServer.start(JettyServer.groovy:106)
    at grails.web.container.EmbeddableServer$start.call(Unknown Source)
    at _GrailsRun_groovy$_run_closure6_closure12.doCall(_GrailsRun_groovy:145)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:266)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:51)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:150)
    at _GrailsRun_groovy$_run_closure6_closure12.doCall(_GrailsRun_groovy)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.Closure.call(Closure.java:279)
    at groovy.lang.Closure.call(Closure.java:274)
    at groovy.lang.Closure$call.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:43)
    at groovy.lang.Closure$call.call(Unknown Source)
    at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:268)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.Closure.call(Closure.java:279)
    at groovy.lang.Script.invokeMethod(Script.java:87)
    at groovy.lang.MetaClassImpl.invokeMethodOnGroovyObject(MetaClassImpl.java:1119)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1023)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
    at _GrailsRun_groovy$_run_closure6.doCall(_GrailsRun_groovy:140)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.Closure.call(Closure.java:279)
    at groovy.lang.Script.invokeMethod(Script.java:87)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:72)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:150)
    at _GrailsRun_groovy.runInline(_GrailsRun_groovy:117)
    at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1009)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.DelegatingMetaClass.invokeMethod(DelegatingMetaClass.java:142)
    at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:127)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
    at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:63)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.DelegatingMetaClass.invokeMethod(DelegatingMetaClass.java:142)
    at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:127)
    at groovy.lang.Closure.call(Closure.java:279)
    at groovy.lang.Closure.call(Closure.java:292)
    at sun.reflect.GeneratedMethodAccessor67.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.DelegatingMetaClass.invokeMethod(DelegatingMetaClass.java:142)
    at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:127)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:39)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:43)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:54)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
    at org.codehaus.gant.GantBinding$_initializeGantBinding_closure4_closure8_closure9.doCall(GantBinding.groovy:152)
    at sun.reflect.GeneratedMethodAccessor66.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:266)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:51)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:150)
    at org.codehaus.gant.GantBinding$_initializeGantBinding_closure4_closure8_closure9.doCall(GantBinding.groovy)
    at sun.reflect.GeneratedMethodAccessor65.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.Closure.call(Closure.java:279)
    at groovy.lang.Closure.call(Closure.java:274)
    at groovy.lang.Closure$call.call(Unknown Source)
    at org.codehaus.gant.GantBinding.withTargetEvent(GantBinding.groovy:90)
    at org.codehaus.gant.GantBinding.this$4$withTargetEvent(GantBinding.groovy)
    at sun.reflect.GeneratedMethodAccessor61.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1009)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:718)
    at groovy.lang.GroovyObjectSupport.invokeMethod(GroovyObjectSupport.java:44)
    at groovy.lang.MetaClassImpl.invokeMethodOnGroovyObject(MetaClassImpl.java:1119)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1023)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:158)
    at org.codehaus.gant.GantBinding$_initializeGantBinding_closure4_closure8.doCall(GantBinding.groovy:152)
    at sun.reflect.GeneratedMethodAccessor60.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:266)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:51)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:150)
    at org.codehaus.gant.GantBinding$_initializeGantBinding_closure4_closure8.doCall(GantBinding.groovy)
    at sun.reflect.GeneratedMethodAccessor59.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.Closure.call(Closure.java:279)
    at groovy.lang.Script.invokeMethod(Script.java:87)
    at groovy.lang.MetaClassImpl.invokeMethodOnGroovyObject(MetaClassImpl.java:1119)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1023)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.DelegatingMetaClass.invokeMethod(DelegatingMetaClass.java:142)
    at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:127)
    at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:162)
    at groovy.lang.GroovyObjectSupport.invokeMethod(GroovyObjectSupport.java:44)
    at groovy.lang.MetaClassImpl.invokeMethodOnGroovyObject(MetaClassImpl.java:1119)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1023)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:142)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:146)
    at _GrailsRun_groovy$_run_closure8_closure14.doCall(_GrailsRun_groovy:235)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:266)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:51)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:142)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:150)
    at _GrailsRun_groovy$_run_closure8_closure14.doCall(_GrailsRun_groovy)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.Closure.call(Closure.java:279)
    at groovy.lang.Closure.call(Closure.java:274)
    at groovy.lang.Closure$call.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:43)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
    at _GrailsPackage_groovy$_run_closure7.doCall(_GrailsPackage_groovy:259)
    at sun.reflect.GeneratedMethodAccessor386.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.Closure.call(Closure.java:279)
    at groovy.lang.Script.invokeMethod(Script.java:87)
    at groovy.lang.MetaClassImpl.invokeMethodOnGroovyObject(MetaClassImpl.java:1119)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1023)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.DelegatingMetaClass.invokeMethod(DelegatingMetaClass.java:142)
    at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:127)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
    at _GrailsRun_groovy$_run_closure8.doCall(_GrailsRun_groovy:224)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.DelegatingMetaClass.invokeMethod(DelegatingMetaClass.java:142)
    at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:127)
    at groovy.lang.Closure.call(Closure.java:279)
    at groovy.lang.Closure.call(Closure.java:292)
    at sun.reflect.GeneratedMethodAccessor67.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.DelegatingMetaClass.invokeMethod(DelegatingMetaClass.java:142)
    at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:127)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:39)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:43)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:54)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
    at org.codehaus.gant.GantBinding$_initializeGantBinding_closure4_closure8_closure9.doCall(GantBinding.groovy:152)
    at sun.reflect.GeneratedMethodAccessor66.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:266)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:51)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:150)
    at org.codehaus.gant.GantBinding$_initializeGantBinding_closure4_closure8_closure9.doCall(GantBinding.groovy)
    at sun.reflect.GeneratedMethodAccessor65.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.Closure.call(Closure.java:279)
    at groovy.lang.Closure.call(Closure.java:274)
    at groovy.lang.Closure$call.call(Unknown Source)
    at org.codehaus.gant.GantBinding.withTargetEvent(GantBinding.groovy:90)
    at org.codehaus.gant.GantBinding.this$4$withTargetEvent(GantBinding.groovy)
    at sun.reflect.GeneratedMethodAccessor61.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1009)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:718)
    at groovy.lang.GroovyObjectSupport.invokeMethod(GroovyObjectSupport.java:44)
    at groovy.lang.MetaClassImpl.invokeMethodOnGroovyObject(MetaClassImpl.java:1119)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1023)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:158)
    at org.codehaus.gant.GantBinding$_initializeGantBinding_closure4_closure8.doCall(GantBinding.groovy:152)
    at sun.reflect.GeneratedMethodAccessor60.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:266)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:51)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:150)
    at org.codehaus.gant.GantBinding$_initializeGantBinding_closure4_closure8.doCall(GantBinding.groovy)
    at sun.reflect.GeneratedMethodAccessor59.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.Closure.call(Closure.java:279)
    at groovy.lang.Script.invokeMethod(Script.java:87)
    at groovy.lang.MetaClassImpl.invokeMethodOnGroovyObject(MetaClassImpl.java:1119)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1023)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.DelegatingMetaClass.invokeMethod(DelegatingMetaClass.java:142)
    at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:127)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:142)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:146)
    at RunApp$_run_closure1.doCall(RunApp.groovy:35)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.DelegatingMetaClass.invokeMethod(DelegatingMetaClass.java:142)
    at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:127)
    at groovy.lang.Closure.call(Closure.java:279)
    at groovy.lang.Closure.call(Closure.java:292)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.DelegatingMetaClass.invokeMethod(DelegatingMetaClass.java:142)
    at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:127)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:39)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:43)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
    at org.codehaus.gant.GantBinding$_initializeGantBinding_closure4_closure8_closure9.doCall(GantBinding.groovy:152)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:266)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:51)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:142)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:150)
    at org.codehaus.gant.GantBinding$_initializeGantBinding_closure4_closure8_closure9.doCall(GantBinding.groovy)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.Closure.call(Closure.java:279)
    at groovy.lang.Closure.call(Closure.java:274)
    at groovy.lang.Closure$call.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:43)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
    at org.codehaus.gant.GantBinding.withTargetEvent(GantBinding.groovy:90)
    at org.codehaus.gant.GantBinding.this$4$withTargetEvent(GantBinding.groovy)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1009)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:718)
    at groovy.lang.GroovyObjectSupport.invokeMethod(GroovyObjectSupport.java:44)
    at groovy.lang.MetaClassImpl.invokeMethodOnGroovyObject(MetaClassImpl.java:1119)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1023)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:142)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:158)
    at org.codehaus.gant.GantBinding$_initializeGantBinding_closure4_closure8.doCall(GantBinding.groovy:152)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:266)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:51)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:142)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:150)
    at org.codehaus.gant.GantBinding$_initializeGantBinding_closure4_closure8.doCall(GantBinding.groovy)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.Closure.call(Closure.java:279)
    at groovy.lang.Closure.call(Closure.java:274)
    at groovy.lang.Closure$call.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:43)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
    at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:324)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.Closure.call(Closure.java:279)
    at groovy.lang.Closure.call(Closure.java:292)
    at groovy.lang.Closure$call$0.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:43)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
    at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:266)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:51)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:142)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:150)
    at gant.Gant$_dispatch_closure6.doCall(Gant.groovy)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.Closure.call(Closure.java:279)
    at groovy.lang.Closure.call(Closure.java:274)
    at groovy.lang.Closure$call.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:43)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
    at gant.Gant.withBuildListeners(Gant.groovy:344)
    at gant.Gant.this$2$withBuildListeners(Gant.groovy)
    at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:142)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:150)
    at gant.Gant.dispatch(Gant.groovy:334)
    at gant.Gant.this$2$dispatch(Gant.groovy)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:720)
    at gant.Gant.invokeMethod(Gant.groovy)
    at groovy.lang.GroovyObject$invokeMethod.callCurrent(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:142)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
    at gant.Gant.processTargets(Gant.groovy:495)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:266)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:51)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:142)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
    at gant.Gant.processTargets(Gant.groovy:480)
    at org.codehaus.groovy.grails.cli.GrailsScriptRunner.callPluginOrGrailsScript(GrailsScriptRunner.java:397)
    at org.codehaus.groovy.grails.cli.GrailsScriptRunner.executeCommand(GrailsScriptRunner.java:270)
    at org.codehaus.groovy.grails.cli.GrailsScriptRunner.main(GrailsScriptRunner.java:106)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.grails.cli.support.GrailsStarter.rootLoader(GrailsStarter.java:157)
    at org.codehaus.groovy.grails.cli.support.GrailsStarter.main(GrailsStarter.java:182)&lt;/code&gt;&lt;/pre&gt;

&lt;pre class='brush:plain'&gt;&lt;code&gt;[17] mortbay.log Failed startup of context org.mortbay.jetty.webapp.WebAppContext@38859d{/proxibid,C:\svn\proxibid\juggernaut/web-app}
org.springframework.beans.factory.access.BootstrapException: Error executing bootstraps; nested exception is org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.NullPointerException
    at org.codehaus.groovy.grails.web.context.GrailsContextLoader.createWebApplicationContext(GrailsContextLoader.java:74)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
    at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:548)
    at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1234)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:460)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
    at org.mortbay.jetty.Server.doStart(Server.java:222)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:229)
    at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
    at org.codehaus.groovy.grails.web.container.JettyServer.startServer(JettyServer.groovy:146)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:266)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:51)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:150)
    at org.codehaus.groovy.grails.web.container.JettyServer.start(JettyServer.groovy:106)
    at grails.web.container.EmbeddableServer$start.call(Unknown Source)
    at RunApp$_run_closure6_closure12.doCall(RunApp:145)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:266)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:51)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:150)
    at RunApp$_run_closure6_closure12.doCall(RunApp)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.Closure.call(Closure.java:279)
    at groovy.lang.Closure.call(Closure.java:274)
    at groovy.lang.Closure$call.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:43)
    at groovy.lang.Closure$call.call(Unknown Source)
    at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:268)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.Closure.call(Closure.java:279)
    at groovy.lang.Script.invokeMethod(Script.java:87)
    at groovy.lang.MetaClassImpl.invokeMethodOnGroovyObject(MetaClassImpl.java:1119)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1023)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
    at RunApp$_run_closure6.doCall(RunApp:140)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.Closure.call(Closure.java:279)
    at groovy.lang.Script.invokeMethod(Script.java:87)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:72)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:150)
    at RunApp.runInline(RunApp:117)
    at RunApp.this$4$runInline(RunApp)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1009)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.DelegatingMetaClass.invokeMethod(DelegatingMetaClass.java:142)
    at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:127)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
    at RunApp$_run_closure1.doCall(RunApp:63)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.DelegatingMetaClass.invokeMethod(DelegatingMetaClass.java:142)
    at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:127)
    at groovy.lang.Closure.call(Closure.java:279)
    at groovy.lang.Closure.call(Closure.java:292)
    at sun.reflect.GeneratedMethodAccessor67.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.DelegatingMetaClass.invokeMethod(DelegatingMetaClass.java:142)
    at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:127)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:39)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:43)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:54)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
    at org.codehaus.gant.GantBinding$_initializeGantBinding_closure4_closure8_closure9.doCall(GantBinding.groovy:152)
    at sun.reflect.GeneratedMethodAccessor66.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:266)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:51)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:150)
    at org.codehaus.gant.GantBinding$_initializeGantBinding_closure4_closure8_closure9.doCall(GantBinding.groovy)
    at sun.reflect.GeneratedMethodAccessor65.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.Closure.call(Closure.java:279)
    at groovy.lang.Closure.call(Closure.java:274)
    at groovy.lang.Closure$call.call(Unknown Source)
    at org.codehaus.gant.GantBinding.withTargetEvent(GantBinding.groovy:90)
    at org.codehaus.gant.GantBinding.this$4$withTargetEvent(GantBinding.groovy)
    at sun.reflect.GeneratedMethodAccessor61.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1009)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:718)
    at groovy.lang.GroovyObjectSupport.invokeMethod(GroovyObjectSupport.java:44)
    at groovy.lang.MetaClassImpl.invokeMethodOnGroovyObject(MetaClassImpl.java:1119)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1023)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:158)
    at org.codehaus.gant.GantBinding$_initializeGantBinding_closure4_closure8.doCall(GantBinding.groovy:152)
    at sun.reflect.GeneratedMethodAccessor60.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:266)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:51)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:150)
    at org.codehaus.gant.GantBinding$_initializeGantBinding_closure4_closure8.doCall(GantBinding.groovy)
    at sun.reflect.GeneratedMethodAccessor59.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.Closure.call(Closure.java:279)
    at groovy.lang.Script.invokeMethod(Script.java:87)
    at groovy.lang.MetaClassImpl.invokeMethodOnGroovyObject(MetaClassImpl.java:1119)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1023)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.DelegatingMetaClass.invokeMethod(DelegatingMetaClass.java:142)
    at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:127)
    at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:162)
    at groovy.lang.GroovyObjectSupport.invokeMethod(GroovyObjectSupport.java:44)
    at groovy.lang.MetaClassImpl.invokeMethodOnGroovyObject(MetaClassImpl.java:1119)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1023)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:142)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:146)
    at RunApp$_run_closure8_closure14.doCall(RunApp:235)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:266)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:51)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:142)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:150)
    at RunApp$_run_closure8_closure14.doCall(RunApp)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.Closure.call(Closure.java:279)
    at groovy.lang.Closure.call(Closure.java:274)
    at groovy.lang.Closure$call.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:43)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
    at _GrailsPackage_groovy$_run_closure7.doCall(_GrailsPackage_groovy:259)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.Closure.call(Closure.java:279)
    at groovy.lang.Script.invokeMethod(Script.java:87)
    at groovy.lang.MetaClassImpl.invokeMethodOnGroovyObject(MetaClassImpl.java:1119)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1023)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.DelegatingMetaClass.invokeMethod(DelegatingMetaClass.java:142)
    at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:127)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
    at RunApp$_run_closure8.doCall(RunApp:224)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.DelegatingMetaClass.invokeMethod(DelegatingMetaClass.java:142)
    at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:127)
    at groovy.lang.Closure.call(Closure.java:279)
    at groovy.lang.Closure.call(Closure.java:292)
    at sun.reflect.GeneratedMethodAccessor67.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.DelegatingMetaClass.invokeMethod(DelegatingMetaClass.java:142)
    at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:127)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:39)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:43)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:54)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
    at org.codehaus.gant.GantBinding$_initializeGantBinding_closure4_closure8_closure9.doCall(GantBinding.groovy:152)
    at sun.reflect.GeneratedMethodAccessor66.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:266)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:51)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:150)
    at org.codehaus.gant.GantBinding$_initializeGantBinding_closure4_closure8_closure9.doCall(GantBinding.groovy)
    at sun.reflect.GeneratedMethodAccessor65.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.Closure.call(Closure.java:279)
    at groovy.lang.Closure.call(Closure.java:274)
    at groovy.lang.Closure$call.call(Unknown Source)
    at org.codehaus.gant.GantBinding.withTargetEvent(GantBinding.groovy:90)
    at org.codehaus.gant.GantBinding.this$4$withTargetEvent(GantBinding.groovy)
    at sun.reflect.GeneratedMethodAccessor61.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1009)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:718)
    at groovy.lang.GroovyObjectSupport.invokeMethod(GroovyObjectSupport.java:44)
    at groovy.lang.MetaClassImpl.invokeMethodOnGroovyObject(MetaClassImpl.java:1119)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1023)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:158)
    at org.codehaus.gant.GantBinding$_initializeGantBinding_closure4_closure8.doCall(GantBinding.groovy:152)
    at sun.reflect.GeneratedMethodAccessor60.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:266)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:51)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:150)
    at org.codehaus.gant.GantBinding$_initializeGantBinding_closure4_closure8.doCall(GantBinding.groovy)
    at sun.reflect.GeneratedMethodAccessor59.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.Closure.call(Closure.java:279)
    at groovy.lang.Script.invokeMethod(Script.java:87)
    at groovy.lang.MetaClassImpl.invokeMethodOnGroovyObject(MetaClassImpl.java:1119)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1023)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.DelegatingMetaClass.invokeMethod(DelegatingMetaClass.java:142)
    at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:127)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:142)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:146)
    at RunApp$_run_closure1.doCall(RunApp.groovy:35)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.DelegatingMetaClass.invokeMethod(DelegatingMetaClass.java:142)
    at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:127)
    at groovy.lang.Closure.call(Closure.java:279)
    at groovy.lang.Closure.call(Closure.java:292)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.DelegatingMetaClass.invokeMethod(DelegatingMetaClass.java:142)
    at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:127)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:39)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:43)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
    at org.codehaus.gant.GantBinding$_initializeGantBinding_closure4_closure8_closure9.doCall(GantBinding.groovy:152)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:266)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:51)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:142)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:150)
    at org.codehaus.gant.GantBinding$_initializeGantBinding_closure4_closure8_closure9.doCall(GantBinding.groovy)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.Closure.call(Closure.java:279)
    at groovy.lang.Closure.call(Closure.java:274)
    at groovy.lang.Closure$call.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:43)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
    at org.codehaus.gant.GantBinding.withTargetEvent(GantBinding.groovy:90)
    at org.codehaus.gant.GantBinding.this$4$withTargetEvent(GantBinding.groovy)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1009)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:718)
    at groovy.lang.GroovyObjectSupport.invokeMethod(GroovyObjectSupport.java:44)
    at groovy.lang.MetaClassImpl.invokeMethodOnGroovyObject(MetaClassImpl.java:1119)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1023)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:142)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:158)
    at org.codehaus.gant.GantBinding$_initializeGantBinding_closure4_closure8.doCall(GantBinding.groovy:152)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:266)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:51)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:142)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:150)
    at org.codehaus.gant.GantBinding$_initializeGantBinding_closure4_closure8.doCall(GantBinding.groovy)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.Closure.call(Closure.java:279)
    at groovy.lang.Closure.call(Closure.java:274)
    at groovy.lang.Closure$call.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:43)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
    at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:324)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.Closure.call(Closure.java:279)
    at groovy.lang.Closure.call(Closure.java:292)
    at groovy.lang.Closure$call$0.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:43)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
    at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:266)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:51)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:142)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:150)
    at gant.Gant$_dispatch_closure6.doCall(Gant.groovy)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.Closure.call(Closure.java:279)
    at groovy.lang.Closure.call(Closure.java:274)
    at groovy.lang.Closure$call.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:43)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
    at gant.Gant.withBuildListeners(Gant.groovy:344)
    at gant.Gant.this$2$withBuildListeners(Gant.groovy)
    at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:142)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:150)
    at gant.Gant.dispatch(Gant.groovy:334)
    at gant.Gant.this$2$dispatch(Gant.groovy)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:720)
    at gant.Gant.invokeMethod(Gant.groovy)
    at groovy.lang.GroovyObject$invokeMethod.callCurrent(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:142)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
    at gant.Gant.processTargets(Gant.groovy:495)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:266)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:51)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:142)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
    at gant.Gant.processTargets(Gant.groovy:480)
    at org.codehaus.groovy.grails.cli.GrailsScriptRunner.callPluginOrGrailsScript(GrailsScriptRunner.java:397)
    at org.codehaus.groovy.grails.cli.GrailsScriptRunner.executeCommand(GrailsScriptRunner.java:270)
    at org.codehaus.groovy.grails.cli.GrailsScriptRunner.main(GrailsScriptRunner.java:106)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.grails.cli.support.GrailsStarter.rootLoader(GrailsStarter.java:157)
    at org.codehaus.groovy.grails.cli.support.GrailsStarter.main(GrailsStarter.java:182)
Caused by: org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.NullPointerException
    at grails.web.container.EmbeddableServer$start.call(Unknown Source)
    at RunApp$_run_closure6_closure12.doCall(RunApp:145)
    at RunApp$_run_closure6_closure12.doCall(RunApp)
    at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:268)
    at RunApp$_run_closure6.doCall(RunApp:140)
    at RunApp.runInline(RunApp:117)
    at RunApp.this$4$runInline(RunApp)
    at RunApp$_run_closure1.doCall(RunApp:63)
    at RunApp$_run_closure8_closure14.doCall(RunApp:235)
    at RunApp$_run_closure8_closure14.doCall(RunApp)
    at _GrailsPackage_groovy$_run_closure7.doCall(_GrailsPackage_groovy:259)
    at RunApp$_run_closure8.doCall(RunApp:224)
    at RunApp$_run_closure1.doCall(RunApp.groovy:35)
    at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:324)
    at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334)
    at gant.Gant$_dispatch_closure6.doCall(Gant.groovy)
    at gant.Gant.withBuildListeners(Gant.groovy:344)
    at gant.Gant.this$2$withBuildListeners(Gant.groovy)
    at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
    at gant.Gant.dispatch(Gant.groovy:334)
    at gant.Gant.this$2$dispatch(Gant.groovy)
    at gant.Gant.invokeMethod(Gant.groovy)
    at gant.Gant.processTargets(Gant.groovy:495)
    at gant.Gant.processTargets(Gant.groovy:480)
Caused by: java.lang.NullPointerException
    at BootStrap$_populateBootstrapData_closure508.doCall(BootStrap.groovy:26)
    at BootStrap.populateBootstrapData(BootStrap.groovy:21)
    at BootStrap$_closure1.doCall(BootStrap.groovy:11)
    ... 24 more
[21] mortbay.log Nested in org.springframework.beans.factory.access.BootstrapException: Error executing bootstraps; nested exception is org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.NullPointerException:
java.lang.NullPointerException
    at BootStrap$_populateBootstrapData_closure508.doCall(BootStrap.groovy:26)
    at BootStrap.populateBootstrapData(BootStrap.groovy:21)
    at BootStrap$_closure1.doCall(BootStrap.groovy:11)
    at grails.web.container.EmbeddableServer$start.call(Unknown Source)
    at RunApp$_run_closure6_closure12.doCall(RunApp:145)
    at RunApp$_run_closure6_closure12.doCall(RunApp)
    at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:268)
    at RunApp$_run_closure6.doCall(RunApp:140)
    at RunApp.runInline(RunApp:117)
    at RunApp.this$4$runInline(RunApp)
    at RunApp$_run_closure1.doCall(RunApp:63)
    at RunApp$_run_closure8_closure14.doCall(RunApp:235)
    at RunApp$_run_closure8_closure14.doCall(RunApp)
    at _GrailsPackage_groovy$_run_closure7.doCall(_GrailsPackage_groovy:259)
    at RunApp$_run_closure8.doCall(RunApp:224)
    at RunApp$_run_closure1.doCall(RunApp.groovy:35)
    at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:324)
    at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334)
    at gant.Gant$_dispatch_closure6.doCall(Gant.groovy)
    at gant.Gant.withBuildListeners(Gant.groovy:344)
    at gant.Gant.this$2$withBuildListeners(Gant.groovy)
    at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
    at gant.Gant.dispatch(Gant.groovy:334)
    at gant.Gant.this$2$dispatch(Gant.groovy)
    at gant.Gant.invokeMethod(Gant.groovy)
    at gant.Gant.processTargets(Gant.groovy:495)
    at gant.Gant.processTargets(Gant.groovy:480)&lt;/code&gt;&lt;/pre&gt;</content>
 </entry>
 
 <entry>
   <title>Boojay is Promising</title>
   <link href="http://draconianoverlord.com/2009/02/06/boojay-is-promising.html"/>
   <updated>2009-02-06T00:00:00-08:00</updated>
   <id>http://draconianoverlord.com/2009/02/06/boojay-is-promising</id>
   <content type="html">&lt;h2&gt;Boojay is Promising&lt;/h2&gt;
&lt;p&gt;Rodrigo B. de Oliveira has a new &lt;a href='http://blogs.codehaus.org/people/bamboo/archives/001751_experience_boojay_with_monolipse.html'&gt;post&lt;/a&gt; up about his progress getting &lt;a href='http://boo.codehaus.org'&gt;boo&lt;/a&gt; running in Eclipse and compiling to the JVM. This is very cool stuff.&lt;/p&gt;

&lt;p&gt;Boo has both a wrist-friendly syntax and macro meta-programming abilities, but in a type-safe language without all the &amp;#8220;gee, what does this code do at runtime again?&amp;#8221; ambiguities of dynamic languages like Groovy and Ruby.&lt;/p&gt;

&lt;p&gt;Okay, yeah, boo can&amp;#8217;t do &lt;code&gt;method_missing&lt;/code&gt;, but I don&amp;#8217;t want that anyway. Closures, type inference, and macros? That&amp;#8217;s all the magic I want and need.&lt;/p&gt;

&lt;p&gt;If you watch the video in his post, it even shows a dual view of the &amp;#8220;regular&amp;#8221; macro/type inferred source code that you actually type, then you can press a shortcut and see a read-only view of the &amp;#8220;processed&amp;#8221; source code after it has been expanded by macros and had the types filled in. I.e. you can easily see exactly what the code you write is going to end up as after the magic is applied.&lt;/p&gt;

&lt;p&gt;Try doing that in the dynamic language of your choice.&lt;/p&gt;

&lt;p&gt;I tried to get Rodrigo&amp;#8217;s example working on my Windows box, and it seems to be really close, but I cannot get the Mono Eclipse plugin to find my local Mono runtime, so nothing is compiling right now. But I&amp;#8217;m not too worried&amp;#8211;it&amp;#8217;s not ready to go just yet, but the progress is very impressive.&lt;/p&gt;

&lt;p&gt;Boo has also impressed me with its longevity&amp;#8211;back in the early days, it seemed like a very cool .NET hobby language that would probably fade after a few releases. IIRC, it even had an edge on C# 1.0 for awhile. Then Microsoft blew everyone away with the C# 2.0 and 3.0 releases, but, contrary to Java, boo is steadily &lt;a href='http://docs.codehaus.org/display/BOO/2009/01/27/Boo+0.9+is+here!'&gt;catching up&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In my opinion, boojay is currently the best &amp;#8220;Java++&amp;#8221; contender. I can&amp;#8217;t wait for a few more releases to go by to see where it goes.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>JavaFX Decompiled</title>
   <link href="http://draconianoverlord.com/2009/01/18/javafx-decompiled.html"/>
   <updated>2009-01-18T00:00:00-08:00</updated>
   <id>http://draconianoverlord.com/2009/01/18/javafx-decompiled</id>
   <content type="html">&lt;h2&gt;JavaFX Decompiled&lt;/h2&gt;
&lt;p&gt;While lamenting the lack of BGGA closures in Java, I came across a &lt;a href='http://java.net/pub/pq/242'&gt;poll&lt;/a&gt; that had some interesting JavaFX comments from a guy named Bryan:&lt;/p&gt;
&lt;blockquote&gt;
    JavaFX Script is Java++ ... as general purpose as Java itself ... type inference ... closures ...

    The primary language on the JVM in the future will be JavaFX Script. New language features will go there. Java will not accept new features.
&lt;/blockquote&gt;
&lt;p&gt;Okay, my interest was piqued. Besides JavaFX being a UI toolkit, turns out JavaFX Script is a new programming language as well. Would Sun really choose an entirely different language to evolve Java? They&amp;#8217;ve done sillier things, I suppose, so, maybe?&lt;/p&gt;

&lt;p&gt;Looking through some tutorials, JavaFX seems like it might actually work&amp;#8211;it even has a crazy &lt;code&gt;bind&lt;/code&gt; keyword for data binding. Given my &lt;a href='http://github.com/stephenh/bindgen'&gt;bindgen&lt;/a&gt; hobby project, I was very interested to see how they implemented first-class data binding.&lt;/p&gt;

&lt;p&gt;Tutorials only go so far though, so I downloaded the JavaFX SDK, made sure I still had the very handy &lt;a href='http://www.kpdus.com/jad.html'&gt;Jad&lt;/a&gt; decompiler around, and thought I&amp;#8217;d see what was really going on.&lt;/p&gt;

&lt;p&gt;After a few tests, I ended up with &lt;code&gt;foo.fx&lt;/code&gt;:&lt;/p&gt;

&lt;pre class='brush:plain'&gt;&lt;code&gt;var num = 1;
var x = bind f(num);

println(&amp;quot;num={num}, x={x}&amp;quot;);

num = 3;
println(&amp;quot;num={num}, x={x}&amp;quot;);

function f(arg:Integer) {
    return arg + 1;
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Running &lt;code&gt;javafxc foo.fx&lt;/code&gt; to compile it and then &lt;code&gt;javafx foo&lt;/code&gt; to run it produces this output:&lt;/p&gt;

&lt;pre class='brush:plain'&gt;&lt;code&gt;num=1, x=2
num=3, x=4&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Okay, cool, the &lt;code&gt;f(num)&lt;/code&gt; function is being lazily bound to &lt;code&gt;x&lt;/code&gt;, such that &lt;code&gt;x&lt;/code&gt; changes with &lt;code&gt;num&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;How&amp;#8217;d they do that?&lt;/p&gt;

&lt;p&gt;Run &lt;code&gt;jad foo.class&lt;/code&gt; and we get:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;import com.sun.javafx.runtime.*;
import com.sun.javafx.runtime.location.*;
import com.sun.javafx.runtime.sequence.Sequence;
import javafx.lang.Builtins;

public class foo implements Intf, FXObject {
    public static final IntVariable $num = IntVariable.make();
    public static final IntVariable $x = IntVariable.make();

    public static Object javafx$run$(Sequence sequence) {
        $num.setAsInt(1);
        $x.bind(IntVariable.make(false, new IntBindingExpression() {
            private IntLocation arg$0;
            { arg$0 = foo.$num; }
            protected Location[] getStaticDependents() {
                return (new Location[] { arg$0 });
            }
            public int computeValue() {
                return foo.f(arg$0.getAsInt());
            }
        }, new Location[0]));
        Builtins.println(String.format(&amp;quot;num=%s, x=%s&amp;quot;, new Object[] {
            Integer.valueOf($num.getAsInt()), Integer.valueOf($x.getAsInt())
        }));
        $num.setAsInt(3);
        Builtins.println(String.format(&amp;quot;num=%s, x=%s&amp;quot;, new Object[] {
            Integer.valueOf($num.getAsInt()), Integer.valueOf($x.getAsInt())
        }));
        return null;
    }

    public static int f(int i) {
        return i + 1;
    }

    public void initialize$() {
        addTriggers$(this);
        userInit$(this);
        postInit$(this);
        InitHelper.finish(new AbstractVariable[0]);
    }

    public static void addTriggers$(Intf intf) {
    }

    public foo() {
        this(false);
        initialize$();
    }

    public foo(boolean flag) {
    }

    public static void userInit$(Intf intf) {
    }

    public static void postInit$(Intf intf) {
    }

    public static void main(String args[]) throws Throwable {
        Entry.start(foo, args);
    }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;A &lt;em&gt;lot&lt;/em&gt; of syntactic sugar is going on here.&lt;/p&gt;

&lt;p&gt;The biggest surprise is that variables in JavaFX are not variables in Java, but instead are wrapper objects, e.g. &lt;code&gt;IntVariable&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This allows the binding to work, where &lt;code&gt;x&lt;/code&gt; is not set to a value, but instead set to an anonymous inner class that holds the reference to &lt;code&gt;num&lt;/code&gt; for late-binding &lt;code&gt;x&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Coincidentally, this is similar to &lt;a href='http://github.com/stephenh/bindgen'&gt;bindgen&lt;/a&gt;&amp;#8217;s approach&amp;#8211;it also uses anonymous inner classes that are initialized with references to late-bind the evaluation.&lt;/p&gt;

&lt;p&gt;What is also surprising is all of the &lt;code&gt;addTriggers&lt;/code&gt;, &lt;code&gt;postInit&lt;/code&gt;, &lt;code&gt;userInit&lt;/code&gt;, etc. in the output.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m not sure what to make of this. This is where I start doubting JavaFX Script as the next general purpose language.&lt;/p&gt;

&lt;p&gt;This is a bit hypocritical of me&amp;#8211;I pine for the &amp;#8220;good&amp;#8221; magic of extension methods, local variable type inference, and BGGA closures, but I start to cringe and label it &amp;#8220;bad&amp;#8221; magic when &lt;code&gt;int&lt;/code&gt; is now an &lt;code&gt;IntVariable&lt;/code&gt; and my class has a bunch of cruft it in. It seems like meta-level semantics that I was not expecting.&lt;/p&gt;

&lt;p&gt;I trust these meta-level semantics are perfect for leveraging JavaFX Script in the JavaFX UI framework, but to me it disqualifies JavaFX as a &amp;#8220;Java++&amp;#8221; contender.&lt;/p&gt;

&lt;p&gt;It seems like all of the &amp;#8220;Java++&amp;#8221; contenders (JavaFX, Groovy, and Scala) add their own meta-level semantics on top of Java. They need the meta-level to do the dynamic, trait, etc., cool features, but, to me, it just adds complexity and a leaky abstraction that I&amp;#8217;d rather not deal with.&lt;/p&gt;

&lt;p&gt;Enterprise software is hard enough and bad enough as it is&amp;#8211;I can&amp;#8217;t imagine the average programmer also having to deal with, say, Scala&amp;#8217;s case classes, or traits, or whatever other nifty tricks the current &amp;#8220;Java++&amp;#8221; contenders layer on top of Java.&lt;/p&gt;

&lt;p&gt;The simplicity of Java is a real virtue. I assert that any language that adds its own &amp;#8220;meta-level semantics&amp;#8221; on top of Java is not going to replace it.&lt;/p&gt;

&lt;p&gt;My current rule of thumb: if you can decompile a &amp;#8220;Java++&amp;#8221; contender&amp;#8217;s code into the regular Java syntax, and have it look pretty darn close to what you&amp;#8217;d type out by hand, then you&amp;#8217;ve found your true &amp;#8220;Java++&amp;#8221; language.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>War-less Development with Jetty</title>
   <link href="http://draconianoverlord.com/2009/01/10/war-less-dev-with-jetty.html"/>
   <updated>2009-01-10T00:00:00-08:00</updated>
   <id>http://draconianoverlord.com/2009/01/10/war-less-dev-with-jetty</id>
   <content type="html">&lt;h2&gt;War-less Development with Jetty&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; see the &lt;a href='http://github.com/stephenh/jtty'&gt;jtty&lt;/a&gt; project for a single jar based on this approach that contains both the Jetty dependencies and a generic bootstrap class.&lt;/p&gt;

&lt;p&gt;Reviewing my posts, most of them are negative rants, so I figured I should contribute something positive every now and then.&lt;/p&gt;

&lt;p&gt;One of my favorite hacks for Java web development is using Jetty for a war-less development environment to get automatic updating of classes/JSPs while debugging your app. Although limited by the usual JVM limitation of no hot reloading class declaration changes, I&amp;#8217;ve nonetheless found this approach to be quick and useful.&lt;/p&gt;

&lt;p&gt;Perhaps lots of people use this type of approach already, but I haven&amp;#8217;t come across it much.&lt;/p&gt;

&lt;p&gt;The idea is to be able to start Jetty as your server against your web project and not have to go through a war step&amp;#8211;instead, Jetty will pick up the &lt;code&gt;web.xml&lt;/code&gt;, JSPs, etc. directly from your source folder, like an exploded war deployment.&lt;/p&gt;

&lt;p&gt;This assumes you have a war-like directory structure of:&lt;/p&gt;

&lt;pre class='brush:plain'&gt;&lt;code&gt;yourapp
  - WebContent
    - ...content...
    - WEB-INF
      - web.xml&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If for whatever reason your project&amp;#8217;s source tree doesn&amp;#8217;t match this, or needs several build steps to generate/massage a web.xml file, then YMMV.&lt;/p&gt;

&lt;p&gt;Instead of a standard jetty script, I typically create a &lt;code&gt;Jetty&lt;/code&gt; wrapper class directly in the project (either &lt;code&gt;src/main&lt;/code&gt; or &lt;code&gt;src/bootstrap&lt;/code&gt;) that resembles:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public class Jetty {
    private static final Server SERVER = new Server();

    public static void main(String[] args) {
        String webapp = &amp;quot;./WebContent&amp;quot;;
        if (args.length &amp;gt; 0) {
            webapp = args[0];
        }

        WebAppContext app = new WebAppContext();
        app.setContextPath(&amp;quot;/yourapp&amp;quot;);
        app.setWar(webapp);
        // Avoid the taglib configuration because its a PITA if you don&amp;#39;t have a net connection
        app.setConfigurationClasses(new String[] { WebInfConfiguration.class.getName(), WebXmlConfiguration.class.getName() });
        app.setParentLoaderPriority(true);

        // We explicitly use the SocketConnector because the SelectChannelConnector locks files
        Connector connector = new SocketConnector();
        connector.setPort(Integer.parseInt(System.getProperty(&amp;quot;jetty.port&amp;quot;, &amp;quot;8080&amp;quot;)));
        connector.setMaxIdleTime(60000);

        Jetty.SERVER.setConnectors(new Connector[] { connector });
        Jetty.SERVER.setHandlers(new Handler[] { app });
        Jetty.SERVER.setAttribute(&amp;quot;org.mortbay.jetty.Request.maxFormContentSize&amp;quot;, 0);
        Jetty.SERVER.setStopAtShutdown(true);

        try {
            Jetty.SERVER.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And run this Java class from Eclipse with a &lt;code&gt;Jetty.launch&lt;/code&gt; target. You&amp;#8217;ll need &lt;code&gt;jetty-6.X.jar&lt;/code&gt; and &lt;code&gt;jetty-util-6.X.jar&lt;/code&gt; on your classpath&amp;#8211;either in &lt;code&gt;lib/main&lt;/code&gt; or a &lt;code&gt;lib/bootstrap&lt;/code&gt; as you won&amp;#8217;t need the Jetty jars ending up in your production war.&lt;/p&gt;

&lt;p&gt;Jetty will start up, see your &lt;code&gt;WebContent/WEB-INF/web.xml&lt;/code&gt;, and fire up your servlet classes.&lt;/p&gt;

&lt;p&gt;Now the interesting part is how it finds the servlet classes&amp;#8211;typically there is the &lt;code&gt;WEB-INF/lib&lt;/code&gt;, &lt;code&gt;WEB-INF/classes&lt;/code&gt;, etc., which works great for production, but you&amp;#8217;re not going to have those without going through a war step.&lt;/p&gt;

&lt;p&gt;But since Eclipse (or IDEA or whatever) is running the &lt;code&gt;Jetty&lt;/code&gt; class as a Java Application, it will put all of your project&amp;#8217;s classes and libraries on the application loader classpath, much like it would if it were running your JUnit tests.&lt;/p&gt;

&lt;p&gt;So, we&amp;#8217;re cheating a bit, as Jetty will get your classes from the same application classloader it finds its own classes on instead of the usual &lt;code&gt;WebappClassloader&lt;/code&gt;, but in practice I&amp;#8217;ve found this is not a big deal.&lt;/p&gt;

&lt;p&gt;Plus, it allows hot code reloading and editing of JSP files (if you have to use them) and seeing the changes automatically in your app without a war/restart delay.&lt;/p&gt;

&lt;p&gt;Now if only Sun would fix hot code replacement to not blow up when you change classes. I know nothing about JVM internals, so I&amp;#8217;ll trust them that this is hard, but, please, pretty please, even if enabled with a debug-only, hurts-perf-25%, never-use-this-in-production flag?&lt;/p&gt;

&lt;p&gt;Also, if you need JNDI resources, you have a few alternatives. One app I worked on did not rely on the container for anything (it used its own c3p0 pool), so this was no problem. Another app did want the DataSource in JNDI, so we wrote a &lt;code&gt;FakeJndiFactory&lt;/code&gt; that returned a &lt;code&gt;FakeContext&lt;/code&gt;&amp;#8211;it&amp;#8217;s kind of stupid, &lt;code&gt;FakeContext&lt;/code&gt; has a 10-15 methods in it, but only &lt;code&gt;lookup&lt;/code&gt; ever seems to be called, so we left most of &lt;code&gt;FakeContext&lt;/code&gt;&amp;#8217;s methods as no-op and had &lt;code&gt;lookup&lt;/code&gt; use a static &lt;code&gt;HashMap&lt;/code&gt;. Then the project-specific Jetty class just did:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;	System.setProperty(&amp;quot;java.naming.factory.initial&amp;quot;, FakeJndiFactory.class.getName());
	FakeJndiFactory.properties.put(&amp;quot;java:comp/env/jdbc/yourapp&amp;quot;, FakeDataSource.getDataSource());&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Where &lt;code&gt;FakeDataSource&lt;/code&gt; was a c3p0-backed data source. If you need more container resources than a DataSource, you&amp;#8217;ll have to invent your own ways to mount them in Jetty or else just stay in the container.&lt;/p&gt;

&lt;p&gt;The ability to customize the &lt;code&gt;Jetty&lt;/code&gt; wrapper class as needed for your project is one of the strengths of this approach, I think. For example, it wouldn&amp;#8217;t make much sense for me to make a &lt;code&gt;github&lt;/code&gt; project out of this, because I think everyone is best off copy/pasting the 20 or so lines of code and just customizing them as needed to their project.&lt;/p&gt;

&lt;p&gt;As alternatives to this war-less Jetty approach, I have seen a few cool reloading hacks like Tapestry 5 live class reloading and JavaRebel&amp;#8217;s ZeroTurnaround. They both seem a bit tricky, though I haven&amp;#8217;t investigated them as much as I should.&lt;/p&gt;

&lt;p&gt;So far, this low tech approach has worked very well on our projects. I hope others like it as well.&lt;/p&gt;

&lt;p&gt;Let me know if you have other cool, avoid-server-restart tips.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>NamedQuery Proposal</title>
   <link href="http://draconianoverlord.com/2009/01/06/namedquery-proposal.html"/>
   <updated>2009-01-06T00:00:00-08:00</updated>
   <id>http://draconianoverlord.com/2009/01/06/namedquery-proposal</id>
   <content type="html">&lt;h2&gt;NamedQuery Proposal&lt;/h2&gt;
&lt;p&gt;Recently I &lt;a href='/2008/12/19/namedquery-considered-stupid'&gt;ranted&lt;/a&gt; about EJB3 &lt;code&gt;@NamedQuery&lt;/code&gt; annotations as being a bad use of annotations.&lt;/p&gt;

&lt;p&gt;Turns out I was mistaken about the lack of pros&amp;#8211;startup-time validation of queries seems like an admirable goal.&lt;/p&gt;

&lt;p&gt;However, I would propose a different implementation: instead of the &amp;#8220;name&amp;#8221; part of the query being in an non-referrable annotation, the annotation should be used solely as a marker on an otherwise pure Java construct. For example:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;@Sql
private static final String FIND_FOO = &amp;quot;select * from foo ...&amp;quot;;

public List&amp;amp;lt;Foo&amp;amp;gt; findFoo() {
    Query q = em.createQuery(FIND_FOO);
    q.setParameter(...);
    return q.getResultList();
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This would alleviate my concerns about type-safety and SQL encapsulation, but still allow the &lt;code&gt;EntityManager&lt;/code&gt; to find all of the annotated queries on startup for validation.&lt;/p&gt;

&lt;p&gt;Until my proposal makes it into EJB4 (haha), I also came across &lt;a href='http://freddy33.blogspot.com/2007/07/jpa-namedqueries-and-jdbc-40.html?showComment=1203615720000#c9040118016780285760'&gt;this comment&lt;/a&gt;, which seems like an acceptable, though verbose, compromise with the current annotation.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Moving to GitHub Pages</title>
   <link href="http://draconianoverlord.com/2008/12/20/moving-to-github-pages.html"/>
   <updated>2008-12-20T00:00:00-08:00</updated>
   <id>http://draconianoverlord.com/2008/12/20/moving-to-github-pages</id>
   <content type="html">&lt;h2&gt;Moving to GitHub Pages&lt;/h2&gt;
&lt;p&gt;WordPress sucks for including code examples. And bulleted lists. And authoring in Opera. So, I&amp;#8217;m going with a GitHub page based on:&lt;/p&gt;

&lt;p&gt;http://github.com/mojombo/mojombo.github.com/tree/master&lt;/p&gt;

&lt;p&gt;It&amp;#8217;s cool stuff. No ability to comment, but I don&amp;#8217;t get a lot of those anyway. Just email me instead.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>NamedQuery Considered Stupid</title>
   <link href="http://draconianoverlord.com/2008/12/19/namedquery-considered-stupid.html"/>
   <updated>2008-12-19T00:00:00-08:00</updated>
   <id>http://draconianoverlord.com/2008/12/19/namedquery-considered-stupid</id>
   <content type="html">&lt;h2&gt;NamedQuery Considered Stupid&lt;/h2&gt;
&lt;p&gt;I was recently exposed to JPA&amp;#8217;s NamedQuery annotation. I cannot imagine a more useless way to store your queries.&lt;/p&gt;

&lt;p&gt;(Well&amp;#8230;okay, it&amp;#8217;s not XML, but still&amp;#8230;)&lt;/p&gt;

&lt;p&gt;A few examples from Google show the basic syntax:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;@Entity
@NamedQuery(
    name=&amp;quot;findAllEmployeesByFirstName&amp;quot;,
    queryString=&amp;quot;SELECT OBJECT(e) FROM Employee e WHERE e.firstName = :firstName&amp;quot;)
public class Employee {
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then somewhere else, you can do:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;Query queryEmployeesByFirstName = em.createNamedQuery(&amp;quot;findAllEmployeesByFirstName&amp;quot;);
queryEmployeeByFirstName.setParameter(&amp;quot;firstName&amp;quot;, &amp;quot;John&amp;quot;);
Collection employees = queryEmployessByFirstName.getResultList();&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;(I&amp;#8217;m using the &lt;a href='http://download.oracle.com/docs/cd/B32110_01/web.1013/b28221/ent30qry001.htm'&gt;first google hit&lt;/a&gt; for &amp;#8220;JPA @NamedQuery&amp;#8221; for the examples.)&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m confused about the benefits of this annotation-based approach.&lt;/p&gt;

&lt;p&gt;If pulling queries out of methods is a must, I would opt for a static final String. This would get you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Compile time enforcement of the &lt;code&gt;findAllEmployeesByFirstName&lt;/code&gt; variable&lt;/li&gt;

&lt;li&gt;Ctrl-Shift-G find references in Eclipse&lt;/li&gt;

&lt;li&gt;Ability to add a &lt;code&gt;private&lt;/code&gt; scope to limit scope of the string&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All of these, to me, are huge pros.&lt;/p&gt;

&lt;p&gt;Instead, with the annotation, it&amp;#8217;s not compile-type checked, you can&amp;#8217;t easily find its references, and the &amp;#8220;somewhere else&amp;#8221; that calls &lt;code&gt;createNamedQuery&lt;/code&gt; could be anywhere in your codebase that has access to the EntityManager. Chaos.&lt;/p&gt;

&lt;p&gt;The only benefit I can guess about this approach is that you&amp;#8217;d get to reuse the &lt;code&gt;findAllEmployeesByFirstName&lt;/code&gt; in multiple places without retyping the SQL query. But I fail to see how this is even worth accomplishing&amp;#8211;my personal preference is to isolate the query in its own method and then just have multiple people call the method:&lt;/p&gt;

&lt;pre class='brush:java'&gt;&lt;code&gt;public Collection findAllEmployeesByFirstName(String firstName) {
    Query queryEmployeesByFirstName = em.createQuery(
        &amp;quot;SELECT OBJECT(e) FROM Employee e WHERE e.firstName = :firstName&amp;quot;);
    queryEmployeeByFirstName.setParameter(&amp;quot;firstName&amp;quot;, &amp;quot;John&amp;quot;);
    return queryEmployessByFirstName.getResultList();
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And there you go, reuse and encapsulation all in one go, and all Plain Old Java.&lt;/p&gt;

&lt;p&gt;But, alas, JPA and NamedQueries are a standard, and so countless Java programmers will think they&amp;#8217;re following best practice by just doing what the standards/examples/books say they should instead of stopping to think critically about it.&lt;/p&gt;

&lt;p&gt;(Sun, if you&amp;#8217;re reading this, can you please work on something more constructive than JPA&amp;#8230;like catching Java up to C#? I don&amp;#8217;t even need LINQ&amp;#8230;just lambdas and static extension methods, that&amp;#8217;s all I ask.)&lt;/p&gt;

&lt;p&gt;To me this is just yet another example of annotations being abused as a non-XML configuration panacea where pure Java constructs would work just fine.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; Turns out I&amp;#8217;m uneducated, named queries can be on-startup verified against the database&amp;#8211;cool, but that&amp;#8217;s &lt;a href='/2009/01/06/namedquery-proposal.html'&gt;still wrong&lt;/a&gt;.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>WEP sucks</title>
   <link href="http://draconianoverlord.com/2008/11/26/wep-sucks.html"/>
   <updated>2008-11-26T00:00:00-08:00</updated>
   <id>http://draconianoverlord.com/2008/11/26/wep-sucks</id>
   <content type="html">&lt;h2&gt;WEP sucks&lt;/h2&gt;
&lt;p&gt;All due to my own stupidity, but WEP led to several hours of frustration today connecting various devices to a Qwest M1000/W1000 modem/gateway:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;64-bit hex keys make it all too easy to transpose digits&amp;#8211;I would have noticed a transposed passwrod a lot sooner.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;While typing in the WEP key, I mistakenly thought this constituted a &amp;#8220;shared key&amp;#8221; and selected as such from the Authorization Type menu. Turns out, no, the correct Authorization Type is &amp;#8220;Open System&amp;#8221;. &amp;#8220;Open System&amp;#8221; even though I&amp;#8217;m using a key? Hm. Okay.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That had me stuck for quite awhile until I hit the &amp;#8220;flip random settings until it works&amp;#8221; stage.&lt;/p&gt;

&lt;p&gt;Especially so because I was configuring a PhotoVu that requires 2 reboots for every settings change. 1st reboot is with a CAT5 plugged into the router to change the settings via its web admin interface, 2nd reboot is without the CAT5 to kick it into wireless mode and see what happens. When it doesn&amp;#8217;t work, repeat. The PhotoVu is slick, but a &amp;#8220;test wireless connection&amp;#8221; button would be very, very helpful.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>More Evil Than Spring</title>
   <link href="http://draconianoverlord.com/2008/11/21/more-evil-than-spring.html"/>
   <updated>2008-11-21T00:00:00-08:00</updated>
   <id>http://draconianoverlord.com/2008/11/21/more-evil-than-spring</id>
   <content type="html">&lt;h2&gt;More Evil Than Spring&lt;/h2&gt;
&lt;p&gt;As if Spring does not give us enough interfaces: &lt;a href='http://www.qi4j.org'&gt;Qi4j&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;And one of its core principles: &amp;#8220;Classes are dead, long live interfaces&amp;#8221;.&lt;/p&gt;

&lt;p&gt;Not this again.&lt;/p&gt;

&lt;p&gt;Perhaps the author can, as I would hope Spring&amp;#8217;s authors can as well, build supremely elegant systems with their tools.&lt;/p&gt;

&lt;p&gt;But for the rest of us, it means yet more codebases with tens and tens of interfaces, all of them having only 1 implementation, all in the name of future flexibility/injection/proxy/something magic.&lt;/p&gt;

&lt;p&gt;You never know when our &lt;code&gt;Employee&lt;/code&gt; class is going to need to mixin some &lt;code&gt;Claim&lt;/code&gt; functionality, so we better just support it now. After we go 1.0 and are in production, we will only be allowed to re-organize mixins, not, you know, just change the model and code as appropriate.&lt;/p&gt;

&lt;p&gt;Rather than throwing a bunch of interfaces around up front, I propose we wait until the reuse/proxy/whatever scenario actually happens, and then we&amp;#8217;ll deal with it. And when it doesn&amp;#8217;t 90% of the time, we all win.&lt;/p&gt;

&lt;p&gt;That being said, Qi4j looks technically spiffy. And I&amp;#8217;m sure the author makes very judicious use of interfaces. I just don&amp;#8217;t look forward to working on any Qi4j codebase that isn&amp;#8217;t written by him.&lt;/p&gt;</content>
 </entry>
 
 
</feed>

