<?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>Molindo Techblog &#187; Java</title>
	<atom:link href="http://techblog.molindo.at/category/java/feed" rel="self" type="application/rss+xml" />
	<link>http://techblog.molindo.at</link>
	<description>Molindo Techblog - formerly known as talk-on-tech.blogspot.com</description>
	<lastBuildDate>Fri, 05 Feb 2010 16:06:12 +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>wicketstuff-merged-resources: 2.1 and 3.0 released!</title>
		<link>http://techblog.molindo.at/2010/02/wicketstuff-merged-resources-2-1-and-3-0-released.html</link>
		<comments>http://techblog.molindo.at/2010/02/wicketstuff-merged-resources-2-1-and-3-0-released.html#comments</comments>
		<pubDate>Fri, 05 Feb 2010 13:57:34 +0000</pubDate>
		<dc:creator>Stefan Fußenegger</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Wicket]]></category>
		<category><![CDATA[wicketstuff-merged-resources]]></category>

		<guid isPermaLink="false">http://techblog.molindo.at/?p=172</guid>
		<description><![CDATA[I&#8217;m happy to announce the releases of wicketstuff-merged-resources 2.1 and 3.0.
Changes from 2.0 to 2.1 (Wicket 1.3.x):

Annotation-based Mounting of Resources
[WMR-7] Failure to load resources if this library is provided in a parent classloader
[WMR-9] Make it possible to define some sort of order in the way files are included in the overall file
[WMR-10] wicketstuff-merged-resources does not [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m happy to announce the releases of <a href="http://wicketstuff.org/confluence/display/STUFFWIKI/wicketstuff-merged-resources" target="_blank">wicketstuff-merged-resources</a> 2.1 and 3.0.</p>
<p><span id="more-172"></span><strong>Changes from 2.0 to 2.1 (Wicket 1.3.x):</strong></p>
<ul>
<li><a href="http://techblog.molindo.at/2009/10/wicket-annotation-based-mounting-of-resources.html">Annotation-based Mounting of Resources</a></li>
<li><a href="http://wicketstuff.org/jira/browse/WMR-7" target="_blank">[WMR-7] Failure to load resources if this library is provided in a parent classloader</a></li>
<li><a href="http://wicketstuff.org/jira/browse/WMR-9" target="_blank">[WMR-9] Make it possible to define some sort of order in the way files are included in the overall file</a></li>
<li><a href="http://wicketstuff.org/jira/browse/WMR-10" target="_blank">[WMR-10] wicketstuff-merged-resources does not compile; missing jetty plugin artifact</a></li>
<li>and a few minor bug fixes and performance improvements: <a href="http://fisheye3.atlassian.com/changelog/~branchConstraint=wicket-1.3.x,startDate=2009-08-24T00:00:00,endDate=2010-02-02T23:59:59/wicket-stuff/branches/wicket-1.3.x/wicketstuff-merged-resources" target="_blank">See full FishEye Activity report</a></li>
</ul>
<p>(Note: <a href="http://wicketstuff.org/jira/browse/WMR-12" target="_blank">[WMR-12]</a> and <a href="http://wicketstuff.org/jira/browse/WMR-14" target="_blank">[WMR-14]</a> already went into <a href="http://wicketstuff.org/maven/repository/org/wicketstuff/wicketstuff-merged-resources/2.2-SNAPSHOT/" target="_blank">2.2-SNAPSHOT</a>)</p>
<p><strong>Changes for 3.0 (Wicket 1.4.x):</strong></p>
<ul>
<li><a href="http://techblog.molindo.at/2009/10/wicket-annotation-based-mounting-of-resources.html">Annotation-based Mounting of Resources</a></li>
<li><a href="http://wicketstuff.org/jira/browse/WMR-6" target="_blank">[WMR-6] Compatibility to wicket 1.4</a></li>
<li><a href="http://wicketstuff.org/jira/browse/WMR-7" target="_blank">[WMR-7] Failure to load resources if this library is provided in a parent classloader</a></li>
<li><a href="http://wicketstuff.org/jira/browse/WMR-7" target="_blank"></a><a href="http://wicketstuff.org/jira/browse/WMR-9">[WMR-9] Make it possible to define some sort of order in the way files are included in the overall file</a></li>
<li><a href="http://wicketstuff.org/jira/browse/WMR-9" target="_blank"></a><a href="http://wicketstuff.org/jira/browse/WMR-10">[WMR-10] wicketstuff-merged-resources does not compile; missing jetty plugin artifact</a></li>
<li><a href="http://wicketstuff.org/jira/browse/WMR-12" target="_blank">[WMR-12] Allow CSS media to be specified in ResourceMount, and honored by build()</a></li>
<li><a href="http://wicketstuff.org/jira/browse/WMR-14" target="_blank">[WMR-14] Error detection for adding CSS and JavaScript resources to ResourceMount</a></li>
<li>and a few minor bug fixes and performance improvements: <a href="http://fisheye3.atlassian.com/changelog/~branchConstraint=trunk,startDate=2009-08-06T00:00:00,endDate=2010-02-05T23:59:59/wicket-stuff/trunk/wicketstuff-merged-resources" target="_blank">See full FishEye Activity report</a></li>
</ul>
<p><strong>Downloads:</strong></p>
<ul>
<li>wicketstuff-merged-resources 2.1: <a href="http://wicketstuff.org/maven/repository/org/wicketstuff/wicketstuff-merged-resources/2.1/wicketstuff-merged-resources-2.1.jar" target="_blank">Jar</a> <a href="http://wicketstuff.org/maven/repository/org/wicketstuff/wicketstuff-merged-resources/2.1/wicketstuff-merged-resources-2.1-sources.jar" target="_blank">Sources</a></li>
<li>wicketstuff-merged-resources 3.0: <a href="http://wicketstuff.org/maven/repository/org/wicketstuff/wicketstuff-merged-resources/3.0/wicketstuff-merged-resources-3.0.jar" target="_blank">Jar</a> <a href="http://wicketstuff.org/maven/repository/org/wicketstuff/wicketstuff-merged-resources/3.0/wicketstuff-merged-resources-3.0-sources.jar" target="_blank">Sources</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://techblog.molindo.at/2010/02/wicketstuff-merged-resources-2-1-and-3-0-released.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Compass: Role based searching using CompassQueryFilter</title>
		<link>http://techblog.molindo.at/2009/12/compass-role-based-searching-using-compassqueryfilter.html</link>
		<comments>http://techblog.molindo.at/2009/12/compass-role-based-searching-using-compassqueryfilter.html#comments</comments>
		<pubDate>Fri, 18 Dec 2009 15:14:37 +0000</pubDate>
		<dc:creator>Michael Sparer</dc:creator>
				<category><![CDATA[Compass]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://techblog.molindo.at/?p=157</guid>
		<description><![CDATA[While implementing a forum with wicket, spring, hibernate and compass for search, I recently ran into a problem: there are topics and posts that should only visible for some users. Say there&#8217;s a moderator forum where all content should only be visible for &#8230; well moderators  .

We&#8217;re using role based authentication in our apps,  [...]]]></description>
			<content:encoded><![CDATA[<p>While implementing <a href="http://www.setlist.fm/forum">a forum</a> with wicket, spring, hibernate and compass for search, I recently ran into a problem: there are topics and posts that should only visible for some users. Say there&#8217;s a moderator forum where all content should only be visible for &#8230; well moderators <img src='http://techblog.molindo.at/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> .<br />
<span id="more-157"></span><br />
We&#8217;re using role based authentication in our apps,  where each User object has one role that can in turn imply other roles. I&#8217;m leaving out some method, but you can imagine the IRole interface like that:</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;">interface</span> IRole <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">List</span> getImpliedRoles<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> hasRole<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> IRole role<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>we&#8217;re using an implementation that&#8217;s quite close to this:</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;">enum</span> SessionRole <span style="color: #000000; font-weight: bold;">implements</span> IRole <span style="color: #009900;">&#123;</span>
&nbsp;
ANONYMOUS<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,
USER<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,
MODERATOR<span style="color: #009900;">&#40;</span>USER<span style="color: #009900;">&#41;</span>,
ADMIN<span style="color: #009900;">&#40;</span>MODERATOR<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">List</span> _impliedRoles<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> SessionRole<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   _impliedRoles <span style="color: #339933;">=</span> <span style="color: #003399;">Collections</span>.<span style="color: #006633;">emptyList</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> SessionRole<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> IRole... <span style="color: #006633;">impliedRoles</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    _name <span style="color: #339933;">=</span> createName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">HashSet</span> set <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">HashSet</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> IRole impliedRole <span style="color: #339933;">:</span> impliedRoles<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   set.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>impliedRole<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   set.<span style="color: #006633;">addAll</span><span style="color: #009900;">&#40;</span>impliedRole.<span style="color: #006633;">getImpliedRoles</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
_impliedRoles <span style="color: #339933;">=</span> <span style="color: #003399;">Collections</span>.<span style="color: #006633;">unmodifiableList</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ArrayList</span><span style="color: #009900;">&#40;</span>set<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">List</span> getImpliedRoles<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> _impliedRoles<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> hasRole<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> IRole role<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span> <span style="color: #339933;">==</span> role <span style="color: #339933;">||</span> _impliedRoles.<span style="color: #006633;">contains</span><span style="color: #009900;">&#40;</span>role<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And for the sake of completeness, here the indexed entity (only showing the relevant fields):</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> ForumEntry <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> _headline<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> _text<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> IRole _readRole<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The visibility of the forum wasn&#8217;t a problem at all &#8211; where it got complicated was when performing a search. Of course the lucene index contains all posts and thus the search runs over all entries and also returns all entries &#8211; leading to results showing up for regular users that should be for moderators&#8217; eyes only.</p>
<p>The first ideas that came to my mind (and also the first I abandoned) were:</p>
<ol>
<li>Performing a regular search without considering any roles at all, then sort out the ones the user isn&#8217;t allowed to see</li>
<li>Save all roles that are allowed to see the entry to the ForumEntry</li>
<li>Add a hook into the indexing process and save the moderator entries in an other index (probably the worst idea)</li>
</ol>
<p>1. is quite bad as far as design is concerned and not really handy when it comes to paging through the results, 2. would bloat the index a bit and each IRole would not only have to know its implied roles, but also its inferring roles (the roles that are higher in hierarchy). E.g. USER would have to know that MODERATOR and ADMIN have at least the same rights. This might seem easy for this case but gets complicated with a more complex role structure. 3. no that&#8217;s really bad &#8230; we want to use the same index (and also the same UI) for all searches.</p>
<p>The solution is pretty simple to implement but was <a href="http://forum.compass-project.org/message.jspa?messageID=160476">very hard to find</a>: CompassQueryFilters. As the name suggests, a CompassQueryFilter is</p>
<blockquote><p>A filter used to filter out query results.</p></blockquote>
<p>For filtering my ForumEntry entities based on the user role, I use a boolean query builder and add a should-rule for each implied role and for the role itself. A should role for a boolean query applies when <strong>at least one of the rules applies to the matching hits</strong>. The code goes something like that:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">CompassSession session <span style="color: #339933;">=</span> ...<span style="color: #339933;">;</span>
IRole userRole <span style="color: #339933;">=</span> ...<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">final</span> CompassQueryBuilder build <span style="color: #339933;">=</span> session.<span style="color: #006633;">queryBuilder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">final</span> CompassQueryStringBuilder queryStringBuilder <span style="color: #339933;">=</span> build.<span style="color: #006633;">queryString</span><span style="color: #009900;">&#40;</span>qry<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">final</span> CompassQuery q <span style="color: #339933;">=</span> queryStringBuilder.<span style="color: #006633;">toQuery</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">final</span> CompassQueryFilterBuilder queryFilterBuilder <span style="color: #339933;">=</span> session.<span style="color: #006633;">queryFilterBuilder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">final</span> CompassQueryBuilder.<span style="color: #006633;">CompassBooleanQueryBuilder</span> booleanQueryBuilder <span style="color: #339933;">=</span> build.<span style="color: #006633;">bool</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>userRole.<span style="color: #006633;">getImpliedRoles</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</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: #000000; font-weight: bold;">final</span> IRole r <span style="color: #339933;">:</span> userRole.<span style="color: #006633;">getImpliedRoles</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
booleanQueryBuilder.<span style="color: #006633;">addShould</span><span style="color: #009900;">&#40;</span>build.<span style="color: #006633;">term</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;readRole&quot;</span>, r.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
booleanQueryBuilder.<span style="color: #006633;">addShould</span><span style="color: #009900;">&#40;</span>build.<span style="color: #006633;">term</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;readRole&quot;</span>, userRole.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">final</span> CompassQueryFilter queryFilter <span style="color: #339933;">=</span> filterBuilder.<span style="color: #006633;">query</span><span style="color: #009900;">&#40;</span>booleanQueryBuilder.<span style="color: #006633;">toQuery</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
q.<span style="color: #006633;">setFilter</span><span style="color: #009900;">&#40;</span>queryFilter<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>One last caveat: the indexed IRole field of ForumEntry cannot be empty or null, the whole filtering process would then yield wrong results. A simple solution is to add a base role to the existing roles which every role implies, something like that:</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;">enum</span> SessionRole <span style="color: #000000; font-weight: bold;">implements</span> IRole <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">DEFAULT</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,
ANONYMOUS<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">DEFAULT</span><span style="color: #009900;">&#41;</span>,
USER<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">DEFAULT</span><span style="color: #009900;">&#41;</span>,
MODERATOR<span style="color: #009900;">&#40;</span>USER<span style="color: #009900;">&#41;</span>,
ADMIN<span style="color: #009900;">&#40;</span>MODERATOR<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://techblog.molindo.at/2009/12/compass-role-based-searching-using-compassqueryfilter.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The Final Take On Java System Properties</title>
		<link>http://techblog.molindo.at/2009/11/java-system-properties.html</link>
		<comments>http://techblog.molindo.at/2009/11/java-system-properties.html#comments</comments>
		<pubDate>Thu, 26 Nov 2009 10:46:40 +0000</pubDate>
		<dc:creator>Stefan Fußenegger</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://techblog.molindo.at/?p=147</guid>
		<description><![CDATA[In this post, I&#8217;m looking for active collaboration of my readers (as I really hope that I have some). I&#8217;ve thought about a simpler way to handle Java system properties as I tend to forget them all the time. Additionally, I don&#8217;t like to see them as string constants &#8211; neither within the code nor [...]]]></description>
			<content:encoded><![CDATA[<p>In this post, I&#8217;m looking for active collaboration of my readers (as I really hope that I have some). I&#8217;ve thought about a simpler way to handle Java system properties as I tend to forget them all the time. Additionally, I don&#8217;t like to see them as string constants &#8211; neither within the code nor somewhere else. I&#8217;ve come up with a single enum class, that aims to simplify handling of system properties. Actually, you won&#8217;t ever think of <a href="http://stackoverflow.com/questions/487590/best-practice-for-using-java-system-properties" target="_blank">possible best practices</a> &#8211; hence &#8220;The Final Take on Java System Properties&#8221; <img src='http://techblog.molindo.at/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
<span id="more-147"></span><br />
<em>Note: the impatient may skip down to the list of requirements &#8211; but please let me give some background first <img src='http://techblog.molindo.at/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </em></p>
<p>Yesterday, I was trying to make all our JUnit tests independent of the current content of a system&#8217;s temporary directory (&#8220;java.io.tmpdir&#8221;). It&#8217;s pretty simple to add &#8220;-Djava.io.tmpdir=`mktemp -d /tmp/junit.XXXX`&#8221; as a JVM parameter &#8211; at least as long as you don&#8217;t have to do it more than a few times. As I didn&#8217;t like the idea of adding this parameter to each and every invocation of our Maven build, I&#8217;ve abandoned this idea rather quickly. Instead, I was looking to set java.io.tmpdir within Maven. To do this, all it takes is adding the appropriate configuration to the maven-surefire-plugin:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;build<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugins<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.apache.maven.plugins<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>maven-surefire-plugin<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2.4.3<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;systemProperties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>java.io.tmpdir<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>${java.io.tmpdir}${file.separator}surefire-${user.name}-${project.artifactId}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/systemProperties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugins<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/build<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>In my case, the resulting value of java.io.tmpdir was &#8220;/tmp/surefire-build-molindo-util-r4711&#8243; (btw, &#8220;build.vcs.number&#8221; is set by TeamCity). Having this done, I&#8217;ve found out another thing: while<strong> the JVM does not guarantee that java.io.tmpdir exists </strong>quite a bunch of our tests assumed that java.io.tmpdir points to an existing directory. So the next step was refactoring some code:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// existing</span>
<span style="color: #003399;">File</span> tmp <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">File</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">System</span>.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;java.io.tmpdir&quot;</span><span style="color: #009900;">&#41;</span>, <span style="color: #0000ff;">&quot;output.txt&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// new</span>
<span style="color: #003399;">File</span> tmpDir <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">File</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">System</span>.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;java.io.tmpdir&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
tmpDir.<span style="color: #006633;">mkdirs</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">File</span> tmp <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">File</span><span style="color: #009900;">&#40;</span>tmpDir, <span style="color: #0000ff;">&quot;output.txt&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>As I don&#8217;t like to repeat myself &#8211; who does? &#8211; I thought about creating a new utility method:</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;">static</span> <span style="color: #003399;">File</span> getTmpDir<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003399;">File</span> tmpDir <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">File</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">System</span>.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;java.io.tmpdir&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  tmpDir.<span style="color: #006633;">mkdirs</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">return</span> tmpDir<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Well, nothing spectacular here, most likely I wouldn&#8217;t be the first one to write this method. As a second though, I remembered that I had to lookup the property names for my Maven configuration: &#8220;java.io.tmpdir&#8221;, &#8220;file.separator&#8221;, &#8220;user.name&#8221;. Some of you might be able to name all of them instantly, but I&#8217;m admittedly not very good in remembering such things.  As a result, I decided to create a simple utility that should provide four things:</p>
<p><strong>Requirements:</strong></p>
<ul>
<li>simple and consistent access to Java system properties</li>
<li><strong>full</strong> documentation of available properties and their possible values &#8211; within my IDE (i.e. auto-completion, inline Javadoc)</li>
<li>fix inconsistencies in returned values and/or naming</li>
<li>make sure that java.io.tmpdir exists &#8211; acutally that&#8217;s the main reason why I&#8217;m doing all this <img src='http://techblog.molindo.at/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
</ul>
<p>That&#8217;s why I came up with the following class: <a href="http://techblog.molindo.at/files/SystemProperty.java" target="_blank">SystemProperty.java</a></p>
<p>It&#8217;s not complete yet, especially the documentation. Yet, I&#8217;ve only tested it with Sun Java 1.6 on Linux and Mac. To get full documentation of available properties and values, I&#8217;d like to ask <strong>you</strong> to run the included main method and send me the output (simply paste it to your favourite <a href="http://www.google.com/search?q=pastebin" target="_blank">pastebin</a> and post the link in the comments) along with your environment (OS, JVM version). In return, I&#8217;ll promise to update the class with all the gathered input and <a href="http://techblog.molindo.at/files/SystemProperty.java">keep it available at the above URL</a>.</p>
<p>Some highlights:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Use toString() to get values:</span>
<span style="color: #666666; font-style: italic;">// &quot;/tmp/output.txt&quot;</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><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">File</span><span style="color: #009900;">&#40;</span>SystemProperty.<span style="color: #006633;">JAVA_IO_TMPDIR</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;output.txt&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// &quot;You are running Linux, version 2.6.24-25-generic&quot;</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><span style="color: #003399;">String</span>.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;You are running %s, version %s&quot;</span>, SystemProperty.<span style="color: #006633;">OS_NAME</span>, SystemProperty.<span style="color: #006633;">OS_VERSION</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// get and set values</span>
SystemProperty.<span style="color: #006633;">JAVA_IO_TMPDIR</span>.<span style="color: #006633;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/dev/null&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// avoid setting of properties that shouldn't be changed</span>
<span style="color: #666666; font-style: italic;">// throws UnsupportedOperationException</span>
SystemProperty.<span style="color: #006633;">JAVA_CLASS_PATH</span>.<span style="color: #006633;">set</span><span style="color: #009900;">&#40;</span>newClassPath<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Additionally, access to properties is wrapped into a PrivilegedAction which is <a href="http://stackoverflow.com/questions/487590/best-practice-for-using-java-system-properties/488552#488552">suggested as a best practice</a>. If you know of any derived properties that would be cool to include, please let me now (e.g. Maven is providing non-standard os.family which I might include). Next, if you know of any properties that shouldn&#8217;t be read-only, let me know. Finally, if you know of any inconsistencies across different environments (e.g. like java.io.tmpdir that <a href="http://rationalpi.wordpress.com/2007/01/26/javaiotmpdir-inconsitency/" target="_blank">might or might not endswith a file seperator</a>) &#8211; make a guess &#8211; let me know! <img src='http://techblog.molindo.at/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>EDIT: I&#8217;ve also <a href="http://stackoverflow.com/questions/1803075/complete-list-of-available-java-system-properties-and-known-values" target="_blank">asked the people on Stack Overflow for collaboration</a>. You may also add your output there.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.molindo.at/2009/11/java-system-properties.html/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Efficiently Tracking Response Time Percentiles</title>
		<link>http://techblog.molindo.at/2009/11/efficiently-tracking-response-time-percentiles.html</link>
		<comments>http://techblog.molindo.at/2009/11/efficiently-tracking-response-time-percentiles.html#comments</comments>
		<pubDate>Fri, 06 Nov 2009 14:24:27 +0000</pubDate>
		<dc:creator>Stefan Fußenegger</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://techblog.molindo.at/?p=140</guid>
		<description><![CDATA[As we&#8217;ve recently started feeling that response times of one of our webapps got worse, we decided to spend some time tweaking the apps&#8217; performance. As a first step, we wanted to get a thorough understanding of current response times. For performance evaluations, using minimum, maximum or average response times is a bad idea: &#8220;The [...]]]></description>
			<content:encoded><![CDATA[<p>As we&#8217;ve recently started feeling that response times of one of our webapps got worse, we decided to spend some time tweaking the apps&#8217; performance. As a first step, we wanted to get a thorough understanding of current response times. For performance evaluations, using minimum, maximum or average response times is a bad idea: &#8220;The &#8216;average&#8217; is the evil of performance optimization and often as helpful as &#8216;average patient temperature in the hospital&#8217;&#8221; (<a href="http://www.mysqlperformanceblog.com/2008/11/28/computing-95-percentile-in-mysql/">MySQL Performance Blog</a>). Instead, performance tuners should be looking at the <a href="http://en.wikipedia.org/wiki/Percentile">percentile</a>: &#8220;A percentile is the value of a variable below which a certain percent of observations fall&#8221; (Wikipedia). In other words: the 95th percentile is the time in which 95% of requests finished. Therefore, a performance goals related to the percentile could be similar to &#8220;The 95th percentile should be lower than 800 ms&#8221;. Setting such performance goals is one thing, but efficiently tracking them for a live system is another one.<span id="more-140"></span></p>
<p>I&#8217;ve spent quite some time looking for existing implementations of percentile calculations (e.g.  <a href="http://www.mysqlperformanceblog.com/2008/11/28/computing-95-percentile-in-mysql/">1</a>, <a href="http://stackoverflow.com/questions/1248815/percentiles-of-live-data-capture">2</a>). All of them required storing response times for each and every request and calculate the percentile on demand or adding new response times in order. This was not what I wanted. I was hoping for a solution that would allow memory and CPU efficient live statistics for hundreds of thousands of requests. Storing response times for hundreds of thousands of requests and calculating the percentile on demand does neither sound CPU nor memory efficient.</p>
<p>Such a solution as I was hoping for simply seems not to exist. On second thought, I came up with another idea: For the type of performance evaluation I was looking for, it&#8217;s not necessary to get the exact percentile. An approximate answer like &#8220;the 95th percentile is between 850ms and 900ms&#8221; would totally suffice. Lowering the requirements this way makes an implementation extremely easy, especially if upper and lower borders for the possible results are known. For example, I&#8217;m not interested in response times higher than several seconds &#8211; they are extremely bad anyway, regardless of being 10 seconds or 15 seconds.</p>
<p>So here is the idea behind the implementation:</p>
<ol>
<li><span style="background-color: #ffffff;">Define any random number of response time buckets (e.g. 0ms &#8211; 100ms, 100ms &#8211; 200ms, 200ms &#8211; 400ms, 400ms &#8211; 800ms,800ms &#8211; 1200ms, &#8230;)</span></li>
<li><span style="background-color: #ffffff;">Count number of responses and number of response each bucket (For a response time of 360ms, increment the counter for the 200ms &#8211; 400ms bucket)</span></li>
<li><span style="background-color: #ffffff;">Estimate the n-th percentile by summing counter for buckets until the sum exceeds n percent of the total</span></li>
</ol>
<p>It&#8217;s that simple. And here is the code:  <a href="/files/PercentileCounter.java">PercentileCounter.java</a> and <a href="/files/Percentile.java">Percentile.java</a></p>
<p>Some highlights:</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: #000066; font-weight: bold;">void</span> increment<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> millis<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> index<span style="color: #009900;">&#40;</span>millis<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> _limits.<span style="color: #006633;">length</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        _counts<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">++;</span>
    <span style="color: #009900;">&#125;</span>
    _total<span style="color: #339933;">++;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> estimatePercentile<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">double</span> percentile<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>percentile <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">0.0</span> <span style="color: #339933;">||</span> percentile <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">100.0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IllegalArgumentException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;percentile must be between 0.0 and 100.0, was &quot;</span> <span style="color: #339933;">+</span> percentile<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> Percentile p <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>percentile <span style="color: #339933;">-</span> p.<span style="color: #006633;">getPercentage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;=</span> <span style="color: #cc66cc;">0.0001</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">return</span> p.<span style="color: #006633;">getLimit</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>
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #003399;">Integer</span>.<span style="color: #006633;">MAX_VALUE</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This approach only requires two int values (= 8 byte) per bucket, allowing to track 128 buckets with 1K of memory. More than sufficient for analysing response times of a web application using a granularity of 50ms). Additionally, for the sake of performance, I&#8217;ve intentionally implemented this without any synchronization(e.g. using AtomicIntegers), knowing that some increments might get lost.</p>
<p>By the way, using <a href="http://code.google.com/apis/chart/">Google Charts</a> and 60 percentile counters, I was able to create a nice graph out of one hour of collected response times:</p>
<p><img src="http://chart.apis.google.com/chart?cht=bvs&amp;chbh=a&amp;chs=600x400&amp;chd=s:mopoqumruusvuxvx0wxw0wyupmpqsmiolgjhiiokjkmiilpruttvwxzxxyxx,ILJJHFIGGFFFIFGFFGFCFFFHJJIJIJFGJIIIFHJIJGHFJKFFFEFFEFEEEEEF,FDCFCCFECEECCCDCBCBDBDCCEEEDCDEEEFEEEDDEFEDGHDEDCCCBCDCCCCCC,BBCCBBCCBBCCCBBBABBBBBBBCCCCCCECCCCCDCCBCCCCDCCCBBBBCBBCBBBB,CABBBABABBBBABBBBAABABBBBBBBBCCBBDDBCCBBCCBCCCBBBBCAABABBBBB,ABAABBBBBABBBBBAABBBABABABBBBBBCBBBCBBBBBBACABBBBBABBABABBBB,BBBABBBAABBBAAAAAAAABBAABBAAABBBBBBBBCABBBBBBAAAAAABBABBBABB,AAAABAAABABAAAAABBBBAABAAABAABBABBABBBABBAABBABABBAABBBBBABA,AABAABAAAAAABAABAAAAAAABBAAABBBABBBBBBBBBBBAABABAABBABAABABA,ABABBAABAAAAAAAAAAABBBAAABABAAAABABBBAAAABAAAABAAABABAAAABAB,AAAAAAAAAAAAAAAAAABAAAAAAAAAABBAAAAABBABBABAAAAAABAAAAABABAA,AAAABAAAABAAAABAAAAAAAAAAAAAAAAAAAAABBAAABAABAAAAAABAAABAAAB,BAAAAAAAAAAABAAAAAAAAABAABAAAAAABBABAAAAAAAAAAABAABABAAAAAAA,AAAABAAAAAAAAAAAAABAAAAAAAAAAABAAABABBABABABAABABBABAAAAAAAA,AAAAAABAAAAAAAAAAAABAAAAAAAAAAABAAABABAAAABBBBABABBAAABAABAB,AABAAAAAAAAAAAAAAAAAAAAABAAAABBAAAAABAAABBBAABBAAAABAAAAAAAA,AAAAAAAAAABAABAAAAAAABAAABAAAABABBBAAABBABABBBBBBBBAAAAABABA,ABAAAAAAAAAAAAABAAAAAAABAABAAABAAAABBAAAAAABAAAAAAABABAAAAAA,AAAAAAAAAAABAAAAAAAAAAAABAAAAAAAABAAAAAAAAABBBAAABBAAAAAAAAA,AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAABBBBBBBAAAAAAAAABAAAAAAA,FEEEDFFEDCECCCCBCCCCBBBBDEDDDEEEEFEFEFEFEEEEECEDCCCCBAABBAAA&amp;chco=338716FF,66A511FF,99C30CFF,CCE107FF,FFFF00FF,FFDF00FF,FFBF00FF,FF9F00FF,FF7E00FF,ED7707FF,DB700EFF,C96915FF,B7621DFF,C54F18FF,D33C13FF,E1290EFF,EF1609FF,FF0000FF,D20046FF,A5008CFF,7800D2FF&amp;chxt=y&amp;chxl=0:|0|20|40|60|80|100&amp;chg=0,20&amp;chdl==%20200|=%20400|=%20600|=%20800|=%201000|=%201200|=%201400|=%201600|=%201800|=%202000|=%202200|=%202400|=%202600|=%202800|=%203000|=%203200|=%203400|=%203600|=%203800|=%204000|%204000" alt="Response times" width="600" height="400" /></p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.molindo.at/2009/11/efficiently-tracking-response-time-percentiles.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Wicket: Annotation-based Mounting of Resources</title>
		<link>http://techblog.molindo.at/2009/10/wicket-annotation-based-mounting-of-resources.html</link>
		<comments>http://techblog.molindo.at/2009/10/wicket-annotation-based-mounting-of-resources.html#comments</comments>
		<pubDate>Tue, 13 Oct 2009 12:05:48 +0000</pubDate>
		<dc:creator>Stefan Fußenegger</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Wicket]]></category>
		<category><![CDATA[wicketstuff-merged-resources]]></category>

		<guid isPermaLink="false">http://techblog.molindo.at/?p=128</guid>
		<description><![CDATA[Today, I&#8217;m happy to announce the availability of annotation-based mounting and merging of resources in wicketstuff-merged-resources (version 3.0-SNAPSHOT for Wicket 1.4, version 2.1-SNAPSHOT for Wicket 1.3). In order to mount resources, all that&#8217;s needed is adding annotations to component classes:

@JsContribution
@CssContribution&#40;media = &#34;print&#34;&#41;
@ResourceContribution&#40;value = &#34;accept.png&#34;, path = &#34;/img/accept.png&#34;&#41;
public class PanelOne extends Panel &#123;
&#160;
    public PanelOne&#40;String id&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>Today, I&#8217;m happy to announce the availability of annotation-based mounting and merging of resources in <a title="Wicketstuff Wiki: wicketstuff-merged-resources" href="http://wicketstuff.org/confluence/display/STUFFWIKI/wicketstuff-merged-resources" target="_blank">wicketstuff-merged-resources</a> (version 3.0-SNAPSHOT for Wicket 1.4, version 2.1-SNAPSHOT for Wicket 1.3). In order to mount resources, all that&#8217;s needed is adding annotations to component classes:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@JsContribution
@CssContribution<span style="color: #009900;">&#40;</span>media <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;print&quot;</span><span style="color: #009900;">&#41;</span>
@ResourceContribution<span style="color: #009900;">&#40;</span>value <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;accept.png&quot;</span>, path <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/img/accept.png&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> PanelOne <span style="color: #000000; font-weight: bold;">extends</span> <span style="color: #003399;">Panel</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> PanelOne<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> id<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// ...</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><span id="more-128"></span><br />
The example above mounts and merges PanelOne.js (default is simple name of class + &#8220;.js&#8221;) into all.js (another default) and PanelOne-print.css into print.css which will be included with scope print. Additionally, accept.png will be mounted to /img/accept.png (as path starts with a &#8216;/&#8217;) which makes it easy to use from css files.</p>
<p>There&#8217;s not much left for this to work. All it takes is a single method call in your Application&#8217;s init code:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">ResourceMount.<span style="color: #006633;">mountAnnotatedPackageResources</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/files&quot;</span>, <span style="color: #0000ff;">&quot;com.example.components&quot;</span>, <span style="color: #000000; font-weight: bold;">this</span>, mount<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In this example, all components in package com.example.components (including sub-packages) will be scanned for annotations. If not defined otherwise, all resources will be merged into  single files for JS (/files/all.js) and all CSS media types (/files/all.css, /files/screen.css, /files/print.css, &#8230;).</p>
<p>As an added benefit, you&#8217;ll get all the other features of wicketstuff-merged-resources:</p>
<ul>
<li>merging of multiple files into one for less HTTP requests</li>
<li>adding of versions to resource paths for aggressive caching</li>
<li>pre-processing of resources (e.g. replacing colors in CSS files)</li>
<li>optionally uploading them to Amazon Cloudfront (well, at least you can expect this feature soon &#8211; <a title="setlist.fm - the setlist wiki" href="http://www.setlist.fm/" target="_blank">we are using it already</a>)</li>
</ul>
<p>So you will <a title="Molindo Techblog: Wicket Interface Speed-Up" href="/2008/08/wicket-interface-speed-up.html" target="_blank">speed up rendering of your pages</a> while simplifying and reducing your code (there&#8217;s no need to merge, mount or add HeaderContributors manually anymore)!</p>
<p><a title="wicketstuff-merged-resources on Wicket Stuff Wiki" href="http://wicketstuff.org/confluence/display/STUFFWIKI/wicketstuff-merged-resources" target="_blank">Further instructions are available on wicketstfuff-merged-resources&#8217; page on Wicket Stuff Wiki</a>.</p>
<p><small>(This new feature is mainly based on the idea and code of <a title="Jörn Zaefferer's profile at LinkedIn" href="http://www.linkedin.com/in/joernzaefferer" target="_blank">Jörn Zaefferer</a> &#8211; Tanks!)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.molindo.at/2009/10/wicket-annotation-based-mounting-of-resources.html/feed</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Using MySQL Collations in Java</title>
		<link>http://techblog.molindo.at/2009/10/using-mysql-collations-in-java.html</link>
		<comments>http://techblog.molindo.at/2009/10/using-mysql-collations-in-java.html#comments</comments>
		<pubDate>Wed, 07 Oct 2009 17:22:14 +0000</pubDate>
		<dc:creator>Stefan Fußenegger</dc:creator>
				<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://techblog.molindo.at/?p=125</guid>
		<description><![CDATA[I&#8217;ve recently discovered Stackoverflow as a nice pass-time on the one hand and as a valuable source for answers on the other hand. Normally it takes only a few minutes to get answers for most questions. However, I managed to ask a question that nobody was able to answer yet. The question was about Collations. As I&#8217;m [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently discovered <a href="http://stackoverflow.com/" target="_blank">Stackoverflow</a> as a nice pass-time on the one hand and as a valuable source for answers on the other hand. Normally it takes only a few minutes to get answers for most questions. However, I managed to ask <a title="Stackoverflow: Use MySQL collation in Java" href="http://stackoverflow.com/questions/1531107/use-mysql-collation-in-java" target="_blank">a question that nobody was able to answer yet</a>. The question was about <a title="Javadoc: Collator" href="http://java.sun.com/javase/6/docs/api/java/text/Collator.html" target="_blank">Collations</a>. As I&#8217;m suspecting that Collations are a Java feature that is hardly used, I kept working on the problem myself rather then just waiting for an answer on Stackoverflow.</p>
<p><span style="background-color: #ffffff; ">I&#8217;ve managed to get something working right now. It&#8217;s not completely tested but it should work quite well. What I&#8217;m doing is the following: I parse the<a title="MySQL doc: 9.4. Adding a New Character Set" href="http://dev.mysql.com/doc/refman/5.0/en/adding-character-set.html" target="_blank"> charset files of MySQL</a> (on an Ubuntu system, you can find them in /usr/share/mysql/charsets/) and do the collation based on those files myself rather than using Java&#8217;s built-in collations.</span></p>
<p><span style="background-color: #ffffff; ">You may <a title="Download: MySqlCollatorFactory.java" href="techblog.molindo.at/files/MySqlCollatorFactory.java" target="_blank">download the full source code</a>.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.molindo.at/2009/10/using-mysql-collations-in-java.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>wicketstuff-merged-resources: New (much simpler) Version</title>
		<link>http://techblog.molindo.at/2009/09/wicketstuff-merged-resources-new-much-simpler-version.html</link>
		<comments>http://techblog.molindo.at/2009/09/wicketstuff-merged-resources-new-much-simpler-version.html#comments</comments>
		<pubDate>Thu, 24 Sep 2009 19:17:56 +0000</pubDate>
		<dc:creator>Stefan Fußenegger</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Wicket]]></category>
		<category><![CDATA[wicketstuff-merged-resources]]></category>

		<guid isPermaLink="false">http://techblog.molindo.at/?p=113</guid>
		<description><![CDATA[It&#8217;s been a while since I&#8217;ve last posted here. Nevertheless, I&#8217;ve been busy working on some (yet to be released) Open Source projects. Others are already released but not documented/promoted yet. One of these unpromoted releases is the new version of wicketstuff-merged-resources.  wicketstuff-merged-resources was the result of my &#8220;Wicket Interface Speed-up&#8221; series where I investigate [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a while since I&#8217;ve last posted here. Nevertheless, I&#8217;ve been busy working on some (yet to be released) Open Source projects. Others are <a title="groovy-mb-mysql - Groovy port of MB_MySQL - the &quot;MusicBrainz Database for MySQL&quot;" href="http://code.google.com/p/groovy-mb-mysql/" target="_blank">already released but not documented/promoted yet</a>. One of these unpromoted releases is the <a title="wicketstuff-merged-resources - a set of simple helper classes to improve Wicket interface loading performance" href="http://wicketstuff.org/confluence/display/STUFFWIKI/wicketstuff-merged-resources" target="_blank">new version of wicketstuff-merged-resources</a>.  wicketstuff-merged-resources was the result of my <a href="http://techblog.molindo.at/2008/08/wicket-interface-speed-up.html">&#8220;Wicket Interface Speed-up&#8221; series</a> where I investigate how to reduce time spent rendering Wicket pages on the client side. wicketstuff-merged-resources has two main purposes: reducing the number of HTTP requests by merging resources (i.e. JS and CSS files) and enabling aggressive caching (up to a year) by adding a version number to mounted resources (e.g. /css/all-42.css instead of /css/all.css). While wicket has the <a title="IResourceSettings#getAddLastModifiedTimeToResourceReferenceUrl()" href="http://wicket.apache.org/docs/1.4/org/apache/wicket/settings/IResourceSettings.html#getAddLastModifiedTimeToResourceReferenceUrl()" target="_blank">option to add a timestamp</a> to references (something like /css/all.css?t=20090924), <a href="http://developer.yahoo.com/performance/rules.html#expires" target="_blank">adding the version to the name is preferred</a> over adding a query string. This said, let&#8217;s see how to use wicketstuff-merged-resources&#8217; new version.<span id="more-113"></span></p>
<p>The main class now is <a title="SVN: ResourceMount.java" href="https://wicket-stuff.svn.sourceforge.net/svnroot/wicket-stuff/trunk/wicketstuff-merged-resources/src/main/java/org/wicketstuff/mergedresources/ResourceMount.java" target="_blank">ResourceMount</a> which replaces the deprecated <a title="SVN: ResourceMountHelper.java" href="https://wicket-stuff.svn.sourceforge.net/svnroot/wicket-stuff/branches/wicket-1.3.x/wicketstuff-merged-resources/src/main/java/org/wicketstuff/mergedresources/ResourceMountHelper.java" target="_blank">ResourceMountHelper (already removed in trunk version)</a>. Mounting is now much simpler. Just see this example:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">ResourceMount mount <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ResourceMount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
.<span style="color: #006633;">setResourceVersionProvider</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> RevisionVersionProvider<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
.<span style="color: #006633;">setPath</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/style/all.css&quot;</span><span style="color: #009900;">&#41;</span>
.<span style="color: #006633;">addResourceSpecsMatchingSuffix</span><span style="color: #009900;">&#40;</span>PanelOne.<span style="color: #000000; font-weight: bold;">class</span>, ComponentB.<span style="color: #000000; font-weight: bold;">class</span>, MyForm.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span>
.<span style="color: #006633;">mount</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Note that you still use the resources as you are used to, e.g.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">add<span style="color: #009900;">&#40;</span>HeaderContributor.<span style="color: #006633;">forCss</span><span style="color: #009900;">&#40;</span>MyForm.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #0000ff;">&quot;MyForm.css&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add<span style="color: #009900;">&#40;</span>HeaderContributor.<span style="color: #006633;">forJavaScript</span><span style="color: #009900;">&#40;</span>MyForm.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #0000ff;">&quot;MyForm.js&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This example simply mounts PanelOne.css, ComponentB.css and MyForm.css into a single file at /style/all.css (the suffix &#8220;.css&#8221; is determined from the path &#8211; &#8220;/style/all.js&#8221; would mount all &#8220;.js&#8221; files). Additionally, the <a title="SVN: RevisionVersionProvider.java" href="https://wicket-stuff.svn.sourceforge.net/svnroot/wicket-stuff/trunk/wicketstuff-merged-resources/src/main/java/org/wicketstuff/mergedresources/versioning/RevisionVersionProvider.java">RevisionVersionProvider</a> is used to determine which version to append (you may implement your own <a title="SVN: IResourceVersionProvider.java" href="https://wicket-stuff.svn.sourceforge.net/svnroot/wicket-stuff/trunk/wicketstuff-merged-resources/src/main/java/org/wicketstuff/mergedresources/versioning/IResourceVersionProvider.java" target="_blank">IResourceVersionProvider</a> that best fits your environment). For example, the merged file may be mounted at /style/all-42.css (while still being available at /style/all.css through a permanent redirect).</p>
<p>While ResourceMount tries to autodetect most properties of the merged resource (e.g. style, locale, compression) it comes with a ton of customization options. For instance, it&#8217;s possible to use a custom <a title="JavaDoc: IRequestTargetUrlCodingStrategy" href="http://wicket.apache.org/docs/1.4/org/apache/wicket/request/target/coding/IRequestTargetUrlCodingStrategy.html" target="_blank">IRequestTargetUrlCodingStrategy</a>. Doesn&#8217;t that sound interesting to you? Well, we used this option to upload all resources to <a title="Amazon S3" href="https://s3.amazonaws.com/" target="_blank">Amazon Simple Storage Service</a>/<a title="Amazon CloudFront" href="http://aws.amazon.com/cloudfront/" target="_blank">CloudFront</a> in order to transparently leverage Amazon&#8217;s <a title="Wikipedia: Content Delivery Network" href="http://en.wikipedia.org/wiki/Content_delivery_network" target="_blank">CDN</a> by simply mounting them in <a title="Setlist.fm - A Molindo Wicket Application" href="http://www.setlist.fm/" target="_blank">our applications</a> (Isn&#8217;t that awesome? Stay tuned for another blog post. Donating might speed things up though).</p>
<p><a title="Jörn Zäfferer's Blog" href="http://bassistance.de/" target="_blank">Jörn Zaefferer</a> suggested adding <a title="Wicketstuff Wiki: wicketstuff-annotations" href="http://wicketstuff.org/confluence/display/STUFFWIKI/wicketstuff-annotation" target="_blank">wicketstuff-annotations</a>-like mounting of (merged) resources using <a title="Java language guide: Annotations" href="http://java.sun.com/j2se/1.5.0/docs/guide/language/annotations.html" target="_blank">annotations</a>, which will hopefully be added in a later version. In the meantime, I may provide Jörn&#8217;s solution for those interested (Jörn, you don&#8217;t mind, do you?) &#8211; just leave a message.</p>
<p>Additional feature include CSS compression using <a title="YUI Compressor" href="http://developer.yahoo.com/yui/compressor/" target="_blank">Yahoo&#8217;s YUI Compressor</a> and resource preprocessing. The later is particularly interesting, as you might implement things like replacing colors in CSS files or add internationalization from .properties files to JS files &#8211; just implement the <a title="SVN: IResourcePreProcessor" href="https://wicket-stuff.svn.sourceforge.net/svnroot/wicket-stuff/trunk/wicketstuff-merged-resources/src/main/java/org/wicketstuff/mergedresources/preprocess/IResourcePreProcessor.java" target="_blank">IResourcePreProcessor</a> interface (or use <a title="SVN: StringResourcePreProcessor" href="https://wicket-stuff.svn.sourceforge.net/svnroot/wicket-stuff/trunk/wicketstuff-merged-resources/src/main/java/org/wicketstuff/mergedresources/preprocess/StringResourcePreProcessor.java" target="_blank">StringResourcePreProcessor</a> if your only dealing with Strings).</p>
<p>I think I&#8217;ve mentioned the most important features now. Just <a title="WicketStuff Wiki: wicketstuff-merged-resources" href="http://wicketstuff.org/confluence/display/STUFFWIKI/wicketstuff-merged-resources" target="_blank">see wicketstuff-merged-resources in WicketStuff&#8217;s Wiki for more (and possibly up-to-date) documentation</a>. If you have any questions, don&#8217;t hesitate to post a comment! It you&#8217;re grateful, don&#8217;t hesitate to donate! <img src='http://techblog.molindo.at/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="2705854">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but21.gif" border="0" name="submit" alt="">
<img alt="" border="0" src="https://www.paypal.com/de_DE/i/scr/pixel.gif" width="1" height="1">
</form></p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.molindo.at/2009/09/wicketstuff-merged-resources-new-much-simpler-version.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Maven/Eclipse: Build path specifies execution environment J2SE-1.5</title>
		<link>http://techblog.molindo.at/2009/04/maven-eclipse-build-path-specifies-execution-environment-j2se-15.html</link>
		<comments>http://techblog.molindo.at/2009/04/maven-eclipse-build-path-specifies-execution-environment-j2se-15.html#comments</comments>
		<pubDate>Mon, 06 Apr 2009 12:16:30 +0000</pubDate>
		<dc:creator>Stefan Fußenegger</dc:creator>
				<category><![CDATA[Maven]]></category>

		<guid isPermaLink="false">http://techblog.molindo.at/?p=109</guid>
		<description><![CDATA[After running `mvn eclipse:eclipse` this morning, we got a warning from eclipse, telling us that &#8220;Build path specifies execution environment J2SE-1.5. There are no JREs in the workspace strictly compatible with this environment.&#8221; We didn&#8217;t make any changes that could cause this warning, though. We deceided to leave the problem as it was and fix [...]]]></description>
			<content:encoded><![CDATA[<p>After running `mvn eclipse:eclipse` this morning, we got a warning from eclipse, telling us that <strong>&#8220;Build path specifies execution environment J2SE-1.5. There are no JREs in the workspace strictly compatible with this environment.&#8221;</strong> We didn&#8217;t make any changes that could cause this warning, though. We deceided to leave the problem as it was and fix it later &#8211; it&#8217;s only a warning anyway. However, when trying to start another project, I got another exception I haven&#8217;t ever received before. It was caused by mixing up wrong versions of different <a href="http://www.slf4j.org/">slf4j</a> JARs.</p>
<p><span id="more-109"></span>I suddenly had the feeling that ther&#8217;s something fishy with the <a href="http://maven.apache.org/plugins/maven-eclipse-plugin/">maven-eclipse-plugin</a>. And in deed, a look into the ~/.m2/repository/org/apache/maven/plugins/maven-eclipse-plugin proved me right. There is <a href="http://www.nabble.com/-ANN--Maven-Eclipse-Plugin-2.6-Released-to22835650.html">a brand new version 2.6 of the plugin</a>.</p>
<p>This new version automagically adds projects from the workspace rather than JARs from the local repository (which is cool, basically). However, that caused Eclipse to load the wrong JARs: One project depended on sl4j 1.3, another one on 1.5 and the other project. Maven perfectly resolves the version of this transient depenedency, while Eclipse picks one by chance. Gotcha#1!</p>
<p>The first warning was caused by <a href="http://maven.apache.org/plugins/maven-compiler-plugin/">maven-compiler-plugin</a> beeing configured to compile for Java 1.5 while only a 1.6 JDK was available. Gotcha#2!</p>
<p>Hopefully this post will save other people from being as clueless as I&#8217;ve been <img src='http://techblog.molindo.at/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.molindo.at/2009/04/maven-eclipse-build-path-specifies-execution-environment-j2se-15.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Detaching and Attaching Persistent Objects on Serialization</title>
		<link>http://techblog.molindo.at/2009/03/detaching-and-attaching-persistent-objects-on-serialization.html</link>
		<comments>http://techblog.molindo.at/2009/03/detaching-and-attaching-persistent-objects-on-serialization.html#comments</comments>
		<pubDate>Wed, 25 Mar 2009 15:52:05 +0000</pubDate>
		<dc:creator>Stefan Fußenegger</dc:creator>
				<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Wicket]]></category>

		<guid isPermaLink="false">http://techblog.molindo.at/?p=100</guid>
		<description><![CDATA[Today I&#8217;ve received a mail by someone interested in a serialization mechanism I described some days ago. This mechanism was implemented to avoid dealing with detached Hibernate objects in different HTTP (i.e. Wicket) requests (it&#8217;s not restricted to Hibernate though). The idea is quite simple: detach objects if they are persistent, serialize them if they [...]]]></description>
			<content:encoded><![CDATA[<p>Today I&#8217;ve received a mail by someone interested in <a href="http://stronglytypedblog.blogspot.com/2009/03/wicket-patterns-and-pitfalls-1.html?showComment=1236931620000#c7920901088559233703">a serialization mechanism I described some days ago</a>. This mechanism was implemented to avoid dealing with detached Hibernate objects in different HTTP (i.e. Wicket) requests (it&#8217;s not restricted to Hibernate though). The idea is quite simple: detach objects if they are persistent, serialize them if they are transient, deserialize and attach for the next request &#8211; all transparently. So far, this isn&#8217;t very special and doesn&#8217;t justify such a complicated approach. However, it&#8217;s the only way of attaching and detaching object graphs that consist of transient <strong>and</strong> persistent objects I know.<br />
<span id="more-100"></span>The mechanism uses the magic serialization hooks readResolve() and writeReplace() (<a href="http://www.jguru.com/faq/view.jsp?EID=44039">see jGuru</a>). Knowing these hooks (yeah, knowing &#8230; as it is probably harder to know them than to actually use them), the rest is quite easy. Replace persistent object with a placeholder but serialize regular objects:</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;">final</span> <span style="color: #003399;">Object</span> writeReplace<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;">ObjectStreamException</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>isTransient<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</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: #000000; font-weight: bold;">this</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> ReplaceHolder<span style="color: #009900;">&#40;</span>getClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, getId<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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>The ReplaceHolder &#8211; isn&#8217;t it a lovely name? &#8211; is responsible for replacing itself with the persistent object we didn&#8217;t want to serialize before:</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;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">class</span> ReplaceHolder <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">Serializable</span> <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">long</span> serialVersionUID <span style="color: #339933;">=</span> 1L<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> _entityName<span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Serializable</span> _id<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> ReplaceHolder<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">Class</span> entity, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Serializable</span> id<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    _entityName <span style="color: #339933;">=</span> entity.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    _id <span style="color: #339933;">=</span> id<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Serializable</span> getId<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> _id<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  @SuppressWarnings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;unchecked&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> getEntity<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;">ClassNotFoundException</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">Class</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">Class</span>.<span style="color: #006633;">forName</span><span style="color: #009900;">&#40;</span>_entityName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Object</span> readResolve<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;">ObjectStreamException</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: #000000; font-weight: bold;">return</span> loadEntity<span style="color: #009900;">&#40;</span>getEntity<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, getId<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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: #000000; font-weight: bold;">final</span> <span style="color: #003399;">ClassNotFoundException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">InvalidClassException</span><span style="color: #009900;">&#40;</span>_entityName, e.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getSimpleName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;: &quot;</span> <span style="color: #339933;">+</span> e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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></pre></div></div>

<p>And that&#8217;s it. Well, not completely, but <a title="AbstractPersistentObject.java" href="http://techblog.molindo.at/files/AbstractPersistentObject.java">see the attached .java file</a> for details.</p>
<p>There is only one thing Wicket developers have to be aware of. Objects aren&#8217;t serialized between requests &#8211; don&#8217;t confuse it with model detaching. If I remember correctly, there is always one page kept detached but un-serialized. So if one would like to use the serialization, one has to make sure, that the objects are already serialized as soon as the models are detached. For this purpose, I implemented <a title="SerializingModel.java" href="http://techblog.molindo.at/files/SerializingModel.java">a special Model, that serializes its object on detach</a>:</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: #000066; font-weight: bold;">void</span> detach<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;">if</span> <span style="color: #009900;">&#40;</span>_object <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</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: #000000; font-weight: bold;">final</span> <span style="color: #003399;">ByteArrayOutputStream</span> bs <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ByteArrayOutputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ObjectOutputStream</span><span style="color: #009900;">&#40;</span>bs<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">writeObject</span><span style="color: #009900;">&#40;</span>_object<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      _bytes <span style="color: #339933;">=</span> bs.<span style="color: #006633;">toByteArray</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      _object <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</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: #000000; font-weight: bold;">final</span> <span style="color: #003399;">IOException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> WicketRuntimeException<span style="color: #009900;">&#40;</span>e<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></pre></div></div>

<p>You might say that this feels like a hack &#8211; at least that&#8217;s what I think of it <img src='http://techblog.molindo.at/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  But it works perfectly, especially for complex forms where you add persistent objects to transient ones. Furthermore, you make sure that you&#8217;ll never serialize a huge persistent object graph into your Wicket session, which definetely is a Bad Thing &#8482;.</p>
<p>EDIT: This blogger is thirsty! Please buy him a beer: <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="2705854">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but21.gif" border="0" name="submit" alt="">
<img alt="" border="0" src="https://www.paypal.com/de_DE/i/scr/pixel.gif" width="1" height="1">
</form></p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.molindo.at/2009/03/detaching-and-attaching-persistent-objects-on-serialization.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Talk On Tech now Molindo Techblog</title>
		<link>http://techblog.molindo.at/2009/01/talk-on-tech-now-molindo-techblog.html</link>
		<comments>http://techblog.molindo.at/2009/01/talk-on-tech-now-molindo-techblog.html#comments</comments>
		<pubDate>Fri, 23 Jan 2009 10:00:24 +0000</pubDate>
		<dc:creator>Stefan Fußenegger</dc:creator>
				<category><![CDATA[Compass]]></category>
		<category><![CDATA[SVN]]></category>
		<category><![CDATA[Wicket]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://tech.molindo.at/?p=84</guid>
		<description><![CDATA[Talk On Tech (talk-on-tech.blogspot.com &#8211; the tech blog you truly love, don&#8217;t you?) was our nice, green home since August 2007. Now, after 1.5 years it was time to move on &#8230; Well, okay, we just want to consolidate all our blogs on a single self-hosted platform. In the course of doing that, we also [...]]]></description>
			<content:encoded><![CDATA[<p>Talk On Tech (talk-on-tech.blogspot.com &#8211; the tech blog you truly love, don&#8217;t you?) was our nice, green home since August 2007. Now, after 1.5 years it was time to move on &#8230; Well, okay, we just want to<a href="http://tech.molindo.at/2008/12/virtual-wordpress-hosts-made-easy.html"> consolidate all our blogs on a single self-hosted platform</a>. In the course of doing that, we also changed the name from Talk on Tech (Let&#8217;s create a blog! How do we name it? What about &#8220;Talk on Tech&#8221;? Yeah, that name is free!) to Molindo Techblog (where Molindo is the name of <a href="http://www.molindo.at/">our very own startup</a>).</p>
<p>If it comes to new posts, We have a lot of ideas but not enough time to elaborate them all. Some ideas are:<br />
<span id="more-84"></span></p>
<ul>
<li>An easy to use <a title="Wicket" href="http://wicket.apache.org">Wicket</a> component for advanced Google Analytics (Outgoing link tracking, search tracking, AJAX events tracking, user defined variables, &#8230;)</li>
<li>Faster batch indexing for <a title="Compass Project" href="http://compass-project.org/">Compass</a></li>
<li>Managing <a title="Subversion" href="http://subversion.tigris.org/">Subversion</a> user access privileges with <a title="Drupal" href="http://drupal.org/">Drupal</a> &#8211; and probably how to move to Wordpress afterwards <img src='http://techblog.molindo.at/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </li>
<li>Wicket <a title="Blueprint CSS Framework" href="http://www.blueprintcss.org/">Blueprint</a> integration</li>
<li>How to apply some on-site SEO with a little help of Wicket</li>
<li>Unleashing the full power of Wicket with <a title="Cometd project" href="http://cometdproject.dojotoolkit.org/">Cometd</a> using <a title="wicketstuff-dojo-1.1" href="http://wicketstuff.org/confluence/display/STUFFWIKI/wicketstuff-dojo-1.1">wicketstuff-dojo-1.1</a> and <a title="&quot;Wicket: Loose Coupling of Componens for Ajax Updates&quot; on Molindo Techblog" href="http://tech.molindo.at/2008/09/wicket-loose-coupling-of-componens-for-ajax-updates.html">loose coupling of components</a>.</li>
</ul>
<p>If you particulary like one of the ideas post a wish in the comments &#8211; and think about enforcing your wish with a donation: <img src='http://techblog.molindo.at/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="2705854">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but21.gif" border="0" name="submit" alt="">
<img alt="" border="0" src="https://www.paypal.com/de_DE/i/scr/pixel.gif" width="1" height="1">
</form></p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.molindo.at/2009/01/talk-on-tech-now-molindo-techblog.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
