<?xml version="1.0" encoding="utf-8"?>



<feed version="0.3" xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="en">
<title>Carbon Five Community</title>
<link rel="alternate" type="text/html" href="http://www.carbonfive.com/community/" />
<modified>2008-05-05T23:30:09Z</modified>
<tagline>Carbon Five Community Weblog for sharing our thoughts, software and discoveries.</tagline>
<id>tag:www.carbonfive.com,2008:/community//1</id>
<generator url="http://www.movabletype.org/" version="3.33">Movable Type</generator>
<copyright>Copyright (c) 2008, Christian Nelson</copyright>
<entry>
<title>Multithreaded Testing</title>
<link rel="alternate" type="text/html" href="http://www.carbonfive.com/community/archives/2008/05/multithreaded_t.html" />
<modified>2008-05-05T23:30:09Z</modified>
<issued>2008-05-05T23:06:42Z</issued>
<id>tag:www.carbonfive.com,2008:/community//1.29</id>
<created>2008-05-05T23:06:42Z</created>
<summary type="text/plain">Every now and then you&apos;ll work on something that needs to handle requests from multiple concurrent threads in a special way. I say &quot;special way&quot; because in a web application, everything needs to handle being executed concurrently and there are...</summary>
<author>
<name>Christian Nelson</name>

<email>christian@carbonfive.com</email>
</author>
<dc:subject>Java</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.carbonfive.com/community/">
<![CDATA[<p>Every now and then you'll work on something that needs to handle requests from multiple concurrent threads in a special way.  I say "special way" because in a web application, <i>everything</i> needs to handle being executed concurrently and there are a slew of techniques used to handle this (prototypes, thread locals, stateless services, etc).  Here's an example of what I mean by "special"...</p>

<p>On my current project, we have a queue of articles that need human-user attention.  Each article must be doled out to only one user and there are multiple instances of the web application servicing requests in the cluster.  We can't rely on Java synchronization because it only works within the JVM instance, not across instances.</p>

<p>The simplified version of the service interface we're working on looks like this:</p>

<pre><span class="category1">public</span> <span class="category1">interface</span> ArticleService {
 
     Article findNextArticleForModeration();
 
}</pre>


<p>What makes this interesting is that we must ensure that the service doesn't hand out the same Article to more than one user.  This is impossible to assert using a single thread.  We've all been told that multiple threads and automated testing don't mix.  It's generally true and should be avoided if at all possible, but in some cases it's the only way we can truly assert specific behavior.  I've found a pretty simple way to do this type of testing in a reliable, consistent, and non-disruptive manner.  Despite the fact that the technique leverages Java 1.5 built-in concurrency utilities, most of the engineers who have seen it are surprised and weren't aware that such testing was so easy to implement.</p>

<p>Given the above service interface, here's a test that will assert that no single article is given out to more than one invoker of the method findNextArticleForModeration().  The scenario we're simulating is 10 users feverishly moderating a queue of 250 articles as quickly as possible.</p>

<pre><span class="category1">public</span> <span class="category1">void</span> findNextArticleForModerationStressTest() <span class="category1">throws</span> <span class="category2">Exception</span>
{
     <span class="category1">final</span> <span class="category1">int</span> ARTICLE_COUNT = 250;
     <span class="category1">final</span> <span class="category1">int</span> THREAD_COUNT = 10;
 
     <span class="linecomment">// Create test data and callable tasks</span>
     <span class="linecomment">//</span>
     Set&lt;Article&gt; testArticles = <span class="category1">new</span> HashSet&lt;Article&gt;();
 
     Collection&lt;Callable&lt;Article&gt;&gt; tasks = <span class="category1">new</span> ArrayList&lt;Callable&lt;Article&gt;&gt;();
     <span class="category1">for</span> (<span class="category1">int</span> i = 0; i &lt; ARTICLE_COUNT; i++)
     {
          <span class="linecomment">// Test data</span>
          testArticles.add(<span class="category1">new</span> Article());
  
          <span class="linecomment">// Tasks - each task makes exactly one service invocation.</span>
          tasks.add(<span class="category1">new</span> Callable&lt;Article&gt;()
          {
               <span class="category1">public</span> Article call() <span class="category1">throws</span> <span class="category2">Exception</span>
               {
                    <span class="category1">return</span> articleService.findNextArticleForModeration();
                }
           });
      }
     articleService.createArticles(testArticles);
 
     <span class="linecomment">// Execute tasks</span>
     <span class="linecomment">//</span>
     ExecutorService executorService = Executors.newFixedThreadPool(THREAD_COUNT);
     <span class="linecomment">// invokeAll() blocks until all tasks have run...</span>
     <span class="category2">List</span>&lt;Future&lt;Article&gt;&gt; futures = executorService.invokeAll(tasks);    
     assertThat(futures.size(), is(ARTICLE_COUNT));
 
     <span class="linecomment">// Assertions</span>
     <span class="linecomment">//</span>
     Set&lt;<span class="category2">Long</span>&gt; articleIds = <span class="category1">new</span> HashSet&lt;<span class="category2">Long</span>&gt;(ARTICLE_COUNT);
     <span class="category1">for</span> (Future&lt;Article&gt; future : futures)
     {
          <span class="linecomment">// get() will throw an exception if an exception was thrown by the service.</span>
          Article article = future.get();
          <span class="linecomment">// Did we get an article?</span>
          assertThat(article, not(nullValue()));
          <span class="linecomment">// Did the service lock the article before returning?</span>
          assertThat(article.isLocked(), is(<span class="category1">true</span>));
          <span class="linecomment">// Is the article id unique (see Set.add() javadoc)?</span>
          assertThat(articleIds.add(article.getId()), is(<span class="category1">true</span>));
      }
     <span class="linecomment">// Did we get the right number of article ids?</span>
     assertThat(articleIds.size(), is(ARTICLE_COUNT));
}</pre>


<p>The test starts off by creating 250 test articles to be moderated.  It also creates 250 'tasks', each designed to make a single service invocation of findNextArticleForModeration().  The real magic happens in <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/Executors.html#newFixedThreadPool(int)">Executors.newFixedThreadPool()</a> and <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ExecutorService.html#invokeAll(java.util.Collection)">executorService.invokeAll()</a>.  The first creates a new <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ExecutorService.html">ExecutorService</a> backed by a thread pool of the specified size.  This is a generic ExecutorService that is designed to churn through tasks using all of the threads in the pool.  invokeAll blocks until every task has finished executing.  In this test, 10 threads will rip through 250 tasks, each making a single call to our service and capturing the result of that call.  Each task execution results in a <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/Future.html">Future</a>, which is a handle to the results of the task (and more).</p>

<p>Iterating over each resulting future, we make several assertions.  The most important one is the last, where we assert that every task is given a unique Article.  Thanks to the natural semantics of Set, this is easy to do in an elegant way.  Another useful, though unexpected, feature is that if an exception occurs during the task execution, an <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ExecutionException.html">ExecutionException</a> will be thrown when <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/Future.html#get()">get()</a> is called on the corresponding Future.  If our service fails for some reason, the test will fail because no exceptions are expected.</p>

<p>This technique makes simulating a multi-threaded environment in a test easy and readable.  It's important to only use this technique when it's really necessary.  The resulting test is more of an integration test than a unit test, and its run time is an order of magnitude or more than a unit test, so overuse of the technique will artificially inflate the time it takes to runs the tests.  After I've finished working on the component under test, I will reduce the test-data size and thread count to a level that the test still provides value, but is no longer a stress test (e.g. 10 articles and 2 threads).  The next time the component is being worked on, the developer can crank up the values and run the tests to be confident that the behavior isn't broken.</p>

<p>The complete source for a working example of this technique is available <a href="http://svn.carbonfive.com/public/christian/multi-threaded-testing/trunk">here</a>.  You'll need Maven (or IntelliJ IDEA 7.x) to build and run the test.  By default, the tests run against an in-memory H2Database instance, but if you look at application.properties you'll see configurations for PostgreSQL and MySQL as well.</p>

<p>Happy testing!</p>]]>


<!--$MTEntryMore encode_xml="1"$-->
</content>
</entry>
<entry>
<title>Configuring applications with Spring</title>
<link rel="alternate" type="text/html" href="http://www.carbonfive.com/community/archives/2008/04/configuring_app.html" />
<modified>2008-04-25T19:19:15Z</modified>
<issued>2008-04-25T18:57:31Z</issued>
<id>tag:www.carbonfive.com,2008:/community//1.28</id>
<created>2008-04-25T18:57:31Z</created>
<summary type="text/plain">If you&apos;ve used Spring before, you&apos;ve almost definitely used a PropertyPlaceholderConfigurer to inject settings from external sources -- most likely properties files -- into your application context. The most common use cases include JDBC and Hibernate settings, but it&apos;s not...</summary>
<author>
<name>Christian Nelson</name>

<email>christian@carbonfive.com</email>
</author>
<dc:subject>Java</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.carbonfive.com/community/">
<![CDATA[<p>If you've used Spring before, you've almost definitely used a PropertyPlaceholderConfigurer to inject settings from external sources -- most likely properties files -- into your application context.  The most common use cases include JDBC and Hibernate settings, but it's not that uncommon to also configure Lucene index, temp file, or image cache directories as well.  The simplest case looks something like this:</p>

<pre>&lt;bean <span class="category1">class</span>="<span class="quote">org.springframework.beans.factory.config.PropertyPlaceholderConfigurer</span>"&gt;
    &lt;property name="<span class="quote">location</span>" value="<span class="quote">classpath:application.properties</span>"/&gt;
&lt;/bean&gt;

&lt;!-- A sample bean that needs some settings. --&gt;
&lt;bean id="<span class="quote">dataSource</span>" <span class="category1">class</span>="<span class="quote">org.springframework.jdbc.datasource.DriverManagerDataSource</span>"&gt;
    &lt;property name="<span class="quote">driverClassName</span>" value="<span class="quote">${jdbc.driver}</span>"/&gt;
    &lt;property name="<span class="quote">url</span>" value="<span class="quote">${jdbc.url}</span>"/&gt;
    &lt;property name="<span class="quote">username</span>" value="<span class="quote">${jdbc.username}</span>"/&gt;
    &lt;property name="<span class="quote">password</span>" value="<span class="quote">${jdbc.password}</span>"/&gt;
&lt;/bean&gt;</pre>


<p>And application.properties might look like this:</p>

<pre>jdbc.driver=org.h2.Driver
jdbc.url=jdbc:h2:mem:example
jdbc.username=sa
jdbc.password=</pre>


<p>Note, you can achieve the same simple configuration using the new spring 2.x style schema configuration, but it doesn't allow for any further customization so we're going to use the old style.</p>

<pre>&lt;!-- Example of <span class="category1">new</span> Spring 2.x style --&gt;
&lt;context:property-placeholder location="<span class="quote">classpath:application.properties</span>"/&gt;</pre>


<p>This handles the simple case of replacing placeholders (e.g. ${jdbc.url}) with values found in a properties files (e.g. jdbc.url=jdbc:h2:mem:example).  In a real-world application, we not only need to collect settings, but also override them in different environments.  Many of our applications are deployed in 4 or more environments (developer machine, build server, staging server, and production), each requiring different databases at the very least.</p>

<p>There are a few ways to enable overriding of properties.  Let's take a look at them in turn:</p>

<h3>1. Setting the system properties mode to override (default is fallback)</h3>

<pre>&lt;bean <span class="category1">class</span>="<span class="quote">org.springframework.beans.factory.config.PropertyPlaceholderConfigurer</span>"&gt;
    &lt;property name="<span class="quote">systemPropertiesModeName</span>" value="<span class="quote">SYSTEM_PROPERTIES_MODE_OVERRIDE</span>"/&gt;
    &lt;property name="<span class="quote">location</span>" value="<span class="quote">classpath:application.properties</span>"/&gt;
&lt;/bean&gt;</pre>


<p>When configured in this mode, any value specified as a system property to the JVM will override any values set in properties files.  For example, adding -Djdbc.url=jdbc:h2:mem:cheesewhiz to the JVM arguments would override the value in the file (jdbc:h2:mem:example).  On a Java 1.5 or newer platform, Spring will also look for an environment variable called jdbc.url is no system property was found.</p>

<h3>2. Specifying an optional properties file</h3>

<pre>&lt;bean <span class="category1">class</span>="<span class="quote">org.springframework.beans.factory.config.PropertyPlaceholderConfigurer</span>"&gt;
    &lt;property name="<span class="quote">ignoreResourceNotFound</span>" value="<span class="quote">true</span>"/&gt;
    &lt;property name="<span class="quote">locations</span>"&gt;
        &lt;list&gt;
            &lt;value&gt;classpath:application.properties&lt;/value&gt;
            &lt;value&gt;classpath:local.properties&lt;/value&gt;
        &lt;/list&gt;
    &lt;/property&gt;
&lt;/bean&gt;</pre>


<p>When <i>ignoreResourceNotFound</i> is set to true, Spring will ignore resources that don't exist.  You can imagine application.properties, containing all of the default settings, versioned in your SCM system.  Developers have the option of creating a properties file called local.properties to override any settings that differ in their environment.  This file should be unversioned and ignored by your SCM system.  This works because properties are loaded in order and replace previous values.</p>

<h3>3. Web Application overrides</h3>

<p>In a web application environment, Spring also supports specifying values in web.xml as context params or in your application server specific meta-data as servlet attributes.  For example, if you're using Tomcat you can specify one or more parameter elements in your context.xml, and Spring will can inject those values into placeholders.</p>

<pre>&lt;bean <span class="category1">class</span>="<span class="quote">org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer</span>"&gt;
    &lt;property name="<span class="quote">location</span>" value="<span class="quote">classpath:application.properties</span>"/&gt;
&lt;/bean&gt;</pre>

<p>The ServletContextPropertyPlaceholderConfigurer conveniently works in non servlet environments by falling back to the behavior of a PropertyPlaceholderConfigurer.  This is great when running unit tests.</p>
<h3>4. Combining techniques</h3>

<p>There's no reason why these techniques can't be combined.  Technique #1 is great for overriding a few values while #2 is better for overriding many.  #3 just expands the field of view when Spring goes to resolve placeholders.  When combined, system properties override those in files.  When using technique #3, there are some settings available for adjusting the override behavior (see contextOverride).  Test the resolution order when combining to ensure it's behaving as expected.</p>

<h3>Optional External Properties</h3>

<p>There's another use case that applies to some projects.  Often in non-developer environments, system admins want to keep properties for the environment outside of the deployable archive or the application server, and they don't want to deal with keeping those files in a Tomcat context file; they prefer a simple properties file.  They also don't want to have to place the file in a hard-coded location (e.g. /var/acmeapp/application.properties) or they may keep configuration for multiple servers in the same network directory, each file names after the server.  With a little trickery, it's easy to support an optional external properties file that isn't in a hard-coded location.  The location of the file is passed as a single system property to the JVM, for example: -Dconfig=file://var/acmeapp/server1.properties.  Here's the configuration to make it happen:</p>

<pre>&lt;bean <span class="category1">class</span>="<span class="quote">org.springframework.beans.factory.config.PropertyPlaceholderConfigurer</span>"&gt;
    &lt;property name="<span class="quote">ignoreUnresolvablePlaceholders</span>" value="<span class="quote">true</span>"/&gt;
&lt;/bean&gt;

&lt;bean <span class="category1">class</span>="<span class="quote">org.springframework.beans.factory.config.PropertyPlaceholderConfigurer</span>"&gt;
    &lt;property name="<span class="quote">ignoreResourceNotFound</span>" value="<span class="quote">true</span>"/&gt;
    &lt;property name="<span class="quote">location</span>" value="<span class="quote">${config}</span>"/&gt;
&lt;/bean&gt;</pre>


<p>The first definition enables basic property resolution through system properties (in fallback mode).  The second bean loads the resource from the location resolved from the system property -Dconfig.  All spring resource urls are supported, making this very flexible.</p>

<h3>Putting it all together</h3>

<p>Here's a configuration that does more than most people would need, but allows for ultimate flexibility:</p>

<pre>&lt;bean <span class="category1">class</span>="<span class="quote">org.springframework.beans.factory.config.PropertyPlaceholderConfigurer</span>"&gt;
    &lt;property name="<span class="quote">ignoreUnresolvablePlaceholders</span>" value="<span class="quote">true</span>"/&gt;
&lt;/bean&gt;

&lt;bean <span class="category1">class</span>="<span class="quote">org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer</span>"&gt;
    &lt;property name="<span class="quote">systemPropertiesModeName</span>" value="<span class="quote">SYSTEM_PROPERTIES_MODE_OVERRIDE</span>"/&gt;
    &lt;property name="<span class="quote">searchContextAttributes</span>" value="<span class="quote">true</span>"/&gt;
    &lt;property name="<span class="quote">contextOverride</span>" value="<span class="quote">true</span>"/&gt;
    &lt;property name="<span class="quote">ignoreResourceNotFound</span>" value="<span class="quote">true</span>"/&gt;
    &lt;property name="<span class="quote">locations</span>"&gt;
        &lt;list&gt;
            &lt;value&gt;classpath:application.properties&lt;/value&gt;
            &lt;value&gt;classpath:local.properties&lt;/value&gt;
            &lt;value&gt;${config}&lt;/value&gt;
        &lt;/list&gt;
    &lt;/property&gt;
&lt;/bean&gt;</pre>


<p>Every placeholder goes through the following resolution process.  Once a value is found it's set and the next placeholder is resolved:</p>

<ol>
<li>(optional) Property value specified as a system or environment property; useful for overriding specific placeholders.<br/>
   e.g. -Djdbc.host=devdb<br/>
   e.g. -Djdbc.username=carbon5</li>
<li>(optional) Context parameters located in web.xml or context attributes specified in application server meta-data (e.g. a Tomcat context.xml).</li>
<li>(optional) Properties file located by the system/environment variable called "config"; useful for externalizing configuration.  All URL types are supported.<br/>
   e.g. -Dconfig=c://hmc.properties</li>
<li>(optional) Properties file identified by classpath:local.properties; useful for specific developer overrides.</li>
<li>(required) Properties file identified by classpath:application.properties, which contains default settings for our application.</li>
</ol>

<h3>Best Practices</h3>

<ul>
<li>Deploy the same exact artifact (e.g. war, ear, etc) across all environments by externalizing configuration.  This may seem daunting, but the emergent benefits are huge in terms of simplicity.</li>
<li>Only make things that can safely change across environments configurable.  Also, only things that need to be configurable should be configurable, it's easy to go overboard.</li>
<li>Configure the minimal properties search path that meets your requirements.</li>
<li>When looking for properties files in the project tree, use classpath resources whenever possible.  This makes finding those files easy, consistent, and insensitive to the working-dir, which is great when running tests from your IDE and command line.</li>
<li>Aim for a zero-configuration check-out, build, run-tests cycle for the environment where its happens most: development.</li>
</ul>

What other interesting configuration scenarios have you seen?]]>


<!--$MTEntryMore encode_xml="1"$-->
</content>
</entry>
<entry>
<title>Injecting Spring 2.5 beans into Stripes Actions</title>
<link rel="alternate" type="text/html" href="http://www.carbonfive.com/community/archives/2008/03/injection_sprin.html" />
<modified>2008-03-27T18:09:06Z</modified>
<issued>2008-03-27T17:52:25Z</issued>
<id>tag:www.carbonfive.com,2008:/community//1.27</id>
<created>2008-03-27T17:52:25Z</created>
<summary type="text/plain">I&apos;ve been playing around with Stripes, a light-weight, well-designed simple Java web MVC framework recently. I haven&apos;t had the pleasure of working with it on a production application yet, but hope to sometime soon. Meanwhile, I&apos;ve been tinkering on a...</summary>
<author>
<name>Christian Nelson</name>

<email>christian@carbonfive.com</email>
</author>
<dc:subject>Java</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.carbonfive.com/community/">
<![CDATA[<p>I've been playing around with <a href="http://www.stripesframework.org">Stripes</a>, a light-weight, well-designed simple Java web MVC framework recently.  I haven't had the pleasure of working with it on a production application yet, but hope to sometime soon.  Meanwhile, I've been tinkering on a pet project.</p>

<p>As you may know, we often use <a href="http://springframework.org/">Spring</a> for lifecycle management of our services and dependency injection (among other uses).  In a Stripes + Spring application, you can imagine Spring-managed services being used by Stripes Actions (i.e. controllers).  Every incoming HTTP request results in a new instance of a Stripes Action, thus the newly created actions must have their dependencies injected for every request.</p>

<p>Stripes ships with a <a href="http://stripes.sourceforge.net/docs/current/javadoc/index.html?net/sourceforge/stripes/integration/spring/SpringInterceptor.html">SpringInterceptor</a> that supports annotating fields and methods on your actions with <a href="http://stripes.sourceforge.net/docs/current/javadoc/net/sourceforge/stripes/integration/spring/SpringBean.html">@SpringBean</a>.  While this works fine, I was pretty interested in being able to use Spring 2.5's annotations for marking what should be injected on my actions, so I created a Spring25Interceptor (see code below).</p>

<p>The Spring25Interceptor is configured the same way as the out-of-the-box SpringInterceptor.  In your web.xml:</p>

<pre>...
&lt;filter&gt;
    &lt;display-name&gt;Stripes Filter&lt;/display-name&gt;
    &lt;filter-name&gt;StripesFilter&lt;/filter-name&gt;
    &lt;filter-<span class="category1">class</span>&gt;net.sourceforge.stripes.controller.StripesFilter&lt;/filter-<span class="category1">class</span>&gt;
    &lt;init-param&gt;
        &lt;param-name&gt;Interceptor.Classes&lt;/param-name&gt;
        &lt;param-value&gt;
            net.sourceforge.stripes.integration.spring.Spring25Interceptor
        &lt;/param-value&gt;
    &lt;/init-param&gt;
    ...
&lt;/filter&gt;
...</pre>


<p>Since it uses the same annotations that Spring 2.5's supports (<a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/beans/factory/annotation/Autowired.html">@Autowired</a>, @Resource, and <a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/beans/factory/annotation/Qualifier.html">@Qualifier</a>), annotating your Stripes Actions is easy and should look pretty familiar (see <a href="http://blog.springsource.com/main/2008/01/28/spring-25s-comprehensive-annotation-support/">Juergen's blog</a> for a comprehensive overview).  Here are a few hypothetical examples:</p>

<pre><span class="category1">public</span> <span class="category1">class</span> LandingActionBean <span class="category1">extends</span> AbstractActionBean
{
     <span class="linecomment">// Autowire by type (looks for a bean in the application context of type ServiceA)</span>
     @Autowired ServiceA serviceA;
 
     <span class="linecomment">// Autowire by name (looks for a bean with the name 'serviceB')</span>
     @Resource ServiceB serviceB;
     
     <span class="linecomment">// Autowire by name (looks for a bean with the name 'serviceC')</span>
     @Autowired @Qualifier("<span class="quote">serviceC</span>") ServiceC serviceCee;
     
     <span class="linecomment">// Method injection examples (all of the above can be applied to methods as well)</span>
 
     @Autowired
     <span class="category1">public</span> <span class="category1">void</span> setServiceA(ServiceA a) { this.serviceA = a; }
     
     @Autowired
     <span class="category1">public</span> <span class="category1">void</span> setServices(ServiceA a, ServiceB b, ServiceC c) {
          this.serviceA = a;
          this.serviceB = b;
          this.serviceC = c;
      }
 
     @DefaultHandler
     <span class="category1">public</span> Resolution execute()
     {
          <span class="category1">return</span> <span class="category1">new</span> ForwardResolution("<span class="quote">/landing.jsp</span>");
      }
}</pre>


<p>While it may be considered a subtle improvement, I really like the fact that with this new interceptor, my application has a consistent syntax for dependency injection across the tiers.  Additionally, the semantics of the Spring annotations are also consistent and shared throughout.  An added bonus is that the new Interceptor is significantly smaller than the existing one.</p>

<p>Here's the Interceptor code that does the dependency injection into actions:</p>

<pre><span class="category1">import</span> net.sourceforge.stripes.action.*;
<span class="category1">import</span> net.sourceforge.stripes.controller.*;
<span class="category1">import</span> net.sourceforge.stripes.util.*;
<span class="category1">import</span> org.springframework.beans.factory.config.*;
<span class="category1">import</span> org.springframework.context.*;
<span class="category1">import</span> org.springframework.util.*;
<span class="category1">import</span> org.springframework.web.context.support.*;
<span class="category1">import</span> javax.servlet.*;

@Intercepts(LifecycleStage.ActionBeanResolution)
<span class="category1">public</span> <span class="category1">class</span> Spring25Interceptor <span class="category1">implements</span> Interceptor
{
     <span class="category1">private</span> <span class="category1">static</span> <span class="category1">final</span> Log log = Log.getInstance(Spring25Interceptor.class);
 
     <span class="category1">public</span> Resolution intercept(ExecutionContext context) <span class="category1">throws</span> <span class="category2">Exception</span>
     {
          Resolution resolution = context.proceed();
          log.debug("<span class="quote">Running Spring dependency injection for instance of </span>", context.getActionBean().getClass().getSimpleName());
          ServletContext servletContext = StripesFilter.getConfiguration().getServletContext();
          ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
          AutowireCapableBeanFactory beanFactory = applicationContext.getAutowireCapableBeanFactory();
          beanFactory.autowireBeanProperties(context.getActionBean(), AutowireCapableBeanFactory.AUTOWIRE_NO, <span class="category1">false</span>);
          beanFactory.initializeBean(context.getActionBean(), StringUtils.uncapitalize(context.getActionBean().getClass().getSimpleName()));
          <span class="category1">return</span> resolution;
      }
}</pre>


<p>I've created a <a href="http://www.stripesframework.org/jira/browse/STS-520">enhancement request</a> for this feature, though the comment-thread is a little bit all over the place.  You can find the latest version of the code and Javadoc as an attachment on the issue.</p>]]>


<!--$MTEntryMore encode_xml="1"$-->
</content>
</entry>
<entry>
<title>Alan Cooper presented by IxDA at Hot Studio</title>
<link rel="alternate" type="text/html" href="http://www.carbonfive.com/community/archives/2008/03/alan_cooper_pre_1.html" />
<modified>2008-03-26T20:13:46Z</modified>
<issued>2008-03-26T18:33:08Z</issued>
<id>tag:www.carbonfive.com,2008:/community//1.26</id>
<created>2008-03-26T18:33:08Z</created>
<summary type="text/plain">Alan Cooper spoke last night around the corner at Hot Studio at an event organized by the San Francisco chapter of IxDA, the Interaction Design Association. His talk was titled &quot;An Insurgence of Quality&quot; and was similar to the talk...</summary>
<author>
<name>Alon Salant</name>

<email>alon@carbonfive.com</email>
</author>
<dc:subject>Agile</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.carbonfive.com/community/">
<![CDATA[<p>Alan Cooper spoke last night around the corner at <a href="http://www.hotstudio.com">Hot Studio</a> at an event organized by the San Francisco chapter of <a href="http://www.ixda.org/">IxDA</a>, the Interaction Design Association. His talk was titled "An Insurgence of Quality" and was similar to <a href="http://www.brightcove.tv/title.jsp?title=1416866797&channel=1274129191">the talk he gave at an IxDA event in Savannah in February</a>.</p>

<p>Cooper talked for a while about the concept of craftsmanship as it relates to designers and developers. He emphasized that craftsmanship prioritizes quality over cost and time. While keeping costs down and accomplishing tasks in a timely matter are important, craftspeople do not sacrifice quality for either. They take the time and spend the money that it takes to do it right.</p>

<p><b>The Triad</b></p>

<p>He proposes that interaction designers and programmers are craftspeople who should unite around their common commitment to quality and demand that business take the time and spend the money to do things right. Doing things right in his proposal means a three-stage process of:</p>

<p>Interaction Design &raquo; Design Engineering &raquo; Production Engineering</p>

<p>Interaction Design starts with interaction designers talking to stakeholders, both customers and users, to understand the domain and behavioral requirements for software. They then design behaviors for the software based on this primary research.</p>

<p>Design Engineering starts with programmers working with interaction designers to evaluate the feasibility of the designed behavior, iterating over the designs in collaboration with the interaction designers. In this phase, programmers also hash out how the final system will work through a series of short iterations of development focused on identifying and solving technical problems. This product of this work is not production code, it is the definition of how the final system should be built. He feels that Agile methods are very appropriate for this phase.</p>

<p>Production Engineering is the process of cranking out the final product based on detailed written specifications produced in the prior two phases. Cooper claims that since all the details have been worked out, both in behavior and technology, this phase will be maximally efficient &mdash; a straight line of productive software development from start to delivery. He feels that a process like RUP is appropriate for this phase.</p>

<p>Cooper calls this process the Triad and <a href="http://www.cooper.com/insights/journal_of_design/articles/design_engineering_the_next_st.html">elaborates on his web site</a>.</p>

<p>His split between Design Engineering and Production Engineering is based partly on his claim that programmers can fundamentally be divided into two types &mdash; those who above all else want to do it right and those who want to get it done and out the door. The ones who want to do it right are the craftsmen and are best suited to be Design Engineering practitioners. The ones who want to get it done are best suited to be Production Engineering practitioners.</p>

<p><b>Hmmm</b></p>

<p>Cooper seems to have come a long way in his understanding and appreciation of Agile practices since his <a href="http://web.archive.org/web/20070313205440/http://www.fawcette.com/interviews/beck_cooper/">notorious 2002  conversation with Kent Beck</a>. Iteration, collaboration and feedback are all important characteristics of his Design Engineering phase.</p>

<p>However, it's not clear why Production Engineering would not benefit from an Agile process focused on frequent delivery of working software and tracking toward an end goal that has good definition. It's also not clear why Design Engineering shouldn't produce early versions of working software that can be tested with users and be the foundation of the final delivered software.</p>

<p>Some projects may benefit from his phasing. I could see his process benefiting a year long initiative to build shrink wrapped software where there is a desire to offshore a portion of the development. </p>

<p>But web software development does not work like that. You can release web software early and often without compromising quality. Yes, heed Cooper's warning not to rush prematurely to market with ill-conceived products. Stay focused on what matters to users and let them use it as early as you can. Cooper himself cites Sergey Brin of Google as saying, paraphrased, "that early on they were in no rush to have people try Google today. Tomorrow it would be better. Tomorrow would be fine." Google was in fact out early with something simple but well-considered in users' hands. They've evolved their product daily and weekly to what it is today. They are proof that releasing early does not necessarily mean prematurely.</p>

<p>Cooper's attempt to place interaction designers between programmers and their customers and users is also troubling. He claims that programmers don't want to talk to users which we know is simply wrong. In our experience, the further we are from our customer and end user in a project the greater the likelihood the project will go awry. I'd rather see an approach that figures out how to get programmers and interaction designers understanding the needs of their customers and users together and using that understanding to direct work in their specialized areas of expertise.</p>

<p>As a programmer, Cooper can be a bit hard to swallow. He definitely encourages an "us and them" perspective with his tongue-in-cheek comments about the inscrutability of programmers and their work. Of course he does the same for other relationships with a slew of disparaging claims about management and business executives.</p>

<p>Yet it's encouraging to hear him emphasize the importance of true collaboration between designers and programmers through the life of a project. I hope his understanding of programmers and their craft continues to evolve to support this goal.</p>]]>


<!--$MTEntryMore encode_xml="1"$-->
</content>
</entry>
<entry>
<title>Using paginating_find with has_finder</title>
<link rel="alternate" type="text/html" href="http://www.carbonfive.com/community/archives/2008/02/using_paginatin.html" />
<modified>2008-02-28T03:40:52Z</modified>
<issued>2008-02-28T03:23:04Z</issued>
<id>tag:www.carbonfive.com,2008:/community//1.25</id>
<created>2008-02-28T03:23:04Z</created>
<summary type="text/plain">I&apos;ve been enjoying using has_finder by Nick at Pivotal Labs and recently added pagination to the application I am providing volunteer time to for the San Francisco Bike Kitchen. I like the semantics of paginating_find over will_paginate but am not...</summary>
<author>
<name>Alon Salant</name>

<email>alon@carbonfive.com</email>
</author>
<dc:subject>Ruby (on Rails)</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.carbonfive.com/community/">
<![CDATA[<p>I've been enjoying using <a href="http://pivots.pivotallabs.com/users/nick/blog/articles/284-hasfinder-it-s-now-easier-than-ever-to-create-complex-re-usable-sql-queries">has_finder</a> by Nick at Pivotal Labs and recently added pagination to the application I am providing volunteer time to for the <a href="http://www.bikekitchen.org">San Francisco Bike Kitchen</a>.</p>

<p>I like the semantics of <a href="http://cardboardrocket.com/pages/paginating_find">paginating_find</a> over <a href="http://rock.errtheblog.com/will_paginate">will_paginate</a> but am not married to that choice if anyone wants to try to convince me otherwise.</p>

<p>In any case, I wanted to paginate the finders created by has_finder. I wrote a simple ActiveRecord mixin that provides a class method 'acts_as_paginated and is used in your model like:</p>

<pre><span class="category1">class</span> Visit &lt; ActiveRecord::Base
  belongs_to :person

  acts_as_paginated :size=&gt; 10
  
  has_finder :for_person, lambda { |person| {
        :conditions =&gt; { :person_id =&gt; person},
        :order =&gt; 'datetime DESC'
    } }

  has_finder :in_date_range, lambda { |from,to| {
        :conditions =&gt; [ "<span class="quote">visits.datetime &gt;= ? and visits.datetime &lt;= ?</span>", from, to ]
    } }
end</pre>


<p>Client code looks like:</p>

<pre> from, to = Date.new(2008,2,1), Date.new(2008,2,3)
 visits = Visit.for_person(@person).in_date_range(from, to).paginate(:page =&gt; 3)</pre>


<p>The mixin looks like:</p>

<pre># Provides Model.paginate(options={}) to allow
# the paginating_find plugin to be used with the has_finder plugin.
#
# Usage:
#   acts_as_paginated
#   acts_as_paginated :page =&gt; 2, size =&gt; 10
# 
# Install:
#   Save <span class="category1">this</span> file as lib/acts_as_paginated.rb and require 'acts_as_paginated'
#   in environment.rb.
#
module HasFinder
  module PaginatingFind #:nodoc:

    def self.included(mod)
      mod.extend(ClassMethods)
    end

    module ClassMethods
      def acts_as_paginated(options={ :page =&gt; 1, :size =&gt; 20})
        cattr_accessor :paginate_defaults
        self.paginate_defaults = options

        self.class_eval <span class="category1">do</span>
          extend HasFinder::PaginatingFind::SingletonMethods
        end
      end
    end

    module SingletonMethods
      def paginate(args={})
        options = self.paginate_defaults.clone
        options[:page] = args[:page].to_i <span class="category1">if</span> args[:page]
        options[:size] = args[:size].to_i <span class="category1">if</span> args[:size]
        find(:all, :page =&gt; { :size =&gt; options[:size], :current =&gt; options[:page], :first =&gt; 1 })
      end
    end
  end
end

ActiveRecord::Base.send(:include, HasFinder::PaginatingFind)</pre>


<p>It also works to paginate associations:</p>

<pre>@person.visits.paginate(:size =&gt; 4)</pre>
]]>


<!--$MTEntryMore encode_xml="1"$-->
</content>
</entry>
<entry>
<title>markaby_scaffold Rails Plugin</title>
<link rel="alternate" type="text/html" href="http://www.carbonfive.com/community/archives/2008/02/markaby_scaffol.html" />
<modified>2008-02-21T20:42:06Z</modified>
<issued>2008-02-20T20:32:09Z</issued>
<id>tag:www.carbonfive.com,2008:/community//1.24</id>
<created>2008-02-20T20:32:09Z</created>
<summary type="text/plain">We&apos;ve been enjoying using Markaby on our recent rails projects. When bootstrapping with scaffolding there&apos;s a common recipe of turning ERB views into Markaby and then refactoring views with Markaby helper functions. One project wrote a rake task that converts...</summary>
<author>
<name>Alon Salant</name>

<email>alon@carbonfive.com</email>
</author>
<dc:subject>Ruby (on Rails)</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.carbonfive.com/community/">
<![CDATA[<p>We've been enjoying using <a href="http://code.whytheluckystiff.net/markaby/">Markaby</a> on our recent rails projects. When bootstrapping with scaffolding there's a common recipe of turning ERB views into Markaby and then refactoring views with Markaby helper functions.</p>

<p>One project wrote a rake task that converts ERB views to Markaby. Then Ingar created a plugin that re-implements the base Rails scaffolding to create Markaby views that output the same HTML as the base Rails scaffolding. I took his work one standard refactor further to introduce a MarkabyHelper with helper functions for the layout of form inputs and model views.</p>

<p><b>Usage</b></p>

<pre>
./script/plugin install http://svn.carbonfive.com/public/carbonfive/rails/plugins/markaby_scaffold/trunk/
</pre>

<p>Use it as you would regular Rails scaffolding:</p>

<pre>
./script/generate markaby_scaffold Post title:string body:text published:boolean
</pre>

<p><b>Prerequisites</b></p>

<p>markaby_scaffold requires that you install <a href="http://redhanded.hobix.com/inspect/markabyForRails.html">Markaby as a Rails plugin</a>.</p>

<p><b>Gravy</b></p>

<p>Unfortunately, Markaby does not appear to be getting the love that it deserves. There is an issue using Markaby with Rails 2.0.2 for which <a href="http://code.whytheluckystiff.net/markaby/ticket/58">Randy has submitted a patch</a>. This plugin includes a <a href="http://en.wikipedia.org/wiki/Monkey_patch">monkey patch</a> for Markaby and Rails 2.0.2 that provides this fix so you don't have to apply it yourself.</p>

<p>Additionally, the generated MarkabyHelper includes support for using Markaby in your helpers, provides a quick start for refactoring the scaffolding layouts and includes test cases to get you started testing your Markaby helpers.<br />
</p>]]>


<!--$MTEntryMore encode_xml="1"$-->
</content>
</entry>
<entry>
<title>Introducing Java DB Migrations</title>
<link rel="alternate" type="text/html" href="http://www.carbonfive.com/community/archives/2008/02/introducing_jav.html" />
<modified>2008-03-08T08:09:40Z</modified>
<issued>2008-02-07T00:42:56Z</issued>
<id>tag:www.carbonfive.com,2008:/community//1.23</id>
<created>2008-02-07T00:42:56Z</created>
<summary type="text/plain">Here at Carbon Five we have the luxury of working on many projects, so anything we can do to make things easier will pay off in multiplicity across new projects. One of the things that we have to deal with...</summary>
<author>
<name>Christian Nelson</name>

<email>christian@carbonfive.com</email>
</author>
<dc:subject>Java</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.carbonfive.com/community/">
<![CDATA[<p>Here at Carbon Five we have the luxury of working on many projects,
so anything we can do to make things easier will pay off in multiplicity across
new projects.  One of the things that we have to deal with on every project is
maintaining a database schema over time.  We’ve had a manual process of
capturing changes in incremental db patch scripts for a while, but it was error
prone and sometimes neglected.  We’ve been doing more Ruby on Rails work and
found <a href="http://wiki.rubyonrails.org/rails/pages/UnderstandingMigrations">Rails
Migrations</a> easy to work with and a real time saver.  We wanted something
that would make our lives easier when working on Java projects in the same way
Migrations improve Rails development.  With that manifest in mind, Alon and I
collaborated on a simple Java database migration framework.</p>

<p>During development, it’s a big deal because each engineer has
two instances of the database, one for unit tests and another for running the
application.  We need an easy way to create a new, up-to-date database and update
existing databases.  Once a project has launched, it’s a big deal because we
need a way to migrate a database teeming with important production data to the
latest version without losing critical information.</p>

<p>High Level Requirements</p>

<ul>
 <li>Initiate a migration from the command-line as a Maven
     plugin</li>
 <li>Programmatically migrate a database during application startup</li>
 <li>Convention over Configuration</li>
 <li>Initially support migrations written in SQL</li>
</ul>

<p>At a high level, the migration process looks like this:</p>

<ol>
 <li>Query the database (table db_version) to find the current
     version.</li>
 <li>Determine the latest database schema version available.</li>
 <li>If the database is out of date, run each migration in
     order in its own transaction, updating the db_version for each migration.</li>
</ol>

<p>We’d identified two usage patterns, the first is more akin
to the Rails Migration model in that you explicitly migrate the database via the
command line.  The second is automatic migration when an application starts up,
before Hibernate initializes or any other data access takes place.  I’ll
discuss each in turn.</p>

<p><b>Migrating using Maven</b></p>

<p>This functionality is easy to enable in a mavenized project. 
First you add the Carbon Five public plugin repository:</p>

<pre>&lt;pluginRepositories&gt;
  &lt;pluginRepository&gt;
    &lt;id&gt;c5-<span class="category1">public</span>-repository&lt;/id&gt;
    &lt;url&gt;http:<span class="linecomment">//mvn.carbonfive.com/public&lt;/url&gt;</span>
  &lt;/pluginRepository&gt;
&lt;/pluginRepositories&gt;</pre>



<p>And then you configure the migration plugin:</p>

<pre>&lt;plugin&gt;
  &lt;groupId&gt;com.carbonfive&lt;/groupId&gt;
  &lt;artifactId&gt;maven-migration-plugin&lt;/artifactId&gt;
  &lt;version&gt;0.9-SNAPSHOT&lt;/version&gt;
  &lt;configuration&gt;
    &lt;defaultEnvironment&gt;test&lt;/defaultEnvironment&gt;
    &lt;environments&gt;
      &lt;environment&gt;
        &lt;name&gt;<span class="category1">default</span>&lt;/name&gt;
        &lt;driver&gt;com.mysql.jdbc.Driver&lt;/driver&gt;
        &lt;username&gt;dev&lt;/username&gt;
        &lt;password&gt;dev&lt;/password&gt;
      &lt;/environment&gt;
      &lt;environment&gt;
        &lt;name&gt;test&lt;/name&gt;
        &lt;url&gt;jdbc:mysql:<span class="linecomment">//localhost/myapp_test&lt;/url&gt;</span>
      &lt;/environment&gt;
      &lt;environment&gt;
        &lt;name&gt;development&lt;/name&gt;
        &lt;url&gt;jdbc:mysql:<span class="linecomment">//localhost/myapp_development&lt;/url&gt;</span>
      &lt;/environment&gt;
    &lt;/environments&gt;
  &lt;/configuration&gt;
  &lt;dependencies&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;mysql&lt;/groupId&gt;
      &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
      &lt;version&gt;5.1.5&lt;/version&gt;
    &lt;/dependency&gt;
  &lt;/dependencies&gt;
&lt;/plugin&gt;</pre>


<p>You’ll notice that we’ve got 2 environments configured.  You
can have as many as you need and you can specify which you want to migrate on
the command line.  If none are specified the default environment will be
migrated.  In this example we’re specifying the dependency on our JDBC driver
so that the plugin has access to the code it needs to connect the database.</p>

<p>Lastly, you drop in your migration scripts into the
src/main/resources/db/migrations directory, naming them using the pattern NNN_description.sql,
where NNN is three digits indicating the script sequence.  Some examples might be:</p>

<ul >
 <li>001_create_users_table.sql</li>
 <li>002_add_default_users.sql</li>
 <li>003_add_lastvisit_column.sql</li>
</ul>

<p>The description is optional and isn’t used for anything, it’s
just there so that other developers can get an idea of what a script does
without having to open it.</p>

<p>From the command line, you can run the migration plugin like
this:</p>

$ mvn migration:migrate

<p>Note that he database must exist for the migrations to take
place as we do not create missing databases (yet).</p>

<p>I’ve created a simple, complete sample that shows off this
functionality, it’s on the C5 public subversion repository <a
href="https://svn.carbonfive.com/public/christian/migration-sample1/trunk">here</a>.
Check it out and then read the readme.txt at the top of the project.</p>

<p><b>Migrating from your Application</b></p>

<p>The other usage scenario is to auto-migrate during
application startup.  At the core of the framework, there’s an interface called
MigrationManager which has two implementations: DataSourceMigrationManager and
DriverManagerMigrationManager. Migration happens right after
a datasource (of the javax.sql variety) is created.</p>

<p>Migrating from your application is as easy as instantiating one of these early in the startup cycle and invoking the migrate() method, something like this:</p>

<pre>MigrationManager migrationManager = <span class="category1">new</span>
    DriverManagerMigrationManager(“com.mysql.jdbc.Driver”, “jdbc:mysql:<span class="linecomment">//localhost/myapp_test”,</span>
“dev”, “dev”);
migrationManager.migrate();</pre>


<p>Of course this needs to happen before anything else in the
application uses the database; we want to database to be updated completely
before it’s used.</p>

<p>Spring is part of our standard development stack on our Java
projects, and it’s easy to enforce these dependencies in Spring configuration. 
First we define a data source for the application:</p>

<pre>&lt;bean id="<span class="quote">dataSource</span>" <span class="category1">class</span>="<span class="quote">org.springframework.jdbc.datasource.DriverManagerDataSource</span>"&gt;
  &lt;property name="<span class="quote">driverClassName</span>" value="<span class="quote">org.h2.Driver</span>"/&gt;
  &lt;property name="<span class="quote">url</span>" value="<span class="quote">jdbc:h2:file:~/.h2/migration_sample2_test</span>"/&gt;
  &lt;property name="<span class="quote">username</span>" value="<span class="quote">dev</span>"/&gt;
  &lt;property name="<span class="quote">password</span>" value="<span class="quote">dev</span>"/&gt;
&lt;/bean&gt;</pre>


<p>And now we declare our MigrationManager instance.  Note the ‘init-method’
attribute:</p>

<pre>&lt;bean id="<span class="quote">migrationManager</span>"
    <span class="category1">class</span>="<span class="quote">com.carbonfive.db.migration.DataSourceMigrationManager</span>"
    init-method="<span class="quote">migrate</span>"&gt;
  &lt;constructor-arg ref="<span class="quote">dataSource</span>"/&gt;
&lt;/bean&gt;</pre>


<p>And then you define something that’s going to use the
defined DataSource.  Note the ‘depends-on’ attribute:</p>

<pre> &lt;bean id="<span class="quote">userService</span>"
    <span class="category1">class</span>="<span class="quote">com.carbonfive.migration.sample2.UserService</span>"
    depends-on="<span class="quote">migrationManager</span>"&gt;
  &lt;constructor-arg ref="<span class="quote">dataSource</span>"/&gt;
&lt;/bean&gt;</pre>


<p>This is obviously a little contrived for the sake of example, but you get the
point.  In a typical application the thing that would depend on the datasource
is a Hibernate SessionFactory.</p>

<p>You can visit the source code for this example on the C5 public
subversion repository <a
href="https://svn.carbonfive.com/public/christian/migration-sample2/trunk">here</a>.</p>


<p><b>Best Practices</b></p>


<p>Here are a few of the things we’ve learned along the way:</p>

<ul>
 <li>Start using migrations early.  Definitely start by time there’s
     more than one person on a project. I usually start off letting hibernate
     generate my schema while I’m experimenting with things, but as soon as I’m
     really working on features I’ll switch over to migrations.</li>
 <li>All database changes are captured as a new migration.</li>
 <li>Migration scripts cannot be changed once *<b>anyone</b>*
     has run them and make further changes in a new migrations.</li>
</ul>

<p><b>Source Code Access</b></p>

<p>The Carbon Five db-support project which contains all of this
migration goodness is available on the C5 public subversion repository at <a
href="https://svn.carbonfive.com/public/carbonfive/db-support/trunk">https://svn.carbonfive.com/public/carbonfive/db-support/trunk</a>. 
It’s a maven project and should compile and pass its tests out of the box.  I
encourage you to look through the code and check out the tests.</p>

<p><b>Future</b></p>

<p>If you look through the code you’ll see some of what’s in
store for this project.  We’ve got initial support for writing migrations in
Groovy and JRuby and we’re thinking about added Java support as well.  We’re
looking for feedback to drive the future direction of the project, so feel free
to write us and let us know what you think.</p>]]>


<!--$MTEntryMore encode_xml="1"$-->
</content>
</entry>
<entry>
<title>Versioning your IDEA module meta-data (.iml)</title>
<link rel="alternate" type="text/html" href="http://www.carbonfive.com/community/archives/2008/02/versioning_your.html" />
<modified>2008-02-07T01:52:47Z</modified>
<issued>2008-02-06T19:38:33Z</issued>
<id>tag:www.carbonfive.com,2008:/community//1.22</id>
<created>2008-02-06T19:38:33Z</created>
<summary type="text/plain">On one of our larger client projects, we’ve been tackling an array of improvements to the development environment. This is largely motivated by the fact that it’s a big project with lots of modules and engineers and time lost dealing...</summary>
<author>
<name>Christian Nelson</name>

<email>christian@carbonfive.com</email>
</author>
<dc:subject>IntelliJ IDEA</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.carbonfive.com/community/">
<![CDATA[<p>On one of our larger client projects, we’ve been tackling an array of improvements to the development environment.  This is largely motivated by the fact that it’s a big project with lots of modules and engineers and time lost dealing with environment issues was expensive and frustrating.  Everyone wants to be productive without having to wrestle with their tools or understand the ins and outs of things on the periphery, like build systems and IDE configuration.</p>

<p>We migrated to Maven 2 for builds partially because it’s convention driven, so when questions of how we should do something come up we can default to Maven best practices.  Another reason is that it enabled us to stick to the <a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself">Don’t Repeat Yourself (DRY) principle</a>.  We didn’t want to duplicate build meta-data by maintaining both command-line configuration (Maven pom.xmls) and IntelliJ IDEA configuration.  Maven deals with this pretty well via the <a href="http://maven.apache.org/plugins/maven-idea-plugin/">maven-idea-plugin</a>.</p>

<p>The downside to running “mvn idea:module” every time there’s a pom change is that it eats at least a few minutes with all of the checks for sources and javadocs.  To make matters worse, we <em>always</em> had to run it from the master directory so that intra-module dependencies were modeled correctly as IDEA module dependencies, not jar dependencies.   Each developer would go through this routine when there was a change because we weren’t versioning our IDEA meta-data in subversion.  When considering all of the engineer’s time, this process would consume over half an hour in total.</p>

<p>I wanted to change the process so that we still used the maven-idea-plugin to generate the meta-data (staying true to DRY), but then commit the generated files to subversion so that only one person would have to go through the pain of re-generating (presumably whoever made the changes to the poms) and the rest of the team could continue without much disruption.  The problem is that each generated .iml file contains absolute paths which are specific to their machine.</p>

<p>After a bit of sleuthing, I discovered an IDEA option called Path Variables which is available in the general settings section.  There isn’t much to tell you what it does, so it’s easily overlooked.  You can specify one or more variables and IDEA will automatically replace file paths in project (.ipr) and module files (.iml) with the provided variables.  Everyone on the development team added a Path Variable called “M2_REPO” which points to their local maven repository (~/.m2/repository). </p>

<center><img alt="add path variable" src="http://www.carbonfive.com/community/add-path-varible.jpg" width="389" height="134" /></center>

<p>After running “mvn idea:module” we just open the project in IDEA and it will do the replacing behind the scenes.  Now the module meta-data can be versioned and shared.</p>

<p>It’s a small feature, but it’s helping us streamline everyone’s day-to-day.</p>

<p>IDEA 7 includes native Maven support which is getting better with each point release.  The process described herein works great with the native plugin as well.<br />
</p>]]>


<!--$MTEntryMore encode_xml="1"$-->
</content>
</entry>
<entry>
<title>Google Talking with JRuby and Smack</title>
<link rel="alternate" type="text/html" href="http://www.carbonfive.com/community/archives/2008/02/google_talking_1.html" />
<modified>2008-02-03T23:02:45Z</modified>
<issued>2008-02-03T22:09:53Z</issued>
<id>tag:www.carbonfive.com,2008:/community//1.21</id>
<created>2008-02-03T22:09:53Z</created>
<summary type="text/plain">We&apos;ve kicked off a new project that extends well beyond standard webapp frameworks and tools including significant instant messaging integration. Portions of the project will use Ruby on Rails for web functionality. I know that the open source Jabber software...</summary>
<author>
<name>Alon Salant</name>

<email>alon@carbonfive.com</email>
</author>
<dc:subject>Ruby (on Rails)</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.carbonfive.com/community/">
<![CDATA[<p>We've kicked off a new project that extends well beyond standard webapp frameworks and tools including significant instant messaging integration. Portions of the project will use <a href="http://www.rubyonrails.org">Ruby on Rails</a> for web functionality. I know that the <a href="http://www.igniterealtime.org/projects/">open source Jabber software</a> from <a href="http://www.jivesoftware.com/">Jive Software</a> is excellent quality and feature rich. Would <a href="http://jruby.codehaus.org/">JRuby</a> be a good tool for leveraging these Java libraries in a Ruby environment?</p>

<p>Here's a toy chat client and parrot bot I wrote for the <a href="http://code.google.com/apis/talk/open_communications.html">Google Talk service</a> using JRuby and the <a href="http://www.igniterealtime.org/projects/smack/index.jsp">Java Smack API</a> from Jive's open source portal <a href="http://www.igniterealtime.org/">ignite realtime</a>.</p>]]>


<!--$MTEntryMore encode_xml="1"$-->
</content>
</entry>
<entry>
<title>JRubyGems Release</title>
<link rel="alternate" type="text/html" href="http://www.carbonfive.com/community/archives/2008/01/jrubygems_relea_1.html" />
<modified>2008-01-29T01:52:04Z</modified>
<issued>2008-01-04T20:39:27Z</issued>
<id>tag:www.carbonfive.com,2008:/community//1.20</id>
<created>2008-01-04T20:39:27Z</created>
<summary type="text/plain">I&apos;m releasing a first version of JRubyGems. This post is documentation until I come up with something better. JRubyGems allows you to package RubyGems on your Java application classpath. It removes the file system dependencies on locally installed gems that...</summary>
<author>
<name>Alon Salant</name>

<email>alon@carbonfive.com</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.carbonfive.com/community/">
<![CDATA[<p>I'm releasing a first version of JRubyGems. This post is documentation until I come up with something better.</p>

<p>JRubyGems allows you to package RubyGems on your Java application classpath. It removes the file system dependencies on locally installed gems that get awkward when using JRuby and dependent gems in a Java environment.</p>

<b><a name="JRubyGems-Usage"></a>Usage</b>

<p>Use JRubyGems as a replacement for RubyGems. Instead of</p>


<pre>require 'rubygems'
gem 'activerecord'</pre>


<p>use</p>

<pre>require 'jrubygems'
gem 'activerecord'</pre>


<p>Behind the scenes JRubyGems requires RubyGems and injects behavior specific to finding gems on the Java classpath if they are not already installed.</p>

<p>You make JRubyGems available to your application by putting the jar on your application classpath. </p>
]]>


<!--$MTEntryMore encode_xml="1"$-->
</content>
</entry>
<entry>
<title>Thoughts on JRuby</title>
<link rel="alternate" type="text/html" href="http://www.carbonfive.com/community/archives/2008/01/thoughts_on_jru.html" />
<modified>2008-01-04T21:34:22Z</modified>
<issued>2008-01-02T22:00:47Z</issued>
<id>tag:www.carbonfive.com,2008:/community//1.19</id>
<created>2008-01-02T22:00:47Z</created>
<summary type="text/plain">At Carbon Five we have built our professional consulting practice on the solid foundation of enterprise Java development. In 2007 we added Ruby and Ruby on Rails as development tool and framework that complement our existing values and process in...</summary>
<author>
<name>Alon Salant</name>

<email>alon@carbonfive.com</email>
</author>
<dc:subject>Ruby (on Rails)</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.carbonfive.com/community/">
<![CDATA[<p>At Carbon Five we have built our professional consulting practice on the solid foundation of enterprise Java development. In 2007 we added Ruby and Ruby on Rails as development tool and framework that complement our existing values and process in many fantastic ways.</p>

<p>Looking forward, I want to be sure that we take maximum advantage of our existing knowledge and new learning in both Java and Ruby. I have high hopes for <a href="http://jruby.codehaus.org/">JRuby</a> as a valuable bridge that spans both languages and gives developers the flexibility to use the strengths of the two. Sun appears to feel the same way as <a href="http://headius.blogspot.com/2006/09/jruby-steps-into-sun.html">they have hired the two core JRuby developers</a>, <a href="http://headius.blogspot.com/2007/11/top-five-questions-i-get-asked.html">Charles Nutter</a> and Thomas Enebo, to work on JRuby full time.</p>

<p>In preparation for more specific posts, here are some light musings on JRuby.</p>
]]>


<!--$MTEntryMore encode_xml="1"$-->
</content>
</entry>
<entry>
<title>Ruby on Rails Project Report</title>
<link rel="alternate" type="text/html" href="http://www.carbonfive.com/community/archives/2007/09/ruby_on_rails_p.html" />
<modified>2007-09-11T17:30:20Z</modified>
<issued>2007-09-10T23:17:17Z</issued>
<id>tag:www.carbonfive.com,2007:/community//1.18</id>
<created>2007-09-10T23:17:17Z</created>
<summary type="text/plain">Randy and I recently completed a project implemented with Ruby on Rails. This is a writeup of the tools and strategies we used and what we learned, liked and disliked about Rails development....</summary>
<author>
<name>Alon Salant</name>

<email>alon@carbonfive.com</email>
</author>
<dc:subject>Ruby (on Rails)</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.carbonfive.com/community/">
Randy and I recently completed a project implemented with Ruby on Rails. This is a writeup of the tools and strategies we used and what we learned, liked and disliked about Rails development.


<!--$MTEntryMore encode_xml="1"$-->
</content>
</entry>
<entry>
<title>Agile User Experience (UX) Resources</title>
<link rel="alternate" type="text/html" href="http://www.carbonfive.com/community/archives/2007/09/agile_user_expe.html" />
<modified>2008-02-14T18:17:22Z</modified>
<issued>2007-09-07T00:12:19Z</issued>
<id>tag:www.carbonfive.com,2007:/community//1.17</id>
<created>2007-09-07T00:12:19Z</created>
<summary type="text/plain">For the seven years that we have been evolving our Extreme Programming practice, we have repeatedly readdressed the question of how to best integrate user experience design (visual design, information architecture,...) with an agile process. As a consulting company, it...</summary>
<author>
<name>Alon Salant</name>

<email>alon@carbonfive.com</email>
</author>
<dc:subject>Agile</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.carbonfive.com/community/">
<![CDATA[<p>For the seven years that we have been evolving our Extreme Programming practice, we have repeatedly readdressed the question of how to best integrate user experience design (visual design, information architecture,...) with an agile process. As a consulting company, it has always been a requirement that we flex our process to accommodate our clients and partners. Over the last year or two we have found our clients and partners increasingly interested in flexing their processes to work more agile and collaboratively with us.</p>

<p>The post is the first of a series on user experience (UX) design practices for agile software development teams. In an upcoming project with our partner Hot Studios we will be exploring new ways to integrate their user experience design process with our software development process. We'll share some learnings from that, experiences from the past and new ideas for the future.</p>

<p>First we have a growing reading list of existing resources on the topic that I am posting here for you. If you have other resources for us, please share.</p>

<p><a href="http://timiti.blogspot.com/2008/02/user-research-as-commodity.html">User Research as a Commodity</a><br />
<i>Added 2008-02-14</i><br />
Alex at Pivotal Labs <a href="http://pivots.pivotallabs.com/users/alex/blog/articles/400-user-research-as-a-commodity">noted this post</a> from a user experience manager at Kaiser Permanente who describes a strategy for including regular user testing in an agile development process. The strategy is attractive because it fits with a key characteristic of agile where simple practices performed regularly produce high level complex results.</p>

<p><a href="http://web.archive.org/web/20070313205440/http://www.fawcette.com/interviews/beck_cooper/">Kent Beck v. Alan Cooper</a><br />
This is a 2002 article with the following abstract "Kent Beck is known as the father of 'extreme programming,' a process created to help developers design and build software that effectively meets user expectations. Alan Cooper is the prime proponent of interaction design, a process with similar goals but different methodology. We brought these two visionaries together to compare philosophies, looking for points of consensus—and points of irreconcilable difference." The difference in perspective between the two is very expressive of the conflicts we have seen between design and agile development processes. Many of the following resources reference this discussion.</p>

<p><i>Note: the original source for this great interview appears to have been taken over by another entity that is no longer making the article available. I am linking to it in the <a href="http://www.archive.org">Internet Archive</a>.</i></p>

<p><a href="http://www.disambiguity.com/waterfall-bad-washing-machine-good-ia-summit-07-slides/">Waterfall Bad, Washing Machine Good</a><br />
Leisa Reichelt's IA Summit 07 presentation on the role of IA in the design process identifies the failures of a waterfall design process and argues that an agile, iterative design process is superior. Slide 14 is right on.</p>

<p><a href="http://www.agilemodeling.com/essays/agileUsability.htm">User Experience Activities on Agile Development Projects</a><br />
Recent article by Scott Ambler addresses the gap between Beck and Cooper by identifying a middle ground that requires UX and agile practitioners to learn a bit more about each others' practices and to adopt some of each.</p>

<p><a href="http://agileproductdesign.com/blog/index.html">Holistic Product Design &amp; Development</a><br />
A series of blog posts by Jeff Patton on agile software development and user centered design. Jeff moderates the <span class="nobr"><a href="http://tech.groups.yahoo.com/group/agile-usability/">agile-usability Yahoo group</a></span>.</p>

<p><a href="http://tech.groups.yahoo.com/group/agile-usability/">Agile Usability Yahoo! Group</a><br />
The description for this group provides a good summary of the issues we are tackling here. You are invited to jump into the fray.</p>

<p><a href="http://www.agilelogic.com/files/ExperiencesIntegratingUEDPractices.pdf">Experiences Integrating UED Practices</a><br />
In this experience report Paul Hodgetts presents his "teams' struggles to come to grips with the often programming-centric orientation of agile processes, and their ongoing efforts to integrate their UED (user experience design) best practices into the incremental, collaborative world of agile processes." He provides an overview to the range of UX practices, identifies challenges and discusses practices that he found were particularly useful in integrating UX and and agile development.</p>

<p><a href="http://lists.interactiondesigners.com/htdig.cgi/discuss-interactiondesigners.com/2004-March/001083.html">Agile User-Centered Design</a><br />
A post to ID-discuss that presents one designer's struggle to reconcile agile and user-centered design.</p>

<p><a href="http://www.foruse.com/articles/agiledesign.pdf">Process Agility and Software Usability: Toward Lightweight Usage-Centered Design</a><br />
2001 paper by Larry Constantine presents concrete practices for UX that map to agile practices. His approach is simple and pragmatic.</p>

<p><a href="http://www.slideshare.net/theinfonaut/are-agile-projects-doomed-to-halfbaked-design/">The Challenge of Agile Design</a><br />
These are slides from a talk given by our friends at Pivotal Labs and Satisfaction.</p>

<p><a href="http://agiletoolkit.libsyn.com/index.php?post_id=15584">User Centered Design Round Table</a><br />
Podcast of a discussion on user-centered design and agile development with Lynn Miller, Jeff Patton and Rebecca Wirfs-Brock.</p>

<p><i>Originally posted 2007-09-06</i><br />
<i>Last updated 2008-02-14</i></p>]]>


<!--$MTEntryMore encode_xml="1"$-->
</content>
</entry>
<entry>
<title>Dojo drag and drop gotcha in IE</title>
<link rel="alternate" type="text/html" href="http://www.carbonfive.com/community/archives/2007/06/dojo_drag_and_d.html" />
<modified>2007-06-13T21:51:02Z</modified>
<issued>2007-06-13T18:21:37Z</issued>
<id>tag:www.carbonfive.com,2007:/community//1.16</id>
<created>2007-06-13T18:21:37Z</created>
<summary type="text/plain"> I have been working on a web app for one of our clients that includes a pretty interactive AJAX / Web 2.0 component within it. This component is essentially a simplified drag-and-drop book publishing tool, which allows users to...</summary>
<author>
<name>Mike Wynholds</name>

<email>mike@carbonfive.com</email>
</author>
<dc:subject>JavaScript / AJAX</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.carbonfive.com/community/">
<![CDATA[<p>
I have been working on a web app for one of our clients that includes a pretty interactive AJAX / Web 2.0 component within it.  This component is essentially a simplified drag-and-drop book publishing tool, which allows users to upload images and then to arrange them on predefined templates in order to create a book.
</p>
<p>
We chose to use the <a href="http://dojotoolkit.org/">Dojo Toolkit</a> (version 0.4.2) for both the AJAX (ie: remote calls to the server) and the Widegtry side of the Web 2.0 style.  It's been working fairly well.  Dojo has a lot of functionality, but also has a few areas that still need some refinement.  The most interesting / infuriating to me so far has to do with Dojo drag-and-drop functionality within IE.
</p>]]>


<!--$MTEntryMore encode_xml="1"$-->
</content>
</entry>
<entry>
<title>Parameterized REST URLs with Spring MVC</title>
<link rel="alternate" type="text/html" href="http://www.carbonfive.com/community/archives/2007/06/parameterized_rest_urls_with_spring_mvc.html" />
<modified>2008-01-02T23:48:28Z</modified>
<issued>2007-06-11T17:45:03Z</issued>
<id>tag:www.carbonfive.com,2007:/community//1.15</id>
<created>2007-06-11T17:45:03Z</created>
<summary type="text/plain">At Carbon Five, we&apos;ve been working REST-ful practices into our web applications for some time now. Providing simple URLs for application entities is a key principal of this style, but parsing parameters out of the request path has been klunky...</summary>
<author>
<name>Alex Cruikshank</name>

<email>alex@carbonfive.com</email>
</author>
<dc:subject>Java</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.carbonfive.com/community/">
<![CDATA[<p>At Carbon Five, we've been working <a href="http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm">REST</a>-ful practices into our web applications for some time now.  Providing simple URLs for application entities is a key principal of this style, but parsing parameters out of the request path has been klunky in Spring MVC.  Spring's <a href="http://opensource.atlassian.com/confluence/spring/display/WEBFLOW/Home">WebFlow</a> apparently supports REST-ful URLs, but I've never found anything in what I've read or heard to recommended that project (though I've heard nothing bad).</p>

<p>I finally got fed up with the situation and worked out a solution that lets developers specify path parameters in the dispatcher mappings, which will appear as request parameters in the controller and view.  I've made the project <a href="https://svn.carbonfive.com/public/pathparameter/trunk/">available</a> on our public SVN server.  The solution requires only 4 classes, so you can <a href="https://svn.carbonfive.com/public/pathparameter/trunk/src/main/java/carbonfive/spring/web/pathparameter/">download</a> them instead.  Read on for configuration information.</p>]]>


<!--$MTEntryMore encode_xml="1"$-->
</content>
</entry>

</feed>