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

<channel>
	<title>random()</title>
	<atom:link href="http://blog.maxgarfinkel.com/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.maxgarfinkel.com</link>
	<description>All sorts, who knows?</description>
	<lastBuildDate>Sun, 18 Dec 2011 15:34:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>HBase Too many open files, OS X 10.6.8</title>
		<link>http://blog.maxgarfinkel.com/archives/257</link>
		<comments>http://blog.maxgarfinkel.com/archives/257#comments</comments>
		<pubDate>Sun, 18 Dec 2011 15:34:57 +0000</pubDate>
		<dc:creator>max</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.maxgarfinkel.com/?p=257</guid>
		<description><![CDATA[Today I ran into the following error 2011-12-18 13:02:52,918 FATAL org.apache.hadoop.hbase.regionserver.MemStoreFlusher: Replay of hlog required. Forcing server shutdown org.apache.hadoop.hbase.DroppedSnapshotException: region: .META.,,1 at org.apache.hadoop.hbase.regionserver.HRegion.internalFlushcache(HRegion.java:946) at org.apache.hadoop.hbase.regionserver.HRegion.flushcache(HRegion.java:839) at org.apache.hadoop.hbase.regionserver.MemStoreFlusher.flushRegion(MemStoreFlusher.java:241) at org.apache.hadoop.hbase.regionserver.MemStoreFlusher.run(MemStoreFlusher.java:149) Caused by: java.io.FileNotFoundException: /Users/maxgarfinkel/Hadoop/hbase-datastore/hbase-maxgarfinkel/hbase/.META./1028785192/info/223659818943414297 (Too many open files) This is a well documented error and is caused by HBase opening more files than the OS will [...]]]></description>
			<content:encoded><![CDATA[<p>Today I ran into the following error</p>
<pre>
2011-12-18 13:02:52,918 FATAL org.apache.hadoop.hbase.regionserver.MemStoreFlusher: Replay of hlog required. Forcing server shutdown
org.apache.hadoop.hbase.DroppedSnapshotException: region: .META.,,1
	at org.apache.hadoop.hbase.regionserver.HRegion.internalFlushcache(HRegion.java:946)
	at org.apache.hadoop.hbase.regionserver.HRegion.flushcache(HRegion.java:839)
	at org.apache.hadoop.hbase.regionserver.MemStoreFlusher.flushRegion(MemStoreFlusher.java:241)
	at org.apache.hadoop.hbase.regionserver.MemStoreFlusher.run(MemStoreFlusher.java:149)
Caused by: java.io.FileNotFoundException: /Users/maxgarfinkel/Hadoop/hbase-datastore/hbase-maxgarfinkel/hbase/.META./1028785192/info/223659818943414297 (Too many open files)
</pre>
<p>This is a well documented error and is caused by HBase opening more files than the OS will let it. To be clear this is an OS configuration issue. On the mac OS the default max number of files a process can open is 264, this can however be changed.</p>
<p>The command</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">launchctl</pre></div></div>

<p>opens a command line application that lets you view and update this setting and related system settings. Once in launchctl typing the command</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"> limit</pre></div></div>

<p> shows the following output:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">max-garfinkels-computer:~ maxgarfinkel$ launchctl
launchd<span style="color: #000000; font-weight: bold;">%</span> limit
	cpu         unlimited      unlimited      
	filesize    unlimited      unlimited      
	data        unlimited      unlimited      
	stack       <span style="color: #000000;">8388608</span>        <span style="color: #000000;">67104768</span>       
	core        <span style="color: #000000;">0</span>              unlimited      
	rss         unlimited      unlimited      
	memlock     unlimited      unlimited      
	maxproc     <span style="color: #000000;">266</span>            <span style="color: #000000;">532</span>            
	maxfiles    <span style="color: #000000;">20000</span>          <span style="color: #000000;">50000</span>          
launchd<span style="color: #000000; font-weight: bold;">%</span></pre></div></div>

<p>When in launchctl you can update the maxfiles property by issuing the command:</p>
<pre code="bash">limit maxfiles 20000 5000</pre>
<p> The first value is the soft limit and the second value is the hard limit. I don&#8217;t know what the difference is, however I do know you cannot set either to unlimited. The big problem I found however is that this setting doesn&#8217;t seem to stick. To make it stick there is a config file you must change. The file is /etc/launchd.conf, and you will probably have to create it. In nano this is dead easy:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">nano</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>launchd.conf</pre></div></div>

<p>Then add the following line to the file:</p>
<pre>
limit maxfiles 20000 50000
</pre>
<p>save it and reboot. If this fails it seems to fail silently so it is worth verifying by launching launchctl and issuing the limit command.<br />
You can check that HBase has picked up this setting by checking the master log and the regionservers log. The mater log file will have the following line, dumped at start up:</p>
<pre>
Sun 18 Dec 2011 13:32:52 GMT Starting master on max-garfinkels-computer.local
ulimit -n 20000
</pre>
<p>and the region log will have :</p>
<pre>
Sun Dec 18 13:32:53 GMT 2011 Starting regionserver on max-garfinkels-computer.local
ulimit -n 20000
</pre>
<p>with the ulimit -n xxx being the maxfiles limit we applied.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.maxgarfinkel.com/archives/257/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reading files from in a jar</title>
		<link>http://blog.maxgarfinkel.com/archives/246</link>
		<comments>http://blog.maxgarfinkel.com/archives/246#comments</comments>
		<pubDate>Sun, 27 Nov 2011 18:47:31 +0000</pubDate>
		<dc:creator>max</dc:creator>
				<category><![CDATA[learning Java]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blog.maxgarfinkel.com/?p=246</guid>
		<description><![CDATA[Getting a java.io.FileNotFoundException when trying to load a resource. This didn&#8217;t occur when running the code from the IDE but when it was deployed. The culprit was getClass().getResource(&#8220;filename&#8221;), which returns a url. I then created a BufferedReader from a FileReader, from a File, from the url, phew. What I think happens in that the wrong [...]]]></description>
			<content:encoded><![CDATA[<p>Getting a java.io.FileNotFoundException when trying to load a resource. This didn&#8217;t occur when running the code from the IDE but when it was deployed.</p>
<p>The culprit was getClass().getResource(&#8220;filename&#8221;), which returns a url. I then created a BufferedReader from a FileReader, from a File, from the url, phew. </p>
<p>What I think happens in that the wrong handler get used, java assumes you are trying to read a normal file from the filesystem and uses the file protocol handler, when in fact you need the jar protocol handler.</p>
<p>FIX</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">InputStream</span> inputStream <span style="color: #339933;">=</span> getClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getResourceAsStream</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;fileName&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
reader <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BufferedReader</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">InputStreamReader</span><span style="color: #009900;">&#40;</span>inputStream<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.maxgarfinkel.com/archives/246/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Functional programming</title>
		<link>http://blog.maxgarfinkel.com/archives/250</link>
		<comments>http://blog.maxgarfinkel.com/archives/250#comments</comments>
		<pubDate>Sat, 30 Apr 2011 20:54:14 +0000</pubDate>
		<dc:creator>max</dc:creator>
				<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blog.maxgarfinkel.com/archives/250</guid>
		<description><![CDATA[Just finished reading a fantastic article on functional programming, http://www.defmacro.org/ramblings/fp.html I can&#8217;t recommend it enough!]]></description>
			<content:encoded><![CDATA[<p>Just finished reading a fantastic article on functional programming, http://www.defmacro.org/ramblings/fp.html I can&#8217;t recommend it enough!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.maxgarfinkel.com/archives/250/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Saving Image object in java on OS X</title>
		<link>http://blog.maxgarfinkel.com/archives/247</link>
		<comments>http://blog.maxgarfinkel.com/archives/247#comments</comments>
		<pubDate>Tue, 15 Feb 2011 22:20:16 +0000</pubDate>
		<dc:creator>max</dc:creator>
				<category><![CDATA[learning Java]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blog.maxgarfinkel.com/?p=247</guid>
		<description><![CDATA[Difficulty converting Image to BufferedImage, On a mac and getting apple.awt.OSXImage cannot be cast to java.awt.image.BufferedImage errors? Dan is your man!]]></description>
			<content:encoded><![CDATA[<p>I have an app I am working on that stores an image an ImageIcon object. I want to save this image to disk. So I start with:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">Image</span> image <span style="color: #339933;">=</span> imageIcon.<span style="color: #006633;">getImage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This creates an Image object which is a super class of the BufferedImage. Did a bit of reading and it seemed it should really be a BufferedImage, so all that was really necessary was to call:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">ImageIO.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">BufferedImage</span><span style="color: #009900;">&#41;</span>image, <span style="color: #0000ff;">&quot;png&quot;</span>, file<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>casting the Image to a BufferedImage. However the system balked at this irresponsible and apparently ill advised abuse of the typing system and delivered me a swift rebuke, in the form of a class cast exception. Well I guess I was asking for it, but what exactly was the problem? was it a volatile image perhaps? The other documented sub class of Image? No such luck, this was the telling off I got: <code>java.lang.ClassCastException: apple.awt.OSXImage cannot be cast to java.awt.image.BufferedImage</code>. Turns out on the mac (oh how I love you and hate you apple), they have their own pretty much undocumented image class OSXImage. So how to deal with this. I did a little googling and came across <a href="http://www.velocityreviews.com/forums/t134036-image-to-bufferedimage.html">this</a>. To summarise the advice was essentially:</p>
<ul>
<li>Get the Image&#8217;s consumer with Image.getSource().</li>
<li>Use a PixelGrabber to read the image data from the consumer into some<br />
pixel array</li>
<li>Create a DataBufferInt from the pixel data</li>
<li>Create a WritableRaster using the DataBufferInt</li>
<li>Create a BufferedImage using the WritableRaster</li>
<li>curse, wait, curse, wait, curse, curse, curse</li>
</ul>
<p>More than a little daunting, still I hadn&#8217;t found any thing else of any use so I gave it a crack. Documentation on this stuff was painfully thin on the ground but I got something that created an image &#8211; just not the right image. I had real trouble with understanding the bitmasks required for decoding pixels packed into ints offsets and all sorts of other things I will have to get to grips with at some point. But thankfully not now. After hours of cursing and waiting as advised in the approach quoted, I went back to google. After a while I stumbled across <a href="http://blog.pengoworks.com/index.cfm/2008/2/8/The-nightmares-of-getting-images-from-the-Mac-OS-X-clipboard-using-Java">this</a>, thank you dan!</p>
<p>Dan is the man! He out thought the problem and came up with a beautifully simple solution!</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">Image</span> image <span style="color: #339933;">=</span> imgIcon.<span style="color: #006633;">getImage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">int</span> width <span style="color: #339933;">=</span> imgIcon.<span style="color: #006633;">getIconWidth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">int</span> height <span style="color: #339933;">=</span> imgIcon.<span style="color: #006633;">getIconHeight</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">BufferedImage</span> bi <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BufferedImage</span><span style="color: #009900;">&#40;</span>width, height, <span style="color: #003399;">BufferedImage</span>.<span style="color: #006633;">TYPE_INT_RGB</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">Graphics</span> graphics <span style="color: #339933;">=</span> bi.<span style="color: #006633;">getGraphics</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
graphics.<span style="color: #006633;">drawImage</span><span style="color: #009900;">&#40;</span>image, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
graphics.<span style="color: #006633;">dispose</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Basically get the Image out of the icon, create a new BufferedImage. Get its graphics object and just draw our image into it! Now we have a buffered image, with our image in it. This seems like it should be a nice solution that will ensure that this image saving malarkey doesn&#8217;t fail on crazy java VM implementations where the image class is unexpectedly extended. Best of all no more, seat of the pants casting!</p>
<p>Thanks Dan!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.maxgarfinkel.com/archives/247/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The dreaded equals() and hashcode()</title>
		<link>http://blog.maxgarfinkel.com/archives/243</link>
		<comments>http://blog.maxgarfinkel.com/archives/243#comments</comments>
		<pubDate>Mon, 14 Feb 2011 17:06:22 +0000</pubDate>
		<dc:creator>max</dc:creator>
				<category><![CDATA[learning Java]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blog.maxgarfinkel.com/?p=243</guid>
		<description><![CDATA[Today I finally got to the bottom of a bug that has been causing a headache. The solution was too obvious and text book that I thought I would publicly humiliate myself so as help me remember never to let it happen again. The story is this: I created a class called Landmark: public class [...]]]></description>
			<content:encoded><![CDATA[<p>Today I finally got to the bottom of a bug that has been causing a headache. The solution was too obvious and text book that I thought I would publicly humiliate myself so as help me remember never to let it happen again.</p>
<p>The story is this:<br />
I created a class called Landmark:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Landmark <span style="color: #009900;">&#123;</span>
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Key uniquely identifying landmark.
     */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">long</span> id<span style="color: #339933;">;</span>
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Textual representation of the landmark.
     */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> name<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Constructor creates a landmark with id and name.
     * @param id
     * @param name
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> Landmark<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">long</span> id, <span style="color: #003399;">String</span> name<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">id</span> <span style="color: #339933;">=</span> id<span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">name</span> <span style="color: #339933;">=</span> name<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Creates a landmark object with only an id.
     * @param id
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> Landmark<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">long</span> id<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">id</span> <span style="color: #339933;">=</span> id<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
....
....</pre></div></div>

<p>All looks pretty reasonable, however notice the overloaded constructor, you can make a landmark just with the id, which happens to be really handy. Now see if you can spot the problem!</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Equality is only checked on id
     * @param obj
     * @return
     */</span>
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> equals<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> obj<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>obj <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>getClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> obj.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">final</span> Landmark other <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Landmark<span style="color: #009900;">&#41;</span> obj<span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">id</span> <span style="color: #339933;">!=</span> other.<span style="color: #006633;">id</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #666666; font-style: italic;">/*
        if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
            return false;
        }*/</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> hashCode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">int</span> hash <span style="color: #339933;">=</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">;</span>
        hash <span style="color: #339933;">=</span> <span style="color: #cc66cc;">53</span> <span style="color: #339933;">*</span> hash <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">id</span> <span style="color: #339933;">^</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">id</span> <span style="color: #339933;">&gt;&gt;&gt;</span> <span style="color: #cc66cc;">32</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        hash <span style="color: #339933;">=</span> <span style="color: #cc66cc;">53</span> <span style="color: #339933;">*</span> hash <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">name</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">?</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">name</span>.<span style="color: #006633;">hashCode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> hash<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Ok so notice that equality was originally checked on name and id, thus is the name was missing they were not the same. You can imagine this became a real pain in the arse, because they should really be the same because they refer to the same landmark. So you can see one day in a fit of rage I simply commented out the line comparing the names and settled on equality based only on id. Spotted the issue yet?</p>
<p>Well being in a fit of rage I didn&#8217;t think it through very far, or look a few lines below, at the hashcode implementation. So now equality is defined as simply equality of id but hashcode is calculated from id and name! Guess what happened?</p>
<p>Well I was stashing some Landmarks in a hashmap as a key with some Integer values associated with them. I had a second Set of Landmarks which I needed the Integer for, so I happily try and pull out the Integer using one of my Landmarks. However the Landmark in the hashmap has a title, the Landmark I am using to pull the int doesn&#8217;t. Result? can&#8217;t retrieve a single value and get null pointer exceptions all over the shot! Why? Because the two landmarks I consider the same and that the <code>.equals(object)</code> method consider the same aren&#8217;t gonna be in the same place in the hashtable, so as far as the hash table is concerned, they sure aint the same!</p>
<p>Result? Give thought to <code>equals()</code> and <code>hashcode()</code> and remember what they do. All in all I learnt a good lesson at the expense of some real pain even if it was a programming 101 lesson <img src='http://blog.maxgarfinkel.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.maxgarfinkel.com/archives/243/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>class.getResource() returns null when using netbeans</title>
		<link>http://blog.maxgarfinkel.com/archives/240</link>
		<comments>http://blog.maxgarfinkel.com/archives/240#comments</comments>
		<pubDate>Fri, 11 Feb 2011 15:31:15 +0000</pubDate>
		<dc:creator>max</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.maxgarfinkel.com/?p=240</guid>
		<description><![CDATA[If you are running your project from netbeans directly and you have added a resource to a package and you are trying to access it using class.getResource&#40;path&#41; and you find yourself banging your head against the wall because it doesn&#8217;t seem to work as it should, then you may need to do a clean build [...]]]></description>
			<content:encoded><![CDATA[<p>If you are running your project from netbeans directly and you have added a resource to a package and you are trying to access it using</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getResource</span><span style="color: #009900;">&#40;</span>path<span style="color: #009900;">&#41;</span></pre></div></div>

<p>and you find yourself banging your head against the wall because it doesn&#8217;t seem to work as it should, then you may need to do a clean build of the project as the resource may be missing from the jar. Wish I had known that before giving myself a bloody forehead and my desk a dent!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.maxgarfinkel.com/archives/240/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Functional programming</title>
		<link>http://blog.maxgarfinkel.com/archives/239</link>
		<comments>http://blog.maxgarfinkel.com/archives/239#comments</comments>
		<pubDate>Fri, 04 Feb 2011 08:59:31 +0000</pubDate>
		<dc:creator>max</dc:creator>
				<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blog.maxgarfinkel.com/archives/239</guid>
		<description><![CDATA[Just finished reading a fantastic article on functional programming, http://www.defmacro.org/ramblings/fp.html I can&#8217;t recommend it enough!]]></description>
			<content:encoded><![CDATA[<p>Just finished reading a fantastic article on functional programming, http://www.defmacro.org/ramblings/fp.html I can&#8217;t recommend it enough!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.maxgarfinkel.com/archives/239/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mockito Hadoop and HBase</title>
		<link>http://blog.maxgarfinkel.com/archives/233</link>
		<comments>http://blog.maxgarfinkel.com/archives/233#comments</comments>
		<pubDate>Wed, 26 Jan 2011 22:17:14 +0000</pubDate>
		<dc:creator>max</dc:creator>
				<category><![CDATA[Hadoop]]></category>
		<category><![CDATA[learning Java]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blog.maxgarfinkel.com/?p=233</guid>
		<description><![CDATA[Today I started writing my first map reduce job that runs against HBase. I have been trying hard to work in a test driven manner and this both seemed like a good thing to use TDD on but also a hard thing to use TDD on. The MR job is fairly simple &#8211; read two [...]]]></description>
			<content:encoded><![CDATA[<p>Today I started writing my first map reduce job that runs against HBase. I have been trying hard to work in a test driven manner and this both seemed like a good thing to use TDD on but also a hard thing to use TDD on. The MR job is fairly simple &#8211; read two columns from the table and do some basic processing &#8211; much like the famous word count example &#8211; and then write the results back to a new table. Now perhaps I am speaking too soon but I have set up a basic unit test for the mapper in the job. Thanks to <a title="Mockito on google code" href="http://code.google.com/p/mockito/" target="_blank">Mockito</a> this proved to be far easier than I anticipated.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@Override
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> map<span style="color: #009900;">&#40;</span>ImmutableBytesWritable key, Result value, <span style="color: #003399;">Context</span> context<span style="color: #009900;">&#41;</span>
                                  <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span>, <span style="color: #003399;">InterruptedException</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">int</span> frequency <span style="color: #339933;">=</span> Bytes.<span style="color: #006633;">toInt</span><span style="color: #009900;">&#40;</span>value.<span style="color: #006633;">getValue</span><span style="color: #009900;">&#40;</span>HBaseSchemaConstants.<span style="color: #006633;">FREQUENCY_BYTES</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">String</span> trail <span style="color: #339933;">=</span> Bytes.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span>value.<span style="color: #006633;">getValue</span><span style="color: #009900;">&#40;</span>HBaseSchemaConstants.<span style="color: #006633;">TRAILSTRING_BYTES</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> landmarks <span style="color: #339933;">=</span> trail.<span style="color: #006633;">split</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;:&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> landmarks.<span style="color: #006633;">length</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">String</span> pair <span style="color: #339933;">=</span> landmarks<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;:&quot;</span> <span style="color: #339933;">+</span> landmarks<span style="color: #009900;">&#91;</span>i<span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        context.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Text<span style="color: #009900;">&#40;</span>pair<span style="color: #009900;">&#41;</span>, <span style="color: #000000; font-weight: bold;">new</span> IntWritable<span style="color: #009900;">&#40;</span>frequency<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>So whats the problem here? Well we have a problem with getting input in and we have a problem with verifying the output.</p>
<h2>Input</h2>
<p>The input is passed through a <a href="http://hbase.apache.org/docs/r0.20.5/api/org/apache/hadoop/hbase/client/Result.html" target="_blank">Result</a> object which has not setters on it, so I can&#8217;t pre populate it with dummy data. This is where Mockito comes in. We create a mock of the result object and stub the getValue calls on it.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">Result result <span style="color: #339933;">=</span> mock<span style="color: #009900;">&#40;</span>Result.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> frequencyColumnId <span style="color: #339933;">=</span> Bytes.<span style="color: #006633;">toBytes</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;frequency&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> frequency <span style="color: #339933;">=</span> Bytes.<span style="color: #006633;">toBytes</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">12</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> trailColumnId <span style="color: #339933;">=</span> Bytes.<span style="color: #006633;">toBytes</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;trailstring&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> trail <span style="color: #339933;">=</span> Bytes.<span style="color: #006633;">toBytes</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;1:2:3:4:5:3:2:1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
when<span style="color: #009900;">&#40;</span>result.<span style="color: #006633;">getValue</span><span style="color: #009900;">&#40;</span>frequencyColumnId<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">thenReturn</span><span style="color: #009900;">&#40;</span>frequency<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
when<span style="color: #009900;">&#40;</span>result.<span style="color: #006633;">getValue</span><span style="color: #009900;">&#40;</span>trailColumnId<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">thenReturn</span><span style="color: #009900;">&#40;</span>trail<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The first line creates the actual mock. The next four lines are just me encoding the mock values I will use in the test into byte arrays. The final two lines are the stubs for the getValue() call I will be making in the map method I am testing. These translate as &#8220;when getValue is called with an argument equal to frequencyColumnId then return (int)12&#8243; and &#8220;when getValue is called with an argument equal to trailColumnId then return (String)1:2:3:4:5:3:2:1&#8243;. This ensures I get some mock values into my map.</p>
<h2>Output</h2>
<p>Now the problem of the output. In my mapper I make multiple calls to context.write(), which I need to verify, once again I can use Mockito, but this time in a slightly different way. The really cool feature of Mockito here is that it records the number of times each method was called with given arguments.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">Context</span> context <span style="color: #339933;">=</span> mock<span style="color: #009900;">&#40;</span><span style="color: #003399;">Context</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
main body of test
**/</span>
verify<span style="color: #009900;">&#40;</span>context, times<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Text<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;1:2&quot;</span><span style="color: #009900;">&#41;</span>, <span style="color: #000000; font-weight: bold;">new</span> IntWritable<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">12</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
verify<span style="color: #009900;">&#40;</span>context, times<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Text<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;2:3&quot;</span><span style="color: #009900;">&#41;</span>, <span style="color: #000000; font-weight: bold;">new</span> IntWritable<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">12</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
verify<span style="color: #009900;">&#40;</span>context, times<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Text<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;3:4&quot;</span><span style="color: #009900;">&#41;</span>, <span style="color: #000000; font-weight: bold;">new</span> IntWritable<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">12</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
verify<span style="color: #009900;">&#40;</span>context, times<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Text<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;4:5&quot;</span><span style="color: #009900;">&#41;</span>, <span style="color: #000000; font-weight: bold;">new</span> IntWritable<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">12</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
verify<span style="color: #009900;">&#40;</span>context, times<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Text<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;3:2&quot;</span><span style="color: #009900;">&#41;</span>, <span style="color: #000000; font-weight: bold;">new</span> IntWritable<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">12</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
verify<span style="color: #009900;">&#40;</span>context, times<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Text<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;2:1&quot;</span><span style="color: #009900;">&#41;</span>, <span style="color: #000000; font-weight: bold;">new</span> IntWritable<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">12</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In this block of code we call verify(nameOfMockObject, time(numberOfTimesCalled).methodWeAreInterestedIn(expectedArgs); basically we can repeatedly call verify as many times as we have expected calls on the mock, in this case context.</p>
<p>Ill add more once I have done my reduce method too, but so far its looking like a cinch!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.maxgarfinkel.com/archives/233/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hacking or engineering? what, when and why</title>
		<link>http://blog.maxgarfinkel.com/archives/214</link>
		<comments>http://blog.maxgarfinkel.com/archives/214#comments</comments>
		<pubDate>Sat, 15 Jan 2011 20:00:28 +0000</pubDate>
		<dc:creator>max</dc:creator>
				<category><![CDATA[learning Java]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blog.maxgarfinkel.com/?p=214</guid>
		<description><![CDATA[I am working on a research project whilst at the same time reading Refactoring by Martin Fowler and Growing Object-Oriented Software Guided By Tests by Steve Freeman and Nat Pryce. I think both books go really nicely hand in hand with the general philosophy of test driven development with both supporting each other very well. [...]]]></description>
			<content:encoded><![CDATA[<p>I am working on a research project whilst at the same time reading Refactoring by Martin Fowler and Growing Object-Oriented Software Guided By Tests by Steve Freeman and Nat Pryce. I think both books go really nicely hand in hand with the general philosophy of test driven development with both supporting each other very well.</p>
<p>However I have a dilemma &#8211; I want experimental results quickly and will learn a lot on the way, however following a rigours test driven approach with refactoring seems to mean I am getting better software but I am also getting further from my results.</p>
<p>In theory (and I do believe the theory) I will end up with much better designed software through using the techniques described in the books. Coupling should be lower making the code more flexible and reusable &#8211; important in an ever changing research environment. Also I can make bigger changes with the confidence that I can do them incrementally testing that contracts are kept all along. This is all great, but I am still learning and as such the code base could do with much refactoring simply to enable more through unit testing. As it happens this will also benefit the architecture, but it will cost time.</p>
<p>Also as this progresses I can see that one ends up with a larger structure of code made of smaller bits, so on one hand you are making the software more modular and flexible and generally simplifying and making more readable blocks of code, but is this at the expense of a more complex overall structure?</p>
<p>I can only guess for now, and for now I will still be doing a degree of ugly hacking but it is feeling more and more wrong.</p>
<p>Speaking to other researchers some have told me of there regret for not starting out with unit testing and well engineered code, whilst others have completed plenty of high quality published research on the back of throw-away, proof of concept hacking, and have no real experience of a more engineering oriented approach.</p>
<p>I suspect there isn&#8217;t a black and white answer and it depends on the purpose of your code, like most things it is probably generally a nuanced and slightly subjective call based on the details of your requirements.</p>
<p>I will try and update this post with more reflections on this problem as I make progress.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.maxgarfinkel.com/archives/214/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Subversion notes</title>
		<link>http://blog.maxgarfinkel.com/archives/215</link>
		<comments>http://blog.maxgarfinkel.com/archives/215#comments</comments>
		<pubDate>Mon, 10 Jan 2011 20:42:06 +0000</pubDate>
		<dc:creator>max</dc:creator>
				<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blog.maxgarfinkel.com/?p=215</guid>
		<description><![CDATA[Subversion server died the other day, and I haven&#8217;t been backing it up. I use mediatemple for my hosting and they offer subversion so I thought I would start using it. Last time I got a friend to set it up for me but this time I thought I should do it my self. I [...]]]></description>
			<content:encoded><![CDATA[<p>Subversion server died the other day, and I haven&#8217;t been backing it up. I use mediatemple for my hosting and they offer subversion so I thought I would start using it. Last time I got a friend to set it up for me but this time I thought I should do it my self. I know subversion is great, but it is also quite complex, I found it a complete nightmare, but I now have something that vaguely  approximates working.</p>
<p>The goal was to move all my local files that used to belong to the previous repository to a new repository hosted on my mediatemple server. Then get netbeans talking to it, and, hopefully have a clue how it all works. This proved to be a complete nightmare and so before I forget all the things I learned I will try and get down as many of them as possible here.</p>
<h2><span style="font-weight: normal;">General Points</span></h2>
<ul>
<li>Subversion allows for repositories at the top level with multiple projects under that. This is what I have done.</li>
<li>The svn server stores everything in a folder I named svn &#8211; you don&#8217;t really want to go looking around it as far as I can tell.</li>
<li>Items have an address within the repository that looks something like this:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">protocol:<span style="color: #000000; font-weight: bold;">//</span>host.com<span style="color: #000000; font-weight: bold;">/</span>folder<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>the<span style="color: #000000; font-weight: bold;">/</span>repository<span style="color: #000000; font-weight: bold;">/</span>svn<span style="color: #000000; font-weight: bold;">/</span>myRepo</pre></div></div>

<p>The path needs to be from the root of the host and the protocol can be several things depending on where you are accessing from. When accessing locally, i.e. you are on the same machine that hosts the repository you should use something akin to this (notice that there is no host, we don&#8217;t need it because we are on the machine in question).</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">file</span>:<span style="color: #000000; font-weight: bold;">///</span>home<span style="color: #000000; font-weight: bold;">/</span>max<span style="color: #000000; font-weight: bold;">/</span>svn<span style="color: #000000; font-weight: bold;">/</span>myRepo</pre></div></div>

<p>If however you are accessing a mediatemple hosted subversion repository you need to access it via svn+ssh which is the svn protocol tunnelled through ssh. In this case the path would look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">svn</span>+<span style="color: #c20cb9; font-weight: bold;">ssh</span>:<span style="color: #000000; font-weight: bold;">//</span>myhostname.com<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1234</span><span style="color: #000000; font-weight: bold;">/</span>users<span style="color: #000000; font-weight: bold;">/</span>max<span style="color: #000000; font-weight: bold;">/</span>svn<span style="color: #000000; font-weight: bold;">/</span>mtSvnRepo1</pre></div></div>

<p>or</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">svn</span>+<span style="color: #c20cb9; font-weight: bold;">ssh</span>:<span style="color: #000000; font-weight: bold;">//</span>myusername<span style="color: #000000; font-weight: bold;">@</span>myhostname.com<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1234</span><span style="color: #000000; font-weight: bold;">/</span>users<span style="color: #000000; font-weight: bold;">/</span>max<span style="color: #000000; font-weight: bold;">/</span>svn<span style="color: #000000; font-weight: bold;">/</span>mtSvnRepo1</pre></div></div>

<p>The only difference being the inclusion of the username that you wish to use with the host (your username for logging into the machine hosting the repository). More about that later. Now this is just the path to the repository, your projects and the files within them are then just bolted on the end thus.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">svn</span>+<span style="color: #c20cb9; font-weight: bold;">ssh</span>:<span style="color: #000000; font-weight: bold;">//</span>myhostname.com<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1234</span><span style="color: #000000; font-weight: bold;">/</span>users<span style="color: #000000; font-weight: bold;">/</span>max<span style="color: #000000; font-weight: bold;">/</span>svn<span style="color: #000000; font-weight: bold;">/</span>mtSvnRepo1<span style="color: #000000; font-weight: bold;">/</span>project1<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>someFile.java</pre></div></div>

</li>
</ul>
<h2>Some Commands</h2>
<ul>
<li>Create a repository

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">svnadmin</span> create <span style="color: #660033;">--fs-type</span> fsfs</pre></div></div>

</li>
<li>Import some files into the repository

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">svn</span> import <span style="color: #000000; font-weight: bold;">/</span>just<span style="color: #000000; font-weight: bold;">/</span>a<span style="color: #000000; font-weight: bold;">/</span>folder <span style="color: #c20cb9; font-weight: bold;">svn</span>+<span style="color: #c20cb9; font-weight: bold;">ssh</span>:<span style="color: #000000; font-weight: bold;">//</span>myhostname.com<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1234</span><span style="color: #000000; font-weight: bold;">/</span>users<span style="color: #000000; font-weight: bold;">/</span>max<span style="color: #000000; font-weight: bold;">/</span>svn<span style="color: #000000; font-weight: bold;">/</span>mtSvnRepo1 <span style="color: #660033;">-m</span> <span style="color: #ff0000;">&quot;a test of adding a new project remotly&quot;</span></pre></div></div>

<p>the -m flag is the commit message which is stored with the revision number</li>
<li>List the projects under svn control

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">svn</span> list <span style="color: #660033;">--verbose</span> <span style="color: #c20cb9; font-weight: bold;">svn</span>+<span style="color: #c20cb9; font-weight: bold;">ssh</span>:<span style="color: #000000; font-weight: bold;">//</span>myhostname.com<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1234</span><span style="color: #000000; font-weight: bold;">/</span>users<span style="color: #000000; font-weight: bold;">/</span>max<span style="color: #000000; font-weight: bold;">/</span>svn<span style="color: #000000; font-weight: bold;">/</span>mtSvnRepo1
      <span style="color: #000000;">2</span> maxgarfi              Jan <span style="color: #000000;">10</span> <span style="color: #000000;">15</span>:<span style="color: #000000;">12</span> RAVisualisationClient-01<span style="color: #000000; font-weight: bold;">/</span>
      <span style="color: #000000;">4</span> maxgarfi              Jan <span style="color: #000000;">10</span> <span style="color: #000000;">15</span>:<span style="color: #000000;">20</span> RAVisualisationDataAccess-01<span style="color: #000000; font-weight: bold;">/</span>
     <span style="color: #000000;">18</span> maxgarfi              Jan <span style="color: #000000;">10</span> <span style="color: #000000;">18</span>:<span style="color: #000000;">30</span> RAVisualisationEngine-01<span style="color: #000000; font-weight: bold;">/</span>
      <span style="color: #000000;">8</span> maxgarfi              Jan <span style="color: #000000;">10</span> <span style="color: #000000;">15</span>:<span style="color: #000000;">32</span> RAVisualisationGUI-01<span style="color: #000000; font-weight: bold;">/</span>
     <span style="color: #000000;">10</span> maxgarfi              Jan <span style="color: #000000;">10</span> <span style="color: #000000;">15</span>:<span style="color: #000000;">37</span> RAVisualisationLib-01<span style="color: #000000; font-weight: bold;">/</span>
     <span style="color: #000000;">12</span> maxgarfi              Jan <span style="color: #000000;">10</span> <span style="color: #000000;">15</span>:<span style="color: #000000;">49</span> RAVisualisationServer-01<span style="color: #000000; font-weight: bold;">/</span>
     <span style="color: #000000;">19</span> maxgarfi              Jan <span style="color: #000000;">10</span> <span style="color: #000000;">19</span>:00 librarys<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

</li>
<li>Checkout or co. Unlike Team Foundation or Source Safe on windows this doesn&#8217;t lock any files it just gets the latest copy from the repository.</li>
<li>Add &#8211; adds a new file to the repository.</li>
<li>Delete &#8211; removes the file from the repository (sort of) and only removes it from the repo when you commit.</li>
<li>Update &#8211; pulls down any changes to the files in the repo and tries to merge them with the local files on your machine.</li>
<li>Commit  - submits your changed files to the repo and gives them a revision number.</li>
</ul>
<h2>Removing Files From Subversion Control</h2>
<p>No this really caught me out. When you associate files with a subversion repository the subversion client on your local machine peppers the folders of your project with hidden .svn folders. This is how it knows what is what and keeps track of stuff. BUT, and this is a big but, if you end up with a dead/no longer accessible repository and you want to move you local files so they are looked after by a new repository, then your in trouble. Its worth noting that at this stage you have lost all the previous history of your files &#8211; that went with the previous repository, but hey at least you have your files.</p>
<p>Try just adding these files to a new repository? It aint gonna work &#8211; subversion will tell you that they are being looked after by a now non existent repository. Took me a long time to find it but there is a subversion command that &#8220;exports&#8221; the files in your projects without all the hidden .svn files, and its called export:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"> <span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>old<span style="color: #000000; font-weight: bold;">/</span>project<span style="color: #000000; font-weight: bold;">/</span> path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>new<span style="color: #000000; font-weight: bold;">/</span>version<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>Great! just one little snag to look out for: if there were files in your project that you hadn&#8217;t added to the repo before it all went tits up export wont copy them over &#8211; you might need to hunt them down manually and copy them over to your new location.</p>
<h2>SSH details</h2>
<p>To get netbeans working with svn+ssh there was a fair bit of fafing around, there is a good page on the <a title="Article on configuring netbeans to handle svn+ssh" href="http://wiki.netbeans.org/FaqSubversionSSH" target="_blank">netbeans site</a>. You also need to set up passwordless ssh access to the subversion server and possible create a .ssh/config file where you can specify the username to use when ssh&#8217;ing to that host.</p>
<h2>Links</h2>
<ul>
<li><a title="The SVN book" href="http://svnbook.red-bean.com/" target="_blank">The SVN book</a></li>
<li><a title="Netbeans svn+ssh configuration" href="http://wiki.netbeans.org/FaqSubversionSSH" target="_blank">Netbeans svn+ssh configuration</a></li>
<li><a title="Passwordless ssh " href="http://www.debian-administration.org/articles/152" target="_blank">Passwordless ssh</a></li>
<li>If you lock yourself out of your server by getting your passwordless ssh set up wrong <a title="Force ssh to ask for a password" href="http://blog.maxgarfinkel.com/archives/205" target="_blank">this post will get you out of trouble</a>.</li>
<li>mediatemple articles on <a title="MediaTemple svn configuration" href="http://kb.mediatemple.net/questions/143/Using+Subversion" target="_blank">configuring svn</a> and <a title="mediatemple passwordless ssh instructions" href="http://kb.mediatemple.net/questions/1626/Using+SSH+Keys+on+your+server" target="_blank">passwordless ssh</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.maxgarfinkel.com/archives/215/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

