<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JAW Speak &#187; code</title>
	<atom:link href="http://jawspeak.com/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://jawspeak.com</link>
	<description>Jonathan Andrew Wolter</description>
	<lastBuildDate>Fri, 30 Jul 2010 20:39:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Session State &#8211; it&#8217;s not complicated, but options are limited</title>
		<link>http://jawspeak.com/2010/07/30/session-state-its-not-complicated-but-options-are-limited/</link>
		<comments>http://jawspeak.com/2010/07/30/session-state-its-not-complicated-but-options-are-limited/#comments</comments>
		<pubDate>Fri, 30 Jul 2010 20:39:08 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[architecture]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://jawspeak.com/?p=277</guid>
		<description><![CDATA[Reading time: 3 &#8211; 4 minutes

			
				
			
		
Web apps have numerous choices for storing stateful data in between requests. For example, when a user goes through a multi-step wizard, he or she might make choices on page one that need to be propagated to page three. That data could be stored in http session. (It also could [...]]]></description>
			<content:encoded><![CDATA[<p>Reading time: 3 &#8211; 4 minutes</p>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fjawspeak.com%2F2010%2F07%2F30%2Fsession-state-its-not-complicated-but-options-are-limited%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=?url=http%3A%2F%2Fjawspeak.com%2F2010%2F07%2F30%2Fsession-state-its-not-complicated-but-options-are-limited%2F&amp;style=normal&amp;service=bit.ly" height="61" width="51" /><br />
			</a>
		</div>
<p>Web apps have numerous choices for storing stateful data in between requests. For example, when a user goes through a multi-step wizard, he or she might make choices on page one that need to be propagated to page three. That data could be stored in <a href="http://en.wikipedia.org/wiki/HTTP">http</a> <a href="http://en.wikipedia.org/wiki/Session_%28computer_science%29">session</a>. (It also could get stored into some backend persistence and skip session altogether).</p>
<p>So where does session get stored? There are basically four choices here.</p>
<ol>
<li>Store state on one app server, i.e. for java in HttpSession. Subsequent requests need to be pinned to that particular app server via your load balancer. If you hit another app server, you will not have that data in session.</li>
<li>Store state in session, and then replicate that session to all or many other app servers. This means you don&#8217;t need a load balancer to anchor a user to one app server; multiple requests can either hit any app server (full replication). Or use the load balancer to pin to particular cluster (themselves replicating sessions, and giving higher availability). Replication can be smart so only the deltas of binary data are multicast to the other servers.</li>
<li>Store the state on the client side, via cookies, hidden form fields, query strings, or client side storage in flash or html 5. Rails has an option to store it in cookies automatically. Consider encrypting the session data. However, some of these options can involve a lot of data going back and forth on every request, especially if it&#8217;s in a cookie and images/scripts are served from the same domain.</li>
<li>Store no state on app servers, instead write everything in between requests down to backend persistence. Do not necessarily use the concept of http session. Use id&#8217;s to look up those entities. Persistence could be a relational database, distributed/replicated key/value storage, etc. Your session data is serialized in one big object graph, or as multiple specific entries.</li>
</ol>
<p>What you choose is up to many factors, however a few guidelines help:</p>
<ol>
<li>Try to keep what is in session small.</li>
<li>If possible, keep session state on the client side.</li>
<li>Prefer key/value storage replicated among a small cluster over replicating all session state among all app servers.</li>
<li>Genuinely consider sticky sessions, which home users to a particular app server. Many benefits abound, including what Paul Hammant talks about w.r.t Servlet spec 7.7.2 <a href="http://paulhammant.com/blog/appengines-blind-spot.html">Appengine&#8217;s Blind Spot</a>.</li>
<li>If you serialize an object graph, recognize that when you do a deployment it will probably mean existing sessions are now unable to be deserialized by the newly deployed app. Avoid this by using your load balancer to swing new traffic into the new deployments, monitor errors, and then let the old sessions expire before switching all users over to the new deployment. Bleed them over.</li>
<li>Session is not for caching. It may be tempting to store data in session for caching purposes, but soon you will need a cache.</li>
<li>Store in session what is absolutely necessary for that user, but not more. See caches, above.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://jawspeak.com/2010/07/30/session-state-its-not-complicated-but-options-are-limited/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spring Request Scoped FactoryBean returning null gets cached forever</title>
		<link>http://jawspeak.com/2010/07/27/spring-request-scoped-factorybean-returning-null-gets-cached-forever/</link>
		<comments>http://jawspeak.com/2010/07/27/spring-request-scoped-factorybean-returning-null-gets-cached-forever/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 04:18:40 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://jawspeak.com/?p=269</guid>
		<description><![CDATA[Reading time: 2 &#8211; 4 minutes

			
				
			
		
We are using FactoryBeans extensively to own the responsibility of interesting work in constructing our object graph. These are request scoped, because they may depend on other objects that were themselves created by FactoryBeans specific to this request. For example, we have a Customer which needs an Account, so CustomerFactoryBean [...]]]></description>
			<content:encoded><![CDATA[<p>Reading time: 2 &#8211; 4 minutes</p>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fjawspeak.com%2F2010%2F07%2F27%2Fspring-request-scoped-factorybean-returning-null-gets-cached-forever%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=?url=http%3A%2F%2Fjawspeak.com%2F2010%2F07%2F27%2Fspring-request-scoped-factorybean-returning-null-gets-cached-forever%2F&amp;style=normal&amp;service=bit.ly" height="61" width="51" /><br />
			</a>
		</div>
<p>We are using <a href="http://static.springsource.org/spring/docs/2.5.6/api/org/springframework/beans/factory/FactoryBean.html">FactoryBeans</a> extensively to own the responsibility of interesting work in constructing our object graph. These are request scoped, because they may depend on other objects that were themselves created by FactoryBeans specific to this request. For example, we have a Customer which needs an Account, so CustomerFactoryBean depends on the field Account to be injected. (We use field or setter injection because otherwise creating a factory bean that depends on another object that is created by a factory bean may create a spring exception about circular dependencies.)</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.example.dotcom</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.example.common.Account</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.example.dotcom.session.CustomSession</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.beans.factory.FactoryBean</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.beans.factory.annotation.Autowired</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.context.annotation.Scope</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// the scope is crucial, this controls the scope of the factory bean</span>
@Scope<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;request&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AccountFactoryBean <span style="color: #000000; font-weight: bold;">implements</span> FactoryBean <span style="color: #009900;">&#123;</span>
&nbsp;
       <span style="color: #666666; font-style: italic;">// this is itself created from another factory bean</span>
       @Autowired
       CustomSession session<span style="color: #339933;">;</span>
&nbsp;
	@Override
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Object</span> getObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Sometimes this is going to return null, other times an instance.</span>
                <span style="color: #666666; font-style: italic;">// The fix is to always return a non-null instance (despite what the</span>
                <span style="color: #666666; font-style: italic;">// javadoc says). Use the Null Object pattern.</span>
                <span style="color: #000000; font-weight: bold;">return</span> session.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>Account.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
		<span style="color: #666666; font-style: italic;">// Note: you will need to implement caching in here or in </span>
		<span style="color: #666666; font-style: italic;">// a custom scope (which we did). Or every time you need</span>
		<span style="color: #666666; font-style: italic;">// to inject the Account it will call getObject(), which</span>
		<span style="color: #666666; font-style: italic;">// could be problematic if it was a slow operation.</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@Override
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">Class</span> getObjectType<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> Account.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@Override
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> isSingleton<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>We are using autowiring by type, but we encountered a problem when the result of a factory bean&#8217;s getObject() is sometimes null. If the first call to that request scoped factory bean returned null, it would never call getObject() again in future requests. Upon investigation, you can see there is a subtle caching of null return values from factory beans. (Even if they are request scoped.) Might be a bug, I don&#8217;t know. But the work around is probably a good idea to implement anyways: use <a href="http://cs.oberlin.edu/~jwalker/nullObjPattern/">Null Objects</a> instead of passing around null.</p>
<p>Here is the problematic code from Spring that caches the null return value: <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.springframework/spring-beans/2.5.6/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java#390">AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement</a>. There is a field <tt>cached</tt> and <tt>cachedFieldValue</tt>. These are set if the value is null, and then on subsequent calls they will return the null value without calling <tt>getObject</tt> on the factory bean.</p>
<p>I recommend not returning null in factory beans, or else it might be cached by Spring and your factory bean will not be called again when that object is needed.</p>
]]></content:encoded>
			<wfw:commentRss>http://jawspeak.com/2010/07/27/spring-request-scoped-factorybean-returning-null-gets-cached-forever/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hotspot caused exceptions to lose their stack traces in production &#8211; and the fix</title>
		<link>http://jawspeak.com/2010/05/26/hotspot-caused-exceptions-to-lose-their-stack-traces-in-production-and-the-fix/</link>
		<comments>http://jawspeak.com/2010/05/26/hotspot-caused-exceptions-to-lose-their-stack-traces-in-production-and-the-fix/#comments</comments>
		<pubDate>Wed, 26 May 2010 05:46:42 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[thoughtworks]]></category>

		<guid isPermaLink="false">http://jawspeak.com/?p=233</guid>
		<description><![CDATA[Reading time: 3 &#8211; 4 minutes

			
				
			
		
Today I was working with Kumar and Elian where we encountered production logs with dozens of NullPointerExceptions with no stack trace. We identified that the JIT compiler will optimize away stack traces in certain exceptions if they happen enough. The code below reproduces it. We are on jdk 1.6 (I [...]]]></description>
			<content:encoded><![CDATA[<p>Reading time: 3 &#8211; 4 minutes</p>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fjawspeak.com%2F2010%2F05%2F26%2Fhotspot-caused-exceptions-to-lose-their-stack-traces-in-production-and-the-fix%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=?url=http%3A%2F%2Fjawspeak.com%2F2010%2F05%2F26%2Fhotspot-caused-exceptions-to-lose-their-stack-traces-in-production-and-the-fix%2F&amp;style=normal&amp;service=bit.ly" height="61" width="51" /><br />
			</a>
		</div>
<p>Today I was working with <a href="http://www.linkedin.com/in/kumarvora">Kumar</a> and <a href="http://www.linkedin.com/pub/elian-haliman/4/102/786">Elian</a> where we encountered production logs with dozens of NullPointerExceptions with no stack trace. We identified that the JIT compiler will optimize away stack traces in certain exceptions if they happen enough. The code below reproduces it. We are on jdk 1.6 (I don&#8217;t remember the minor version now).</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> NpeThief <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> callManyNPEInLoop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">100000</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span><span style="color: #009900;">&#41;</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #666666; font-style: italic;">// This will switch from 2 to 0 (indicating our problem is happening)</span>
                <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> ... <span style="color: #006633;">args</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        NpeThief thief <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> NpeThief<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        thief.<span style="color: #006633;">callManyNPEInLoop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Run it as follows and the issue will appear (the stack trace length changes from 2 to 0):<br />
<code>javac NpeThief.java &amp;&amp; java -classpath . NpeThief<br />
javac NpeThief.java &amp;&amp; java -server -classpath . NpeThief<br />
</code></p>
<p>How to fix it? The following options resolve it and it stays at 2, never going to 0 as length of NPE&#8217;s stack trace:<br />
<code>javac NpeThief.java &amp;&amp; java -XX:-OmitStackTraceInFastThrow -server -classpath . NpeThief<br />
javac NpeThief.java &amp;&amp; java -XX:-OmitStackTraceInFastThrow -classpath . NpeThief<br />
javac NpeThief.java &amp;&amp; java -Xint -classpath . NpeThief<br />
javac NpeThief.java &amp;&amp; java -Xint -server -classpath . NpeThief<br />
</code><br />
So the solution is to start with <tt>-XX:-OmitStackTraceInFastThrow</tt> argument to java which instructs the JIT to remove this optimization [1,2], or operate in interpreted only mode [3]. What is going on? [2]</p>
<blockquote>
<div>
<p>The JVM flag -XX:-OmitStackTraceInFastThrow disables the performance optimization of the JVM for this use case. If this flag is set, the stacktrace will be available. (editor: or if the -Xint is set).</p>
<p>&#8220;The compiler in the server VM now provides correct stack backtraces for all &#8220;cold&#8221; built-in exceptions. For performance purposes, when such an exception is thrown a few times, the method may be recompiled. After recompilation, the compiler may choose a faster tactic using preallocated exceptions that do not provide a stack trace. To disable completely the use of preallocated exceptions, use this new flag: -XX:-OmitStackTraceInFastThrow.&#8221; <a rel="nofollow" href="http://java.sun.com/j2se/1.5.0/relnotes.html">http://java.sun.com/j2se/1.5.0/relnotes.html</a></p>
</div>
</blockquote>
<p>How does this impact performance? I did extremely naive timing and <tt>time java [args] -classpath . NpeThief</tt>. It behaved as expected, with interpreted the slowest. Is that the solution?</p>
<p>No. We weren&#8217;t going to change production JVM options to resolve this, instead since our isolated example code above indicated that initial exceptions would throw with the full stack trace, we went back into older logs and grepped. Sure enough, right after we deployed there were exceptions appearing with the full stack trace. That gives us enough information where we can identify and fix the bug.</p>
<p>Notes:<br />
[1] Related sun bug <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4292742">4292742 NullPointerException with no stack trace</a><br />
[2] Helpful StackOverflow discussion of <a href="http://stackoverflow.com/questions/1076191/nullpointerexception-stack-trace-not-available-without-debug-agent">NullPointerException missing stack traces</a><br />
[3] -Xint:  Operate in interpreted-only mode. Compilation to native code is disabled, and all bytecodes are executed by the interpreter. The performance benefits offered by the Java HotSpot VMs’ adaptive compiler will not be present in this mode.</p>
]]></content:encoded>
			<wfw:commentRss>http://jawspeak.com/2010/05/26/hotspot-caused-exceptions-to-lose-their-stack-traces-in-production-and-the-fix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>12 Tips for Less* Hate of Maven</title>
		<link>http://jawspeak.com/2010/05/14/12-tips-for-less-hate-of-maven/</link>
		<comments>http://jawspeak.com/2010/05/14/12-tips-for-less-hate-of-maven/#comments</comments>
		<pubDate>Fri, 14 May 2010 13:13:27 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[thoughtworks]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[troubleshooting]]></category>

		<guid isPermaLink="false">http://jawspeak.com/?p=152</guid>
		<description><![CDATA[Reading time: 3 &#8211; 5 minutes

			
				
			
		
We&#8217;re (stuck*) using maven on a project, and this means often the build doesn&#8217;t act like you&#8217;re expecting. Debugging requires knowledge about maven&#8217;s capabilities and less documented features. Here are some tips, please add more in the comments.

The -X flag shows debug logging, and tee it to a file which [...]]]></description>
			<content:encoded><![CDATA[<p>Reading time: 3 &#8211; 5 minutes</p>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fjawspeak.com%2F2010%2F05%2F14%2F12-tips-for-less-hate-of-maven%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=?url=http%3A%2F%2Fjawspeak.com%2F2010%2F05%2F14%2F12-tips-for-less-hate-of-maven%2F&amp;style=normal&amp;service=bit.ly" height="61" width="51" /><br />
			</a>
		</div>
<p>We&#8217;re (stuck*) using maven on a project, and this means often the build doesn&#8217;t act like you&#8217;re expecting. Debugging requires knowledge about maven&#8217;s capabilities and less documented features. Here are some tips, please add more in the comments.</p>
<ol>
<li>The <code>-X</code> flag shows debug logging, and tee it to a file which you then search for clues of what happened. This is great for verifying if a plugin actually ran, and what it did. Example: <code>mvn -X install | tee out.txt</code></li>
<li><code>mvn dependency:tree</code> (show the transitive dependencies of your dependencies) [1]</li>
<li><code>-Dtest=MyJavaTest</code> (just use the name of the class, no package necessary)</li>
<li><code>mvn help:system</code> (show environmental variables and system properties) [2]</li>
<li><code>mvn help:active-profiles</code> (show the active profiles to be run)</li>
<li><code>mvn help:all-profiles</code> (show all profiles maven reads)</li>
<li><code>mvn help:effective-pom</code> (show the logical pom.xml being used)</li>
<li><code>mvn help:effective-settings</code> (show the logical settings.xml which is being used)</li>
<li><code>mvn help:describe -DgroupId=org.apache.maven.plugins -DartifactId=maven-resources-plugin -Ddetail</code> (show details about a plugin&#8217;s options)</li>
<li><code>-DskipTests</code> this will skip running tests, but still compile it. or <code>-Dmaven.test.skip=true</code> which will skip compilation and execution of tests (use with judgment, <a href="http://jawspeak.com/category/testability/">I believe in testing</a>)</li>
<li>If <code>-X</code> doesn&#8217;t show you the properties when you needed them, you can also use the ant-run plugin to echo a property value (does anyone else know a better way to do this in maven? Tell me what a property value is at the time of the plugin or goal executing?)</li>
<li>Run your tests paused in debug mode, waiting for a debugger to attach to port 5005 with <tt>mvn -Dmaven.surefire.debug test</tt> [4]</li>
</ol>
<p>References:</p>
<ul>
<li> [1] <a href="http://maven.apache.org/plugins/maven-dependency-plugin/">http://maven.apache.org/plugins/maven-dependency-plugin/</a></li>
<li>[2] <a href="http://maven.apache.org/plugins/maven-help-plugin/">http://maven.apache.org/plugins/maven-help-plugin/</a></li>
<li>[3] <a href="http://cvs.peopleware.be/training/maven/maven2/debuggingPom.html">http://cvs.peopleware.be/training/maven/maven2/debuggingPom.html</a></li>
<li>[4] <a href="http://maven.apache.org/plugins/maven-surefire-plugin/examples/debugging.html">http://maven.apache.org/plugins/maven-surefire-plugin/examples/debugging.html</a></li>
<li><a href="http://puredanger.com/tech/2009/02/25/maven-tips/">http://puredanger.com/tech/2009/02/25/maven-tips/</a></li>
<li>Personal experience</li>
</ul>
<p>*Note: Initially I disliked the confusion and long, slow learning curve with maven. After working 8 months with maven and my colleagues <a href="http://lucas-ward.blogspot.com/">Lucas Ward</a> and <a href="http://paulhammant.com/">Paul Hammant</a>, I&#8217;m feeling much more comfortable and am generally okay with it. For small open source work, where you want a project quickly, but don&#8217;t want to spend a few hours with ant, I like it very much. For our large project, maven is fundamentally broken. Too much file copying is required, and manual intervention on a complex build is impossible, or extremely tedious. Running with our own build script we control could be dramatically more flexible.</p>
<p>On a mailing list Paul recently recommended a few other to consider:</p>
<blockquote><p><em>Maven Dependency plugin</em><br />
mvn dependency:tree<br />
- shows me the transitive deps (say, &#8220;how the hell is MX4J being dragged into the build ?&#8221;)<br />
mvn dependency:analyze<br />
- show me unused, but declared dependencies.<br />
There&#8217;s a ton of free capability to that plugin &#8211; <a href="http://maven.apache.org/plugins/maven-dependency-plugin/">http://maven.apache.org/plugins/maven-dependency-plugin/</a></p>
<p><em> An Atlassian dependency plugin</em><br />
Atlassian wrote a plugin ( <a href="http://confluence.atlassian.com/display/DEV/FedEx+XI+-+Keeping+track+of+you+maven+dependencies">http://confluence.atlassian.com/display/DEV/FedEx+XI+-+Keeping+track+of+you+maven+dependencies</a> ) that guards against undesired changing dependencies.</p>
<p><em> Maven Enforcer Plugin</em><br />
A more intrusive way of guarding against deps that, say, should not make it into a war. <a href="http://maven.apache.org/plugins/maven-enforcer-plugin/"> http://maven.apache.org/plugins/maven-enforcer-plugin/</a></p></blockquote>
<p>What tips do you have? Please share them in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://jawspeak.com/2010/05/14/12-tips-for-less-hate-of-maven/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Injecting HttpServletResponse into Spring MVC request scoped interceptors</title>
		<link>http://jawspeak.com/2010/05/06/injecting-httpservletresponse-into-spring-mvc-request-scoped-interceptors/</link>
		<comments>http://jawspeak.com/2010/05/06/injecting-httpservletresponse-into-spring-mvc-request-scoped-interceptors/#comments</comments>
		<pubDate>Fri, 07 May 2010 02:32:50 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[thoughtworks]]></category>

		<guid isPermaLink="false">http://jawspeak.com/?p=210</guid>
		<description><![CDATA[Reading time: 3 &#8211; 5 minutes

			
				
			
		
I&#8217;ve been heavily refactoring a large team&#8217;s codebase that stuffed many critical dependencies into request attributes. You see request.getAttribute() throughout the code, which is counter to dependency injection&#8217;s principles. Instead of getting what you want, be given it to you. We are moving to a more idiomatic way of using [...]]]></description>
			<content:encoded><![CDATA[<p>Reading time: 3 &#8211; 5 minutes</p>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fjawspeak.com%2F2010%2F05%2F06%2Finjecting-httpservletresponse-into-spring-mvc-request-scoped-interceptors%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=?url=http%3A%2F%2Fjawspeak.com%2F2010%2F05%2F06%2Finjecting-httpservletresponse-into-spring-mvc-request-scoped-interceptors%2F&amp;style=normal&amp;service=bit.ly" height="61" width="51" /><br />
			</a>
		</div>
<p>I&#8217;ve been heavily refactoring a large team&#8217;s codebase that stuffed many critical dependencies into request attributes. You see request.getAttribute() throughout the code, which is counter to dependency injection&#8217;s principles. Instead of getting what you want, be given it to you. We are moving to a more idiomatic way of using spring to inject things such as our custom Session object.</p>
<p>However, there was a lifecycle mismatch between some singleton interceptors which needed the session object, which is only request scoped. We had everything working, except one of those interceptors also needed the response object as a collaborator.</p>
<p>I had a spring instantiated non-controller bean that is request scoped, and I want to inject in two collaborators:</p>
<p>HttpServletRequest (which can be injected)<br />
HttpServletResponse (which fails injection)</p>
<p>Here is my bean:<br />
<code>&lt;bean id="sessionFactory" scope="request"&gt;<br />
&lt;aop:scoped-proxy/&gt; &lt;!-- scoped-proxy to get around the singleton requests injection of a request scoped object problem --&gt;<br />
&lt;/bean&gt;<br />
</code></p>
<p>Here are the autowired fields:<br />
<code>@Autowired HttpServletRequest request;<br />
@Autowired HttpServletResponse response;</code></p>
<p>Can I inject the response object in this bean?</p>
<p>This is the error I was getting:<br />
<small>[INFO] Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name &#8217;scopedTarget.sessionFactory&#8217;: Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Could not autowire field: javax.servlet.http.HttpServletResponse com.example.web.SessionRequiring$SessionFactory.re sponse; <strong>nested exception is org.springframework.beans.factory.NoSuchBeanDefini tionException: No unique bean of type [javax.servlet.http.HttpServletResponse] is defined: Unsatisfied dependency of type [interface javax.servlet.http.HttpServletResponse]: expected at least 1 matching bean</strong><br />
[INFO] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessAfterIn stantiation(AutowiredAnnotationBeanPostProcessor.j ava:243)<br />
</small></p>
<p>I navigated to <code>GenericWebApplicationContext</code>, which delegates to <code>WebApplicationContextUtils.registerWebApplicationS copes(beanFactory)</code>, which then registers <code>ServletRequest.class</code> and <code>HttpSession.class</code> as injectable. But not the response object.</p>
<p>So here&#8217;s what I did, which works for me:</p>
<p>In web.xml add a filter that will store every ServletResponse in a threadlocal, which will be accessible only from your FactoryBean.</p>
<pre dir="ltr">  &lt;filter&gt;
        &lt;filter-name&gt;responseInScopeFilter&lt;/filter-name&gt;
        &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;targetBeanName&lt;/param-name&gt;
            &lt;param-value&gt;responseInScopeFilter&lt;/param-value&gt;
        &lt;/init-param&gt;
  &lt;/filter&gt;
  &lt;filter-mapping&gt;
        &lt;filter-name&gt;responseInScopeFilter&lt;/filter-name&gt;
        &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  &lt;/filter-mapping&gt;</pre>
<p>Create the filter:</p>
<pre dir="ltr">
<pre dir="ltr">    /**
     * We need a filter to capture the HttpServletResponse object such that it can be injectable elsewhere in request scope.
     */
   public static class ResponseInScopeFilter implements Filter {
        // not the most elegant, but our spring commiter friends suggested this way.
        private ThreadLocal&lt;HttpServletResponse&gt; responses = new ThreadLocal&lt;HttpServletResponse&gt;();
        public void init(FilterConfig filterConfig) throws ServletException { }

        public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
            HttpServletResponse response = (HttpServletResponse) servletResponse;
            responses.set(response);
            chain.doFilter(servletRequest, servletResponse);
            responses.remove();
        }

        /** Only to be used by the BeanFactory */
        private HttpServletResponse getHttpServletResponse() {
            return responses.get();
        }

        public void destroy() { }
    }</pre>
</pre>
<p>And also create the FactoryBean:</p>
<pre dir="ltr">
<pre dir="ltr">/** We need our own FactoryBean because Spring does not offer a way to
     * inject request scoped HttpServletResponse objects.
     * See http://forum.springsource.org/showthread.php?p=298179#post298179 */
    public static class HttpServletResponseFactoryBean implements FactoryBean {
        @Autowired ResponseInScopeFilter responseInScopeFilter;

        public Object getObject() throws Exception {
            return responseInScopeFilter.getHttpServletResponse();
        }

        public Class getObjectType() {
            return HttpServletResponse.class;
        }

        public boolean isSingleton() {
            return false;
        }
    }</pre>
</pre>
<p>Wire it all together in applicationContext.xml</p>
<pre dir="ltr">&lt;bean id="httpServletResponse" class="com.example.web.SessionRequiring$HttpServletResponseFactoryBean" scope="request"/&gt;
&lt;bean id="responseInScopeFilter" class="com.example.web.SessionRequiring$ResponseInScopeFilter"/&gt;
</pre>
<p>Elsewhere I can now inject an HttpServletResponse object and it will be request scoped appropriately for this request. You can read more about this in my post on the <a href="http://forum.springsource.org/showthread.php?p=298184#post298184">spring forums</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://jawspeak.com/2010/05/06/injecting-httpservletresponse-into-spring-mvc-request-scoped-interceptors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>maven + growlnotify for notification when your build finishes</title>
		<link>http://jawspeak.com/2009/12/31/maven-growlnotify-for-notification-when-your-build-finishes/</link>
		<comments>http://jawspeak.com/2009/12/31/maven-growlnotify-for-notification-when-your-build-finishes/#comments</comments>
		<pubDate>Thu, 31 Dec 2009 18:23:12 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[automation]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[maven]]></category>

		<guid isPermaLink="false">http://jawspeak.com/?p=154</guid>
		<description><![CDATA[Reading time: 1 &#8211; 2 minutes

			
				
			
		
Working on os x with Spaces means I want to read something on another space instead of waiting idly for a 50 second build. But, I don&#8217;t want to get distracted. So, I use Growl and growlnotify for notifications of the build&#8217;s completion.
#!/bin/sh
# this file is called: mvn (and is [...]]]></description>
			<content:encoded><![CDATA[<p>Reading time: 1 &#8211; 2 minutes</p>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fjawspeak.com%2F2009%2F12%2F31%2Fmaven-growlnotify-for-notification-when-your-build-finishes%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=?url=http%3A%2F%2Fjawspeak.com%2F2009%2F12%2F31%2Fmaven-growlnotify-for-notification-when-your-build-finishes%2F&amp;style=normal&amp;service=bit.ly" height="61" width="51" /><br />
			</a>
		</div>
<p>Working on os x with Spaces means I want to read something on another space instead of waiting idly for a 50 second build. But, I don&#8217;t want to get distracted. So, I use <a href="http://growl.info/">Growl</a> and <a href="http://growl.info/documentation/growlnotify.php">growlnotify</a> for notifications of the build&#8217;s completion.</p>
<pre>#!/bin/sh
# this file is called: mvn (and is executable, and added to path before actual mvn command)

# capture all args passed in to forward to real mvn
ARGS=$*

# We need the client's specific settings.xml, so always specify it now
/usr/bin/mvn -s /Volumes/TrueCryptClient/opt/maven/conf/settings.xml $ARGS 

# when you have growlnotify installed and on your path, this will pop it up
# when the build is done
growlnotify -m "DONE: maven $ARGS"
</pre>
<p>Note: if you get this error from growlnotify: <tt>could not find local GrowlApplicationBridgePathway, falling back to NSDNC</tt>, it probably means growl is not started. Start up growl in your System Preferences.</p>
<p><strong>Update:</strong> Thanks Cosmin, for the enhancement. Use this snipped in the script. Have an environmental variable for what the notify command is. And say what the build status is in the growl notify.:</p>
<pre>if [[ -n $NOTIFY ]]; then
    ($command &amp;&amp; $NOTIFY "Build Complete" &amp;&amp; exit 0) || ($NOTIFY "Build Failed" &amp;&amp; exit 127)
else
    $command
fi
</pre>
]]></content:encoded>
			<wfw:commentRss>http://jawspeak.com/2009/12/31/maven-growlnotify-for-notification-when-your-build-finishes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Can you spot Java Puzzler in this snippet?</title>
		<link>http://jawspeak.com/2009/09/30/can-you-spot-java-puzzler-in-this-snippet/</link>
		<comments>http://jawspeak.com/2009/09/30/can-you-spot-java-puzzler-in-this-snippet/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 19:51:17 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[puzzle]]></category>

		<guid isPermaLink="false">http://jawspeak.com/?p=125</guid>
		<description><![CDATA[Reading time: 2 &#8211; 2 minutes

			
				
			
		
I ran across this last week. It was marvelous when we saw what was happening, but entirely puzzling at first.

Boolean someFlag = complicatedLogicToFigureOutFlag&#40;&#41;;
Person person = new Person&#40;someFlag&#41;;

Any signs for concern? How about if Person&#8217;s constructor is:

Person&#40;boolean someFlag&#41; &#123;
    this.someFlag = someFlag;
&#125;

Any warning signs?
Will it compile?
Read more for [...]]]></description>
			<content:encoded><![CDATA[<p>Reading time: 2 &#8211; 2 minutes</p>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fjawspeak.com%2F2009%2F09%2F30%2Fcan-you-spot-java-puzzler-in-this-snippet%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=?url=http%3A%2F%2Fjawspeak.com%2F2009%2F09%2F30%2Fcan-you-spot-java-puzzler-in-this-snippet%2F&amp;style=normal&amp;service=bit.ly" height="61" width="51" /><br />
			</a>
		</div>
<p>I ran across this last week. It was marvelous when we saw what was happening, but entirely puzzling at first.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">Boolean</span> someFlag <span style="color: #339933;">=</span> complicatedLogicToFigureOutFlag<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Person person <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Person<span style="color: #009900;">&#40;</span>someFlag<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Any signs for concern? How about if Person&#8217;s constructor is:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">Person<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">boolean</span> someFlag<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">someFlag</span> <span style="color: #339933;">=</span> someFlag<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Any warning signs?</p>
<p>Will it compile?</p>
<p>Read more for the full puzzler.</p>
<p><span id="more-125"></span></p>
<p>If you didn&#8217;t see a warning sign, but said it would compile &#8212; you&#8217;re half right. It will compile, but there&#8217;s a great big NullPointer waiting for you depending on the value of someFlag. Because autoboxing was a shim initially slid into Java 1.5, this will compile:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">Boolean</span> someFlag <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
Person person <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Person<span style="color: #009900;">&#40;</span>someFlag<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// will compile, but then NPE ambiguously</span></pre></div></div>

<p>But at runtime, it will fail ambiguously with a Null Pointer on the line of the constructor.</p>
<p>Of course, this will not compile:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">Person person <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Person<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// won't compile because signature is boolean</span></pre></div></div>

<p>My pair and I saw this in a test with a particularly ugly constructor with 12 parameters. We were following <a href="http://misko.hevery.com/2009/02/09/to-assert-or-not-to-assert/">Misko</a>&#8217;s style of &#8220;use nulls in tests, but not in production code&#8221; and thus that Boolean was ending up as null. By binary search we identified which parameter caused the trouble, initialized it to false instead of null, and then shared our &#8220;Ah Ha!&#8221; moment with several other engineers around the office.</p>
<p>Should something like this be an interview question you ask a candidate? Maybe if they are doing great on all other fronts, and you&#8217;re curious how well they understand the intricacies of Java. But I don&#8217;t generally like obscure fact questions because in real life we just figure them out. So, yes I would use this in an interview where we are pairing, so I could watch the candidate troubleshoot.</p>
]]></content:encoded>
			<wfw:commentRss>http://jawspeak.com/2009/09/30/can-you-spot-java-puzzler-in-this-snippet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to do 3-way merges with Subversion and Kdiff3</title>
		<link>http://jawspeak.com/2009/09/17/how-to-do-3-way-merges-with-subversion-and-kdiff3/</link>
		<comments>http://jawspeak.com/2009/09/17/how-to-do-3-way-merges-with-subversion-and-kdiff3/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 01:49:37 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[automation]]></category>
		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://jawspeak.com/?p=140</guid>
		<description><![CDATA[Reading time: 4 &#8211; 6 minutes

			
				
			
		
I do not endorse branch based development. I prefer trunk based development. Specifically I like what my colleague Paul calls Branch By Abstraction, coined by Stacy Curl, and recently mentioned by Martin Fowler (All one time ThoughtWorkers, and 2 currently).
If you&#8217;re stuck with merging though, 3-way merges make it much [...]]]></description>
			<content:encoded><![CDATA[<p>Reading time: 4 &#8211; 6 minutes</p>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fjawspeak.com%2F2009%2F09%2F17%2Fhow-to-do-3-way-merges-with-subversion-and-kdiff3%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=?url=http%3A%2F%2Fjawspeak.com%2F2009%2F09%2F17%2Fhow-to-do-3-way-merges-with-subversion-and-kdiff3%2F&amp;style=normal&amp;service=bit.ly" height="61" width="51" /><br />
			</a>
		</div>
<p>I do not endorse branch based development. I prefer trunk based development. Specifically I like what my colleague Paul calls <a href="http://paulhammant.com/blog/branch_by_abstraction.html">Branch By Abstraction</a>, coined by <a href="http://digital-compulsion.blogspot.com/2007/04/branching-by-abstraction.html">Stacy Curl</a>, and recently mentioned by <a href="http://martinfowler.com/bliki/FeatureBranch.html">Martin Fowler</a> (All one time <a href="http://ThoughtWorks.com">ThoughtWorkers</a>, and 2 currently).</p>
<p>If you&#8217;re stuck with merging though, 3-way merges make it much easier. Doing it with subversion is easy. Instructions are for Linux.</p>
<ol>
<li>apt-get or yum install kdiff3.</li>
<li>Edit your <tt>/etc/subversion/config</tt> and fin the line with <tt>diff3-cmd</tt>, set it to: <tt>diff3-cmd=/usr/local/bin/svndiff.sh</tt></li>
<li>Next, create the file <tt>/usr/local/bin/svndiff.sh</tt>. See below for the script you&#8217;ll want to enter in it.</li>
</ol>
<p>Now when you get a merge conflict you will choose <tt>M</tt> and merge will open in kdiff3. On the left is the base revision, in the middle is your working copy, and on the right the incoming change. This is a little more to look at, but it is invaluable when dealing with merges. I wouldn&#8217;t go back to 2 way diff ever again.</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">#!/bin/bash
&nbsp;
# tim/paul: this is a copy of the file located at http://www.yolinux.com/TUTORIALS/src/svndiffwrapper.txt
#    modified to do a non-conflicting merge automatically. see #HERE#
&nbsp;
# Return an errorcode of 0 on successful merge, 1 if unresolved conflicts
# remain in the result.  Any other errorcode will be treated as fatal.
# Author: Michael Bradley
&nbsp;
#NOTE: all output must be redirected to stderr with &quot;1&gt;&amp;2&quot; as all stdout output is written to the output file
&nbsp;
VDIFF3=&quot;kdiff3&quot;
DIFF3=&quot;diff3&quot; 
DIFF=&quot;kdiff3&quot;  
&nbsp;
promptUser ()
{
    read answer
    case &quot;${answer}&quot; in
&nbsp;
        &quot;M&quot;         ) 
        echo &quot;&quot; 1&gt;&amp;2
        echo &quot;Attempting to merge ${baseFileName} with ${DIFF}&quot; 1&gt;&amp;2
        $VDIFF3 $older $mine $theirs --L1 $labelOlder --L2 $labelMine --L3 $labelTheirs -o $output 1&gt;&amp;2
        bLoop=1
        if [ -f $output ]; then
            if [ -s $output ]; then
                #output succesfully written
                bLoop=0
            fi
        fi
        if [ $bLoop = 0 ]; then
            cat $output
            rm -f $output
            exit 0
        else
            echo &quot;Merge failed, try again&quot; 1&gt;&amp;2
        fi
&nbsp;
        ;;
&nbsp;
        &quot;m&quot;         ) 
        echo &quot;&quot; 1&gt;&amp;2
        echo &quot;Attempting to auto-merge ${baseFileName}&quot; 1&gt;&amp;2
        diff3 -L $labelMine -L $labelOlder -L $labelTheirs -Em $mine $older $theirs &gt; $output
        if [ $? = 1 ]; then
            #Can't auto merge
            rm -f $output
            $VDIFF3 $older $mine $theirs --L1 $labelOlder --L2 $labelMine --L3 $labelTheirs -o $output --auto 1&gt;&amp;2
            bLoop=1
            if [ -f $output ]; then
                if [ -s $output ]; then
                    #output succesfully written
                    bLoop=0
                fi
            fi
            if [ $bLoop = 0 ]; then
                cat $output
                rm -f $output
                exit 0
            else
                echo &quot;Merge failed, try again&quot; 1&gt;&amp;2
            fi
        else
            #We can automerge, and we already did it
            cat $output
            rm -f $output
            exit 0
        fi
        ;;
&nbsp;
        &quot;diff3&quot; | &quot;Diff3&quot; | &quot;DIFF3&quot;  )
        echo &quot;&quot; 1&gt;&amp;2
        echo &quot;Diffing...&quot; 1&gt;&amp;2
        $VDIFF3 $older $mine $theirs --L1 $labelOlder --L2 $labelMine --L3 $labelTheirs 1&gt;&amp;2
        ;;
&nbsp;
        &quot;diff&quot; | &quot;Diff&quot; | &quot;DIFF&quot;  )
        echo &quot;&quot; 1&gt;&amp;2
        echo &quot;Diffing...&quot; 1&gt;&amp;2
        $DIFF $mine $theirs -L $labelMine -L $labelTheirs 1&gt;&amp;2
        ;;
&nbsp;
        &quot;A&quot; | &quot;a&quot;   ) 
        echo &quot;&quot; 1&gt;&amp;2
        echo &quot;Accepting remote version of file...&quot; 1&gt;&amp;2
        cat ${theirs}
        exit 0
        ;;
&nbsp;
        &quot;I&quot; | &quot;i&quot;   ) 
        echo &quot;&quot; 1&gt;&amp;2
        echo &quot;Keeping local modifications...&quot; 1&gt;&amp;2
        cat ${mine}
        exit 0
        ;;
&nbsp;
        &quot;R&quot; | &quot;r&quot;   ) 
        echo &quot;&quot; 1&gt;&amp;2
        echo &quot;Reverting to base...&quot; 1&gt;&amp;2
        cat ${older}
        exit 0
        ;;
&nbsp;
        &quot;D&quot; | &quot;d&quot;   ) 
        echo &quot;&quot; 1&gt;&amp;2
        echo &quot;Runnig diff3...&quot; 1&gt;&amp;2
        diff3 -L $labelMine -L $labelOlder -L $labelTheirs -Em $mine $older $theirs
        #Exit with return vaule of the diff3 (to write out files if necessary)
        exit $?
        ;;
&nbsp;
        &quot;S&quot; | &quot;s&quot;   ) 
        echo &quot;&quot; 1&gt;&amp;2
        echo &quot;Saving for later...&quot; 1&gt;&amp;2
        cat ${mine}
        #Exit with return vaule of 1 to force writting of files
        exit 1
        ;;
&nbsp;
        &quot;Fail&quot; | &quot;fail&quot; | &quot;FAIL&quot;   ) 
        echo &quot;&quot; 1&gt;&amp;2
        echo &quot;Failing...&quot; 1&gt;&amp;2 
        exit 2
        ;;
&nbsp;
        &quot;H&quot; | &quot;h&quot;   ) 
        echo &quot;&quot; 1&gt;&amp;2
        echo &quot;USAGE OPTIONS:&quot; 1&gt;&amp;2 
        echo &quot;  [A]ccept    Accept $labelTheirs and throw out local modifications&quot; 1&gt;&amp;2
        echo &quot;  [D]efault   Use diff3 to merge files (same behavior as vanilla SVN)&quot; 1&gt;&amp;2
        echo &quot;  [Fail]      Kills the command (not suggested)&quot; 1&gt;&amp;2
        echo &quot;  [H]elp      Print this message&quot; 1&gt;&amp;2
        echo &quot;  [I]gnore    Keep your locally modified version as is&quot; 1&gt;&amp;2
        echo &quot;  [M]erge     Manually merge using ${VDIFF3}&quot; 1&gt;&amp;2
        echo &quot;  [m]erge     Same as &quot;M&quot; but attempts to automerge if possible&quot; 1&gt;&amp;2
        echo &quot;  [R]evert    Revert to base version (${labelOlder})&quot; 1&gt;&amp;2
        echo &quot;  [S]ave      Same as 'I' but writes out rold, rnew, and rmine files to deal with later&quot; 1&gt;&amp;2
        echo &quot;  [diff]      Type 'diff' to diff versions $labelMine and $labelTheirsthe before making a descision&quot; 1&gt;&amp;2
        echo &quot;  [diff3]     Type 'diff3' to diff all three versions before making a descision&quot; 1&gt;&amp;2
        echo &quot;&quot; 1&gt;&amp;2
        ;;
&nbsp;
        *   ) 
        echo &quot;'${answer}' is not an option, try again.&quot; 1&gt;&amp;2
        ;;
    esac 
}
&nbsp;
if [ -z $2 ]
then
    echo ERROR: This script expects to be called by subversion
    exit 1
fi
&nbsp;
if [ $2 = &quot;-m&quot; ]
then
    #Setup vars
    labelMine=${4}
    labelOlder=${6}
    labelTheirs=${8}
    mine=${9}
    older=${10}
    theirs=${11}
    output=${9}.svnDiff3TempOutput
    baseFileName=`echo $mine | sed -e &quot;s/.tmp$//&quot;`
&nbsp;
&nbsp;
#HERE#
    diff3 -L $labelMine -L $labelOlder -L $labelTheirs -Em $mine $older $theirs &gt; $output
    if [ $? = 1 ]; then
        #Can't auto merge
        #Prompt user for direction
        while [ 1 ]
        do
            echo &quot;&quot; 1&gt;&amp;2
            echo &quot;${baseFileName} requires merging.&quot; 1&gt;&amp;2 
            echo &quot;&quot; 1&gt;&amp;2
            echo &quot;What would you like to do?&quot; 1&gt;&amp;2
            echo &quot;[M]erge [A]ccept [I]gnore [R]evert [D]efault [H]elp&quot; 1&gt;&amp;2 
            promptUser
        done
    else
        #We can automerge, and we already did it
        cat $output
        rm -f $output
        exit 0
    fi
else
    L=&quot;-L&quot;         #Argument option for left label
    R=&quot;-L&quot;         #Argument option for right label
    label1=$3       #Left label
    label2=$5       #Right label
    file1=$6        #Left file
    file2=$7        #Right file
&nbsp;
    $DIFF $file1 $file2 $L &quot;$label1&quot; $L &quot;$label2&quot; &amp;
    #$DIFF $file1 $file2 &amp;
    #wait for the command to finish
    wait
fi
exit 0</pre></div></div>

<p>Note: I also posted this to a gist on github: <a href="http://gist.github.com/188824">svndiff.sh</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://jawspeak.com/2009/09/17/how-to-do-3-way-merges-with-subversion-and-kdiff3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Large Web App Architecture: Yes to Thicker Stack on One Hardware Node, No to Beautiful &#8220;Redundant&#8221; Spiderwebs</title>
		<link>http://jawspeak.com/2009/08/19/large-web-app-architecture-yes-to-thicker-stack-on-one-hardware-node-no-to-beautiful-redundant-spiderwebs/</link>
		<comments>http://jawspeak.com/2009/08/19/large-web-app-architecture-yes-to-thicker-stack-on-one-hardware-node-no-to-beautiful-redundant-spiderwebs/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 05:55:21 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[architecture]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[scalability]]></category>

		<guid isPermaLink="false">http://jawspeak.com/?p=118</guid>
		<description><![CDATA[Reading time: 4 &#8211; 7 minutes

			
				
			
		
My last client our team worked with had a large ecommerce operation. Yearly revenue in the new site is in the high single digit billions of dollars. This necessitates extremely high availability. I will draw an initially favorable looking configuration for this high availability (&#8220;beautiful spiderwebs&#8221;), but then tear it [...]]]></description>
			<content:encoded><![CDATA[<p>Reading time: 4 &#8211; 7 minutes</p>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fjawspeak.com%2F2009%2F08%2F19%2Flarge-web-app-architecture-yes-to-thicker-stack-on-one-hardware-node-no-to-beautiful-redundant-spiderwebs%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=?url=http%3A%2F%2Fjawspeak.com%2F2009%2F08%2F19%2Flarge-web-app-architecture-yes-to-thicker-stack-on-one-hardware-node-no-to-beautiful-redundant-spiderwebs%2F&amp;style=normal&amp;service=bit.ly" height="61" width="51" /><br />
			</a>
		</div>
<p>My last client our team worked with had a large ecommerce operation. Yearly revenue in the new site is in the high single digit billions of dollars. This necessitates extremely high availability. I will draw an initially favorable looking configuration for this high availability (&#8220;beautiful spiderwebs&#8221;), but then tear it apart and suggest an alternative (&#8220;Thicker Stack on One Hardware&#8221;).</p>
<h3>1. &#8220;Beautiful Spiderwebs&#8221; &#8211; Often Not Recommended</h3>
<p>Here&#8217;s one common way people could implement high availability. Notice how there are always multiple routes available for servicing a request. If one BIG IP goes down, there is another to help. And this could be doubled with multiple data centers, failed over with DNS.</p>
<p>The visible redundancy and complexity in one diagram may be appealing. One can run through scenarios in order to make sure that yes, we can actually survive any failure and the ecommerce will not stop.</p>
<p><a title="not recommended spiderweb tiers by JAWspeak, on Flickr" href="http://www.flickr.com/photos/jawspeak/3836184306/"><img src="http://farm3.static.flickr.com/2588/3836184306_96e6a18f29.jpg" alt="not recommended spiderweb tiers" width="443" height="500" /></a></p>
<p>So then what could make this my <em>Not Recommended </em>option?<em><br />
</em></p>
<h3>2. Martin&#8217;s Reminder how to Think About Nodes</h3>
<p>Fowler reminded us in <a href="http://www.amazon.com/gp/product/0321127420?ie=UTF8&amp;tag=econtechblog-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0321127420">Patterns of Enterprise Application Architecture</a> how to look at distribution and tiers. For some reason people keep wanting to have certain &#8220;machines running certain services&#8221; and <em>just</em> make a <em>few</em> service calls to stitch up all the services you need. If you&#8217;re concerned about performance, though, you&#8217;re a looking for punishment. Remote calls are several orders of magnitude greater than in process, or calls within the same machine. And this architectural preference is rarely necessary.</p>
<p>One might lead to the first design with the logic of: &#8220;We can run each component on a separate box. If one component gets too busy we add extra boxes for it so we can load-balance our app.&#8221; Is that a good idea?</p>
<p><a title="fowler distributed objects not recommended by JAWspeak, on Flickr" href="http://www.flickr.com/photos/jawspeak/3835392251/"><img src="http://farm3.static.flickr.com/2551/3835392251_d4824c236f.jpg" alt="fowler distributed objects not recommended" width="500" height="299" /></a></p>
<p>The above is not recommended:</p>
<blockquote><p>A procedure call between two separate processes is orders of magnitude slower [than in-process]. Make that a process running on another machine and you can add another order of magnitude or two, depending on the network topography involved. [PoEAA Ch 7]</p></blockquote>
<p>This leads into his <em>First Law of Distributed Object Design: Don&#8217;t distribute your objects!</em></p>
<p>The solution?</p>
<blockquote><p>Put all the classes into a single process and then run multiple copies of that process on the various nodes. That way each process uses local calls to get the job done and thus does things faster. You can also use fine- grained interfaces for all the classes within the process and thus get better maintainability with a simpler programming model. [PoEAA Ch 7]</p></blockquote>
<p><a title="fowler clustered application recommended by JAWspeak, on Flickr" href="http://www.flickr.com/photos/jawspeak/3835392281/"><img src="http://farm4.static.flickr.com/3580/3835392281_35920eff8d.jpg" alt="fowler clustered application recommended" width="463" height="307" /></a></p>
<h3>3. &#8220;Strive for Thicker Stack on One Hardware Node&#8221; &#8211; Recommended</h3>
<p>Observe the recommended approach below. There is still an external load balancer, but after a request is routed to an Apache/Nginx/etc front end, you&#8217;re all on one* machine.</p>
<p>If one tier fails on a node, pull the whole node out from rotation. Replace it. And re-enter it in the mix.</p>
<p>Your companies teams have worked together to be able to deploy modular services. So when your ecommerce site needs a merchant gateway processing service, you can include that (library or binary) and run it locally on your node, making a call through to it as needed.</p>
<p>Services are also simpler to deploy, upgrade and monitor as there are fewer processes and fewer differently-configured machines.</p>
<p><a title="recommended thicker nodes tiers by JAWspeak, on Flickr" href="http://www.flickr.com/photos/jawspeak/3835392219/"><img src="http://farm3.static.flickr.com/2525/3835392219_88ca43602b.jpg" alt="recommended thicker nodes tiers" width="500" height="429" /></a></p>
<p>(* I understand there may be the occasional exception for remote calls that need to be made to other machines. Possibly databases, mcached obviously third party hosted services, but the point is <em>most everything else</em> need not be remote.)</p>
<h3>4. But, Practically Speaking How Far Do We Go?</h3>
<p>A caveat first: these benefits get pronounced as you have more and more nodes. (And thus, more and more complex of spiderwebs of unnecessary failover).</p>
<p>Should there be a database server running on each node? Probably not at first. There is a maintenance associated with that. But after sharding your database and running with replication, why not? This way if a node fails, you simply pull it out and replace it with a functioning one.</p>
<h3>5. Checklist of Takeaway Lessons</h3>
<ol>
<li>Keep it local. Local calls orders of magnitude faster than remote calls.</li>
<li>Make services modular so they don&#8217;t need to be remote, yet still have all the organizational benefits of separate teams.</li>
<li>Simplicity in node-level-redundancy is preferred over tier-level-redundancy.</li>
</ol>
<p>Often, people think of high availability with terms such as the following: <a href="http://en.wikipedia.org/wiki/Round-robin_scheduling">Round Robin</a>, <a href="http://en.wikipedia.org/wiki/Load_balancing_%28computing%29">Load Balancing</a>, and <a href="http://en.wikipedia.org/wiki/Failover">Failover</a>. What do you think of? Leave a comment below with how you meet the trade-offs of designing for HA as well as architectural decisions of low latency.</p>
]]></content:encoded>
			<wfw:commentRss>http://jawspeak.com/2009/08/19/large-web-app-architecture-yes-to-thicker-stack-on-one-hardware-node-no-to-beautiful-redundant-spiderwebs/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>What is grad school for a consultant (or practicing software engineer)</title>
		<link>http://jawspeak.com/2009/08/10/what-is-grad-school-for-a-consultant-or-practicing-software-engineer/</link>
		<comments>http://jawspeak.com/2009/08/10/what-is-grad-school-for-a-consultant-or-practicing-software-engineer/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 00:21:47 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[career]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[gradschool]]></category>

		<guid isPermaLink="false">http://jawspeak.com/?p=113</guid>
		<description><![CDATA[Reading time: 2 &#8211; 4 minutes

			
				
			
		
Does it make sense for practicing software engineer to go to grad school? Technologies change rapidly, and so do our clients and projects. So we have constant opportunities to learn and most importantly to apply ourselves in building production systems. Bonus: putting production systems live into the world teaches a [...]]]></description>
			<content:encoded><![CDATA[<p>Reading time: 2 &#8211; 4 minutes</p>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fjawspeak.com%2F2009%2F08%2F10%2Fwhat-is-grad-school-for-a-consultant-or-practicing-software-engineer%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=?url=http%3A%2F%2Fjawspeak.com%2F2009%2F08%2F10%2Fwhat-is-grad-school-for-a-consultant-or-practicing-software-engineer%2F&amp;style=normal&amp;service=bit.ly" height="61" width="51" /><br />
			</a>
		</div>
<p>Does it make sense for practicing software engineer to go to grad school? Technologies change rapidly, and so do our clients and projects. So we have constant opportunities to learn <em>and most importantly</em> to apply ourselves in building production systems. Bonus: putting production systems live into the world teaches a lot more than a good grade in an exam.</p>
<p>I once remember in undergrad my friend getting an offer at Microsoft, but he was torn on going to grad school. Basically his sponsor there told him graduate degrees aren&#8217;t worth much, and I&#8217;d go so far as to suggest that they <em>can be</em> less useful than <em>varied and interesting real project work</em>.</p>
<blockquote><p><em>&#8220;Sure, go to cs grad school if it makes your ego feel better, but don&#8217;t do it for your career.&#8221;</em></p></blockquote>
<p>Oh?, my friend said, and if my memory serves me, he went on to grad school.</p>
<p>Everyone&#8217;s situation <em>is </em>different. However this is something I&#8217;ve struggled with for the last several years: does it make sense to step back and do research, and to do computer science-y things instead of day to day project delivery? Maybe. Maybe not. I&#8217;ve more or less made my decision for now. But every few months the nagging urge comes back.</p>
<p>I found these posts helpful for framing my decisions.</p>
<ol>
<li><a rel="nofollow" href="http://jxyzabc.blogspot.com/2008/08/cs-grad-school-part-1-deciding-to-apply.html">http://jxyzabc.blogspot.com/2008/08/cs-grad-school-part-1-deciding-to-apply.html</a> (the whole multi-part series, actually)</li>
<li><a rel="nofollow" href="http://www.stanford.edu/%7Epgbovine/grad-school-app-tips.htm">http://www.stanford.edu/~pgbovine/grad-school-app-tips.htm</a> &#8211; says how it is all about research, and really Ph.D. applications are a job application, where you are applying to do research, rather than a place to be taught. (MBA, Med School, and other higher education avenues are a place you pay to be taught.) Masters degrees are different, but generally still have the same theme &#8220;you&#8217;re getting paid, so you better love (your) research.&#8221;</li>
</ol>
<p><strong>Update: <a href="http://www.markhneedham.com/blog/">Mark </a></strong><a href="http://www.markhneedham.com/blog/"><strong>Needham</strong></a><strong> </strong><strong>commented about two pointed posts from Penelope Trunk&#8217;s blog. Worth reading.<br />
</strong></p>
<ol>
<li><a href="http://blog.penelopetrunk.com/2008/06/18/seven-reasons-why-graduate-school-is-outdated">http://blog.penelopetrunk.com/2008/06/18/seven-reasons-why-graduate-school-is-outdated</a><br />
Grad School isn&#8217;t needed, and it causes more harm than good. Too much focus. Careers change too much. Experience trumps prolonged childlike academic sheltering. (Note: My opinion isn&#8217;t so harsh. <em>Your</em> grad school might not apply, it depends on what you want to do).</li>
<li><a onclick="javascript:pageTracker._trackPageview('/outbound/comment/blog.penelopetrunk.com');" rel="nofollow" href="http://blog.penelopetrunk.com/2009/02/03/dont-try-to-dodge-the-recession-with-grad-school/">http://blog.penelopetrunk.com/2009/02/03/dont-try-to-dodge-the-recession-with-grad-school/</a><br />
She prefers learning by doing, and suggests a feeling of &#8220;being lost&#8221; is actually helpful for growing.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://jawspeak.com/2009/08/10/what-is-grad-school-for-a-consultant-or-practicing-software-engineer/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
