<?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>Gary Boone, PhD &#187; Coding</title>
	<atom:link href="http://garyboone.com/category/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://garyboone.com</link>
	<description>Clippings, code snippets, and other searchable web notes</description>
	<lastBuildDate>Mon, 21 Jun 2010 20:42:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Fix: Jetty and ScalaObject Not Found</title>
		<link>http://garyboone.com/2010/06/fix-jetty-and-scalaobject-not-found/</link>
		<comments>http://garyboone.com/2010/06/fix-jetty-and-scalaobject-not-found/#comments</comments>
		<pubDate>Mon, 21 Jun 2010 20:42:28 +0000</pubDate>
		<dc:creator>gary</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://garyboone.com/?p=260</guid>
		<description><![CDATA[Working with Vaadin, Jetty, Scala and Eclipse, I&#8217;ve seen intermittent deployment failures in which the web application would fail with a 500 error and

Problem accessing /HomepageDashboard/. Reason:
    scala/ScalaObject
Caused by:
java.lang.NoClassDefFoundError: scala/ScalaObject

The problem is that the scala library files are not being copied correctly into the WEB-INFO/lib directory. This omission can be verified by [...]]]></description>
			<content:encoded><![CDATA[<p>Working with Vaadin, Jetty, Scala and Eclipse, I&#8217;ve seen intermittent deployment failures in which the web application would fail with a 500 error and</p>
<blockquote><p>
Problem accessing /HomepageDashboard/. Reason:</p>
<p>    scala/ScalaObject<br />
Caused by:</p>
<p>java.lang.NoClassDefFoundError: scala/ScalaObject
</p></blockquote>
<p>The problem is that the scala library files are not being copied correctly into the WEB-INFO/lib directory. This omission can be verified by looking into the war file:</p>
<blockquote><p>
jar tvf HomepageDashboard.war
</p></blockquote>
<p>for the content the WEB-INFO/lib directory.</p>
<p>Some suggested fixes, such as checking the scala library in the project&#8217;s &#8220;Java EE Modules Dependencies&#8221; have not worked consistently for me. Instead, the simple solution is to just manually copy the files where they need to go. The files are found inside the Scala distribution jar. Just extract and copy the needed files:</p>
<blockquote><p>
jar xvf scala.library_2.7.7.final.jar<br />
cp lib/scala-dbc.jar lib/scala-library.jar lib/scala-swing.jar WebContent/WEB-INF/lib/
</p></blockquote>
<p>When the eclipse plugin deploys correctly, it copies all three. You probably only need the scala-library.jar.</p>
]]></content:encoded>
			<wfw:commentRss>http://garyboone.com/2010/06/fix-jetty-and-scalaobject-not-found/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SingletonApp: How to run only one application instance at a time in Scala</title>
		<link>http://garyboone.com/2010/02/singletonapp-how-to-allow-only-one-application-instance-at-a-time/</link>
		<comments>http://garyboone.com/2010/02/singletonapp-how-to-allow-only-one-application-instance-at-a-time/#comments</comments>
		<pubDate>Fri, 26 Feb 2010 04:48:00 +0000</pubDate>
		<dc:creator>gary</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://garyboone.com/2010/02/singletonapp-how-to-allow-only-one-application-instance-at-a-time/</guid>
		<description><![CDATA[Here&#8217;s a way to ensure that only one instance of your application runs at a time. Perhaps it updates a resource and you need to prevent duplicate updates. Or, in another use, I recently wanted to make sure an application was always running. So I wrote a cron job to periodically start the program; if [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a way to ensure that only one instance of your application runs at a time. Perhaps it updates a resource and you need to prevent duplicate updates. Or, in another use, I recently wanted to make sure an application was always running. So I wrote a cron job to periodically start the program; if it was already running, the new start failed.</p>
<p>A traditional method for ensure single instances of program uses file locking and PIDs. A program, upon start up, would get its process id (PID) from the OS, then write it to a file called &#8220;program.lock&#8221; in a known, fixed location. Then it would read the file and check the written PID against its own. If they match, great; continue. If they don&#8217;t match, it means that another file succeeded at creating the file, ie got the lock, so this application must shut down. You might think that if the file exists, then no check is necessary. However, the idea is to handle the situation when multiple instances start at nearly identical times. Neither sees the file and tries to create it, but only one succeeds because Unix file creation is atomic.</p>
<p>The traditional method is clever, but challenging to get right. Lock files must be removed on exit, requiring more code. If the program terminates unexpectedly, provisions must be made to catch the exit signal and clean up or use additional methods to reap leftover lockfiles.</p>
<p>Here&#8217;s a much simpler method. Like the traditional method, each application attempts to hold a shared resource. Only one succeeds, and the resource hold is automatically released on program termination. The resource? A OS network port. So the only risk is accidentally choosing a port needed by another application for actual communication.</p>
<p>All you have to do is choose a port to use as an &#8220;application exclusion group id&#8221;. Several applications use the id. But only one application among the group sharing the id can run at a time.</p>
<p>Here&#8217;s the code. Include the file in your program, then call <em>SingletonApp.performSolo</em> as shown in the demo. To demo, just run multiple copies of the file as shown in the comments. Only one will run at a time&#8230;</p>
<pre class="brush: scala;">
import java.net.BindException
import java.net.ServerSocket

/**
 * This class enables applications to ensure that only one instance
 * of the application runs at a time.
 *
 * @author  Gary Boone, PhD
 * @version 1.0, 2010/02/24
 */
object SingletonApp {

	var serverSocket:ServerSocket = null

	/**
	 * Pick a port number to use as the application exclusion
	 * group id. Choose a port that won't conflict with other
	 * applications. See
	 * http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers
	 * for common port numbers.
	 *
	 * Additionally, pass in a closure to be run if the application
	 * is already running.
	 */
	def performSolo( portToHold:Int)( fail: =&gt; Unit ) = {
		try {
			serverSocket = new ServerSocket(portToHold)
		} catch {
		  	case e:BindException =&gt; fail
		}
	}

	/**
	 * Demo the SingletonApp class
	 *
	 * Compile, or run with:
	 * scala -i SingletonApp.scala -e 'SingletonApp.main(null)' &amp;
	 * Then start another instance to see it fail.
	 */
	def main( args:Array[String] ) : Unit = {
		val DEMO_PORT_TO_HOLD = 15486

		// ensure single instance
		SingletonApp.performSolo(DEMO_PORT_TO_HOLD) {
			println(&quot;failing due to already-running instance.&quot;)
			exit
		}

		println(&quot;Application started. Try to start another instance.&quot;)
		Thread.sleep(300000)		// 3e6 ms = 300 sec = 5 min
		println(&quot;exiting&quot;)
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://garyboone.com/2010/02/singletonapp-how-to-allow-only-one-application-instance-at-a-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Instant REST api?</title>
		<link>http://garyboone.com/2009/09/instant-rest-api/</link>
		<comments>http://garyboone.com/2009/09/instant-rest-api/#comments</comments>
		<pubDate>Sat, 05 Sep 2009 01:12:08 +0000</pubDate>
		<dc:creator>gary</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://garyboone.com/2009/09/instant-rest-api/</guid>
		<description><![CDATA[The Jersey package is Sun&#8217;s reference implementation of the JAX-RS standard for RESTful web services. It&#8217;s easy to use; with a few annotations, you&#8217;ll have your own REST api. The examples show how to use the included Grizzly server, allowing you to create embedded servers. That is, instead of fussy XML configurations for the large [...]]]></description>
			<content:encoded><![CDATA[<p style="clear: both">The Jersey package is Sun&#8217;s reference implementation of the JAX-RS standard for RESTful web services. It&#8217;s easy to use; with a few annotations, you&#8217;ll have your own REST api. The examples show how to use the included Grizzly server, allowing you to create embedded servers. That is, instead of fussy XML configurations for the large web servers, you can create small, easily deployable servers that you control via REST calls.</p>
<p style="clear: both">Using eclipse, just create your project, adding the jars required by Jersey. Follow the <a href="https://jersey.dev.java.net/source/browse/*checkout*/jersey/tags/jersey-1.0.3/jersey/getting-started.html">Getting Started</a> guide for an example. </p>
<p style="clear: both">To deploy, you can package your project into a single jar using &#8220;File | Export&#8230;&#8221; Then you can run the jar using </p>
<blockquote style="clear: both"><p>java -Xmx512m -jar MyServer.jar</p>
</blockquote>
<p style="clear: both">where you use -Xmx to make sure your server has enough memory. There&#8217;s just one problem&#8230;</p>
<p style="clear: both">When you run the jar, the program will start up cleanly. But when you hit it with a url, you see</p>
<blockquote style="clear: both"><p>The ResourceConfig instance does not contain any root resource classes.</p>
</blockquote>
<p style="clear: both">followed by some exception. The problem is the server can&#8217;t find your classes. The simple trick is to add your bin directory to your classpath. Use &#8220;Project | Properties | Java Build Path.&#8221; On the Libraries tab, click &#8220;Add External Class Folder&#8230;&#8221; and add the &#8220;bin&#8221; directory in your project root.</p>
<p style="clear: both">Next time you run, you&#8217;ll see</p>
<blockquote style="clear: both"><p>Scanning for root resource and provider classes in the packages:<br /> main<br /> Root resource classes found:<br /> class main.MyClass1Resource<br /> class main.MyClass2Resource<br /> class main.MyClass3Resource<br /> class main.MyClass4Resource</p>
</blockquote>
<p style="clear: both">as the embedded Grizzly server scans the package (&#8221;main&#8221;) you gave it when you initialized it:</p>
<blockquote style="clear: both"><p> initParams.put(&#8221;com.sun.jersey.config.property.packages&#8221;, &#8220;main&#8221;);</p>
</blockquote>
<p style="clear: both">Instant RESTful server, one line deploy. What&#8217;s not to love?</p>
<p style="clear: both">
<p><br class="final-break" style="clear: both" /></p>
]]></content:encoded>
			<wfw:commentRss>http://garyboone.com/2009/09/instant-rest-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scala Books</title>
		<link>http://garyboone.com/2009/06/scala-books/</link>
		<comments>http://garyboone.com/2009/06/scala-books/#comments</comments>
		<pubDate>Sat, 13 Jun 2009 03:54:48 +0000</pubDate>
		<dc:creator>gary</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://garyboone.com/2009/06/scala-books/</guid>
		<description><![CDATA[Programming in Scala is the first of the recent set of Scala books that marks the coming of age of the language. It&#8217;s comprehensive, but readable. 


]]></description>
			<content:encoded><![CDATA[<p style="clear: both"><em>Programming in Scala</em> is the first of the recent set of Scala books that marks the coming of age of the language. It&#8217;s comprehensive, but readable. </p>
<p style="clear: both">
<p><br class="final-break" style="clear: both" /></p>
]]></content:encoded>
			<wfw:commentRss>http://garyboone.com/2009/06/scala-books/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Running Clang Checker</title>
		<link>http://garyboone.com/2009/06/running-clang-checker/</link>
		<comments>http://garyboone.com/2009/06/running-clang-checker/#comments</comments>
		<pubDate>Sun, 07 Jun 2009 22:45:46 +0000</pubDate>
		<dc:creator>gary</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[checker]]></category>
		<category><![CDATA[clang]]></category>

		<guid isPermaLink="false">http://garyboone.com/2009/06/running-clang-checker/</guid>
		<description><![CDATA[There&#8217;s a fantastic iPhone debugging tool in development called Clang Checker. It does deep code analysis and can find memory leaks and other problems by following potential code paths. To use it, just download the package and uncompress it. The CD to your Xcode project directory and run it like:
xcodebuild clean; ~/development/checker-0.210/scan-build -k -V -warn-objc-missing-dealloc [...]]]></description>
			<content:encoded><![CDATA[<p style="clear: both">There&#8217;s a fantastic iPhone debugging tool in development called Clang Checker. It does deep code analysis and can find memory leaks and other problems by following potential code paths. To use it, just <a href="http://clang.llvm.org/StaticAnalysis.html" title="Clang Checker">download</a> the package and uncompress it. The CD to your Xcode project directory and run it like:</p>
<blockquote style="clear: both"><p>xcodebuild clean; ~/development/checker-0.210/scan-build -k -V -warn-objc-missing-dealloc xcodebuild -sdk iphonesimulator2.2</p>
</blockquote>
<p style="clear: both">If you have errors, a nicely formatted webpage opens to shows them. </p>
<p style="clear: both">Other notes:</p>
<p style="clear: both">- Run scan-build &#8211;help to see the other tests you can add in. </p>
<p style="clear: both">- Make the argument to -sdk match one of your SDKs, which you can list via:</p>
<blockquote style="clear: both"><p>xcodebuild -showsdks</p>
</blockquote>
<p style="clear: both">
<p style="clear: both">
<p><br class="final-break" style="clear: both" /></p>
]]></content:encoded>
			<wfw:commentRss>http://garyboone.com/2009/06/running-clang-checker/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
