<?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>Loosely coupled thoughts</title>
	<atom:link href="http://www.restfusion.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.restfusion.com/blog</link>
	<description>Seeking the ultimate answer to SOA, REST and everything</description>
	<lastBuildDate>Sun, 11 Jul 2010 17:58:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Patterns Antipattern</title>
		<link>http://www.restfusion.com/blog/2010/07/patterns-antipattern/</link>
		<comments>http://www.restfusion.com/blog/2010/07/patterns-antipattern/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 16:34:08 +0000</pubDate>
		<dc:creator>karaznie</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[antipatterns]]></category>
		<category><![CDATA[deign patterns]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://www.restfusion.com/blog/?p=126</guid>
		<description><![CDATA[In late nineties I started my career in software development. This was roughly few days since I started my second gig. In a Bank. After initial hoopla I finally tackled my new SUN  Ultra 5 pizza boxed workstation, CDE and all that bleeding edge stuff like CVS and gcc. I was ready and excited to [...]]]></description>
			<content:encoded><![CDATA[<p>In late nineties I started my career in software development. This was roughly few days since I started my second gig. In a Bank. After initial hoopla I finally tackled my new <a href="http://en.wikipedia.org/wiki/Sun_Ultra_series">SUN  Ultra</a> 5 pizza boxed workstation, <a href="http://en.wikipedia.org/wiki/Common_Desktop_Environment">CDE</a> and all that bleeding edge stuff like CVS and gcc. I was ready and excited to start my next journey, dive into muddy waters of bits we were working on. Oh boy that was freaking great feeling. Me working on a critical online banking system, could You believe? Me&#8230; erm&#8230; completely green. Me, the novice.</p>
<p>Eagle was a senior developer. Not a formal leader, just guy keeping development going, knowing all dark nooks of our app, build scripts and interfaces; all stuff. A go-to fellow. He was proud owner of SUN Ultra 10, with whole gig of RAM, and he always built the final release of the system. Because his workstation was, pretty much, the only one capable enough to build whole system within less than half a day. He was a gate keeper and an expert.</p>
<p>Eagle didn’t talk much. He rather showed in his cubicle early morning, typed with the speed of machine gun and bah! Next feature ready. We, all the greenhorns, pulled his new stuff from CVS immediately and tried understand all that brilliantly esoteric bits. He was the only guy who actually actively used all cast types in C++: dynamic, reinterpret, static and const casts. And he understood the difference. He was probably the only person who understood this on planet Earth (OK, maybe <a href="http://pl.wikipedia.org/wiki/Bjarne_Stroustrup">Bjarne Stroustrup</a> knew this stuff, too, however I&#8217;ve never talked to him, so I&#8217;m not sure:). Huh! That was mastery. Truly. And this was how Eagle had communicated with the rest of the world. Through the stuff he was working on; the code. He checked bits into repository, we pulled it and tried to understand. A communication loop. Or stream, strictly speaking. Because there was no feedback back-channel closing the loop. Eagle didn’t care much about our code, granted we followed his ideas and style. And we followed.</p>
<p>One day our manager popped in and communicated we have to start working on a brand new module. And we started. We formed small team: Eagle, Paw &#8211; a competent fellow developer, and me &#8211; the novice guy. Next day Eagle showed up, and he didn’t start coding immediately, as he usually had used to. He stared at me for a while, came to my cubicle and put white, a little bit fatigued paper brick on my desk. A book with friendly, blue letters: “<a href="http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1278843786&amp;sr=8-1">Design Patterns: elements of reusable object-oriented software</a>”. And he went back to his Ultra 10, and started typing. After few seconds I got e-mail: “We gonna use Design Patterns in this new module. Read this book. Regards. Eagle”. Holly! Eagle emailed me. Can You believe? And we gonna use Design Patterns, ain’t this cool?! ‘Design Patterns’&#8230;Wait! &#8216;Design&#8217; what? What the hell are ‘design patterns’? And remember this was in late nineties, the prehistory. No google search, no wikipedia and all this usual stuff we are so used to nowadays. My <a href="http://pl.wikipedia.org/wiki/AltaVista">altavista</a> search didn’t cut it; neither my experience from university days. Nothing. &#8220;This must be even more esoteric stuff than all that C++ casts we used&#8221;. I thought.</p>
<p>This afternoon I brought &#8220;Design Patterns&#8221; book with me and started reading. Indeed, this was more esoteric than all this ‘C++ casts’ stuff. Lots of high-level ideas, with names, in the form of ready-made recipes. And all that taxonomy (and Yes, I looked up <strong>paper </strong>dictionary to discover what &#8216;taxonomy&#8217; actually meant. Remember, no google search back then). Lots of examples in Smalltalk. Wow! Smalltalk! I’d used Smalltalk during one of my university courses. Wrote few trivial, hello-world size projects. Didn’t even know somebody used this stuff in real-life. Huh! Those <a href="http://en.wikipedia.org/wiki/Design_Patterns_(book)">GoF</a> guys must be smart, they use Smalltalk! And Eagle asked me digest this book. Cool! Two days later I was speaking patterns. Ha! <strong><em>Design </em></strong>patterns. I’ve seen patterns everywhere and was ready to put this stuff into my code. I was wondering how the hell I survived without patterns actually.</p>
<p>Next day we gathered: Eagle, Paw &#8211; a competent fellow developer, and me &#8211; now design patterns guy. Design patterns and&#8230; still novice. Anyhow. We brainstormed our high level design, full of patterns. The only guy who had a problem with all those patterns was&#8230; Paw. Meh! Eagle and me voted for patterns, Paw was against. But eventually all that Paw’s ‘Why?’ annoying questions were refused. Didn’t he know GoF guys are smart, so we were, using their patterns, huh?! Boring. Eagle took final decision. Use design patterns. Period. Paw went away with his opinion in his mind, anyhow.</p>
<p>We started coding brand new module. Full of patterns. We built beautiful architecture with all possible levels of abstraction. We created every single object with Builders. We glue stuff with Bridges and Delegates. We implemented business logic with Chain of Responsibility. We built SQL queries with Visitors. We implemented security with Proxies. Everything with grain of Singletons and MVC. Just to name few patterns. You know&#8230; all this smart stuff. Let me rephrase: <em><strong>all</strong></em> this smart stuff. Literally. We actually worked two months more than expected and produced half the code whole system had so far. But who cared? We did great stuff, right? At least I was proud of this.</p>
<p>Few months later Eagle left company, and me and Paw eventually ended up with this design patters legacy. Alone.</p>
<p>Fast forward. Quite few brand new modules later&#8230; Now, I walk Eagle’s shoes.  I’m the expert. I&#8217;m go-to guy. I even understand all C++ cast types. Huh! And I drive all development, including our shiny design patterns sandbox. Still have to support it. But guess what? It’s the worst module in whole system. Seriously. How come? Somebody did something wrong in the meantime? Somebody has broken beautiful architecture? Sneaked some wrong ideas?<em><strong>&#8230; Antipatterns</strong></em>? Nope. Nobody even wanted to touch it because every single change took literally weeks. Almost nothing changed since its inception. So what happened, then? Nothing. It’s actually the same, original module we wrote few years ago. Untouched. Oh&#8230;wait&#8230; there were quite a few workarounds carefully bypassing this stuff. It stayed in its own vacuum.</p>
<p>It was quite few Years, and few gigs ago, in the middle of all that Patterns mumbo-jumbo. Some <a href="http://en.wikipedia.org/wiki/Singleton_pattern">Patterns</a> became <a href="http://code.google.com/p/google-singleton-detector/wiki/WhySingletonsAreControversial">antipatterns</a> since then. And we eventually drank our cool aid. But guess what? I like this story. It taught me more than all <a href="http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1278858029&amp;sr=8-1">Patterns</a> <a href="http://www.amazon.com/Enterprise-Integration-Patterns-Designing-Deploying/dp/0321200683/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1278858065&amp;sr=1-1">books</a> I <a href="http://www.amazon.com/Patterns-Enterprise-Application-Architecture-Martin/dp/0321127420/ref=pd_rhf_shvl_1">have</a> <a href="http://www.amazon.com/Design-Patterns-Prentice-Service-Oriented-Computing/dp/0136135161/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1278858140&amp;sr=1-1">read</a>. I learned that patterns, without enough care, might become harmful. Astonishingly harmful. Even more astonishingly harmful without proper communication and reasoning. It&#8217;s what I call a <strong><em>Patterns Antipattern</em></strong>. What this story all about: blindly followed ideas, just because someone smart wrote a book about them. And someone had wild idea to check if all this stuff work together. And won&#8217;t implode. And someone else followed. Do not try this at work. Avoid <em><strong>Patterns Antipattern</strong></em>.</p>
<p>So&#8230; be the Paw, not the Eagle! Challenge ideas. Don&#8217;t drink cool aid without asking questions. Paw, thanks for the lesson, pal!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.restfusion.com/blog/2010/07/patterns-antipattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>James Gosling leaves Oracle</title>
		<link>http://www.restfusion.com/blog/2010/04/james-gosling-leaves-oracle/</link>
		<comments>http://www.restfusion.com/blog/2010/04/james-gosling-leaves-oracle/#comments</comments>
		<pubDate>Sat, 10 Apr 2010 13:46:56 +0000</pubDate>
		<dc:creator>karaznie</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Varia]]></category>

		<guid isPermaLink="false">http://www.restfusion.com/blog/?p=119</guid>
		<description><![CDATA[This just hit me this morning: James Gosling leaves Oracle. Although not so unexpected move, frankly, it&#8217;s quite significant. With all uncertainty about Oracle commitment to java (especially openness, agility and simply, kinda of good, balanced attitude) this might boil java trouble water more. I love Gosling&#8217;s attitude and his perception of simplicity. Anyway, hope [...]]]></description>
			<content:encoded><![CDATA[<p>This just hit me this morning: <a href="http://nighthacks.com/roller/jag/entry/time_to_move_on">James Gosling leaves Oracle</a>. Although not so unexpected move, frankly, it&#8217;s quite significant. With all uncertainty about Oracle commitment to java (especially openness, agility and simply, kinda of good, balanced attitude) this might boil java trouble water more. I love Gosling&#8217;s attitude and his <a href="http://www.javaworld.com/javaworld/jw-08-2003/jw-0801-toolbox.html">perception of simplicity</a>. Anyway, hope Gosling continue his excellent work, and looking forward and expect some great, new bits from father of java! Bookmarked and subscribed James <a href="http://nighthacks.com/roller/jag/">new blog</a> feeds&#8230; Thanks for all the fish, James <img src='http://www.restfusion.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . And&#8230; what&#8217;s Your opinion?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.restfusion.com/blog/2010/04/james-gosling-leaves-oracle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New gig and I&#8217;m dzone.com MVB!</title>
		<link>http://www.restfusion.com/blog/2010/03/new-gig-and-i-m-dzone-mvb/</link>
		<comments>http://www.restfusion.com/blog/2010/03/new-gig-and-i-m-dzone-mvb/#comments</comments>
		<pubDate>Sat, 13 Mar 2010 10:50:08 +0000</pubDate>
		<dc:creator>karaznie</dc:creator>
				<category><![CDATA[Varia]]></category>

		<guid isPermaLink="false">http://www.restfusion.com/blog/?p=105</guid>
		<description><![CDATA[February was pretty busy to me. First I decided to take new opportunity and got new, exciting gig. I&#8217;ll be doing what I have doing so far: software architecture and integration, but in completely different field: telco. Pretty challenging, but also pretty interesting and refreshing, giving completely new perspectives. Now I&#8217;m diving deeply into TM [...]]]></description>
			<content:encoded><![CDATA[<p>February was pretty busy to me. First I decided to take new opportunity and got new, <a href="http://www.linkedin.com/in/karazniewicz">exciting gig</a>. I&#8217;ll be doing what I have doing so far: software architecture and integration, but in completely different field: <a href="http://www.netia.pl//en/about_netia.html">telco</a>. Pretty challenging, but also pretty interesting and refreshing, giving completely new perspectives. Now I&#8217;m diving deeply into <a href="http://www.tmforum.org/browse.aspx">TM Forum</a>, <a href="http://www.tmforum.org/BusinessProcessFramework/1647/home.html">eTOM</a>, <a href="http://www.tmforum.org/InformationFramework/1684/home.html">SID</a> etc.</p>
<p>Secondly I&#8217;ve become <a href="http://www.dzone.com/aboutmvb">Dzone MVB</a> (dzone.com Most Valuable Blogger). Huh, being a <a href="http://www.dzone.com/page/mvbs">MVB</a>, together with such great bloggers like <a href="http://blogs.tedneward.com/">Ted Neward</a>, <a href="http://memeagora.blogspot.com/">Neal Ford</a>, <a href="http://www.adam-bien.com/roller/abien/">Adam Bien</a> (just to name few) is quite challenging too. Expect more, and high quality content <img src='http://www.restfusion.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . My <a href="http://java.dzone.com/articles/jee-sdk-%E2%80%93-loathe-it-or-ignore">first Dzone entry</a>, with my <a href="http://www.restfusion.com/blog/2010/02/jee-sdk-loathe-it-or-ignore-it-you-cant-like-it/">rant</a> about state of JEE 6 SDK<a href="http://java.dzone.com/articles/jee-sdk-%E2%80%93-loathe-it-or-ignore"> sparkled quite heated discussion</a> on <a href="http://java.dzone.com/">javalobby</a> with some tough reactions, and massive, hot discussion with JEE proponents (which I&#8217;m too, actually;), including JCP member and <a href="http://www.caucho.com/">Caucho Resin</a> lead, <a href="http://www.rahmannet.net/blog/">Rahman Reza</a>. Overall, despite some initial rude reactions, I&#8217;m happy that my rant sparkled such a interesting discussion <img src='http://www.restfusion.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
]]></content:encoded>
			<wfw:commentRss>http://www.restfusion.com/blog/2010/03/new-gig-and-i-m-dzone-mvb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JEE SDK &#8211; Loathe it or ignore it. You can&#8217;t like it.</title>
		<link>http://www.restfusion.com/blog/2010/02/jee-sdk-loathe-it-or-ignore-it-you-cant-like-it/</link>
		<comments>http://www.restfusion.com/blog/2010/02/jee-sdk-loathe-it-or-ignore-it-you-cant-like-it/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 09:53:03 +0000</pubDate>
		<dc:creator>karaznie</dc:creator>
				<category><![CDATA[JEE]]></category>

		<guid isPermaLink="false">http://www.restfusion.com/blog/?p=86</guid>
		<description><![CDATA[It&#8217;s only me who think JEE 6 SDK is complete mess? Don&#8217;t get me wrong, I&#8217;m not saying JEE 6 is mess. It&#8217;s SDK which brings accidental complexity, the hard way. It failed my five minutes usability test, and it continues to fail still, after few months.
The problem with SDK
It&#8217;s not SDK actually; it&#8217;s just [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s only me who think JEE 6 SDK is complete mess? Don&#8217;t get me wrong, I&#8217;m not saying JEE 6 is mess. It&#8217;s SDK which brings <a href="http://en.wikipedia.org/wiki/Accidental_complexity">accidental complexity</a>, the hard way. It failed my five minutes usability test, and it continues to fail still, after few months.</p>
<h3>The problem with SDK</h3>
<p>It&#8217;s not SDK actually; it&#8217;s just Glassfish bundled with some documentation, examples and random APIs. That&#8217;s it. Here&#8217;s what You get with JEE bundle:<code></code></p>
<p><code>.org.opensolaris,pkg<br />
bin<br />
glassfish<br />
install<br />
javadb<br />
mq<br />
pkg<br />
uninstall.exe<br />
uninstall.sh<br />
updatetool<br />
var<br />
</code></p>
<p>Ascetic, isn&#8217;t it? Expected some standard stuff like <code>lib</code> or, better, <code>dist</code> directories? Some jars or APIs? Or some form of readme, or docs? It&#8217;s SDK, the <a href="http://en.wikipedia.org/wiki/Software_development_kit">Software Development Kit</a>, right? It should have all that usual stuff somewhere. Well, sort of. If You&#8217;re stubborn enough and lookup Glassfish directory, even though don&#8217;t expect too much.  This is <em>&#8220;enterprise&#8221;</em> stuff,  it can&#8217;t be just as simple as picking some jars and start working with it <img src='http://www.restfusion.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> . So where are all <a href="http://java.sun.com/javaee/downloads/javaee6sdk_contents.jsp">expected JEE APIs</a>?  I&#8217;m not quite sure, except some mere suspicion. After quick <a href="http://tonyxzt.blogspot.com/2008/02/how-to-find-what-jar-contain-particular.html">bashing</a> it turned out that <code>$SDK_HOME/glassfish/modules</code> contains most interesting bits. Most&#8230; except, believe me or not, JMS and JTA APIs. Surprised? Most probably. SDK comes <strong>without</strong> core stuff like: JMS and JTA APIs. Or again, maybe it&#8217;s just me who failed? Would love someone point out I&#8217;m wrong. I know, I know: I can find all this stuff <a href="http://java.sun.com/products/jms/docs.html">here</a>. But isn&#8217;t it SDK supposed to come with? </p>
<p>Even though <code>$SDK_HOME/glassfish/modules</code> contains something&#8230; it&#8217;s Glassfish runtime, and I have no confidence what all those jars actually are. Are they official APIs, or maybe OSGI bundles, or is this Glassfish specific stuff, RIs, or something else? I&#8217;m not sure, neither my google is. Anyhow I don&#8217;t think server runtime is the best place to throw APIs in. Thanks God SpringSource guys didn&#8217;t mix Spring Framework with Tomcat distribution.</p>
<h3>How it should look like, then?</h3>
<p>Enough ranting. How to fix it? Take some time and take a look how does <a href="http://www.springsource.org">competition</a> work. Just create simple, lightweight SDK (<em>&#8220;lightweight</em>&#8221; is the main theme behind JEE 6 after all, isn&#8217;t it?). Just bundle APIs, documentation and samples (and keep separate Glassfish bundle, of course). That&#8217;s it. JEE is supposed to be portable and universal; not everyone is interested in full Glassfish distribution. Make it simple for beginners and give a chance the JEE SDK passes 5 minute usability test. That&#8217;s all.</p>
<p>Hope <a href="http://java.sun.com/javaee/"><em>&#8220;Do more with less work&#8221;</em></a> would work better next time&#8230; or it&#8217;s only me? Should I RTFM? Anyone care to comment?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.restfusion.com/blog/2010/02/jee-sdk-loathe-it-or-ignore-it-you-cant-like-it/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>I do believe into Software Architecture</title>
		<link>http://www.restfusion.com/blog/2010/01/i-do-believe-into-software-architecture/</link>
		<comments>http://www.restfusion.com/blog/2010/01/i-do-believe-into-software-architecture/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 14:50:31 +0000</pubDate>
		<dc:creator>karaznie</dc:creator>
				<category><![CDATA[Architecture]]></category>

		<guid isPermaLink="false">http://www.restfusion.com/blog/?p=73</guid>
		<description><![CDATA[Recently, interesting post by Sergey Mikhanov sparkled vivid discussion about Software Architects, and Software Architecture in general. While Sergey&#8217;s post holds title bit controversial title, it spotted pretty valid problems. At first, I wanted answer Sergey&#8217;s post directly, but after while I thought my answer is little bit long. So here it is.
To make long [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, <a href="http://www.mikhanov.com/2010/01/26/why-i-dont-believe-in-software-architects-120">interesting post</a> by Sergey Mikhanov sparkled vivid discussion about Software Architects, and Software Architecture in general. While Sergey&#8217;s post holds title bit controversial title, it spotted pretty valid problems. At first, I wanted answer Sergey&#8217;s post directly, but after while I thought my answer is little bit long. So here it is.</p>
<p>To make long story short: I do believe into <strong>real</strong> Software Architects. Unfortunately there is no single, agreed upon definition what Software Architect actually is. And that&#8217;s the problem Sergey spotted. The Software Architect role is not only often unclear, sometimes blurry, but worse, has depreciated over the years. The part of the problem is lack of formal definition, but other part is that often this title means nothing, except somebody, somewhere thought it would be nice to put such a &#8216;Software Architect&#8217; tag on somebody&#8217;s visit card. It&#8217;s not uncommon to become Software Architect overnight, just because one finished few projects successfully in a row or did something extraordinary like that. That&#8217;s the problem. I see this recurring pattern especially in consulting companies. You can earn Architect title for nothing. </p>
<p>What makes somebody <strong>the</strong> Software Architect? It&#8217;s not a title on a visit card definitely. Fortunately I have met brilliant software architects during my life and actually only few of them hold &#8216;Software Architect&#8217; moniker. If I had to point out one, single quality those sharp guys had in common &#8211; it would be: Big Picture. They had seen Big Picture; the whole thing. Be it module (Software Architect), single system (System Architect), whole solution (Solution Architect), some problem domain (Domain Architect) or even whole corporation (Enterprise Architect). They had this rare ability of seeing that thing, they were working on, was not just simple sum of parts, it was something more &#8211; the whole thing. In every possible aspect: functional, non functional, technical and, yes, business. And they were steering others into the right direction. With their help, things went smoothly and everybody felt much more comfortable. That was precious and encouraging. They were Lead Developers, Senior Developers, some of them where Analysts, and few of them were actually &#8216;Architects&#8217;. So I should have actually said: I believe into Software Architecture, not necessary into Architects. Show me one, and I can tell if he or she is worth the title she or he holds. Actually this is the question of seeing, not believing. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.restfusion.com/blog/2010/01/i-do-believe-into-software-architecture/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Why Asynchronous Servlets matter, part I</title>
		<link>http://www.restfusion.com/blog/2010/01/why-asynchronous-servlets-matter-part-i/</link>
		<comments>http://www.restfusion.com/blog/2010/01/why-asynchronous-servlets-matter-part-i/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 10:41:33 +0000</pubDate>
		<dc:creator>karaznie</dc:creator>
				<category><![CDATA[JEE]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.restfusion.com/blog/?p=8</guid>
		<description><![CDATA[Most of us, in java world, are well aware of the new spec bundle under the JEE 6 moniker released last December. Along with well recognized and discussed features like JPA 2.0, EJB 3.1 or CDI, JCP sneaked really innovative bit &#8211; JSR 315, aka Java Servlet 3.0 Specification. To be honest &#8211; historically Servlets [...]]]></description>
			<content:encoded><![CDATA[<p>Most of us, in java world, are well aware of the new spec bundle under the <a href="http://java.sun.com/javaee/">JEE 6 moniker released last December</a>. Along with well recognized and discussed features like <a href="http://jcp.org/en/jsr/detail?id=317">JPA 2.0</a>, <a href="http://jcp.org/en/jsr/detail?id=318">EJB 3.1</a> or <a href="http://jcp.org/en/jsr/summary?id=299">CDI</a>, JCP sneaked really innovative bit &#8211; <a href="http://jcp.org/en/jsr/detail?id=315">JSR 315</a>, aka Java Servlet 3.0 Specification. To be honest &#8211; historically Servlets API wasn&#8217;t the most exciting thing on the planet. Sure it&#8217;s important, it&#8217;s solid pillar of JEE, but &#8211; let&#8217;s face it &#8211; most of us probably not only can&#8217;t spot any difference between subsequent Serlvet specs, but probably, haven&#8217;t even scrapped the Servlet API surface directly for years, used to convenient abstractions introduced by tons of frameworks we are used to nowadays. Servlet API happened to be kind of <a href="http://ola-bini.blogspot.com/2008/01/viability-of-java-and-stable-layer.html">Stable Layer</a> of JEE.</p>
<p>This time things seems to be different, though. Real innovation comes from the very core layer of JSR-315 with notion of asynchronous servlets. Unfortunately as few times before, JCP put great marketing effort to make this piece as much esoteric as they could. At least from my perspective. Documentation is sparse at best, examples are hard to understand and We, the community, are not far better in this very matter. Admittedly there are pretty <a href="http://blogs.webtide.com/gregw/entry/use_cases_for_async_servlets">good</a> <a href="http://www.javaworld.com/javaworld/jw-02-2009/jw-02-servlet3.html?page=1">examples</a> and introductions around the web, but none of them draw big picture.</p>
<p>So this is my first instalment of trilogy. I want  to cast some light on this topic, will try to put all puzzles together to easily grasp whole asynchronous servlet concept: what&#8217;s it, what&#8217;s not, what&#8217;s good, bad and the ugly. In the second part I&#8217;ll show some real life examples of asynchronous servlets (and clients), introduce higher level frameworks and techniques: cometd and Bayeux.  In the last part I will show, what I&#8217;m particularly most interested in, how this whole idea fits into web services world.  But&#8230;</p>
<h3>First things first</h3>
<p>Before we grasp the idea of asynchronous servlets, we have to understand basics: how HTTP servers actually work. I won&#8217;t dive into nuts and bolts here &#8211; I&#8217;ll briefly describe some nuances of HTTP protocol handling, and how modern HTTP servers work. Just to understand what&#8217;s so innovative in asynchronous HTTP processing. If You are interested in more in-depth analysis i highly recommend <a href="http://www.javaworld.com/javaworld/jw-02-2009/jw-02-servlet3.html?page=1">great article by Xinyu Liu</a>.</p>
<h4>Thread-per-connection</h4>
<p>Nowadays most HTTP engines use some variation of so called thread-per-connection pattern. Basically, when HTTP connection arrives, HTTP server picks single thread, of out a pool, to handle it till it&#8217;s committed (meaning all response data are written and response output stream is closed), then thread is freed-up back to the pool.  This approach scales pretty well, but it has some drawbacks, though. One of significant aspects of HTTP 1.1 protocol is keep-alive option. Client and server may (and they usually do) negotiate to keep connection open and span multiple HTTP request and responses. In traditional approach this means that thread can potentially be allocated for significant amount of time, even if it&#8217;s just idle. Fortunately this problem might be mitigated with&#8230;</p>
<h4>Asynchronous IO and Thread-per-request</h4>
<p>With Web 2.0 and AJAX, web application comes with far richer user experience and, usually, needs hundreds of request to render and refresh its content. This raises performance bar significantly. Fortunately, most HTTP server vendors have undertaken tremendous amount of research, and they reach <a href="http://blogs.webtide.com/gregw/2008/01/07/1199704334432.html">stunning numbers</a> in the of concurrent connections they can handle simultaneously. With help of asynchronous IO it is no longer needed to maintain thread up until connection is closed. As long as request processing is finished, processing thread can be reused, while IO stuff can be handled asynchronously. This effectively means that even Client and server keep connection alive for significant amount of time, we don&#8217;t need any thread associated with it. Fortunately, this is done completely transparently from Servlet API perspective.</p>
<h3>The need of asynchronous servlets</h3>
<p>So why we actually need asynchronous servlets? Well, Web 2.0 redefined how web applications work, but what&#8217;s even more important, Web 2.0 redefined Web architecture as well in the terms of rich user experience, high interactivity and low latency messaging. Asynchronous servlets address low latency, asynchronous messaging aspect.  This aspect has quite broad use-cases, from real-time messaging services (like <a href="http://wave.google.com">google wave</a>) to enterprise level services, like trading, stocks etc.</p>
<h3>Quote Service</h3>
<p>To make this whole story more concrete I will illustrate above idea with simple Stock Quote Service and Stock Quote Widget. Stock Quote AJAX Widget will present real-time share price provided by Stock Quote Service. We will use <a href="http://en.wikipedia.org/wiki/Observer_pattern">Observer</a>, or more broadly publish/subscribe pattern &#8211; so every Client would subscribe given channel and watch stock prices. Of course, we cannot guarantee how frequently we get information from our backing stock exchange system. It&#8217;s asynchronous. Since we don&#8217;t have real connection to real-time sock quote service, we will mock it with simple MockStockQuoteService:</p>
<pre class="brush: java">
package org.restfusion.jsr315.stockquote;

import java.util.Observable;
import java.util.Random;

public class MockStockQuoteService extends Observable implements StockQuote, Runnable {

public void run() {
setChanged();
notifyObservers();
}

public String getSymbol() {
return &quot;GOOG&quot;;
}

public Double getValue() {
return Math.abs(new Random().nextDouble());
}
}
</pre>
<p>For sake of brevity, Observable holds simple stock quote data behind this simple interface:</p>
<pre class="brush: java">
package org.restfusion.jsr315.stockquote;

interface StockQuote {
public String getSymbol();
public Double getValue();
}
</pre>
<p>And for testing purposes it will just return some random share price for &#8220;GOOG&#8221;. Nothing unusual so far.</p>
<p>Our first, naive approach would be like this: write simple synchronous servlet and poll it every second from within Our widget using some flavour of AJAX toolkit. Our servlet would observe MockStockQuoteService and return information if something has changed, or not. This is actually pretty simple and common approach. Here&#8217;s how it&#8217;s gonna work:</p>
<p style="text-align: center;"><a href="http://www.restfusion.com/blog/wp-content/uploads/2010/01/reqresp.png"><img class="alignnone size-full wp-image-20" title="reqresp" src="http://www.restfusion.com/blog/wp-content/uploads/2010/01/reqresp.png" alt="" width="423" height="169" /></a></p>
<p>It&#8217;s clear that only portion of responses would carry interesting information, and the rest would effectively just say &#8216;nothing changed&#8217;. As You can see only second pair (in red) of request/response carries some significant value. So far so good. Now lets imagine that one day someone find Our widget useful and put it on <a href="google.com/ig">igoogle</a>. We have to prepare to face with something of <a href="http://www.urbandictionary.com/define.php?term=Google%20scale">google scale</a>, right? Let&#8217;s be modest, say 10000 clients will subscribe Our service. Now we have to handle (potentially) 10000 requests per second, ergo we have to scale Our server to handle 10000 threads. Pretty impressive number, isn&#8217;t it? What&#8217;s worse, most of those threads will do virtually nothing except saying: &#8216;nothing changed&#8217;. It&#8217;s where asynchronous servlets shine.</p>
<h4>Long polling</h4>
<p>The trouble with Our initial approach comes from the fact that we use synchronous approach to solve asynchronous problem. Stock quote service is asynchronous by its nature. We don&#8217;t ask Stock Exchange for stock price, they will usually give us that information. It would be nice to follow this approach on Servlets API &#8211; listen for events, rather than poll. Now our second approach would be Long Polling. Here is how it works:</p>
<p style="text-align: center;"><a href="http://www.restfusion.com/blog/wp-content/uploads/2010/01/longpoll.png"><img class="size-full wp-image-19 aligncenter" title="longpoll" src="http://www.restfusion.com/blog/wp-content/uploads/2010/01/longpoll.png" alt="" width="423" height="224" /></a></p>
<p>Compare this with previous one. Can You spot the difference? Right! Now, every response carries some valuable information. Note that we actually establish HTTP connection and wait for response up until we have some interesting information available (in this case new stock price). We do poll still, but at much lower ratio, and are waiting for some valuable information. When information arrives we consume it, and poll once more. Potentially ad infinitum. Here is sample Stock Quote Widget:</p>
<pre class="brush: html">
&lt;html&gt;
&lt;head&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;jquery-1.3.2.min.js&quot;&gt; &lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
$(document).ready(longPoll);

function longPoll() {
$.get(&quot;/jsr315/longPollingStock&quot;, {}, function ( data, status ) {
$(&quot;#quoteWidget&quot;).html(data);
longPoll();
} );
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id=&quot;quoteWidget&quot;&gt;&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p><em>jQuery crash course: longPoll function simply sends GET requests to Our servlet and waits for completion (new stock quote). Once it arrives, it updates our widget (<code>quoteWidget div</code>) and initiates next poll.</em></p>
<p>Now, finally, lets look how Our server side stuff support this approach.</p>
<pre class="brush: java">
@WebServlet(urlPatterns = &quot;/longPollingStock&quot;, asyncSupported = true)
public class LongPollingStockServlet extends HttpServlet {

static MockStockQuoteService stockQuoteService = new MockStockQuoteService();
static ScheduledThreadPoolExecutor worker = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(1);

static {
worker.scheduleAtFixedRate(stockQuoteService, 0, 5, TimeUnit.SECONDS);
}

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
AsyncContext ctx = req.startAsync(req, resp);
stockQuoteService.addObserver(new QuoteObserver(ctx));
}
}
</pre>
<p>Here are two things to note:</p>
<p><strong>asyncSupported = true</strong> &#8211; this flag instructs HTTP container that this servlet might support asynchronous processing.</p>
<p><strong>AsyncContext ctx = req.startAsync(req, resp</strong>) &#8211; this is where we actually initiate asynchronous processing by calling <a href="http://java.sun.com/javaee/6/docs/api/javax/servlet/ServletRequest.html#startAsync(javax.servlet.ServletRequest,%20javax.servlet.ServletResponse)">HttpServletRequest#startAsync</a>. As servlet documentation says:</p>
<blockquote><p>Calling this method will cause committal of the associated  response to be delayed until <code>AsyncContext#complete</code> is  called on the returned <code>AsyncContext</code>, or the asynchronous  operation has timed out.</p></blockquote>
<p>And that&#8217;s the whole thing. We delay request  committal up until we process this request in the future, asynchronously. If we wouldn&#8217;t do above, Our HTTP request would be effectively committed right after <code>doGet</code> method is finished. This time we postpone request processing until Our  <code>QuoteObserver</code> gets notified by <code>MockStockQuoteService</code> asynchronously. At the same time we finish doGet and give processing thread back to the HTTP container. We register <code>QuteObserver</code> on <code>MockStockQuoteEngine</code> which would notify all its observer every five seconds, as You might deduced looking at  <code>ScheduledThreadPoolExecutor</code>. More on this later, now lest assume that&#8217;s just black box, it would notify us asynchronously. Just don&#8217;t look into that box right now <img src='http://www.restfusion.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>Now, let&#8217;s look where actually something useful happens:</p>
<pre class="brush: java">
public class QuoteObserver implements Observer {

private AsyncContext ctx;

public QuoteObserver(AsyncContext ctx) {
this.ctx = ctx;
}

public void update(Observable observable, Object arg) {
StockQuote quote = (StockQuote) observable;
try {
ctx.getResponse().setContentType(&quot;text/html&quot;);
Writer writer = ctx.getResponse().getWriter();
writer.write(&quot;&lt;span&gt;Symbol: &quot; + quote.getSymbol() + &quot;, Price &quot; + quote.getValue() +  &quot;&lt;/span&gt;&quot;);
observable.deleteObserver(this);
ctx.complete();
} catch (IOException e) { /* ignore */ }
}
}
</pre>
<p>Here we are doing pretty useful stuff. Once we get notified, we inform Our subscribers that we just got new stock prices. And effectively causing response committal calling <code>ctx.complete();</code> (and we are removing this Observer from Observers pool, because we don&#8217;t know if client would choose to poll anymore). Note that we do this processing in completely different context.  <code>doGet </code>unwound probably few seconds before, and Our previous processing thread is serving next request, hopefully. Now&#8230;</p>
<h5>Putting it all together</h5>
<p>Finally, when You deploy this application and reach Your Stock Quote Widget You would see something like this (and the price part will be refreshed every five seconds).</p>
<p style="text-align: center;"><a href="http://www.restfusion.com/blog/wp-content/uploads/2010/01/stockquote.png"><img class="size-full wp-image-43 aligncenter" title="stockquote" src="http://www.restfusion.com/blog/wp-content/uploads/2010/01/stockquote.png" alt="" width="300" height="83" /></a></p>
<h4>Don&#8217;t look into the box</h4>
<p>Lest step back a little and take a look at <code>ScheduledThreadPoolExecutor</code>. You may probably wonder: why actually use another thread just to handle request asynchronously while we said, that all that stuff is about limiting thread usage, right? Now, isn&#8217;t it counter-intuitive to spawn other Thread (or even Executor) just to handle request asynchronously? Well, that&#8217;s pretty valid question. It&#8217;s just for sake of brevity. In the next instalment of this series I will show how we can integrate this technique and available asynchronous options, like JMS and asynchronous methods (new in spring 3.0 and EJB 3.1). For now&#8230; just don&#8217;t look into the box.</p>
<p>To sum this part up: this approach seems to be more reasonable. It reduces significantly polling frequency, and request carry only important data. Though, it still has some important holes. First of all, subscribers are not durable. We can miss some information between subsequent polls. This is probably not the problem in Our, simple case, but it might be in plethora of other scenarios. Fortunately here comes&#8230;</p>
<h4>HTTP streaming</h4>
<p>Idea behind HTTP streaming is actually pretty simple. Client initiates connection and keeps it open possibly ad infinitum. Subsequent messages from servlet to client are sent using previously allocated communication channel. Conceptually we newer commit response. Here is how it works</p>
<p style="text-align: center;"><a href="http://www.restfusion.com/blog/wp-content/uploads/2010/01/streaming.png"><img class="size-full wp-image-21 aligncenter" title="streaming" src="http://www.restfusion.com/blog/wp-content/uploads/2010/01/streaming.png" alt="" width="423" height="226" /></a></p>
<p>This seems to be better approach that previous one, we eliminate polling, and once subscribed, we won&#8217;t miss communicates. So how Our servlet would look like? Exactly like before:</p>
<pre class="brush: java">
@WebServlet(urlPatterns = &quot;/streamingQuoteService&quot;, asyncSupported=true)
public class StreamingStockServlet extends HttpServlet {

static MockStockQuoteService stockQuoteService = new MockStockQuoteService();
static ScheduledThreadPoolExecutor worker = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(1);

static {
worker.scheduleAtFixedRate(stockQuoteService, 0, 5, TimeUnit.SECONDS);
}

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
AsyncContext ctx = req.startAsync(req, resp);
stockQuoteService.addObserver(new StreamingQuoteObserver(ctx));
}
}
</pre>
<p>And here comes <code>StreamingQuoteObserver</code></p>
<pre class="brush: java">
public class StreamingQuoteObserver implements Observer {

private AsyncContext ctx;

public StreamingQuoteObserver(AsyncContext ctx) {
this.ctx = ctx;
}

public void update(Observable observable, Object arg) {
StockQuote quote = (StockQuote) observable;
try {
ctx.getResponse().setContentType(&quot;text/html&quot;);
Writer writer = ctx.getResponse().getWriter();
writer.write(&quot;&lt;span&gt;Symbol: &quot; + quote.getSymbol() + &quot;, Price &quot; + quote.getValue() +  &quot;&lt;/span&gt;&quot;);
writer.flush();
} catch (IOException e) { /* ignore */ }
}
}
</pre>
<p>Note that we keep connection open all the time (here is no <code>ctx.complete()</code>).  On client side we will get stream of events:</p>
<pre class="brush: html">
&lt;span&gt;Symbol: GOOG, Price 0.8843558760137272&lt;/span&gt;
&lt;span&gt;Symbol: GOOG, Price 0.30434186388689377&lt;/span&gt;
&lt;span&gt;Symbol: GOOG, Price 0.673062794397491&lt;/span&gt;
...
</pre>
<p>Now it&#8217;s client&#8217;s responsibility to parse incoming stream of events and update Our Stock Quote Widget. Unfortunately there <a href="http://ajaxpatterns.org/HTTP_Streaming">is no simple, reliable, standard way to do such a thing in modern browsers</a>. Basically most browser limit partial response retrieval. Note that, in previous example, this function</p>
<pre class="brush: javascript">
$.get(&quot;/jsr315/longPollingStock&quot;, {}, function ( data, status ) {
$(&quot;#quoteWidget&quot;).html(data);
longPoll();
} )
</pre>
<p>gets called when response is committed. That&#8217;s why this technique is somewhat limited right now. Of course we can still use this technique with other clients, including java ones. Here is how this looks like with <a href="http://curl.haxx.se/">curl</a>:</p>
<pre class="brush: php">
$ curl http://localhos:8080/jsr315/streamingQuoteService
&lt;span&gt;Symbol: GOOG, Price 0.8843558760137272&lt;/span&gt;
&lt;span&gt;Symbol: GOOG, Price 0.30434186388689377&lt;/span&gt;
&lt;span&gt;Symbol: GOOG, Price 0.673062794397491&lt;/span&gt;
...
</pre>
<h3>The Good, The Bad and the Ugly</h3>
<p>Let&#8217;s try to sum all above this. Definitely asynchronous servlets spec opens whole <a href="http://cometd.org/">new</a> <a href="http://svn.cometd.com/trunk/bayeux/bayeux.html">era</a> and possibilities. Historically few HTTP Servlet container vendors <a href="http://docs.codehaus.org/display/JETTY/Continuations">built</a> <a href="http://tomcat.apache.org/tomcat-6.0-doc/api/org/apache/catalina/CometProcessor.html">their</a> <a href="http://download.oracle.com/docs/cd/E13222_01/wls/docs92/javadocs/weblogic/servlet/http/AbstractAsyncServlet.html">own</a>, <a href="http://docs.sun.com/app/docs/doc/820-4496/ggrgt?a=view">incompatible</a> implementations. Now it&#8217;s standardized, and that&#8217;s probably makes JEE far ahead of competition in this matter. That&#8217;s good.</p>
<p>The bad thing is this whole new servlet processing model comes at a cost</p>
<ul>
<li>Some basic assumptions, which were true before are any more what would lead to some <a href="http://www.theserverside.com/news/thread.tss?thread_id=44466#228512">important implications</a></li>
<li>Also some simple things are <a href="http://blogs.webtide.com/gregw/entry/patterns_for_servlet_3_0#comment-1236003334000">not so simple anymore</a></li>
</ul>
<p>Here also comes the ugly bit. But it&#8217;s not necessarily associated with Servlet 3.0 spec, but rather with the architecture part.</p>
<p>You have probably noted before that HTTP streaming is <a href="http://ajaxpatterns.org/HTTP_Streaming">rather hard to achieve </a></p>
<p>But also it&#8217;s somehow <a href="http://cometd.org/node/81">hard to proxy Your asynchronous application through intermediaries</a>, which is really problematic since most companies I know front their application server through bunch of intermediaries (proxies, load balancers, application level firewalls etc.)</p>
<p>Here are also some <a href="http://cometdaily.com/2007/11/11/the-dreaded-2-connection-limit/">esoteric limitations</a> of HTTP spec, followed by some clients, which limit this approach also</p>
<p>But problems aside. I believe asynchronous servlets open new, broad horizons, but most likely average developer would not touch asynchronous API directly. In my opinion it is solid foundation for <a href="http://svn.cometd.com/trunk/bayeux/bayeux.html">higher level frameworks</a>, which will be subject of next instalment of this saga. Enjoy and stay tuned!</p>
<h3>Further reading</h3>
<p>If You are interested in this topic, I strongly recommend follow <a href="http://blogs.webtide.com/gregw/">Greg Wilkins</a> (of jetty fame) blog and <a href="http://cometd.org/">cometd.org</a>. This is valuable source of information, which this entry bases upon heavily.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.restfusion.com/blog/2010/01/why-asynchronous-servlets-matter-part-i/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
