<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Letsgetdugg</title>
	
	<link>http://letsgetdugg.com</link>
	<description>Random tech jargon</description>
	<lastBuildDate>Fri, 21 Jan 2011 19:31:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/Letsgetdugg" /><feedburner:info uri="letsgetdugg" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>MySQL ZFS Snapshot Backups</title>
		<link>http://feedproxy.google.com/~r/Letsgetdugg/~3/99mQAKmi6Dc/</link>
		<comments>http://letsgetdugg.com/2010/08/31/mysql-zfs-snapshot-backups/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 22:08:43 +0000</pubDate>
		<dc:creator>victori</dc:creator>
				<category><![CDATA[administration]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[zfs]]></category>

		<guid isPermaLink="false">http://letsgetdugg.com/?p=767</guid>
		<description><![CDATA[This is a followup on my previous post concerning how to correctly snapshot databases on ZFS. Snapshotting MySQL any other way will just lead to corrupt database states, essentially making your backups useless. Here is my script that I use to snapshot our MySQL database. It uses my zBackup.rb script for the automated backup rotation. [...]]]></description>
			<content:encoded><![CDATA[<p>This is a followup on my previous <a href="http://letsgetdugg.com/2010/06/23/postgresql-zfs-snapshot-backups/">post concerning how to correctly snapshot databases on ZFS</a>. Snapshotting MySQL any other way will just lead to corrupt database states, essentially making your backups useless. </p>
<p>Here is my script that I use to snapshot our MySQL database. It uses my <a href="http://letsgetdugg.com/2010/03/30/automated-zfs-snapshots/">zBackup.rb script</a> for the automated backup rotation. </p>
<div class="codesnip-container" >#!/bin/sh</p>
<p>mysql -h fab2 -u usr -ppass -e &#8216;flush tables;flush tables with read lock;&#8217;</p>
<p>/usr/bin/ruby /opt/zbackup.rb rpool/mydata 7</p>
<p>mysql -h fab2 -u usr -ppass -e &#8216;unlock tables;&#8217;</p></div>
<img src="http://feeds.feedburner.com/~r/Letsgetdugg/~4/99mQAKmi6Dc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://letsgetdugg.com/2010/08/31/mysql-zfs-snapshot-backups/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://letsgetdugg.com/2010/08/31/mysql-zfs-snapshot-backups/</feedburner:origLink></item>
		<item>
		<title>Ruby LocaleTranslator</title>
		<link>http://feedproxy.google.com/~r/Letsgetdugg/~3/JXOtBU0bOS4/</link>
		<comments>http://letsgetdugg.com/2010/07/20/ruby-locale-translator/#comments</comments>
		<pubDate>Tue, 20 Jul 2010 21:05:55 +0000</pubDate>
		<dc:creator>victori</dc:creator>
				<category><![CDATA[main]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[localization]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://letsgetdugg.com/?p=741</guid>
		<description><![CDATA[Today, I am open sourcing my Ruby LocaleTranslator; the translator uses google&#8217;s translator API to translate a primary seed locale into various other languages. This eases the creation of multi-lingual sites. Not only can the LocaleTranslator translate your main seed locale into different languages but it can also recursively merge in differences, this comes in [...]]]></description>
			<content:encoded><![CDATA[<p>Today, I am open sourcing my Ruby LocaleTranslator; the translator uses google&#8217;s translator API to translate a primary seed locale into various other languages. This eases the creation of multi-lingual sites. Not only can the LocaleTranslator translate your main seed locale into different languages but it can also recursively merge in differences, this comes in handy if you have hand-optimized your translated locales.</p>
<p>Viva Localization!</p>
<p>My projects that use the LocaleTranslator;  <a href="http://uploadbooth.com/">UploadBooth</a>, <a href="http://pastebooth.com/">PasteBooth</a> and <a href="http://shrinkbooth.com/">ShrinkBooth</a>.</p>
<h3>LocaleTranslator Examples</h3>
<p><strong>en.yml</strong></p>
<pre>
<div class="codesnip-container" >site:
  hello_world: Hello World!
  home: Home
  statement: Localization should be simple!</div>
</pre>
<p>Batch Conversion of your English locale.</p>
<div class="codesnip-container" >
<div class="ruby codesnip" style="font-family:monospace;"><span class="co1">#!/opt/local/bin/ruby</span></p>
<p><span class="kw3">require</span> <span class="st0">&#8216;monkey-patches.rb&#8217;</span><br />
<span class="kw3">require</span> <span class="st0">&#8216;locale_translator.rb&#8217;</span></p>
<p>en_yml = <span class="kw4">YAML</span>::<span class="kw3">load</span><span class="br0">&#40;</span><span class="kw4">File</span>.<span class="kw3">open</span><span class="br0">&#40;</span><span class="st0">&#8216;en.yml&#8217;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></p>
<p><span class="br0">&#91;</span><span class="re3">:de</span>,:ru<span class="br0">&#93;</span>.<span class="me1">each</span> <span class="kw1">do</span> <span class="sy0">|</span>lang<span class="sy0">|</span><br />
&nbsp; lang_yml = LocaleTranslator.<span class="me1">translate</span><span class="br0">&#40;</span>en_yml,<br />
&nbsp; &nbsp; <span class="re3">:to</span><span class="sy0">=&gt;</span>lang,<br />
&nbsp; &nbsp; <span class="re3">:html</span><span class="sy0">=&gt;</span>true,<br />
&nbsp; &nbsp; <span class="re3">:key</span><span class="sy0">=&gt;</span><span class="st0">&#8216;GOOGLE API KEY&#8217;</span><span class="br0">&#41;</span><br />
&nbsp; f = <span class="kw4">File</span>.<span class="me1">new</span><span class="br0">&#40;</span><span class="st0">&quot;#{lang.to_s.downcase}.yml&quot;</span>,<span class="st0">&quot;w&quot;</span><span class="br0">&#41;</span><br />
&nbsp; f.<span class="kw3">puts</span><span class="br0">&#40;</span>lang_yml.<span class="me1">ya2yaml</span><span class="br0">&#40;</span><span class="re3">:syck_compatible</span> <span class="sy0">=&gt;</span> <span class="kw2">true</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; f.<span class="me1">close</span><br />
&nbsp; <span class="kw3">p</span> <span class="st0">&quot;Translated to #{lang.to_s}&quot;</span><br />
<span class="kw1">end</span></div>
</div>
<p>Merge in new locale keys from your English Locale into your already translated Russian locale.</p>
<div class="codesnip-container" >
<div class="ruby codesnip" style="font-family:monospace;"><span class="co1">#!/opt/local/bin/ruby</span></p>
<p><span class="kw3">require</span> <span class="st0">&#8216;monkey-patches.rb&#8217;</span><br />
<span class="kw3">require</span> <span class="st0">&#8216;locale_translator.rb&#8217;</span></p>
<p>en_yml = <span class="kw4">YAML</span>::<span class="kw3">load</span><span class="br0">&#40;</span><span class="kw4">File</span>.<span class="kw3">open</span><span class="br0">&#40;</span><span class="st0">&#8216;en.yml&#8217;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
ru_yml = <span class="kw4">YAML</span>::<span class="kw3">load</span><span class="br0">&#40;</span><span class="kw4">File</span>.<span class="kw3">open</span><span class="br0">&#40;</span><span class="st0">&#8216;ru.yml&#8217;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></p>
<p>ru_new_yml = LocaleTranslator.<span class="me1">translate</span><span class="br0">&#40;</span>en_yml,<br />
&nbsp; <span class="re3">:to</span><span class="sy0">=&gt;</span>:ru,<br />
&nbsp; <span class="re3">:html</span><span class="sy0">=&gt;</span>true,<br />
&nbsp; <span class="re3">:merge</span><span class="sy0">=&gt;</span>ru_yml,<br />
&nbsp; <span class="re3">:key</span><span class="sy0">=&gt;</span><span class="st0">&#8216;GOOGLE API KEY&#8217;</span><span class="br0">&#41;</span><br />
<span class="kw3">puts</span> ru_new_yml.<span class="me1">ya2yaml</span><span class="br0">&#40;</span><span class="re3">:syck_compatible</span> <span class="sy0">=&gt;</span> <span class="kw2">true</span><span class="br0">&#41;</span></div>
</div>
<h3>The Implementation Code</h3>
<p><strong>Support Monkey Patches</strong></p>
<p><strong>monkey-patches.rb</strong></p>
<div class="codesnip-container" >
<div class="ruby codesnip" style="font-family:monospace;"><span class="kw1">class</span> <span class="kw4">Hash</span><br />
&nbsp; <span class="kw1">def</span> to_list<br />
&nbsp; &nbsp; h2l<span class="br0">&#40;</span><span class="kw2">self</span><span class="br0">&#41;</span><br />
&nbsp; <span class="kw1">end</span><br />
&nbsp; <br />
&nbsp; <span class="kw1">def</span> diff<span class="br0">&#40;</span>hash<span class="br0">&#41;</span><br />
&nbsp; &nbsp; hsh = <span class="br0">&#123;</span><span class="br0">&#125;</span><br />
&nbsp; &nbsp; this = <span class="kw2">self</span><br />
&nbsp; &nbsp; hash.<span class="me1">each</span> <span class="kw1">do</span> <span class="sy0">|</span>k,v<span class="sy0">|</span> <br />
&nbsp; &nbsp; &nbsp; <span class="kw1">if</span> v.<span class="me1">kind_of</span>?<span class="kw4">Hash</span> <span class="kw1">and</span> this.<span class="me1">key</span>?k<br />
&nbsp; &nbsp; &nbsp; &nbsp; tmp = this<span class="br0">&#91;</span>k<span class="br0">&#93;</span>.<span class="me1">diff</span><span class="br0">&#40;</span>v<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; hsh<span class="br0">&#91;</span>k<span class="br0">&#93;</span> = tmp <span class="kw1">if</span> tmp.<span class="me1">size</span> <span class="sy0">&gt;</span> 0 <br />
&nbsp; &nbsp; &nbsp; <span class="kw1">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; hsh<span class="br0">&#91;</span>k<span class="br0">&#93;</span> = v <span class="kw1">unless</span> this.<span class="me1">key</span>?k <br />
&nbsp; &nbsp; &nbsp; <span class="kw1">end</span><br />
&nbsp; &nbsp; <span class="kw1">end</span><br />
&nbsp; &nbsp; hsh<br />
&nbsp; <span class="kw1">end</span><br />
&nbsp; <br />
&nbsp; <span class="kw1">def</span> merge_r<span class="br0">&#40;</span>hash<span class="br0">&#41;</span><br />
&nbsp; &nbsp; hsh = <span class="br0">&#123;</span><span class="br0">&#125;</span><br />
&nbsp; &nbsp; this = <span class="kw2">self</span><br />
&nbsp; &nbsp; hash.<span class="me1">each</span> <span class="kw1">do</span> <span class="sy0">|</span>k,v<span class="sy0">|</span> <br />
&nbsp; &nbsp; &nbsp; <span class="kw1">if</span> v.<span class="me1">kind_of</span>?<span class="kw4">Hash</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; hsh<span class="br0">&#91;</span>k<span class="br0">&#93;</span> = this<span class="br0">&#91;</span>k<span class="br0">&#93;</span>.<span class="me1">merge_r</span><span class="br0">&#40;</span>v<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; hsh<span class="br0">&#91;</span>k<span class="br0">&#93;</span> = v<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">end</span><br />
&nbsp; &nbsp; <span class="kw1">end</span><br />
&nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">merge</span><span class="br0">&#40;</span>hsh<span class="br0">&#41;</span><br />
&nbsp; <span class="kw1">end</span><br />
&nbsp; <br />
&nbsp; private <br />
&nbsp; &nbsp; <span class="kw1">def</span> h2l<span class="br0">&#40;</span>hash<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; list = <span class="br0">&#91;</span><span class="br0">&#93;</span><br />
&nbsp; &nbsp; &nbsp; hash.<span class="me1">each</span> <span class="br0">&#123;</span><span class="sy0">|</span>k,v<span class="sy0">|</span> list = <span class="br0">&#40;</span>v.<span class="me1">kind_of</span>?<span class="kw4">Hash</span><span class="br0">&#41;</span> ? list.<span class="me1">merge_with_dups</span><span class="br0">&#40;</span>h2l<span class="br0">&#40;</span>v<span class="br0">&#41;</span><span class="br0">&#41;</span> : list <span class="sy0">&lt;&lt;</span> v <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; list<br />
&nbsp; &nbsp; <span class="kw1">end</span><br />
<span class="kw1">end</span></p>
<p><span class="kw1">class</span> <span class="kw3">Array</span><br />
&nbsp; <span class="kw1">def</span> chunk<span class="br0">&#40;</span><span class="kw3">p</span>=2<span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="kw2">return</span> <span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="kw1">if</span> <span class="kw3">p</span>.<span class="me1">zero</span>?<br />
&nbsp; &nbsp; p_size = <span class="br0">&#40;</span>length.<span class="me1">to_f</span> <span class="sy0">/</span> <span class="kw3">p</span><span class="br0">&#41;</span>.<span class="me1">ceil</span><br />
&nbsp; &nbsp; <span class="br0">&#91;</span>first<span class="br0">&#40;</span>p_size<span class="br0">&#41;</span>, <span class="sy0">*</span>last<span class="br0">&#40;</span>length <span class="sy0">-</span> p_size<span class="br0">&#41;</span>.<span class="me1">chunk</span><span class="br0">&#40;</span><span class="kw3">p</span> <span class="sy0">-</span> 1<span class="br0">&#41;</span><span class="br0">&#93;</span><br />
&nbsp; <span class="kw1">end</span><br />
&nbsp; <span class="kw1">def</span> to_hash<span class="br0">&#40;</span>hash<span class="br0">&#41;</span><br />
&nbsp; &nbsp; l2h<span class="br0">&#40;</span>hash,<span class="kw2">self</span><span class="br0">&#41;</span><br />
&nbsp; <span class="kw1">end</span><br />
&nbsp; <span class="kw1">def</span> merge<span class="br0">&#40;</span>arr<span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="kw2">self</span> <span class="sy0">|</span> arr<br />
&nbsp; <span class="kw1">end</span><br />
&nbsp; <span class="kw1">def</span> merge_with_dups<span class="br0">&#40;</span>arr<span class="br0">&#41;</span><br />
&nbsp; &nbsp; temp = <span class="br0">&#91;</span><span class="br0">&#93;</span><br />
&nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">each</span> <span class="br0">&#123;</span><span class="sy0">|</span>a<span class="sy0">|</span> temp <span class="sy0">&lt;&lt;</span> a <span class="br0">&#125;</span><br />
&nbsp; &nbsp; arr.<span class="me1">each</span> <span class="br0">&#123;</span><span class="sy0">|</span>a<span class="sy0">|</span> temp <span class="sy0">&lt;&lt;</span> a <span class="br0">&#125;</span><br />
&nbsp; &nbsp; temp<br />
&nbsp; <span class="kw1">end</span><br />
&nbsp; <span class="kw1">def</span> merge!<span class="br0">&#40;</span>arr<span class="br0">&#41;</span><br />
&nbsp; &nbsp; temp = <span class="kw2">self</span>.<span class="me1">clone</span><br />
&nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">clear</span><br />
&nbsp; &nbsp; temp.<span class="me1">each</span> <span class="br0">&#123;</span><span class="sy0">|</span>a<span class="sy0">|</span> <span class="kw2">self</span> <span class="sy0">&lt;&lt;</span> a <span class="br0">&#125;</span><br />
&nbsp; &nbsp; arr.<span class="me1">each</span> <span class="br0">&#123;</span><span class="sy0">|</span>a<span class="sy0">|</span> <span class="kw2">self</span> <span class="sy0">&lt;&lt;</span> a <span class="kw1">unless</span> temp.<span class="kw1">include</span>?a <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="kw2">true</span><br />
&nbsp; <span class="kw1">end</span><br />
&nbsp; <span class="kw1">def</span> merge_with_dups!<span class="br0">&#40;</span>arr<span class="br0">&#41;</span><br />
&nbsp; &nbsp; temp = <span class="kw2">self</span>.<span class="me1">clone</span><br />
&nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">clear</span><br />
&nbsp; &nbsp; temp.<span class="me1">each</span> <span class="br0">&#123;</span><span class="sy0">|</span>a<span class="sy0">|</span> <span class="kw2">self</span> <span class="sy0">&lt;&lt;</span> a <span class="br0">&#125;</span><br />
&nbsp; &nbsp; arr.<span class="me1">each</span> <span class="br0">&#123;</span><span class="sy0">|</span>a<span class="sy0">|</span> <span class="kw2">self</span> <span class="sy0">&lt;&lt;</span> a <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="kw2">true</span><br />
&nbsp; <span class="kw1">end</span><br />
&nbsp; private<br />
&nbsp; &nbsp; <span class="kw1">def</span> l2h<span class="br0">&#40;</span>hash,lst<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; hsh = <span class="br0">&#123;</span><span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; hash.<span class="me1">each</span> <span class="br0">&#123;</span><span class="sy0">|</span>k,v<span class="sy0">|</span> hsh<span class="br0">&#91;</span>k<span class="br0">&#93;</span> = <span class="br0">&#40;</span>v.<span class="me1">kind_of</span>?<span class="kw4">Hash</span><span class="br0">&#41;</span> ? l2h<span class="br0">&#40;</span>v,lst<span class="br0">&#41;</span> : lst.<span class="me1">shift</span> <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; hsh<br />
&nbsp; &nbsp; <span class="kw1">end</span><br />
<span class="kw1">end</span></div>
</div>
<p><strong>The LocaleTranslator Implementation</strong></p>
<p>You need the ya2yaml and easy_translate gems. Ya2YAML can export locales in UTF-8 unlike the standard yaml implementation that can only export in binary for non-standard ascii.</p>
<p><strong>locale-translator.rb</strong></p>
<div class="codesnip-container" >
<div class="ruby codesnip" style="font-family:monospace;"><span class="re0">$KCODE</span> = <span class="st0">&#8216;UTF8&#8242;</span> <span class="kw1">if</span> RUBY_VERSION <span class="sy0">&lt;</span> <span class="st0">&#8217;1.9.0&#8242;</span><br />
<span class="kw3">require</span> <span class="st0">&#8216;rubygems&#8217;</span><br />
<span class="kw3">require</span> <span class="st0">&#8216;ya2yaml&#8217;</span><br />
<span class="kw3">require</span> <span class="st0">&#8216;yaml&#8217;</span><br />
<span class="kw3">require</span> <span class="st0">&#8216;easy_translate&#8217;</span></p>
<p><span class="kw1">class</span> LocaleTranslator<br />
&nbsp; <span class="kw1">def</span> <span class="kw2">self</span>.<span class="me1">translate</span><span class="br0">&#40;</span>text,opts<span class="br0">&#41;</span><br />
&nbsp; &nbsp; opts<span class="br0">&#91;</span><span class="re3">:to</span><span class="br0">&#93;</span> = <span class="br0">&#91;</span>opts<span class="br0">&#91;</span><span class="re3">:to</span><span class="br0">&#93;</span><span class="br0">&#93;</span> <span class="kw1">if</span> opts<span class="br0">&#91;</span><span class="re3">:to</span><span class="br0">&#93;</span> <span class="kw1">and</span> !opts<span class="br0">&#91;</span><span class="re3">:to</span><span class="br0">&#93;</span>.<span class="me1">kind_of</span>?<span class="kw3">Array</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw1">if</span> opts<span class="br0">&#91;</span><span class="re3">:merge</span><span class="br0">&#93;</span>.<span class="me1">kind_of</span>?<span class="kw4">Hash</span> <span class="kw1">and</span> text.<span class="me1">kind_of</span>?<span class="kw4">Hash</span><br />
&nbsp; &nbsp; &nbsp; diff = opts<span class="br0">&#91;</span><span class="re3">:merge</span><span class="br0">&#93;</span>.<span class="me1">diff</span><span class="br0">&#40;</span>text<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; diff_hsh = LocaleTranslator.<span class="me1">translate</span><span class="br0">&#40;</span>diff,:to<span class="sy0">=&gt;</span>opts<span class="br0">&#91;</span><span class="re3">:to</span><span class="br0">&#93;</span>,:html<span class="sy0">=&gt;</span>true<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw2">return</span> opts<span class="br0">&#91;</span><span class="re3">:merge</span><span class="br0">&#93;</span>.<span class="me1">merge_r</span><span class="br0">&#40;</span>diff_hsh<span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="kw1">end</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw1">if</span> text.<span class="me1">kind_of</span>?<span class="kw4">Hash</span><br />
&nbsp; &nbsp; &nbsp; t_arr = text.<span class="me1">to_list</span><br />
&nbsp; &nbsp; &nbsp; t_arr = t_arr.<span class="me1">first</span> <span class="kw1">if</span> t_arr.<span class="me1">size</span> == 1<br />
&nbsp; &nbsp; &nbsp; tout_arr = LocaleTranslator.<span class="me1">translate</span><span class="br0">&#40;</span>t_arr,:to<span class="sy0">=&gt;</span>opts<span class="br0">&#91;</span><span class="re3">:to</span><span class="br0">&#93;</span>,:html<span class="sy0">=&gt;</span>true<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; tout_arr = <span class="br0">&#91;</span>tout_arr<span class="br0">&#93;</span> <span class="kw1">if</span> tout_arr.<span class="me1">kind_of</span>?<span class="kw3">String</span><br />
&nbsp; &nbsp; &nbsp; tout_arr.<span class="me1">to_hash</span><span class="br0">&#40;</span>text<span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="kw1">elsif</span> text.<span class="me1">kind_of</span>?<span class="kw3">Array</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">if</span> text.<span class="me1">size</span> <span class="sy0">&gt;</span> 50<br />
&nbsp; &nbsp; &nbsp; &nbsp; out = <span class="br0">&#91;</span><span class="br0">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; text.<span class="me1">chunk</span>.<span class="me1">each</span> <span class="br0">&#123;</span><span class="sy0">|</span>l<span class="sy0">|</span> out.<span class="me1">merge_with_dups</span>!<span class="br0">&#40;</span>EasyTranslate.<span class="me1">translate</span><span class="br0">&#40;</span>l,opts<span class="br0">&#41;</span>.<span class="me1">first</span><span class="br0">&#41;</span> <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; out<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; text = text.<span class="me1">first</span> <span class="kw1">if</span> text.<span class="me1">size</span> == 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; EasyTranslate.<span class="me1">translate</span><span class="br0">&#40;</span>text,opts<span class="br0">&#41;</span>.<span class="me1">first</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">end</span><br />
&nbsp; &nbsp; <span class="kw1">else</span><br />
&nbsp; &nbsp; &nbsp; EasyTranslate.<span class="me1">translate</span><span class="br0">&#40;</span>text,opts<span class="br0">&#41;</span>.<span class="me1">first</span><br />
&nbsp; &nbsp; <span class="kw1">end</span><br />
&nbsp; <span class="kw1">end</span><br />
<span class="kw1">end</span></div>
</div>
<img src="http://feeds.feedburner.com/~r/Letsgetdugg/~4/JXOtBU0bOS4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://letsgetdugg.com/2010/07/20/ruby-locale-translator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://letsgetdugg.com/2010/07/20/ruby-locale-translator/</feedburner:origLink></item>
		<item>
		<title>MacOS X ZFS Samba Transfer Fix</title>
		<link>http://feedproxy.google.com/~r/Letsgetdugg/~3/wLGi6_Wvtbg/</link>
		<comments>http://letsgetdugg.com/2010/07/18/macos-x-zfs-samba-transfer-fix/#comments</comments>
		<pubDate>Sun, 18 Jul 2010 16:19:01 +0000</pubDate>
		<dc:creator>victori</dc:creator>
				<category><![CDATA[administration]]></category>
		<category><![CDATA[main]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[fix]]></category>
		<category><![CDATA[zfs]]></category>

		<guid isPermaLink="false">http://letsgetdugg.com/?p=737</guid>
		<description><![CDATA[I have a very non-standard storage setup at home. The setup is made up of a 3x500G raidz array on ZFS hosted by OSX. For the longest time I could not get files to copy over samba on ZFS. The files would stream just fine but not copy over, they would abort at the 99% [...]]]></description>
			<content:encoded><![CDATA[<p>I have a very non-standard storage setup at home. The setup is made up of a 3x500G raidz array on ZFS hosted by OSX. For the longest time I could not get files to copy over samba on ZFS. The files would stream just fine but not copy over, they would abort at the 99% transfer point. Well, I have finally found the fix for it; turn off extended attributes!</p>
<p>smb.conf</p>
<div class="codesnip-container" >#vfs objects = notify_kqueue,darwinacl,darwin_streams<br />
    vfs objects = notify_kqueue,darwinacl</p>
<p>    ; The darwin_streams module gives us named streams support.<br />
    stream support = no<br />
    ea support = no</p>
<p>    ; Enable locking coherency with AFP.<br />
    darwin_streams:brlm = no</p></div>
<p>As Charles Heston would say, You can have my ZFS when you pry it from my cold dead hands. </p>
<p>viva ZFS on OSX!</p>
<img src="http://feeds.feedburner.com/~r/Letsgetdugg/~4/wLGi6_Wvtbg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://letsgetdugg.com/2010/07/18/macos-x-zfs-samba-transfer-fix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://letsgetdugg.com/2010/07/18/macos-x-zfs-samba-transfer-fix/</feedburner:origLink></item>
		<item>
		<title>STOMP Client on JRuby</title>
		<link>http://feedproxy.google.com/~r/Letsgetdugg/~3/Sqsn13WuUO4/</link>
		<comments>http://letsgetdugg.com/2010/07/16/stomp-client-on-jruby/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 18:13:59 +0000</pubDate>
		<dc:creator>victori</dc:creator>
				<category><![CDATA[main]]></category>
		<category><![CDATA[jruby]]></category>
		<category><![CDATA[monkey-patching]]></category>

		<guid isPermaLink="false">http://letsgetdugg.com/?p=733</guid>
		<description><![CDATA[I recently needed to make use of our ActiveMQ message queue service to scale up write performance of CouchDB. However, there seemed to be a bug with JRuby that kills off the STOMP subscriber every 5 seconds. Digging a bit deeper into the STOMP source, I figured out a way to get around the bug [...]]]></description>
			<content:encoded><![CDATA[<p>I recently needed to make use of our <a href="http://activemq.apache.org/">ActiveMQ message queue</a> service to scale up write performance of <a href="http://couchdb.apache.org/">CouchDB</a>. However, there seemed to be a bug with <a href="http://jruby.org/">JRuby</a> that kills off the STOMP subscriber every 5 seconds. Digging a bit deeper into the STOMP source, I figured out a way to get around the bug by removing the timeout line. </p>
<p>ActiveMQ let me scale CouchDB writes from 10req/sec to 128req/sec. Huge performance win with very little effort. </p>
<p><a href="http://jira.codehaus.org/browse/JRUBY-4941">Ticket to the bug.</a></p>
<p><b>STOMP Library Monkey Patch:</b></p>
<div class="codesnip-container" >
<div class="ruby codesnip" style="font-family:monospace;"><span class="co1"># for stomp subscriber</span><br />
<span class="kw1">if</span> <span class="kw1">defined</span>?<span class="br0">&#40;</span>JRUBY_VERSION<span class="br0">&#41;</span><br />
&nbsp; <span class="kw1">module</span> Stomp<br />
&nbsp; &nbsp; <span class="kw1">class</span> Connection<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">def</span> _receive<span class="br0">&#40;</span> read_socket <span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">@read_semaphore</span>.<span class="me1">synchronize</span> <span class="kw1">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;line = read_socket.<span class="kw3">gets</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw2">return</span> <span class="kw2">nil</span> <span class="kw1">if</span> line.<span class="kw2">nil</span>?</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="co1"># If the reading hangs for more than 5 seconds, abort the parsing process</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="co1">#Timeout::timeout(5, Stomp::Error::PacketParsingTimeout) do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="co1"># Reads the beginning of the message until it runs into a empty line</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;message_header = <span class="st0">&#8221;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;message_header <span class="sy0">+</span>= line<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;line = read_socket.<span class="kw3">gets</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">rescue</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">p</span> read_socket<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">end</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">end</span> <span class="kw1">until</span> line =~ <span class="sy0">/</span>^\s?\n$<span class="sy0">/</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="co1"># Checks if it includes content_length header</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;content_length = message_header.<span class="me1">match</span> <span class="sy0">/</span>content<span class="sy0">-</span>length\s?:\s?<span class="br0">&#40;</span>\d<span class="sy0">+</span><span class="br0">&#41;</span>\s?\n<span class="sy0">/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;message_body = <span class="st0">&#8221;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="co1"># If it does, reads the specified amount of bytes</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;char = <span class="st0">&#8221;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">if</span> content_length<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;message_body = read_socket.<span class="me1">read</span> content_length<span class="br0">&#91;</span>1<span class="br0">&#93;</span>.<span class="me1">to_i</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw3">raise</span> <span class="re2">Stomp::Error::InvalidMessageLength</span> <span class="kw1">unless</span> parse_char<span class="br0">&#40;</span>read_socket.<span class="me1">getc</span><span class="br0">&#41;</span> == <span class="st0">&quot;<span class="es0">\0</span>&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="co1"># Else reads, the rest of the message until the first \0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;message_body <span class="sy0">+</span>= char <span class="kw1">while</span> read_socket.<span class="me1">ready</span>? <span class="sy0">&amp;&amp;</span> <span class="br0">&#40;</span>char = parse_char<span class="br0">&#40;</span>read_socket.<span class="me1">getc</span><span class="br0">&#41;</span><span class="br0">&#41;</span> != <span class="st0">&quot;<span class="es0">\0</span>&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">end</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="co1"># If the buffer isn&#8217;t empty, reads the next char and returns it to the buffer</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="co1"># unless it&#8217;s a \n</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">if</span> read_socket.<span class="me1">ready</span>?<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;last_char = read_socket.<span class="me1">getc</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;read_socket.<span class="me1">ungetc</span><span class="br0">&#40;</span>last_char<span class="br0">&#41;</span> <span class="kw1">if</span> parse_char<span class="br0">&#40;</span>last_char<span class="br0">&#41;</span> != <span class="st0">&quot;<span class="es0">\n</span>&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">end</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="co1"># Adds the excluded \n and \0 and tries to create a new message with it</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Message.<span class="me1">new</span><span class="br0">&#40;</span>message_header <span class="sy0">+</span> <span class="st0">&quot;<span class="es0">\n</span>&quot;</span> <span class="sy0">+</span> message_body <span class="sy0">+</span> <span class="st0">&quot;<span class="es0">\0</span>&quot;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">end</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="co1">#end</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">end</span><br />
&nbsp; &nbsp; <span class="kw1">end</span><br />
&nbsp; <span class="kw1">end</span><br />
<span class="kw1">end</span></div>
</div>
<img src="http://feeds.feedburner.com/~r/Letsgetdugg/~4/Sqsn13WuUO4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://letsgetdugg.com/2010/07/16/stomp-client-on-jruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://letsgetdugg.com/2010/07/16/stomp-client-on-jruby/</feedburner:origLink></item>
		<item>
		<title>A fix for the sound delay  with VoodooHDA and Final Cut Pro</title>
		<link>http://feedproxy.google.com/~r/Letsgetdugg/~3/WP-HoWbXw14/</link>
		<comments>http://letsgetdugg.com/2010/07/01/a-fix-for-the-sound-delay-with-voodoohda-and-final-cut-pro/#comments</comments>
		<pubDate>Fri, 02 Jul 2010 03:01:52 +0000</pubDate>
		<dc:creator>victori</dc:creator>
				<category><![CDATA[main]]></category>
		<category><![CDATA[fix]]></category>

		<guid isPermaLink="false">http://letsgetdugg.com/?p=704</guid>
		<description><![CDATA[I spent the better part of the day trying to figure out why the Final Cut Pro audio was out of sync. The audio would be delayed by 3 seconds in playback. I thought it was some setting in Final Cut Pro that broke, but eventually came to the conclusion that it was the OS [...]]]></description>
			<content:encoded><![CDATA[<p>I spent the better part of the day trying to figure out why the Final Cut Pro audio was out of sync. The audio would be delayed by 3 seconds in playback. I thought it was some setting in Final Cut Pro that broke, but eventually came to the conclusion that it was the OS and not Final Cut Pro that was causing the audio delay. The specific cause was the <a href="http://code.google.com/p/voodoohda/">VoodooHDA</a> driver, even though it worked perfect in ordinary applications such as iTunes and Safari it had a delay issue with Final Cut Pro. The Fix? Install <a href="http://code.google.com/p/soundflower/">SoundFlowerBed</a> and configure your audio output settings in it. This somehow magically fixes the delay issue in the VoodooHDA driver. I thought I should post it here for &#8220;internet&#8221; record keeping.</p>
<p><img src="http://letsgetdugg.com/wp-content/uploads/2010/07/sf1.jpg" alt="sf1.jpg" border="0" width="430" height="412" /></p>
<img src="http://feeds.feedburner.com/~r/Letsgetdugg/~4/WP-HoWbXw14" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://letsgetdugg.com/2010/07/01/a-fix-for-the-sound-delay-with-voodoohda-and-final-cut-pro/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://letsgetdugg.com/2010/07/01/a-fix-for-the-sound-delay-with-voodoohda-and-final-cut-pro/</feedburner:origLink></item>
		<item>
		<title>CouchDB on ZFS</title>
		<link>http://feedproxy.google.com/~r/Letsgetdugg/~3/mfQtDBgUF8M/</link>
		<comments>http://letsgetdugg.com/2010/06/25/couchdb-on-zfs/#comments</comments>
		<pubDate>Sat, 26 Jun 2010 06:29:22 +0000</pubDate>
		<dc:creator>victori</dc:creator>
				<category><![CDATA[administration]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[couchdb]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[zfs]]></category>

		<guid isPermaLink="false">http://letsgetdugg.com/?p=694</guid>
		<description><![CDATA[CouchDB was made for next generation filesystems such as ZFS and BTRFS. First off, unlike PostgreSQL or MySQL, CouchDB can be snapshot while in production without any flushing or locking trickery since it uses an append only B-Tree storage approach. That alone makes it a compelling database choice on ZFS/BTRFS. Second, CouchDB works hand-in-hand with [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://couchdb.apache.org/">CouchDB</a> was <em>made</em> for next generation filesystems such as <a href="http://en.wikipedia.org/wiki/ZFS">ZFS</a> and <a href="http://en.wikipedia.org/wiki/Btrfs">BTRFS</a>. First off, unlike <a href="http://www.postgresql.org/">PostgreSQL</a> or <a href="http://www.mysql.com/">MySQL</a>, CouchDB can be snapshot while in production without any flushing or locking trickery since it uses an append only B-Tree storage approach. That alone makes it a compelling database choice on ZFS/BTRFS. </p>
<p>Second, CouchDB works hand-in-hand with ZFS&#8217;s block level compression. ZFS can compress blocks of data as they are being written out to the disk. However, it only does it for new blocks and not retroactively. Now, the awesome part, CouchDB on compaction writes out a brand new database file which can utilize the new gzip compression settings on ZFS. This means you can try out different gzip compression settings just by compacting your CouchDB. </p>
<p>Some tips on running CouchDB on ZFS:</p>
<p>1. Use automated snapshots to prevent $admin error, it is painless with ZFS and CouchDB loves being snapshot <img src='http://letsgetdugg.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>You can give my little <a href="http://letsgetdugg.com/2010/03/30/automated-zfs-snapshots/">ruby script a try for daily snapshots</a>; I use it both on Mac OSX and Solaris for automated ZFS snapshot goodness.</p>
<div class="codesnip-container" >zfs snapshot rpool/couchdb@mysnapshot-tuesday</div>
<p>2. Try out various gzip compression schemes on your CouchDB workload, re-compact the database to use the new gzip compression settings. I personally use the gzip-4 compression for our workload which strikes the perfect balance between space and cpu utilization. </p>
<div class="codesnip-container" >zfs set compression=gzip-4 rpool/couchdb</div>
<p>3. Set the ZFS dataset to 4k block record size and turn off atime. Yes the B-Tree append only approach is elastic on writes but you can have near perfect tiny writes with a small 4k block record size. </p>
<div class="codesnip-container" >zfs set recordsize=4k rpool/couchdb<br />
zfs set atime=off rpool/couchdb</div>
<img src="http://feeds.feedburner.com/~r/Letsgetdugg/~4/mfQtDBgUF8M" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://letsgetdugg.com/2010/06/25/couchdb-on-zfs/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://letsgetdugg.com/2010/06/25/couchdb-on-zfs/</feedburner:origLink></item>
		<item>
		<title>PostgreSQL ZFS Snapshot Backups</title>
		<link>http://feedproxy.google.com/~r/Letsgetdugg/~3/v_j6qecu_BQ/</link>
		<comments>http://letsgetdugg.com/2010/06/23/postgresql-zfs-snapshot-backups/#comments</comments>
		<pubDate>Wed, 23 Jun 2010 19:31:15 +0000</pubDate>
		<dc:creator>victori</dc:creator>
				<category><![CDATA[administration]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[zfs]]></category>

		<guid isPermaLink="false">http://letsgetdugg.com/?p=676</guid>
		<description><![CDATA[I recently had a WD Raptor drive die in a server that hosted our PostgreSQL database. I had a ZFS snapshot strategy setup that sent over ZFS snapshots of the live database to a ZFS mirror for backup purposes. Looked good in theory right? Except, I forgot to do one critical thing, test my backups. [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had a WD Raptor drive die in a server that hosted our <a href="http://www.postgresql.org/">PostgreSQL</a> database. I had a ZFS snapshot strategy setup that sent over ZFS snapshots of the live database to a ZFS mirror for backup purposes. Looked good in theory right? Except, I forgot to do one critical thing, test my backups. Long story short, I had a bunch of snapshots that were useless. Luckily I had offsite nightly PostgreSQL dumps that I did test which were used to seed my development database. So in the end I avoided catastrophic data failure.</p>
<p>With that lesson in mind, I reconfigured our backup system to do it correctly after re-reading the PostgreSQL documentation.</p>
<p><strong>Prerequisite:</strong> You must have WAL archiving on and have the archive directory under your database directory. For example if your database is under <em>/rpool/pgdata/db1</em> configure your archive directory under <em>/rpool/pgdata/db1/archives</em></p>
<p>Completely optional but I highly suggest you automate your backups; My <a href="http://letsgetdugg.com/2010/03/30/automated-zfs-snapshots/">zbackup ruby script is pretty simple to setup.</a></p>
<p>This is how my /rpool/pgdata/db1 Looks like:</p>
<pre>
victori@opensolaris:/# ls /rpool/data/db1
archives      pg_clog	     pg_multixact  pg_twophase	    postmaster.log
backup_label  pg_hba.conf    pg_stat_tmp   PG_VERSION	    postmaster.opts
base	      pg_ident.conf  pg_subtrans   pg_xlog	    postmaster.pid
global	      pg_log	     pg_tblspc	   postgresql.conf
</pre>
<p>Source for my pgsnap.sh script.</p>
<div class="codesnip-container" >#!/bin/sh</p>
<p>PGPASSWORD=&#8221;mypass&#8221; psql -h fab2 postgres -U myuser -c &#8220;select pg_start_backup(&#8216;nightly&#8217;,true);&#8221;</p>
<p>/usr/bin/ruby /opt/zbackup.rb rpool/pgdata 7</p>
<p>PGPASSWORD=&#8221;mypass&#8221; psql -h fab2 postgres -U myuser -c &#8220;select pg_stop_backup();&#8221;</p>
<p>rm /rpool/pgdata/db1/archives/*</p></div>
<p>The process is quite simple. You issue a command to initiate the backup process so PostgreSQL goes into &#8220;backup mode.&#8221; Second, you do the ZFS snapshot, in this case I am using my <a href="http://letsgetdugg.com/2010/03/30/automated-zfs-snapshots/">zbackup ruby script</a>. Third, you issue another SQL command to PostgrSQL to get out of backup mode. Lastly, since you have the database snapshot you can safely delete your previous WAL archives. </p>
<p>Now, this is all nice and dandy but you should *TEST* your backups, before assuming your backup strategy actually worked. </p>
<div class="codesnip-container" >zfs clone rpool/pgdata@2010-6-17 rpool/pgtest<br />
postgres &#8211;singleuser mydb -D /rpool/pgtest/db1</div>
<p>Basically you clone the snapshot and test it by running it under PostgreSQL in single user mode. Once in singleuser mode, test out your backup to make sure it is readable, you can issue a SQL queries to confirm that all is fine with the backup. </p>
<p>ZFS you rock my world <img src='http://letsgetdugg.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<img src="http://feeds.feedburner.com/~r/Letsgetdugg/~4/v_j6qecu_BQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://letsgetdugg.com/2010/06/23/postgresql-zfs-snapshot-backups/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://letsgetdugg.com/2010/06/23/postgresql-zfs-snapshot-backups/</feedburner:origLink></item>
		<item>
		<title>Scala yEnc Decoder</title>
		<link>http://feedproxy.google.com/~r/Letsgetdugg/~3/HX9D1r_roIQ/</link>
		<comments>http://letsgetdugg.com/2010/06/22/scala-yenc-decoder/#comments</comments>
		<pubDate>Tue, 22 Jun 2010 22:07:17 +0000</pubDate>
		<dc:creator>victori</dc:creator>
				<category><![CDATA[open source]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://letsgetdugg.com/?p=671</guid>
		<description><![CDATA[SYEnc is a Scala decoder for the yEnc format that is based on Alex Russ&#8217;s Java yEnc Decoder. SYEnc was designed to be used as a library by applications needing to use yEnc to decode data. It should be thread-safe, so don&#8217;t worry about using it in a threaded context. Uploaded to github: http://github.com/victori/syenc Example: [...]]]></description>
			<content:encoded><![CDATA[<p>SYEnc is a Scala decoder for the <a href="http://www.yenc.org/">yEnc format</a> that is based on Alex Russ&#8217;s Java yEnc Decoder. SYEnc was designed to be used as a library by applications needing to use yEnc to decode data. It should be thread-safe, so don&#8217;t worry about using it in a threaded context.</p>
<p>Uploaded to github: <a href="http://github.com/victori/syenc">http://github.com/victori/syenc</a></p>
<p><b>Example:</b></p>
<div class="codesnip-container" >
<div class="scala codesnip" style="font-family:monospace;"><a href="http://scala-lang.org"><span class="kw1">val</span></a> baos <span class="sy0">=</span> <a href="http://scala-lang.org"><span class="kw1">new</span></a> ByteArrayOutputStream<br />
SYEnc.<span class="me1">decode</span><span class="br0">&#40;</span><a href="http://scala-lang.org"><span class="kw1">new</span></a> ByteArrayInputStream<span class="br0">&#40;</span>stringFromStream.<span class="me1">getBytes</span><span class="br0">&#40;</span><span class="st0">&quot;UTF-8&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>, baos<span class="br0">&#41;</span><br />
println<span class="br0">&#40;</span>baos.<span class="me1">toString</span><span class="br0">&#41;</span></div>
</div>
<img src="http://feeds.feedburner.com/~r/Letsgetdugg/~4/HX9D1r_roIQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://letsgetdugg.com/2010/06/22/scala-yenc-decoder/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://letsgetdugg.com/2010/06/22/scala-yenc-decoder/</feedburner:origLink></item>
		<item>
		<title>Automated ZFS Snapshots</title>
		<link>http://feedproxy.google.com/~r/Letsgetdugg/~3/Z83wkyJbUoE/</link>
		<comments>http://letsgetdugg.com/2010/03/30/automated-zfs-snapshots/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 00:04:33 +0000</pubDate>
		<dc:creator>victori</dc:creator>
				<category><![CDATA[administration]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[zfs]]></category>

		<guid isPermaLink="false">http://letsgetdugg.com/?p=653</guid>
		<description><![CDATA[I needed something like zfs-auto-snapshot written by Tim Foster but portable so it works on all systems that support ZFS. I reviewed a few scripts on github and was unhappy with what was out there so I decided to write my own. With zbackup.rb you can define what to snapshot and how many rotation days [...]]]></description>
			<content:encoded><![CDATA[<p>I needed something like <a href="http://blogs.sun.com/timf/entry/zfs_automatic_snapshots_0_12">zfs-auto-snapshot</a> written by Tim Foster but portable so it works on all systems that support ZFS. I reviewed a few scripts on github and was unhappy with what was out there so I decided to write my own.</p>
<p>With zbackup.rb you can define what to snapshot and how many rotation days you want to go back. </p>
<p>So say you want a month of snapshots:</p>
<div class="codesnip-container" >/usr/bin/zbackup.rb iraidz/zWork 30</div>
<p>Simple, no? <img src='http://letsgetdugg.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<div class="codesnip-container" >
<div class="ruby codesnip" style="font-family:monospace;"><span class="co1">#!/usr/bin/env ruby</span></p>
<p><span class="co1"># Create snapshots for a 7 day rotation.</span><br />
<span class="co1"># ./zbackup.rb iraidz/zWork 7</span><br />
<span class="co1">#</span><br />
<span class="co1"># Add to crontab</span><br />
<span class="co1"># crontab -e</span><br />
<span class="co1"># 0 2 * * * /usr/bin/zbackup.rb iraidz/zWork 7</span></p>
<p>pool = ARGV<span class="br0">&#91;</span>0<span class="br0">&#93;</span><br />
days_back = ARGV<span class="br0">&#91;</span>1<span class="br0">&#93;</span>.<span class="me1">to_i</span></p>
<p><span class="kw1">if</span> pool.<span class="kw2">nil</span>? <span class="kw1">or</span> pool.<span class="me1">empty</span>?<br />
&nbsp; <span class="kw3">puts</span> <span class="st0">&quot;<span class="es0">\n</span>Define the pool you want to snapshot:&quot;</span><br />
&nbsp; <span class="kw3">puts</span> <span class="st0">&quot;<span class="es0">\t</span>ex: zbackup.rb iraidz/zWork 7<span class="es0">\n</span><span class="es0">\n</span>&quot;</span><br />
&nbsp; <span class="kw3">exit</span> 0<br />
<span class="kw1">end</span></p>
<p><span class="kw1">if</span> days_back.<span class="kw2">nil</span>? <span class="kw1">or</span> days_back <span class="sy0">&lt;</span> 1 <br />
&nbsp; <span class="kw3">puts</span> <span class="st0">&quot;<span class="es0">\n</span>Define how many days for your rotation:&quot;</span><br />
&nbsp; <span class="kw3">puts</span> <span class="st0">&quot;<span class="es0">\t</span>ex: zbackup.rb iraidz/zWork 7<span class="es0">\n</span><span class="es0">\n</span>&quot;</span><br />
&nbsp; <span class="kw3">exit</span> 0<br />
<span class="kw1">end</span></p>
<p><span class="co1"># response from zfs list</span><br />
curr_snaps = <span class="st0">`zfs list -t snapshot -o name`</span><br />
<span class="co1"># days back limit variable</span><br />
date_back = <span class="kw4">Time</span>.<span class="me1">now</span> <span class="sy0">-</span> <span class="br0">&#40;</span>86400<span class="sy0">*</span>days_back<span class="br0">&#41;</span></p>
<p>curr_snaps.<span class="kw3">split</span><span class="br0">&#40;</span><span class="sy0">/</span>\n<span class="sy0">/</span><span class="br0">&#41;</span>.<span class="me1">each</span> <span class="kw1">do</span> <span class="sy0">|</span>pline<span class="sy0">|</span><br />
&nbsp; <span class="kw1">if</span> m = pline.<span class="me1">match</span><span class="br0">&#40;</span><span class="sy0">/</span><span class="co1">#{pool}\@([0-9]+)\-([0-9]+)\-([0-9]+)/)</span><br />
&nbsp; &nbsp; <span class="kw1">if</span> date_back <span class="sy0">&gt;</span>= <span class="kw4">Time</span>.<span class="me1">local</span><span class="br0">&#40;</span>m<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span>,m<span class="br0">&#91;</span><span class="nu0">2</span><span class="br0">&#93;</span>,m<span class="br0">&#91;</span><span class="nu0">3</span><span class="br0">&#93;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span class="st0">`zfs destroy #{pline}`</span><br />
&nbsp; &nbsp; <span class="kw1">end</span><br />
&nbsp; <span class="kw1">end</span><br />
<span class="kw1">end</span></p>
<p><span class="co1"># take snapshot for this run if needed.</span><br />
month = <span class="kw4">Time</span>.<span class="me1">now</span>.<span class="me1">month</span><br />
day = <span class="kw4">Time</span>.<span class="me1">now</span>.<span class="me1">day</span><br />
year = <span class="kw4">Time</span>.<span class="me1">now</span>.<span class="me1">year</span><br />
<span class="kw1">if</span> curr_snaps !~ <span class="sy0">/</span><span class="co1">#{pool}\@#{year}\-#{month}\-#{day}/</span><br />
&nbsp; <span class="st0">`zfs snapshot -r #{pool}@#{year}-#{month}-#{day}`</span><br />
<span class="kw1">end</span></div>
</div>
<img src="http://feeds.feedburner.com/~r/Letsgetdugg/~4/Z83wkyJbUoE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://letsgetdugg.com/2010/03/30/automated-zfs-snapshots/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://letsgetdugg.com/2010/03/30/automated-zfs-snapshots/</feedburner:origLink></item>
		<item>
		<title>Clustering Wicket for fun and profit!</title>
		<link>http://feedproxy.google.com/~r/Letsgetdugg/~3/rGCJgMOiM8M/</link>
		<comments>http://letsgetdugg.com/2010/02/07/clustering-wicket-for-fun-and-profit/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 17:55:09 +0000</pubDate>
		<dc:creator>victori</dc:creator>
				<category><![CDATA[administration]]></category>
		<category><![CDATA[main]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[clustering]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[wicket]]></category>

		<guid isPermaLink="false">http://letsgetdugg.com/?p=615</guid>
		<description><![CDATA[I hate expired sessions, death to all expired sessions. Traditionally a Java servlet container has a fixed session time, a flood of traffic can potentially cause JVM OOM errors if the session time is set too high. I wanted a smart session container that can hold onto sessions for as long as possible and expire [...]]]></description>
			<content:encoded><![CDATA[<p>I hate expired sessions, death to all expired sessions. Traditionally a Java servlet container has a fixed session time, a flood of traffic can potentially cause <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/OutOfMemoryError.html">JVM OOM errors</a> if the session time is set too high. I wanted a smart session container that can hold onto sessions for as long as possible and expire sessions only when it is absolutely necessary; A <a href="http://memcached.org/">Memcached</a> store would be perfect for this. </p>
<p>There for I recently open sourced the <a href="http://github.com/victori/jetty-session-cache">jetty-session-store</a> to solve this problem. With the jetty-session-store you can save your session state to Ehcache, <a href="http://memcached.org/">Memcached</a> or the database. State should not be bound to a single JVM, Viva Shared Session Stores! </p>
<p>So now that jetty-session-store is out in the wild you can technically cluster Wicket using just the <a href="http://wicket.sourceforge.net/apidocs/wicket/protocol/http/HttpSessionStore.html">HttpSessionStore</a>. However, it isn’t very efficient with the way Memcached allocates data in fixed sized cache buckets.</p>
<p>1. Wicket sessions under the HttpSessionStore can get quite large, well over 1Mb in size. A Wicket session not only stores the session state but also the previous serialized pages the user has visited. </p>
<p>2. Serializing and de-serializing a large data structure can get expensive. The HttpSessionStore retains an <a href="http://wicket.apache.org/docs/1.4/org/apache/wicket/AccessStackPageMap.html">AccessStackPageMap</a>, which is a list data structure consisting of multiple <a href="http://cwiki.apache.org/WICKET/page-maps.html">page map revisions</a>. </p>
<p>So instead of saving one large AccessStackPageMap, I wrote a <a href="http://wicket.apache.org/docs/wicket-1.3.2/wicket/apidocs/org/apache/wicket/protocol/http/SecondLevelCacheSessionStore.html">SecondLevelCacheSessionStore</a> that saves a page map revision per cache entry. This leads to much better cache utilization and a whole lot less serialization on the wire. Not to mention this avoids the whole 1Mb Memcached size limit.</p>
<p>Before you go willy nilly with clustering, read the <a href="http://cwiki.apache.org/WICKET/render-strategies.html">Wicket render strategies page</a>. <b>Wicket requires session affinity for buffered responses with the default rendering strategy.</b></p>
<h3>Clustering Wicket has never been easier.</h3>
<p>Here is an example on how to offload page maps to a hybrid EhCache/Memcached cache. Memcached for long term shared storage while EhCache for short-lived fast cache look ups. </p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="kw1">public</span> <span class="kw1">class</span> WebApp <span class="kw1">extends</span> WebApplication <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">protected</span> ISessionStore newSessionStore<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// localhost:11211 &#8212; memcached server</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// &quot;fabpagestore&quot; &#8212; unique appender to avoid key clashes.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// 300 &#8212; 5 minute TTL for local ehcache.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw1">new</span> SecondLevelCacheSessionStore<span class="br0">&#40;</span><span class="kw1">this</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">new</span> CachePageStore<span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aarrays+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">Arrays</span></a>.<span class="me1">asList</span><span class="br0">&#40;</span><span class="st0">&quot;localhost:11211&quot;</span><span class="br0">&#41;</span>,<span class="st0">&quot;fabpagestore&quot;</span>,300<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>Here is an example on how to offload page maps to the database. </p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="kw1">public</span> <span class="kw1">class</span> WebApp <span class="kw1">extends</span> WebApplication <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">protected</span> ISessionStore newSessionStore<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// &quot;fabpagestore&quot; &#8212; unique appender to avoid key clashes.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw1">new</span> SecondLevelCacheSessionStore<span class="br0">&#40;</span><span class="kw1">this</span>,<span class="kw1">new</span> CachePageStore<span class="br0">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">new</span> DBCache<span class="br0">&#40;</span><span class="st0">&quot;jdbc:mysql://foo/mydb&quot;</span>, <span class="st0">&quot;myname&quot;</span>, <span class="st0">&quot;mypass&quot;</span>, <span class="st0">&quot;com.driver.Name&quot;</span>, <span class="st0">&quot;fabpagestore&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>Here is my CachePageStore;</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;"><span class="kw1">package</span> <span class="co2">com.base.pagestore</span><span class="sy0">;</span></p>
<p><span class="kw1">import</span> <span class="co2">com.base.cache.AsyncMemcache</span><span class="sy0">;</span><br />
<span class="kw1">import</span> <span class="co2">com.base.cache.ICache</span><span class="sy0">;</span><br />
<span class="kw1">import</span> <span class="co2">org.apache.wicket.Page</span><span class="sy0">;</span><br />
<span class="kw1">import</span> <span class="co2">org.apache.wicket.protocol.http.SecondLevelCacheSessionStore.IClusteredPageStore</span><span class="sy0">;</span><br />
<span class="kw1">import</span> <span class="co2">org.apache.wicket.protocol.http.pagestore.AbstractPageStore</span><span class="sy0">;</span><br />
<span class="kw1">import</span> <span class="co2">org.slf4j.Logger</span><span class="sy0">;</span><br />
<span class="kw1">import</span> <span class="co2">org.slf4j.LoggerFactory</span><span class="sy0">;</span></p>
<p><span class="kw1">import</span> <span class="co2">java.util.List</span><span class="sy0">;</span></p>
<p><span class="kw1">public</span> <span class="kw1">class</span> CachePageStore <span class="kw1">extends</span> AbstractPageStore <span class="kw1">implements</span> IClusteredPageStore <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">private</span> ICache cache<span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw1">private</span> Logger logger <span class="sy0">=</span> LoggerFactory.<span class="me1">getLogger</span><span class="br0">&#40;</span>CachePageStore.<span class="kw1">class</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">public</span> CachePageStore<span class="br0">&#40;</span><span class="kw1">final</span> List<span class="sy0">&lt;</span>String<span class="sy0">&gt;</span> servers, <span class="kw1">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> poolName, <span class="kw1">final</span> <span class="kw4">int</span> ttl<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span><span class="br0">&#40;</span>servers, poolName, <span class="kw2">true</span>, ttl<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">public</span> CachePageStore<span class="br0">&#40;</span><span class="kw1">final</span> List<span class="sy0">&lt;</span>String<span class="sy0">&gt;</span> servers, <span class="kw1">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> poolName, <span class="kw4">boolean</span> async, <span class="kw1">final</span> <span class="kw4">int</span> ttl<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span><span class="br0">&#40;</span><span class="kw1">new</span> AsyncMemcache<span class="br0">&#40;</span>servers, poolName, async, ttl<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">public</span> CachePageStore<span class="br0">&#40;</span><span class="kw1">final</span> ICache cache<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">cache</span> <span class="sy0">=</span> cache<span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="co1">// If pageVersion -1 must return highest page version.</span><br />
&nbsp; &nbsp; <span class="kw1">protected</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> getKey<span class="br0">&#40;</span><span class="kw1">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> sessId, <span class="kw1">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> pageMapName, <span class="kw1">final</span> <span class="kw4">int</span> pageId, <span class="kw1">final</span> <span class="kw4">int</span> pageVersion<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">int</span> pageVer <span class="sy0">=</span> <span class="br0">&#40;</span>pageVersion <span class="sy0">==</span> <span class="sy0">-</span>1<span class="br0">&#41;</span> <span class="sy0">?</span> 0 <span class="sy0">:</span> pageVersion<span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>pageVersion <span class="sy0">==</span> <span class="sy0">-</span>1<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a><span class="br0">&#91;</span><span class="br0">&#93;</span> meta <span class="sy0">=</span> getMeta<span class="br0">&#40;</span>sessId, pageMapName, pageId<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pageVer <span class="sy0">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainteger+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">Integer</span></a>.<span class="me1">valueOf</span><span class="br0">&#40;</span>meta<span class="br0">&#91;</span>0<span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> sessId <span class="sy0">+</span> <span class="st0">&quot;:&quot;</span> <span class="sy0">+</span> pageMapName <span class="sy0">+</span> <span class="st0">&quot;:&quot;</span> <span class="sy0">+</span> pageId <span class="sy0">+</span> <span class="st0">&quot;:&quot;</span> <span class="sy0">+</span> pageVer<span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="co1">// If pageVersion -1 must return highest page version.</span><br />
&nbsp; &nbsp; <span class="co1">// If ajaxVersion -1 must return highest version.</span><br />
&nbsp; &nbsp; <span class="kw1">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> getKey<span class="br0">&#40;</span><span class="kw1">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> sessId, <span class="kw1">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> pageMapName, <span class="kw1">final</span> <span class="kw4">int</span> pageId, <span class="kw1">final</span> <span class="kw4">int</span> pageVersion, <span class="kw1">final</span> <span class="kw4">int</span> ajaxVersion<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Default it to 0 initially</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">int</span> ajaxVer <span class="sy0">=</span> <span class="br0">&#40;</span>ajaxVersion <span class="sy0">==</span> <span class="sy0">-</span>1<span class="br0">&#41;</span> <span class="sy0">?</span> 0 <span class="sy0">:</span> ajaxVersion<span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">int</span> pageVer <span class="sy0">=</span> <span class="br0">&#40;</span>pageVersion <span class="sy0">==</span> <span class="sy0">-</span>1<span class="br0">&#41;</span> <span class="sy0">?</span> 0 <span class="sy0">:</span> pageVersion<span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>pageVersion <span class="sy0">==</span> <span class="sy0">-</span>1 <span class="sy0">||</span> ajaxVersion <span class="sy0">==</span> <span class="sy0">-</span>1<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a><span class="br0">&#91;</span><span class="br0">&#93;</span> meta <span class="sy0">=</span> getMeta<span class="br0">&#40;</span>sessId, pageMapName, pageId<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>pageVersion <span class="sy0">==</span> <span class="sy0">-</span>1<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pageVer <span class="sy0">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainteger+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">Integer</span></a>.<span class="me1">valueOf</span><span class="br0">&#40;</span>meta<span class="br0">&#91;</span>0<span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>ajaxVersion <span class="sy0">==</span> <span class="sy0">-</span>1<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ajaxVer <span class="sy0">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainteger+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">Integer</span></a>.<span class="me1">valueOf</span><span class="br0">&#40;</span>meta<span class="br0">&#91;</span>1<span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> sessId <span class="sy0">+</span> <span class="st0">&quot;:&quot;</span> <span class="sy0">+</span> pageMapName <span class="sy0">+</span> <span class="st0">&quot;:&quot;</span> <span class="sy0">+</span> pageId <span class="sy0">+</span> <span class="st0">&quot;:&quot;</span> <span class="sy0">+</span> pageVer <span class="sy0">+</span> <span class="st0">&quot;:&quot;</span> <span class="sy0">+</span> ajaxVer<span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">protected</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> storeKey<span class="br0">&#40;</span><span class="kw1">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> sessionId, <span class="kw1">final</span> Page page<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> sessionId <span class="sy0">+</span> <span class="st0">&quot;:&quot;</span> <span class="sy0">+</span> page.<span class="me1">getPageMapName</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">&quot;:&quot;</span> <span class="sy0">+</span> page.<span class="me1">getId</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">&quot;:&quot;</span> <span class="sy0">+</span> page.<span class="me1">getCurrentVersionNumber</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">&quot;:&quot;</span> <span class="sy0">+</span> page.<span class="me1">getAjaxVersionNumber</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">protected</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> getBaseKey<span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> sessionId, Page page<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> sessionId <span class="sy0">+</span> <span class="st0">&quot;:&quot;</span> <span class="sy0">+</span> page.<span class="me1">getPageMapName</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">&quot;:&quot;</span> <span class="sy0">+</span> page.<span class="me1">getId</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">protected</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> getMetaKey<span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> sessionId, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> pageMap, <span class="kw4">int</span> id<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> getBaseKey<span class="br0">&#40;</span>sessionId,pageMap,id<span class="br0">&#41;</span><span class="sy0">+</span><span class="st0">&quot;_meta&quot;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">protected</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> getMetaKey<span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> sessionId, Page page<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> getBaseKey<span class="br0">&#40;</span>sessionId,page<span class="br0">&#41;</span><span class="sy0">+</span><span class="st0">&quot;_meta&quot;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">protected</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> getBaseKey<span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> sessionId, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> pageMap, <span class="kw4">int</span> id<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>id <span class="sy0">==</span> <span class="sy0">-</span>1<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> sessionId <span class="sy0">+</span> <span class="st0">&quot;:&quot;</span> <span class="sy0">+</span> pageMap<span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> sessionId <span class="sy0">+</span> <span class="st0">&quot;:&quot;</span> <span class="sy0">+</span> pageMap <span class="sy0">+</span> <span class="st0">&quot;:&quot;</span> <span class="sy0">+</span> id<span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw4">boolean</span> containsPage<span class="br0">&#40;</span><span class="kw1">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> sessionId, <span class="kw1">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> pageMapName, <span class="kw1">final</span> <span class="kw4">int</span> pageId, <span class="kw1">final</span> <span class="kw4">int</span> pageVersion<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> key <span class="sy0">=</span> getKey<span class="br0">&#40;</span>sessionId, pageMapName, pageId, pageVersion, <span class="sy0">-</span>1<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>logger.<span class="me1">isDebugEnabled</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logger.<span class="me1">debug</span><span class="br0">&#40;</span><span class="st0">&quot;CheckExists: &quot;</span> <span class="sy0">+</span> key<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> cache.<span class="me1">keyExists</span><span class="br0">&#40;</span>key<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw4">void</span> destroy<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">public</span> <span class="sy0">&lt;</span>T<span class="sy0">&gt;</span> Page getPage<span class="br0">&#40;</span><span class="kw1">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> sessionId, <span class="kw1">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> pagemap, <span class="kw1">final</span> <span class="kw4">int</span> id, <span class="kw1">final</span> <span class="kw4">int</span> versionNumber, <span class="kw1">final</span> <span class="kw4">int</span> ajaxVersionNumber<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> key <span class="sy0">=</span> getKey<span class="br0">&#40;</span>sessionId, pagemap, id, versionNumber, ajaxVersionNumber<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>logger.<span class="me1">isDebugEnabled</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logger.<span class="me1">debug</span><span class="br0">&#40;</span><span class="st0">&quot;GetPage: &quot;</span> <span class="sy0">+</span> key<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="br0">&#40;</span>Page<span class="br0">&#41;</span> cache.<span class="me1">get</span><span class="br0">&#40;</span>key<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw4">void</span> pageAccessed<span class="br0">&#40;</span><span class="kw1">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> sessionId, <span class="kw1">final</span> Page page<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="co1">// If ID == -1 remove the entire pagemap; getBaseKey() takes care of this.</span><br />
&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw4">void</span> removePage<span class="br0">&#40;</span><span class="kw1">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> sessionId, <span class="kw1">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> pagemap, <span class="kw1">final</span> <span class="kw4">int</span> id<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> key <span class="sy0">=</span> getBaseKey<span class="br0">&#40;</span>sessionId, pagemap, id<span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>logger.<span class="me1">isDebugEnabled</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logger.<span class="me1">debug</span><span class="br0">&#40;</span><span class="st0">&quot;RemovePage: &quot;</span> <span class="sy0">+</span> key<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; cache.<span class="me1">remove</span><span class="br0">&#40;</span>getMetaKey<span class="br0">&#40;</span>sessionId, pagemap, id<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span> <span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> k <span class="sy0">:</span> cache.<span class="me1">getKeys</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>k.<span class="me1">startsWith</span><span class="br0">&#40;</span>key<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cache.<span class="me1">remove</span><span class="br0">&#40;</span>k<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">protected</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a><span class="br0">&#91;</span><span class="br0">&#93;</span> getMeta<span class="br0">&#40;</span><span class="kw1">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> sessionId, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> pageMap, <span class="kw4">int</span> pageId<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> metaKey <span class="sy0">=</span> getMetaKey<span class="br0">&#40;</span>sessionId,pageMap,pageId<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aobject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">Object</span></a> ret <span class="sy0">=</span> cache.<span class="me1">get</span><span class="br0">&#40;</span>metaKey<span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>logger.<span class="me1">isDebugEnabled</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logger.<span class="me1">debug</span><span class="br0">&#40;</span><span class="st0">&quot;GetMeta: &quot;</span> <span class="sy0">+</span> metaKey<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>ret <span class="sy0">==</span> <span class="kw2">null</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw1">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a><span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="br0">&#123;</span><span class="st0">&quot;0&quot;</span>,<span class="st0">&quot;0&quot;</span><span class="br0">&#125;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a>.<span class="me1">valueOf</span><span class="br0">&#40;</span>ret<span class="br0">&#41;</span>.<span class="me1">split</span><span class="br0">&#40;</span><span class="st0">&quot;:&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">protected</span> <span class="kw4">void</span> storeMeta<span class="br0">&#40;</span><span class="kw1">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> sessionId, <span class="kw1">final</span> Page page<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> metaKey <span class="sy0">=</span> getMetaKey<span class="br0">&#40;</span>sessionId, page<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aobject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">Object</span></a> ret <span class="sy0">=</span> cache.<span class="me1">get</span><span class="br0">&#40;</span>metaKey<span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>logger.<span class="me1">isDebugEnabled</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logger.<span class="me1">debug</span><span class="br0">&#40;</span><span class="st0">&quot;StoreMeta: &quot;</span> <span class="sy0">+</span> metaKey<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>ret <span class="sy0">==</span> <span class="kw2">null</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cache.<span class="me1">put</span><span class="br0">&#40;</span>metaKey,page.<span class="me1">getCurrentVersionNumber</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">+</span><span class="st0">&quot;:&quot;</span><span class="sy0">+</span>page.<span class="me1">getAjaxVersionNumber</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a><span class="br0">&#91;</span><span class="br0">&#93;</span> vals <span class="sy0">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a>.<span class="me1">valueOf</span><span class="br0">&#40;</span>ret<span class="br0">&#41;</span>.<span class="me1">split</span><span class="br0">&#40;</span><span class="st0">&quot;:&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">int</span> currPage <span class="sy0">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainteger+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">Integer</span></a>.<span class="me1">valueOf</span><span class="br0">&#40;</span>vals<span class="br0">&#91;</span>0<span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">int</span> currAjax <span class="sy0">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainteger+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">Integer</span></a>.<span class="me1">valueOf</span><span class="br0">&#40;</span>vals<span class="br0">&#91;</span>1<span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>page.<span class="me1">getCurrentVersionNumber</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">&gt;</span> currPage<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currPage <span class="sy0">=</span> page.<span class="me1">getCurrentVersionNumber</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>page.<span class="me1">getAjaxVersionNumber</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">&gt;</span> currAjax<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currAjax <span class="sy0">=</span> page.<span class="me1">getAjaxVersionNumber</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cache.<span class="me1">put</span><span class="br0">&#40;</span>metaKey,currPage<span class="sy0">+</span><span class="st0">&quot;:&quot;</span><span class="sy0">+</span>currAjax<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw4">void</span> storePage<span class="br0">&#40;</span><span class="kw1">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> sessionId, <span class="kw1">final</span> Page page<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> sKey <span class="sy0">=</span> storeKey<span class="br0">&#40;</span>sessionId, page<span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>logger.<span class="me1">isDebugEnabled</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logger.<span class="me1">debug</span><span class="br0">&#40;</span><span class="st0">&quot;StorePage: &quot;</span> <span class="sy0">+</span> sKey<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; cache.<span class="me1">put</span><span class="br0">&#40;</span>sKey, page<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; storeMeta<span class="br0">&#40;</span>sessionId,page<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw4">void</span> unbind<span class="br0">&#40;</span><span class="kw1">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> sessionId<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>logger.<span class="me1">isDebugEnabled</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logger.<span class="me1">debug</span><span class="br0">&#40;</span><span class="st0">&quot;Unbind: &quot;</span> <span class="sy0">+</span> sessionId<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span> <span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> key <span class="sy0">:</span> cache.<span class="me1">getKeys</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>key.<span class="me1">startsWith</span><span class="br0">&#40;</span>sessionId<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cache.<span class="me1">remove</span><span class="br0">&#40;</span>key<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p><span class="br0">&#125;</span></div>
</div>
<img src="http://feeds.feedburner.com/~r/Letsgetdugg/~4/rGCJgMOiM8M" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://letsgetdugg.com/2010/02/07/clustering-wicket-for-fun-and-profit/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://letsgetdugg.com/2010/02/07/clustering-wicket-for-fun-and-profit/</feedburner:origLink></item>
	</channel>
</rss>

