<?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>Frequent incoherent cogitation</title>
	<atom:link href="http://vitamic.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://vitamic.wordpress.com</link>
	<description>the content of cognition</description>
	<lastBuildDate>Wed, 16 Nov 2011 22:05:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='vitamic.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Frequent incoherent cogitation</title>
		<link>http://vitamic.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://vitamic.wordpress.com/osd.xml" title="Frequent incoherent cogitation" />
	<atom:link rel='hub' href='http://vitamic.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Learn by intuition</title>
		<link>http://vitamic.wordpress.com/2007/04/23/learn-by-intuition/</link>
		<comments>http://vitamic.wordpress.com/2007/04/23/learn-by-intuition/#comments</comments>
		<pubDate>Mon, 23 Apr 2007 20:28:09 +0000</pubDate>
		<dc:creator>vitamic</dc:creator>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://vitamic.wordpress.com/2007/04/23/learn-by-intuition/</guid>
		<description><![CDATA[This is a very nice article by Steve Yegge.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vitamic.wordpress.com&amp;blog=655161&amp;post=15&amp;subd=vitamic&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://steve-yegge.blogspot.com/2006/03/math-for-programmers.html" title="Math for Programmers">This</a> is a very nice article by Steve Yegge.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/vitamic.wordpress.com/15/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/vitamic.wordpress.com/15/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vitamic.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vitamic.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vitamic.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vitamic.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vitamic.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vitamic.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vitamic.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vitamic.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vitamic.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vitamic.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vitamic.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vitamic.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vitamic.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vitamic.wordpress.com/15/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vitamic.wordpress.com&amp;blog=655161&amp;post=15&amp;subd=vitamic&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vitamic.wordpress.com/2007/04/23/learn-by-intuition/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4d5f945a897e190af8c0d4a6e1dd5f00?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vitamic</media:title>
		</media:content>
	</item>
		<item>
		<title>One click resizing of browser window in MAC</title>
		<link>http://vitamic.wordpress.com/2007/01/04/one-click-resizing-of-browser-window-in-mac/</link>
		<comments>http://vitamic.wordpress.com/2007/01/04/one-click-resizing-of-browser-window-in-mac/#comments</comments>
		<pubDate>Thu, 04 Jan 2007 02:23:28 +0000</pubDate>
		<dc:creator>vitamic</dc:creator>
				<category><![CDATA[Customization]]></category>
		<category><![CDATA[Desktop]]></category>
		<category><![CDATA[MAC]]></category>

		<guid isPermaLink="false">http://vitamic.wordpress.com/2007/01/04/one-click-resizing-of-browser-window-in-mac/</guid>
		<description><![CDATA[One problem I faced with my new MacBook Pro was not being able to maximize, minimize (or custom size) and re-center the firefox window with a click of a button. So I found some interesting tips online and finally came up with this solution Maximize bookmark (This will maximize your window) javascript:self.moveTo(0,0); self.resizeTo(screen.availWidth,screen.availHeight); To actually [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vitamic.wordpress.com&amp;blog=655161&amp;post=5&amp;subd=vitamic&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p> One problem I faced with my new MacBook Pro was not being able to maximize, minimize (or custom size) and re-center the firefox window with a click of a button. So I found some interesting tips online and finally came up with this solution<span id="more-5"></span></p>
<ol>
<li><span style="font-weight:bold;">Maximize bookmark</span> (This will maximize your window)
<pre><code>javascript:self.moveTo(0,0);
self.resizeTo(screen.availWidth,screen.availHeight);</code></pre>
</li>
<li>To actually get the maximum sizes of your window run this <a href="alertSize();">script</a> (the reason is that the screen.availHeight is not the same as your screen resolution)
<pre><code>function alertSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    <span class="comment">//Non-IE</span>
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement &amp;&amp; ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    <span class="comment">//IE 6+ in 'standards compliant mode'</span>
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body &amp;&amp; ( document.body.clientWidth || document.body.clientHeight ) ) {
    <span class="comment">//IE 4 compatible</span>
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  window.alert( 'Width = ' + myWidth );
  window.alert( 'Height = ' + myHeight );
}</code></pre>
<p>Once you figure out the max dimensions here are some bookmarks you can add to get the job done</li>
<li><span style="font-weight:bold;">Re-Center bookmark</span> (If the screen width or height is not the same as the maximum resolution of your screen then use the values you got from the above script here. For example: my screen resolution is 1400 X 900 but the actual size of the document is 1400 X 749)
<pre><code>javascript:var width = (screen.width - window.innerWidth) / 2;
var height = (749 - window.innerHeight) / 2;
self.moveTo(width, height);</code></pre>
</li>
<li><span style="font-weight:bold;">Custom size bookmark</span> (with the window centered). In the example below I choose a 900 X 600 dimension for my window which you can replace with width and size of your choice.
<pre><code>javascript:self.resizeTo(900, 600);
var width = (screen.width - window.innerWidth) / 2;
var height = (749 - window.innerHeight) / 2;
self.moveTo(width, height);</code></pre>
</li>
</ol>
<p>This definitely works in FireFox and I assume it will also work in Safari with minor tweaks (like maybe using screen.availHeight instead of screen.height etc&#8230;)</p>
<p>NOTE: If you are a developer like I am and you are using FireBug or any other type of  firefox extensions that take some space within the browser, then you might have to close or hide those extensions when running any of the scripts mentioned above. Otherwise the results may not be as expected for the obvious reasons.</p>
<p>Enjoy!</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/vitamic.wordpress.com/5/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/vitamic.wordpress.com/5/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vitamic.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vitamic.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vitamic.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vitamic.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vitamic.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vitamic.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vitamic.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vitamic.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vitamic.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vitamic.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vitamic.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vitamic.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vitamic.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vitamic.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vitamic.wordpress.com&amp;blog=655161&amp;post=5&amp;subd=vitamic&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vitamic.wordpress.com/2007/01/04/one-click-resizing-of-browser-window-in-mac/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4d5f945a897e190af8c0d4a6e1dd5f00?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vitamic</media:title>
		</media:content>
	</item>
		<item>
		<title>Serving fast and effective static content</title>
		<link>http://vitamic.wordpress.com/2007/01/04/serving-fast-and-effective-static-content/</link>
		<comments>http://vitamic.wordpress.com/2007/01/04/serving-fast-and-effective-static-content/#comments</comments>
		<pubDate>Thu, 04 Jan 2007 02:16:57 +0000</pubDate>
		<dc:creator>vitamic</dc:creator>
				<category><![CDATA[Caching]]></category>
		<category><![CDATA[Dynamic Scripting]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Tech]]></category>

		<guid isPermaLink="false">http://vitamic.wordpress.com/2007/01/04/serving-fast-and-effective-static-content/</guid>
		<description><![CDATA[With AJAX becoming more and more popular most of us, developers, have to deal with static content like Javascript, CSS, IMG, XML etc&#8230; sooner or later. To improve the overall performance of the web application HTTP specification provide guidelines for caching the static content on the browser. Caching is very good because the browser doesn&#8217;t [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vitamic.wordpress.com&amp;blog=655161&amp;post=4&amp;subd=vitamic&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>With AJAX becoming more and more popular most of us, developers, have to deal with static content like Javascript, CSS, IMG, XML etc&#8230; sooner or later. To improve the overall performance of the web application HTTP specification provide guidelines for <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html">caching the static content</a> on the browser.</p>
<p>Caching is very good because the browser doesn&#8217;t have to query for the static content for every page request. Most popular browser like IE, FireFox, Safari, Opera first check their local cache for the static file/resource and only if they don&#8217;t find do they make a request to the webserver for the same.</p>
<p>With this arises a problem! What if I needs to update one of these static files? Can I force a browser to let go of the old cached instance of the same?</p>
<p>Well the answer is, the infamous, it depends <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> <span id="more-4"></span></p>
<p>If a static file like javascript, css, img etc&#8230; is cached by a browser with no expiry time then there is no way to update the browser cache other than the brute force way(purge the browser cache or force the browser to refresh the cache). What it means is that there is no way that a web server can force the browser to update its local cache.</p>
<p>On the other hand if there was an expiration time associated with the static file then next time the same instance is requested by a page and if it is expired then the browser will request for the latest from the web server.</p>
<p>But having an expiration time for the static content is not always a preferred or an elegant solution especially with some of the new AJAX application where most of the development is in Javascript and also because its hard to predict how often the content will change. Although in most of the applications I dealt with, an expiration period of a day did very well (not to forget the amount of excess traffic we received every morning)</p>
<p>In this post I will explain how we can handle this in a better, elegant , efficient and effective way.</p>
<p>Before we delve into the details I thought its worth mentioning that there are other options for getting this issue resolved (each with its own advantages and disadvantages)</p>
<p>Here are a few of them</p>
<ol>
<li><span style="font-weight:bold;">Brute Force : </span>CTRL-R (or F5) or whatever the keyboard mapping is to force refresh a page. Another brute fore way is to clear the browser cache every time there is a change. This is plain and simple but not practical in real world and I certainly don&#8217;t approve of this. Obviously we cannot ask each and every person using the web application to do this every time a new version is deployed.</li>
<li><span style="font-weight:bold;">Force no-cache</span> : In this approach Update the HTTP Headers to not cache anything (Cache-Control: no-cache). This is a crude way of fixing this problem. With AJAX becoming more and more popular these days the size and number of javascript files is increasing more than ever. So if every page request has to fetch all the static files it can affect the performance of the application.</li>
<li><span style="font-weight:bold;">Expire Cache</span> : Update the HTTP Headers to cache the files for  only a certain period of time (Cache-Control: max-age= &lt;in future&gt;) after which the resource will expire and the browser is forced to fetch a new one.This approach also can get tricky based on what should the actual expiry time be like. Should the expiration be an hour, a day, a week or a month? Well it depends on the application and how often the file changes but still it will never be perfect. There will always be a window of opportunity where the file can be stale. Nevertheless this approach will suite most of the applications that don&#8217;t change very often.</li>
<li><strong>Versioning static files</strong> : By versioning what I  mean is to add some kind of dynamic data to the static file names. Here are few ways of doing this
<ul>
<li>Add timestamp to the file name. For example: instead of &lt;script src=&#8221;js/prototype.js&#8221;&gt; make it &lt;script src=&#8221;js/prototype.js?12345455&#8243;&gt;.</li>
<li>Move all the static files into a sub folder with a number like &#8220;12/js/prototype.js&#8221; instead of just &#8220;js/protoype.js&#8221; and for every release (or deployment) bump the number up by one. This approach is good but there are couple of issues. One of which is that all the files under that directory need to be refreshed even if only one of then were changed. Another issue is that your app should be built in such a way that you can make changes like this without having to modify every file that includes these static files.</li>
<li>The third way is to update the versions of only the files that were modified. We&#8217;ll talk about this in detail below.</li>
</ul>
</li>
</ol>
<p>Of all these approaches I like the 3rd approach in &#8220;Versioning static files&#8221;. Now how can we achieve this in J2EE world?</p>
<p>First, the idea is to move the logic of versioning away from all the JSP&#8217;s that include it. So everytime we change the version of a static file its reflected in all the including JSP&#8217;s. The best way to do this is by using custom tag libraries.</p>
<p>So lets start with a simple JSP (prior to versioning)</p>
<p><code><br />
<font color="#3333ff">&lt;!</font><font color="#666666">DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</font>"<font color="#3333ff">&gt;</font></code></p>
<p>&lt;%@ <font color="#3333ff">include</font> file=<font color="#009900">&#8220;</font><font color="#009900">/common/taglibs.jsp&#8221;</font>%&gt;<br />
<font color="#3333ff">&lt;html&gt;<br />
&lt;head&gt;</font><br />
&lt;%@ include file=&#8221;/common/meta.jsp&#8221; %&gt;<br />
<font color="#3333ff">&lt;title&gt;&lt;fmt:message key=</font><font color="#009900">&#8220;webapp.name&#8221;</font><font color="#3333ff">/&gt;&lt;/title&gt;</font><br />
<font color="#3333ff">&lt;link rel=</font><font color="#009900">&#8220;shortcut icon&#8221;</font> <font color="#3333ff">href=</font><font color="#009900">&#8220;&lt;c:url value=&#8221;/favicon.ico&#8221;/&gt;&#8221;</font><font color="#000099"><font color="#3333ff">/&gt;<br />
&lt;link rel=<font color="#009900">&#8220;stylesheet&#8221;<font color="#3333ff"> type=<font color="#009900">&#8220;text/css&#8221; <font color="#3333ff">href=</font></font></font></font></font></font><code><font color="#009900">"&lt;c:url value="/css/style.css"/&gt;"</font></code><code><font color="#000099"><font color="#3333ff">/&gt;<br />
&lt;script type=</font></font></code><code><font color="#000099"><font color="#3333ff"><font color="#009900"><font color="#3333ff"><font color="#009900">"text/javascript" </font></font></font></font></font></code><code><font color="#000099"><font color="#3333ff"><font color="#009900"><font color="#3333ff"><font color="#009900"><font color="#3333ff">src=</font></font></font></font></font></font></code><code></code><code><font color="#009900">"&lt;c:url value="/js/prototype.js"/&gt;"</font></code><code><font color="#000099"><font color="#3333ff">&gt;&lt;/script&gt;</font></font></code><code><br />
<font color="#3333ff">&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;div class="main"&gt;<br />
</font></code><font color="#999999">&#8230;</font></p>
<p><code><font color="#3333ff">&lt;/div&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
</font></code></p>
<p>To add versioning using custom tag library, the above should look like this</p>
<p><code><font color="#3333ff"><br />
&lt;!</font><font color="#666666">DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</font>"<font color="#3333ff">&gt;</font></code></p>
<p>&lt;%@ <font color="#3333ff">include</font> file=<font color="#009900">&#8220;</font><font color="#009900">/common/taglibs.jsp&#8221;</font>%&gt;<br />
<font color="#cc0000">&lt;%@ taglib prefix=&#8221;ut&#8221; uri=&#8221;/WEB-INF/utils.tld&#8221; %&gt;</font><br />
<font color="#3333ff">&lt;html&gt;<br />
&lt;head&gt;</font><br />
&lt;%@ include file=&#8221;/common/meta.jsp&#8221; %&gt;<br />
<font color="#3333ff">&lt;title&gt;&lt;fmt:message key=</font><font color="#009900">&#8220;webapp.name&#8221;</font><font color="#3333ff">/&gt;&lt;/title&gt;</font><br />
<font color="#3333ff">&lt;link rel=</font><font color="#009900">&#8220;shortcut icon&#8221;</font> <font color="#3333ff">href=</font><font color="#009900">&#8220;&lt;c:url value=&#8221;/favicon.ico&#8221;/&gt;&#8221;</font><font color="#000099"><font color="#3333ff">/&gt;</font></font><code></code><br />
<code><font color="#cc0000">    &lt;ut:include type="css"&gt;&lt;c:url value="/css/style.css"/&gt;&lt;/ut:include&gt;<br />
&lt;ut:include type="js"&gt;&lt;c:url value="/js/js.js"/&gt;&lt;/ut:include&gt;<br />
</font> <font color="#3333ff">&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;div class="main"&gt;<br />
</font></code><font color="#999999">&#8230;</font></p>
<p><code><font color="#3333ff">&lt;/div&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</font></code></p>
<p>Here is the utils.tld</p>
<p><code><br />
<font color="#3333ff"><font color="#666666">&lt;?xml version=</font><font color="#666666">"1.0" encoding="UTF-8" ?&gt;</font><br />
&lt;taglib xmlns=<font color="#009900">"http://java.sun.com/xml/ns/j2ee"</font><br />
xmlns:xsi=<font color="#009900">"http://www.w3.org/2001/XMLSchema-instance"</font><br />
xsi:schemaLocation=<font color="#009900">"http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"</font><br />
version=<font color="#009900">"2.0"</font>&gt;</font></code></p>
<p><font color="#3333ff">  &lt;description&gt;<font color="#333333">Versioning util library</font>&lt;/description&gt;<br />
&lt;display-name<font color="#333333">&gt;</font><font color="#333333">versioning&lt;/</font>display-name&gt;<br />
&lt;tlib-version&gt;<font color="#333333">1.1</font>&lt;/tlib-version&gt;</font></p>
<p><font color="#3333ff">  &lt;short-name&gt;<font color="#333333">ut</font>&lt;/short-name&gt;<br />
&lt;uri&gt;<font color="#333333">http://www.example.org/taglibs/utils</font>&lt;/uri&gt;</font></p>
<p><font color="#3333ff">  &lt;tag&gt;<br />
&lt;name&gt;<font color="#333333">include</font>&lt;/name&gt;<br />
&lt;tag-class&gt;<font color="#333333">org.example.tags.IncludeTag</font>&lt;/tag-class&gt;<br />
&lt;body-content&gt;<font color="#333333">JSP</font>&lt;/body-content&gt;<br />
&lt;attribute&gt;<br />
&lt;name&gt;<font color="#333333">url</font>&lt;/name&gt;<br />
&lt;required&gt;<font color="#333333">false</font>&lt;/required&gt;<br />
&lt;rtexprvalue&gt;<font color="#333333">true</font>&lt;/rtexprvalue&gt;<br />
&lt;/attribute&gt;<br />
&lt;attribute&gt;<br />
&lt;name&gt;<font color="#333333">type</font>&lt;/name&gt;<br />
&lt;required&gt;<font color="#333333">true</font>&lt;/required&gt;<br />
&lt;rtexprvalue&gt;<font color="#333333">false</font>&lt;/rtexprvalue&gt;<br />
&lt;/attribute&gt;<br />
&lt;attribute&gt;<br />
&lt;name&gt;<font color="#333333">params</font>&lt;/name&gt;<br />
&lt;required&gt;<font color="#333333">false</font>&lt;/required&gt;<br />
&lt;rtexprvalue&gt;<font color="#333333">false</font>&lt;/rtexprvalue&gt;<br />
&lt;/attribute&gt;<br />
&lt;/tag&gt;<br />
&lt;/taglib&gt;</font></p>
<p>Now lets see the implementation of org.example.tags.IncludeTag</p>
<p class="java" align="left">
<table bgcolor="#ffffff" border="0" cellpadding="3" cellspacing="0" width="281">
<tr>
<td align="left" nowrap="nowrap" valign="top"><code><br />
<font color="#7f0055"><strong>package </strong></font><font color="#000000">org.example.tags;</font> </code><font color="#7f0055"><strong>import </strong></font><font color="#000000">java.io.IOException;</font><br />
<font color="#7f0055"><strong>import </strong></font><font color="#000000">java.util.HashMap;</font><br />
<font color="#7f0055"><strong>import </strong></font><font color="#000000">java.util.Map;</font><font color="#7f0055"><strong>import </strong></font><font color="#000000">javax.servlet.jsp.tagext.BodyTagSupport;</font></p>
<p><font color="#3f5fbf">/**</font><br />
<font color="#ffffff"> </font><font color="#3f5fbf">* Demonstrates how to use versioning for static content.<br />
* In this example the static file and its version numbers are stored<br />
* as key values pairs but in real-time it makes sense to have this information<br />
* in a file (which probably is generated using a script). These version numbers<br />
* can be random or can be the real version numbers from the source control.<br />
</font><font color="#ffffff"> </font><font color="#3f5fbf">*/</font><br />
<font color="#7f0055"><strong>public class </strong></font><font color="#000000">IncludeTag </font><font color="#7f0055"><strong>extends </strong></font><font color="#000000">BodyTagSupport </font><font color="#000000">{</font><br />
<font color="#ffffff">  </font><font color="#7f0055"><strong>private </strong></font><font color="#000000">String url = </font><font color="#7f0055"><strong>null</strong></font><font color="#000000">;</font><br />
<font color="#ffffff">  </font><font color="#7f0055"><strong>private </strong></font><font color="#000000">String type = </font><font color="#7f0055"><strong>null</strong></font><font color="#000000">;</font><br />
<font color="#ffffff">  </font><font color="#7f0055"><strong>private </strong></font><font color="#000000">String params = </font><font color="#7f0055"><strong>null</strong></font><font color="#000000">;</font><br />
<font color="#ffffff">  </font><font color="#7f0055"><strong>private static final </strong></font><font color="#000000">Map&lt;String, String&gt; versions = </font><font color="#7f0055"><strong>new </strong></font><font color="#000000">HashMap&lt;String, String&gt;</font><font color="#000000">()</font><font color="#000000">;</font></p>
<p><font color="#ffffff">  </font><font color="#3f7f5f">// Javascript versions</font><br />
<font color="#ffffff">  </font><font color="#7f0055"><strong>static </strong></font><font color="#000000">{</font><br />
<font color="#ffffff">    </font><font color="#000000">versions.put</font><font color="#000000">(</font><font color="#2a00ff">&#8220;/js/js.js&#8221;</font><font color="#000000">, </font><font color="#2a00ff">&#8220;113&#8243;</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">    </font><font color="#000000">versions.put</font><font color="#000000">(</font><font color="#2a00ff">&#8220;/js/prototype.js&#8221;</font><font color="#000000">, </font><font color="#2a00ff">&#8220;159&#8243;</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">  </font><font color="#000000">}</font></p>
<p><font color="#ffffff">  </font><font color="#3f7f5f">// CSS Versions</font><br />
<font color="#ffffff">  </font><font color="#7f0055"><strong>static </strong></font><font color="#000000">{</font><br />
<font color="#ffffff">    </font><font color="#000000">versions.put</font><font color="#000000">(</font><font color="#2a00ff">&#8220;/css/style.css&#8221;</font><font color="#000000">, </font><font color="#2a00ff">&#8220;158&#8243;</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">    </font><font color="#000000">versions.put</font><font color="#000000">(</font><font color="#2a00ff">&#8220;/css/tabber.css&#8221;</font><font color="#000000">, </font><font color="#2a00ff">&#8220;126&#8243;</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">  </font><font color="#000000">}</font></p>
<p><font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#000000">String getUrl</font><font color="#000000">() {</font><br />
<font color="#ffffff">    </font><font color="#7f0055"><strong>return this</strong></font><font color="#000000">.url;</font><br />
<font color="#ffffff">  </font><font color="#000000">}</font></p>
<p><font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#7f0055"><strong>void </strong></font><font color="#000000">setUrl</font><font color="#000000">(</font><font color="#000000">String url</font><font color="#000000">) {</font><br />
<font color="#ffffff">    </font><font color="#7f0055"><strong>this</strong></font><font color="#000000">.url = url;</font><br />
<font color="#ffffff">  </font><font color="#000000">}</font></p>
<p><font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#000000">String getType</font><font color="#000000">() {</font><br />
<font color="#ffffff">    </font><font color="#7f0055"><strong>return </strong></font><font color="#000000">type;</font><br />
<font color="#ffffff">    </font><font color="#3f7f5f">//return getUrl().substring(getUrl().indexOf(&#8220;.&#8221;) + 1);</font><br />
<font color="#ffffff">  </font><font color="#000000">}</font></p>
<p><font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#7f0055"><strong>void </strong></font><font color="#000000">setType</font><font color="#000000">(</font><font color="#000000">String type</font><font color="#000000">) {</font><br />
<font color="#ffffff">    </font><font color="#7f0055"><strong>this</strong></font><font color="#000000">.type = type;</font><br />
<font color="#ffffff">  </font><font color="#000000">}</font></p>
<p><font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#000000">String getParams</font><font color="#000000">() {</font><br />
<font color="#ffffff">    </font><font color="#7f0055"><strong>return </strong></font><font color="#000000">params;</font><br />
<font color="#ffffff">  </font><font color="#000000">}</font></p>
<p><font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#7f0055"><strong>void </strong></font><font color="#000000">setParams</font><font color="#000000">(</font><font color="#000000">String params</font><font color="#000000">) {</font><br />
<font color="#ffffff">    </font><font color="#7f0055"><strong>this</strong></font><font color="#000000">.params = params;</font><br />
<font color="#ffffff">  </font><font color="#000000">}</font><font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#7f0055"><strong>int </strong></font><font color="#000000">doEndTag</font><font color="#000000">() {</font><br />
<font color="#ffffff">    </font><font color="#7f0055"><strong>try </strong></font><font color="#000000">{</font><br />
<font color="#ffffff">      </font><font color="#7f0055"><strong>if </strong></font><font color="#000000">(</font><font color="#000000">bodyContent == </font><font color="#7f0055"><strong>null </strong></font><font color="#000000">|| bodyContent.getString</font><font color="#000000">() </font><font color="#000000">== </font><font color="#7f0055"><strong>null</strong></font><font color="#000000">) {</font><br />
<font color="#ffffff">        </font><font color="#000000">url = </font><font color="#2a00ff">&#8220;&#8221;</font><font color="#000000">;</font><br />
<font color="#ffffff">      </font><font color="#000000">}</font><br />
<font color="#ffffff">      </font><font color="#7f0055"><strong>else </strong></font><font color="#000000">{</font><br />
<font color="#ffffff">        </font><font color="#000000">url = bodyContent.getString</font><font color="#000000">()</font><font color="#000000">.trim</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">      </font><font color="#000000">}</font><br />
<font color="#ffffff">      </font><font color="#000000">StringBuffer buf = </font><font color="#7f0055"><strong>new </strong></font><font color="#000000">StringBuffer</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">      </font><font color="#7f0055"><strong>final </strong></font><font color="#000000">String type = getType</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">      </font><font color="#7f0055"><strong>if </strong></font><font color="#000000">(</font><font color="#000000">type.equalsIgnoreCase</font><font color="#000000">(</font><font color="#2a00ff">&#8220;js&#8221;</font><font color="#000000">)) {</font><br />
<font color="#ffffff">        </font><font color="#000000">buf.append</font><font color="#000000">(</font><font color="#2a00ff">&#8220;&lt;script type=\&#8221;text/javascript\&#8221; src=\&#8221;"</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">        </font><font color="#000000">buf.append</font><font color="#000000">(</font><font color="#000000">getSource</font><font color="#000000">())</font><font color="#000000">;</font><br />
<font color="#ffffff">        </font><font color="#000000">buf.append</font><font color="#000000">(</font><font color="#2a00ff">&#8220;\&#8221;/&gt;&lt;/script&gt;&#8221;</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">      </font><font color="#000000">}</font><br />
<font color="#ffffff">      </font><font color="#7f0055"><strong>else if</strong></font><font color="#000000">(</font><font color="#000000">type.equalsIgnoreCase</font><font color="#000000">(</font><font color="#2a00ff">&#8220;css&#8221;</font><font color="#000000">)) {</font><br />
<font color="#ffffff">        </font><font color="#000000">buf.append</font><font color="#000000">(</font><font color="#2a00ff">&#8220;&lt;link rel=\&#8221;stylesheet\&#8221; href=\&#8221;"</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">        </font><font color="#000000">buf.append</font><font color="#000000">(</font><font color="#000000">getSource</font><font color="#000000">())</font><font color="#000000">;</font><br />
<font color="#ffffff">        </font><font color="#000000">buf.append</font><font color="#000000">(</font><font color="#2a00ff">&#8220;\&#8221; type=\&#8221;text/css\&#8221; media=\&#8221;screen, projection\&#8221;/&gt;&#8221;</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">      </font><font color="#000000">}</font></p>
<p><font color="#ffffff">      </font><font color="#000000">pageContext.getOut</font><font color="#000000">()</font><font color="#000000">.println</font><font color="#000000">(</font><font color="#000000">buf.toString</font><font color="#000000">())</font><font color="#000000">;</font><br />
<font color="#ffffff">    </font><font color="#000000">} </font><font color="#7f0055"><strong>catch </strong></font><font color="#000000">(</font><font color="#000000">IOException ignored</font><font color="#000000">) {}</font><br />
<font color="#ffffff">    </font><font color="#7f0055"><strong>return </strong></font><font color="#000000">EVAL_PAGE;</font><br />
<font color="#ffffff">  </font><font color="#000000">}</font></p>
<p><font color="#ffffff">  </font><font color="#3f5fbf">/**</font><br />
<font color="#ffffff">   </font><font color="#3f5fbf">* Returns the source value that can be included in the script src<br />
* attribute of css href attribute.<br />
</font><font color="#ffffff">   </font><font color="#3f5fbf">* </font><font color="#7f9fbf">@return</font><br />
<font color="#ffffff">   </font><font color="#3f5fbf">*/</font><br />
<font color="#ffffff">  </font><font color="#7f0055"><strong>protected </strong></font><font color="#000000">String getSource</font><font color="#000000">() {</font><br />
<font color="#ffffff">    </font><font color="#000000">StringBuffer buf = </font><font color="#7f0055"><strong>new </strong></font><font color="#000000">StringBuffer</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">    </font><font color="#000000">buf.append</font><font color="#000000">(</font><font color="#000000">getUrl</font><font color="#000000">())</font><font color="#000000">;</font><br />
<font color="#ffffff">    </font><font color="#000000">String version = getVersion</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">    </font><font color="#7f0055"><strong>if </strong></font><font color="#000000">(</font><font color="#000000">version != </font><font color="#7f0055"><strong>null</strong></font><font color="#000000">) {</font><br />
<font color="#ffffff">      </font><font color="#000000">buf.append</font><font color="#000000">(</font><font color="#2a00ff">&#8220;?v=&#8221; </font><font color="#000000">+ version</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">    </font><font color="#000000">}</font><br />
<font color="#ffffff">    </font><font color="#7f0055"><strong>if </strong></font><font color="#000000">(</font><font color="#000000">getParams</font><font color="#000000">() </font><font color="#000000">!= </font><font color="#7f0055"><strong>null</strong></font><font color="#000000">) {</font><br />
<font color="#ffffff">      </font><font color="#7f0055"><strong>if</strong></font><font color="#000000">(</font><font color="#000000">version == </font><font color="#7f0055"><strong>null</strong></font><font color="#000000">) {</font><br />
<font color="#ffffff">        </font><font color="#000000">buf.append</font><font color="#000000">(</font><font color="#2a00ff">&#8220;?&#8221;</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">      </font><font color="#000000">}</font><br />
<font color="#ffffff">      </font><font color="#7f0055"><strong>else </strong></font><font color="#000000">{</font><br />
<font color="#ffffff">        </font><font color="#000000">buf.append</font><font color="#000000">(</font><font color="#2a00ff">&#8220;&amp;&#8221;</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">      </font><font color="#000000">}</font><br />
<font color="#ffffff">      </font><font color="#000000">buf.append</font><font color="#000000">(</font><font color="#000000">getParams</font><font color="#000000">())</font><font color="#000000">;</font><br />
<font color="#ffffff">    </font><font color="#000000">}</font></p>
<p><font color="#ffffff">    </font><font color="#7f0055"><strong>return </strong></font><font color="#000000">buf.toString</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">  </font><font color="#000000">}</font></p>
<p><font color="#ffffff">  </font><font color="#3f5fbf">/**</font><br />
<font color="#ffffff">   </font><font color="#3f5fbf">* Returns the version number of this file</font><br />
<font color="#ffffff">   </font><font color="#3f5fbf">* </font><font color="#7f9fbf">@return</font><br />
<font color="#ffffff">   </font><font color="#3f5fbf">*/</font><br />
<font color="#ffffff">  </font><font color="#7f0055"><strong>protected </strong></font><font color="#000000">String getVersion</font><font color="#000000">() {</font><br />
<font color="#ffffff">    </font><font color="#7f0055"><strong>return </strong></font><font color="#000000">versions.get</font><font color="#000000">(</font><font color="#000000">getUrl</font><font color="#000000">())</font><font color="#000000">;</font><br />
<font color="#ffffff">  </font><font color="#000000">}</font><br />
<font color="#000000">}</font></td>
</tr>
</table>
<p>So now everytime you have to make a new release just bump up the version numbers of all the files that have been changed and you no longer have to worry about stale or conflicting static files.</p>
<p><strong>Resources</strong></p>
<ol>
<li>http://www.thinkvitamin.com/features/webapps/serving-javascript-fast</li>
<li>http://www.websiteoptimization.com/speed/tweak/cache/</li>
<li>http://java.sun.com/products/jsp/tutorial/TagLibrariesTOC.html</li>
</ol>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/vitamic.wordpress.com/4/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/vitamic.wordpress.com/4/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vitamic.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vitamic.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vitamic.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vitamic.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vitamic.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vitamic.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vitamic.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vitamic.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vitamic.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vitamic.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vitamic.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vitamic.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vitamic.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vitamic.wordpress.com/4/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vitamic.wordpress.com&amp;blog=655161&amp;post=4&amp;subd=vitamic&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vitamic.wordpress.com/2007/01/04/serving-fast-and-effective-static-content/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4d5f945a897e190af8c0d4a6e1dd5f00?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vitamic</media:title>
		</media:content>
	</item>
		<item>
		<title>Anemic Domain Model Illustrated</title>
		<link>http://vitamic.wordpress.com/2007/01/04/anemic-domain-model-illustrated/</link>
		<comments>http://vitamic.wordpress.com/2007/01/04/anemic-domain-model-illustrated/#comments</comments>
		<pubDate>Thu, 04 Jan 2007 00:55:02 +0000</pubDate>
		<dc:creator>vitamic</dc:creator>
				<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[J2EE]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[Tech]]></category>

		<guid isPermaLink="false">http://vitamic.wordpress.com/2007/01/04/anemic-domain-model-illustrated/</guid>
		<description><![CDATA[One thing that keeps coming back to me time and again, something that people often misunderstand, at least in my opinion, is Anemic Domain Model. Martin Fowler wrote an excellent article about this but I would like to illustrate, as I understand, what best describes an Anemic Domain Model through an example. Stripping off domain [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vitamic.wordpress.com&amp;blog=655161&amp;post=3&amp;subd=vitamic&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>One thing that keeps coming back to me time and again, something that people often misunderstand, at least in my opinion, is Anemic Domain Model. Martin Fowler wrote an excellent <a href="http://www.martinfowler.com/bliki/AnemicDomainModel.html">article</a> about this but I would like to illustrate, as I understand, what best describes an Anemic Domain Model through an example.</p>
<p>Stripping off domain logic from Domain Model is what is &#8220;Anemic Domain&#8221; and as Martin Fowler said, quote <span style="color:#009900;">domain logic is the antidote to domain anemia</span> unquote.<span id="more-3"></span></p>
<p>Lets take for example an Account object. Anemic Domain Account looks something like this (in Java world you would call it a Java bean)</p>
<p class="java" align="left">
<table bgcolor="#ffffff" border="0" cellpadding="3" cellspacing="0">
<tr>
<td align="left" nowrap="nowrap" valign="top"><code><font color="#7f0055"><strong>class </strong></font><font color="#000000">Account </font><font color="#000000">{</font><br />
<font color="#ffffff">  </font><font color="#7f0055"><strong>private </strong></font><font color="#7f0055"><strong>double </strong></font><font color="#000000">balance;</font><br />
<font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#7f0055"><strong>double </strong></font><font color="#000000">getBalance</font><font color="#000000">() {</font><br />
<font color="#ffffff">    </font><font color="#7f0055"><strong>return </strong></font><font color="#000000">balance;</font><br />
<font color="#ffffff">  </font><font color="#000000">}</font><br />
<font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#7f0055"><strong>void </strong></font><font color="#000000">setBalance</font><font color="#000000">(</font><font color="#7f0055"><strong>double </strong></font><font color="#000000">balance</font><font color="#000000">) {</font><br />
<font color="#ffffff">    </font><font color="#7f0055"><strong>this</strong></font><font color="#000000">.balance = balance;</font><br />
<font color="#ffffff">  </font><font color="#000000">}</font> </code></td>
</tr>
</table>
<table bgcolor="#ffffff" border="0" cellpadding="3" cellspacing="0" width="268">
<tr>
<td align="left" nowrap="nowrap" valign="top"><code><font color="#7f0055"><strong>class </strong></font><font color="#000000">AccountService </font><font color="#000000">{</font><br />
<font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#7f0055"><strong>void </strong></font><font color="#000000">debit</font><font color="#000000">(</font><font color="#000000">Account account, </font><font color="#7f0055"><strong>double </strong></font><font color="#000000">amount</font><font color="#000000">) {</font><br />
<font color="#ffffff">    </font><font color="#000000">account.setBalance</font><font color="#000000">(</font><font color="#000000">account.getBalance</font><font color="#000000">() </font><font color="#000000">- </font></code><code><font color="#000000">amount</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">  </font><font color="#000000">}</font><br />
<font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#7f0055"><strong>void </strong></font><font color="#000000">credit</font><font color="#000000">(</font><font color="#000000">Account account, </font><font color="#7f0055"><strong>double </strong></font><font color="#000000">amount</font><font color="#000000">) {</font><br />
<font color="#ffffff">     </font><font color="#000000">account.setBalance</font><font color="#000000">(</font><font color="#000000">account.getBalance</font><font color="#000000">() </font><font color="#000000">+ amount</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">  </font><font color="#000000">}</font><br />
<font color="#000000">}</font></code></td>
</tr>
</table>
<p>As shown above the object Account acts just as a place holder for &#8220;balance&#8221;. In this model most probably some kind of service object (AccountService) sets and gets the value of the balance to reflect any changes to the balance. This is very luring because its pretty straight forward. What makes this Anemic is there is no behavior associated with this Account object itself. So lets add the antidote to this and make it come alive</p>
<p class="java" align="left">
<table bgcolor="#ffffff" border="0" cellpadding="3" cellspacing="0">
<tr>
<td align="left" nowrap="nowrap" valign="top"><code><font color="#7f0055"><strong>class </strong></font><font color="#000000">Account </font><font color="#000000">{</font><br />
<font color="#ffffff">  </font><font color="#7f0055"><strong>private </strong></font><font color="#7f0055"><strong>double </strong></font><font color="#000000">balance;</font><br />
<font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#7f0055"><strong>double </strong></font><font color="#000000">getBalance</font><font color="#000000">() {</font><br />
<font color="#ffffff">    </font><font color="#7f0055"><strong>return </strong></font><font color="#000000">balance;</font><br />
<font color="#ffffff">  </font><font color="#000000">}</font><br />
<font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#7f0055"><strong>double </strong></font><font color="#000000">setBalance</font><font color="#000000">(</font><font color="#7f0055"><strong>double </strong></font><font color="#000000">balance</font><font color="#000000">) {</font><br />
<font color="#ffffff">    </font><font color="#7f0055"><strong>this</strong></font><font color="#000000">.balance = balance;</font><br />
<font color="#ffffff">  </font><font color="#000000">}</font><br />
<font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#7f0055"><strong>double </strong></font><font color="#3333ff">credit</font><font color="#000000">(</font><font color="#7f0055"><strong>double </strong></font><font color="#000000">amount</font><font color="#000000">) {</font><br />
<font color="#ffffff">    </font><font color="#7f0055"><strong>this</strong></font><font color="#000000">.balance += amount;</font><br />
<font color="#ffffff">  </font><font color="#000000">}</font><br />
<font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#7f0055"><strong>double </strong></font><font color="#3333ff">debit</font><font color="#000000">(</font><font color="#7f0055"><strong>double </strong></font><font color="#000000">amount</font><font color="#000000">) {</font><br />
<font color="#ffffff">    </font><font color="#7f0055"><strong>this</strong></font><font color="#000000">.balance -= amount;</font><br />
<font color="#ffffff">  </font><font color="#000000">}</font><br />
<font color="#000000">}</font></code></td>
</tr>
</table>
<p>Now we are talking. We added some behavior to the Account object. In the anemic domain model these methods (credit, debit) are implemented in the service layer as shown above.</p>
<p>What are we really missing in the Anemic version of Account?</p>
<p>Well to answer that question lets assume that we have different types of accounts, RegularAccount and PlatinumAccount.</p>
<p>In the Anemic Version they would look something like this</p>
<p class="java" align="left">
<table bgcolor="#ffffff" border="0" cellpadding="3" cellspacing="0">
<tr>
<td align="left" nowrap="nowrap" valign="top"><code><font color="#7f0055"><strong>class </strong></font><font color="#000000">RegularAccount </font><font color="#7f0055"><strong>extends </strong></font><font color="#000000">Account </font><font color="#000000">{</font><br />
<font color="#ffffff">  </font><font color="#7f0055"><strong>private </strong></font><font color="#7f0055"><strong>double </strong></font><font color="#000000">overdraftPenalty = </font><font color="#990000">30.00</font><font color="#000000">;</font><br />
<font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#7f0055"><strong>double </strong></font><font color="#000000">getOverdraftPenalty</font><font color="#000000">() {</font><br />
<font color="#ffffff">    </font><font color="#7f0055"><strong>return </strong></font><font color="#000000">overdraftPenalty;</font><br />
<font color="#ffffff">  </font><font color="#000000">}</font><br />
<font color="#000000">}</font></code></td>
</tr>
</table>
<table bgcolor="#ffffff" border="0" cellpadding="3" cellspacing="0">
<tr>
<td align="left" nowrap="nowrap" valign="top"><code> <font color="#7f0055"><strong>class </strong></font><font color="#000000">PlatinumAccount </font><font color="#7f0055"><strong>extends </strong></font><font color="#000000">Account </font><font color="#000000">{</font><br />
<font color="#ffffff">  </font><font color="#7f0055"><strong>private </strong></font><font color="#7f0055"><strong>double </strong></font><font color="#000000">interest = </font><font color="#990000">0.1</font><font color="#000000">;</font><br />
<font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#7f0055"><strong>double </strong></font><font color="#000000">getInterest</font><font color="#000000">() {</font><br />
<font color="#ffffff">    </font><font color="#7f0055"><strong>return </strong></font><font color="#000000">interest;</font><br />
<font color="#ffffff">  </font><font color="#000000">}</font><br />
<font color="#000000">}</font></code></td>
</tr>
</table>
<p>So what is the problem here?</p>
<p>Lets say that all PlatinumAccounts, currently, have overdraft protection and RegularAccounts don&#8217;t. Then the withdraw methods in the service layer would look something like this</p>
<p class="java" align="left">
<table bgcolor="#ffffff" border="0" cellpadding="3" cellspacing="0">
<tr>
<td align="left" nowrap="nowrap" valign="top"><code> <font color="#7f0055"><strong>class </strong></font><font color="#000000">AccountService </font><font color="#000000">{</font><br />
<font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#7f0055"><strong>void </strong></font><font color="#000000">debit</font><font color="#000000">(</font><font color="#000000">Account account, </font><font color="#7f0055"><strong>double </strong></font><font color="#000000">amount</font><font color="#000000">) {</font><br />
<font color="#ffffff">    </font><font color="#7f0055"><strong>if </strong></font><font color="#000000">(</font><font color="#000000">account.getBalance</font><font color="#000000">() </font><font color="#000000">&lt;= amount<br />
&amp;&amp; account </font><font color="#7f0055"><strong>instanceof </strong></font><font color="#ff6600">SimpleAccount</font><font color="#000000">) {</font><br />
<font color="#ffffff">      </font><font color="#000000">deductOverdraftPenalty</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">    </font><font color="#000000">}</font><br />
<font color="#ffffff">      </font><font color="#000000">account.setBalance</font><font color="#000000">(</font><font color="#000000">account.getBalance</font><font color="#000000">() </font><font color="#000000">- amount</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">  </font><font color="#000000">}</font><br />
<font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#7f0055"><strong>void </strong></font><font color="#000000">credit</font><font color="#000000">(</font><font color="#000000">Account account, </font><font color="#7f0055"><strong>double </strong></font><font color="#000000">amount</font><font color="#000000">) {</font><br />
<font color="#ffffff">      </font><font color="#000000">account.setBalance</font><font color="#000000">(</font><font color="#000000">account.getBalance</font><font color="#000000">() </font><font color="#000000">+ amount</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">  </font><font color="#000000">}</font><br />
<font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#7f0055"><strong>void </strong></font><font color="#000000">calculateInterest</font><font color="#000000">(</font><font color="#000000">Account account</font><font color="#000000">) {</font><br />
<font color="#ffffff">    </font><font color="#7f0055"><strong>if </strong></font><font color="#000000">(</font><font color="#000000">account </font><font color="#7f0055"><strong>instanceof </strong></font><font color="#ff6600">PlatinumAccount</font><font color="#000000">) {</font><br />
<font color="#ffffff">         </font><font color="#7f0055"><strong>double </strong></font><font color="#000000">interest = account.getBalance</font><font color="#000000">() </font><font color="#000000">* account.getInterest</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">      </font><font color="#000000">account.setBalance</font><font color="#000000">(</font><font color="#000000">account.getBalance</font><font color="#000000">() </font><font color="#000000">+ interest</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">    </font><font color="#000000">}</font><br />
<font color="#ffffff">  </font><font color="#000000">}</font><br />
<font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#7f0055"><strong>void </strong></font><font color="#000000">deductOverdraftPenalty</font><font color="#000000">(</font><font color="#000000">Account account</font><font color="#000000">) {</font><br />
<font color="#ffffff">      </font><font color="#000000">account.setBalance</font><font color="#000000">(</font><font color="#000000">account.getBalance</font><font color="#000000">() </font><font color="#000000">- account.getOverdraftPenalty</font><font color="#000000">())</font><font color="#000000">;</font><br />
<font color="#ffffff">  </font><font color="#000000">}</font><br />
<font color="#000000">}</font></code></td>
</tr>
</table>
<p>As you can see, now the service layer is behaving differently based on the object type (although  there are ways to avoid this by having getters and setters for overdraft with zero value for those accounts that do not have the overdraft penalty, but thats not the point here). This has now become a procedural way to getting things done not the OO way.</p>
<p>With the Domain Model we do it the OO way. This is how it would be implemented in the Domain Model</p>
<p class="java" align="left">
<table bgcolor="#ffffff" border="0" cellpadding="3" cellspacing="0">
<tr>
<td align="left" nowrap="nowrap" valign="top"><code> <font color="#7f0055"><strong>class </strong></font><font color="#000000">SimpleAccount </font><font color="#7f0055"><strong>extends </strong></font><font color="#000000">Account </font><font color="#000000">{</font><br />
<font color="#ffffff">  </font><font color="#7f0055"><strong>private </strong></font><font color="#7f0055"><strong>double </strong></font><font color="#000000">overdraftPenalty = </font><font color="#990000">30.00</font><font color="#000000">;</font><br />
<font color="#ffffff">  </font><font color="#7f0055"><strong>private </strong></font><font color="#7f0055"><strong>double </strong></font><font color="#000000">getOverdraftPenalty</font><font color="#000000">() {</font><br />
<font color="#ffffff">    </font><font color="#7f0055"><strong>return </strong></font><font color="#000000">overdraftPenalty;</font><br />
<font color="#ffffff">  </font><font color="#000000">}</font><br />
<font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#7f0055"><strong>double </strong></font><font color="#000000">debit</font><font color="#000000">(</font><font color="#7f0055"><strong>double </strong></font><font color="#000000">amount</font><font color="#000000">) {</font><br />
<font color="#ffffff">    </font><font color="#7f0055"><strong>if </strong></font><font color="#000000">(</font><font color="#000000">getBalance</font><font color="#000000">() </font><font color="#000000">&lt;= amount</font><font color="#000000">) {</font><br />
<font color="#ffffff">      </font><font color="#000000">deductOverdraftPenalty</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">    </font><font color="#000000">}</font><br />
<font color="#ffffff">    </font><font color="#7f0055"><strong>this</strong></font><font color="#000000">.balance -= amount;</font><br />
<font color="#ffffff">  </font><font color="#000000">}</font><br />
<font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#7f0055"><strong>void </strong></font><font color="#000000">deductOverdraftPenalty</font><font color="#000000">() {</font><br />
<font color="#ffffff">    </font><font color="#7f0055"><strong>this</strong></font><font color="#000000">.balance -= overdraftPenalty;</font><br />
<font color="#ffffff">  </font><font color="#000000">}</font><br />
<font color="#000000">}</font><font color="#ffffff"><br />
</font></code></td>
</tr>
</table>
<table bgcolor="#ffffff" border="0" cellpadding="3" cellspacing="0">
<tr>
<td align="left" nowrap="nowrap" valign="top"><code> <font color="#7f0055"><strong>class </strong></font><font color="#000000">PlatinumAccount </font><font color="#7f0055"><strong>extends </strong></font><font color="#000000">Account </font><font color="#000000">{</font><br />
<font color="#ffffff">  </font><font color="#7f0055"><strong>private </strong></font><font color="#7f0055"><strong>double </strong></font><font color="#000000">interest = </font><font color="#990000">0.1</font><font color="#000000">;</font><br />
<font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#7f0055"><strong>double </strong></font><font color="#000000">getInterest</font><font color="#000000">() {</font><br />
<font color="#ffffff">    </font><font color="#7f0055"><strong>return </strong></font><font color="#000000">interest;</font><br />
<font color="#ffffff">  </font><font color="#000000">}</font><br />
<font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#7f0055"><strong>void </strong></font><font color="#000000">addInterest</font><font color="#000000">() {</font><br />
<font color="#ffffff">    </font><font color="#000000">credit</font><font color="#000000">(</font><font color="#000000">getBalance</font><font color="#000000">() </font><font color="#000000">* getInterest</font><font color="#000000">())</font><font color="#000000">;</font><br />
<font color="#ffffff">  </font><font color="#000000">}</font><br />
<font color="#000000">}</font></code></td>
</tr>
</table>
<p>Hope this illustrates the point.</p>
<p><span style="color:#ff0000;">Now the important question that keeps coming back to me!!!! </span></p>
<p>Why shouldn&#8217;t we allow the Account object to be able to Save it self by passing the DataSource?</p>
<p>Very good question (although its besides the point of Anemic Domain Model).</p>
<p>The answer to this is, it depends on the application</p>
<p>(To be continued &#8230; )</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/vitamic.wordpress.com/3/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/vitamic.wordpress.com/3/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vitamic.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vitamic.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vitamic.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vitamic.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vitamic.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vitamic.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vitamic.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vitamic.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vitamic.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vitamic.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vitamic.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vitamic.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vitamic.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vitamic.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vitamic.wordpress.com&amp;blog=655161&amp;post=3&amp;subd=vitamic&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vitamic.wordpress.com/2007/01/04/anemic-domain-model-illustrated/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4d5f945a897e190af8c0d4a6e1dd5f00?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vitamic</media:title>
		</media:content>
	</item>
		<item>
		<title>MySql Master Master Replication</title>
		<link>http://vitamic.wordpress.com/2007/01/04/hello-world/</link>
		<comments>http://vitamic.wordpress.com/2007/01/04/hello-world/#comments</comments>
		<pubDate>Thu, 04 Jan 2007 00:40:30 +0000</pubDate>
		<dc:creator>vitamic</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tech]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[I have been wanting to setup MySQL Master Master configuration, for a project I have been working on lately, for a while and finally got my hands dirty and got it done. Its quite easy and there are tons of tutorials out there describing how to do it. Let me point out that there are [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vitamic.wordpress.com&amp;blog=655161&amp;post=1&amp;subd=vitamic&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span><br />
I have been wanting to setup MySQL Master Master configuration, for a project I have been working on lately, for a while and finally got my hands dirty and got it done. Its quite easy and there are tons of tutorials out there describing how to do it. Let me point out that there are many ways of achieving this. This is just my experience and not really a full fledged tutorial.</span></p>
<p>The main reason for doing this is for <a href="http://en.wikipedia.org/wiki/High_availability">HA</a></p>
<p>Here is what I had<br />
1. Clean database (no previous data to deal with)<br />
2. Two clean instances of MySQL 5.0.27 running on separate machines (Host A and Host B)<br />
3. Host A is running <a href="http://www.ubuntu.com/">6.0.6</a> and Host B is running <a href="http://fedora.redhat.com/">Fedora 5.0</a></p>
<p><strong>Step 1 (Setup the system)<br />
</strong>
<ol>
<li><span>Make sure you are able to ping  Host B from Host A and vice-versa.</span></li>
<li><span style="font-size:100%;">Make sure that you are able to reach port 3306 on Host B (or whatever port your <span class="blsp-spelling-corrected">MySQL</span> is configured to run on) from Host A and vice-versa. If there is a firewall configured then make sure to allow the port <span class="blsp-spelling-corrected">MySQL</span> is running on. (ex: <span class="blsp-spelling-corrected">MySQL</span> -h <span class="blsp-spelling-error">hostB</span> -u <span class="blsp-spelling-error">username</span> -p password)</span></li>
<li><span style="font-size:100%;">It is recommended to have same versions of MySQL running on both the machines, if possible. Otherwise you&#8217;ll have to run some additional steps (not described here) to create this configuration.</span><span id="more-1"></span></li>
</ol>
<p><span>Step 2 (Configure Master on Host A)</span><span style="font-family:lucida grande;font-size:100%;"></span></p>
<p>Edit my.<span class="blsp-spelling-error">cnf</span> and add the following (On <span class="blsp-spelling-error">Ubuntu</span> 6.0.6 this file is located at /etc/<span class="blsp-spelling-error">mysql</span>) and add the following</p>
<p>[<span class="blsp-spelling-error">mysql</span>]<br />
&#8230;.</p>
<p>log-bin=/var/log/<span class="blsp-spelling-error">mysql</span>/<span class="blsp-spelling-error">mysql</span>-bin.log<br />
<span class="blsp-spelling-error">binlog</span>-do-db= <span style="color:#009900;"># The database you want to replicate</span><br />
replicate-do-db=  <span style="color:#009900;"># The database you want to replicate</span><br />
binlog-ignore-db=mysql <span style="color:#009900;"># Ignore db from replication</span><br />
replicate-ignore-db=mysql <span style="color:#009900;"># </span><span style="font-family:lucida grande;font-size:100%;"><span style="color:#009900;">Ignore db from replication</span></span><span style="font-family:lucida grande;font-size:100%;"></span></p>
<p>server-id=1 <span style="color:#ff6600;"># This is very important</span><br />
&#8230;</p>
<p><span style="font-weight:bold;">Step 3 (Create Slave Account on Host A)</span></p>
<p><span style="font-size:100%;">Create a replication slave account for Host B on Host A.<br />
</span><span style="font-family:lucida grande;font-size:100%;">mysql&gt; grant replication slave on *.* to &#8216;repusername&#8217;@host_B_IP identified by &#8216;slavepass&#8217;;</span></p>
<p>This allows slave process on Host B to connect to the master on Host A to initiate the replication process.</p>
<p>Note: You can replace &#8220;host_B_IP&#8221; with your domain name or your subdomain like &#8220;example.org&#8221; or &#8220;subdomain.example.org&#8221; if the IP of host B is not static.</p>
<p><span style="font-weight:bold;">Step 4 (Create Slave on Host B)<br />
</span><span style="font-weight:bold;"><span style="font-weight:bold;"><span style="font-weight:bold;"><br />
</span></span></span>Edit my.cnf and add the following (On Fedora 5.0 this file is located at /etc) and add the following</p>
<p><span>[mysqld]<br />
&#8230;</span></p>
<p><span class="system">server-id=2 </span><span style="color:#ff6600;font-family:lucida grande;font-size:100%;"># This is very important</span><span style="font-family:lucida grande;font-size:100%;"><br />
<span class="system"><br />
master-host = host_A_IP </span></span><span style="color:#009900;font-family:lucida grande;font-size:100%;"># The IP address of the master host</span><span style="font-family:lucida grande;font-size:100%;"><br />
<span class="system">master-user = repusername </span></span><span style="color:#009900;font-family:lucida grande;font-size:100%;"># The username to use to connect to master</span><span style="font-family:lucida grande;font-size:100%;"><br />
<span class="system">master-password = slavepass </span></span><span style="color:#009900;font-family:lucida grande;font-size:100%;"># The password to use to connect to master</span><span style="font-family:lucida grande;font-size:100%;"><br />
<span class="system">master-port = 3306 </span></span><span style="color:#009900;font-family:lucida grande;font-size:100%;"># The port where the master is running, default is 3306</span><span style="font-family:lucida grande;font-size:100%;"><br />
<span class="system"><br />
&#8230;</span></span></p>
<p>Now we have a master slave configuration master being Host A and slave being Host B.</p>
<p><span style="font-weight:bold;">Step 5 (Verify Master Slave Configuration)</span><br />
<span style="font-weight:bold;"><span style="font-weight:bold;"><br />
</span></span><span>Now lets make sure that the master slave configuration really works. To do that restart both the database instances.</span></p>
<p>[<span style="color:#ff6600;">hostA</span>@ ubuntu]&gt; /etc/init.d/mysql restart<br />
<span style="font-family:lucida grande;font-size:100%;">[<span style="color:#009900;">hostB</span>@ fedora]&gt; /etc/init.d/mysqld restart</span></p>
<p><span style="font-weight:bold;">On host B run the following command</span></p>
<p>mysql&gt; start slave;<br />
mysql&gt; show slave status\G;</p>
<p><span style="font-family:lucida grande;font-size:100%;"><span style="color:#999999;" class="system">*************************** 1. row ***************************</span></span><span style="font-size:100%;"><br />
Slave_IO_State: Waiting for master to send event<br />
Master_Host: HOST A IP<br />
Master_User: repusername<br />
Master_Port: 3306<br />
Connect_Retry: 60<br />
Master_Log_File: hostAmysql01-bin.000009<br />
Read_Master_Log_Pos: 4</span><span style="font-size:100%;"><span class="system"><span style="font-style:italic;"><br />
</span>Relay_Log_File: </span><span class="system">hostAmysql</span><span class="system">02-relay-bin.000015</span><br />
Relay_Log_Pos: 3630</span><span class="system" style="font-size:100%;"><br />
Relay_Master_Log_File: </span><span class="system" style="font-size:100%;">hostAmysql</span><span style="font-size:100%;">01-bin.000009</span><span style="color:#ff6600;font-size:100%;"><br />
Slave_IO_Running: Yes</span><span style="color:#ff6600;font-size:100%;"><br />
Slave_SQL_Running: Yes</span><span style="font-size:100%;"><br />
Replicate_Do_DB:<br />
Replicate_Ignore_DB:<br />
Replicate_Do_Table:<br />
Replicate_Ignore_Table:<br />
Replicate_Wild_Do_Table:<br />
Replicate_Wild_Ignore_Table:<br />
Last_Errno: 0<br />
Last_Error:<br />
Skip_Counter: 0<br />
Exec_Master_Log_Pos: 4<br />
Relay_Log_Space: 3630<br />
Until_Condition: None<br />
Until_Log_File:<br />
Until_Log_Pos: 0<br />
Master_SSL_Allowed: No<br />
Master_SSL_CA_File:<br />
Master_SSL_CA_Path:<br />
Master_SSL_Cert:<br />
Master_SSL_Cipher:<br />
Master_SSL_Key:</span><span style="font-size:100%;"><span class="system"><br />
Seconds_Behind_Master: 1519187</span></span><span style="font-size:100%;"><span class="system"></span></span></p>
<p>1 row in set (0.00 sec)</p>
<p><span style="font-family:lucida grande;font-size:100%;">Make sure that the text <span style="color:#ff6600;">highlighted<span style="color:#000000;"> shows &#8220;Yes&#8221;. If not its time to debug. The first place to start will be /var/log/mysqld.log or /var/log/mysql/mysql.log (depending on the settings). See if something is obvious. Some of the obvious errors are &#8220;Access denied&#8221;, &#8220;unable to reach host&#8221;. These error messages are exactly not as mentioned here but if you google the error codes you&#8217;ll find it quickly.</span></span></span></p>
<p><span style="font-family:lucida grande;font-size:100%;"><span style="font-weight:bold;">On host A run the following command</span></span><span style="font-size:100%;"><br />
</span><span style="font-family:lucida grande;font-size:100%;"><span style="color:#ff6600;"><span style="color:#000000;"><br />
</span></span><span class="system">mysql&gt; show master status;<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
| File                   | Position | <span class="blsp-spelling-error">Binlog</span>_Do_DB | <span class="blsp-spelling-error">Binlog</span>_Ignore_DB |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
|<span class="blsp-spelling-error">hostAmysql</span>01-bin.000008 |      98 | <span class="blsp-spelling-error">replicationdb</span>         |                  |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
1 row in set (0.00 sec)</span><br />
</span><span style="font-family:lucida grande;font-size:100%;"><br />
<span style="font-weight:bold;">Step 6 (Create Master on Host B)</span></span></p>
<p><span style="font-weight:bold;"></span><span style="font-family:lucida grande;font-size:100%;">Edit my.<span class="blsp-spelling-error">cnf</span> and add the following (On <span class="blsp-spelling-error">Ubuntu</span> 6.0.6 this file is located at /etc/<span class="blsp-spelling-error">mysql</span>) and add the following</span></p>
<p><span style="font-family:lucida grande;font-size:100%;"><span>[<span class="blsp-spelling-error">mysqld</span>]<br />
&#8230;</span></span></p>
<p><span class="system">server-id=2 </span><span style="color:#ff6600;font-family:lucida grande;font-size:100%;"># This is very important</span><span style="font-family:lucida grande;font-size:100%;"><br />
<span class="system"><br />
master-host = host_A_<span class="blsp-spelling-error">IP</span> </span></span><span style="color:#009900;font-family:lucida grande;font-size:100%;"># The <span class="blsp-spelling-error">IP</span> address of the master host</span><span style="font-family:lucida grande;font-size:100%;"><br />
<span class="system">master-user = <span class="blsp-spelling-error">repusername</span> </span></span><span style="color:#009900;font-family:lucida grande;font-size:100%;"># The <span class="blsp-spelling-error">username</span> to use to connect to master</span><span style="font-family:lucida grande;font-size:100%;"><br />
<span class="system">master-password = <span class="blsp-spelling-error">slavepass</span> </span></span><span style="color:#009900;font-family:lucida grande;font-size:100%;"># The password to use to connect to master</span><span style="font-family:lucida grande;font-size:100%;"><br />
<span class="system">master-port = 3306 </span></span><span style="color:#009900;font-family:lucida grande;font-size:100%;"># The port where the master is running, default is 3306</span><span style="font-family:lucida grande;font-size:100%;"><br />
<span class="system"><br />
<span style="color:#ff6600;"># The following makes Host B act as a master</span><br />
</span></span><span style="font-size:100%;"><span style="color:#3333ff;">log-bin=/var/log/<span class="blsp-spelling-error">mysql</span>/<span class="blsp-spelling-error">mysql</span>-bin.log</span><br />
<span style="color:#3333ff;"><span class="blsp-spelling-error">binlog</span>-do-db= </span></span><span style="color:#3333ff;font-family:lucida grande;font-size:100%;"></span><span style="color:#009900;font-size:100%;"># The database you want to replicate</span><span style="font-size:100%;"><br />
<span style="color:#3333ff;">replicate-do-db=</span> </span><span style="color:#3333ff;font-family:lucida grande;font-size:100%;"></span><span style="font-size:100%;"><span style="color:#009900;"># The database you want to replicate</span><br />
binlog-ignore-db=mysql <span style="color:#009900;"># </span></span><span style="font-family:lucida grande;font-size:100%;"><span style="color:#009900;">Ignore db from replication</span></span><span style="font-size:100%;"><br />
replicate-ignore-db=mysql <span style="color:#009900;"># </span></span><span style="font-family:lucida grande;font-size:100%;"><span style="color:#009900;">Ignore db from replication</span></span><span style="font-size:100%;"><br />
</span><span style="font-size:100%;"><span style="color:#009900;"><br />
</span></span><span style="font-family:lucida grande;font-size:100%;"><span class="system">&#8230;</span></span><span style="font-family:lucida grande;font-size:100%;"></span></p>
<p><span style="font-size:100%;"><span style="font-weight:bold;">Step 7 (Create Slave Account on Host B)</span></span></p>
<p>Create a replication slave account for Host A on Host B.<br />
mysql&gt; grant replication slave on *.* to &#8216;repusername&#8217;@host_A_IP identified by &#8216;slavepass&#8217;;</p>
<p><span style="font-family:lucida grande;font-size:100%;"><span style="font-weight:bold;">Step 8 (Make Host A the slave)</span></span></p>
<p><span style="font-size:100%;">Edit my.cnf and add the following (On Ubuntu 6.0.6 this file is located at /etc/mysql) and add the following</span></p>
<p>[mysql]<br />
&#8230;.</p>
<p>log-bin=/var/log/mysql/mysql-bin.log<br />
binlog-do-db= <span style="color:#009900;font-size:100%;"># The database you want to replicate</span><span style="font-size:100%;"><br />
replicate-do-db= <span style="color:#009900;"># The database you want to replicate</span><br />
binlog-ignore-db=mysql <span style="color:#009900;"># </span></span><span style="font-family:lucida grande;font-size:100%;"><span style="color:#009900;">Ignore db from replication</span></span><span style="font-size:100%;"><br />
replicate-ignore-db=mysql <span style="color:#009900;"># </span></span><span style="font-family:lucida grande;font-size:100%;"><span style="color:#009900;">Ignore db from replication</span></span></p>
<p><span style="font-size:100%;">server-id=1 <span style="color:#ff6600;"># This is very important</span></span></p>
<p># This makes Host A a slave<br />
<span style="font-family:lucida grande;font-size:100%;"><span class="system"><span style="color:#3333ff;">master-host = host_B_IP</span> </span></span><span style="color:#009900;font-family:lucida grande;font-size:100%;"># The IP address of the master host</span><span style="font-family:lucida grande;font-size:100%;"><br />
<span style="color:#3333ff;" class="system">master-user = repusername </span></span><span style="color:#009900;font-family:lucida grande;font-size:100%;"># The username to use to connect to master</span><span style="font-family:lucida grande;font-size:100%;"><br />
<span class="system"><span style="color:#3333ff;">master-password = slavepass</span> </span></span><span style="color:#009900;font-family:lucida grande;font-size:100%;"># The password to use to connect to master</span><span style="font-family:lucida grande;font-size:100%;"><br />
<span style="color:#3333ff;" class="system">master-port = 3306 </span></span><span style="color:#009900;font-family:lucida grande;font-size:100%;"># The port where the master is running, default is 3306</span><span style="font-family:lucida grande;font-size:100%;"><br />
</span><span style="font-size:100%;"><br />
&#8230;</span></p>
<p><span style="font-family:lucida grande;font-size:100%;"><span class="system"><span style="font-weight:bold;">Step 9 (Verify Master Master Configuration)</span></span></span></p>
<p><span style="font-family:lucida grande;font-size:100%;"><span>Now lets make sure that the master master configuration really works. To do that restart both the database instances.</span></span></p>
<p>[<span style="color:#ff6600;">hostA</span>@ ubuntu]&gt; /etc/init.d/mysql restart<br />
<span style="font-family:lucida grande;font-size:100%;">[<span style="color:#009900;">hostB</span>@ fedora]&gt; /etc/init.d/mysqld restart</span></p>
<p><span style="font-weight:bold;">On host A run the following command</span></p>
<p>mysql&gt; start slave;<br />
mysql&gt; show slave status\G;</p>
<p>Make sure that the following is true<br />
<span style="color:#ff6600;font-size:100%;">Slave_IO_Running: Yes</span><span style="color:#ff6600;font-size:100%;"><br />
Slave_SQL_Running: Yes</span></p>
<p><span style="font-family:lucida grande;font-size:100%;">mysql&gt; show master status;</span><span style="font-size:100%;"><br />
</span><span style="font-family:lucida grande;font-size:100%;"><br />
Repeat the same on Host B.</span></p>
<p><span style="font-weight:bold;">Step 10 (Confirm replication)</span></p>
<p>Now run your  related <span class="blsp-spelling-error">DDL</span> / <span class="blsp-spelling-error">DML</span> queries and see them replicated on the slave. Try from both the instances. Enjoy!!!</p>
<p><span style="font-weight:bold;"></span><span style="font-family:lucida grande;font-size:100%;"><span style="font-weight:bold;">Resources<br />
</span></span></p>
<ol>
<li><span style="font-size:100%;"><a href="http://dev.mysql.com/doc/refman/5.0/en/replication-howto.html"><span class="blsp-spelling-corrected">MySQL</span> Replication</a><br />
</span></li>
</ol>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/vitamic.wordpress.com/1/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/vitamic.wordpress.com/1/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vitamic.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vitamic.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vitamic.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vitamic.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vitamic.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vitamic.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vitamic.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vitamic.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vitamic.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vitamic.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vitamic.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vitamic.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vitamic.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vitamic.wordpress.com/1/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vitamic.wordpress.com&amp;blog=655161&amp;post=1&amp;subd=vitamic&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vitamic.wordpress.com/2007/01/04/hello-world/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4d5f945a897e190af8c0d4a6e1dd5f00?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vitamic</media:title>
		</media:content>
	</item>
	</channel>
</rss>
