<?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>wuetender-junger-mann.de &#187; Visionäre Projekte</title>
	<atom:link href="http://wuetender-junger-mann.de/wordpress/category/visionare-projekte/feed/" rel="self" type="application/rss+xml" />
	<link>http://wuetender-junger-mann.de/wordpress</link>
	<description>Der Freiheit eine Gasse</description>
	<lastBuildDate>Tue, 20 Sep 2011 12:40:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Getting Real with Enumerable.java</title>
		<link>http://wuetender-junger-mann.de/wordpress/2010/10/getting-real-with-enumerable-java/</link>
		<comments>http://wuetender-junger-mann.de/wordpress/2010/10/getting-real-with-enumerable-java/#comments</comments>
		<pubDate>Sat, 09 Oct 2010 19:22:38 +0000</pubDate>
		<dc:creator>felix</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Visionäre Projekte]]></category>

		<guid isPermaLink="false">http://wuetender-junger-mann.de/wordpress/?p=1034</guid>
		<description><![CDATA[Two weeks back I posted a video explaining how to get started with Enumerable.java. While this might have been enough information to start playing, there is a lot more to consider when going with Enumerable.java for production use. Over the past few weeks I went through that experience on my project and here are some [...]]]></description>
			<content:encoded><![CDATA[<p>
Two weeks back I posted a <a href="http://wuetender-junger-mann.de/wordpress/2010/09/get-closures-for-java-now/">video</a> explaining how to get started with <a href="http://enumerable.org">Enumerable.java</a>. While this might have been enough information to start playing, there is a lot more to consider when going with Enumerable.java for production use.
</p>
<p>
Over the past few weeks I went through that experience on my project and here are some of the practices that we found useful. Håkan also released version 0.3.0 that incorporates some of our learnings.
</p>
<p>
When working in the IDE we used the javaagent to weave the lambdas. However there were a few caveats. In version 0.2.4 you could only black list packages to prevent them from being weaved. In most cases it is easier to specify explicitly for which package to enable weaving. Also when using contemporary java goodness there is other parties doing byte code magic. We experienced these problems with spring&#8217;s scoped proxies, therefore we introduced another parameter to filter out classes by a regular expression applied to the full classname. Proxy classes usually come with a lot of dollar signs in their names.<br />
So the vmargs we are using in development are:</p>
<pre>
-javaagent:lib/deploy/enumerable-agent-0.x.x.jar
-Dlambda.weaving.included.packages=felix.application
-Dlambda.weaving.exclude.pattern=\$\$
</pre>
<p>
If you are using eclipse you can specify these parameters as default vm-parameters in your JRE definition:
</p>
<p><a href="http://wuetender-junger-mann.de/wordpress/wp-content/uploads/2010/10/Screen-shot-2010-10-09-at-20.57.38.png"><img src="http://wuetender-junger-mann.de/wordpress/wp-content/uploads/2010/10/Screen-shot-2010-10-09-at-20.57.38.png" alt="" title="Screen shot 2010-10-09 at 20.57.38" width="600"  class="aligncenter size-full wp-image-1055" /></a></p>
<p>
While using an agent in the ide is acceptable it gets messy, when deploying the application. Essentially all the JVMs on the way to production including your application server would need the agent. What we did instead is, we instrumented our class files in our build using the AOT lambda compiler. So this is a single step after the compilation. If you are using ant it could look somewhat like this:</p>
<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;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;lambda&quot;</span> <span style="color: #000066;">depends</span>=<span style="color: #ff0000;">&quot;compile&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;java</span> <span style="color: #000066;">fork</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">classname</span>=<span style="color: #ff0000;">&quot;lambda.weaving.LambdaCompiler&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">failonerror</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sysproperty</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;lambda.weaving.debug&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/sysproperty<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;classpath<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;path</span> <span style="color: #000066;">refid</span>=<span style="color: #ff0000;">&quot;prod&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/classpath<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;prod.jar&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/arg<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/java<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><strong>Important:</strong> The lambda weaver needs debug information on local variables and also you need to encode your source files as utf-8 to get the fancy lambda letter, so perhaps you have to change your compile target like this:
</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;javac</span> <span style="color: #000066;">srcdir</span>=<span style="color: #ff0000;">&quot;src/java&quot;</span> </span>
<span style="color: #009900;">            <span style="color: #000066;">destdir</span>=<span style="color: #ff0000;">&quot;${basedir}/tempCompile&quot;</span> </span>
<span style="color: #009900;">            <span style="color: #000066;">classpathref</span>=<span style="color: #ff0000;">&quot;prod&quot;</span></span>
<span style="color: #009900;">            <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf8&quot;</span></span>
<span style="color: #009900;">            <span style="color: #000066;">debug</span>=<span style="color: #ff0000;">&quot;on&quot;</span></span>
<span style="color: #009900;">            <span style="color: #000066;">debuglevel</span>=<span style="color: #ff0000;">&quot;lines,vars,source&quot;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>
From a technical point of view this is all you need to do. However there is also the question of how to use the new feature &#8220;responsibly&#8221;. In our code base we used the generic CollectionUtils to filter and transform Collections. While they are elegant from a theoretical point of view, they are quite an insult to the eye, so our aim was to replace all these with Enumerable.java. Functional operations on collections are very well understood (the method names used in Enumerable.java go at least back to Smalltalk-80, that&#8217;s thirty years).
</p>
<p>
So the advice introduce your team the following methods and aim to restrict the use of lambda expressions to those:
</p>
<ul>
<li><code>select</code></li>
<li><code>collect</code></li>
<li><code>find</code></li>
<li><code>inject</code></li>
<li><code>groupBy</code></li>
<li>While there is remarkable support for arrays and primitives, try to stick to<br />
 Collections and proper Objects.
</ul>
<p>I think these alone justify the investment.<br />
Things you should avoid or do only in after proper consideration:</p>
<ul>
<li>Do not declare parameters of function types</li>
<li>Do not declare local variables of function types</li>
<li>Do not declare fields of function types</li>
<li>Do not modify enclosed state from within the closure, i.e. local variables or fields</li>
<li>Generally avoid side effects</li>
</ul>
<p>The typical transformation we did, looked something like this:

<div class="wp_syntax"><div class="code"><pre class="jave" style="font-family:monospace;">    private Set&lt;Order.Status&gt; retrieveOrderStatuses() {
        Set&lt;Order.Status&gt; statuses = new HashSet&lt;Order.Status&gt;();
        if (orders == null) return statuses;
&nbsp;
        for (Order  order : orders) {
            statuses.add(order.getStatus());
        }
        return statuses;
    }</pre></div></div>

<p>
becomes:
</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">    @LambdaParameter <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> Order o<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> Set<span style="color: #339933;">&lt;</span>Order.<span style="color: #006633;">Status</span><span style="color: #339933;">&gt;</span> retrieveOrderStatuses<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>orders <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">return</span> emptySet<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>  collect<span style="color: #009900;">&#40;</span>orders, λ<span style="color: #009900;">&#40;</span>o, o.<span style="color: #006633;">getStatus</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: #006633;">toSet</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>
Because getting the lambda character (you might also want to use the alias fn) is a bit tricky you might want to use this java editor template for eclipse that also sorts out the static import:
</p>
<pre>
λ(${impst:importStatic('lambda.Lambda.*')}${cursor})
</pre>
<p>
Sticking to these simple rules actually helped us getting away from the anonymous inner classes and CollectionUtils and that was an easy sell to the mostly mathematically inclined team. In my opinion the fact that lambdas are restricted to expressions is actually a good thing.</p>
]]></content:encoded>
			<wfw:commentRss>http://wuetender-junger-mann.de/wordpress/2010/10/getting-real-with-enumerable-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get Closures for Java Now!</title>
		<link>http://wuetender-junger-mann.de/wordpress/2010/09/get-closures-for-java-now/</link>
		<comments>http://wuetender-junger-mann.de/wordpress/2010/09/get-closures-for-java-now/#comments</comments>
		<pubDate>Sun, 19 Sep 2010 18:33:07 +0000</pubDate>
		<dc:creator>felix</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Visionäre Projekte]]></category>

		<guid isPermaLink="false">http://wuetender-junger-mann.de/wordpress/?p=1026</guid>
		<description><![CDATA[The general state of affairs at Sun/ Oracle is very sad. If you are like me, you cannot take this much longer. Fortunately enough my esteemed colleague Håkan Råberg has invented what is at least a molotov cocktail perhaps even a guillotine to the revolution of java software development. Yes, I am talking about the [...]]]></description>
			<content:encoded><![CDATA[<p>
The general state of affairs at Sun/ Oracle is very sad. If you are like me, you cannot take this much longer. Fortunately enough my esteemed colleague <a href="http://www.jroller.com/ghettoJedi/">Håkan Råberg</a> has invented what is at least a molotov cocktail perhaps even a guillotine to the revolution of java software development. Yes, I am talking about the modestly named <a href="http://www.jroller.com/ghettoJedi/entry/enumerable_java_lambdas_in_java">Enumerable.java</a>, which brings the Ruby enumerable module and closures to java. Without a special compiler, just by pushing the boundaries and enhancing byte code.
</p>
<p>
I created this little screencast, that shows how to get up and running with Enumerable.java:
</p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/sMsJUvHUmmM?hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/sMsJUvHUmmM?hl=en&#038;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
<p>
There is also a <a href="https://docs.google.com/leaf?id=0Bytlr4GJJxT9MGEzZjliYWItNmFmYi00ZjE2LTliZmQtOGJlOGYxZTRjYzRl&#038;sort=name&#038;layout=list&#038;num=50">hi-res version</a> of the videos on google docs (approx. 20M download size).
</p>
<p>
For more examples and explanation watch <a href="http://www.jroller.com/ghettoJedi/">Håkan&#8217;s blog</a> and read the <a href="http://github.com/hraberg/enumerable">source</a>.
</p>
<p>
Now, go, download and, enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://wuetender-junger-mann.de/wordpress/2010/09/get-closures-for-java-now/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Visualising log files with gnuplot</title>
		<link>http://wuetender-junger-mann.de/wordpress/2009/06/visualising-log-files-with-gnuplot/</link>
		<comments>http://wuetender-junger-mann.de/wordpress/2009/06/visualising-log-files-with-gnuplot/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 17:17:28 +0000</pubDate>
		<dc:creator>felix</dc:creator>
				<category><![CDATA[Held der Kommandozeile]]></category>
		<category><![CDATA[Musik]]></category>
		<category><![CDATA[Reading]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Visionäre Projekte]]></category>

		<guid isPermaLink="false">http://wuetender-junger-mann.de/wordpress/?p=768</guid>
		<description><![CDATA[I recently had the pleasure of supporting a new system throughout its first month of production. This was a good opportunity to refresh my command line skills. As it happened I spent a lot of time looking at log files trying to figure out what happened to the productions system. I figured, that a graphical [...]]]></description>
			<content:encoded><![CDATA[<p>
I recently had the pleasure of supporting a new system throughout its first month of production. This was a good opportunity to refresh my command line skills. As it happened I spent a lot of time looking at log files trying to figure out what happened to the productions system. I figured, that a graphical representation of the events would be nice and started using <a href="http://www.gnuplot.info/">gnuplot</a>.</p>
</p>
<p>
First I started out with a bunch of bash scripts, using what your usual unix installation provides, but then I actually came up with <a href="http://github.com/fleipold/logvisualizer/tree/master">some groovy scripts</a> to provide better abstractions. A log file generally looks somewhat like this:
</p>
<pre>
04/01/1970 07:55:13 garbage
04/01/1970 09:27:48 Event 2
04/01/1970 10:01:28 garbage
04/01/1970 10:38:30 garbage
04/01/1970 10:48:36 garbage
04/01/1970 10:51:58 Event 2
04/01/1970 11:03:45 garbage
04/01/1970 11:34:03 Event 1
04/01/1970 12:24:33 garbage
05/01/1970 04:35:50 ERROR
</pre>
<p>
There is a lot of garbage plus some events we might be interested in. It allows to specify events, e.g. by providing a regexp:
</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">Event</span> EVENT1 <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> RegExEvent<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Event 1&quot;</span>, ~<span style="color: #339933;">/</span><span style="color: #003399;">Event</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">/</span><span style="color: #009900;">&#41;</span>
<span style="color: #003399;">Event</span> EVENT2 <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> RegExEvent<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Event 2&quot;</span>, ~<span style="color: #339933;">/</span><span style="color: #003399;">Event</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">/</span><span style="color: #009900;">&#41;</span>
<span style="color: #003399;">Event</span> ERROR <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> RegExEvent<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error&quot;</span>, ~<span style="color: #339933;">/</span>ERROR<span style="color: #339933;">/</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>
The next step is newing up a <code>TimeLineVisualizer</code> on these events and passing in a stream with the actual log:
</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">def logFile <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: #0000ff;">&quot;test.log&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
logFile.<span style="color: #006633;">withInputStream</span> <span style="color: #009900;">&#123;</span><span style="color: #003399;">InputStream</span> stream <span style="color: #339933;">-&gt;</span>
  def visualizer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TimeLineVisualizer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>
          EVENT1,
          EVENT2,
          ERROR
  <span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  visualizer.<span style="color: #006633;">visualize</span><span style="color: #009900;">&#40;</span>stream<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>
If you have the <code>gnuplot</code> binary on your path this will yield something like this:
</p>
<p><img src="http://wuetender-junger-mann.de/wordpress/wp-content/uploads/2009/06/timeline.png" alt="timeline" title="timeline" width="846" class="alignnone size-full wp-image-771" /></p>
<p>
Also in some cases you would like to know which time of day events are most likely to happen. For producing histograms I created another visualizer (which currently takes only one event).
</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">logFile.<span style="color: #006633;">withInputStream</span> <span style="color: #009900;">&#123;</span><span style="color: #003399;">InputStream</span> stream <span style="color: #339933;">-&gt;</span>
  def visualizer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HistogramVisualizer<span style="color: #009900;">&#40;</span>EVENT2, HistogramVisualizer.<span style="color: #006633;">HOUR_OF_DAY_BINS</span><span style="color: #009900;">&#41;</span>
  visualizer.<span style="color: #006633;">visualize</span><span style="color: #009900;">&#40;</span>stream<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>
For the example log file, which unfortunately has an even distribution of events, we get this:
</p>
<p><img src="http://wuetender-junger-mann.de/wordpress/wp-content/uploads/2009/06/histogram.png" alt="histogram" title="histogram" width="846"  class="alignnone size-full wp-image-772" /></p>
<p>
The cool thing about gnuplot is, that you can actually run these things in a cron job to produce daily reports (and mail them to the appropriate people) or on a continuous integration server to visualise how the system is being exercised by the test suite.</p>
]]></content:encoded>
			<wfw:commentRss>http://wuetender-junger-mann.de/wordpress/2009/06/visualising-log-files-with-gnuplot/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

