<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Development Etc.</title>
	<atom:link href="http://markjgreene.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://markjgreene.wordpress.com</link>
	<description>"Maybe it's about time I expanded the realm of possibilities around here." - MacGyver</description>
	<lastBuildDate>Tue, 23 Nov 2010 04:06:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='markjgreene.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Development Etc.</title>
		<link>http://markjgreene.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://markjgreene.wordpress.com/osd.xml" title="Development Etc." />
	<atom:link rel='hub' href='http://markjgreene.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Iterate over entire Cassandra column family</title>
		<link>http://markjgreene.wordpress.com/2010/05/05/iterate-over-entire-cassandra-column-family/</link>
		<comments>http://markjgreene.wordpress.com/2010/05/05/iterate-over-entire-cassandra-column-family/#comments</comments>
		<pubDate>Thu, 06 May 2010 01:27:59 +0000</pubDate>
		<dc:creator>MG</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cassandra]]></category>
		<category><![CDATA[hector]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[NoSQL]]></category>

		<guid isPermaLink="false">http://markjgreene.wordpress.com/?p=217</guid>
		<description><![CDATA[I&#8217;m in the middle of implementing a Cassandra persistence adapter for ActiveMQ and one of the requirements is to recover all the messages. This of course means I need to iterate over all the keys in a Column Family. I&#8217;m going to show how to do this in Cassandra using the Hector client. This example [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=markjgreene.wordpress.com&amp;blog=6034167&amp;post=217&amp;subd=markjgreene&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m in the middle of implementing a Cassandra persistence adapter for ActiveMQ and one of the requirements is to recover all the messages. This of course means I need to iterate over all the keys in a Column Family. I&#8217;m going to show how to do this in Cassandra using the Hector client. This example code has also been given to the Hector project on github because it&#8217;s all about spreading the love!</p>
<pre>package example.hector;

import static me.prettyprint.cassandra.utils.StringUtils.bytes;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import me.prettyprint.cassandra.service.CassandraClient;
import me.prettyprint.cassandra.service.CassandraClientPool;
import me.prettyprint.cassandra.service.CassandraClientPoolFactory;
import me.prettyprint.cassandra.service.Keyspace;
import me.prettyprint.cassandra.service.PoolExhaustedException;

import org.apache.cassandra.thrift.Column;
import org.apache.cassandra.thrift.ColumnParent;
import org.apache.cassandra.thrift.ColumnPath;
import org.apache.cassandra.thrift.SlicePredicate;

/**
 * Simple example showing how to iterate over an entire column family. This will work even with
 * the Random Partitioner but be aware that you will of course, get results in an unordered manner.
 * @author mark j greene
 */
public class IterateExample {

public IterateExample() {
}

private void iterateEntireColumnFamily(CassandraClient client, Keyspace ks, ColumnParent cp,
				SlicePredicate sp, String start, String end, int rowFetchSize) throws Exception {

	// get all the keys with a limit of rowFetchSize values returned
	Map&lt;String, List&lt;Column&gt;&gt; results = this.fetchPagedResults(ks, cp, sp, start, end, rowFetchSize);

	Iterator&lt;String&gt; i = results.keySet().iterator();
	while (i.hasNext()) {
		String key = i.next();
		List&lt;Coulmn&gt; c = results.get(key);

		//check for tombstones
		if (c.isEmpty()) {
			System.out.println("Column is null for key: " + key);
		} else {
			//key was found, print to console
			System.out.println(key + " -&gt; " + new String(results.get(key).get(0).getValue()));
		}

		if(!i.hasNext()) {
			System.out.println("This page has run out, getting more results from key: " + key);

			//we've run out of results in this page, get more
			results = this.fetchPagedResults(ks, cp, sp, key, "", rowFetchSize);

			String inclusiveStart = results.keySet().iterator().next();
			System.out.println("Removing inclusive start key: " + inclusiveStart);

			//remove the inclusive start key from the results
			results.remove(inclusiveStart);
			Set&lt;String&gt; keySet = results.keySet();

			//if more results were found, replace the iterator
			if(keySet.size() &gt; 0) {
				i = keySet.iterator();
			}
		}
	}
}

private Map&lt;String, List&lt;Column&gt;&gt; fetchPagedResults( Keyspace ks, ColumnParent cp,
		SlicePredicate sp, String start, String end, int rowFetchSize ) throws Exception {

	 Map&lt;String, List&lt;Column&gt;&gt; results = ks.getRangeSlice(cp, sp, start, end, rowFetchSize);		

	return results;
}

public void setupAndIterate() throws Exception {
	CassandraClientPool pool = CassandraClientPoolFactory.INSTANCE.get();
	CassandraClient client = pool.borrowClient("localhost", 9160);

	try {
		Keyspace ks = client.getKeyspace("Keyspace1");

		// just look for one column for now
		List&lt;byte[]&gt; colNames = new ArrayList&lt;byte[]&gt;();
		colNames.add("column-name".getBytes());

		// setup the slice predicate
		SlicePredicate sp = new SlicePredicate();
		sp.setColumn_names(colNames);

		// setup column parent
		ColumnParent cp = new ColumnParent("Standard3");

		this.iterateEntireColumnFamily(client, ks, cp, sp, "", "", 5);
	} finally {
		if (pool != null) {
			pool.releaseClient(client);
		}
	}

}

public static void main(String[] args) throws IllegalStateException, PoolExhaustedException, Exception {
	IterateExample dao = new IterateExample();
	dao.setupAndIterate();
}
}</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/markjgreene.wordpress.com/217/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/markjgreene.wordpress.com/217/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/markjgreene.wordpress.com/217/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/markjgreene.wordpress.com/217/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/markjgreene.wordpress.com/217/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/markjgreene.wordpress.com/217/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/markjgreene.wordpress.com/217/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/markjgreene.wordpress.com/217/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/markjgreene.wordpress.com/217/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/markjgreene.wordpress.com/217/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/markjgreene.wordpress.com/217/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/markjgreene.wordpress.com/217/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/markjgreene.wordpress.com/217/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/markjgreene.wordpress.com/217/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=markjgreene.wordpress.com&amp;blog=6034167&amp;post=217&amp;subd=markjgreene&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://markjgreene.wordpress.com/2010/05/05/iterate-over-entire-cassandra-column-family/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">MG</media:title>
		</media:content>
	</item>
		<item>
		<title>Range Slices In Cassandra With Hector</title>
		<link>http://markjgreene.wordpress.com/2010/05/05/range-slices-in-cassandra-with-hector/</link>
		<comments>http://markjgreene.wordpress.com/2010/05/05/range-slices-in-cassandra-with-hector/#comments</comments>
		<pubDate>Thu, 06 May 2010 00:35:10 +0000</pubDate>
		<dc:creator>MG</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cassandra]]></category>
		<category><![CDATA[hector]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[NoSQL]]></category>

		<guid isPermaLink="false">http://markjgreene.wordpress.com/?p=199</guid>
		<description><![CDATA[I thought I&#8217;d write up a simple tutorial on how do a simple range slice in Cassandra with Hector for people coming from the relational world. I&#8217;m going to outline the Cassandra version of SELECT col_name_1 FROM table_name LIMIT 100 Step 1) Setup the connection pool and the client CassandraClientPool pool = CassandraClientPoolFactory.INSTANCE.get(); CassandraClient client [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=markjgreene.wordpress.com&amp;blog=6034167&amp;post=199&amp;subd=markjgreene&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I thought I&#8217;d write up a simple tutorial on how do a simple range slice in Cassandra with Hector for people coming from the relational world. </p>
<p>I&#8217;m going to outline the Cassandra version of SELECT col_name_1 FROM table_name LIMIT 100 </p>
<p><strong>Step 1) Setup the connection pool and the client</strong></p>
<pre>
CassandraClientPool pool = CassandraClientPoolFactory.INSTANCE.get();
CassandraClient client = pool.borrowClient("localhost", 9160);
</pre>
<p><strong>Step 2) Define which Keyspace you want to use. This is equivalent to which DB or Schema.</strong></p>
<pre>
Keyspace keyspace = client.getKeyspace("Keyspace1");
</pre>
<p><strong>Step 3) Setup the slice predicate by defining which columns within the row you want returned. This is equivalent to SELECT col_name_1</strong></p>
<pre>
// just look for one column for now
List&lt;byte[]&gt; colNames = new ArrayList&lt;byte[]&gt;();
colNames.add("column-name".getBytes());

// setup the slice predicate
SlicePredicate sp = new SlicePredicate();
sp.setColumn_names(colNames);
</pre>
<p><strong>Step 4) Specify which Column Family to use. This is equivalent to a table or FROM table_name in SQL</strong></p>
<pre>
// setup column parent (CF)
ColumnParent cp = new ColumnParent("Standard3");
</pre>
<p><strong>Step 5) Execute the request. This is equivalent to executing a SQL query.</strong></p>
<pre>
// get all the keys with a limit of 100 values returned
Map&lt;String, List&lt;Column&gt;&gt; map = keyspace.getRangeSlice(cp, sp, "", "", 100);
</pre>
<p>Note that the 3rd and 4th method args are empty strings. When you combine two empty strings for the start and end range, it is like saying SELECT col_name_1 FROM table_name without a WHERE clause.<br />
Also if you have records that were deleted, the List of Column objects will be empty but the key will still be returned until is GC&#8217;d by Cassandra. </p>
<p>This example was used against a single Cassandra node using the Random Partitioner. Results will be returned to you in an unordered fashion.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/markjgreene.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/markjgreene.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/markjgreene.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/markjgreene.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/markjgreene.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/markjgreene.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/markjgreene.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/markjgreene.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/markjgreene.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/markjgreene.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/markjgreene.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/markjgreene.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/markjgreene.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/markjgreene.wordpress.com/199/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=markjgreene.wordpress.com&amp;blog=6034167&amp;post=199&amp;subd=markjgreene&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://markjgreene.wordpress.com/2010/05/05/range-slices-in-cassandra-with-hector/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">MG</media:title>
		</media:content>
	</item>
		<item>
		<title>Durability With Cassandra</title>
		<link>http://markjgreene.wordpress.com/2010/04/10/durability-with-cassandra/</link>
		<comments>http://markjgreene.wordpress.com/2010/04/10/durability-with-cassandra/#comments</comments>
		<pubDate>Sat, 10 Apr 2010 17:10:07 +0000</pubDate>
		<dc:creator>MG</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cassandra]]></category>
		<category><![CDATA[NoSQL]]></category>

		<guid isPermaLink="false">http://markjgreene.wordpress.com/?p=148</guid>
		<description><![CDATA[After an RTFM fail pointed out by Project Chair Jonathan Ellis about how Cassandra handles durability I thought I&#8217;d share what I learned. In a single node configuration by default, Cassandra will not immediately fsync() your write to the commit log from buffer cache to disk. I discovered this (thanks to Jon via the users [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=markjgreene.wordpress.com&amp;blog=6034167&amp;post=148&amp;subd=markjgreene&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After an RTFM fail pointed out by Project Chair Jonathan Ellis about how Cassandra handles durability I thought I&#8217;d share what I learned.</p>
<p>In a single node configuration by default, Cassandra will not immediately <a href="http://linux.die.net/man/2/fsync"><em>fsync()</em></a> your write to the commit log from buffer cache to disk. I discovered this (thanks to Jon via the users mailing list) when I was trying to do an insert and immediately tried to shutdown Cassandra and start it again. What I found was if I did that within a second or two, Cassandra&#8217;s commit log did not have my insert. If I waited around 5-10 seconds before shutting it down it did. So if you see this behavior this is what is happening. Now, a single node configuration for production is not desirable but I think it&#8217;s worth blogging about because it&#8217;s a common configuration for someone who is just hacking around and evaluating Cassandra for the first time. </p>
<p>Cassandra will let you achieve guaranteed durability for the commit log if you want. You can change this by changing &#8220;CommitLogSync&#8221; from periodic to batch and setting &#8220;CommitLogSyncBatchWindowInMS&#8221; to an appropriate number. This will obviously come with performance trade offs but at least you get to pick what is right for you. Also, if you are running a multi node configuration this may not be needed, assuming you are doing replication for your writes as Cassandra won&#8217;t acknowledge the write until that replication has finished. By doing this you virtually eliminate the effects of a hard system crash and can relax the durability of commit log writes for individual nodes.</p>
<p>Cassandra Durability Wiki: <a href="http://wiki.apache.org/cassandra/Durability">http://wiki.apache.org/cassandra/Durability</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/markjgreene.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/markjgreene.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/markjgreene.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/markjgreene.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/markjgreene.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/markjgreene.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/markjgreene.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/markjgreene.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/markjgreene.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/markjgreene.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/markjgreene.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/markjgreene.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/markjgreene.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/markjgreene.wordpress.com/148/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=markjgreene.wordpress.com&amp;blog=6034167&amp;post=148&amp;subd=markjgreene&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://markjgreene.wordpress.com/2010/04/10/durability-with-cassandra/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">MG</media:title>
		</media:content>
	</item>
		<item>
		<title>Troubleshooting Hung Systems: Spiked CPU</title>
		<link>http://markjgreene.wordpress.com/2009/12/11/troubleshooting-hung-systems-spiked-cpu/</link>
		<comments>http://markjgreene.wordpress.com/2009/12/11/troubleshooting-hung-systems-spiked-cpu/#comments</comments>
		<pubDate>Sat, 12 Dec 2009 00:01:12 +0000</pubDate>
		<dc:creator>MG</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[High CPU]]></category>
		<category><![CDATA[Hung System]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JBoss]]></category>
		<category><![CDATA[Thread Dump]]></category>
		<category><![CDATA[Thread Hang]]></category>
		<category><![CDATA[Thread Hung]]></category>

		<guid isPermaLink="false">http://markjgreene.wordpress.com/?p=121</guid>
		<description><![CDATA[First off I wanted to thank Filip Hanik. He illustrated this technique in a presentation at SpringOne this year in New Orleans. I happened to actually give a similar presentation to my fellow engineers at my current employer. The goal here is to figure out using the top command in linux combined with thread dumps [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=markjgreene.wordpress.com&amp;blog=6034167&amp;post=121&amp;subd=markjgreene&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>First off I wanted to thank Filip Hanik. He illustrated this technique in a presentation at SpringOne this year in New Orleans. I happened to actually give a similar presentation to my fellow engineers at my current employer.</p>
<p>The goal here is to figure out using the top command in linux combined with thread dumps to figure out which thread and java code is consuming CPU resources. Below is a step by step walk through on how to accomplish this.</p>
<h2>Step 1</h2>
<p>Execute top command to determine the process id (PID) for the JBoss server. It will be listed under “java”</p>
<p><img class="alignleft" src="http://markjgreene.files.wordpress.com/2009/12/step1.png?w=576&#038;h=176" alt="Add an Image" width="576" height="176" /></p>
<h2></h2>
<h2></h2>
<h2></h2>
<h2></h2>
<h2></h2>
<h2></h2>
<h2>Step 2</h2>
<p>Run the top command to show only the threads associated with the java process.<br />
Execute top –H –p PID<br />
(In this example the PID is 10937)</p>
<p><img src="http://markjgreene.files.wordpress.com/2009/12/step2a.png?w=318&#038;h=25" alt="Add an Image" width="318" height="25" /></p>
<p><img src="http://markjgreene.files.wordpress.com/2009/12/step2b.png?w=576&#038;h=157" alt="Add an Image" width="576" height="157" /></p>
<h2>Step 3</h2>
<p>Execute kill -3<br />
to obtain a stack trace  (In this example the PID is 10937)<br />
<em>Note: You can also utilize the dump stack capability in the JBoss JMX Console under the ServerInfo MBean</em></p>
<p><img src="http://markjgreene.files.wordpress.com/2009/12/step3.png?w=330&#038;h=22" alt="Add an Image" width="330" height="22" /></p>
<h2>Step 4</h2>
<p>Take the PID of the thread you want to correlate and convert it to hex using calc on Windows.<br />
<img src="http://markjgreene.files.wordpress.com/2009/12/step4a.png?w=477&#038;h=313" alt="Add an Image" width="477" height="313" /></p>
<p><img src="http://markjgreene.files.wordpress.com/2009/12/step4b.png?w=478&#038;h=315" alt="Add an Image" width="478" height="315" /></p>
<h2>Step 5</h2>
<p>Open the log file and do a search for the hex representation (native ID) of the thread ID. In this example it will be “<strong>2ae1</strong>”</p>
<p><img src="http://markjgreene.files.wordpress.com/2009/12/step5.png?w=571&#038;h=155" alt="Add an Image" width="571" height="155" /></p>
<p>This effectively tells you the line of code that is responsible for consuming the CPU resources.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/markjgreene.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/markjgreene.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/markjgreene.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/markjgreene.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/markjgreene.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/markjgreene.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/markjgreene.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/markjgreene.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/markjgreene.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/markjgreene.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/markjgreene.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/markjgreene.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/markjgreene.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/markjgreene.wordpress.com/121/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=markjgreene.wordpress.com&amp;blog=6034167&amp;post=121&amp;subd=markjgreene&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://markjgreene.wordpress.com/2009/12/11/troubleshooting-hung-systems-spiked-cpu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">MG</media:title>
		</media:content>

		<media:content url="http://markjgreene.files.wordpress.com/2009/12/step1.png" medium="image">
			<media:title type="html">Add an Image</media:title>
		</media:content>

		<media:content url="http://markjgreene.files.wordpress.com/2009/12/step2a.png" medium="image">
			<media:title type="html">Add an Image</media:title>
		</media:content>

		<media:content url="http://markjgreene.files.wordpress.com/2009/12/step2b.png" medium="image">
			<media:title type="html">Add an Image</media:title>
		</media:content>

		<media:content url="http://markjgreene.files.wordpress.com/2009/12/step3.png" medium="image">
			<media:title type="html">Add an Image</media:title>
		</media:content>

		<media:content url="http://markjgreene.files.wordpress.com/2009/12/step4a.png" medium="image">
			<media:title type="html">Add an Image</media:title>
		</media:content>

		<media:content url="http://markjgreene.files.wordpress.com/2009/12/step4b.png" medium="image">
			<media:title type="html">Add an Image</media:title>
		</media:content>

		<media:content url="http://markjgreene.files.wordpress.com/2009/12/step5.png" medium="image">
			<media:title type="html">Add an Image</media:title>
		</media:content>
	</item>
		<item>
		<title>Impulse Buying Redux</title>
		<link>http://markjgreene.wordpress.com/2009/03/06/impulse-buying-redux/</link>
		<comments>http://markjgreene.wordpress.com/2009/03/06/impulse-buying-redux/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 17:20:36 +0000</pubDate>
		<dc:creator>MG</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://markjgreene.wordpress.com/?p=117</guid>
		<description><![CDATA[I&#8217;ve started noticing a very interesting trend. Woot and RedTagCrazy have seemingly figured out that people are very interested in social impulse shopping. A quick visit to RedTagCrazy.com and you will witness a set of people expressing shoppers remorse quickly followed up by another set of people producing amusing justifications for pushing the &#8220;Buy Now&#8221; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=markjgreene.wordpress.com&amp;blog=6034167&amp;post=117&amp;subd=markjgreene&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve started noticing a very interesting trend. Woot and RedTagCrazy have seemingly figured out that people are very interested in social impulse shopping. A quick visit to RedTagCrazy.com and you will witness a set of people expressing shoppers remorse quickly followed up by another set of people producing amusing justifications for pushing the &#8220;Buy Now&#8221; button. In some sense the social aspect is really what makes these sites and the companies who own them absolutely love it. Think about it, how many times do you walk into a clothing store and there are hundreds of people conversing back and forth about how great this one particular item is. The whole thing is genius and forces buyers on the fence to feel left out if they don&#8217;t conform to the herd mentality. </p>
<p>The beauty of this &#8220;new&#8221; kind of e-commerce is that it&#8217;s already been done&#8230;well at least on TV. I mean let&#8217;s not forget about how easy it is to get sucked into QVC at 1 in the morning after you forgot to pay your expanded cable bill. All kidding aside, what I love best is the minimalist approach these sites have taken on. It is in fact, a common trend in most Web 2.0 sites and encourages a specific set of workflows for the user to follow. And when it comes to retailing, you want to make it is as simple as possible for someone to open their wallet. Amazon is definitely an early pioneer in this area with their fancy one click purchasing.</p>
<p>With this trend proving itself, it seems to me that the giant retailers of the world ought to pay attention to this racket. I think it&#8217;s inevitable that the Target&#8217;s, Wal-Mart&#8217;s, etc, will get into this independently or through some sort of collaborative network. If retailers don&#8217;t jump on this first, I can easily see other industries utilizing this as a way of getting in front of consumers without overwhelming them.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/markjgreene.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/markjgreene.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/markjgreene.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/markjgreene.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/markjgreene.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/markjgreene.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/markjgreene.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/markjgreene.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/markjgreene.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/markjgreene.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/markjgreene.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/markjgreene.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/markjgreene.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/markjgreene.wordpress.com/117/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=markjgreene.wordpress.com&amp;blog=6034167&amp;post=117&amp;subd=markjgreene&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://markjgreene.wordpress.com/2009/03/06/impulse-buying-redux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">MG</media:title>
		</media:content>
	</item>
		<item>
		<title>DB Indices: Tread Carefully</title>
		<link>http://markjgreene.wordpress.com/2009/02/21/db-indices-tread-carefully/</link>
		<comments>http://markjgreene.wordpress.com/2009/02/21/db-indices-tread-carefully/#comments</comments>
		<pubDate>Sat, 21 Feb 2009 16:49:04 +0000</pubDate>
		<dc:creator>MG</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[DB Index]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://markjgreene.wordpress.com/?p=109</guid>
		<description><![CDATA[To much of a good thing It&#8217;s certainly easy as a software engineer to just believe the DB is this magical box that self optimizes and all you have to do is turn on various settings to make it go faster. I wanted to share a real word example of how that line of thinking [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=markjgreene.wordpress.com&amp;blog=6034167&amp;post=109&amp;subd=markjgreene&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2>To much of a good thing</h2>
<p>It&#8217;s certainly easy as a software engineer to just believe the DB is this magical box that self optimizes and all you have to do is turn on various settings to make it go faster. I wanted to share a real word example of how that line of thinking can get you into hot water, quickly.</p>
<h2>The Situation</h2>
<p>We have a MySQL 5 database in our hosted environment which runs on a dedicated dual quad core with 4 gigs of RAM. The only reason why I highlight the hardware here is because only a programmer could bring that type of computing power to its knees <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  .</p>
<p>The table in question had about 850k rows in it, rapidly approaching 1M. In my experience, once you start approaching this level, at least with MySQL, you better have a really good idea how that table is being queried. In this case, we realized we were doing more writes than reads and we had an index on the table that really wasn&#8217;t necessary after all from a cost benefit point of view. Also, the data in the table could be purged more frequently to reduce the number of rows at any given time which decreases the time needed to rebuild the index after each insert, update, and delete operation.</p>
<p>Below are some graphs of the performance impact:</p>
<div id="attachment_111" class="wp-caption alignleft" style="width: 520px"><img class="size-full wp-image-111" title="loadavg21" src="http://markjgreene.files.wordpress.com/2009/02/loadavg21.png?w=510&#038;h=147" alt="Two Cliffs" width="510" height="147" /><p class="wp-caption-text">Two Cliffs</p></div>
<div id="attachment_112" class="wp-caption alignleft" style="width: 520px"><img class="size-full wp-image-112" title="loadavg" src="http://markjgreene.files.wordpress.com/2009/02/loadavg.png?w=510&#038;h=147" alt="Week Long View" width="510" height="147" /><p class="wp-caption-text">Week Long View</p></div>
<h2>Lesson Learned</h2>
<p>Even though initially, we thought that indexing a hash value (yes I know its a String field) would benefit our lookups, it ended up hurting us more than anything. Everyone&#8217;s situation is a little different but my hope is that I outlined a couple options to alleviate specific performance bottlenecks. If for example, you don&#8217;t have the luxury of just purging rows, you might want to consider archiving records into another table. I won&#8217;t comment any further on this specific topic because I believe this ventures into data warehousing which I am no expert on.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/markjgreene.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/markjgreene.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/markjgreene.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/markjgreene.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/markjgreene.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/markjgreene.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/markjgreene.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/markjgreene.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/markjgreene.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/markjgreene.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/markjgreene.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/markjgreene.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/markjgreene.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/markjgreene.wordpress.com/109/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=markjgreene.wordpress.com&amp;blog=6034167&amp;post=109&amp;subd=markjgreene&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://markjgreene.wordpress.com/2009/02/21/db-indices-tread-carefully/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">MG</media:title>
		</media:content>

		<media:content url="http://markjgreene.files.wordpress.com/2009/02/loadavg21.png" medium="image">
			<media:title type="html">loadavg21</media:title>
		</media:content>

		<media:content url="http://markjgreene.files.wordpress.com/2009/02/loadavg.png" medium="image">
			<media:title type="html">loadavg</media:title>
		</media:content>
	</item>
		<item>
		<title>Fight Carpal Tunnel, Use JWebUnit</title>
		<link>http://markjgreene.wordpress.com/2009/02/16/fight-carpal-tunnel-use-jwebunit/</link>
		<comments>http://markjgreene.wordpress.com/2009/02/16/fight-carpal-tunnel-use-jwebunit/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 22:06:18 +0000</pubDate>
		<dc:creator>MG</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://markjgreene.wordpress.com/?p=91</guid>
		<description><![CDATA[Love at first sight You won&#8217;t find this darling on match.com but I can guarantee you the inside is just as beautiful as the outside. I came across JWebUnit after becoming completely frustrated with Canoo WebTest. My team and I were running into many cases where tests would fail and because of a bug that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=markjgreene.wordpress.com&amp;blog=6034167&amp;post=91&amp;subd=markjgreene&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2>Love at first sight</h2>
<p>You won&#8217;t find this darling on match.com but I can guarantee you the inside is just as beautiful as the outside. I came across <a title="JWebUnit" href="http://jwebunit.sourceforge.net/" target="_blank">JWebUnit </a>after becoming completely frustrated with Canoo WebTest. My team and I were running into many cases where tests would fail and because of a bug that hasn&#8217;t been fixed for quite some time, it doesn&#8217;t save the HTML output, thus not providing you with any immediate insight to why a test failed. This forced us to either guess or spend about a half hour trying to repeat the test case just to find out what happened.</p>
<p>Needless to say, JWebUnit allows easy access to the current state of the HTML page whenever you want it. Additionally, it will keep the state of all forms so you can see exactly what the framework set for values.</p>
<h2>Wrap me up</h2>
<p>JWebUnit is in a round about way, a select set of wrappers that covers about 90% of all web testing operations for a typical application. Also, because it is Java and extends the JUnit framework, abstraction is a breeze.</p>
<p>We found on average, we were writing 30-40% less lines of code in JWebUnit vs Canoo WebTest. Now you can certainly argue this may be a little unfair seeing as Canoo is a declarative framework but perhaps that is just a flaw due to its implementation.</p>
<p>My team and I had to add some additional helper methods to make testing easier but it was simple and very straight forward with basic object oriented design methods.</p>
<h2>AJAX Support</h2>
<p>As with Canoo WebTest, a simple Thread.sleep() for a second or two will allow you to do assertions on ajax based forms.</p>
<h2>Needed Improvements</h2>
<p>I noticed a couple items this framework was missing that Canoo WebTest offered:</p>
<p>1)  I noticed early on in our conversion there was a lack of support for direct XPath. There is currently no way via JWebUnit directly to evaluate Boolean XPath expressions. I&#8217;m currently looking for a workaround on this and also noticed it&#8217;s a rather highly requested feature on SourceForge.</p>
<p>2) The ability to perform assertions on row and column composition was absent. To remedy this situation, I had to write my own wrapper method but it was fairly easy. See below:</p>
<p>**Note WordPress takes out the full entity reference for non breaking spaces, so I just denoted it as &#8220;nbsp&#8221;:</p>
<pre>public void assertValueInCell(String tableID, int rowNum, int colNum, String value) {
        assertElementPresent(tableID);
        Table reqTable = getTable(tableID);
        String[][] tableLookup = new String[reqTable.getRowCount() + 1][15];
        int rowCount = 0;
        int colCount = 0;

        Iterator rowItr = reqTable.getRows().iterator();
        while (rowItr.hasNext()) {
            //reset column counter for every new row iterated over
            colCount = 0;

            Row row = rowItr.next();
            Iterator cells = row.getCells().iterator();

            while (cells.hasNext()) {
                Cell cell = cells.next();

                tableLookup[rowCount][colCount] = cell.getValue().replaceAll("nbsp", "");
                colCount++;
            }

            rowCount++;
        }

        String tableVal = tableLookup[rowNum][colNum];
        if (!tableVal.equals(value)) {
            fail("Value: "
                    + value
                    + " not found in cell: ["
                    + rowNum
                    + ","
                    + colNum
                    + "]  -- Found this instead: "
                    + tableVal);
        }
    }</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/markjgreene.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/markjgreene.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/markjgreene.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/markjgreene.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/markjgreene.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/markjgreene.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/markjgreene.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/markjgreene.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/markjgreene.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/markjgreene.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/markjgreene.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/markjgreene.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/markjgreene.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/markjgreene.wordpress.com/91/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=markjgreene.wordpress.com&amp;blog=6034167&amp;post=91&amp;subd=markjgreene&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://markjgreene.wordpress.com/2009/02/16/fight-carpal-tunnel-use-jwebunit/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">MG</media:title>
		</media:content>
	</item>
		<item>
		<title>Professional Growth vs. Business Objectives</title>
		<link>http://markjgreene.wordpress.com/2009/01/27/professional-growth-vs-business-objectives/</link>
		<comments>http://markjgreene.wordpress.com/2009/01/27/professional-growth-vs-business-objectives/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 00:43:53 +0000</pubDate>
		<dc:creator>MG</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://markjgreene.wordpress.com/?p=72</guid>
		<description><![CDATA[The scales of profits and professional development Reconciling the professional growth needs of developers against business goals is one of the hardest things I&#8217;ve come across as a development manager. In a software company there is seemingly countless reactions for every action and customer needs coming from every angle. Making sure your developers are getting [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=markjgreene.wordpress.com&amp;blog=6034167&amp;post=72&amp;subd=markjgreene&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2>The scales of profits and professional development</h2>
<p>Reconciling the professional growth needs of developers against business goals is one of the hardest things I&#8217;ve come across as a development manager. In a software company there is seemingly countless reactions for every action and customer needs coming from every angle. Making sure your developers are getting what they need career wise adds a twist to an already challenging set of responsibilities.</p>
<p>It is common to have this problem only examined once a year during an annual review. Generally, some assembly of a plan is drafted up containing your goals for the following year but often times those plans succumb to &#8220;We just need to get through this next release&#8221; type of mantra and are quickly forgotten.</p>
<p>When I first started noticing that this was an important and ethical responsibility for my post, I found it difficult because as a co-owner I wanted the highest financial success possible.  After a lot of thought and informal discussions with my team, it became quite obvious about how passionate each member was about specific tasks they have worked on in the past or wanted to get involved with. It&#8217;s hard to put a direct dollar value on employee happiness, but after one experiences different groups of people in different corporate cultures, you can either sense the energy or you can&#8217;t. The companies that have this energy have passionate people who are directly or indirectly increasing their skill set, adding value to their organization. An overstated example of this would be Google. Developers are given time to explore their creative capabilities and yield eye popping technologies like Google Maps.</p>
<h2>Knowledge complacency</h2>
<p>Assigning the right task to the right person makes a lot of sense&#8230;.on paper. The task is worked on by an individual deemed most competent and in theory, the best artifacts are produced in the shortest amount of time. I&#8217;m a firm proponent that this cycle needs to be broken from time to time at the very least, if not on a regular basis.</p>
<p>At some point or another, team members will start to notice their peers advancing in their fields or perhaps working on the next cutting edge. Most developers realize at some level that when you become complacent with your skill set, you become less valuable. Software developers are problems solvers but only in a realm that is defined first by their own knowledge and capabilities followed by the environment in which they are placed in. It is advantageous to any technical organization to not only be willing but encourage completely new ideas to solve problems. This includes but is not limited to re-architecting with different technologies and methods. By adapting this culture, engineers feel investing their own time in learning about new technologies and design philosophies will directly benefit them and the organization in which they are employed. This type of culture however, can be difficult to justify and defend in the face &#8220;growth at all costs&#8221; mentality. In this context, it is nearly impossible to justify the short term benefits of being a pro research &amp; development organization.</p>
<p>In the end, it is difficult to have a technical company firing on all cylinders without being cognitive of how to balance both cultures. Simply adapting one or the other in whole will likely lead to long term imbalance and/or a company with great financial difficulty.</p>
<h2>Until next time…..</h2>
<p>Knowing the precise amount of resources and time to focus on satisfying both needs is a skill I look forward to sharpening. I hope in the near future to share my observations and strategies on this subject.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/markjgreene.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/markjgreene.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/markjgreene.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/markjgreene.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/markjgreene.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/markjgreene.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/markjgreene.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/markjgreene.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/markjgreene.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/markjgreene.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/markjgreene.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/markjgreene.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/markjgreene.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/markjgreene.wordpress.com/72/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=markjgreene.wordpress.com&amp;blog=6034167&amp;post=72&amp;subd=markjgreene&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://markjgreene.wordpress.com/2009/01/27/professional-growth-vs-business-objectives/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">MG</media:title>
		</media:content>
	</item>
		<item>
		<title>Uploading one or many files with Struts 2</title>
		<link>http://markjgreene.wordpress.com/2009/01/06/uploading-one-or-many-files-with-struts-2/</link>
		<comments>http://markjgreene.wordpress.com/2009/01/06/uploading-one-or-many-files-with-struts-2/#comments</comments>
		<pubDate>Wed, 07 Jan 2009 03:43:55 +0000</pubDate>
		<dc:creator>MG</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Struts 2]]></category>
		<category><![CDATA[Upload File]]></category>

		<guid isPermaLink="false">http://markjgreene.wordpress.com/?p=63</guid>
		<description><![CDATA[Pre-game This post will go over the basic points of creating a web form that uploads multiple files. There is some trickery here that I got tripped up on that I will make blatantly obvious here. The Form &#60;script&#62; function addFile(id) {     var parentElm  = document.getElementById(id);     var file = document.createElement('input');     file.setAttribute('name','upload');     [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=markjgreene.wordpress.com&amp;blog=6034167&amp;post=63&amp;subd=markjgreene&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2>Pre-game</h2>
<p>This post will go over the basic points of creating a web form that uploads multiple files. There is some trickery here that I got tripped up on that I will make blatantly obvious here.</p>
<h2>The Form</h2>
<pre>&lt;script&gt;
function addFile(id) {
    var parentElm  = document.getElementById(id);
    var file = document.createElement('input');
    file.setAttribute('name','upload');
    file.setAttribute('type','file');

    parentElm.appendChild(file);
}
&lt;/script&gt;
&lt;s:form action="uploadFileExample"  enctype="multipart/form-data"&gt;
	&lt;div id="fileDiv"&gt;
		Atttach   &lt;s:file <strong>name="upload"</strong> label="File"/&gt;
	&lt;/div&gt;
	&lt;a href="javascript:addFile('fileDiv');"&gt;Attach another file&lt;/a&gt;
	&lt;s:submit/&gt;
&lt;/s:form&gt;</pre>
<p>The most important part here is that you take notice of whatever you name the file input element denoted in <strong>BOLD</strong>.</p>
<h2>The Action</h2>
<pre>private File[] file;
private String[] contentType;
private String[] filename;

public void set<strong>Upload</strong>(File[] file) {
	this.file = file;
}

public void set<strong>Upload</strong>ContentType(String[] contentType) {
	this.contentType = contentType;
}

public void set<strong>Upload</strong>FileName(String[] filename) {
	this.filename = filename;
}

public String execute() throws Exception {
       //...
}</pre>
<p>Notice the <strong>BOLD</strong> in the method signatures. The key here is whatever you put into the name attribute from the step above, must go into the method name after the set prefix and before the actual object reference suffix.</p>
<p>From here, you&#8217;ll have a a File[] that you can loop over. Keep in mind, Struts 2 will upload the files to a temporary directory, depending on what application server you use, this will vary. The best thing to do here is just loop over each file that was uploaded and move each file into a more permanent location. And of course the other arrays contain exactly what you may think they contain. For moving files from one location to another: <a href="http://www.exampledepot.com/egs/java.io/MoveFile.html">Move File</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/markjgreene.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/markjgreene.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/markjgreene.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/markjgreene.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/markjgreene.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/markjgreene.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/markjgreene.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/markjgreene.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/markjgreene.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/markjgreene.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/markjgreene.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/markjgreene.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/markjgreene.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/markjgreene.wordpress.com/63/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=markjgreene.wordpress.com&amp;blog=6034167&amp;post=63&amp;subd=markjgreene&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://markjgreene.wordpress.com/2009/01/06/uploading-one-or-many-files-with-struts-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">MG</media:title>
		</media:content>
	</item>
		<item>
		<title>Struts 2 Exception Handling W/ Hibernate</title>
		<link>http://markjgreene.wordpress.com/2009/01/05/struts-2-exception-handling-w-hibernate/</link>
		<comments>http://markjgreene.wordpress.com/2009/01/05/struts-2-exception-handling-w-hibernate/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 03:10:10 +0000</pubDate>
		<dc:creator>MG</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Struts 2]]></category>

		<guid isPermaLink="false">http://markjgreene.wordpress.com/?p=39</guid>
		<description><![CDATA[The who and the what? This post will illustrate one of the many ways to utilize Struts 2 to deal with handling global exception. Additionally, this topic will also include a way to rollback transactions for Hibernate. The game plan 1) Let&#8217;s extend the existing ExceptionMappingInterceptor and just override only what we need: public class [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=markjgreene.wordpress.com&amp;blog=6034167&amp;post=39&amp;subd=markjgreene&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2>The who and the what?</h2>
<p>This post will illustrate one of the many ways to utilize Struts 2 to deal with handling global exception. Additionally, this topic will also include a way to rollback transactions for Hibernate.</p>
<h2>The game plan</h2>
<p><strong>1) Let&#8217;s extend the existing ExceptionMappingInterceptor and just override only what we need:</strong></p>
<pre>public class MyExceptionInterceptor extends ExceptionMappingInterceptor {

    private static final Logger log = Logger.getLogger(MyExceptionInterceptor.class);

    protected void publishException(ActionInvocation invocation, ExceptionHolder exceptionHolder) {
        try {
            log.error(exceptionHolder.getExceptionStack());

             HibUtil.rollback();
       } catch (Exception e) {
            log.error(e, e);
        }

        super.publishException(invocation, exceptionHolder);
    }
}</pre>
<p><strong>2) Now we need to define our new interceptor and <span style="text-decoration:underline;">redefine</span> the default stack:</strong></p>
<pre>&lt;interceptors&gt;
		&lt;interceptor name="exception" class="MyExceptionInterceptor" /&gt;

		&lt;interceptor-stack name="defaultStack"&gt;
		&lt;interceptor-ref name="exception" /&gt;
		&lt;interceptor-ref name="alias" /&gt;
		&lt;interceptor-ref name="servletConfig" /&gt;
		&lt;interceptor-ref name="prepare" /&gt;
		&lt;interceptor-ref name="i18n" /&gt;
		&lt;interceptor-ref name="chain" /&gt;
		&lt;interceptor-ref name="debugging" /&gt;
		&lt;interceptor-ref name="profiling" /&gt;
		&lt;interceptor-ref name="scopedModelDriven" /&gt;
	        &lt;interceptor-ref name="modelDriven" /&gt;
		&lt;interceptor-ref name="fileUpload" /&gt;
		&lt;interceptor-ref name="checkbox" /&gt;
		&lt;interceptor-ref name="staticParams" /&gt;
		&lt;interceptor-ref name="params"&gt;
			&lt;param name="excludeParams"&gt;dojo\..*&lt;/param&gt;
		&lt;/interceptor-ref&gt;
		&lt;interceptor-ref name="conversionError" /&gt;
		&lt;interceptor-ref name="validation"&gt;
			&lt;param name="excludeMethods"&gt;input,back,cancel,browse&lt;/param&gt;
		&lt;/interceptor-ref&gt;
		&lt;interceptor-ref name="workflow"&gt;
			&lt;param name="excludeMethods"&gt;input,back,cancel,browse&lt;/param&gt;
		&lt;/interceptor-ref&gt;
        &lt;/interceptor-stack&gt;
&lt;/interceptors&gt;

&lt;default-interceptor-ref name="defaultStack" /&gt;</pre>
<p><strong>3)  Define a global transaction handler:</strong></p>
<pre>&lt;global-results&gt;
	&lt;result name="Exception"&gt;/jsp/error/exception.jsp&lt;/result&gt;
&lt;/global-results&gt;
&lt;global-exception-mappings&gt;
	&lt;exception-mapping exception="java.lang.Exception" result="Exception" /&gt;
&lt;/global-exception-mappings&gt;</pre>
<p><strong>4) The following properties will be present on the stack if you wish to write a  simple JSP to display the error:</strong></p>
<pre>&lt;s:property value="%{exception.message}"/&gt;
&lt;s:property value="%{exceptionStack}"/&gt;</pre>
<h2>Final Thoughts</h2>
<p>One thing that I have either not figured out or just simply don&#8217;t like is the inability to just extend an interceptor definition. Struts 2 seems to force the developer to redefine an entire stack in order for the new interceptor to be used. I hope I&#8217;m not missing something fundamental here but during my tests I wasn&#8217;t able to get that working and found no documentation to support my initial assumptions.  It almost seems that this configuration framework only fufills a subset of object oriented behavior. In any case, that wraps up this episode. I hope this gives some basic insight on how to put global exception handling and transaction rollback management in to your application.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/markjgreene.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/markjgreene.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/markjgreene.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/markjgreene.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/markjgreene.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/markjgreene.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/markjgreene.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/markjgreene.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/markjgreene.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/markjgreene.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/markjgreene.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/markjgreene.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/markjgreene.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/markjgreene.wordpress.com/39/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=markjgreene.wordpress.com&amp;blog=6034167&amp;post=39&amp;subd=markjgreene&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://markjgreene.wordpress.com/2009/01/05/struts-2-exception-handling-w-hibernate/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">MG</media:title>
		</media:content>
	</item>
	</channel>
</rss>
