<?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>undesigned &#187; java</title>
	<atom:link href="http://www.joelduffin.com/blog/category/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.joelduffin.com/blog</link>
	<description>life is a rum go guv’nor, and that’s the truth</description>
	<lastBuildDate>Thu, 30 Sep 2010 07:08:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Getting started with Hadoop on Amazon&#8217;s elastic mapreduce</title>
		<link>http://www.joelduffin.com/blog/2010/09/08/getting-started-with-hadoop-on-amazons-elastic-mapreduce/</link>
		<comments>http://www.joelduffin.com/blog/2010/09/08/getting-started-with-hadoop-on-amazons-elastic-mapreduce/#comments</comments>
		<pubDate>Wed, 08 Sep 2010 15:23:54 +0000</pubDate>
		<dc:creator>joel</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[recommender]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.joelduffin.com/blog/?p=474</guid>
		<description><![CDATA[After playing with Hadoop a bit in the past, I&#8217;m now trying out some things on Amazon&#8217;s Elastic MapReduce.
I signed up for a new AWS account and ran their sample LogAnalyzer Job Flow using the AWS console. That was easy enough. Next I attempted to run the same sample from the command line using the [...]]]></description>
			<content:encoded><![CDATA[<p>After playing with Hadoop a bit in the past, I&#8217;m now trying out some things on <a href="http://aws.amazon.com/elasticmapreduce/">Amazon&#8217;s Elastic MapReduce</a>.</p>
<p>I signed up for a new AWS account and ran their <a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=2440">sample LogAnalyzer Job Flow</a> using the AWS console. That was easy enough. Next I attempted to run the same sample from the command line using the <a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=2264">Amazon Elastic MapReduce Ruby Client</a>.</p>
<p><strong>Note</strong>: The <a href="http://github.com/tc/elastic-mapreduce-ruby/blob/master/README">Ruby Client README</a> turns out to be very helpful.</p>
<p>Next I downloaded the source and looked at. Seems simple enough. I notice that this sample uses a library called <a href="http://www.cascading.org/">Cascading</a>, which appears to be a way to simplify common job flow tasks.</p>
<p>After adding the elastic-mapreduce app to my path and setting up my credentials file, I ran:</p>
<p>elastic-mapreduce &#8211;create &#8211;jar  s3n://elasticmapreduce/samples/cloudfront/logprocessor.jar &#8211;args  &#8220;-input,s3n://elasticmapreduce/samples/cloudfront/input,-output,s3n://folksemantic.com/cloudfront/log-reports,-start,any,-end,2010-09-07-21,-timeBucket,300,-overallVolumeReport&#8221;</p>
<p>It produced:</p>
<p>INFO Exception Retriable invalid response returned from RunJobFlow: {&#8221;Error&#8221;=&gt;{&#8221;Details&#8221;=&gt;#&lt;SocketError: getaddrinfo: nodename nor servname provided, or not known&gt;, &#8220;Code&#8221;=&gt;&#8221;InternalFailure&#8221;, &#8220;Type&#8221;=&gt;&#8221;Sender&#8221;}} while calling RunJobFlow on Amazon::Coral::ElasticMapReduceClient, retrying in 3.0 seconds.</p>
<p>After some poking around, I realized that I specified &#8220;west-1&#8243; as my region when it should have been &#8220;us-west-1&#8243;. This resulted in the client trying to contact a non-existent server I&#8217;m guessing.</p>
<p>So now, my jobs started, but failed immediately. I logged into the AWS console and clicked on one of the failed job flows to see the reason for the failure (Last State Change Reason):</p>
<p><span>The given SSH key name was invalid</span></p>
<p><span>Googling found: </span>http://developer.amazonwebservices.com/connect/message.jspa?messageID=166768</p>
<p>Which at first confused me, then I went ahead and followed <a href="https://console.aws.amazon.com/ec2/home#c=EC2&amp;s=KeyPairs">the link</a> (while logged in) and did what it said to. (Amazing how that works sometimes <img src='http://www.joelduffin.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> ) It prompted me to create a new key and to assign it a name.</p>
<p>After I had generated the key and put its name in the credentials.json, things worked like a charm. It turns out that if you run a job from scratch, it has to fire up an EC2 instance in order to run the job, and that can take a while. To avoid that start up time, you can run:</p>
<p>elastic-mapreduce &#8211;create &#8211;alive &#8211;log-uri s3://my-example-bucket/logs</p>
<p>As mentioned in the README.TXT</p>
<p>My next steps are to:</p>
<ol>
<li>Modify the job flow and run that job flow.</li>
<li>Run the job flow locally.</li>
<li>Debug the MapReduce portion of the job flow.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.joelduffin.com/blog/2010/09/08/getting-started-with-hadoop-on-amazons-elastic-mapreduce/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Configuring Apache and Tomcat to serve my java web application through port 80</title>
		<link>http://www.joelduffin.com/blog/2010/08/16/configuring-apache-and-tomcat-to-serve-my-java-web-application-through-port-80/</link>
		<comments>http://www.joelduffin.com/blog/2010/08/16/configuring-apache-and-tomcat-to-serve-my-java-web-application-through-port-80/#comments</comments>
		<pubDate>Mon, 16 Aug 2010 14:15:33 +0000</pubDate>
		<dc:creator>joel</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.joelduffin.com/blog/?p=445</guid>
		<description><![CDATA[Default Tomcat installations run on port 8080 so you get urls like:
http://mydomain.com:8080/lms/index.jsp
Some firewalls block port 8080 so I wanted my site to be available on port 80 so that it uses urls like:
http://mydomain.com/lms/index.jsp.
One option was to modify the Tomcat configuration to listen on port 80. However, I already have Apache installed and listening on port [...]]]></description>
			<content:encoded><![CDATA[<p>Default Tomcat installations run on port 8080 so you get urls like:</p>
<pre>http://mydomain.com:8080/lms/index.jsp</pre>
<p>Some firewalls block port 8080 so I wanted my site to be available on port 80 so that it uses urls like:</p>
<pre>http://mydomain.com/lms/index.jsp.</pre>
<p>One option was to modify the Tomcat configuration to listen on port 80. However, I already have Apache installed and listening on port 80 (to serve other content) so I couldn&#8217;t that. Instead I configured Apache to route requests for my web application to Tomcat. I&#8217;ve been through this process a number of times before, and it never seems to go smoothly, so I document it here. I am running Apache 2.2 and Tomcat 6 on 32 bit Ubuntu Linux.</p>
<h2>Overview</h2>
<p>The steps are:</p>
<ol>
<li>Download the Apache jk connector module (mod_jk.so).</li>
<li>Create Apache module configuration files for the jk connector (jk.load and jk.conf) and enable the module.</li>
<li>Create a worker.properties file to configure the Tomcat worker for the connector.</li>
<li>Define an AJP connector in your Tomcat configuration file (server.xml)</li>
<li>Assign urls to Tomcat in your Apache virtual hosts file.</li>
</ol>
<h2>Download the Apache jk connector module (mod_jk.so)</h2>
<p>Apache uses the jk connector module to talk to Tomcat. I downloaded it from a subdirectory of <a href="http://www.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/">http://www.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/</a>. I wasn&#8217;t sure which OS I was running and whether or not I was running a 32 bit version (i586 directory) or a 64 bit version (x86_64). To find this out, I ran:</p>
<pre>file /usr/bin/file
/usr/bin/file: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped</pre>
<pre><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;">So I downloaded: <a href="http://www.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/linux/jk-1.2.28/i586/mod_jk-1.2.28-httpd-2.2.X.so">http://www.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/linux/jk-1.2.28/i586/mod_jk-1.2.28-httpd-2.2.X.so</a></span></pre>
<p>I chose that version because I am running Apache 2.2. There are different versions for different versions of Apache.</p>
<p>I put the file in my Apache modules directory (/usr/lib/apache2/modules/) and renamed it to mod_jk.so.</p>
<h2>Create Apache module configuration files for the jk connector (jk.load and jk.conf) and enable the module</h2>
<p>In order to get Apache to load and configure the jk connector module, I created jk.load and jk.conf files (in /etc/apache2/mods-available/) and then enabled them. jk.load just tells Apache where to find the module:</p>
<pre>LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so</pre>
<p>jk.conf ties everything together by configuring the jk connector module:</p>
<pre># Where to find workers.properties
# Update this path to match your conf directory location (put workers.properties next to httpd.conf)
JkWorkersFile /etc/apache2/workers.properties

# Where to put jk shared memory
# Update this path to match your local state directory or logs directory
JkShmFile     /var/log/apache2/mod_jk.shm

# Where to put jk logs
# Update this path to match your logs directory location (put mod_jk.log next to access_log)
JkLogFile     /var/log/apache2/mod_jk.log

# Set the jk log level [debug/error/info]
JkLogLevel    info

# Select the timestamp log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "</pre>
<p>For more information about the Apache jk connector module configuration, see the <a href="http://tomcat.apache.org/connectors-doc/webserver_howto/apache.html">Tomcat Connector &#8211; Apache Webserver HowTo</a>.</p>
<p>Initially I set the JkLogLevel to debug, so I could see any error messages, but then changed it to info once I had everything working.</p>
<p>After creating the files, I enabled the module using:</p>
<pre>sudo a2enmod jk</pre>
<p>That creates symlinks to the jk.load and jk.conf files in the mods-enabled directory where my Apache is configured to look for modules to load.</p>
<h2 style="font-size: 1.5em;">Define an AJP connector in your Tomcat configuration file (server.xml)</h2>
<p>AJP is an efficient protocol that Apache and Tomcat can be configured to use to talk to each other. I set up an AJP connector in my Tomcat configuration file (/etc/tomcat6/server.xml). The default configuration file has the connector defined but commented out, so I uncommented it:</p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;!&#8211; Define an AJP 1.3 Connector on port 8009 &#8211;&gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;Connector port=&#8221;8009&#8243; protocol=&#8221;AJP/1.3&#8243; redirectPort=&#8221;8443&#8243; /&gt;</div>
<pre style="font: normal normal normal 12px/18px Consolas, Monaco, 'Courier New', Courier, monospace;">&lt;!-- Define an AJP 1.3 Connector on port 8009 --&gt;
&lt;Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /&gt;</pre>
<p>For details see the <a href="http://tomcat.apache.org/tomcat-6.0-doc/config/ajp.html">Tomcat AJP Connector documentation</a>.</p>
<h2 style="font-size: 1.5em;">Create a worker.properties file to configure the Tomcat ajp worker for the connector</h2>
<p>&#8220;A <strong>Tomcat worker </strong>is a Tomcat instance that is waiting to execute servlets or any other content on behalf of some web server&#8221;.</p>
<p><em>Note: this quote from the documentation is a bit curious, because, nowhere in the Tomcat configuration files do I tell Tomcat about the worker. I think that the worker is actually a process that the jk connector spawns</em>.</p>
<p>I configured a worker to listen to Apache requests by creating a worker.properties file in the same directory as the Apache configuration file (/etc/apache2/workers.properties).</p>
<pre style="font: normal normal normal 12px/18px Consolas, Monaco, 'Courier New', Courier, monospace;"># Define 1 real worker using ajp13
worker.list=worker1

# Set properties for worker1 (ajp13)
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009</pre>
<p>The jk connector knows how to talk to this worker, because the file name is specified in the Apache jk connector configuration file (/etc/apache2/mods-available/jk.conf). For more information see the <a href="http://tomcat.apache.org/connectors-doc/generic_howto/quick.html">Tomcat Connector Quick Start</a> or the <a href="http://tomcat.apache.org/connectors-doc/reference/workers.html">Tomcat Connector Reference Guide</a>.</p>
<h2>Assign urls to Tomcat in your Apache virtual hosts file</h2>
<p>After I configured a Tomcat worker to listen to AJP requests and configured Apache to use the jk connector module to talk to that worker, the last thing that was needed was to configure my web site&#8217;s virtual host (/etc/apache2/sites-available/default) to route urls to Tomcat:</p>
<pre>&lt;VirtualHost *:80&gt;
...
        JkMount /lms/* worker1
...
&lt;/VirtualHost&gt;</pre>
<p>Note that <em>worker1</em> is the name I gave to the worker I set up in the workers.properties file. Note that by using a * mask, I routed all requests (including static files) through Tomcat. Alternatively I could have configured only jsp requests to be routed to Tomcat, using:</p>
<pre>&lt;VirtualHost *:80&gt;
...
        JkMount /lms/*.jsp worker1
...
&lt;/VirtualHost&gt;</pre>
<div>I would then have needed added Directory configurations to the virtual host telling Apache where to serve the static files from.</div>
<h2>Restart Tomcat and Apache</h2>
<div>Of course, after I had done all of this, I had to restart Tomcat and Apache:</div>
<pre>sudo /etc/init.d/tomcat6 restart
sudo /etc/init.d/apache2 restart</pre>
<h2>Lifecycle</h2>
<p>To the best of my understanding, the relevant lifecycle is:</p>
<ol>
<li>When Tomcat starts up, it begins listening for AJP requests on port 8009 (because the connector is defined in /etc/tomcat6/server.xml).</li>
<li>When Apache starts up, it loads the jk connector module (because it is defined in /etc/apache2/mods-enabled/jk.load).</li>
<li>When Apache loads the jk connector, its configuration file (/etc/apache2/mods-enabled/jk.conf) tells it to send requests to the specified Tomcat worker and to use shared memory to do that.</li>
<li>It is not clear to me whether or not the Tomcat worker gets spawned when Apache starts up or on each request. I don&#8217;t see how it could get spawned when Tomcat starts up since Tomcat has no way of knowing about it.</li>
<li>Apache receives a request for a url that is mapped to Tomcat (in the virtual host file &#8211; /etc/apache2/sites-enabled/default).</li>
<li>Apache uses the jk connector module (mod_jk.so) to generate a request to send to Tomcat via a Tomcat worker.</li>
<li>The Tomcat worker communicates with Tomcat using the protocol (AJP) and port (8009) defined in the workers configuration file (/etc/apache2/workers.properties).</li>
<li>Tomcat processes the request and returns the response back through the worker and connector to Apache which returns it to the client.</li>
</ol>
<p>Kind of complicated, huh? And of course, this is just my best guess.</p>
<h2>Questions and problems</h2>
<div>The questions / problems I ran into this time I went through this process were:</div>
<div>
<ul>
<li>Not knowing which version of the JK connector to download</li>
<li>Forgetting I needed to configure the AJP connector in the Tomcat configuration file</li>
<li>Initially I routed only requests for JSP pages to Tomcat and so my stylesheets and images did not show up</li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.joelduffin.com/blog/2010/08/16/configuring-apache-and-tomcat-to-serve-my-java-web-application-through-port-80/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mixing AWT and Swing is No Fun!</title>
		<link>http://www.joelduffin.com/blog/2008/04/03/mixing-awt-and-swing-is-no-fun/</link>
		<comments>http://www.joelduffin.com/blog/2008/04/03/mixing-awt-and-swing-is-no-fun/#comments</comments>
		<pubDate>Thu, 03 Apr 2008 15:25:53 +0000</pubDate>
		<dc:creator>joel</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[nlvm]]></category>

		<guid isPermaLink="false">http://www.joelduffin.com/blog/2008/04/03/mixing-awt-and-swing-is-no-fun/</guid>
		<description><![CDATA[A couple of years ago I wrote the NLVM Application using Java Swing 1.4. It incorporates the Interactive Math Applets from the NLVM Website. The challenge was that those applets were written based on framework built back in the bronze ages when Netscape on Mac 8 was used heavily in the schools. At that time [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.joelduffin.com/blog/wp-content/uploads/2008/04/argh1.jpg"><img class="alignright size-medium wp-image-63" title="Argh!" src="http://www.joelduffin.com/blog/wp-content/uploads/2008/04/argh1.jpg" alt="" width="300" height="225" /></a>A couple of years ago I wrote the <a href="http://www.mattimath.com/download.asp">NLVM Application</a> using <a href="http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/package-summary.html">Java Swing 1.4</a>. It incorporates the <a href="http://nlvm.usu.edu/">Interactive Math Applets from the NLVM Website</a>. The challenge was that those applets were written based on framework built back in the bronze ages when Netscape on Mac 8 was used heavily in the schools. At that time I Googled around to figure out <a href="http://java.sun.com/products/jfc/tsc/articles/mixing/">how to mix Swing and AWT</a>. I decided to ignore <a href="http://www.google.com/search?hl=en&amp;rlz=1B3GGGL_enUS244US244&amp;q=don%27t+mix+swing+awt&amp;btnG=Search">the warnings</a> because of the large code base and eventually got it to work.</p>
<p>This past week I began updating the NLVM Application to support switching between multiple languages. On the screen that displays applets I added a <a href="http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JComboBox.html">JComboBox</a> below the applet containing a list of languages that a user can select. Everything seemed to work fine until I noticed that once I clicked on the list box the applets stopped updating. After much <a href="http://en.wikipedia.org/wiki/Pain_and_suffering">pain and suffering</a> and digging through the Swing source code I figured out the problem:</p>
<p>When JComboBox gets focus it (via javax.swing.plaf.basic.BasicPopupMenuUI.grabContainer) calls addMouseListener, addMouseMotionListener, and addMouseWheelListener on the applet, which are implemented in <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Component.html">java.awt.Component</a>. This is where the problems begin. All of those methods contain an innocuous line:</p>
<p><code>newEventsOnly = true;</code></p>
<p>There is the evil. The effect of this flag being set bears fruit in java.awt.Component.dispatchEventImpl where there is a set of nested if statements that begins:</p>
<p><code>if (newEventsOnly) {<br />
if (eventEnabled(e)) {<br />
processEvent(e);<br />
}<br />
}<br />
...<br />
</code><br />
The result is that none of the old AWT events (that the applets depend on) are sent after one of those listeners is added and the flag is set. It turns out, there are more methods that set the flag as well: addComponentListener, addFocusListener, addHierarchyListener, addHierarchyBoundsListener, addKeyListener, and addInputMethodListener, but the JComboBox never calls those methods.</p>
<p>My simple hack was to override those addXXXListener methods in my base class to prevent the calls from reaching down into Component where the flag gets set.  I did this by writing a new J14Applet base class which extends java.applet.Applet and extending my former J10Applet base class from J14Applet instead of Applet. I&#8217;m sure this may have side effects but it seems to work fine for now.</p>
<p>As to why JComboBox was adding those listeners in the first place? I think it is so it can handle mouse messages when it has the focus but the mouse is not over the component, so I have defeated that behavior, but I can live with it. It is not as clean a hack as I would like because I want to be able to compile the applets for running on machines that don&#8217;t have a 1.4+ JVM. It would be nice to be able to have my Swing app <a href="http://www.ruby-lang.org/en/">dynamically add those methods like you can do in Ruby</a>, but I don&#8217;t quickly see how to do that. For now, I will just change what J10Applet extends depending on what target I&#8217;m compiling for.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joelduffin.com/blog/2008/04/03/mixing-awt-and-swing-is-no-fun/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Configuring Mathlets</title>
		<link>http://www.joelduffin.com/blog/2003/09/16/configuring-mathlets/</link>
		<comments>http://www.joelduffin.com/blog/2003/09/16/configuring-mathlets/#comments</comments>
		<pubDate>Tue, 16 Sep 2003 21:00:01 +0000</pubDate>
		<dc:creator>joel</dc:creator>
				<category><![CDATA[authoring tools]]></category>
		<category><![CDATA[interactive online math]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[dissertation]]></category>
		<category><![CDATA[enlvm]]></category>

		<guid isPermaLink="false">http://www.joelduffin.com/blog/2003/09/16/configuring-mathlets/</guid>
		<description><![CDATA[I&#8217;ve been re reading Lite Applets at Joma and looking at the Java Components for Mathematics website and imagining that I could quickly make those applets configurable from within TADRIOLA. It shouldn&#8217;t take much and I believe it will make teacher use of those mathlets much more likely.
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been re reading <a href="http://web.archive.org/web/20040108084548/http://www.joma.org/vol2/articles/wattenberg/JOMA_article/wattenberg1.html">Lite Applets</a> at Joma and looking at the <a href="http://web.archive.org/web/20040108084548/http://math.hws.edu/javamath/">Java Components for Mathematics</a> website and imagining that I could quickly make those applets configurable from within TADRIOLA. It shouldn&#8217;t take much and I believe it will make teacher use of those mathlets much more likely.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joelduffin.com/blog/2003/09/16/configuring-mathlets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

