<?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"
	>

<channel>
	<title>Christian Schenk</title>
	<atom:link href="http://www.christianschenk.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.christianschenk.org</link>
	<description>Blogging about my experiences with technology and all different kinds of projects and experiments</description>
	<pubDate>Tue, 15 Jul 2008 08:22:41 +0000</pubDate>
	
	<language>en</language>
			<item>
		<title>Follow meta refresh with Commons HttpClient</title>
		<link>http://www.christianschenk.org/blog/follow-meta-refresh-with-commons-httpclient/</link>
		<comments>http://www.christianschenk.org/blog/follow-meta-refresh-with-commons-httpclient/#comments</comments>
		<pubDate>Thu, 22 May 2008 13:25:14 +0000</pubDate>
		<dc:creator>Christian Schenk</dc:creator>
		
		<category><![CDATA[HowTo]]></category>

		<category><![CDATA[commons]]></category>

		<category><![CDATA[httpclient]]></category>

		<category><![CDATA[java]]></category>

		<category><![CDATA[meta refresh]]></category>

		<guid isPermaLink="false">http://www.christianschenk.org/follow-meta-refresh-with-commons-httpclient/</guid>
		<description><![CDATA[Want to follow HTTP redirects and meta refresh tags as well? Have a look at the code in this post.]]></description>
			<content:encoded><![CDATA[<p>Having to check the <code>title</code> tag from a lot of different websites I needed a tool that would follow HTTP redirects as well as redirects in meta refresh tags. As a fan of <a href="http://www.google.de/search?q=commons+httpclient&#038;btnI">Commons HttpClient</a>, I hacked together some code that does the work.</p>
<p>For the impatient: check out the code <a title="Code reference" href="http://data.christianschenk.org/follow-meta-refresh-with-commons-httpclient/xref/">here</a>.</p>
<h2>The code</h2>
<p>The actual code is very simple:</p>
<ol>
<li>it executes an HTTP GET with a given URL</li>
<li>follows HTTP redirects</li>
<li>finally downloads the contents</li>
<li>checks whether there&#8217;s a meta refresh tag
<ul>
<li>starts over at 1. if it found such a tag</li>
</ul>
</li>
<li>returns the content.</li>
</ol>
<p>Have a look at the class <code>TitleTest</code> <a title="Code reference" href="http://data.christianschenk.org/follow-meta-refresh-with-commons-httpclient/xref/">here</a>: the private method <code>doGet</code> will be most interesting. </p>
<h2>Conclusion</h2>
<p>I was wondering why there aren&#8217;t that many tools out there which support following meta refresh tags. Since a lot of websites use this feature I thought that this would be something a lot of people might want to use when testing their websites.<br />
Hacking a small tool that does the job is very easy though, as demonstrated in this post.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christianschenk.org/blog/follow-meta-refresh-with-commons-httpclient/feed/</wfw:commentRss>
		</item>
		<item>
		<title>German translation for xRecurseDiff</title>
		<link>http://www.christianschenk.org/blog/german-translation-for-xrecursediff/</link>
		<comments>http://www.christianschenk.org/blog/german-translation-for-xrecursediff/#comments</comments>
		<pubDate>Tue, 06 May 2008 07:09:06 +0000</pubDate>
		<dc:creator>Christian Schenk</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[diff]]></category>

		<category><![CDATA[translation]]></category>

		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.christianschenk.org/german-translation-for-xrecursediff/</guid>
		<description><![CDATA[If you'd like to compare the files from two directories you may want to try xRecurseDiff that comes with a German translation now]]></description>
			<content:encoded><![CDATA[<p>I was searching for a simple Windows application that compares the files of two directories. This comes in handy if you&#8217;ve downloaded an update to some Open Source software and want to know what exactly changed in the new version. So I found <a href="http://www.matteolucarelli.net/xrecursediff/index_en.htm">xRecurseDiff</a> and it was perfect for my situation.</p>
<p>Since there wasn&#8217;t a German translation for it I created one and the author, Matteo Lucarelli, integrated it into a new release. If you&#8217;re from Germany and don&#8217;t speak English you may want to give this software a shot.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christianschenk.org/blog/german-translation-for-xrecursediff/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Deleting files older than a week under Windows</title>
		<link>http://www.christianschenk.org/blog/deleting-files-older-than-a-week-under-windows/</link>
		<comments>http://www.christianschenk.org/blog/deleting-files-older-than-a-week-under-windows/#comments</comments>
		<pubDate>Wed, 23 Apr 2008 08:15:59 +0000</pubDate>
		<dc:creator>Christian Schenk</dc:creator>
		
		<category><![CDATA[HowTo]]></category>

		<category><![CDATA[at]]></category>

		<category><![CDATA[cron]]></category>

		<category><![CDATA[vbs]]></category>

		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.christianschenk.org/deleting-files-older-than-a-week-under-windows/</guid>
		<description><![CDATA[Shows how to use a Visual Basic script and the at command to delete files older than a week under Windows]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re running a Windows server and want to delete files that are older than, say, a week then Visual Basic comes to the rescue. Once you&#8217;ve got the script running you&#8217;d like Windows to start it every day so you don&#8217;t have to do this manually: <code>at</code> will be your friend here.</p>
<h2>The Visual Basic script</h2>
<p>For everybody who knows how to program in Visual Basic it&#8217;s be pretty easy to write some lines that get the files from a certain directory and deletes them if they haven&#8217;t been changed for some time. For everybody else: just copy the following lines into a file e.g. <code>cleaner.vbs</code>.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="vb"><span style="color: #b1b100;">Dim</span> fso, f, f1, fc
<span style="color: #b1b100;">Set</span> fso = <span style="color: #b1b100;">CreateObject</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Scripting.FileSystemObject&quot;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #b1b100;">Set</span> f = fso.<span style="color: #66cc66;">GetFolder</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;C:\foo\bar&quot;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #b1b100;">Set</span> fc = f.<span style="color: #66cc66;">Files</span>
<span style="color: #b1b100;">For</span> Each f1 in fc
<span style="color: #b1b100;">If</span> <span style="color: #b1b100;">DateDiff</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;d&quot;</span>, f1.<span style="color: #66cc66;">DateLastModified</span>, <span style="color: #b1b100;">Now</span><span style="color: #66cc66;">&#41;</span> &gt; <span style="color: #cc66cc;">7</span> <span style="color: #b1b100;">Then</span> f1.<span style="color: #66cc66;">Delete</span>
<span style="color: #b1b100;">Next</span></pre></td></tr></table></div>

<p>All that&#8217;s left to do is to change the folder in line 3 to whatever you want. Have a look at line 6 and adapt the number of days, currently <code>7</code>, to your needs.</p>
<h2>Running the script</h2>
<p>The <code>at</code> command helps you to run programs at a certain time. Let&#8217;s say we want to run our script every day at 22:30 o&#8217;clock (that&#8217;s 10:30PM) we would type this on the command prompt:</p>

<div class="wp_syntax"><div class="code"><pre class="dos">at <span style="color: #cc66cc;">22</span>:<span style="color: #cc66cc;">30</span> /every:M,T,W,Th,F,S,Su C:\Scripts\cleaner.vbs</pre></div></div>

<p>If we just type <code>at</code> we&#8217;ll see all the tasks that are planned for execution.</p>
<h2>Conclusion</h2>
<p>With a simple Visual Basic script and the <code>at</code> command it&#8217;s pretty easy to run recurring tasks under Windows. If your Windows server is running longer than a week without rebooting this is a really nice solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christianschenk.org/blog/deleting-files-older-than-a-week-under-windows/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Remove clutter from WordPress 2.5</title>
		<link>http://www.christianschenk.org/blog/remove-clutter-from-wordpress-25/</link>
		<comments>http://www.christianschenk.org/blog/remove-clutter-from-wordpress-25/#comments</comments>
		<pubDate>Wed, 16 Apr 2008 08:20:11 +0000</pubDate>
		<dc:creator>Christian Schenk</dc:creator>
		
		<category><![CDATA[HowTo]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.christianschenk.org/remove-clutter-from-wordpress-25/</guid>
		<description><![CDATA[This post shows you how to remove some clutter from your WordPress installation. Namely: RSD and WLW links and some JavaScript.]]></description>
			<content:encoded><![CDATA[<p>After upgrading to WordPress 2.5 I noticed some extra tags in the HTML header of my site: an RSD link, a link to the <code>wlwmanifest.xml</code> and a meta tag with the name set to <code>generator</code>.</p>
<p>While the link tags were introduced in an earlier release of WordPress the meta tag came with 2.5. I&#8217;m pretty sure that the latter will cause incompatibilities with a lot of existing themes that have a line like this in their <code>header.php</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;meta</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;generator&quot;</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">&quot;WordPress 2.3.2&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- leave this for stats please --&gt;</span></span></pre></div></div>

<p>In this post I&#8217;d like to share my ideas about removing some clutter from your WordPress installation. Namely:</p>
<ul>
<li>RSD and WLW links</li>
<li>generator tag</li>
<li>some JavaScript</li>
</ul>
<h2>Removing RSD and WLW links</h2>
<p>Getting rid of this stuff is as easy as using the <a title="WLW Disabler" href="http://www.planetmike.com/plugins/wlw-disabler/">WLW Disabler</a> plugin. After installing and activating the plugin the links are gone. That&#8217;s great.</p>
<h2>Getting rid of the generator tag</h2>
<p>Maybe it&#8217;s possible to write a nice plugin that removes this tag too but a quick and dirty hack is to edit the file <code>general-template.php</code>; you can find it in <code>wp-includes</code>. On line 1187 set the variable <code>$gen</code> to an empty string:</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #808080; font-style: italic;">// ...</span>
<span style="color: #ff0000">$gen</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">;</span>
<span style="color: #b1b100;">return</span> apply_filters<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;get_the_generator_{$type}&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #808080; font-style: italic;">// ...</span></pre></div></div>

<p>If you come up with a clean solution to this please <a href="#respond">leave a comment</a>.</p>
<h2>Living without JavaScript</h2>
<p>Although this isn&#8217;t really related to the previous two I&#8217;d like to share this one too. I&#8217;ve disabled most of the JavaScript that comes with WordPress quite some time ago. And it works great for me: especially the admin pages load a lot faster.</p>
<p>Furthermore I got rid of <a href="http://www.prototypejs.org/">Prototype</a> that doesn&#8217;t play well with SmoothGallery. So, if you&#8217;re using the <a href="http://www.christianschenk.org/projects/wordpress-smoothgallery-plugin/">WordPress SmoothGallery plugin</a> this might be something for you.</p>
<p>Just open the file <code>wp-includes/script-loader.php</code> and comment out the line saying:</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #ff0000">$this</span><span style="color: #66cc66;">-&gt;</span><span style="color: #006600;">default_scripts</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span></pre></div></div>

<p>That&#8217;s it.</p>
<h2>Conclusion</h2>
<p>If you don&#8217;t use Windows Live Writer and the like, using WLW Disabler should be of no harm for you. Disabling some of the JavaScript will give you a performance boost but you&#8217;ll lose some of the nifty features at the same time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christianschenk.org/blog/remove-clutter-from-wordpress-25/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Analyzing letter frequencies of RFCs</title>
		<link>http://www.christianschenk.org/blog/analyzing-letter-frequencies-of-rfcs/</link>
		<comments>http://www.christianschenk.org/blog/analyzing-letter-frequencies-of-rfcs/#comments</comments>
		<pubDate>Wed, 19 Mar 2008 09:15:17 +0000</pubDate>
		<dc:creator>Christian Schenk</dc:creator>
		
		<category><![CDATA[Projects]]></category>

		<category><![CDATA[frequencies]]></category>

		<category><![CDATA[letter]]></category>

		<category><![CDATA[rfc]]></category>

		<guid isPermaLink="false">http://www.christianschenk.org/blog/analyzing-letter-frequencies-of-rfcs/</guid>
		<description><![CDATA[I analyzed the letter frequencies of RFCs and related text files and came to reasonable results]]></description>
			<content:encoded><![CDATA[<p>Lately, I wrote a small <a href="http://www.christianschenk.org/projects/charactercounter/">tool</a> that analyzes letter frequencies of arbitrary text files. So I decided to download all <a href="http://www.rfc-editor.org/">RFC</a>&#8217;s and give the tool a try. I was wondering whether the relative frequencies of letters in the RFC&#8217;s would match those shown on <a href="http://en.wikipedia.org/wiki/Letter_frequencies">Wikipedia</a> or <a href="http://www.google.com/search?q=letter+frequencies">other</a> websites.</p>
<h2>Results</h2>
<p>I ran a case insensitive analysis on 2833 RFC&#8217;s and related text documents from <a href="http://www.rfc-editor.org/">here</a>; all in all 169 MB. This took quite some time but once it was done I had these results, sorted by:</p>
<ul>
<li><a href="http://data.christianschenk.org/analyzing-letter-frequencies-of-rfcs/stat-alph.txt?keepThis=true&#038;TB_iframe=true&#038;height=350&#038;width=200" title="Letter frequencies" class="thickbox">letters</a></li>
<li><a href="http://data.christianschenk.org/analyzing-letter-frequencies-of-rfcs/stat-count.txt?keepThis=true&#038;TB_iframe=true&#038;height=350&#038;width=200" title="Letter frequencies" class="thickbox">occurrence count</a></li>
</ul>
<p>I didn&#8217;t thought that I might come up with nice results so easily.</p>
<p><img src="http://data.christianschenk.org/analyzing-letter-frequencies-of-rfcs/lorfc2.png" alt="Letter frequencies" /></p>
<p>The most frequently used characters make up the word <em>etiansor</em> here.</p>
<h2>Conclusion</h2>
<p>If I seriously wanted to analyze the letter frequencies of a text corpus I would implement some sort of filtering. But without that I got reasonable results too.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christianschenk.org/blog/analyzing-letter-frequencies-of-rfcs/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Iterating over the characters in a string</title>
		<link>http://www.christianschenk.org/blog/iterating-over-the-characters-in-a-string/</link>
		<comments>http://www.christianschenk.org/blog/iterating-over-the-characters-in-a-string/#comments</comments>
		<pubDate>Thu, 13 Mar 2008 14:20:19 +0000</pubDate>
		<dc:creator>Christian Schenk</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[characters]]></category>

		<category><![CDATA[java]]></category>

		<category><![CDATA[performance]]></category>

		<category><![CDATA[string]]></category>

		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://www.christianschenk.org/blog/iterating-over-the-characters-in-a-string/</guid>
		<description><![CDATA[Evaluates the fastest method to iterate over the characters in a string with Java]]></description>
			<content:encoded><![CDATA[<p>I was wondering what would be the fastest method to iterate over the characters in a string with Java. A small test implements the following things:</p>
<ul>
<li>using an Iterable</li>
<li><code>toCharArray()</code></li>
<li><code>charAt()</code></li>
<li>calling <code>charAt()</code> on a <code>CharSequence</code></li>
</ul>
<p>You can download the Eclipse project as a <a href="http://data.christianschenk.org/iterating-over-the-characters-in-a-string/StringIterator-1.0.tar.gz">tar</a> or <a href="http://data.christianschenk.org/iterating-over-the-characters-in-a-string/StringIterator-1.0.zip">zip</a> or browse the code online <a href="http://data.christianschenk.org/iterating-over-the-characters-in-a-string/xref/">here</a>; have a look at the <code>StringIteratorTest</code> class first.</p>
<h2>Results</h2>
<p>Without further ado here are the results:</p>
<table>
<tr>
<th>Variant</th>
<th>Time in ms.</th>
</tr>
<tr>
<td>Iterator</td>
<td>5.5</td>
</tr>
<tr>
<td><code>toCharArray()</code></td>
<td>1.1</td>
</tr>
<tr>
<td><code>charAt()</code></td>
<td>1.6</td>
</tr>
<tr>
<td><code>CharSequence.charAt()</code></td>
<td>2.2</td>
</tr>
</table>
<p><img src="http://data.christianschenk.org/iterating-over-the-characters-in-a-string/stringIterator.jpg" alt="Bar chart of the test results"/></p>
<h2>Conclusion</h2>
<p>If speed is what you want you shouldn&#8217;t use Iterators but one of the other solutions instead. On the other hand if you <em>just like</em> to play with Iterators and classes that implement <code>Iterable</code> you may want to choose the <em>slower</em> solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christianschenk.org/blog/iterating-over-the-characters-in-a-string/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Caching with dynamic proxy classes</title>
		<link>http://www.christianschenk.org/blog/caching-with-dynamic-proxy-classes/</link>
		<comments>http://www.christianschenk.org/blog/caching-with-dynamic-proxy-classes/#comments</comments>
		<pubDate>Thu, 28 Feb 2008 09:25:10 +0000</pubDate>
		<dc:creator>Christian Schenk</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[cache]]></category>

		<category><![CDATA[java]]></category>

		<category><![CDATA[proxy]]></category>

		<guid isPermaLink="false">http://www.christianschenk.org/blog/caching-with-dynamic-proxy-classes/</guid>
		<description><![CDATA[In my last post I used AspectJ to implement a cache that stored the returned result of methods with a special annotation (@Cachable). If you can&#8217;t use AspectJ you may want to use a dynamic proxy class: in this post I&#8217;ll present a solution for this.
You can download the Eclipse project as a tar or [...]]]></description>
			<content:encoded><![CDATA[<p>In my <a title="Caching with AspectJ" href="http://www.christianschenk.org/blog/caching-with-aspectj/">last post</a> I used AspectJ to implement a cache that stored the returned result of methods with a special annotation (<code>@Cachable</code>). If you can&#8217;t use AspectJ you may want to use a dynamic proxy class: in this post I&#8217;ll present a solution for this.</p>
<p>You can download the Eclipse project as a <a href="http://data.christianschenk.org/caching-with-dynamic-proxy-classes/CachingWithProxyInstances-1.0.tar.gz">tar</a> or <a href="http://data.christianschenk.org/caching-with-dynamic-proxy-classes/CachingWithProxyInstances-1.0.zip">zip</a> file or view the code online <a href="http://data.christianschenk.org/caching-with-dynamic-proxy-classes/xref/">here</a>.</p>
<h2>Implementation</h2>
<p>If you don&#8217;t know how <a title="Dynamic Proxy Classes" href="http://java.sun.com/j2se/1.3/docs/guide/reflection/proxy.html">dynamic proxy classes</a> work here&#8217;s a short overview. Let&#8217;s say you want to do some extra work if the methods <code>foo</code> and <code>bar</code> from the class <code>Tee</code> are called. You would extract the methods into an interface and let <code>Tee</code> implement this interface.</p>
<p>Next, you&#8217;d implement a factory that produces a proxy instance for <code>Tee</code> with a custom <code>InvocationHandler</code>. This handler would have a look at the method&#8217;s name and check whether it&#8217;s <code>foo</code> or <code>bar</code>: you can now implement any extra actions in this handler.</p>
<p>You can also examine the annotations of the invoked method and that&#8217;s what I did: if the method has got the <code>@Cachable</code> annotation we&#8217;ll utilize a cache. But how do we know whether we can safely return an object from the cache?</p>
<h3>Constructing a unique method identifier</h3>
<p>This is crucial since we don&#8217;t want to return the same result from the cache if the method was called with different parameters. So we&#8217;ll have to add the values of the parameters to a identifier like so:</p>

<div class="wp_syntax"><div class="code"><pre class="java"><span style="color: #ff0000;">&quot;package-name&quot;</span> + <span style="color: #ff0000;">&quot;class-name&quot;</span> + <span style="color: #ff0000;">&quot;method-name&quot;</span> + <span style="color: #ff0000;">&quot;param1-param2-[...]&quot;</span></pre></div></div>

<p>This way we&#8217;ll create a unique entry in the cache for different method calls.</p>
<h2>How to</h2>
<p>All we have to do is to add <code>@Cachable</code> to some methods:</p>

<div class="wp_syntax"><div class="code"><pre class="java"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> Foo <span style="color: #66cc66;">&#123;</span>
  @Cachable
  <span style="color: #000000; font-weight: bold;">public</span> SomeObject foo<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span> param<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
  @Cachable
  <span style="color: #000000; font-weight: bold;">public</span> AnotherObject bar<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span> param1, <span style="color: #993333;">long</span> param2<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Once we&#8217;ve done that we can use the factory to produce a new proxy instance with our custom <code>InvocationHandler</code>. The handler will use the cache, i.e. the method calls will return faster.</p>
<h2>Conclusion</h2>
<p>In this post I presented a simple solution for a cache that may speed up method calls. Although I recommend using AspectJ for this kind of job you can use dynamic proxy instances if your environment (in most cases read: your project leader) doesn&#8217;t permit you to use AspectJ.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christianschenk.org/blog/caching-with-dynamic-proxy-classes/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Caching with AspectJ</title>
		<link>http://www.christianschenk.org/blog/caching-with-aspectj/</link>
		<comments>http://www.christianschenk.org/blog/caching-with-aspectj/#comments</comments>
		<pubDate>Sat, 16 Feb 2008 09:28:59 +0000</pubDate>
		<dc:creator>Christian Schenk</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[aop]]></category>

		<category><![CDATA[aspectj]]></category>

		<category><![CDATA[cache]]></category>

		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.christianschenk.org/blog/caching-with-aspectj/</guid>
		<description><![CDATA[Shows how to use AspectJ and annotations to implement a simple cache that speeds up your application]]></description>
			<content:encoded><![CDATA[<p>In my <a title="Implementing a simple cache with Java" href="http://www.christianschenk.org/blog/implementing-a-simple-cache-with-java/">last post</a> I presented a very simple cache that stores objects. Now I want to use this cache with <a href="http://www.eclipse.org/aspectj/">AspectJ</a> in a small sample application.</p>
<p>You can download the Eclipse project as a <a href="http://data.christianschenk.org/caching-with-aspectj/CachingWithAspectJ-1.0.tar.gz">tar</a> or <a href="http://data.christianschenk.org/caching-with-aspectj/CachingWithAspectJ-1.0.zip">zip</a> file or browse the code online <a href="http://data.christianschenk.org/caching-with-aspectj/xref/">here</a>.</p>
<h2>Implementing the aspect</h2>
<p>I decided to use an annotation and an aspect with a pointcut that matches this annotation. All I had to do was to annotate the methods that should be cached.</p>
<p>Here&#8217;s the very generic version of a pointcut that matches the execution of all methods annotated with <code>@Cachable</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="java">@Pointcut<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;execution(@Cachable * *.*(..))&quot;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #993333;">void</span> cache<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>The logic is this simple:</p>

<div class="wp_syntax"><div class="code"><pre class="java">@Around<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;cache()&quot;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #aaaadd; font-weight: bold;">Object</span> aroundProfileMethods<span style="color: #66cc66;">&#40;</span>ProceedingJoinPoint thisJoinPoint<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
  <span style="color: #808080; font-style: italic;">// construct genericIdentifier</span>
  <span style="color: #aaaadd; font-weight: bold;">Object</span> obj = cache.<span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span>genericIdentifier<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>obj == <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    obj = thisJoinPoint.<span style="color: #006600;">proceed</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
    cache.<span style="color: #006600;">put</span><span style="color: #66cc66;">&#40;</span>genericIdentifier, obj<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
  <span style="color: #66cc66;">&#125;</span>
  <span style="color: #000000; font-weight: bold;">return</span> obj<span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Everytime a cachable method is executed we&#8217;ll first have a look at the cache. If there&#8217;s a cache hit we&#8217;ll immediately return the object. If there&#8217;s no such object in the cache, we&#8217;ll call the cachable method, put the returned object in the cache and finally return the object.</p>
<p>The <code>genericIdentifier</code> is a string consisting of the package-, class- and method-name and the supplied arguments. For a method named <code>foo</code> from a class <code>bar</code> inside a package called <code>baz</code> this might result in:</p>

<div class="wp_syntax"><div class="code"><pre class="java"><span style="color: #ff0000;">&quot;baz.bar.foo-Integer-42&quot;</span></pre></div></div>

<p>The method <code>foo</code> takes one argument and at the time of this execution it was <code>42</code>. This way we&#8217;ll only return objects from the cache if this <code>generic identifier</code> matches.</p>
<h2>Using the aspect</h2>
<p>All we have to do is to use the <code>@Cachable</code> annotation. Hava a look at it:</p>

<div class="wp_syntax"><div class="code"><pre class="java">@Retention<span style="color: #66cc66;">&#40;</span>RetentionPolicy.<span style="color: #006600;">RUNTIME</span><span style="color: #66cc66;">&#41;</span>
@Target<span style="color: #66cc66;">&#40;</span>ElementType.<span style="color: #006600;">METHOD</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> @<span style="color: #000000; font-weight: bold;">interface</span> Cachable <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>It can be used with any method that returns something:</p>

<div class="wp_syntax"><div class="code"><pre class="java">@Cachable
<span style="color: #000000; font-weight: bold;">public</span> BigObject getObject<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #993333;">int</span> param<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> BigObject<span style="color: #66cc66;">&#40;</span>param<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>The first time this method is called we&#8217;ll store the object in the cache. If it&#8217;s called again with the same parameter we&#8217;ll return the object from the cache.</p>
<h2>Conclusion</h2>
<p>Implementing a cache is simple and so is using it with AspectJ. I presented a straightforward way to speed up any application that deals with <em>big</em> objects which take a long time to load. All you have to do is to use the <code>@Cachable</code> annotation along with the aspect. Implementing another cache in the aspect should be simple, too.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christianschenk.org/blog/caching-with-aspectj/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Implementing a simple cache with Java</title>
		<link>http://www.christianschenk.org/blog/implementing-a-simple-cache-with-java/</link>
		<comments>http://www.christianschenk.org/blog/implementing-a-simple-cache-with-java/#comments</comments>
		<pubDate>Sun, 10 Feb 2008 14:38:24 +0000</pubDate>
		<dc:creator>Christian Schenk</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[cache]]></category>

		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.christianschenk.org/blog/implementing-a-simple-cache-with-java/</guid>
		<description><![CDATA[I present a simple cache written in Java that can be used to store objects of any kind]]></description>
			<content:encoded><![CDATA[<p>In this post I&#8217;ll present a simple cache written in Java. It can be used to store objects of any kind or specific types only. The objects will expire after a certain time that can be customized too. Since this cache is really simple I didn&#8217;t implement a caching strategy nor an option for a maximum capacity.</p>
<p>You can download the Eclipse project as <a href="http://data.christianschenk.org/implementing-a-simple-cache-with-java/SimpleCache-1.0.tar.gz">tar</a> or <a href="http://data.christianschenk.org/implementing-a-simple-cache-with-java/SimpleCache-1.0.tar.gz">zip</a> or browse the code online <a href="http://data.christianschenk.org/implementing-a-simple-cache-with-java/xref/">here</a>.</p>
<h2>Basic operations</h2>
<p>The cache supports these basic operations: you can <code>put</code> and <code>get</code> objects. If you put an object you can specify a time in seconds - after this time period the object will be remove from the cache.</p>
<p>Getting an object from the cache is simple too and you&#8217;ve also got the possibility to specify the type of the object you&#8217;re retrieving from the cache - this adds some type safety.</p>
<p>Have a look at this sample code:</p>

<div class="wp_syntax"><div class="code"><pre class="java">SimpleCache<span style="color: #66cc66;">&lt;</span>Integer<span style="color: #66cc66;">&gt;</span> intCache = <span style="color: #000000; font-weight: bold;">new</span> SimpleCache<span style="color: #66cc66;">&lt;</span>Integer<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
intCache.<span style="color: #006600;">put</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;one&quot;</span>, <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
assertEquals<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #aaaadd; font-weight: bold;">Integer</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>, intCache.<span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;one&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span></pre></div></div>

<p>This creates a <code>SimpleCache</code> that holds objects derived from <code>Integer</code>. Since you parameterized this cache with <code>Integer</code> you&#8217;ll only be able to <code>put</code> and <code>get</code> integers.</p>
<p>If you want to save all different kinds of objects in the cache that&#8217;s no problem at all. If you do this you can use the convenience method <code>get</code> which performs a cast for you. Have a look at this example:</p>

<div class="wp_syntax"><div class="code"><pre class="java">SimpleCache cache = <span style="color: #000000; font-weight: bold;">new</span> SimpleCache<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
cache.<span style="color: #006600;">put</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;one&quot;</span>, <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
cache.<span style="color: #006600;">put</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;str&quot;</span>, <span style="color: #ff0000;">&quot;Some string&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
assertEquals<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #aaaadd; font-weight: bold;">Integer</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>, cache.<span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;one&quot;</span>, <span style="color: #aaaadd; font-weight: bold;">Integer</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
assertEquals<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Some string&quot;</span>, cache.<span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;str&quot;</span>, <span style="color: #aaaadd; font-weight: bold;">String</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span></pre></div></div>

<p>I think it&#8217;s better to create several instances of <code>SimpleCache</code> that store objects of a specific type.</p>
<h2>Removing expired objects</h2>
<p>Once an object is expired we want to remove it from the cache. The <code>SimpleCache</code> class supports two ways of removing old objects:</p>
<ol>
<li>if the <code>get</code> method is called we&#8217;ll check whether the object that&#8217;s about to be returned is expired. If that&#8217;s the case we&#8217;ll remove it from the cache.</li>
<li>a thread that runs periodically removes expired objects from the cache.</li>
</ol>
<p>Both features reside in implementations of <code>Runnable</code> so they can be executed in separate threads. This way the basic operations will not be slowed down by this kind of housekeeping.</p>
<p>With Java 5 it&#8217;s easy to schedule recurring tasks with the <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/Executors.html">Executors</a> class. To remove expired objects from the cache we can use this code:</p>

<div class="wp_syntax"><div class="code"><pre class="java"><span style="color: #aaaadd; font-weight: bold;">Runnable</span> cleaner = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #aaaadd; font-weight: bold;">Runnable</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> run<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #808080; font-style: italic;">/* remove expired objects here */</span> <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">;</span>
Executors.<span style="color: #006600;">newScheduledThreadPool</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>
         .<span style="color: #006600;">scheduleWithFixedDelay</span><span style="color: #66cc66;">&#40;</span>cleaner, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">30</span>, TimeUnit.<span style="color: #006600;">SECONDS</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span></pre></div></div>

<h2>Conclusion</h2>
<p>I presented a very simple cache written in Java that stores objects of any kind. It&#8217;s configurable, type safe and easy to use; it should be pretty easy to integrate this cache into an existing project.</p>
<p>I&#8217;ve tried to keep the cache fast: certain tasks will be executed in threads to speed things up. But don&#8217;t worry because the threads are easy to maintain and to understand.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christianschenk.org/blog/implementing-a-simple-cache-with-java/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Integrate SmoothGallery into WordPress</title>
		<link>http://www.christianschenk.org/blog/integrate-smoothgallery-into-wordpress/</link>
		<comments>http://www.christianschenk.org/blog/integrate-smoothgallery-into-wordpress/#comments</comments>
		<pubDate>Tue, 05 Feb 2008 22:45:33 +0000</pubDate>
		<dc:creator>Christian Schenk</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[plugin]]></category>

		<category><![CDATA[prototype]]></category>

		<category><![CDATA[smoothgallery]]></category>

		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.christianschenk.org/blog/integrate-smoothgallery-into-wordpress/</guid>
		<description><![CDATA[SmoothGallery doesn't play well with Prototype if you're using Internet Explorer so don't use them together]]></description>
			<content:encoded><![CDATA[<p>Lately I&#8217;ve been working on a <a href="http://www.christianschenk.org/projects/wordpress-smoothgallery-plugin/">plugin</a> that integrates JonDesign&#8217;s <a href="http://smoothgallery.jondesign.net/">SmoothGallery</a> into WordPress. Basically this is pretty straightforward because all I had to do was to build some code around the JavaScript and CSS and put everything into a plugin.</p>
<p>Then I was <a href="http://www.christianschenk.org/projects/wordpress-smoothgallery-plugin/#comment-636">told</a> that the plugin as I built it wasn&#8217;t working with Internet Explorer. I booted up Windows and came up with a solution to this <em>problem</em> that I want to share here: don&#8217;t embed SmoothGallery and <a href="http://www.prototypejs.org/">Prototype</a> on the same page.</p>
<h2>SmoothGallery and Prototype</h2>
<p>Jonathan warns us on the <a href="http://smoothgallery.jondesign.net/download/">download page</a> that he doesn&#8217;t recommend the <code>namespaced</code> version of SmoothGallery because of incompatible frameworks like <a href="http://www.prototypejs.org/">Prototype</a> or <a href="http://jquery.com/">jQuery</a>.</p>
<p>I did some tests and found out that SmoothGallery doesn&#8217;t work with Prototype at all - if you&#8217;re using Internet Explorer. You can download the tests <a title="Tests using SmoothGallery and Prototype" href="http://data.christianschenk.org/integrate-smoothgallery-into-wordpress/sg-ie-test.zip">here</a>: Just open the HTML files and check whether the gallery is present.</p>
<p>Have a look at my results:</p>
<table class="cmpicons">
<thead>
<tr>
<th>SmoothGallery</th>
<th>Prototype</th>
<th>Internet Explorer</th>
<th>Firefox</th>
<th>Safari</th>
</tr>
</thead>
<tr>
<td>1.2</td>
<td class="present"><span>Present</span></td>
<td class="doesntwork"><span>Doesn&#8217;t work</span></td>
<td class="works"><span>Works</span></td>
<td class="works"><span>Works</span></td>
</tr>
<tr>
<td>1.2</td>
<td class="notpresent"><span>Not present</span></td>
<td class="works"><span>Works</span></td>
<td class="works"><span>Works</span></td>
<td class="works"><span>Works</span></td>
</tr>
<tr>
<td>2.0</td>
<td class="present"><span>Present</span></td>
<td class="doesntwork"><span>Doesn&#8217;t work</span></td>
<td class="works"><span>Works</span></td>
<td class="works"><span>Works</span></td>
</tr>
<tr>
<td>2.0</td>
<td class="notpresent"><span>Not present</span></td>
<td class="works"><span>Works</span></td>
<td class="works"><span>Works</span></td>
<td class="works"><span>Works</span></td>
</tr>
</table>
<p>If you try to use SmoothGallery with Prototype enabled in Internet Explorer the gallery won&#8217;t be rendered; I have tested this with version 6 and 7 of IE. No problems with Firefox or Safari though.</p>
<p>There&#8217;s another thing I noticed: if you change the order of the <code>script</code> entries in the HTML header IE will display the images of the gallery in two different ways. Either you&#8217;ll be able to see all pictures in the gallery or you&#8217;ll just see the first one.</p>
<p>Another observation is that SmoothGallery breaks apart if you insert an <code>a</code> tag with the <code>name</code> set to <em>options</em>. Once you&#8217;ve inserted such an anchor IE won&#8217;t render the gallery; again no problems with Firefox or Safari.</p>
<h2>Conclusion</h2>
<p>I&#8217;ve just explained what I observed testing JonDesign&#8217;s SmoothGallery and Prototype with Internet Explorer, Firefox and Safari. I didn&#8217;t take a look at the JavaScript and didn&#8217;t search for a solution there.</p>
<p>If you want IE users to watch a <em>smooth</em> gallery on your website it seems that there&#8217;s no other way than to get rid of Prototype - remove it at least from the specific page you&#8217;re using a SmoothGallery on.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christianschenk.org/blog/integrate-smoothgallery-into-wordpress/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 1.612 seconds -->
<!-- Cached page served by WP-Cache -->
<!-- Compression = gzip -->