<?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>Nick Zalabak - techwhizbang &#187; clojure</title>
	<atom:link href="http://techwhizbang.com/tag/clojure/feed/" rel="self" type="application/rss+xml" />
	<link>http://techwhizbang.com</link>
	<description>my work, life, and ideas</description>
	<lastBuildDate>Thu, 08 Mar 2012 06:07:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Clojure Applications as Daemons</title>
		<link>http://techwhizbang.com/2012/02/clojure-applications-as-daemons/</link>
		<comments>http://techwhizbang.com/2012/02/clojure-applications-as-daemons/#comments</comments>
		<pubDate>Wed, 29 Feb 2012 06:17:39 +0000</pubDate>
		<dc:creator>techwhizbang</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[clojure]]></category>
		<category><![CDATA[daemon]]></category>
		<category><![CDATA[jvm]]></category>

		<guid isPermaLink="false">http://techwhizbang.com/?p=571</guid>
		<description><![CDATA[Running your Clojure app as a daemon is very useful especially when you&#8217;re ready to take it live for several reasons. You need a way to easily and consistently &#8220;background&#8221; or disassociate from the controlling tty for every deployment. Systems often start daemons at boot time (think about when your server is rebooted intentionally and more often&#8230;unintentionally). [...]]]></description>
			<content:encoded><![CDATA[<p>Running your Clojure app as a daemon is very useful especially when you&#8217;re ready to take it live for several reasons.</p>
<ul>
<li>You need a way to easily and consistently &#8220;background&#8221; or disassociate from the controlling tty for every deployment.</li>
</ul>
<ul>
<li>Systems often <em>start daemons</em> at boot time (think about when your server is rebooted intentionally and more often&#8230;unintentionally).</li>
</ul>
<ul>
<li>Something a monitor script can execute if your application becomes unresponsive or unruly.</li>
</ul>
<p>There may be others, but those are the main reasons.</p>
<p>Those unfamiliar with the Java ecosystem may feel especially lost in this area, but fear not because here is an awesome solution. I am going to walk you through getting your application running as a daemon using a great piece of software made by <a title="Tanuki Java Service Wrapper" href="http://wrapper.tanukisoftware.com/doc/english/download.jsp" target="_blank">Tanuki</a>. I do not work for Tanuki, nor do I even know anyone at Tanuki, and so trust me this isn&#8217;t some lame plug for a product. I&#8217;ve used it for many of my Java applications and now I use it with my Clojure applications. It is quite simply a great piece of software. They call it a &#8220;Java Service Wrapper&#8221;, but that is a bit of a misnomer. It is really a <em>JVM</em> Service Wrapper.</p>
<p>In order to start using it, you&#8217;ll need to bundle your application as a Jar file. As you&#8217;ll read from the documentation on the Tanuki site there are several ways to &#8220;integrate&#8221; with the service wrapper. However, I find that using their <a href="http://wrapper.tanukisoftware.com/doc/english/integrate.html#method4" target="_blank">fourth approach</a> is the best. It is not  coupled in any way to your application and there is no code to be written. Generating a Jar file is of course a breeze if you&#8217;re using Leiningen or Cake. I&#8217;m most familiar with Leiningen so you&#8217;ll want to build an &#8220;uberjar&#8221; or an equivalent Jar file that contains all of its dependencies. Wait, you&#8217;re already <a title="quander" href="http://www.urbandictionary.com/define.php?term=quander">quandering</a>&#8230;&#8221;will it work if I have a web app?&#8221; Yes! You can make it a War file, if you are using an embedded Jetty server. In fact, you can make your web application a Jar file if you&#8217;re using the Ring Jetty adapter and skip the complexity of a War file. Of course this is beyond the scope of the post. Before you jump off into the deep end with the service wrapper be sure that your application starts properly. Remember you&#8217;ll need a &#8220;main&#8221; function registered in the manifest of your Jar file. On the command line start it up like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">java <span style="color: #660033;">-jar</span> your-nifty-clojure-app.jar</pre></div></div>

<p>Perfect. Now you&#8217;ll need to download the service wrapper from <a title="Tanuki Service Wrapper Download" href="http://wrapper.tanukisoftware.com/doc/english/download.jsp#latest" target="_blank">here</a>. You&#8217;ll see that they have thought of just about every OS distribution. If your development and production OS are the same, simply choose the right download. Or if you develop on a Mac and deploy to a Linux server like me, then choose the &#8220;Delta Pack&#8221;. The &#8220;Delta Pack&#8221; is cross platform support for those of us who develop  and deploy to a multitude of OS&#8217;s. I forgot to mention I use the community edition and that is what I will be using for this setup.</p>
<p>I prefer to create a folder in my project called &#8220;daemon&#8221; and unzip the service wrapper contents there. Once unzipped you&#8217;ll see a directory structure like this. Begin trimming the unnecessary files by deleting the README&#8217;s, doc, and jdoc folders.</p>
<p style="text-align: center;"><img class="aligncenter  wp-image-581" title="tanuki directory structure" src="http://techwhizbang.com/wp-content/uploads/2012/02/tanuki_directory_structure.jpg" alt="" width="620" height="73" /></p>
<p>Now go into the src/bin directory and find a file called &#8220;sh.script.in&#8221;. Copy it into the bin folder of daemon directory, rename it, and lastly make it executable.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> src<span style="color: #000000; font-weight: bold;">/</span>bin
<span style="color: #c20cb9; font-weight: bold;">cp</span> sh.script.in ..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>your-nifty-clojure-app
<span style="color: #7a0874; font-weight: bold;">cd</span> ..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>bin
<span style="color: #c20cb9; font-weight: bold;">chmod</span> +x your-nifty-clojure-app</pre></div></div>

<p>Open the executable and edit the following three variables to match your application name.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">APP_NAME</span>=<span style="color: #ff0000;">&quot;your-nifty-clojure-app&quot;</span>
<span style="color: #007800;">APP_LONG_NAME</span>=<span style="color: #ff0000;">&quot;Your Nifty Clojure App&quot;</span>
...
<span style="color: #007800;">PIDDIR</span>=<span style="color: #ff0000;">&quot;./&quot;</span></pre></div></div>

<p>Naturally you can change the PIDDIR to write where ever you want or conditionally change it based on the target environment. For starters though just put the PID file where you start the script.</p>
<p>Now go into the src/conf directory and find a file called &#8220;wrapper.conf.in&#8221;. Copy it into the conf folder of daemon directory, and rename it &#8220;wrapper.conf&#8221;.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cp</span> src<span style="color: #000000; font-weight: bold;">/</span>conf<span style="color: #000000; font-weight: bold;">/</span>wrapper.conf.in conf<span style="color: #000000; font-weight: bold;">/</span>wrapper.conf</pre></div></div>

<p>You&#8217;ll to make several edits to the wrapper.conf file. </p>
<p>Begin by telling the wrapper script that it should use the fourth integration method. Specifically it will use the WrapperJarApp as the main method and then subsequently execute your main method.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">...
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperJarApp
...</pre></div></div>

<p>I like to set a reusable variable that sets the path to your application Jar file.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">...
<span style="color: #666666; font-style: italic;"># Reusable path to the main JAR file for your application</span>
set.APP_JAR_PATH=..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>your-nifty-clojure-app.jar
...</pre></div></div>

<p>Now you&#8217;ll need to add your Jar file to the classpath as defined in the wrapper.conf.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Java Classpath (include wrapper.jar)  Add class path elements as</span>
<span style="color: #666666; font-style: italic;">#  needed starting from 1</span>
wrapper.java.classpath.1=..<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>wrapper.jar
wrapper.java.classpath.2=<span style="color: #000000; font-weight: bold;">%</span>APP_JAR_PATH<span style="color: #000000; font-weight: bold;">%</span></pre></div></div>

<p>You should adjust the JVM minimum and maximum heap sizes.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Initial Java Heap Size (in MB)</span>
wrapper.java.initmemory=<span style="color: #000000;">256</span> <span style="color: #666666; font-style: italic;"># Set it to whatever you see fit...</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Maximum Java Heap Size (in MB)</span>
wrapper.java.maxmemory=<span style="color: #000000;">512</span> <span style="color: #666666; font-style: italic;"># Set it to whatever you see fit...</span></pre></div></div>

<p>Lastly, tell the wrapper script what Jar file to execute. These work like command line arguments. If your application requires arguments, feel free to enumerate them</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">...
wrapper.app.parameter.1=<span style="color: #000000; font-weight: bold;">%</span>APP_JAR_PATH<span style="color: #000000; font-weight: bold;">%</span>
<span style="color: #666666; font-style: italic;">#wrapper.app.parameter.2=some argument</span>
<span style="color: #666666; font-style: italic;">#wrapper.app.parameter.3=another argument</span>
...</pre></div></div>

<p>Now you should be able to start,stop, and restart your application using the bin/your-nifty-clojure-app</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>your-nifty-clojure-app start<span style="color: #000000; font-weight: bold;">|</span>stop<span style="color: #000000; font-weight: bold;">|</span>restart</pre></div></div>

<p>Tanuki offers a bunch of other options that I haven&#8217;t even scratched the surface on and they are worth a look. I hope this helps you daemonize your Clojure application!</p>
]]></content:encoded>
			<wfw:commentRss>http://techwhizbang.com/2012/02/clojure-applications-as-daemons/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Short and Sweet Disclojure</title>
		<link>http://techwhizbang.com/2012/01/short-and-sweet-disclojure/</link>
		<comments>http://techwhizbang.com/2012/01/short-and-sweet-disclojure/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 06:32:53 +0000</pubDate>
		<dc:creator>techwhizbang</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[clojure]]></category>
		<category><![CDATA[jvm]]></category>
		<category><![CDATA[lisp]]></category>

		<guid isPermaLink="false">http://techwhizbang.com/?p=516</guid>
		<description><![CDATA[After experimenting and bouncing back and forth on several relatively new languages, I was undecided on what new language I wanted to commit myself to. It wasn&#8217;t until I began reading Clojure in Action that I really started to grok and see through its otherwise intimidating syntax. Admittedly, Clojure just looked and sounded too exotic [...]]]></description>
			<content:encoded><![CDATA[<p>After experimenting and bouncing back and forth on several relatively new languages, I was undecided on what new language I wanted to commit myself to. It wasn&#8217;t until I began reading <em><a href="http://amzn.com/1935182595" title="Clojure in Action" target="_blank">Clojure in Action</a></em> that I really started to grok and see through its otherwise intimidating syntax. Admittedly, Clojure just looked and sounded too exotic at first glance. Do I really want to learn Lisp? Aren&#8217;t those parentheses crazy? Shouldn&#8217;t I be programming the next million dollar idea for the iPhone? </p>
<p>It turns out that the answers to those questions are: Yes. No. What money? </p>
<p>I wanted a challenge. I wanted something that would transcend the way I&#8217;ve been thinking about programming. I wanted something that I knew would make me a better software engineer. I wanted something more expressive and powerful. </p>
<p>Luckily, the past two weeks I&#8217;ve had an excellent opportunity at work to apply and push my learnings of Clojure further. I thought it would be an opportune time to share the good, the bad, and whatever else in between. A reflective and honest &#8220;disclojure&#8221;. </p>
<p>It seems that the best way to learn a new language is finding well documented source code and blogs from likeminded people. Clojure is a &#8220;newer&#8221; burgeoning language so it goes without saying that there are far fewer comprehensive online resources to tap into. The blogosphere is actually a bit sparse on Clojure. I&#8217;d strongly recommend having a couple Clojure e-books at your fingertips for reference. Speaking of books, don&#8217;t expect to learn Clojure by reading a stack of books for 5 months and think that it will magically flow from your digits. It&#8217;ll never ever happen. The best recipe for me has been a 1:1 ratio of time spent reading and coding. If you&#8217;re in pursuit of books that might help you on your quest to learning Clojure, remember Clojure is a Lisp. <em><a href="http://amzn.com/0262560992" title="The Little Schemer" target="_blank">The Little Schemer</a></em> and <em><a href="http://amzn.com/026256100X" title="The Seasoned Schemer" target="_blank">The Seasoned Schemer</a></em> have been priming Lisp programmers for decades. If anything reading these two books will make you hungrier for more, wink wink nudge nudge.</p>
<p>Github has been an invaluable asset when looking for good source code examples. One of the questions I continue to ask myself while coding, &#8220;Is the code I&#8217;m writing idiomatic?&#8221; That is important to me because one of my main objectives is to transcend my thinking and programming style. So before you add that dependency to your <a href="https://github.com/technomancy/leiningen" title="Leiningen" target="_blank">Leiningen</a> project.clj have a peek at the author&#8217;s source. In reality, you might often find yourself sifting through source because of the lack of documentation or examples. Actually I read other developers source code daily for this very reason. So let me re-phrase that, while you&#8217;re trying to figure out how the heck some library or &#8220;clojar&#8221; works, be mindful of the coding style. Undoubtedly you will pick up something useful.</p>
<p>I had a perplexing problem the other day and for the life of me I couldn&#8217;t figure it out. I simply lacked the context necessary that other more advanced Clojure developers have. I found my answer after posting my question on the <a href="http://groups.google.com/group/clojure" title="Clojure Google Groups" target="_blank">Clojure forum</a> hosted on Google Groups. More specifically, I was using lein run to execute a simple database preparation task, but the process was hanging on well after it completed. It wasn&#8217;t until someone informed me that I should use (shutdown-agents) after the task I was running finished because of the way the agent thread pool delays shut down. See my gist <a href="https://gist.github.com/1635837">here</a>. The turn around time on the Clojure forum varies. I think it took 2 or 3 days before my post was moderated and then received a response. Most if not all of the Clojure core developers answer questions in this forum so the responses are of high quality and are super helpful.</p>
<p>Sometimes you&#8217;re totally stuck. Even after using your e-book as a reference and reading the source code it just doesn&#8217;t make sense. Enter <a href="irc://irc.freenode.net/#clojure" title="Clojure IRC" target="_blank">Clojure IRC</a>! During the daytime it is bustling with chatter. Lots of the folks who answer questions on the Clojure forum hang out here too. In my experiences, the community that gathers here is friendly and willing to help. </p>
<p>Clojure is as expressive, powerful, and succinct as advertised. The Java interop with Clojure is about the simplest and cleanest I&#8217;ve seen thus far and that includes JRuby and Scala. I&#8217;m impressed with the clean HTTP API Ring has to offer and using the Clojure JDBC API is really nice. If only JDBC were that easy in Java there would be no need for heavyweight clunky ORMs. In terms of testing, speclj is a pretty awesome testing framework that mirrors Ruby&#8217;s RSpec API. I also have enjoyed rolling my own solutions for things that aren&#8217;t available yet. And one of the most important parts&#8230;it is fast and performs very well under load. I don&#8217;t make these claims falsely either, we ran a load test today at work and we were absolutely thrilled with the response times and throughput. I look forward to posting more about Clojure in the coming weeks. Stay tuned!</p>
]]></content:encoded>
			<wfw:commentRss>http://techwhizbang.com/2012/01/short-and-sweet-disclojure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bright Future for Dynamic Languages</title>
		<link>http://techwhizbang.com/2010/04/bright-future-for-dynamic-languages/</link>
		<comments>http://techwhizbang.com/2010/04/bright-future-for-dynamic-languages/#comments</comments>
		<pubDate>Sat, 10 Apr 2010 20:35:26 +0000</pubDate>
		<dc:creator>techwhizbang</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[clojure]]></category>
		<category><![CDATA[dynamic languages]]></category>
		<category><![CDATA[functional programming]]></category>
		<category><![CDATA[jruby]]></category>
		<category><![CDATA[jvm]]></category>

		<guid isPermaLink="false">http://techwhizbang.com/?p=130</guid>
		<description><![CDATA[I find myself infinitely fascinated by the increasing number of dynamic languages. For many of us dynamic language introduction came by way of Ruby, Python, and/or Javascript. While my fascination with these languages hasn’t ended,  I am more enthralled with dynamic languages whose strength is concurrency and multi-threading. Indeed, these are exciting times and there is a shift happening in the software community. Honestly, who hasn’t bragged on Twitter that they just finished reading the latest book on Clojure, or Erlang? Clearly there is momentum and change in the air. The future of software and computing in the next 10 or 15 years is being shaped and molded with the underlying fundamentals and principles of these languages.]]></description>
			<content:encoded><![CDATA[<p>I find myself fascinated by the increasing popularity of dynamic languages. For many of us dynamic language introduction came by way of Ruby, Python, and/or Javascript. While my fascination with these languages hasn&#8217;t ended, I am more enthralled with dynamic languages whose strength is concurrency. Indeed, these are exciting times and there is a shift happening in the software community. Honestly, who hasn&#8217;t bragged on Twitter that they just finished reading the latest book on Clojure or Erlang? Clearly there is momentum and change in the air. The future of software and computing in the next 10 or 15 years is being shaped and molded with the underlying fundamentals and principles of these languages.</p>
<p>I&#8217;m excited about the evolution happening. There is a higher degree of maturity, professionalism, and most importantly scientific and mathematical infused creativity. We&#8217;ve all heard the anecdotal comparison of a craft like architecture versus software. Yes software as a craft is merely a fetus when compared to architecture. For centuries architecture has used equal parts science and artistry to build some of the most breathtaking sites in the world. I believe the software community has really begun using more scientific and mathematical backed <em>artsy creativity.</em> We must flex both sides of our brains to imagine the crazy, the impossible, and make it reality. I digress&#8230;back to the languages.</p>
<p>Why am I so fascinated? The bottom line is we are evolving and learning.</p>
<ul>
<li>Language composition and leverage</li>
<li>Developer productivity</li>
<li>Functional programming and concurrency</li>
</ul>
<p>Clojure and JRuby both run on the JVM. Undoubtedly there are statistics somewhere showing that Java is one of the most popular languages of our time and it is probably running in your software shop in some capacity. As a result the barrier to entry for integrating and using these new languages has been lowered. It is comparatively easier than the transition when Java gained <em><em>über</em></em> popularity in the 90&#8242;s. However, this isn&#8217;t as important and _fascinating_ as how these languages integrate directly with the Java language. The number of possibilities for composing and leveraging preexisting Java libraries with these languages seems endless. This eliminates many reasons to reinvent a library or API. When you wish you could use some Java component, framework, or API, you can &#8211; easily! I&#8217;ve used this fact to my advantage using JRuby numerous times. The other really neat possibility that I haven&#8217;t messed around with yet is using Clojure in JRuby.</p>
<p>The next reason for my interest is directly related to why Ruby is hot and will remain so for a long time. On a side note, I feel the need to disclose that I am not a Ruby &#8220;fan boy&#8221;, I&#8217;ve spent my time in the ranks wrestling with C and Java and still have an fond appreciation for both. Back to what is important, developer productivity. Here are some of the things these dynamic languages really excel in, while keeping in mind that correlation doesn&#8217;t imply causation:</p>
<ul>
<li>It will make your developers happy to write less elaborate wordy boilerplate code</li>
<li>Writing less boilerplate code usually results in writing more human readable and elegant code (it has been said before that code should be human readable first and just coincidentally interpreted by a machine)</li>
<li>More human readable code can improve maintainability, health, and longevity of the code base</li>
<li>Maintainability can result in greater agility to output more business value</li>
</ul>
<p>Mathematicians have been joking that they&#8217;ve known that functional programming rocks for a pretty long time now. How could they not? Functions are the premise of their craft. It is true they&#8217;ve been using Lisp, Sage, and Python for years. I remember my MCS professors telling us in the late 90&#8242;s and early 2000&#8242;s that we better learn why these languages are kick ass (all the while they were teaching us the principles of OOP with this new language called Java). In fact, I noticed the other day that the new course outlines for MCS students at UIC have plenty of functional programming aspects using Python and Lisp. Sure Python isn&#8217;t a purist&#8217;s functional language, but anything with support for closures will do. Joining the bandwagon, I am trying to get good with Clojure at the moment with the trusty Pragmatic Programming Clojure book at my side. I am not going to lie, it has been tough to wrap my head around this concept (but doesn&#8217;t that generally happen with anything outside your comfort zone?). I would be remiss if I didn&#8217;t mention Erlang or Haskell in the context of popular functional languages. I suppose I could of chosen either one of those. I felt like Clojure was a better fit for me since it runs on the JVM, it&#8217;s dynamic, and the application of my learnings would be easier to integrate at work. So I have written fewer lines of code and as a result things are just concise. I am not sitting there worrying about immutability and concurrency they are just the fruits of my labor. I hope to extract some of the cool ideas out of the O&#8217;Reilly Collective Intelligence book and write them in Clojure.</p>
<p>I&#8217;m definitely stoked about the future with these languages. There is certainly so many possibilities and cool things to come. So the question is what will you be doing with these languages?</p>
]]></content:encoded>
			<wfw:commentRss>http://techwhizbang.com/2010/04/bright-future-for-dynamic-languages/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 0.594 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-05-20 10:23:16 -->

