tag:blogger.com,1999:blog-1373851816248476399Thu, 10 Oct 2024 14:12:24 +0000EclipseScalabilityAPI DesignArchitectureBig DataCacheCore JavaData TransformerEclipse Modelling 3D EMF ZEST GEFHTML5HibernateJFace DialogMulti-TenancyPaaSPerformance MonitoringProductivity Toolsconcurrencyenterprise 2.0jMakijava MEjavaFXjdkmashletmashupmongodbMusings on Technologyhttp://musings-on-technology.blogspot.com/noreply@blogger.com (Kaniska)Blogger55125tag:blogger.com,1999:blog-1373851816248476399.post-7592655643796574234Thu, 01 Mar 2012 05:59:00 +00002012-03-01T11:50:56.576+05:30Setup Hadoop and Hbase Environment<div dir="ltr" style="text-align: left;" trbidi="on">Setup Apache BigTop<br /> <br /> <a href="http://apachebigtop.pbworks.com/w/page/48434924/FrontPage">http://apachebigtop.pbworks.com/w/page/48434924/FrontPage</a><br /> <span style="background-color: white; color: #cb182f; font-family: Arial, Helvetica, sans-serif; font-size: 26px; line-height: 28px; text-align: -webkit-auto;"><br /> </span><br /> <span style="background-color: white; font-family: Arial, Helvetica, sans-serif; line-height: 28px; text-align: -webkit-auto;">How to develop Big Data Pipelines for Hadoop</span><br /> <span style="background-color: white; font-family: Arial, Helvetica, sans-serif; line-height: 28px; text-align: -webkit-auto;">I Didn't Know You Could Do All that with Hadoop</span><br /> <span style="background-color: white; font-family: Arial, Helvetica, sans-serif; line-height: 28px; text-align: -webkit-auto;">Storm: distributed and fault-tolerant realtime computation</span><br /> <span style="background-color: white; font-family: Arial, Helvetica, sans-serif; line-height: 28px; text-align: -webkit-auto;">Hadoop Plugin for MongoDB: The Elephant in the Room</span><br /> <span style="background-color: white; font-family: Arial, Helvetica, sans-serif; line-height: 28px; text-align: -webkit-auto;"><br /> </span><br /> <span style="background-color: white; line-height: 28px; text-align: -webkit-auto;"><span style="font-family: Arial, Helvetica, sans-serif;">StrataConf 2012 Hive Tutorial</span></span><br /> <a href="http://assets.en.oreilly.com/1/event/75/Hadoop%20Data%20Warehousing%20with%20Hive%20Paper.pdf">http://assets.en.oreilly.com/1/event/75/Hadoop%20Data%20Warehousing%20with%20Hive%20Paper.pdf</a><br /> <span style="background-color: white; font-family: Arial, Helvetica, sans-serif; line-height: 28px; text-align: -webkit-auto;">Hadoop Data Warehousing with Hive</span><br /> <br /> Cloudera Hbase Training<br /> <a href="http://university.cloudera.com/training/apache_hbase/hbase.html">http://university.cloudera.com/training/apache_hbase/hbase.html</a> <br /> <br /> <br /> <h1 class="firstHeading gumax-firstHeading" id="firstHeading" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: none; background-origin: initial; border-bottom-color: rgb(221, 221, 221); border-bottom-style: solid; border-bottom-width: 1px; color: #0099cc; font-family: 'Trebuchet MS', Arial, Verdana; font-size: 21px; font-weight: normal; line-height: 1.2em; margin-bottom: 0.1em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto;">Hadoop on Amazon AWS</h1><br /> <a href="http://cs.smith.edu/dftwiki/index.php/Hadoop_Tutorial_3_--_Hadoop_on_Amazon_AWS">http://cs.smith.edu/dftwiki/index.php/Hadoop_Tutorial_3_--_Hadoop_on_Amazon_AWS</a> <br /> <br /> <span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 22px; text-align: -webkit-auto;">Build and Run Hadoop Java program with Ant and Maven</span><br /> <br /> <a href="http://stones333.blogspot.com/2012/02/build-and-run-hadoop-java-program-with.html">http://stones333.blogspot.com/2012/02/build-and-run-hadoop-java-program-with.html</a> <br /> <br /> <span style="background-color: white; color: #444444; font-family: 'Segoe UI', 'Lucida Grande', Arial; line-height: 31px;"><b>Machine Learning on Big Data with MapReduce</b></span> <br /> <a href="http://machinelearningbigdata.pbworks.com/w/page/37651454/FrontPage">http://machinelearningbigdata.pbworks.com/w/page/37651454/FrontPage</a> <br /> <br /> <b>Hbase &amp; NoSQL&nbsp;Comparison&nbsp;:</b><br /> <a href="http://kkovacs.eu/cassandra-vs-mongodb-vs-couchdb-vs-redis">http://kkovacs.eu/cassandra-vs-mongodb-vs-couchdb-vs-redis</a> <br /> <a href="http://ria101.wordpress.com/2010/02/24/hbase-vs-cassandra-why-we-moved/">http://ria101.wordpress.com/2010/02/24/hbase-vs-cassandra-why-we-moved/</a> <br /> <a href="http://natishalom.typepad.com/nati_shaloms_blog/hbase/">http://natishalom.typepad.com/nati_shaloms_blog/hbase/</a> <br /> <a href="http://natishalom.typepad.com/nati_shaloms_blog/2011/07/real-time-analytics-for-big-data-an-alternative-approach.html">http://natishalom.typepad.com/nati_shaloms_blog/2011/07/real-time-analytics-for-big-data-an-alternative-approach.html</a> <br /> <br /> Beyond Hadoop : Stream based Messaging (Storm / Kafka )<br /> <a href="http://natishalom.typepad.com/nati_shaloms_blog/2011/07/real-time-analytics-for-big-data-an-alternative-approach-to-facebooks-new-realtime-analytics-system.html">http://natishalom.typepad.com/nati_shaloms_blog/2011/07/real-time-analytics-for-big-data-an-alternative-approach-to-facebooks-new-realtime-analytics-system.html</a> <br /> <br /> </div>http://musings-on-technology.blogspot.com/2012/03/setup-hadoop-and-hbase-environment.htmlnoreply@blogger.com (Kaniska)3tag:blogger.com,1999:blog-1373851816248476399.post-3138922585636962718Sun, 12 Feb 2012 06:22:00 +00002012-02-12T11:59:14.171+05:30Multi-TenancyBuilding Multi-Tenant Platform for Data Acquisition, Analysis Visualization<div dir="ltr" style="text-align: left;" trbidi="on"><span style="color: #0c343d;"><b>Multi-Tenant Data Access Security :</b></span><br /> Cross-Organization and Cross-Application SSO<br /> <br /> <h3 class="r" style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: medium; font-weight: normal; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: hidden; overflow-y: hidden; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto; text-overflow: ellipsis; white-space: nowrap;"><a class="l" href="http://www.onelogin.com/" style="color: #1122cc; cursor: pointer;"><span style="color: #1122cc;"><span style="cursor: pointer;">Single sign-on for the cloud and SaaS -</span></span><span style="color: #1122cc;"><span style="cursor: pointer;">&nbsp;</span></span><em style="color: #1122cc; cursor: pointer; font-style: normal; font-weight: bold;">OneLogin</em></a></h3><h3 class="r" style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: medium; font-weight: normal; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: hidden; overflow-y: hidden; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto; text-overflow: ellipsis; white-space: nowrap;"><br /> </h3><div><b style="color: #0c343d;">Multi-Tenant&nbsp;</b><b>Data Compliance :</b></div><div><div>&nbsp;Satisfy Data Compliance and Regulations and Data Encryption</div><div>Reference : <a href="http://www.sesamesoftware.com/pdf-docs/Satisfying_Compliance_Regulations_for_CRM_Data.pdf">http://www.sesamesoftware.com/pdf-docs/Satisfying_Compliance_Regulations_for_CRM_Data.pdf&nbsp;</a></div></div><div><br /> </div><div><b style="color: #0c343d;">Multi-Tenant&nbsp;</b><b>Data Acquisition :</b></div><div><div>Multi-Tenant Data Acquisition , MDM, Data Cleansing, Data Mapping - Component :</div><div>Capture data from Multiple Apps for Multiple Tenants through the same 'Integration Platform'</div><div>"If it's Not Multitenant, it's Not Really SaaS." --</div><div><a href="http://www.ebizq.net/blogs/connectedweb/2010/02/why_your_cloud_applications_sh.php">http://www.ebizq.net/blogs/connectedweb/2010/02/why_your_cloud_applications_sh.php</a></div><div><a href="http://www.boomi.com/products/technical/platform_architecture">http://www.boomi.com/products/technical/platform_architecture</a></div><div><a href="http://blogs.boomi.com/bod/2010/06/boomi-suggest-the-power-of-multitenancy.html">http://blogs.boomi.com/bod/2010/06/boomi-suggest-the-power-of-multitenancy.html</a></div></div><div><br /> </div><div>Mule+ion , Boomi+atom, Cast~Iron</div><div><br /> </div><div><b style="color: #0c343d;">Multi-Tenant&nbsp;</b><b>Data Storage :</b></div><div><a href="http://msdn.microsoft.com/en-us/library/aa479086.aspx">http://msdn.microsoft.com/en-us/library/aa479086.aspx</a></div><div>Scalable Elastic NoSQL or Partitioned RDBMS</div><div><br /> <b>Multi-Tenant Metadata Manager and Application Provisioning :</b><br /> <br /> <br /> </div><div><b style="color: #0c343d;">Multi-Tenant&nbsp;</b><b>Data Analysis :</b></div><div>Extensible Rules and Queries - configurable across tenants.</div><div>Tenant-Aware Resource Access Rules</div><div><b><br /> </b></div><div><b style="color: #0c343d;">Multi-Tenant&nbsp;</b><b>Data Service API:</b></div><div>Tenant-aware Resource Access Rules.</div><div>Tenant-aware Server, Sessions and Cache.<br /> Tenant-aware Rest Services , Work-flow and Rules-Engine</div><div><br /> </div><div><b style="color: #0c343d;">Multi-Tenant&nbsp;</b><b>Data Apps Server :</b> (Cloud-enabled and Tenant-aware )</div><div><div>&nbsp;Application Resource Allocation (App Server / DB Connection / Fail-over ) for all the tenants without stepping into each other's resources.</div><div>POD System is a popular recommended Multi-Tenant Model</div><div>-- &nbsp;<a href="http://connectedco.com/2011/04/18/the-future-is-podular/">http://connectedco.com/2011/04/18/the-future-is-podular/</a>&nbsp;</div><div>-- PaaS script will automatically roll out new resources ... &nbsp;its a mini-combo of (app-server, db, vm for a logical group of tenants)</div><div>-- <a href="http://www.cisco.com/en/US/docs/solutions/Enterprise/Data_Center/VMDC/2.0/large_pod_design_guide/Large_Pod_Design_Guide.pdf">http://www.cisco.com/en/US/docs/solutions/Enterprise/Data_Center/VMDC/2.0/large_pod_design_guide/Large_Pod_Design_Guide.pdf</a></div></div><div><br /> </div><div><b style="color: #0c343d;">Multi-Tenant&nbsp;</b><b>Data Viz :</b></div><div>Multi-Tenant Charts/Graphs and Configurable Dashboards.</div><div>Pentaho , YellowFin</div></div>http://musings-on-technology.blogspot.com/2012/02/building-multi-tenant-platform-for-data.htmlnoreply@blogger.com (Kaniska)0tag:blogger.com,1999:blog-1373851816248476399.post-2338766022428554270Sun, 12 Feb 2012 04:44:00 +00002012-02-12T10:14:04.725+05:30Securing Enterprise Application Access : Learning from Salesforce<div dir="ltr" style="text-align: left;" trbidi="on"><br /> <div class="MsoNormal"><span style="color: #1f497d; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;"><o:p>Securing Enterprise Application Access : &nbsp;Learning from Salesforce&nbsp;</o:p></span></div><div class="MsoNormal"><span style="color: #1f497d; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;"><o:p><br /> </o:p></span></div><div class="MsoNormal"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">1 : &nbsp;<b><span style="color: #17375e;">SFDC Tab invokes the following url to access the application :</span></b><span style="color: #17375e;"><o:p></o:p></span></span></div><div class="MsoNormal" style="text-indent: .5in;"><span lang="PT-BR" style="color: #1f497d; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt; mso-ansi-language: PT-BR;">(a)</span><span lang="PT-BR" style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt; mso-ansi-language: PT-BR;"> &nbsp;</span><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;"><a href="http://uat.dellcloudapplications.com/docs/secure_access/validate.php?location=%7B%21API.Partner_Server_URL_220%7D&amp;session_id=%7B%21API.Session_ID%7D" target="_blank"><span lang="PT-BR" style="color: windowtext; mso-ansi-language: PT-BR;">https://mysite.com/secure_access/validate.php?location={!API.Partner_Server_URL_220}&amp;session_id={!API.Session_ID}</span></a></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">2 : &nbsp;</span><b style="font-family: Arial, sans-serif; font-size: 15px;"><span style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #17375e;">Web Request Verification :&nbsp;</span></b><b style="font-family: Arial, sans-serif; font-size: 11pt;"><span style="color: #17375e;">Load Balancer Level :</span></b></div><div class="MsoListParagraph" style="margin-left: 57.0pt; mso-list: l0 level1 lfo1; text-indent: -.25in;"><!--[if !supportLists]--><span style="color: #1f497d; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt; mso-bidi-font-weight: bold; mso-fareast-font-family: Arial;">(a)<span style="font-family: 'Times New Roman'; font-size: 7pt;">&nbsp; </span></span><!--[endif]--><b><span style="color: #953735; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">- We need to perform referral check and IP range check<o:p></o:p></span></b></div><div class="MsoListParagraph" style="margin-left: 57.0pt; mso-list: l0 level1 lfo1; text-indent: -.25in;"><span style="color: #1f497d; font-family: Arial, sans-serif;"><span style="font-size: 15px;"><br /> </span></span></div><div class="MsoNormal"><span style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; font-family: Arial, sans-serif; font-size: 11pt;">Vulnerability Protection :<b>&nbsp;(</b></span><span style="font-family: Arial, sans-serif; font-size: 11pt;"><a href="http://wiki.developerforce.com/index.php/Secure_Coding_Single_Sign_On">http://wiki.developerforce.com/index.php/Secure_Coding_Single_Sign_On</a><span style="color: #1f497d;">&nbsp;</span>)</span></div><div style="font-style: inherit; line-height: 15pt; margin-bottom: 6pt; margin-left: 0.5in; margin-right: 0in; margin-top: 4.8pt; outline-width: 0px;"><span style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; font-family: Arial, sans-serif; font-size: 11pt;">Below is the regular expression to validate legitimate API Partner Server URL servers:<o:p></o:p></span></div><div class="MsoNormal" style="line-height: 15pt; margin-bottom: 1.2pt; margin-left: 0.75in; margin-right: 0in; margin-top: 0in; text-indent: -0.25in;"><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; font-family: Arial, sans-serif; font-size: 11pt;"><a href="https://[%5E/?%5d+\\.(sales|visual\\.)force\\.com/services/(S|s)(O|o)(A|a)(P|p)/(u|c)/.*"><span style="color: windowtext;">https://[^/?]+\\.(sales|visual\\.)force\\.com/services/(S|s)(O|o)(A|a)(P|p)/(u|c)/.*</span></a><o:p></o:p></span></div><div style="font-style: inherit; line-height: 15pt; margin-bottom: 0.0001pt; margin-left: 0.5in; margin-right: 0in; margin-top: 0in; outline-width: 0px;"><span style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; font-family: Arial, sans-serif; font-size: 11pt;">To summarize the above regular expression, it ensures that the URL starts with ‘<a href="https://xn--evg/" target="_blank" title="https://’"><span style="border-bottom-color: windowtext; border-bottom-style: none; border-bottom-width: 1pt; border-image: initial; border-left-color: windowtext; border-left-style: none; border-left-width: 1pt; border-right-color: windowtext; border-right-style: none; border-right-width: 1pt; border-top-color: windowtext; border-top-style: none; border-top-width: 1pt; color: windowtext; padding-bottom: 0in; padding-left: 0in; padding-right: 0in; padding-top: 0in; text-decoration: none;">https://’</span></a>, followed by a character other than ‘/ ‘ or '?' for 1 or more times, followed by a ‘.’, followed by ‘sales’ or ‘visual.’ followed by ‘<a href="http://force.com/services/SOAP/" target="_blank"><span style="color: windowtext;">force.com/services/SOAP/</span></a>’, followed by ‘u’ or ‘c’, followed by ‘/’. This will allow:<o:p></o:p></span></div><div class="MsoNormal" style="line-height: 15pt; margin-left: 0.75in; text-indent: -0.25in;"><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; font-family: Arial, sans-serif; font-size: 11pt;"><a href="https://%2A.salesforce.com/services/SOAP/u/" target="_blank" title="https://*.salesforce.com/services/SOAP/u/"><span style="border-bottom-color: windowtext; border-bottom-style: none; border-bottom-width: 1pt; border-image: initial; border-left-color: windowtext; border-left-style: none; border-left-width: 1pt; border-right-color: windowtext; border-right-style: none; border-right-width: 1pt; border-top-color: windowtext; border-top-style: none; border-top-width: 1pt; color: windowtext; padding-bottom: 0in; padding-left: 0in; padding-right: 0in; padding-top: 0in; text-decoration: none;">https://*.salesforce.com/services/SOAP/u/</span></a><o:p></o:p></span></div><div class="MsoNormal" style="line-height: 15pt; margin-left: 0.75in; text-indent: -0.25in;"><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; font-family: Arial, sans-serif; font-size: 11pt;"><a href="https://%2A.salesforce.com/services/SOAP/c/" target="_blank" title="https://*.salesforce.com/services/SOAP/c/"><span style="border-bottom-color: windowtext; border-bottom-style: none; border-bottom-width: 1pt; border-image: initial; border-left-color: windowtext; border-left-style: none; border-left-width: 1pt; border-right-color: windowtext; border-right-style: none; border-right-width: 1pt; border-top-color: windowtext; border-top-style: none; border-top-width: 1pt; color: windowtext; padding-bottom: 0in; padding-left: 0in; padding-right: 0in; padding-top: 0in; text-decoration: none;">https://*.salesforce.com/services/SOAP/c/</span></a><o:p></o:p></span></div><div class="MsoNormal" style="line-height: 15pt; margin-left: 0.75in; text-indent: -0.25in;"><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; font-family: Arial, sans-serif; font-size: 11pt;"><a href="https://%2A.visual.force.com/services/SOAP/u/" target="_blank" title="https://*.visual.force.com/services/SOAP/u/"><span style="border-bottom-color: windowtext; border-bottom-style: none; border-bottom-width: 1pt; border-image: initial; border-left-color: windowtext; border-left-style: none; border-left-width: 1pt; border-right-color: windowtext; border-right-style: none; border-right-width: 1pt; border-top-color: windowtext; border-top-style: none; border-top-width: 1pt; color: windowtext; padding-bottom: 0in; padding-left: 0in; padding-right: 0in; padding-top: 0in; text-decoration: none;">https://*.visual.force.com/services/SOAP/u/</span></a><o:p></o:p></span></div><div class="MsoNormal" style="line-height: 15pt; margin-left: 0.75in; text-indent: -0.25in;"><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; font-family: Arial, sans-serif; font-size: 11pt;"><a href="https://%2A.visual.force.com/services/SOAP/c/" target="_blank" title="https://*.visual.force.com/services/SOAP/c/"><span style="border-bottom-color: windowtext; border-bottom-style: none; border-bottom-width: 1pt; border-image: initial; border-left-color: windowtext; border-left-style: none; border-left-width: 1pt; border-right-color: windowtext; border-right-style: none; border-right-width: 1pt; border-top-color: windowtext; border-top-style: none; border-top-width: 1pt; color: windowtext; padding-bottom: 0in; padding-left: 0in; padding-right: 0in; padding-top: 0in; text-decoration: none;">https://*.visual.force.com/services/SOAP/c/</span></a></span></div><div class="MsoNormal"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;"><br /> </span></div><div class="MsoNormal"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">3 : <b><span style="color: #17375e;">Delegate the request to validator &nbsp;(php / javascript / servlet filter )&nbsp;</span></b></span></div><div class="MsoNormal"><span style="color: #1f497d; font-family: Arial, sans-serif; font-size: 11pt; text-indent: -0.25in;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(a)<span style="font-family: 'Times New Roman'; font-size: 7pt;">&nbsp; </span></span><span style="font-family: Arial, sans-serif; font-size: 11pt; text-indent: -0.25in;">we can <b><span style="color: #953735;">double-check if request coming from salesforce</span></b></span></div><div class="MsoNormal"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #1f497d;">(b)</span> <b><span style="color: #953735;">validate the session-id by making a reverse call</span></b><span style="color: #953735;"> </span>to SFDC.<o:p></o:p></span></div><div class="MsoNormal"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #1f497d;">i.</span>&nbsp;- simply <b><span style="color: #953735;">retrieve the UserInfo </span></b>for that connection <b><span style="color: #953735;">and extract the user-id.</span></b><o:p></o:p></span></div><div class="MsoNormal"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if there is error condition, then forward to trial page<span style="color: #1f497d;"> or whatever relevant</span>.</span><b style="font-family: Arial, sans-serif; font-size: 11pt;"><span style="color: #953735;">verify if the (c)&nbsp;</span></b><b style="color: #1f497d; font-family: Arial, sans-serif; font-size: 15px;">User Authorization : Verify if&nbsp;</b><b style="font-family: Arial, sans-serif; font-size: 11pt;"><span style="color: #953735;">user-id is registered</span></b><span style="font-family: Arial, sans-serif; font-size: 11pt;">. (highly recommended by salesforce)</span></div><div class="MsoNormal"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #1f497d;">iii</span>&nbsp;- another layer of security <span style="color: #1f497d;">–</span> <b><span style="color: #953735;">verify call is initiated by salesforce by using private security</span></b><span style="color: #953735;"> </span>certificate from SalesForce<o:p></o:p></span></div><div class="MsoNormal"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Include this certificate in every http / soap call to SFDC from validate.php.<o:p></o:p></span></div><div class="MsoNormal"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<o:p></o:p></span><a href="http://wiki.developerforce.com/index.php/Single_Sign_On_for_Composite_Apps" style="font-family: Arial, sans-serif; font-size: 15px;">http://wiki.developerforce.com/index.php/Single_Sign_On_for_Composite_Apps</a><span style="color: #1f497d; font-family: Arial, sans-serif; font-size: 15px;">&nbsp; &nbsp;</span></div><div class="MsoNormal"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;"><br /> </span></div><div class="MsoNormal"><span style="color: #1f497d; font-family: Arial, sans-serif; font-size: 11pt;">4. </span><b><span style="color: #17375e; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">Enable SSL in uat-apache</span></b></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><b><span style="color: #17375e; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">5. U</span></b><b><span style="color: #17375e; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">se SalesForce Certificate :<o:p></o:p></span></b></div><div class="MsoNormal"><span style="background: white; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">This certificate is meant to identify that the request is coming from&nbsp;<a href="http://salesforce.com/" target="_blank"><span style="color: windowtext;">salesforce.com</span></a>, not a specific user.</span><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;"><o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;"><a href="http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_om_outboundmessaging_setting_up.htm#om_user_profile">http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_om_outboundmessaging_setting_up.htm#om_user_profile</a><span style="color: #1f497d;"> </span><o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><span style="background: white; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">Your application (endpoint) server's SSL/TLS may be configured to require client certificates (two-way SSL/TLS), in order to validate the identity of the&nbsp;Salesforce&nbsp;server when it takes the role of client to your server. If this is the case, you can download the&nbsp;Salesforce&nbsp;client certificate from the&nbsp;Salesforce&nbsp;application user interface.&nbsp;</span><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;"><o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><span style="color: #1f497d; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">6. </span><b><span style="color: #17375e; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">Enable SSO (in future)&nbsp;:<o:p></o:p></span></b></div><div class="MsoNormal"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">As per SalesForce : - &nbsp;<a href="https://na7.salesforce.com/help/doc/en/sso_delauthentication_configuring.htm">https://na7.salesforce.com/help/doc/en/sso_delauthentication_configuring.htm</a><span style="color: #1f497d;"> </span><o:p></o:p></span></div><div class="MsoNormal"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">Use -&nbsp;<b><span style="background: white;">Delegated Authentication WSDL</span></b><o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><span style="background: white; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">If Single Sign-On (SSO) is enabled for your organization, users who access the API or a desktop client cannot log in to&nbsp;Salesforce&nbsp;unless their IP address is included on your organization's list of trusted IP addresses or on their profile, if their profile has IP address restrictions set. Futhermore, the delegated authentication authority usually handles login lockout policies for users with the “Uses Single Sign-On” permission. However, if the security token is enabled for your organization, then your organization's login lockout settings determine the number of times a user can attempt to log in with an invalid security token before being locked out of&nbsp;Salesforce. For more information, see “Setting Login Restrictions” and “Setting Password Policies” in the online help.</span><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;"><o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><b><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">More details :&nbsp;</span></b><span style="background: white; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;"><a href="http://www.salesforce.com/docs/developer/cookbook/Content/sso_delegated.htm">http://www.salesforce.com/docs/developer/cookbook/Content/sso_delegated.htm</a></span><span style="color: #1f497d; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;"> </span><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;"><o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><b><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">Broad Topics on application security :</span></b><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">&nbsp;<a href="http://wiki.developerforce.com/index.php/Apex_and_Visualforce_Security_Tips">http://wiki.developerforce.com/index.php/Apex_and_Visualforce_Security_Tips</a><span style="color: #1f497d;"> </span><o:p></o:p></span></div><div class="MsoNormal"><span style="background: white; color: grey; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt;">1.&nbsp;<a href="http://wiki.developerforce.com/index.php/Secure_Coding_Cross_Site_Scripting" target="_blank" title="http://wiki.developerforce.com/index.php/Secure_Coding_Cross_Site_Scripting"><span style="border: none windowtext 1.0pt; color: #3366bb; font-family: inherit; mso-border-alt: none windowtext 0in; padding: 0in; text-decoration: none; text-underline: none;">Cross-Site Scripting</span></a><br /> 2.&nbsp;<a href="http://wiki.developerforce.com/index.php/Secure_Coding_SQL_Injection" target="_blank" title="http://wiki.developerforce.com/index.php/Secure_Coding_SQL_Injection"><span style="border: none windowtext 1.0pt; color: #3366bb; font-family: inherit; mso-border-alt: none windowtext 0in; padding: 0in; text-decoration: none; text-underline: none;">S(O)QL Injection</span></a><br /> 3.&nbsp;<a href="http://wiki.developerforce.com/index.php/Secure_Coding_Cross_Site_Request_Forgery" target="_blank" title="http://wiki.developerforce.com/index.php/Secure_Coding_Cross_Site_Request_Forgery"><span style="border: none windowtext 1.0pt; color: #3366bb; font-family: inherit; mso-border-alt: none windowtext 0in; padding: 0in; text-decoration: none; text-underline: none;">Cross Site Request Forgery</span></a><br /> 4.&nbsp;<a href="http://wiki.developerforce.com/index.php/Secure_Coding_Secure_Communications" target="_blank" title="http://wiki.developerforce.com/index.php/Secure_Coding_Secure_Communications"><span style="border: none windowtext 1.0pt; color: #3366bb; font-family: inherit; mso-border-alt: none windowtext 0in; padding: 0in; text-decoration: none; text-underline: none;">Secure Communications and Cookies</span></a><br /> 5.&nbsp;<a href="http://wiki.developerforce.com/index.php/Secure_Coding_Storing_Secrets" target="_blank" title="http://wiki.developerforce.com/index.php/Secure_Coding_Storing_Secrets"><span style="border: none windowtext 1.0pt; color: #3366bb; font-family: inherit; mso-border-alt: none windowtext 0in; padding: 0in; text-decoration: none; text-underline: none;">Storing Secrets</span></a><br /> 6.&nbsp;<a href="http://wiki.developerforce.com/index.php/Secure_Coding_Arbitrary_Redirect" target="_blank" title="http://wiki.developerforce.com/index.php/Secure_Coding_Arbitrary_Redirect"><span style="border: none windowtext 1.0pt; color: #3366bb; font-family: inherit; mso-border-alt: none windowtext 0in; padding: 0in; text-decoration: none; text-underline: none;">Arbitrary Redirects</span></a><br /> 7.&nbsp;<a href="http://wiki.developerforce.com/index.php/Secure_Coding_Access_Control" target="_blank" title="http://wiki.developerforce.com/index.php/Secure_Coding_Access_Control"><span style="border: none windowtext 1.0pt; color: #3366bb; font-family: inherit; mso-border-alt: none windowtext 0in; padding: 0in; text-decoration: none; text-underline: none;">Access Control</span></a><br /> 8.&nbsp;<a href="http://wiki.developerforce.com/index.php/Testing_CRUD_and_FLS_Enforcement" target="_blank" title="http://wiki.developerforce.com/index.php/Testing_CRUD_and_FLS_Enforcement"><span style="border: none windowtext 1.0pt; color: #3366bb; font-family: inherit; mso-border-alt: none windowtext 0in; padding: 0in; text-decoration: none; text-underline: none;">Enforcing CRUD and FLS (Force.com)</span></a><br /> 9.&nbsp;<a href="http://wiki.developerforce.com/index.php/Secure_Coding_Single_Sign_On" target="_blank" title="http://wiki.developerforce.com/index.php/Secure_Coding_Single_Sign_On"><span style="border: none windowtext 1.0pt; color: #3366bb; font-family: inherit; mso-border-alt: none windowtext 0in; padding: 0in; text-decoration: none; text-underline: none;">SSO for Composite Apps</span></a>&nbsp;</span><o:p></o:p></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><span style="color: #632523; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;"><o:p>&nbsp;</o:p></span><span style="color: #1f497d; font-family: Calibri, sans-serif; font-size: 11pt;">Just like PHP Toolkit / Java Client API for SalesForce, the ajax toolkit is also very simple to use&nbsp;&nbsp;</span><span style="font-family: Arial, sans-serif; font-size: 11pt;"><a href="http://www.salesforce.com/us/developer/docs/ajax/apex_ajax.pdf%20%0d2"><span style="text-decoration: none;">http://www.salesforce.com/us/developer/docs/ajax/apex_ajax.pdf</span></a></span></div></div>http://musings-on-technology.blogspot.com/2012/02/securing-enterprise-application-access.htmlnoreply@blogger.com (Kaniska)0tag:blogger.com,1999:blog-1373851816248476399.post-4886439797205340114Sat, 31 Dec 2011 23:06:00 +00002012-01-01T04:36:57.588+05:30Online CS Courses<div dir="ltr" style="text-align: left;" trbidi="on"><a href="http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/">http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/</a><br /> <span style="color: #a33033; font-family: Verdana, Arial, Helvetica, sans-serif;">Introduction to Computer Science and Programming</span><br /> <span style="color: #a33033; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 1.6em;"><br /> </span><br /> <a href="http://web.mit.edu/newsoffice/2011/mitx-faq-1219.html">http://web.mit.edu/newsoffice/2011/mitx-faq-1219.html</a> <br /> <br /> <h1 style="background-color: white; font-family: Arial, Helvetica, sans-serif; line-height: 24px; margin-bottom: 5px; margin-top: 0px;"><span style="font-size: small;">What is&nbsp;<i>MITx</i>?</span></h1><div><br /> </div><div><a href="http://academicearth.org/courses/programming-methodology">http://academicearth.org/courses/programming-methodology</a> </div><div><h1 style="background-color: #efefef; color: #333333; font-family: Arial, Helvetica, sans-serif; line-height: 1em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto;"><span style="font-size: x-small;">Computer Science I: Programming Methodology</span></h1></div></div>http://musings-on-technology.blogspot.com/2012/01/online-cs-courses.htmlnoreply@blogger.com (Kaniska)0tag:blogger.com,1999:blog-1373851816248476399.post-7705330480673396222Sat, 31 Dec 2011 22:48:00 +00002012-01-05T09:56:57.046+05:30Lightweight Persistence Service for Dynamic Entities<div dir="ltr" style="text-align: left;" trbidi="on"><br /> <div style="background-color: white; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 19px; margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto;"><strong style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Goal :</strong></div><ul style="background-color: white; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 19px; margin-bottom: 0px; margin-left: 2.6em; margin-right: 0px; margin-top: 1.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto;"><li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Persist incoming stream of Objects of into the Database.</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Parse the incoming XML/Json data to extract "Object of similar type" (i.e. a particular Business Entity) .</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">The Business Entity may have a fixed set of attributes or a dynamically changing set of attributes.</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">We should not create/maintain ORM layer and no need for POJO conversions from/to wsdl/http streams.</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">We should keep the&nbsp; persistence service layer very very light-weight.</li> </ul><div style="background-color: white; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 19px; margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto;"><strong style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Setup :</strong></div><ul style="background-color: white; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 19px; margin-bottom: 0px; margin-left: 2.6em; margin-right: 0px; margin-top: 1.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto;"><li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">mongodb2.0.1 (A database named "staging" needs to be created in MongoDB)</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">spring-data-mongodb 1.0.0.M4, mongo-java-driver 2.5.2 (and all other dependencies specified in pom.xml)</li> </ul><div style="background-color: white; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 19px; margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto;"><strong style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Development Environment :</strong>&nbsp;SpringSource Tool Suite - 2.8.1.RELEASE</div><div style="background-color: white; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 19px; margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto;"><strong style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Implementation Approach :</strong></div><ul style="background-color: white; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 19px; margin-bottom: 0px; margin-left: 2.6em; margin-right: 0px; margin-top: 1.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto;"><li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">SimpleJdbcInsert Command make things really simple when Objects of same type has a fixed set of attributes.</li> </ul><blockquote class="tr_bq"><span style="background-color: #fff2cc;">Create the singleton instance of the SimpleJdbcInsert Command for the corresponding table.</span><span style="background-color: #fff2cc;">Prepare the Map of key-value &nbsp;pairs by parsing the incoming data and simply push the data into the tables against the corresponding columns (keys in the map).</span></blockquote><blockquote class="tr_bq"><span style="background-color: #fff2cc; font-family: Consolas; font-size: 10pt; line-height: 115%;">Number num = insertCommand.executeAndReturnKey(parameters);<br /> </span><span style="background-color: #fff2cc; font-family: Consolas; font-size: 10pt; line-height: 115%;">Or insertCommand.executeBatch(…)&nbsp;&nbsp;</span></blockquote><div class="MsoNormal" style="text-align: left;"><o:p></o:p></div><ul style="background-color: white; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 19px; margin-bottom: 0px; margin-left: 2.6em; margin-right: 0px; margin-top: 1.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto;"><li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">It may be tweaked to leverage DatabaseMetadata and perform DDL on RDBMS programmatically.</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">But its very costly to Create/Update/Delete columns in relational data-store on-the-fly.</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">So finally we take resort to MongoDB.</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">If the Business Entity has a pre-defined set of attributes we should leverage the well-known annotated document object.</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Otherwise if Entity structure is changing constantly to accommodate newer attributes, then just create new DBOnjects and DBRefs.</li> </ul><div style="background-color: white; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 19px; margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto;"><em style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">MongoConfig creates a MongoTemplate against the database "staging"</em>&nbsp;<em style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">MongoDataAccessService provides all CRUD operations.</em><em style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">MongoRestController specifies all the Rest operations.</em></div><div style="background-color: white; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 19px; margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto;">Sneak Peak into the code .. org.jdom.Element rootElement = jdomDocument.getRootElement(); String rootElemName = rootElement.getName();</div><pre style="background-color: white; border-bottom-color: rgb(204, 204, 204); border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-bottom-style: solid; border-bottom-width: 1px; border-image: initial; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-left-radius: 3px; border-top-right-radius: 3px; border-top-style: solid; border-top-width: 1px; font-size: 13px; font: normal normal normal 12px/normal 'Bitstream Vera Sans Mono', Courier, monospace; line-height: 19px; margin-top: 20px; overflow-x: auto; overflow-y: auto; padding-bottom: 6px; padding-left: 10px; padding-right: 10px; padding-top: 6px; text-align: -webkit-auto;"><code style="background-color: transparent; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-left-radius: 3px; border-top-right-radius: 3px; border-top-style: none; border-width: initial; font: normal normal normal 12px/normal 'Bitstream Vera Sans Mono', Courier, monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"> if (!mongoDataAccessService.collectionExists(rootElemName)) { mongoDataAccessService.createCollection(rootElemName); } // we assume the element contains all the values for the table-columns // as the attributes. List list = rootElement.getAttributes(); DBObject parentDocument = new BasicDBObject(); // suppress _ClassName in the DbObject for (Object attr : list) { org.jdom.Attribute source = (org.jdom.Attribute) attr; if (source.getName().equals("Id")) { parentDocument.put("_id", source.getValue()); // use the original incoming Id // candidate for shard key -- TODO } else { parentDocument.put(source.getName(), source.getValue()); } } // Now iterate through the Child Elements and store them as Database // References DBRef childDocumentRef = new DBRef( mongoDataAccessService.getDB("staging"), elementName, elementId); parentDocument.put(elementName + "_ref", childDocumentRef); </code></pre><div style="background-color: white; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 19px; margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto;"><strong style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Runtime Steps :</strong></div><ul style="background-color: white; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 19px; margin-bottom: 0px; margin-left: 2.6em; margin-right: 0px; margin-top: 1.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto;"><li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">target folder already contains a pre-built war file.</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">just drop the war inside an app server context root.</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><em style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">http://localhost:8080/dynamic-data-collection/mongo/entities/add</em></li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Run the MongoRestClient to dynamically extract an entity from XML fragment and add it to the corresponding Collection.</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Simple MongoClient just creates instance of a predefined Mongo Document. This comes handy when Entity has a fixed set of attributes.</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><br /> </li> </ul><span style="font-family: helvetica, arial, freesans, clean, sans-serif;"><span style="font-size: 14px; line-height: 19px;"><b>Code :</b>&nbsp;</span></span> <a href="https://github.com/kaniska/Dynamic-Object-Persistence">https://github.com/kaniska/Dynamic-Object-Persistence</a>&nbsp;<span style="font-family: helvetica, arial, freesans, clean, sans-serif;"><span style="font-size: 14px; line-height: 19px;"><br /> </span></span><br /> <div style="background-color: white; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 19px; margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto;"><strong style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Take Away :</strong></div><ul style="background-color: white; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 19px; margin-bottom: 0px; margin-left: 2.6em; margin-right: 0px; margin-top: 1.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto;"><li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Analyze the Business requirements and accordingly categorize the types of Entities.</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">If all Entities can have pre-defined schema then use SimpleJdbcInsert Command along with MySQL / Oracle for best performance.</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">But in case the Business Process consists of both fixed and dynamic entities, then consider the following approach.</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Define annotated POJO (Mongo Document) for the Entities having a fixed structure.</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">If same type of Entity has different set of attributes for different entities then consider creating them dynamically.</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">So the choice of database (MongoDB Vs RDBMS) - depends upon how much dynamism one needs to accommodate in the application.</li> </ul><div style="background-color: white; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 19px; margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto;"><b>Future Improvements</b></div><ol style="background-color: white; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 19px; margin-bottom: 0px; margin-left: 2.6em; margin-right: 0px; margin-top: 1.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left;"><li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><div style="margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Externalize the MongoDB configuration in external properties file. (Tried but somehow it did not work.)</div></li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><div style="margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Use the latest Spring-MongoDB release</div></li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><div style="margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Work with XPathOperations instead of parsing xml fragments manually.</div></li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><div style="margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Figure out if Spring-Data MongoDB API leverages latest Morphia annotations for journal-sync, suppressing _ClassName in objects etc.</div><div style="margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><b>Reference :&nbsp;</b><a href="http://www.springsource.org/spring-data/mongodb">http://www.springsource.org/spring-data/mongodb</a></div></li> </ol></div>http://musings-on-technology.blogspot.com/2012/01/lightweight-persistence-service-for.htmlnoreply@blogger.com (Kaniska)0tag:blogger.com,1999:blog-1373851816248476399.post-137478637139424746Sun, 18 Sep 2011 20:32:00 +00002011-09-19T02:02:04.771+05:30DreamForce Presentations<div dir="ltr" style="text-align: left;" trbidi="on"><br /> <table border="0" cellpadding="0" class="MsoNormalTable" style="width: 600px;"><tbody> <tr> <td style="border-bottom: solid #DEE5EA 1.0pt; border: none; mso-border-bottom-alt: solid #DEE5EA .75pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;" valign="top"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><img alt="Session" id="_x0000_i1025" src="https://dreamevent.my.salesforce.com/img/icon/plane16.png?fromEmail=1" title="Session" />&nbsp;<a href="https://dreamevent.my.salesforce.com/a093000000CeqeV?fromEmail=1"><b>Designing for the Cloud: The 12 Factor App</b></a> — <span class="feeditemtext1"><a href="https://dreamevent.my.salesforce.com/00530000004oi1U?fromEmail=1"><b>Valerie Ringer</b></a> The slides are on Ryan's web page ryandotsmith.heroku.com</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="https://dreamevent.my.salesforce.com/a093000000CeqeV?ChatterFeedItemId=0D53000000RX6vj&amp;fromEmail=1"><span class="feeditemtimestamp1">Saturday, September 17, 2011 4:46 PM</span></a> &nbsp; <a href="https://dreamevent.my.salesforce.com/a093000000CeqeV?OpenCommentForEdit=1&amp;ChatterFeedItemId=0D53000000RX6vj&amp;fromEmail=1"><span class="commentverb1"><span style="font-size: 8.5pt;">Comment</span></span></a><o:p></o:p></span></div></td> </tr> <tr> <td style="border-bottom: solid #DEE5EA 1.0pt; border: none; mso-border-bottom-alt: solid #DEE5EA .75pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;" valign="top"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><img alt="Session" border="0" id="_x0000_i1026" src="https://dreamevent.my.salesforce.com/img/icon/plane16.png?fromEmail=1" title="Session" />&nbsp;<a href="https://dreamevent.my.salesforce.com/a093000000COQgy?fromEmail=1"><b>Using Node.js on Heroku</b></a> — <span class="feeditemtext1"><a href="https://dreamevent.my.salesforce.com/005300000040AgQ?fromEmail=1"><b>Pat Patterson</b></a> Session video on YouTube</span></span><span class="feeditemtext1"><span style="font-size: 9.0pt;"><o:p></o:p></span></span></div><table border="0" cellpadding="0" class="MsoNormalTable"><tbody> <tr> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><img alt="Using Node.js on Heroku" border="0" height="16" id="_x0000_i1027" src="https://dreamevent.my.salesforce.com/img/chatterEmail/link16.png?fromEmail=1" title="Using Node.js on Heroku" width="16" /><o:p></o:p></span></div></td> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="http://www.youtube.com/watch?v=PACwQ632jIE&amp;fromEmail=1" target="_blank"><span title="http://www.youtube.com/watch?v=PACwQ632jIE">Using Node.js on Heroku</span></a><o:p></o:p></span></div></td> </tr> <tr> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><br /> </div></td> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="http://www.youtube.com/watch?v=PACwQ632jIE">http://www.youtube.com/watch?v=PACwQ632jIE</a><o:p></o:p></span></div></td> </tr> </tbody></table><div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="https://dreamevent.my.salesforce.com/a093000000COQgy?ChatterFeedItemId=0D53000000RX5Ej&amp;fromEmail=1"><span class="feeditemtimestamp1">Saturday, September 17, 2011 10:52 AM</span></a> &nbsp; <a href="https://dreamevent.my.salesforce.com/a093000000COQgy?OpenCommentForEdit=1&amp;ChatterFeedItemId=0D53000000RX5Ej&amp;fromEmail=1"><span class="commentverb1"><span style="font-size: 8.5pt;">Comment</span></span></a></span><o:p></o:p></div></td> </tr> <tr> <td style="border-bottom: solid #DEE5EA 1.0pt; border: none; mso-border-bottom-alt: solid #DEE5EA .75pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;" valign="top"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><img alt="Session" border="0" id="_x0000_i1028" src="https://dreamevent.my.salesforce.com/img/icon/plane16.png?fromEmail=1" title="Session" />&nbsp;<a href="https://dreamevent.my.salesforce.com/a0930000009YIQw?fromEmail=1"><b>The Next Step of Evolution in the Force.com REST API</b></a> — <span class="feeditemtext1"><a href="https://dreamevent.my.salesforce.com/005300000040AgQ?fromEmail=1"><b>Pat Patterson</b></a> Session video on YouTube</span></span><span class="feeditemtext1"><span style="font-size: 9.0pt;"><o:p></o:p></span></span></div><table border="0" cellpadding="0" class="MsoNormalTable"><tbody> <tr> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><img alt="The Next Step of Evolution in the Force.com REST API" border="0" height="16" id="_x0000_i1029" src="https://dreamevent.my.salesforce.com/img/chatterEmail/link16.png?fromEmail=1" title="The Next Step of Evolution in the Force.com REST API" width="16" /><o:p></o:p></span></div></td> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="http://www.youtube.com/watch?v=9ur5D1Q-oCQ&amp;fromEmail=1" target="_blank"><span title="http://www.youtube.com/watch?v=9ur5D1Q-oCQ">The Next Step of Evolution in the Force.com REST API</span></a><o:p></o:p></span></div></td> </tr> <tr> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><br /> </div></td> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="http://www.youtube.com/watch?v=9ur5D1Q-oCQ">http://www.youtube.com/watch?v=9ur5D1Q-oCQ</a><o:p></o:p></span></div></td> </tr> </tbody></table><div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="https://dreamevent.my.salesforce.com/a0930000009YIQw?ChatterFeedItemId=0D53000000RX5Ee&amp;fromEmail=1"><span class="feeditemtimestamp1">Saturday, September 17, 2011 10:51 AM</span></a> &nbsp; <a href="https://dreamevent.my.salesforce.com/a0930000009YIQw?OpenCommentForEdit=1&amp;ChatterFeedItemId=0D53000000RX5Ee&amp;fromEmail=1"><span class="commentverb1"><span style="font-size: 8.5pt;">Comment</span></span></a></span><o:p></o:p></div></td> </tr> <tr> <td style="border-bottom: solid #DEE5EA 1.0pt; border: none; mso-border-bottom-alt: solid #DEE5EA .75pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;" valign="top"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><img alt="Session" border="0" id="_x0000_i1030" src="https://dreamevent.my.salesforce.com/img/icon/plane16.png?fromEmail=1" title="Session" />&nbsp;<a href="https://dreamevent.my.salesforce.com/a0930000009YIPB?fromEmail=1"><b>Security and Authentication for Mobile Apps</b></a> — <span class="feeditemtext1"><a href="https://dreamevent.my.salesforce.com/005300000040AgQ?fromEmail=1"><b>Pat Patterson</b></a> Session video on YouTube</span></span><span class="feeditemtext1"><span style="font-size: 9.0pt;"><o:p></o:p></span></span></div><table border="0" cellpadding="0" class="MsoNormalTable"><tbody> <tr> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><img alt="Security and Authentication for Mobile Apps" border="0" height="16" id="_x0000_i1031" src="https://dreamevent.my.salesforce.com/img/chatterEmail/link16.png?fromEmail=1" title="Security and Authentication for Mobile Apps" width="16" /><o:p></o:p></span></div></td> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="http://www.youtube.com/watch?v=ia8yaTtnK0w&amp;fromEmail=1" target="_blank"><span title="http://www.youtube.com/watch?v=ia8yaTtnK0w">Security and Authentication for Mobile Apps</span></a><o:p></o:p></span></div></td> </tr> <tr> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><br /> </div></td> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="http://www.youtube.com/watch?v=ia8yaTtnK0w">http://www.youtube.com/watch?v=ia8yaTtnK0w</a><o:p></o:p></span></div></td> </tr> </tbody></table><div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="https://dreamevent.my.salesforce.com/a0930000009YIPB?ChatterFeedItemId=0D53000000RX4z2&amp;fromEmail=1"><span class="feeditemtimestamp1">Saturday, September 17, 2011 10:32 AM</span></a> &nbsp; <a href="https://dreamevent.my.salesforce.com/a0930000009YIPB?OpenCommentForEdit=1&amp;ChatterFeedItemId=0D53000000RX4z2&amp;fromEmail=1"><span class="commentverb1"><span style="font-size: 8.5pt;">Comment</span></span></a></span><o:p></o:p></div></td> </tr> <tr> <td style="border-bottom: solid #DEE5EA 1.0pt; border: none; mso-border-bottom-alt: solid #DEE5EA .75pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;" valign="top"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><img alt="Session" border="0" id="_x0000_i1032" src="https://dreamevent.my.salesforce.com/img/icon/plane16.png?fromEmail=1" title="Session" />&nbsp;<a href="https://dreamevent.my.salesforce.com/a0930000009YIP3?fromEmail=1"><b>Mashing Up the Cloud with Force.com Toolkits</b></a> — <span class="feeditemtext1"><a href="https://dreamevent.my.salesforce.com/005300000040AgQ?fromEmail=1"><b>Pat Patterson</b></a> Session video on YouTube</span></span><span class="feeditemtext1"><span style="font-size: 9.0pt;"><o:p></o:p></span></span></div><table border="0" cellpadding="0" class="MsoNormalTable"><tbody> <tr> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><img alt="Mashing Up the Cloud with Force.com Toolkits" border="0" height="16" id="_x0000_i1033" src="https://dreamevent.my.salesforce.com/img/chatterEmail/link16.png?fromEmail=1" title="Mashing Up the Cloud with Force.com Toolkits" width="16" /><o:p></o:p></span></div></td> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="http://www.youtube.com/watch?v=pe2Ke4a9zas&amp;fromEmail=1" target="_blank"><span title="http://www.youtube.com/watch?v=pe2Ke4a9zas">Mashing Up the Cloud with Force.com Toolkits</span></a><o:p></o:p></span></div></td> </tr> <tr> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><br /> </div></td> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="http://www.youtube.com/watch?v=pe2Ke4a9zas">http://www.youtube.com/watch?v=pe2Ke4a9zas</a><o:p></o:p></span></div></td> </tr> </tbody></table><div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="https://dreamevent.my.salesforce.com/a0930000009YIP3?ChatterFeedItemId=0D53000000RX55j&amp;fromEmail=1"><span class="feeditemtimestamp1">Saturday, September 17, 2011 10:27 AM</span></a> &nbsp; <a href="https://dreamevent.my.salesforce.com/a0930000009YIP3?OpenCommentForEdit=1&amp;ChatterFeedItemId=0D53000000RX55j&amp;fromEmail=1"><span class="commentverb1"><span style="font-size: 8.5pt;">Comment</span></span></a></span><o:p></o:p></div></td> </tr> <tr> <td style="border-bottom: solid #DEE5EA 1.0pt; border: none; mso-border-bottom-alt: solid #DEE5EA .75pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;" valign="top"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><img alt="Session" border="0" id="_x0000_i1034" src="https://dreamevent.my.salesforce.com/img/icon/plane16.png?fromEmail=1" title="Session" />&nbsp;<a href="https://dreamevent.my.salesforce.com/a093000000BtFdV?fromEmail=1"><b>HTML 5 and Geo-Location Using Visualforce and Apex</b></a> — <span class="feeditemtext1"><a href="https://dreamevent.my.salesforce.com/005300000040AgQ?fromEmail=1"><b>Pat Patterson</b></a> Session video on YouTube</span></span><span class="feeditemtext1"><span style="font-size: 9.0pt;"><o:p></o:p></span></span></div><table border="0" cellpadding="0" class="MsoNormalTable"><tbody> <tr> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><img alt="HTML 5 and Geo-Location Using Visualforce and Apex" border="0" height="16" id="_x0000_i1035" src="https://dreamevent.my.salesforce.com/img/chatterEmail/link16.png?fromEmail=1" title="HTML 5 and Geo-Location Using Visualforce and Apex" width="16" /><o:p></o:p></span></div></td> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="http://www.youtube.com/watch?v=wwTdGqOygBQ&amp;fromEmail=1" target="_blank"><span title="http://www.youtube.com/watch?v=wwTdGqOygBQ">HTML 5 and Geo-Location Using Visualforce and Apex</span></a><o:p></o:p></span></div></td> </tr> <tr> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><br /> </div></td> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="http://www.youtube.com/watch?v=wwTdGqOygBQ">http://www.youtube.com/watch?v=wwTdGqOygBQ</a><o:p></o:p></span></div></td> </tr> </tbody></table><div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="https://dreamevent.my.salesforce.com/a093000000BtFdV?ChatterFeedItemId=0D53000000RX4o3&amp;fromEmail=1"><span class="feeditemtimestamp1">Saturday, September 17, 2011 10:26 AM</span></a> &nbsp; <a href="https://dreamevent.my.salesforce.com/a093000000BtFdV?OpenCommentForEdit=1&amp;ChatterFeedItemId=0D53000000RX4o3&amp;fromEmail=1"><span class="commentverb1"><span style="font-size: 8.5pt;">Comment</span></span></a></span><o:p></o:p></div></td> </tr> <tr> <td style="border-bottom: solid #DEE5EA 1.0pt; border: none; mso-border-bottom-alt: solid #DEE5EA .75pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;" valign="top"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><img alt="Session" border="0" id="_x0000_i1036" src="https://dreamevent.my.salesforce.com/img/icon/plane16.png?fromEmail=1" title="Session" />&nbsp;<a href="https://dreamevent.my.salesforce.com/a0930000009YINh?fromEmail=1"><b>Getting Started with the Force.com Streaming API</b></a> — <span class="feeditemtext1"><a href="https://dreamevent.my.salesforce.com/005300000040AgQ?fromEmail=1"><b>Pat Patterson</b></a> Session video on YouTube</span></span><span class="feeditemtext1"><span style="font-size: 9.0pt;"><o:p></o:p></span></span></div><table border="0" cellpadding="0" class="MsoNormalTable"><tbody> <tr> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><img alt="Getting Started with the Force.com Streaming API" border="0" height="16" id="_x0000_i1037" src="https://dreamevent.my.salesforce.com/img/chatterEmail/link16.png?fromEmail=1" title="Getting Started with the Force.com Streaming API" width="16" /><o:p></o:p></span></div></td> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="http://www.youtube.com/watch?v=8UqeVRiv6-s&amp;fromEmail=1" target="_blank"><span title="http://www.youtube.com/watch?v=8UqeVRiv6-s">Getting Started with the Force.com Streaming API</span></a><o:p></o:p></span></div></td> </tr> <tr> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><br /> </div></td> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="http://www.youtube.com/watch?v=8UqeVRiv6-s">http://www.youtube.com/watch?v=8UqeVRiv6-s</a><o:p></o:p></span></div></td> </tr> </tbody></table><div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="https://dreamevent.my.salesforce.com/a0930000009YINh?ChatterFeedItemId=0D53000000RX50J&amp;fromEmail=1"><span class="feeditemtimestamp1">Saturday, September 17, 2011 10:25 AM</span></a> &nbsp; <a href="https://dreamevent.my.salesforce.com/a0930000009YINh?OpenCommentForEdit=1&amp;ChatterFeedItemId=0D53000000RX50J&amp;fromEmail=1"><span class="commentverb1"><span style="font-size: 8.5pt;">Comment</span></span></a></span><o:p></o:p></div></td> </tr> <tr> <td style="border-bottom: solid #DEE5EA 1.0pt; border: none; mso-border-bottom-alt: solid #DEE5EA .75pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;" valign="top"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><img alt="Session" border="0" id="_x0000_i1038" src="https://dreamevent.my.salesforce.com/img/icon/plane16.png?fromEmail=1" title="Session" />&nbsp;<a href="https://dreamevent.my.salesforce.com/a093000000CPLnH?fromEmail=1"><b>Event-Driven Programming with Node.js and the Force.com Streaming API</b></a> — <span class="feeditemtext1"><a href="https://dreamevent.my.salesforce.com/005300000040AgQ?fromEmail=1"><b>Pat Patterson</b></a> Session video on YouTube</span></span><span class="feeditemtext1"><span style="font-size: 9.0pt;"><o:p></o:p></span></span></div><table border="0" cellpadding="0" class="MsoNormalTable"><tbody> <tr> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><img alt="Event-Driven Programming with Node.js and the Force.com Streaming API" border="0" height="16" id="_x0000_i1039" src="https://dreamevent.my.salesforce.com/img/chatterEmail/link16.png?fromEmail=1" title="Event-Driven Programming with Node.js and the Force.com Streaming API" width="16" /><o:p></o:p></span></div></td> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="http://www.youtube.com/watch?v=_Vt0TPS5HLw&amp;fromEmail=1" target="_blank"><span title="http://www.youtube.com/watch?v=_Vt0TPS5HLw">Event-Driven Programming with Node.js and the Force.com Streaming API</span></a><o:p></o:p></span></div></td> </tr> <tr> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><br /> </div></td> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="http://www.youtube.com/watch?v=_Vt0TPS5HLw">http://www.youtube.com/watch?v=_Vt0TPS5HLw</a><o:p></o:p></span></div></td> </tr> </tbody></table><div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="https://dreamevent.my.salesforce.com/a093000000CPLnH?ChatterFeedItemId=0D53000000RX4z1&amp;fromEmail=1"><span class="feeditemtimestamp1">Saturday, September 17, 2011 10:23 AM</span></a> &nbsp; <a href="https://dreamevent.my.salesforce.com/a093000000CPLnH?OpenCommentForEdit=1&amp;ChatterFeedItemId=0D53000000RX4z1&amp;fromEmail=1"><span class="commentverb1"><span style="font-size: 8.5pt;">Comment</span></span></a></span><o:p></o:p></div></td> </tr> <tr> <td style="border-bottom: solid #DEE5EA 1.0pt; border: none; mso-border-bottom-alt: solid #DEE5EA .75pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;" valign="top"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><img alt="Session" border="0" id="_x0000_i1040" src="https://dreamevent.my.salesforce.com/img/icon/plane16.png?fromEmail=1" title="Session" />&nbsp;<a href="https://dreamevent.my.salesforce.com/a093000000BrGSS?fromEmail=1"><b>Authentication: A Practical Guide</b></a> — <span class="feeditemtext1"><a href="https://dreamevent.my.salesforce.com/005300000040AgQ?fromEmail=1"><b>Pat Patterson</b></a> Session video on YouTube</span></span><span class="feeditemtext1"><span style="font-size: 9.0pt;"><o:p></o:p></span></span></div><table border="0" cellpadding="0" class="MsoNormalTable"><tbody> <tr> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><img alt="Authentication: A Practical Guide" border="0" height="16" id="_x0000_i1041" src="https://dreamevent.my.salesforce.com/img/chatterEmail/link16.png?fromEmail=1" title="Authentication: A Practical Guide" width="16" /><o:p></o:p></span></div></td> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="http://www.youtube.com/watch?v=9McaWgMLprs&amp;fromEmail=1" target="_blank"><span title="http://www.youtube.com/watch?v=9McaWgMLprs">Authentication: A Practical Guide</span></a><o:p></o:p></span></div></td> </tr> <tr> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><br /> </div></td> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="http://www.youtube.com/watch?v=9McaWgMLprs">http://www.youtube.com/watch?v=9McaWgMLprs</a><o:p></o:p></span></div></td> </tr> </tbody></table><div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="https://dreamevent.my.salesforce.com/a093000000BrGSS?ChatterFeedItemId=0D53000000RX50t&amp;fromEmail=1"><span class="feeditemtimestamp1">Saturday, September 17, 2011 10:02 AM</span></a> &nbsp; <a href="https://dreamevent.my.salesforce.com/a093000000BrGSS?OpenCommentForEdit=1&amp;ChatterFeedItemId=0D53000000RX50t&amp;fromEmail=1"><span class="commentverb1"><span style="font-size: 8.5pt;">Comment</span></span></a></span><o:p></o:p></div></td> </tr> </tbody></table></div>http://musings-on-technology.blogspot.com/2011/09/dreamforce-presentations.htmlnoreply@blogger.com (Kaniska)0tag:blogger.com,1999:blog-1373851816248476399.post-4499025359788798362Fri, 27 May 2011 06:49:00 +00002011-05-28T08:59:52.996+05:30Challenge the Conventional Wisdom : MongoSF 2011<div dir="ltr" style="text-align: left;" trbidi="on"><div class="separator" style="clear: both; text-align: center;"><span class="Apple-style-span" style="font-family: inherit;">||| MongoSF , May 25, 2011 &nbsp;|||</span></div><span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6glsYSlpixPQZMZMORq-2Cmo8jewE10al_gG_quVRg_bTcuxq1XAt6Awh09Pezw7bUIoEv0dkxeqzCIZb-UNqpw4PLZvSZs3_elncbhuOFsqx7Lokc2eabsTQ3Ogbf3Q3cOyrZKmnHg8/s1600/moon_walk.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6glsYSlpixPQZMZMORq-2Cmo8jewE10al_gG_quVRg_bTcuxq1XAt6Awh09Pezw7bUIoEv0dkxeqzCIZb-UNqpw4PLZvSZs3_elncbhuOFsqx7Lokc2eabsTQ3Ogbf3Q3cOyrZKmnHg8/s320/moon_walk.png" width="242" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjQ654AU_DD3iqt3Dxiz9qUrSCZAM812H-GXaY1dYmFnPGIklSZyOsZ12MOW0iiMs54-N0Ym5G4X9lQp8T6P4oZyky8tEBhV3TfeRzLtAjUNl2zemeAVMUsb3qEAJ3Q3_C0UNJUMxg3Kg/s1600/www.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="109" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjQ654AU_DD3iqt3Dxiz9qUrSCZAM812H-GXaY1dYmFnPGIklSZyOsZ12MOW0iiMs54-N0Ym5G4X9lQp8T6P4oZyky8tEBhV3TfeRzLtAjUNl2zemeAVMUsb3qEAJ3Q3_C0UNJUMxg3Kg/s320/www.png" style="cursor: move;" width="320" /></a></span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;">* shamelessly borrowed from Kyle's great slides ... &nbsp;I consider this as the best example to drive home the simple yet strong message from MongoSF Seminar !</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="color: #741b47; font-family: inherit;"><b>Professor Calculus trying to convince Captain Haddock that he should embark upon the Shuttle to Planet MONGO !</b></span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;"><b>Capt. H :</b> <span class="Apple-style-span" style="color: #660000;">My data is not super-transactional , but time-critical and move very fast .. So are you saying <b>I don't need Normalization </b>?</span></span><br /> <span class="Apple-style-span" style="font-family: inherit;"><b>Prof. C :</b> &nbsp;<span class="Apple-style-span" style="color: #20124d;">Exactly ! <b>Design your database as per your usecase</b>. In <b>absence of a schema</b>, no need to build/maintain the lifecycle of a model (conceptual [ERD]-&gt; logical [UML] -&gt; physical [DB] -&gt; sql -&gt; xsd ..)</span></span><br /> <span class="Apple-style-span" style="color: #20124d;"><span class="Apple-style-span" style="font-family: inherit;">Captain! just&nbsp;</span>spell-out your thoughts as</span>..<span class="Apple-style-span" style="color: #38761d;"><b>{vendor_id : "apple", products : ["iphone","ipod", "ipad"] }</b></span><br /> <span class="Apple-style-span" style="font-family: inherit;">Embedded Array is a powerful concept to get a list of associated entities for a specific entity at one go !&nbsp;</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;">With full respect to RDBMS world (which will always be relevant in the Operational Domain like sayManufacturing ...) few imp points to remember :</span><br /> <span class="Apple-style-span" style="font-family: inherit;">&gt;&gt; &nbsp;</span><span class="Apple-style-span" style="color: #20124d;">Tradional DB - Schema has no bias for a specific usecase. It encompasses all possible relationships between the entities (stakeholders) of a domain !</span><br /> <span class="Apple-style-span" style="font-family: inherit;">&gt;&gt; </span><span class="Apple-style-span" style="color: #20124d;"><span class="Apple-style-span" style="font-family: inherit;">So its great for ad-hoc queries and data-rigid ness .... &nbsp;but very very slow for data manipulation and for hopping around !! This trade-off can be equated with the famous trade-offs between 'bloated Wsdl and simplistic Rest' or 'Schematic XML and&nbsp;</span>Schema-less<span class="Apple-style-span" style="font-family: inherit;">&nbsp;Json' !</span></span><br /> <br /> <span class="Apple-style-span" style="font-family: inherit;"><b>Capt. H : </b>&nbsp;<span class="Apple-style-span" style="color: #660000;">Traditionally, first I normalize the data for OLTP and then de-normalize the data for BI .. &nbsp;?</span></span><br /> <span class="Apple-style-span" style="font-family: inherit;"><b>Prof. C :</b> &nbsp;I do understand your pain points ! Welcome to MongoDB &nbsp;!<span class="Apple-style-span" style="color: #4c1130;"> Just fire few aggregation queries on the same document that stores your business model and you extract all the intelligence at no extra cost !</span></span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;"><b>Capt. H :</b><span class="Apple-style-span" style="color: #660000;"> So far so good ! Do I still need&nbsp;a Cache or ORM layer ?</span></span><br /> <span class="Apple-style-span" style="font-family: inherit;"><b>Prof. C :</b> Well.. Captain .. <span class="Apple-style-span" style="color: #4c1130;">Caching was a Work-around for slow lookups from over-burdened database</span> !</span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;">Now the <b>db itself is extremely light weight engine </b>- fast lock-free lookup, aycnchonous parrallel writes, distributed loads on shards etc. etc.</span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;">- ORM is another work-around to abstract rigid SQL and convert pojo from specific framework to db entities ! .. Well .. in most of cases .. no need for any sort of mappng ideally ! MongoDB manadates that Code and Data should reside in seperate layers and each understand one standard i.e. Json!&nbsp;</span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;"><b>It flows so smoothly from front-end &nbsp;(Php/pearl/python/gwt/js .. all understand json) to the json-friendly Rest layer and finally lands on the lap of MongoDB as Bson !</b>&nbsp;</span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;">Rememeber ...&nbsp;we now have a database which itself <b>follows object structure</b> that your app layer is based on ... <b>&nbsp;so no need of any ORM layer</b> !</span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;">Now for the sake of backward&nbsp;compatibility and smooth integration with existing&nbsp;pojo-based apps (which were talking to rdbms), Spring-data provides nice wrappers to NoSqls !</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <b>Capt. H :</b><span class="Apple-style-span" style="color: #660000; font-family: inherit;">Well I love breaking down a large Entity like Product into multiple components like - { line_item, payment, order, etc.. } .. but I pay the heavy price of slow joins ?</span><br /> <b>Prof. C :</b><span class="Apple-style-span" style="font-family: inherit;">&nbsp;<span class="Apple-style-span" style="color: #20124d;">Hmm .. how about creating <b>a Rich Document - Product and then embed sub-documents</b> {line_ites, payment, order..} inside the parent..</span></span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;">Then index on sub documents and perform super-fast asynchrnous atomic updates on a single document</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <b>Capt. H :&nbsp;</b><span class="Apple-style-span" style="color: #660000; font-family: inherit;">Great ! You know .. I love storing the parent-child relationship .. i.e. the Inheritence or.. a Tree-Hierarchy in a single table .... &nbsp;but as a result in RDBMS .. you know .. I have redundant columns !!</span><br /> <b>Prof. C :</b><span class="Apple-style-span" style="font-family: inherit;">&nbsp;<span class="Apple-style-span" style="color: #20124d;">No worries ! in MongoDB,<b> data itself defines its schema</b> ! (metadata free modelling)&nbsp;</span></span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;">So you can specify ...</span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;">db.shapes.find()</span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;">&nbsp; {_id:"1",type:"circle",area: 3.14, radius: 1 }</span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;">&nbsp; {_id:"2",type:"square",area: 4, d: 2 }</span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;">&nbsp; {_id:"3",type:"rect",area: 10, length: 5 , width: 2}</span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;">-- And wait .. you can <b>apply the beautiful 'Sparse Index' to diverse data-set</b> stored inside same collection !</span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;">Did you catch the sweet spot 'radius' - just by its sheer presence as an unique attribute an 'inherent restriction' is applied on the collection.</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;"><b>Capt H:</b> <span class="Apple-style-span" style="color: #660000;">Professor .. You simply Rock ! .. I kinda learnt how to partition my data in rdbms ! But so difficult to maintain when data outgrows the chunks ...</span></span><br /> <span class="Apple-style-span" style="font-family: inherit;"><b>Prof C</b>. .. <span class="Apple-style-span" style="color: #20124d;">Sorry to hear that captain ! ... <b>data-partitioning is a no brainer</b> !</span></span><br /> <span class="Apple-style-span" style="font-family: monospace; line-height: 16px; white-space: pre-wrap;">db.runCommand( { addshard : <span class="code-quote" style="background-color: inherit; color: #009100; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">"localhost:10000"</span> } )</span><br /> <pre class="code-java" style="line-height: 1.3; margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 10px; overflow-x: auto; overflow-y: auto; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; white-space: pre-wrap;"><span class="Apple-style-span" style="font-family: inherit;">{ <span class="code-quote" style="background-color: inherit; color: #009100; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">"shardadded"</span> : <span class="code-quote" style="background-color: inherit; color: #009100; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">"shard0000"</span>, <span class="code-quote" style="background-color: inherit; color: #009100; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">"ok"</span> : 1 } db.runCommand( { addshard : <span class="code-quote" style="background-color: inherit; color: #009100; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">"localhost:10001"</span> } ) { <span class="code-quote" style="background-color: inherit; color: #009100; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">"shardadded"</span> : <span class="code-quote" style="background-color: inherit; color: #009100; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">"shard0001"</span>, <span class="code-quote" style="background-color: inherit; color: #009100; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">"ok"</span> : 1 }</span></pre><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;">All the goodness of&nbsp;sophisticated <b>master-slave nodes allocation, replication, internal node state management, auto-recovery</b> are provided out-of-the box !&nbsp;</span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;"><b>ReplicaSet </b>Mode detects all the hosts every 5 sec.</span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;"><b>Replica1 </b>: {chunk1(user1 - user100) =&gt; shard1, chunk2(user101 - user 200) =&gt; shard1}</span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;"><b>Replica2 </b>: {chunk1(user1 - user100) =&gt; shard1, chunk2(user101 - user 200) =&gt; shard1}</span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;">MongoS process is the load-balancer. Upon startup it finds out which servers are up and based on the latency picks the shard. It routes the chunks between shards in replica sets.</span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;">If new hot chunk is created, MongoS can dynamically allocate the chunk to an available shard - shard2.</span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;">Otherwise it will spawn new shard by dividing existing shard at its median !</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <b>Capt H:&nbsp;</b><span class="Apple-style-span" style="color: #660000; font-family: inherit;">Very Interesting ! So I can choose whether my <b>query will work on primary or secondary</b>.</span><br /> <b>Prof C:&nbsp;</b><span class="Apple-style-span" style="color: #20124d; font-family: inherit;">You got it right ! For immediate consistency, query from / write into the primary master. For eventual consistency query the slaves ! Reads may go out-of-date on slaves. Its just a tip of iceberg ! So refer to the document for more details !</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <b>Capt H:&nbsp;</b><span class="Apple-style-span" style="color: #20124d; font-family: inherit;">Great ! Now that my app working fine ... need to do some analysis .. So coming to <b>data-crunching in batch</b> ! I am a startup guy and have no time to setup hadoop-hive-mahout on a seperate cluster , neither have the luxury to build the&nbsp;infrastructure&nbsp;of Amazon Elastic Map-Reduce .... &nbsp;so .. I guess .. MongoDB ..</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <b>Prof C:&nbsp;</b><span class="Apple-style-span" style="font-family: inherit;">&nbsp;<span class="Apple-style-span" style="color: #20124d;">Oh ! Yah ! Absolutely ! Right here ... Why as a developer in a fast-paced-env you need to worry about the gory details of data crunching !! <b>Just call map-reduce api</b> ! Stay tuned ! Out-of-the box Aggregation API coming soon ! Remember the key point ... &nbsp;you can now <b>enjoy a real-time streaming analytics with negligible latency </b>!</span></span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <b>Capt H: &nbsp;</b><span class="Apple-style-span" style="color: #660000; font-family: inherit;">I am ecstatic to hear this ! On a different note I love indexed-based searching using lucene-solr .. but just checking in if ..</span><br /> <b>Prof C:&nbsp;</b><span class="Apple-style-span" style="font-family: inherit;">&nbsp;<span class="Apple-style-span" style="color: #20124d;">Sure ! MongoDB hears you ... &nbsp;full-fledged text-searching .. will be released by end of 2011 !</span></span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <b>Capt H:&nbsp;</b><span class="Apple-style-span" style="color: #660000; font-family: inherit;">I love Scala and Node.js .. a big fan of <b>executing requests&nbsp;parallely ..&nbsp;</b>&nbsp;but it gets very tricky to solve table-level and row-level locking issues in Database ....</span><br /> <b>Prof C:</b><span class="Apple-style-span" style="font-family: inherit;">&nbsp;<span class="Apple-style-span" style="color: #20124d;">Absolutely ! <b>Your writes per document are atomic and reads are parallel in nature</b> (cpu cores scaling out not speeding up ... so mongodb native threads just love&nbsp;asynchronous&nbsp;parallel processing) ! But if writes fail .. there is no auto-rollback machanism .. your app should be responsible for data consistency ! &nbsp;No support for distributed transactions ! &nbsp;So use a language of your choice and no need to shard in the app layer !</span></span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <b>Capt H:&nbsp;</b><span class="Apple-style-span" style="color: #660000; font-family: inherit;">A compelling reason for adopting AWS was SimpleDB .. I mean instead of moving my DB to Cloud I tried to &nbsp;access a DB on Cloud .. but sacrificed many features of RDBMS .... &nbsp;So .. is it a Big Ask from Mongo ... ?</span><br /> <b>Prof C:&nbsp;</b><span class="Apple-style-span" style="font-family: inherit;">&nbsp;<span class="Apple-style-span" style="color: #20124d;">Not at all ! &nbsp;MongoDB is <b>Cloud-ready by virtue of its horizontal scalability, multi-tenancy , fail-safe nature, statelessness and atomic transactions. Scale linearly, increase capacity with no down-time.</b></span></span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="color: #741b47; font-family: inherit;"><b>So Captain Welcome Aboard ! Enjoy your journey into Mongo !</b></span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <b><span class="Apple-style-span" style="color: #741b47;">With freedom comes responsibility :</span></b><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;">1. <span class="Apple-style-span" style="color: #20124d;">MongoDB<b> does not encourage storing reverse links in referred documents</b> for implementing many-2-many relationship. </span></span><br /> <span class="Apple-style-span" style="font-family: inherit;">Captain I know you love your language .. you wont mind couple of extra lines of query in app layer :-)</span><br /> <span class="Apple-style-span" style="font-family: inherit;">//All categories for a given product</span><br /> <span class="Apple-style-span" style="font-family: inherit;">product = db.products.find(_id, prod_id);</span><br /> <span class="Apple-style-span" style="font-family: inherit;">db.categories.find({_id: &nbsp;{$in : product.category_ids} })</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;">2. <b><span class="Apple-style-span" style="color: #20124d;">Its not a full-fledged caching solution</span></b> ... so there are pending issues with data-eviction ! Expired objects reportedly sit back in memory ! MongoDB believes in reusing memory rather than suffering from reclaiming-reallocating overhead every now-n -then ! But the garbage collection algo definitely get better and better with community support !</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;">3. The thrust is on 'eventual consistency' for writes. there is <span class="Apple-style-span" style="color: #351c75;"><b>no 'Retries' for writes</b></span> !<b><span class="Apple-style-span" style="color: #20124d;"> So we need to judiciously handle the write-exceptions in app layer.</span></b> We need to remember - if we explicitly mark a 'transaction request' as 'done' then only mongoDB driver will clean-up the connection from the thread-local !</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;">4. While designing the data model, we need to understand where to <b><span class="Apple-style-span" style="color: #073763;">'embed'</span></b> and where to<span class="Apple-style-span" style="color: #0b5394;"><b> 'link</b></span>.</span><br /> <span class="Apple-style-span" style="font-family: inherit;">Definitely 'Linking' has a higher 'cost of relocation' than 'Embedding'. That implies in a Tree we better store the list of&nbsp;descendants&nbsp;directly.</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;">5. The workingSet size should be kept minimal and need to be distributed evenly.</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><span class="Apple-style-span" style="color: #073763;"><b>Pre-splitting for initial bulk loading is always advised.</b></span>&nbsp;</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;">6.<span class="Apple-style-span" style="color: #0b5394;"><b> Queries on sharded key are fastest</b></span>.</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;">7. For pagination we should depend upon stateful cursor_index instead of depending on stateless sharded key.</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="color: #660000; font-family: inherit;"><b>Tips, tricks, references :</b></span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;"><b><span class="Apple-style-span" style="color: blue;">Thought-provoking :</span></b> &nbsp;<a href="http://www.slideshare.net/tackers/moving-from-relational-to-document-store">http://www.slideshare.net/tackers/moving-from-relational-to-document-store</a></span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;"><span class="Apple-style-span" style="color: blue;"><b>Great summary on app-design principles </b></span></span><span class="Apple-style-span" style="font-family: inherit;">:</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><a href="http://speakerdeck.com/u/kbanker/p/the-mongodb-gamut-four-app-designs">http://speakerdeck.com/u/kbanker/p/the-mongodb-gamut-four-app-designs</a></span><br /> <br /> <br /> <span class="Apple-style-span" style="font-family: inherit;"><span class="Apple-style-span" style="font-weight: bold; line-height: 12px;"><a href="http://my.safaribooksonline.com/book/databases/9781449306779" style="outline-color: initial; outline-style: none; outline-width: initial; text-decoration: none;" title="50 Tips and Tricks for MongoDB Developers"><span class="Apple-style-span" style="color: blue;">50 Tips and Tricks for MongoDB Developers</span></a></span><span class="Apple-style-span" style="font-weight: bold; line-height: 12px;"><span class="Apple-style-span" style="color: blue;">&nbsp;:</span></span></span><span class="Apple-style-span" style="font-family: inherit;"><span class="Apple-style-span" style="font-weight: bold; line-height: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><a href="http://my.safaribooksonline.com/book/databases/9781449306779/firstchapter">http://my.safaribooksonline.com/book/databases/9781449306779/firstchapter</a></span><br /> <br /> <br /> <span class="Apple-style-span" style="color: blue; font-family: inherit;"><b>Schema Design Basics :&nbsp;</b></span><span class="Apple-style-span" style="font-family: tahoma, times, serif; font-size: 13px;"><a href="http://speakerdeck.com/u/kbanker/p/mongodb-schema-design-mongosf-2011" rel="nofollow" target="_blank">http://speakerdeck.com/u/kbanker/p/mongodb-schema-design-mongosf-2011</a></span><br /> <span class="Apple-style-span" style="font-family: inherit;"><a href="http://www.slideshare.net/mongodb/mongodb-schema-design-richard-kreuters-mongo-berlin-preso">http://www.slideshare.net/mongodb/mongodb-schema-design-richard-kreuters-mongo-berlin-preso</a></span><br /> <br /> <b><span class="Apple-style-span" style="color: blue;">New Aggregation Features </span></b>:&nbsp;<a href="http://www.slideshare.net/cwestin63/mongodb-aggregation-mongosf-may-2011">http://www.slideshare.net/cwestin63/mongodb-aggregation-mongosf-may-2011</a><br /> <br /> <div class="MsoNormal" style="mso-layout-grid-align: none; mso-pagination: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: inherit;"><span class="Apple-style-span" style="color: blue;"><b>Performance Considerations :</b></span>&nbsp;</span><span class="Apple-style-span" style="font-family: tahoma, times, serif; font-size: 13px;"><a href="http://speakerdeck.com/u/kbanker/p/10-key-mongodb-performance-indicators" rel="nofollow" target="_blank">http://speakerdeck.com/u/kbanker/p/10-key-mongodb-performance-indicators</a></span></div><span class="Apple-style-span" style="color: blue;"><a href="http://blog.zawodny.com/2011/03/06/mongodb-pre-splitting-for-faster-data-loading-and-importing/">http://blog.zawodny.com/2011/03/06/mongodb-pre-splitting-for-faster-data-loading-and-importing/</a></span><br /> <span class="Apple-style-span" style="font-family: inherit;"></span><br /> <div class="MsoNormal" style="mso-layout-grid-align: none; mso-pagination: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: inherit;"><span lang="EN"><br /> </span></span></div><span class="Apple-style-span" style="font-family: inherit;"><span class="Apple-style-span" style="color: blue;"><b>Great Teachings from MongDB Mentor :</b></span>&nbsp;</span><a href="http://www.scribd.com/alvin_richards"><span style="color: blue;">http://www.scribd.com/alvin_richards</span></a><span class="Apple-style-span" style="font-family: inherit;"></span><br /> <div class="MsoNormal" style="mso-layout-grid-align: none; mso-pagination: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: inherit;"><span lang="EN"><br /> </span></span></div><br /> <span class="Apple-style-span" style="font-family: inherit;"><span class="Apple-style-span" style="color: blue;"><b>MongoSF Streaming :</b></span>&nbsp;</span><a href="http://www.justin.tv/mongodb/b/286578814">http://www.justin.tv/mongodb/b/286578814</a><br /> <b><span class="Apple-style-span" style="color: blue;">Webinars :</span></b>&nbsp;<a href="http://www.10gen.com/webinars"><span class="Apple-style-span" style="font-family: inherit;">http://www.10gen.com/webinars</span></a><br /> <span class="Apple-style-span" style="color: blue;"><b>Original Docs :</b></span>&nbsp;<a href="http://www.mongodb.org/display/DOCS/Home">http://www.mongodb.org/display/DOCS/Home</a><br /> <span class="Apple-style-span" style="color: blue;"><b>The little mongo book and Interactive Tutorial :</b></span> &nbsp;<a href="http://mongly.com/">http://mongly.com/</a><br /> <b><span class="Apple-style-span" style="color: blue;">Tools to play with MongoDB :</span></b> &nbsp;<a href="http://mongolab.com/">mongolab.com</a>&nbsp;, &nbsp;<a href="http://mongo.cloudfoundry.com/"><span class="Apple-style-span" style="font-family: inherit;">http://mongo.cloudfoundry.com/</span></a><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <b>CaseStudy :</b> &nbsp;<span class="Apple-style-span" style="color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px;"><span class="h-username" style="border-bottom-width: 0px; border-color: initial; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-style: initial; border-top-width: 0px; color: #0077aa; font-family: inherit; font-size: 12px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none; vertical-align: top;"><a class="userimage-link j-tooltip-bottom" href="http://www.slideshare.net/ggoodale" original-title="ggoodale | Happy-go-lucky hacker. Scale junkie. Chief Janitor at Massively Fun. The internet is full of very cool toys." style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #0077aa; font-family: inherit; font-size: 12px; font-style: inherit; font-weight: 700; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none; vertical-align: baseline;">Grant Goodale</a>&nbsp;has the best collection of MongoDB Slides&nbsp;</span></span><br /> <a href="http://www.slideshare.net/ggoodale/geospatial-indexing-and-querying-with-mongodb">http://www.slideshare.net/ggoodale/geospatial-indexing-and-querying-with-mongodb</a><br /> <br /> </div>http://musings-on-technology.blogspot.com/2011/05/challenge-conventional-wisdom-mongosf.htmlnoreply@blogger.com (Kaniska)0tag:blogger.com,1999:blog-1373851816248476399.post-996805662522116130Thu, 26 May 2011 14:39:00 +00002011-09-09T04:32:26.132+05:30CloudFoundry - Simplicity Matters<div dir="ltr" style="text-align: left;" trbidi="on"><span class="Apple-style-span" style="font-family: inherit;">'Simplicity Matters' - is the mantra of <span class="Apple-style-span" style="color: blue;">SpringSource</span>.</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;">Its just amazing to witness how fast SpringSource <span class="Apple-style-span" style="color: blue;">simplifying the access to huge number of heterogeneous service providers</span> based on the ideas of AOP and DI.</span><br /> <span class="Apple-style-span" style="color: #333333;"><span class="Apple-style-span" style="font-size: 15px; line-height: 23px;"><i><br /> </i></span></span><br /> <span class="Apple-style-span" style="font-family: inherit;"><span class="Apple-style-span" style="color: blue;">Spring Roo</span> revolutionized the concept of 'Rapid Application Development' by on-demand resource allocation and service provisioning through load-time-weaving of aspects !</span><br /> <span class="Apple-style-span" style="font-family: inherit;">Couple of lines of commands and the complete gwt-spring-mvc application launched into Google App Engine !</span><br /> <span class="Apple-style-span" style="font-family: inherit;">At the same time, <span class="Apple-style-span" style="color: blue;">MongoDB</span> came up with a 'ridiculously simple' json-based api to provide super-fast asynchronous highly-scalable, available, partitioned data-storage with simple ways to crud, map-reduce, search, index ! It challenged the 'conventional wisdom' of building 'ultra-pathetic', 'super-complex' enterprise OLTP and BI solutions ! <span class="Apple-style-span" style="color: blue;">Redis </span>garnered much excitement by providing a brilliant 'data-structure key-value storage' !</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;">Its no wonder that <span class="Apple-style-span" style="color: blue;">Spring quickly provided a wrapper to access MongoDB, Redis, Riak, Node.js.&nbsp;</span></span><br /> <br /> <div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="color: #333333; font-family: inherit; font-size: 15px; line-height: 23px;"><i>'Spring Data promotes the&nbsp;<span style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">classic</span>&nbsp;Spring values, enhancing developer productivity by removing the API noise, boiler-plate code and resource management and offering a consistent programming model.'</i></span></div><div>Birds of same feather flock together :-)</div><span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;"><span class="Apple-style-span" style="color: blue;"><b>Soon.. SpringSource reached the point of culmination by offering ... CloudFoundry !</b></span>&nbsp;</span><br /> <span class="Apple-style-span" style="font-family: inherit;">Its motto<span class="Apple-style-span" style="color: purple;"> 'Every Programmer is a Hero'</span> !</span><br /> <span class="Apple-style-span" style="font-family: inherit;">Just by hiding gory details of IaaS, PaaS (which hitherto seemed like sole properties of large enterprise companies) ...</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <br /> <div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="font-family: inherit;">It provides the<span class="Apple-style-span" style="color: blue;"> much-awaited magic-touch to launch an user application directly onto cloud, making it always available, fail-safe, scalable, manageable</span> !&nbsp;</span></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="font-family: inherit;">User can simply specify/change/manage what sorts of service it requires (mongodb, redis, grails, node.js etc..) and specify the target (amazon cloud, vmware, cloud foundry , azure, etc..) .. all dynamically !</span></div><br /> <br /> Well ! the only change you need to make is -(1) inside spring-beans xml, specify a <cloud profile...=""> with the name of dataSource that (2) you need to add as a service to your deployed app - on the fly (through STS / CLI) ! Thats it ! WoW !</cloud><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="color: blue;">When Spring Integration is supported in Cloud Foundry</span>, its going to join another long-time friend of developers - Mule ... which has already provided industry's first iPaas (Integration Platform as Service) !<br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;">Enough theory ! Its time to get our hands dirty !</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <b>Build Cloud-ready App using Ruby :</b><br /> <span class="Apple-style-span" style="font-family: inherit;">The CLI Tool - VMC (vmware cloud-controller) can be installed by ruby gem.</span><br /> VMC simply make various rest requests (push / update / target / start / stop ..). Accordingly cloud-controller delegates the requests to droplet execution engine which routes the requests to service providers (allocated by cloud-controllers).<br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;">Here goes the simple steps to push a ruby 'Say hello' app to Cloud !</span><br /> <a href="http://seroter.wordpress.com/2011/05/11/6-quick-steps-for-windows-net-folks-to-try-out-cloud-foundry/"><span class="Apple-style-span" style="font-family: inherit;">http://seroter.wordpress.com/2011/05/11/6-quick-steps-for-windows-net-folks-to-try-out-cloud-foundry/</span></a><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="font-family: inherit;">require 'sinatra'&nbsp;</span></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="font-family: inherit;">get '/' do &nbsp;</span></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="font-family: inherit;">&nbsp; &nbsp; "Welcome ! &nbsp;You are now in Cloud Foundry! "</span></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="font-family: inherit;">end</span></div><span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <b>Launch a Spring-MySql App into Cloud :</b><br /> <br /> <div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="color: blue; font-family: inherit;">Nothing gets more exciting to be able to deploy our very own sample app on cloud !</span></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="font-family: inherit;">Starting point IDE :&nbsp;<a href="http://blog.springsource.com/2011/04/13/using-cloud-foundry-from-sts/">http://blog.springsource.com/2011/04/13/using-cloud-foundry-from-sts/</a></span></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">CLI :&nbsp;<span class="Apple-style-span" style="font-family: tahoma, times, serif; font-size: 13px;"><a href="http://support.cloudfoundry.com/entries/20012337-getting-started-guide-command-line-vmc-users" rel="nofollow" target="_blank">http://support.cloudfoundry.com/entries/20012337-getting-started-guide-command-line-vmc-users</a></span></div><br /> <span class="Apple-style-span" style="font-family: inherit;">1. This sample code 'To-Do List Manager' just works and need no tweaking !</span><br /> <a href="https://github.com/daveys/spring-todo"><span class="Apple-style-span" style="font-family: inherit;">https://github.com/daveys/spring-todo</span></a><br /> <span class="Apple-style-span" style="font-family: inherit;">** Login Credentials specified in security-context.xml</span><br /> <span class="Apple-style-span" style="font-family: inherit;">2. Just need to remember that we should create a 'tododb' service and link it to the application !</span><br /> <span class="Apple-style-span" style="font-family: inherit;">Upon starting the app if it does not work on first chance, we just need to restart it once or twice !</span><br /> <span class="Apple-style-span" style="font-family: inherit;">3. Inspect logs</span><br /> <span class="Apple-style-span" style="color: #333333; font-family: inherit; font-size: 12px; line-height: 17px;"># look at the main logs that contain crash information<br style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" />vmc crashlogs my-app<br style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" /># to inspect other logs (migration.log, staging.log, etc.)<br style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" />vmc files my-app logs/migration.log</span><br /> <span class="Apple-style-span" style="font-family: inherit;">4.Check-out&nbsp;<a href="http://blog.springsource.com/2011/04/12/cloud-foundry-for-spring-developers/">http://blog.springsource.com/2011/04/12/cloud-foundry-for-spring-developers/</a></span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;"><b>Launch a Spring-MongoDB App on the Cloud :</b></span><br /> <span class="Apple-style-span" style="font-family: inherit;">1.</span>&nbsp;Download <b>hello-spring-mongodb</b> from cloudfoundry samples.<br /> <span class="Apple-style-span" style="font-family: inherit;">2. Import the project in <b>STS</b>.</span><br /> <span class="Apple-style-span" style="font-family: inherit;">3. Rename the application to some unique name like <user-name>-<b>mongoapp</b></user-name></span><br /> <span class="Apple-style-span" style="font-family: inherit;">4. Remember to add the mongodb namespace - in <b>root-context.xml</b></span><br /> <span class="Apple-style-span" style="font-family: inherit;">xmlns:mongo="http://www.springframework.org/schema/data/mongo" and specify the schema location</span><br /> <span class="Apple-style-span" style="font-family: inherit;">http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;">5. Now few Command Line tasks..</span><br /> <span class="Apple-style-span" style="font-family: inherit;">6.&nbsp;</span>Package the app : <b>mvn package</b><br /> <span class="Apple-style-span" style="font-family: inherit;">7.&nbsp;</span>Test that vmc target is<b> api.cloudfoundry.com</b><br /> <span class="Apple-style-span" style="font-family: inherit;">8.&nbsp;</span>Next attach a mongoDB service and start the service as shown below...<br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisDAvF8RIdTjX_ysGOyPJmDgXAcvg24Jw2rtYpzvKS-X0LPa-vSwUaXu8CDxl0dr-j4H6QqT-Sfb3AauxVePi1EoPrW6Pgqf3qYTRZQHTlp_B_ivmlOyaKSkhS4QzSuZYr5m4yaXX9fjY/s1600/MongoDBAppDeploy.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span class="Apple-style-span" style="font-family: inherit;"><img border="0" height="427" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisDAvF8RIdTjX_ysGOyPJmDgXAcvg24Jw2rtYpzvKS-X0LPa-vSwUaXu8CDxl0dr-j4H6QqT-Sfb3AauxVePi1EoPrW6Pgqf3qYTRZQHTlp_B_ivmlOyaKSkhS4QzSuZYr5m4yaXX9fjY/s640/MongoDBAppDeploy.JPG" width="640" /></span></a></div><span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;">9. The service name should match with the one specified in '<b>mongoTemplate</b>' e.g. '<b>mongodb-hello-mongo</b>'</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;">10. Finally we should expect the output as specified in -&nbsp;<a href="https://github.com/SpringSource/cloudfoundry-samples/wiki/Spring-Hello-MongoDB-Sample-Application">https://github.com/SpringSource/cloudfoundry-samples/wiki/Spring-Hello-MongoDB-Sample-Application</a></span><br /> <span class="Apple-style-span" style="font-family: inherit;">----------------------------------------------------------------------------</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><b>A ready-to-go powerful web-flow sample :</b></span><br /> <span class="Apple-style-span" style="font-family: inherit;">See Live :&nbsp;</span><a href="http://travel.cloudfoundry.com/">http://travel.cloudfoundry.com</a><br /> ----------------------------------------------------------------------------<br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="color: blue; font-family: inherit;">We can easily tweak any of the above apps in STS to make it a real-life robust app and take full advantage of free cloud !</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;">For more<span class="Apple-style-span" style="color: blue;"><b> complicated examples involving Social Search, Events and Caching -</b></span> we can consult the following articles : &nbsp;this is a SUPER SHOT ... &nbsp;&nbsp;<a href="http://blog.springsource.com/2011/05/03/using-mongodb-redis-node-js-and-spring-mvc-in-a-single-cloud-foundry-application/">http://blog.springsource.com/2011/05/03/using-mongodb-redis-node-js-and-spring-mvc-in-a-single-cloud-foundry-application/</a>&nbsp; .....</span><br /> <span class="Apple-style-span" style="font-family: inherit;">and another ACTION-PACKED sample ...&nbsp;<a href="http://blog.springsource.com/2011/04/27/getting-started-redis-spring-cloud-foundry/">http://blog.springsource.com/2011/04/27/getting-started-redis-spring-cloud-foundry/</a></span><br /> <br /> <b>A very complex streaming-events sample </b>where external source sends events to redis store. Events are sent to browser using ajax-long-polling (instant update) and also pushed into Mongo for future lookup and &nbsp;analysis (BI) . Cloudfoundry makes it look so simple and easy to learn the concepts !<br /> <br /> Here I show the steps ... &nbsp;(assumption : ticker-analysis mongo service and ticker-stream redis service are already created) :<br /> <br /> <div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg40k8r0RWQsbmCx4Jtz28ZCJ2JtlBMjDNg5CrU9x82rfJXtWn-uOrpl275e7RU9tudUEG1FDlxkGHobyrjp-qREbDiy5pF9vCyzM0SKgLuKdoJchzvpOGvq4IsoTTdTQ9cIPefrZIM7Ww/s1600/streaming_events_flow.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="366" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg40k8r0RWQsbmCx4Jtz28ZCJ2JtlBMjDNg5CrU9x82rfJXtWn-uOrpl275e7RU9tudUEG1FDlxkGHobyrjp-qREbDiy5pF9vCyzM0SKgLuKdoJchzvpOGvq4IsoTTdTQ9cIPefrZIM7Ww/s640/streaming_events_flow.JPG" width="640" /></a></div><br /> See it live :&nbsp;<a href="http://streaming-events.cloudfoundry.com/">http://streaming-events.cloudfoundry.com</a><br /> More food for thoughts :&nbsp;<a href="http://blog.mongodb.org/post/6587009156/cloudfoundry-mongodb-and-nodejs">http://blog.mongodb.org/post/6587009156/cloudfoundry-mongodb-and-nodejs</a><br /> <br /> <span class="Apple-style-span" style="color: blue;"><span class="Apple-style-span" style="font-family: inherit;"><b>References :</b></span><span class="Apple-style-span" style="font-family: inherit;">&nbsp;&nbsp;</span></span><br /> <span class="Apple-style-span" style="font-family: inherit;">Comprehensive List : &nbsp;<a href="http://devstonez.wordpress.com/2011/04/13/all-you-need-to-know-about-cloud-foundry-blogs-articles-reviews-tutorials-videos/">http://devstonez.wordpress.com/2011/04/13/all-you-need-to-know-about-cloud-foundry-blogs-articles-reviews-tutorials-videos/</a></span><br /> Command Line Reference :&nbsp;<a href="https://github.com/cloudfoundry/vmc/blame/master/README.md">https://github.com/cloudfoundry/vmc/blame/master/README.md</a><br /> <br /> <b>Architecture :&nbsp;</b><br /> <a href="http://www.slideshare.net/mccrory-me/cloud-foundry-a-developers-perspective">http://www.slideshare.net/mccrory-me/cloud-foundry-a-developers-perspective</a>&nbsp;<a href="http://www.slideshare.net/lethee/cloud-foundry-practice">http://www.slideshare.net/lethee/cloud-foundry-practice</a><br /> <br /> <b>Ruby on CloudFoundry :&nbsp;</b><br /> <a href="http://support.cloudfoundry.com/entries/20019747-ruby-and-cloudfoundry-things-to-know">http://support.cloudfoundry.com/entries/20019747-ruby-and-cloudfoundry-things-to-know</a><br /> <a href="http://www.slideshare.net/oisin/constructing-web-apis-with-rack-sinatra-and-mongodb">http://www.slideshare.net/oisin/constructing-web-apis-with-rack-sinatra-and-mongodb</a><br /> <br /> <a href="http://docs.aptana.com/docs/index.php/Plugging_Aptana_into_an_existing_Eclipse_configuration">http://docs.aptana.com/docs/index.php/Plugging_Aptana_into_an_existing_Eclipse_configuration</a><br /> <a href="http://update1.aptana.org/rails/1.2.1.23268/index.html">http://update1.aptana.org/rails/1.2.1.23268/index.html</a><br /> <a href="http://www.ibm.com/developerworks/opensource/library/os-rubyeclipse/">http://www.ibm.com/developerworks/opensource/library/os-rubyeclipse/</a><br /> <br /> <b>MongoDB on CLoudFoundry :</b><br /> <br /> <a href="https://github.com/SpringSource/cloudfoundry-samples/wiki/Spring-MongoDB">https://github.com/SpringSource/cloudfoundry-samples/wiki/Spring-MongoDB</a><br /> <a href="http://mongo.cloudfoundry.com/">http://mongo.cloudfoundry.com/</a><br /> <a href="https://github.com/SpringSource/cloudfoundry-samples/wiki/Spring-Hello-MongoDB-Sample-Application">https://github.com/SpringSource/cloudfoundry-samples/wiki/Spring-Hello-MongoDB-Sample-Application</a><br /> <a href="http://www.slideshare.net/lethee/mongo-db-with-spring-data-document">http://www.slideshare.net/lethee/mongo-db-with-spring-data-document</a><br /> <br /> <b>Redis on CloudFoundry in Ubuntu :</b><br /> <a href="http://blog.aestasit.com/taking-vmware-cloud-foundry-on-a-test-drive/">http://blog.aestasit.com/taking-vmware-cloud-foundry-on-a-test-drive/</a><br /> <a href="http://redis.io/topics/twitter-clone">http://redis.io/topics/twitter-clone</a><br /> <a href="http://static.springsource.org/spring-data/data-keyvalue/examples/retwisj/current/#retwisj:design:persistence">http://static.springsource.org/spring-data/data-keyvalue/examples/retwisj/current/#retwisj:design:persistence</a><br /> <br /> <br /> <br /> <br /> <br /> </div>http://musings-on-technology.blogspot.com/2011/05/cloudfoundry-simplicity-matters.htmlnoreply@blogger.com (Kaniska)0tag:blogger.com,1999:blog-1373851816248476399.post-7896261480984620126Mon, 02 May 2011 06:38:00 +00002011-05-03T10:29:15.864+05:30Cloud and Big Data Meetup<div dir="ltr" style="text-align: left;" trbidi="on">May 1st, 2011 Micorsoft Campus, Cloud Computing Camp !<br /> A very Rewarding Experience indeed !<br /> <br /> My personal interest was to understand how Cloud Computing, Hadoop, NoSql helping Developers to solve problems from purely a Programmer's Viewpoint.<br /> <br /> <span class="Apple-style-span" style="font-size: large;">Food for thoughts</span><br /> <br /> End of the day, it answered some of the most important questions<br /> - <span class="Apple-style-span" style="color: purple;">how to choose a cloud service provider ?</span><br /> <span class="Apple-style-span" style="color: purple;">- how to leverage PaaS and IaaS and whats the thin line between them?</span> <br /> <span class="Apple-style-span" style="color: purple;">- why companies like Netflix very selectively has chosen Amazon Cloud &nbsp;and how they are creating platform on AWS like Cassandra as a Service ?</span><br /> - <span class="Apple-style-span" style="color: purple;">How to adopt Open Sourced CloudFoundry and Microsoft Azure PaaS ?</span><br /> - <span class="Apple-style-span" style="color: purple;">What OpenStack can offer to individual developer / start-ups to enjoy the fruits of IaaS at little cost ?&nbsp;</span><br /> <br /> And of course there were very thoughtful reflections on how to choose what type of&nbsp;<span class="Apple-style-span" style="background-color: white;"><span class="Apple-style-span" style="color: blue;">CAP model</span></span>, deep-diving into <span class="Apple-style-span" style="color: blue;">MongDB internals</span> and talk on a wonderful array of tools to make op's and dev's life smooth while <span class="Apple-style-span" style="color: blue;">building a</span> <span class="Apple-style-span" style="color: blue;">scalable system</span> !!<br /> <br /> <span class="Apple-style-span" style="font-size: large;">Brush the basics and sky-rocket into Clouds</span><br /> <br /> It all started with a great Keynote Speech from Cisco CTO -<br /> A quick reminder of basic properties of a Cloud Provider -<br /> <span class="Apple-style-span" style="color: blue;">Shared Resource, Scalability, Self-Service, Multiple Data-Centers, Measurable Resources, Design-for-failure, Auto-Recovery and Centralized monitoring.</span><br /> <br /> These are well-known facts. But the most interesting point to note was <span class="Apple-style-span" style="color: purple;">evolution of <b>OpenStack</b></span>.<br /> - <span class="Apple-style-span" style="color: blue;">Open eliminates Vendor Lock-in. Freedom to federate and move between clouds.</span><br /> <br /> The intricate details of Network Virtualization, Hypervisor integration didn't attract me much ! Rather was interested in tools around Open Source Clouding.<br /> <a href="http://www.slideshare.net/socializedsoftware/crash-course-in-open-source-cloud-computin">http://www.slideshare.net/socializedsoftware/crash-course-in-open-source-cloud-computin</a>g<br /> <br /> <span class="Apple-style-span" style="color: purple;">Convergence of Network, Compute and Storage is going to be the driving point</span> for handling information explosion and incredible video transmission in coming years.<br /> <a href="http://www.slideshare.net/lewtucker/openstack-time-is-now-lew-tucker">http://www.slideshare.net/lewtucker/openstack-time-is-now-lew-tucker</a><br /> <br /> <span class="Apple-style-span" style="font-size: large;">Case Study - Simplify life</span><br /> <br /> Netflix being one of the largest Amazon Cloud Consumers, shared its pain points and need for migrating to the Cloud.<br /> <span class="Apple-style-span" style="color: purple;">- How Cloud helps us get rid of the 'indefinite wait-cycle' problem in traditional data-center.</span><br /> <span class="Apple-style-span" style="color: purple;">- Keep waiting for 'Permission Grant', 'More Space Allocation' , 'Re-organize Capacity','Endless meetings with IT' etc. ...&nbsp;</span><br /> <br /> No more waiting ! By 2012 probably Cloud Model will be seamlessly part of every single software maker !!<br /> In case of Netflix -<span class="Apple-style-span" style="color: blue;"> Amazon API is the IT Dept !!</span><br /> The best part is the development to deployment flow -<span class="Apple-style-span" style="color: purple;"> Build, War, Rpm, bakes AMI, launch in cloud! Huh !</span><br /> <span class="Apple-style-span" style="color: purple;">How did Cloud simplify life ?</span><br /> <span class="Apple-style-span" style="color: blue;">Quoting&nbsp;Adrian .... &nbsp; (Cloud Architecture)</span><br /> <blockquote>" Central SQL -&gt; Distributed Key/Value NoSQL<br /> &nbsp;&nbsp;Sticky In-Memory Session &gt; Shared Memcached Session (for Others cold cache like&nbsp;MySQL Native Memory / Terracotta Big-Table)</blockquote><blockquote>&nbsp;Chatty Protocol &gt; Latency Tolerant Protocol<br /> &nbsp;&nbsp;Tangled Service Interface &gt; Layered Service Interface<br /> &nbsp;&nbsp;Components as Jars &gt; Components as Service<br /> &nbsp;&nbsp;Fat Complex objects &gt; Lightweight Serializable Objects .."</blockquote>Here goes the great story - <a href="http://www.slideshare.net/adrianco/migrating-to-public-cloud">http://www.slideshare.net/adrianco/migrating-to-public-cloud</a><br /> <br /> On a different context, another interesting article from Adrian Cockcroft on<span class="Apple-style-span" style="color: purple;"> 'creating NoSql service over Amazon Cloud'</span> - <span class="Apple-style-span" style="color: blue;">http://prezi.com/veagqhsz38u8/nosql-maslows-hierarchy-of-reads-and-writes/</span><br /> <br /> <span class="Apple-style-span" style="font-size: large;">PaaS - the Jewel Box</span><br /> <br /> It was really exciting to know that <span class="Apple-style-span" style="color: purple;">Windows Azure is actually an OS on Web which allows user to run any windows-compatible application like accessing database blobs, NoSql data storage, VPN, CDN, Service Bus, Access Control, Monitoring.</span><br /> <br /> Anyone interested to try out Azure, can just <span class="Apple-style-span" style="color: purple;">login at http://windowsazurepass.com/</span> with passcode '<span class="Apple-style-span" style="color: purple;">meetup</span>'<br /> <br /> Well ! Finally the much-awaited .. <b>CloudFoundry </b>! <br /> <span class="Apple-style-span" style="color: purple;">VMWare-SpringSource means so much for the Java Community after the demise of Sun !!!</span><br /> Now you get Grovvy-on-grals, Redis, Node.js and plenty of other services out-of-the CloudFoundry PaaS !<br /> Tthe open source advocate Ezra gave a lightning talk about the <span class="Apple-style-span" style="color: blue;">internals of CloudFoundry</span> :<br /> <blockquote>"First user develops application foo.<br /> vmc push foo -&gt; talks to Cloud Controller through Rest<br /> Cloud Controller takes a snapshot of the 'foo' app structure.<br /> Converts this application to a Droplet runnable in queue.<br /> Droplet Execution Agent node can sit on Amazon / RackSpace completely abstracted from User.<br /> Staging process finds what runtime to launch and load all infrastructure for example it will introspect a war file &nbsp;and find the require jdbc driver and load it and so on.<br /> Staging process send messages to all DEA nodes to find who is least-loaded and can execute the request.<br /> All components are connected through ESB.<br /> Also there is a HealthManager Tool that polls Status Table and matches with Real World State and broadcasts messages ! &nbsp;..." &nbsp; <span class="Apple-style-span" style="color: blue;">.. &nbsp;Thats &nbsp;a Long Story cut Short !</span></blockquote><blockquote>Here goes the full story - <a href="http://blog.cloudfoundry.com/post/4754582920/cloud-foundry-open-paas-deep-dive">http://blog.cloudfoundry.com/post/4754582920/cloud-foundry-open-paas-deep-dive</a></blockquote>Well if you are lucky to get your CloudFoundry Passcode , you can start playing with it through great STS IDE !<br /> <br /> <span class="Apple-style-span" style="font-size: large;">Build your Dinosaur to crunch Big Data</span><br /> <br /> Okay ! Now that we were surfing long on clouds .. its time to understand<span class="Apple-style-span" style="color: blue;"> best practices of handling Big Data </span>(that eventually may fly on cloud) !<br /> <br /> Paco Nathan of IMVU fame delivered a very valuable lecture !<br /> <a href="http://www.slideshare.net/pacoid/hidden-gems-found-with-hadoop">http://www.slideshare.net/pacoid/hidden-gems-found-with-hadoop</a><br /> <br /> The Take Away message :<br /> - <span class="Apple-style-span" style="color: purple;">Select Data Frameworks based on your Data Access Patterns :</span><br /> <span class="Apple-style-span" style="color: purple;">- Relational Data is not good for Queues, Polling Operations, Social graph, Data Analysis and so on !</span><br /> Just can't resist to highlight the following &nbsp;from the slides !<br /> <span class="Apple-style-span" style="color: blue;">How to apply CAP in various scenarios ?</span><br /> <blockquote>" Financial Transactions - General Ledgerin RDBMS - &nbsp;CAx<br /> ad-hoc queries - hosted MySQL - CAx<br /> log - rotation - Riak - xxP<br /> Search Index - Lucene, Solr &nbsp;- xAP<br /> Static Content Archive - S3 - xAP<br /> Customer facts - Redis , Membase &nbsp;- xAP<br /> Distributed counters, sets - Redis - xAP<br /> CRUD - key/value &nbsp; - CxP<br /> Data preparation - Hadoop/ Hive - CxP<br /> Graph Analysis - Hadoop + Redis + Graph - CxP<br /> Data Mart - Hadoop / Hive / Hbase &nbsp;- CxP.."</blockquote>In the same line of identifying correct methodology for data analysis based on data access pattern, <span class="Apple-style-span" style="color: blue;">Apple threw some light about its in-house analytics flow :</span><br /> <blockquote>"Sensors connect to Cassandra over rest to push data (the Click / Navigation / other User Events).<br /> Aggregators read data from Cassandra Key-Value store then aggregate the data through offline batch and replace the data for the keys (compaction) inside K-V Store..."</blockquote><span class="Apple-style-span" style="font-size: large;">Instrument, Measure , Manage Chaos ! Celebrate !</span><br /> <br /> After the thought-provoking sessions,<span class="Apple-style-span" style="color: purple;"> it was time to ride though the Twitter Roller Coaste</span>r !<br /> The Mantra<br /> - <span class="Apple-style-span" style="color: blue;">'We can be Successful only if We can measure'</span><br /> <span class="Apple-style-span" style="color: blue;">- Adopt this early and correctly as per your enterprise system architecture !</span><br /> - <span class="Apple-style-span" style="color: blue;">Remember to minimize - MTTD (Mean time to Detect) and , MTTR (Mean time to Recover) !</span><br /> - &nbsp;<span class="Apple-style-span" style="color: blue;">Instrument Everything ! Cache all decoupled data layers !&nbsp;</span><br /> -&nbsp;Use the correct tools<br /> &nbsp;- for Ruby on Rails &nbsp;use <span class="Apple-style-span" style="color: purple;">Passenger </span>(apache load-balancer fix) , <span class="Apple-style-span" style="color: purple;">Unicorn </span>(Server) in place of Mongrel, use &nbsp; <br /> <span class="Apple-style-span" style="color: purple;">&nbsp;&nbsp; &nbsp;Google Perf Tool</span>.<br /> &nbsp;&nbsp;- In general use <span class="Apple-style-span" style="color: purple;">Puppet </span>and <span class="Apple-style-span" style="color: purple;">Chef </span>as Configuration Tools.<br /> &nbsp;&nbsp;- Explore these tools and use as per need .. <span class="Apple-style-span" style="color: blue;">Whales</span>, <span class="Apple-style-span" style="color: blue;">RainBird</span>, <span class="Apple-style-span" style="color: blue;">Ivy</span>, <span class="Apple-style-span" style="color: blue;">Artifactory</span>, <span class="Apple-style-span" style="color: blue;">AppDynamics</span>, <span class="Apple-style-span" style="color: blue;">EpicNMS</span>..<br /> <a href="http://www.slideshare.net/mattray/scale-2011-deploying-openstack-with-chef">http://www.slideshare.net/mattray/scale-2011-deploying-openstack-with-chef</a><br /> <br /> Enough of appetizer ... <span class="Apple-style-span" style="color: purple;">the meal is served hot here </span>-&nbsp;<a href="http://www.slideshare.net/netik/john-adams-talk-cloudy">http://www.slideshare.net/netik/john-adams-talk-cloudy</a><br /> <br /> <span class="Apple-style-span" style="font-size: large;">Crash Course - learn MongoDB</span><br /> <br /> Next what could be more enticing than <span class="Apple-style-span" style="color: purple;">plunging into the internals of MongoDB </span>!<br /> Alvin Richards&nbsp;is simply great -- <a href="http://www.scribd.com/doc/50019946/MongoAsia-Scaling">http://www.scribd.com/doc/50019946/MongoAsia-Scaling</a> !<br /> Sharding could be ridiculously simple just by creating a compound key <span class="Apple-style-span" style="color: purple;">{server:1, application:1, time:1}</span> and participating in shard <span class="Apple-style-span" style="color: purple;">- db.runCommand({addshard : &nbsp;"shard1"})</span> ... &nbsp;Huh !<br /> <br /> He reflected on -&nbsp;<span class="Apple-style-span" style="color: purple;">Right-balanced-Indexing, Parallel execution of Queries, &nbsp;Range-based partitions, Automatic Sharding, Consistent Hashing, Replication with asynch master/slave, automatic failover through consensus election and many more !&nbsp;</span><br /> For &nbsp;a <span class="Apple-style-span" style="color: blue;">technical deep-dive into consistency models</span> look into - <a href="http://www.10gen.com/video/mongosv2010/consistency">http://www.10gen.com/video/mongosv2010/consistency</a><br /> For hands on refer to <a href="https://github.com/SpringSource/spring-data-document-exampl">https://github.com/SpringSource/spring-data-document-exampl</a>es and follow <a href="http://www.10gen.com/video/mongosv2010/spring">http://www.10gen.com/video/mongosv2010/spring</a><br /> <br /> <span class="Apple-style-span" style="font-size: large;">Build a successful SaaS Business ! Sweet dreams !</span><br /> <br /> Well ! &nbsp;After the rewarding technical sessions it was just perfect to wrap up the day with some insights into <span class="Apple-style-span" style="color: blue;">building successful SaaS Business !</span><br /> <a href="http://www.slideshare.net/KenRutsky/bridging-to-saas-success-a-basic-blueprint">http://www.slideshare.net/KenRutsky/bridging-to-saas-success-a-basic-blueprint</a><br /> <br /> <span class="Apple-style-span" style="color: #4c1130; font-size: large;">Big thanks to Sebastian and other Event organizers !</span><br /> <br /> References :&nbsp;<a href="http://www.meetup.com/cloudcomputing/events/16701362/">http://www.meetup.com/cloudcomputing/events/16701362/</a><br /> <br /> </div>http://musings-on-technology.blogspot.com/2011/05/cloud-and-big-data-meetup.htmlnoreply@blogger.com (Kaniska)0tag:blogger.com,1999:blog-1373851816248476399.post-5257111336353048075Fri, 22 Apr 2011 22:56:00 +00002011-04-23T04:26:17.553+05:30Build Rapid Fire Cloud Ready Apps<div dir="ltr" style="text-align: left;" trbidi="on"><br /> Build CloudFoundry Apps from STS<br /> <a href="http://blog.springsource.com/2011/04/12/cloud-foundry-for-spring-developers/">http://blog.springsource.com/2011/04/12/cloud-foundry-for-spring-developers/</a><br /> <a href="http://blog.springsource.com/2011/04/13/using-cloud-foundry-from-sts/">http://blog.springsource.com/2011/04/13/using-cloud-foundry-from-sts/</a><br /> <br /> Watch the Webinar and Download the Slides !<br /> <a href="http://www.springsource.com/webinar/getting-started-spring-and-springsource-tool-suite">http://www.springsource.com/webinar/getting-started-spring-and-springsource-tool-suite</a><br /> <br /> Grails-Integration -&nbsp;<a href="http://www.grails.org/STS+Integration">http://www.grails.org/STS+Integration</a><br /> <br /> Spring MVC with STS -&nbsp;<a href="http://www.giantflyingsaucer.com/blog/?p=2373">http://www.giantflyingsaucer.com/blog/?p=2373</a><br /> Great MVC Resource -&nbsp;<a href="http://www1.springsource.com/files/Getting%20Started%20with%20Spring%20and%20STS%203-17-11.pdf">http://www1.springsource.com/files/Getting%20Started%20with%20Spring%20and%20STS%203-17-11.pdf</a><br /> <br /> <br /> Google App Engine with STS -&nbsp;<a href="http://code.google.com/webtoolkit/doc/latest/tutorial/roo-sts.html">http://code.google.com/webtoolkit/doc/latest/tutorial/roo-sts.html</a><br /> <br /> Spring Insight for Monitoring :&nbsp;<a href="http://blog.espenberntsen.net/tag/spring-insight/">http://blog.espenberntsen.net/tag/spring-insight/</a></div>http://musings-on-technology.blogspot.com/2011/04/build-rapid-fire-cloud-ready-apps.htmlnoreply@blogger.com (Kaniska)1tag:blogger.com,1999:blog-1373851816248476399.post-839234393668557647Tue, 19 Apr 2011 20:05:00 +00002011-04-20T10:55:08.806+05:30PaaSAnother Big Win for App Developers - Cloud Foundry the PaaS Pioneer<div dir="ltr" style="text-align: left;" trbidi="on"><span class="Apple-style-span" style="color: blue;">Big Win for App Developers !</span><br /> <br /> VMWare just inaugurated another road to Openness !&nbsp;Welcome to <b>Cloud Foundry</b> !<br /> <br /> The question is how much to Open Up and how Far to allow the user Explore !!<br /> <br /> Rails , Spring, Django, NoSqls, Node.js -- all developers frameworks usherd&nbsp;in new horizons of Programming Model thriving on core values of Portability,&nbsp;Productivity and Simplicity !<br /> <br /> Now VMWare publishing them as Service ..&nbsp;empowering any developer to build a scalable system !<br /> No longer need to wonder about&nbsp;secrets of great marvels of architecture like Facebook, Twitter, Foursquare !<br /> <br /> As per some of the other PaaS offerings are concerned,&nbsp;Salesforce+Heroku powerpack is defintely more geeky than Google' Simplistic&nbsp;App Engine !<br /> <br /> Well MuleSoft recently launched first iPass i.e. Cloud-ready Integration&nbsp;Platform ! Mule has always been the darling of SMBs, a quick enabler of&nbsp;lightweight integration&nbsp;infrastructure.<br /> Now VMWare's out-of-the box offering of RabbitMQ definitely adds to the&nbsp;delight of Programmers by offering more arsennels to create rapid-fire&nbsp;solutions !!!<br /> <br /> Enough talk . lets see it happening !<br /> <a href="http://www.youtube.com/user/vmwaretv?feature=mhum#p/c/71331D676E1D17CA/3/5nYAlZ1YFTg">http://www.youtube.com/user/vmwaretv?feature=mhum#p/c/71331D676E1D17CA/3/5nYAlZ1YFTg</a><br /> Just import &nbsp;Spring Travel App into STS, start a VMWare Server and deploy to Cloud Foundry.<br /> Zero configuration... Huh !<br /> <br /> Right now CloudFoundry is the most imporatant thing to happen !<br /> <br /> Get your feet dirty -&nbsp;<a href="http://blog.springsource.com/2011/04/13/using-cloud-foundry-from-sts/">http://blog.springsource.com/2011/04/13/using-cloud-foundry-from-sts/</a><br /> <br /> Starting up MongoDB &nbsp;in Cloud Foundry -&nbsp;<a href="http://blog.mongodb.org/post/4719358003/getting-started-with-vmware-cloudfoundry-mongodb-and">http://blog.mongodb.org/post/4719358003/getting-started-with-vmware-cloudfoundry-mongodb-and</a><br /> <br /> Launching Cloud : &nbsp;<a href="http://blog.springsource.com/2011/04/12/launching-cloud-foundry/">http://blog.springsource.com/2011/04/12/launching-cloud-foundry/</a><br /> <br /> Full Story : <a href="http://gigaom.com/cloud/vmware-open-source-cloud/">http://gigaom.com/cloud/vmware-open-source-cloud/</a><br /> FAQ :&nbsp;<a href="http://support.cloudfoundry.com/forums/373015-knowledge-base">http://support.cloudfoundry.com/forums/373015-knowledge-base</a><br /> <a href="http://www.cloudfoundry.com/">http://www.cloudfoundry.com/</a><br /> <a href="http://www.youtube.com/user/vmwaretv?feature=mhum#p/c/71331D676E1D17CA">http://www.youtube.com/user/vmwaretv?feature=mhum#p/c/71331D676E1D17CA</a></div>http://musings-on-technology.blogspot.com/2011/04/another-big-win-for-app-developers.htmlnoreply@blogger.com (Kaniska)0tag:blogger.com,1999:blog-1373851816248476399.post-3217436291213391721Tue, 19 Apr 2011 06:47:00 +00002011-04-19T12:17:55.420+05:30Big DataMaking sense of Diverse Big DataRecently watched this amazing video - How Space-Time Makes Sense of Big Data <a href="http://gigaom.com/2011/03/23/jeff-jonas-ibm/">http://gigaom.com/2011/03/23/jeff-jonas-ibm/ </a><br /> <br /> Making sense of Big Data ! - <br /> <a href="http://jeffjonas.typepad.com/jeff_jonas/">http://jeffjonas.typepad.com/jeff_jonas/</a><br /> <br /> Colocating Diverse data in same Observational Space.<br /> <br /> <a href="http://jeffjonas.typepad.com/jeff_jonas/2010/11/general-purpose-sensemaking-systems-and-information-colocation.html">http://jeffjonas.typepad.com/jeff_jonas/2010/11/general-purpose-sensemaking-systems-and-information-colocation.html</a><br /> <br /> Now Data will find Data and Relevance will find You !http://musings-on-technology.blogspot.com/2011/04/making-sense-of-diverse-big-data.htmlnoreply@blogger.com (Kaniska)0tag:blogger.com,1999:blog-1373851816248476399.post-4721267848300044182Tue, 19 Apr 2011 06:29:00 +00002011-05-04T23:06:15.952+05:30mongodbScalabilityScalability Stories<div dir="ltr" style="text-align: left;" trbidi="on">'It is not the strongest of species that survives, nor the most intelligent. It is the one that is most adaptable to change' -- This statement is so emphatic in every slide !<br /> <br /> <a href="http://www.slideshare.net/tackers/why-we-chose-mongodb-for-guardiancouk">http://www.slideshare.net/tackers/why-we-chose-mongodb-for-guardiancouk</a><br /> <br /> In a nutshell, the N-tier System swiftly evolved from traditional View-Service-DB architecture to View-Service-Memcached-DB.<br /> <br /> Memcached is a very good candidate for distributed indexing. Extract main id from Web Request and then find related associated index and making fast lookup from mysql storage.<br /> <br /> Hibernate can be effectively tuned to handle large data set specially by leveraging terracotta big data. <br /> <br /> But even if ORM hides complexities, DB has strong influence on domain model.<br /> Still one needs to implement Complex Caching and Optimizations.<br /> Memcached still need lots of writes to DB and Ehcache needs to write-behind the DB.<br /> <br /> Facebook heavily relies upon customized php-thrift-memcached-mysql-cassandra power-packed combo !<br /> <br /> Guardian Architecture highlighted a very simplistic idea ... carrying the JSON from backend to frontend and vice-versa. Json/Rest is the smooth replacement for heavyweight soap/Axis2 in middle-layer. Json such a nice forwardly-extensible structure naturally fitting into to javascript and python. Here comes MongoDB - the Document-oriented Database storing parsed Json documents. The best part is schema can be changed in runtime without any down-time.<br /> <br /> JSON can define different classes as tagged documents, multiple docs part of same collection.<br /> <br /> So where has the DB gone ? Vanished !<br /> <br /> And there is Apache SOLR, Hosted in EC2 [Document Oriented Search Engine, (NO DB .. huh) ..] .. a super fast Read API. <br /> <br /> Its a huge paradigm shift.<br /> <br /> <a href="http://www.slideshare.net/tackers/why-we-chose-mongodb-for-guardiancouk">http://www.slideshare.net/tackers/why-we-chose-mongodb-for-guardiancouk</a><br /> <br /> So far the simplest explanation of CAP theory ..&nbsp;<a href="http://www.slideshare.net/jboner/scalability-availability-stability-patterns">http://www.slideshare.net/jboner/scalability-availability-stability-patterns</a><br /> <br /> This is the best Applicability-Chart of CAP theory - slide 9 of&nbsp;<a href="http://www.slideshare.net/pacoid/hidden-gems-found-with-hadoop">http://www.slideshare.net/pacoid/hidden-gems-found-with-hadoop</a><br /> <br /> Upcoming Event : Register at <a href="http://www.10gen.com/conferences/mongosf2011">http://www.10gen.com/conferences/mongosf2011</a></div>http://musings-on-technology.blogspot.com/2011/04/need-for-more-speed.htmlnoreply@blogger.com (Kaniska)1tag:blogger.com,1999:blog-1373851816248476399.post-4851646848554716835Tue, 19 Apr 2011 04:50:00 +00002011-04-19T10:20:57.487+05:30CacheBuilding High-Speed Cache<div dir="ltr" style="text-align: left;" trbidi="on"><br /> <div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-line-height-alt: 14.25pt; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: maroon; font-size: 24pt;">Recently while developing a caching tool capable of providing access to millions of records in sub-seconds, we analysed some of the existing best practices.<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">&nbsp;<b style="mso-bidi-font-weight: normal;">(1)</b>&nbsp;<b style="mso-bidi-font-weight: normal;">One choice is MySql native memory cache for avoiding GC-pauses</b>.<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">MySQL InnoDB storage engine's dictionary cache provides blazing fast data acceess. On demand, data blocks are read from disk and stored in memory using LRU chains or other advanced mechanisms(like MySQL's Midpoint Insertion Strategy) .<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">When should we use MySQL query cache?<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Here is the summary from -&nbsp;</span><span lang="DE"><a href="http://dev.mysql.com/tech-resources/articles/mysql-query-cache.html"><span style="color: windowtext; font-size: 14pt; text-decoration: none;">http://dev.mysql.com/tech-resources/articles/mysql-query-cache.html</span></a><o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 35.35pt; margin-right: 28.35pt; margin-top: 0in; mso-list: l1 level1 lfo1; mso-pagination: widow-orphan; text-indent: -14.15pt;"><span lang="DE" style="color: black; font-family: OpenSymbol; font-size: 14pt;">•<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Identical queries are issued by the same or multiple clients on a repetitive basis.<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 35.35pt; margin-right: 28.35pt; margin-top: 0in; mso-list: l1 level1 lfo1; mso-pagination: widow-orphan; text-indent: -14.15pt;"><span lang="DE" style="color: black; font-family: OpenSymbol; font-size: 14pt;">•<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">The underlying data being accessed is static or semi-static in nature.<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 35.35pt; margin-right: 28.35pt; margin-top: 0in; mso-list: l1 level1 lfo1; mso-pagination: widow-orphan; text-indent: -14.15pt;"><span lang="DE" style="color: black; font-family: OpenSymbol; font-size: 14pt;">•<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Queries have the potential to be resource-intensive and/or build brief, but complexly computed result sets.<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Data warehouse/business intelligence situations, web-based applications, and traditional OLTP systems all qualify on the surface. The query cache looks for identical queries (spacing, upper/lower case, all come into play), ergo the first point above.<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">For internals of InnoDB Cache, refer to the MySql &nbsp;tutorial.<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">In general, MySQl memory cache provides best performance if&nbsp;the majority of your database queries aresimply SELECT statements.&nbsp;<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b style="mso-bidi-font-weight: normal;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Here the speed gain is definitely due to negligible GC pauses and direct disk access.&nbsp;</span></b><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">This type of caching strategy is popular for eCommerce and bidding platform where data query is more frequent than data updates.<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b style="mso-bidi-font-weight: normal;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">(2) An alternative solution is 'Memcached'</span></b><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">&nbsp;which lives in a different process and manages its own GC (optimized for caching). We know that in order to lookup the value for a key, &nbsp;Memcached cache clents issue multiple&nbsp;parallel&nbsp;requests to memcached servers where keys are sharded across those servers.<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">The value-items resolved by Memcached are usable objects while those returned from&nbsp;the MySQL cache must then be converted into objects.<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">As queries get more complex, Memcached provides more efficient performance.<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">If an application (using mysql cache) is load-balanced over multiple servers, then each web process&nbsp;will maintain a&nbsp;separate&nbsp;duplicate cache unless otherwise customized and optimized specifically. &nbsp;<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">But the advantage of using&nbsp;Memcached is that it creates a single global cache available to all&nbsp;web processes . Individual web&nbsp;processes and threads do not maintain their own caches in this case, but rather use the single global cache. When one web process puts data in the cache, it becomes&nbsp;available for all others to access. It leverages fast Network connections.<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">The detail architecture of Memcahed is out of the scope of this article.<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">The memcached server and clients work together to implement one global cache across as many machines as you have. In fact, it's recommended you run both web nodes (which are typically memory-lite and CPU-hungry)<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">and memcached processes (which are memory-hungry and CPU-lite) on the same machines.<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">For a frequently changing data set , Memcahed is surely better than DB Cache as 'bulk of the data are read from memory&nbsp;rather than disk' . But point to note - it still suffers from GC-pauses however minimal it could be !<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b style="mso-bidi-font-weight: normal;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">(3) Now lets see how 'Ehcache' (leveraging Terracotta BigMemory) has really got the basics right !<o:p></o:p></span></b></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Just by simply adopting a very well known Disk I/O pattern of accessing native memory directly from java, it has simply eliminated the 'GC' factor and proved to be the fastest caching option !<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Now the choice is ours - (a) whether to adopt a caching strategy that requires&nbsp;"build a bigger computer with huge RAMs" (b) or use the faster cache in a machine with smaller RAM.<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">The bottom line is - the cache must be outside GC's control. There is no GC mechanism available as of now (unless we leverage JDK 7 'Garbage First' ) -&nbsp;which provides a relief from 'Stop-of the World' stuation.<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">The trick is to implement a smart&nbsp;serialization&nbsp;technique&nbsp;by storing key, value pairs into&nbsp;Direct Byte Buffer.<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Here are some insights -&nbsp;</span><span lang="DE"><a href="http://www.ibm.com/developerworks/java/library/j-nativememory-linux/"><span style="color: windowtext; font-size: 14pt; text-decoration: none;">http://www.ibm.com/developerworks/java/library/j-nativememory-linux/</span></a><o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Direct ByteBuffers (allocated using the java.nio.ByteBuffer.allocateDirect() method) that are backed by native memory rather than Java heap. Direct ByteBuffers can be passed directly to native OS library functions for performing I/O — making them significantly faster in some scenarios because they can avoid copying data between Java heap and native heap.<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">It's easy to become confused about where direct ByteBuffer data is being stored. The application still uses an object on the Java heap to orchestrate I/O operations, but the buffer that holds the data is held in native memory — the Java heap object only contains a reference to the native heap buffer.<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 0in; margin-right: 28.35pt; margin-top: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">&nbsp;A non-direct ByteBuffer holds its data in a byte[] array on the Java heap.<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">A small prototype using ButeBuffer really yielded high performance.<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Here is a sample code for creating direct-buffer-based cache (of course its just for learning, no where close to actual ehcahe implementation).&nbsp;<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-family: Arial, sans-serif; font-size: 9.5pt;"><a href="http://tusharkhairnar.blogspot.com/2010/09/bigmemory-memory-with-no-garbage.html"><span style="color: black; font-family: 'Times New Roman', serif; font-size: 14pt; text-decoration: none;">http://tusharkhairnar.blogspot.com/2010/09/bigmemory-memory-with-no-garbage.html</span></a><o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">This is how Terracotta Bigmemory got the basics of caching right by implementing ByteBuffer and bypassing GC pauses !&nbsp;<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE"><a href="http://blog.terracottatech.com/2010/09/bigmemory_explained_a_bit.html"><span style="color: windowtext; font-size: 14pt; text-decoration: none;">http://blog.terracottatech.com/2010/09/bigmemory_explained_a_bit.html</span></a><o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 0in; margin-right: 28.35pt; margin-top: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">“ ConcurrentMarkSweep collectors can run for hours w/ no full pauses and then&nbsp; <o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 0in; margin-right: 28.35pt; margin-top: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">&nbsp;&nbsp;&nbsp;&nbsp; suddenly stop the world for 30 minutes trying to catch up to the mess they<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 0in; margin-right: 28.35pt; margin-top: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">&nbsp;&nbsp;&nbsp;&nbsp; have made.<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 0in; margin-right: 28.35pt; margin-top: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .... if (k1, v1) is in cache in Ehcache BigMemory, it has no references to (k2,<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 0in; margin-right: 28.35pt; margin-top: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v2). They cannot refer to each other.<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Which means I don't have to walk the cache looking for cross-references in the data like a GC does. No mark-and-sweep. I merely wait for the dev to call cache.remove( element ) or for the evictor to evict stale data. The evictor and the remove() API are signaling my MemoryManager explicitly just like new() and delete() or malloc() and free(). There is no notion of garbage or collection. Only memory re-use and fragmentation over time.&nbsp; ”<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">If we want to enjoy the fruits of fastest cache we have to perform some simple steps :<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">&nbsp;</span><span lang="DE"><a href="http://ehcache.org/documentation/offheap_store.html"><span style="color: windowtext; text-decoration: none;">http://ehcache.org/documentation/offheap_store.html</span></a><o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">(i) Update the Java classpath to include the new&nbsp;ehcache jar<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">(ii) Modify the App Jvm settings to allocate enough direct byte buffer<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">-XX:MaxDirectMemorySize affect the memory available with this call<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; java.nio.ByteBuffer.allocateDirect(int).<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">(iii) Update the ehcache.xml to set the size of the<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">BigMemory off-heap store.<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;"><ehcache><o:p></o:p></ehcache></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;"><cache <o:p="" maxelementsinmemory="10000" name="mycache"></cache></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">overflowToOffHeap="true" maxMemoryOffHeap="4G"/&gt;<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;"><o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Here in this link -&nbsp;</span><span lang="DE"><a href="http://code.google.com/p/lucene-bytebuffer/"><span style="color: windowtext; font-size: 14pt; text-decoration: none;">http://code.google.com/p/lucene-bytebuffer/</span></a></span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">&nbsp;,&nbsp;we can see how Lucene Buffers bypasses memory intensive slow java&nbsp;garbage collector. &nbsp;The objects whose life-cycle is known beforehand can be effectively cleaned up through simple manual process instead of relying on GC.</span><span lang="DE"><o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">The basic advantages of a direct-buffer-based cache (like BigMemory) is :<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">1. Bigmemory takes away all cache data from gc-managed memory to its own bytebuffer-managed world !<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">2. No need to tune GC<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">3. Low hardware cost and operational simplicity.<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">User can have one 16 GB RAM and and make use of all that memory with only 1 JVM. This saves the user from the huge effort of maintaining multiple JVMs to create a distributed cache. User can still go fot it and utilize every byte of the RAM without waiting for GC pause.... “<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">On a different note, though any one can implement a fast cache (as discussed above) using nio package in jdk 1.6; but if the app involes heavy file handling (index files or web resources or jars) then for faster experience we should use jdk 1.7 nio2.<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Here are reasons : (</span><span lang="DE"><a href="http://download.oracle.com/javase/tutorial/essential/io/legacy.html#mapping"><span style="color: windowtext; font-size: 14pt; text-decoration: none;">http://download.oracle.com/javase/tutorial/essential/io/legacy.html#mapping</span></a></span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">&nbsp;)</span><span lang="DE"><o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Prior to the JDK7 release, the&nbsp;</span><span class="SourceText"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">java.io.File</span></span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">&nbsp;class was the mechanism used for file I/O, but it had several drawbacks.</span><span lang="DE"><o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 35.35pt; margin-right: 28.35pt; margin-top: 0in; mso-list: l0 level1 lfo2; mso-pagination: widow-orphan; text-indent: -14.15pt;"><span lang="DE" style="color: black; font-family: OpenSymbol; font-size: 14pt;">•<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Many methods didn't throw exceptions when they failed, so it was impossible to obtain a useful error message. For example, if a file deletion failed, the program would receive a "delete fail" but wouldn't know if it was because the file didn't exist, the user didn't have permissions, or there was some other problem.<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 35.35pt; margin-right: 28.35pt; margin-top: 0in; mso-list: l0 level1 lfo2; mso-pagination: widow-orphan; text-indent: -14.15pt;"><span lang="DE" style="font-family: OpenSymbol;">•<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">The&nbsp;</span><span class="SourceText"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">rename</span></span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">&nbsp;method didn't work consistently across platforms.</span><span lang="DE"><o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 35.35pt; margin-right: 28.35pt; margin-top: 0in; mso-list: l0 level1 lfo2; mso-pagination: widow-orphan; text-indent: -14.15pt;"><span lang="DE" style="color: black; font-family: OpenSymbol; font-size: 14pt;">•<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">There was no real support for symbolic links.<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 35.35pt; margin-right: 28.35pt; margin-top: 0in; mso-list: l0 level1 lfo2; mso-pagination: widow-orphan; text-indent: -14.15pt;"><span lang="DE" style="color: black; font-family: OpenSymbol; font-size: 14pt;">•<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">More support for metadata was desired, such as file permissions, file owner, and other security attributes.<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 35.35pt; margin-right: 28.35pt; margin-top: 0in; mso-list: l0 level1 lfo2; mso-pagination: widow-orphan; text-indent: -14.15pt;"><span lang="DE" style="color: black; font-family: OpenSymbol; font-size: 14pt;">•<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Accessing file metadata was inefficient.<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 35.35pt; margin-right: 28.35pt; margin-top: 0in; mso-list: l0 level1 lfo2; mso-pagination: widow-orphan; text-indent: -14.15pt;"><span lang="DE" style="font-family: OpenSymbol;">•<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Many of the&nbsp;</span><span class="SourceText"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">File</span></span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">&nbsp;methods didn't scale. Requesting a large directory listing over a server could result in a hang. Large directories could also cause memory resource problems, resulting in a denial of service.</span><span lang="DE"><o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 35.35pt; margin-right: 28.35pt; margin-top: 0in; mso-list: l0 level1 lfo2; mso-pagination: widow-orphan; text-indent: -14.15pt;"><span lang="DE" style="color: black; font-family: OpenSymbol; font-size: 14pt;">•<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">It was not possible to write reliable code that could recursively walk a file tree and respond appropriately if there were circular symbolic links.<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Jdk 1.7 has great many changes to improve developer's productvity and app's performance - (</span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-family: Arial, sans-serif; font-size: 9.5pt;"><a href="http://tech.puredanger.com/java7/"><span style="color: black; font-family: 'Times New Roman', serif; font-size: 14pt; text-decoration: none;">http://tech.puredanger.com/java7/</span></a></span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;"> )<br style="mso-special-character: line-break;" /> <br style="mso-special-character: line-break;" /> </span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-family: Arial, sans-serif; font-size: 9.5pt;"><o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">The last but not the least, since we are discussing handling of direct byte buffers, its worth keeping in mind the recommendations (IO bound cache) posted at - </span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-family: Arial, sans-serif; font-size: 9.5pt;"><a href="http://nadeausoftware.com/articles/2008/02/java_tip_how_read_files_quickly"><span style="color: black; font-family: 'Times New Roman', serif; font-size: 14pt; text-decoration: none;">http://nadeausoftware.com/articles/2008/02/java_tip_how_read_files_quickly</span></a><o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">(a) Minimize I/O operations by reading an array at a time, not a byte at a time.&nbsp;An 8Kbyte array is a good size.<br /> (b) Minimize method calls by getting data an array at a time, not a byte at a time.&nbsp;Use array indexing to get at bytes in the array.<br /> (c) Minimize thread synchronization locks if you don't need thread safety.&nbsp;Either make fewer method calls to a thread-safe class, or use a non-thread-safe class like&nbsp;FileChanneland&nbsp;MappedByteBuffer.<br /> (d) Minimize data copying between the JVM/OS, internal buffers, and application arrays.&nbsp;Use&nbsp;FileChannel&nbsp;with memory mapping, or a direct or wrapped array&nbsp;ByteBuffer.<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">References :<o:p></o:p></span></b></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE"><a href="http://blog.terracottatech.com/2010/09/bigmemory_explained_a_bit.html"><span style="color: windowtext; text-decoration: none;">http://blog.terracottatech.com/2010/09/bigmemory_explained_a_bit.html</span></a><o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE"><a href="http://ehcache.org/documentation/offheap_store.html"><span style="color: windowtext; text-decoration: none;">http://ehcache.org/documentation/offheap_store.html</span></a><o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE"><a href="http://www.ibm.com/developerworks/java/library/j-nativememory-linux/"><span style="color: windowtext; text-decoration: none;">http://www.ibm.com/developerworks/java/library/j-nativememory-linux/</span></a><o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE"><a href="http://developers.sun.com/learning/javaoneonline/2008/pdf/TS-5419.pdf"><span style="color: windowtext; text-decoration: none;">http://developers.sun.com/learning/javaoneonline/2008/pdf/TS-5419.pdf</span></a><o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE"><a href="http://tusharkhairnar.blogspot.com/2010/09/bigmemory-memory-with-no-garbage.html"><span style="color: windowtext; text-decoration: none;">http://tusharkhairnar.blogspot.com/2010/09/bigmemory-memory-with-no-garbage.html</span></a><o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE"><a href="http://download.oracle.com/javase/tutorial/essential/io/legacy.html#mapping"><span style="color: windowtext; text-decoration: none;">http://download.oracle.com/javase/tutorial/essential/io/legacy.html#mapping</span></a><o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE"><a href="http://java.sun.com/developer/technicalArticles/javase/nio/"><span style="color: windowtext; text-decoration: none;">http://java.sun.com/developer/technicalArticles/javase/nio/</span></a><o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE"><a href="http://tech.puredanger.com/java7/"><span style="color: windowtext; text-decoration: none;">http://tech.puredanger.com/java7/</span></a><o:p></o:p></span></div><div class="Standard"><br /> </div></div>http://musings-on-technology.blogspot.com/2011/04/building-high-speed-cache.htmlnoreply@blogger.com (Kaniska)0tag:blogger.com,1999:blog-1373851816248476399.post-873084490185190088Tue, 19 Apr 2011 04:45:00 +00002011-04-19T10:17:06.859+05:30API DesignDesigning Better API<div dir="ltr" style="text-align: left;" trbidi="on"><br /> <div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">1.<b>Each API Interface should be the concise Cover Story of What / How User can achieve out of the API.</b></span><span lang="DE" style="font-size: 14pt;"><o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">We should Code the Use-Case as API.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Each class/interface/method should clearly specify if the implementor / extender needs to do something additional to ensure Performance, State management and Threading. It should say&nbsp; how to use it.&nbsp; <o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">It should spell out clearly – what varargs / enums are being used to serve what purpose.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Here are the guidelines provided in </span><span lang="DE"><a href="http://wiki.eclipse.org/Evolving_Java-based_APIs"><span style="color: windowtext; font-size: 14pt; text-decoration: none;">http://wiki.eclipse.org/Evolving_Java-based_APIs</span></a></span><span lang="DE" style="font-size: 14pt;"> <span style="color: black;">&nbsp;- what I call as </span></span><span lang="DE"><a href="http://wiki.eclipse.org/Evolving_Java-based_APIs"><span style="color: windowtext; text-decoration: none;">Bible for API Architects</span></a></span><span lang="DE" style="color: black; font-size: 14pt;"> - Courtecy : Jim des Rivières, IBM</span><span lang="DE"><o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">We should think deeply how the external world going to provide the service for a requirement.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">When we design the requirement as interface if in doubt about an operation we should leave it !<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">2.How to mark an existing API as obsolete ?<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">How to advertise that a new API method is available ?<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">should use @deprecated<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">3. How to communicate to users whether to extend or not ?<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">@noextend&nbsp; (Eclipse API annotation)<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">4. What can be exposed ?<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Only public static final primitive, string constants, enum values and immutable object references.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">5. Document thread-safety of super class methods<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">@ThreadSafe public class Account {<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">&nbsp; @GuardedBy("this") private int balance;<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">,......<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">}<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Make it very clear if a Task needs to wait or scheduled in future.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">ExecutorService service = Executors.newSingleThreadExecutor();<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">// scheduling is quite different<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Future task = service.submit(someRunnable);<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">// compared to waiting<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">task.get(1000, TimeUnit.MILLISECONDS);<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">This builds on the expected knowledge that waiting is something that can cause deadlocks and that<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">developers should do so with care.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">6. <b>An API can be evolved easily if we expose Factory methods instead of Constructors.</b><o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Advantages :<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">(i) we can return a sub-class / interface from the static factory method . so there will not be any tight coupling with a concrete class.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">(ii) we can cache instances<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">(iii) a factory method can be synchronized as a whole, including<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">potential code before the object creation, the code that creates the instances, as well as the<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">rest of the code that runs after the object is created. This isn’t possible in a constructor at all.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">(iv) Factory methods are not constrained by the type of the enclosing class.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">7. In API class / Interface we should not specify setter method.<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">For example&nbsp;javax.swing.Action has&nbsp;setEnabled(boolean) method - which should be placed in the class AbstractAction .. because this method is specific to implementation not the skeleton api i.e. while creating an Action user need not invoke setEnabled(boolean). In some special cases, if user needs to invoke setEnabled(false) then he should use AbstractAction.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="font-size: 14pt;">8. API is all about good names ! Thats it !<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">&nbsp;if (car.speed() &gt; 1.5*SPEED_LIMIT)<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">&nbsp;&nbsp; alertDriver("Watch out for Cops");<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">Bad Example :<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">Thread.interrupted() -- just a horrific name !&nbsp; It should be a present-tense verb like -clearInteruptStatus() !!<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">Good Example :<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">public interface List {<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">List subList(int fromIndex, int toIndex);<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">}<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Very powerful. easy to remember ...without document<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin: 0in; mso-list: l0 level1 lfo1; mso-pagination: widow-orphan; text-indent: 0in;"><b><span lang="DE" style="color: black; font-size: 14pt;">8.<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></b><b><span lang="DE" style="color: black; font-size: 14pt;">Forbid access to the package containing implementation classes .<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&nbsp;Do this on the class-loading level, - by suffixing pkg name 'internal' when developing bundles inside Eclipse or make them pkg-private for non-osgi environment.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">9. Always introduce an intermediate bridge interface to maintain backward compatibility<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&nbsp;If we have &nbsp;class say - public abstract class HelloVisitor with 2 methods<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&nbsp;&nbsp;- helloAll()<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&nbsp;&nbsp;- helloVisitor(Visitor visitor)<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&nbsp;In next release, you decided to introduce new class- public abstract HelloAll with only one method - helloAll()<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Then for backward compatibility make &nbsp;HelloVisitor extend HelloAll.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">10.&nbsp;Use Builder pattern as a method is better than a variable.<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">docInfo</span></b><span lang="DE" style="color: black; font-size: 14pt;">= DocumentInfo.empty().nameProvider(p).urlProvider(p).normalize(p);<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Never allow more than 3 parameters in arg list<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&gt;&gt; break up into smaller methods .. Builder Pattern .. Named params<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&gt;&gt; Create helper class to hold params<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">11.&nbsp; Clear seperation between API and SPI<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">An API is something that Clients call and an SPI is something that Providers<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">implement.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">For example, in case of the FileSystem API, the FileObject is there to be called, while the<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">LocalFileSystem and JarFileSystem are there to be implemented.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Adding a new method in API delights its client. Whereas adding a new method in SPI breaks the provider's codebase !!<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin: 0in; mso-list: l3 level1 lfo2; mso-pagination: widow-orphan; text-indent: 0in;"><b><span lang="DE" style="font-size: 14pt;">12.<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></b><b><span lang="DE" style="font-size: 14pt;">Catch the exceptions early as part of Pre Condition Validation.<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Remember to throw an Exception at a Consistent Level of Abstraction :<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">class Employee {<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&nbsp;public TaxId getTaxId() throws EmployeeDataNotAvailable {....}<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">}<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">We should not throw a SQLException inside a BankAccountService API rather throw AccountNotAvailable exception.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">13. We should adopt 'Annotation' over 'Configuration'.<o:p></o:p></span></b></div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Spring 2.5 takes a huge step in this direction by providing you with the option<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">to annotate implementation classes:<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">@Service<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">public class SimpleScramblerAnnotated extends SimpleScrambler {<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">public SimpleScramblerAnnotated() {<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">}<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan; tab-stops: -4.5pt;"><span lang="DE" style="color: black; font-size: 14pt;">}<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">@Service<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">public class StaticWordLibraryAnnotated extends StaticWordLibrary {<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">public StaticWordLibraryAnnotated() {<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">}<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">}<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">@Service("ui")<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">public class AnagramsAnnotated extends AnagramsWithConstructor {<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">@Autowired<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">public AnagramsAnnotated(WordLibrary library, Scrambler scrambler) {<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">super(library, scrambler);<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">}<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">}<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">You use an indication that identifies the exported beans, their names, and potentially also<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">their dependencies on other APIs that need to be provided for the implementation to work<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">correctly. The final assembler no longer needs to write a configuration file with references to<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">all names of implementation classes, but rather can instruct the Spring Framework to use the<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">provided annotations.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">It’s still necessary to know the name of the packages that contain all the implementations.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">However, that is significantly less knowledge than knowing all the classes and their parameters.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="font-size: 14pt;">14. Public Concrete&nbsp; Class should be Final and Immutable.<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; A Classic example of Non-Immutable Class is Calender which should have been designed a Mutable because its job is to just mutate Date.&nbsp; Another bad example in Java is Collection Classes which should have been declared Final as they should never be extended rather decorated !<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">Classical design mistakes :: Stack is not a vector .. it has a vector ...<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">Similarly Properties is not HashTable, but it still extends HashTable.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">clone(), readObject(), constructor should never invoke overridable method.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="font-size: 14pt;">15. Avoid Overloading !! Yes thats true !!<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">Avoid overloading .. always use meaningful method names !!<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">Bad Example :<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">1. public TreeSet(Collection c) // Ignores order<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">&nbsp;&gt;&gt; creates a new comparator<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">2. public TreeSet(SortedSet s) // respects order<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">&nbsp;&gt;&gt; uses the comparator of SortedSet<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">Imagine client calls ..<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">SortedSet mySet = ..<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">TreeSet tset = new TreeSet((Collection)mySet)<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">#1 will be invoked .. and the order already present in SortedSet will be ignored .. as it will use a new comparator ..<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">If the behaviors of two methods differ, it's better to give them different names<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">The above confusion arises due to the fact that – Collection Fwk tried to be Flexible by providing overloaded constructors !!!!<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">AbstractSet, AbstractList are good examples !<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="font-size: 14pt;">16.&nbsp; In API, paramerts should be ordered in meaningful fashion :<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">java.util.concurrent provides good examples : .. long delay, TimeUnit unit<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin: 0in; mso-list: l5 level1 lfo3; mso-pagination: widow-orphan; text-indent: 0in;"><b><span lang="DE" style="color: black; font-size: 14pt;">17.<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></b><b><span lang="DE" style="color: black; font-size: 14pt;">Be careful while making super class methods thread safe.<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">The suggested way is to use synchronized in the definition of a method. Fine, that can work for me.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">I am able to write my code in one class without deadlocks. But what if somebody subclasses my object and<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">also uses synchronized methods? Well, in that case it uses the same lock as mine, usually without any<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">knowledge as to how I should use the lock, because my synchronized methods can be private and thus not<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">of interest to subclasses. The result? Deadlocks everywhere.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Subclassing and using synchronized methods sneaks into the superclass’s own synchronization<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">model.That can completely invalidate any synchronization assumptions the<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">superclass has made. Doing so is just plain dangerous.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="font-size: 14pt;">18. API should provide toString implementation<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">Provide programmatic access to all data available in string form. Otherwise, programmers will be forced to parse strings, which is painful. Worse, the string forms will turn into de facto APIs.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">Good StackTrace[] getStackTrace()<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">19.&nbsp; "It’s good to be reminded that the sole</span></b><b><span lang="DE" style="font-size: 14pt;"><o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">purpose of overridable methods is to replace a table mapping method name with actual code<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">snippets."<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">java.util.Arrays has many toString methods, each accepting<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">different array types, such as byte[], short[], and Object[]. These methods are therefore<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">overloaded. When called, the compiler chooses the best one depending on the type of the<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">parameter that is passed for method invocation.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">20. <b>API should encpsulate boilerplate code</b> ..<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&nbsp;&nbsp; User need not bear the burden of heavy-lifting the bulk of logic , say implementing a Transformer to transform a Dom model etc.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&nbsp;There should be a simple method writeDoc(...)&nbsp; which should hide the details.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">21. Return zero-length array or empty collection - not NULL<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">NULL Patterns ::<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">class Service {<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&nbsp; private final Log log;<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&nbsp; Service() {<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&nbsp;&nbsp;&nbsp; this.log = new NullLog();<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&nbsp; }<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">}<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">public final class NullLog implements Log {<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&nbsp; public void write(String messageToLog) {<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&nbsp;&nbsp;&nbsp; // do nothing<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&nbsp; }<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">}<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">22.&nbsp; Contrary to popular belief – do not throw CheckedException so frequently rather throw it very sparingly !<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Bad Enforcement JDK !!!<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">we know it will succeed .. but still client have to catch it ..<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">try {<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Foo f = (Foo) super.clone();<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">} catch(CloneNotSupportedExceptio e) {<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">}<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin: 0in; mso-list: l1 level1 lfo4; mso-pagination: widow-orphan; text-indent: 0in;"><b><span lang="DE" style="color: black; font-size: 14pt;">23.<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></b><b><span lang="DE" style="color: black; font-size: 14pt;">Make everything Final then open up / expose on need basis.<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin: 0in; mso-list: l2 level1 lfo5; mso-pagination: widow-orphan; text-indent: 0in;"><b><span lang="DE" style="color: black; font-size: 14pt;">24.<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></b><b><span lang="DE" style="color: black; font-size: 14pt;">Implemenation Class must be Immutable<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Do not provide a getter method like getValues() that exposes private internal mutable object state<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">without defensively copying the state.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Collections.unmodifiableList(Arrays.asList(items));<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">25. API should not wait for response rather it should strive to reduce latency<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Defer the processing logic in Provider API and return immedialtely to Client<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Create a client API that will post a Future task to a Provider API wrapping up a Single Processor Executor. When user will call the client API either return immediately or time-out.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">26. While resolving Classes for supporting Multiple APIs always use compliant solution.<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">"Two classes are the same class (and consequently the same type) if they are loaded by the same<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">class loader and they have the same fully qualified name" [JVMSpec 1999].<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Noncompliant --<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&gt;&gt; if (auth.getClass().getName().equals("com.application.auth.DefaultAuthenticationHandler")) {<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&nbsp; // ...<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">}<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Compliant&nbsp; --<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&gt;&gt; if (auth.getClass() == this.getClassLoader().loadClass<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">("com.application.auth.DefaultAuthenticationHandler")) {<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&nbsp; // ...<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">}<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin: 0in; mso-list: l4 level1 lfo6; mso-pagination: widow-orphan; text-indent: 0in;"><span lang="DE" style="color: black; font-size: 14pt;">27.<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><b><span lang="DE" style="color: black; font-size: 14pt;">Design Composition and Aggregation inside API </span></b><span lang="DE" style="color: black; font-size: 14pt;">using Decorator and Delegate patterns.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Identify where responsibility can be attached in runtime using Decorator by discouraging the usage of Inheritence.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">28.&nbsp;&nbsp;&nbsp; <b>Handle memory-leak scenarios in Base Implemnetaion Classes</b><o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Its important to encapsulate the core logic of managing listeners, indexes, caches, data-binding, thread-executors, validators etc. Inside base framework classes.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Its absolutely essential to identify the scenarios of using WeakHashmap, cleaning up resources, visitor patterns to minimize 'instance-of' checking, static inner classes.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">References :<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Standard"><span lang="DE"><a href="http://www.infoq.com/presentations/effective-api-design"><span style="color: windowtext; font-size: 14pt; text-decoration: none;">http://www.infoq.com/presentations/effective-api-design</span></a><o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><b style="mso-bidi-font-weight: normal;"><span lang="DE" style="color: #333333; font-size: 14pt;">API Design and Evolution<o:p></o:p></span></b></div><div class="Standard"><span lang="DE"><a href="http://www.eclipsecon.org/2010/sessions/sessions?id=1427"><span style="color: windowtext; font-size: 14pt; text-decoration: none;">http://www.eclipsecon.org/2010/sessions/sessions?id=1427</span></a></span><span lang="DE" style="font-size: 14pt;">&nbsp; </span><span lang="DE"><o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><b><span lang="DE" style="font-size: 14pt;">Java Coding Practice Guidelines<o:p></o:p></span></b></div><div class="Standard"><span lang="DE"><a href="https://www.securecoding.cert.org/confluence/display/java/The+CERT+Oracle+Secure+Coding+Standard+for+Java"><span style="color: windowtext; font-size: 14pt; text-decoration: none;">https://www.securecoding.cert.org/confluence/display/java/The+CERT+Oracle+Secure+Coding+Standard+for+Java</span></a><o:p></o:p></span></div></div>http://musings-on-technology.blogspot.com/2011/04/designing-better-api.htmlnoreply@blogger.com (Kaniska)0tag:blogger.com,1999:blog-1373851816248476399.post-1238470004471331437Tue, 19 Apr 2011 04:44:00 +00002011-04-19T10:17:43.397+05:30concurrencyjdkLearning from JDK Source and Language Specs<div dir="ltr" style="text-align: left;" trbidi="on"><br /> <div class="MsoNormal" style="text-align: justify;"><b>Excerpts from Java Language Framework, Concurrency API Documents, following Websites and personal learning :<o:p></o:p></b></div><div class="MsoNormal" style="text-align: justify;"><br /> </div><div class="MsoNormal" style="text-align: justify;"><span lang="RU" style="font-size: 14pt;">JSR 133 (Java Memory Model) FAQ : <o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span lang="RU" style="font-size: 14pt;">&nbsp;</span><span lang="RU"><a href="http://www.cs.umd.edu/~pugh/java/memoryModel/jsr-133-faq.html">http://www.cs.umd.edu/~pugh/java/memoryModel/jsr-133-faq.html</a></span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span lang="RU" style="font-size: 14pt;">&nbsp;Concurrency Simplified :<o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span lang="RU" style="font-size: 14pt;">&nbsp;</span><span lang="RU"><a href="http://gee.cs.oswego.edu/dl/concurrency-interest/jsr166-slides.pdf">http://gee.cs.oswego.edu/dl/concurrency-interest/jsr166-slides.pdf</a></span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span lang="RU" style="font-size: 14pt;">&nbsp;</span><span lang="RU"><a href="http://www.ibm.com/developerworks/java/library/j-jtp0618.html">http://www.ibm.com/developerworks/java/library/j-jtp0618.html</a></span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><b><span lang="RU" style="font-size: 14pt;">1. </span></b><b><span style="font-size: 14pt;">Recollecting of Basic Concepts :<o:p></o:p></span></b></div><div class="MsoNormal" style="text-align: justify;"><br /> </div><div class="MsoNormal" style="text-align: justify;"><span lang="RU" style="font-size: 14pt;">“Each thread is a different stream of control that can execute its instructions independently, allowing a <o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span lang="RU" style="font-size: 14pt;">multithreaded process to perform numerous tasks concurrently. One thread can run the GUI while <o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span lang="RU" style="font-size: 14pt;">a second thread does some I/O and a third performs calculations. <o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span lang="RU" style="font-size: 14pt;">It is the program state that gets scheduled on a CPU; it is the "thing" that does the work. If a process comprises data, code, kernel state, and a set of CPU registers, then a thread is embodied in the contents of those registers—the program counter, the general registers, the stack pointer, etc., and the stack. A thread, viewed at an instant of time, is the state of the computation.” <o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span lang="RU" style="font-size: 14pt;">– </span><span lang="RU"><a href="http://books.google.com/books?id=bIchilfV3bcC&amp;pg=PT38&amp;lpg=PT38&amp;dq=">Multithreaded programming with Java technology</a></span><i style="mso-bidi-font-style: normal;"><span lang="RU" style="font-size: 14pt;"> , </span></i><span lang="RU" style="font-size: 14pt;">Bil Lewis, Daniel J. Berg <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-align: justify;"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">A thread is a lightweight entity, comprising the registers, stack, and some other data. The rest of the process structure is shared by all threads: the address space, file descriptors, etc. Much (and sometimes all) of the thread structure is in user space, allowing for very fast access. <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-align: justify;"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">The main benefits of writing multithreaded programs are: <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">• Performance gains from multiprocessing hardware (parallelism) <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">• Increased application throughput <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">• Increased application responsiveness <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">• Replacing process-to-process communications <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">• Efficient use of system resources <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">• One binary that runs well on both uniprocessors and multiprocessors <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-align: justify;"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><b><span style="font-size: 14pt;">2. Properties of</span></b><b><span style="font-size: 14pt;"> </span></b><b><span style="font-size: 14pt;">typical</span></b><b><span style="font-size: 14pt;"> </span></b><b><span style="font-size: 14pt;">MultiThreaded</span></b><b><span style="font-size: 14pt;"> </span></b><b><span style="font-size: 14pt;">Program</span></b><b><span lang="RU" style="font-size: 14pt;">: <o:p></o:p></span></b></div><div class="MsoNormal"><b><span lang="RU" style="font-size: 14pt;">Independent tasks <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">A debugger needs to run and monitor a program, keep its GUI active, and display an interactive data inspector, dynamic call grapher, and performance monitor—all in the same address space, all at the same time. <o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><span style="font-size: 14pt;">For example, a </span><span lang="RU" style="font-size: 14pt;">&nbsp;server needs to handle numerous overlapping requests simultaneously. NFS®, NIS, DBMSs,&nbsp; stock quotation servers, etc., all receive large numbers of requests that require the server to do some I/O, then process the results and return answers. Completing one request at a time would be very slow. <o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><b><span lang="RU" style="font-size: 14pt;">Repetitive tasks <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">A simulator needs to simulate the interactions of numerous different elements that operate simultaneously. CAD, structural analysis, weather prediction, etc., all model tiny pieces first, then combine the results to produce an overall picture. <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">-------------------------------------------------------- <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><b><span lang="RU" style="font-size: 14pt;">3.&nbsp;&nbsp;&nbsp; How does the Synchronization work in Memory ? <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">Ref: </span><span lang="RU"><a href="http://www.cs.umd.edu/~pugh/java/memoryModel/jsr-133-faq.html">http://www.cs.umd.edu/~pugh/java/memoryModel/jsr-133-faq.html</a></span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><span lang="RU" style="font-size: 14pt;">“Synchronization has several aspects. The most well-understood is <b>mutual exclusion</b> -- only one thread can hold a monitor at once, so synchronizing on a monitor means that once one thread enters a synchronized block protected by a monitor, no other thread can enter a block protected by that monitor until the first thread exits the synchronized block. <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">But there is more to synchronization than mutual exclusion. <b>Synchronization ensures that memory writes by a thread before or during a synchronized block are made visible in a predictable manner to other threads which synchronize on the same monitor.</b> After we exit a synchronized block, we&nbsp;release&nbsp;the monitor, which has the effect of flushing the cache to main memory, so that writes made by this thread can be visible to other threads. Before we can enter a synchronized block, we&nbsp;acquire&nbsp;the monitor, which has the effect of invalidating the local processor cache so that variables will be reloaded from main memory. We will then be able to see all of the writes made visible by the previous release.” <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><b><span style="font-size: 14pt;">4.</span></b><b><span style="font-size: 14pt;"> <span lang="RU">How Volatile can be used to avoid excessive synchronization <o:p></o:p></span></span></b></div><div class="MsoNormal"><b><span lang="RU" style="font-size: 14pt;">&nbsp;&nbsp;&nbsp; and implement non-blocking operation ? <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">Volatile fields are special fields which are used for communicating state between threads. <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">The compiler and runtime are prohibited from allocating them in registers. They must also ensure that after they are written, they are flushed out of the cache to main memory, so they can immediately become visible to other threads. (executes a WRITE BARRIER like memory writes for UNLOCKING MONITOR). <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">Similarly, before a volatile field is read, the cache must be invalidated so that the value in main memory, not the local processor cache, is the one seen. Even if the volatile field is assigned any value in the reader thread, that value will be replaced by the latest value written by writer thread i.e. it will excute a READ_BARRIER to refresh local value with the ones in main memory. <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">This is how, each read of a volatile will see the last write to that volatile by any thread; in effect, they are designated by the programmer as fields for which it is never acceptable to see a "stale" value as a result of caching or reordering. <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">Each read or write of a volatile field acts like "half" a synchronization, for purposes of visibility. <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">The best example is ConcurrentHashMap </span><span style="font-size: 14pt;">which uses volatile to decide whether to acquire a partial lock on segment of keys or go ahead with direct lookup !!<o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><b><span style="font-size: 14pt;">Now lets look into the usage of Java Synchronizers : Modern non-blocking lock-contention free wait-optimized multi-threading tools<o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><b><span style="font-size: 14pt;">5. How to signal effectively between Consumer and Worker instead of wasting CPU Cycles ?<o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">Condition – can be used to signal between Consumer and Worker threads. <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp;&nbsp;&nbsp; Instead of making consumer thread wait() in while() loop. <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp;&nbsp;&nbsp; This is specially useful for BlockingQueue. <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp;&nbsp; final BlockingQueue<string> msgQ = new LinkedBlockingQueue<string>(); <o:p></o:p></string></string></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp;&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp;&nbsp; public void produceWork() throws InterruptedException { <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String message =&nbsp; get the message from source …. <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; msgQ.put(message); <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp;&nbsp; } <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp; public LoggedService() { // start background thread <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp; Runnable logr = new Runnable() { <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp;&nbsp; public void run() { <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp;&nbsp; try { <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(;;) <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(msqQ.take()); <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp;&nbsp; } catch(InterruptedException ie) {} }}; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp; Executors.newSingleThreadExecutor().execute(logr); <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp; } <o:p></o:p></span></div><div class="MsoNormal"><b><span lang="RU" style="color: blue; font-size: 14pt;">Condition notFull = lock.newCondition(); <o:p></o:p></span></b></div><div class="MsoNormal"><b><span lang="RU" style="color: blue; font-size: 14pt;">Condition notEmpty = lock.newCondition(); <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp; <b>msgQ.take() - will wait till an element is available in Queue. <o:p></o:p></b></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp; while (count == 0) <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; notEmpty.await(); <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><b><span lang="RU" style="color: blue; font-size: 14pt;">msgQ.poll(time..) </span></b><span lang="RU" style="color: blue; font-size: 14pt;">- wait till an element is available after a specified time. <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">msgQ.put(E) – will wait till queue length ls less than capacity. <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp; while (count == items.length) <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b> notFull.await(); <o:p></o:p></b></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><b><span style="color: blue; font-size: 14pt;">**** Lock.lock() replacement for synchronized {…} ; Condition.await()-signal()-signalAll()... replacement for wait()-notify()-nitofyAll() ...<o:p></o:p></span></b></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><b><span style="font-size: 14pt;">This is a wonderful permission system – where N threads can hold a lock at any point of time !!<o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><b><span style="font-size: 14pt;">6</span></b><b><span lang="RU" style="font-size: 14pt;">&nbsp; LOCK – offers significant advantage over 'synchronizing a block of code' i.e. does not force blocking a&nbsp;&nbsp; 'structured locking/unlocking' <o:p></o:p></span></b></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><span style="font-size: 14pt;">Lets go through the Code Comments in LOCK.java<o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp;&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">{@code Lock}</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">implementations</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">provide</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">more</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">extensive</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">locking</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">operations</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">than</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">can</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">be</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">obtained</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">using</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">{@code synchronized}</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">methods</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">and</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">statements.&nbsp; They</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">allow</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">more</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">flexible</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">structuring,</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">may</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">have</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">quite</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">different</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">properties,</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">and</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">may</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">support</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">multiple</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">associated</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">{@link Condition}</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">objects.</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp;</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><b><span lang="RU" style="font-size: 14pt;">Main problem with 'synchronized' </span></b><span lang="RU" style="font-size: 14pt;">-&nbsp; </span><span lang="RU" style="font-size: 14pt;">methods</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">or</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">statements</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">provides</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">access</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">to</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">the</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">implicit</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">monitor</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">lock</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">associated</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">with</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">every</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">object,</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">but</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">forces</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">all</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">lock</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">acquisition</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">and</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">release</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">to</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">occur</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">in</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">a</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">block-structured</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">way</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><b><span lang="RU" style="font-size: 14pt;">– Bigger Scope <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp;</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><b><span lang="RU" style="font-size: 14pt;">Lock </span></b><b><span style="font-size: 14pt;">has the advantage of </span></b><b><span lang="RU" style="font-size: 14pt;">smaller scope</span></b><span lang="RU" style="font-size: 14pt;"> </span><span style="font-size: 14pt;">-<o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">acquire</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">the</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">lock</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">of</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">node</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">A,</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">then</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">node</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">B,</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">then</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">release</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">A</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">and</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">acquire</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">C,</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">then</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">release</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">B</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">and</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">acquire</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">D</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">and</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">so</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">on. (Hand Over Hand / Chain Lock) Implementations</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">of</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">the <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">{@code Lock}</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">interface</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">enable</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">the</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">use</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">of</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">such</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">techniques</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">by</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">allowing</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">a</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">lock</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">to</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">be</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">acquired</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">and</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">released</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">in</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">different</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">scopes <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><b><span lang="RU" style="font-size: 14pt;">Another problem with 'synchronized' – <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">when</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">multiple</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">locks</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">are</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">acquired</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">they</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">must</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">be</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">released</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">in</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">the</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">opposite</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">order,</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">and</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">all</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">locks</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">must</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">be</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">released</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">in</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">the</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">same</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">lexical</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">scope</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">in</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">which</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">they</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">were</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">acquired.</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp;</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><b><span style="font-size: 14pt;">Advantage of</span></b><b><span lang="RU" style="font-size: 14pt;"> 'Lock' </span></b><b><span style="font-size: 14pt;">can be</span></b><b><span lang="RU" style="font-size: 14pt;">- </span></b><b><span lang="RU" style="font-size: 14pt;">released</span></b><b><span lang="RU" style="font-size: 14pt;"> </span></b><b><span lang="RU" style="font-size: 14pt;">in</span></b><b><span lang="RU" style="font-size: 14pt;"> </span></b><b><span lang="RU" style="font-size: 14pt;">any order.</span></b><b><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp;</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><b><span lang="RU" style="font-size: 14pt;">Problem with Lock&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <o:p></o:p></span></b></div><div class="MsoNormal"><span style="font-size: 14pt;">- </span><span lang="RU" style="font-size: 14pt;">With</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">this</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">increased</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">flexibility</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">comes</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">additional</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">responsibility.</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">absence</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">of</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">block-structured</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">locking</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">removes</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">the</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">automatic</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">release</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">of</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">locks</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">that</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">occurs</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">with</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">{@code synchronized}</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">methods</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">and</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">statements.</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">In</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">most</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">cases,</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">the</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">following</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">idiom</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">should</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">be</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">used:</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;"></span></div><pre><tt>&nbsp;&nbsp;&nbsp;&nbsp; Lock<span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">l</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">=</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">...;</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span> <div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp; l.lock();</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp; try</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">{</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">access</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">the</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">resource</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">protected</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">by</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">this</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">lock</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp; }</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">finally</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">{</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; l.unlock();</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp; }</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">**** </span><span style="color: blue; font-size: 14pt;">So now JVM will spend less time in SCHEDULING THREADS and more time in EXECUTING them! <o:p></o:p></span></div><div class="MsoNormal"><span style="color: blue; font-size: 14pt;">**** Lock Contentions can be profiled in a much better way to spot bottlenecks !!<o:p></o:p></span></div><div class="MsoNormal"></div><div class="MsoNormal"><b><span style="font-size: 14pt;">How to e</span></b><b><span lang="RU" style="font-size: 14pt;">nsure Non-Blocking Behaviour <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">an</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">attempt</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">to</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">acquire</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">the</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">lock</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">that</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">can</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">be</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .5in; mso-list: l1 level1 lfo2; tab-stops: list .5in; text-indent: -.25in;"><span lang="RU" style="font-family: Symbol; font-size: 14pt;">·<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span lang="RU" style="font-size: 14pt;">interrupted</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">({@link #lockInterruptibly},<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .5in; mso-list: l1 level1 lfo2; tab-stops: list .5in; text-indent: -.25in;"><span lang="RU" style="font-family: Symbol; font-size: 14pt;">·<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span lang="RU" style="font-size: 14pt;">and</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">an</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">attempt</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">to</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">acquire</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">the</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">lock</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">that</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">can</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">timeout</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">({@link #tryLock(long, TimeUnit)}).<o:p></o:p></span></div><div class="MsoNormal"></div><div class="MsoNormal"><b><span style="font-size: 14pt;">How to ensure </span></b><b><span lang="RU" style="font-size: 14pt;">Concurrent Access </span></b><b><span style="font-size: 14pt;">using Locks </span></b><b><span lang="RU" style="font-size: 14pt;">?<o:p></o:p></span></b></div><div class="MsoNormal"></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">some</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">locks</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">may</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">allow</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">concurrent</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">access</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">to</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">a</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">shared</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">resource,</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">such</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">as</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">the</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">read</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">lock</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">of</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">a</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">{@link ReadWriteLock}.</span><span lang="RU" style="font-size: 14pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">Use ReentrantReadWriteLock&nbsp; for enforcing multiple-reader, single-writer access. <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Write lock can “downgrade” to read lock (not vice-versa). <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><b><span style="font-size: 14pt;">7. How to signal multiple threads simultaneously ?<o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">CountDownLatch </span><span style="font-size: 14pt;">is </span><span style="font-size: 14pt;">- a</span><span style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">synchronization</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">aid</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">that</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">allows</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">one</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">or</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">more</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">threads</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">to</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">wait</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">until</span><span lang="RU" style="font-size: 14pt;">&nbsp; </span><span lang="RU" style="font-size: 14pt;">a</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">set</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">of</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">operations</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">being</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">performed</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">in</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">other</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">threads</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">completes.</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"></div><div class="MsoNormal"><span style="font-size: 14pt;">Example from CounDownLatch.java<o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp;</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp; class</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">Driver</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">{</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">//</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">...</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp; void</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">main()</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">throws</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">InterruptedException</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">{</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp; CountDownLatch</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">startSignal</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">=</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">new</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">CountDownLatch(1);</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp; CountDownLatch</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">doneSignal</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">=</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">new</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">CountDownLatch(N);</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp; for</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">(int</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">i</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">=</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">0;</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">i</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">&lt; N; ++i) // create and start threads</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">Thread(new</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">Worker(startSignal,</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">doneSignal)).start();</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp; doSomethingElse();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">don't</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">let</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">run</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">yet <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp; startSignal.countDown();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">let</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">all</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">threads</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">proceed</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp; doSomethingElse();</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp; <b>doneSignal.await();&nbsp;&nbsp;&nbsp;</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">wait</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">for</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">all</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">to</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">finish</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp; }</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">}</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"></div><div class="MsoNormal"><b><span style="font-size: 14pt;">**** This also exemplifies – how instead of polling and wasting cpu resources, the thread&nbsp; just receives a signal when it is good to proceed !!<o:p></o:p></span></b></div><div class="MsoNormal"></div><div class="MsoNormal"><b><span style="font-size: 14pt;">**** No need to call join multiple times !!<o:p></o:p></span></b></div><div class="MsoNormal"></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">class</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">Worker</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">implements</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">Runnable</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">{</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp; private</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">final</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">CountDownLatch</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">startSignal;</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp; private</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">final</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">CountDownLatch</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">doneSignal;</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp; Worker(CountDownLatch</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">startSignal,</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">CountDownLatch</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">doneSignal)</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">{</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.startSignal</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">=</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">startSignal;</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.doneSignal</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">=</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">doneSignal;</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp; }</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp; public</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">void</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">run()</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">{</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">{</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; startSignal.await(); – this thread can't proceed till Driver calls <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; countDown ..</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; doWork();</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; doneSignal.countDown(); - <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">catch</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">(InterruptedException</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">ex)</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">{}</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">//</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">return;</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp; }</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp; void</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">doWork()</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">{</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">...</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">}</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">}</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; </span><span lang="RU" style="font-size: 14pt;">Another</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">typical</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">usage</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">would</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">be</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">to</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">divide</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">a</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">problem</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">into</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">N</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">parts,</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">describe</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">each</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">part</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">with</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">a</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">Runnable</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">that</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">executes</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">that</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">portion</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">and</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">counts</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">down</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">on</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">the</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">latch,</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">and</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">queue</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">all</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">the</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">Runnables</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">to</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">an</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">Executor.&nbsp; When</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">all</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">sub-parts</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">are</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">complete,</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">the</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">coordinating</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">thread</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">will</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">be</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">able</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">to</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">pass</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">through</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">await.</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><b><span lang="RU" style="font-size: 14pt;">8.&nbsp;</span></b><b><span style="font-size: 14pt;">How to implement non-blocking</span></b><b><span lang="RU" style="font-size: 14pt;">&nbsp; </span></b><b><span lang="RU" style="font-size: 14pt;">Optimistic </span></b><b><span style="font-size: 14pt;">Data Structure </span></b><b><span lang="RU" style="font-size: 14pt;">?</span></b><b><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></b></div><div class="MsoNormal"></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">class OptimisticLinkedList { // incomplete</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">static class Node {</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">volatile Object item;</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">final AtomicReference<node> next;</node></span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">Node(Object x, Node n) {</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">item = x; next = new AtomicReference(n); }</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">}</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">final AtomicReference head = new AtomicReference(null);</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">public void prepend(Object x) {</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">if (x == null) throw new IllegalArgumentException();</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">for(;;) {</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">Node h = head.get();</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">if (head.compareAndSet(h, new Node(x, h)) return;</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">}</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">}</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">public boolean search(Object x) {</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">Node p = head.get();</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">while (p != null &amp;&amp; x != null &amp;&amp; !p.item.equals(x))</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">p = p.next.get();</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">return p != null &amp;&amp; x != null;</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">}</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">}</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp;</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><b><span lang="RU" style="font-size: 14pt;">9.&nbsp;&nbsp;&nbsp; How final fields can offer thread-safety : <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">All threads will read the final value so long as it is guaranteed to be assigned before the object could be made visible to other threads.</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp;&nbsp;</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><b><span lang="RU" style="font-size: 14pt;">10.</span></b><b><span lang="RU" style="font-size: 14pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></b><b><span lang="RU" style="font-size: 14pt;">Perform operations asynchronously </span></b><b><span style="font-size: 14pt;">using Futures <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">when</span><span lang="RU" style="font-size: 14pt;"> </span><span style="font-size: 14pt;">time-consuming independent tasks need to be performed in Main thread.<o:p></o:p></span></div><div class="MsoNormal"></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">class ImageRenderer { Image render(byte[] raw); }</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">class App { // ...</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">Executor executor = ...; // any executor</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span style="color: blue; font-size: 14pt;">DocumentReader</span><span style="color: blue; font-size: 14pt;"> </span><span style="color: blue; font-size: 14pt;">docReader</span><span lang="RU" style="color: blue; font-size: 14pt;"> = new </span><span style="color: blue; font-size: 14pt;">DocumentReader</span><span lang="RU" style="color: blue; font-size: 14pt;">();</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">public void display(final byte[] </span><span style="color: blue; font-size: 14pt;">document</span><span lang="RU" style="color: blue; font-size: 14pt;">) {</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">try {</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">Future&lt;</span><span style="color: blue; font-size: 14pt;">Document</span><span lang="RU" style="color: blue; font-size: 14pt;">&gt; </span><span style="color: blue; font-size: 14pt;">document</span><span lang="RU" style="color: blue; font-size: 14pt;">= Executors.invoke(executor,</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">new Callable&lt;</span><span style="color: blue; font-size: 14pt;">Document</span><span lang="RU" style="color: blue; font-size: 14pt;">&gt;(){</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">public </span><span style="color: blue; font-size: 14pt;">Document</span><span lang="RU" style="color: blue; font-size: 14pt;"> call() {</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">return renderer.render(</span><span style="color: blue; font-size: 14pt;">document</span><span lang="RU" style="color: blue; font-size: 14pt;">);</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">}});</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span style="color: blue; font-size: 14pt;">preparePanel</span><span lang="RU" style="color: blue; font-size: 14pt;">(); // do other things </span><span style="color: blue; font-size: 14pt;">in main thread<o:p></o:p></span></div><div class="MsoNormal"><span style="color: blue; font-size: 14pt;">preparePageCaptions</span><span lang="RU" style="color: blue; font-size: 14pt;">(); // ... while </span><span style="color: blue; font-size: 14pt;">fetching the actual document in a different thread<o:p></o:p></span></div><div class="MsoNormal"><span style="color: blue; font-size: 14pt;">showDocument</span><span lang="RU" style="color: blue; font-size: 14pt;">(</span><span style="color: blue; font-size: 14pt;">document</span><span lang="RU" style="color: blue; font-size: 14pt;">.get()); // </span><span style="color: blue; font-size: 14pt;">block till document is fetched by</span><span lang="RU" style="color: blue; font-size: 14pt;"> future</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">}</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">catch (Exception ex) {</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">cleanup();</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">return;</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">}</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">} }</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><b><span lang="RU" style="font-size: 14pt;">11.&nbsp;&nbsp;&nbsp;How static fields can be used to guarantee thread-safety : <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><span lang="RU" style="font-size: 14pt;">use the Initialization On Demand Holder idiom, which is thread-safe and a lot easier to understand: <o:p></o:p></span></div><div class="MsoNormal" style="background: silver; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 15.0pt; margin-top: 0in;"><span lang="RU" style="font-size: 14pt;">private static class Lazy</span><span style="font-size: 14pt;">Model</span><span lang="RU" style="font-size: 14pt;">Holder {</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="background: silver; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 15.0pt; margin-top: 0in;"><span lang="RU" style="font-size: 14pt;">&nbsp; public static </span><span style="font-size: 14pt;">Model</span><span style="font-size: 14pt;"> </span><span style="font-size: 14pt;">model</span><span lang="RU" style="font-size: 14pt;"> = new </span><span style="font-size: 14pt;">Model</span><span lang="RU" style="font-size: 14pt;">();</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="background: silver; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 15.0pt; margin-top: 0in;"><span lang="RU" style="font-size: 14pt;">}</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="background: silver; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 15.0pt; margin-top: 0in;"><span lang="RU" style="font-size: 14pt;">&nbsp;</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="background: silver; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 15.0pt; margin-top: 0in;"><span lang="RU" style="font-size: 14pt;">public static </span><span style="font-size: 14pt;">Model</span><span lang="RU" style="font-size: 14pt;"> getInstance() {</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="background: silver; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 15.0pt; margin-top: 0in;"><span lang="RU" style="font-size: 14pt;">&nbsp; return Lazy</span><span style="font-size: 14pt;">Model</span><span lang="RU" style="font-size: 14pt;">Holder.something;</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="background: silver; margin-bottom: 14.15pt; margin-left: .5in; margin-right: 15.0pt; margin-top: 0in;"><span lang="RU" style="font-size: 14pt;">}</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt; margin-left: 15.0pt; margin-right: 15.0pt; margin-top: 0in;"><span lang="RU" style="font-size: 14pt;">This code is guaranteed to be correct because of the initialization guarantees for static fields; if a field is set in a static initializer, it is guaranteed to be made visible, correctly, to any thread that accesses that class. <o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt; margin-left: 15.0pt; margin-right: 15.0pt; margin-top: 0in;"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt; margin-left: 15.0pt; margin-right: 15.0pt; margin-top: 0in;"><b><span style="font-size: 14pt;">12</span></b><b><span lang="RU" style="font-size: 14pt;">. </span></b><b><span style="font-size: 14pt;">If not sure of fine-grained theading tools,&nbsp; take resort to traditional synchronization <o:p></o:p></span></b></div><div class="MsoNormal" style="margin-bottom: 6.0pt; margin-left: 15.0pt; margin-right: 15.0pt; margin-top: 0in;"><span lang="RU" style="font-size: 14pt;">LinkedList queue = new LinkedList(); <o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt; margin-left: 15.0pt; margin-right: 15.0pt; margin-top: 0in;"><span lang="RU" style="font-size: 14pt;">// Add to end of queue queue.add(<i style="mso-bidi-font-style: normal;">object</i>); <o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt; margin-left: 15.0pt; margin-right: 15.0pt; margin-top: 0in;"><span lang="RU" style="font-size: 14pt;">// Get head of queue Object o = queue.removeFirst(); <o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt; margin-left: 15.0pt; margin-right: 15.0pt; margin-top: 0in;"><span lang="RU" style="font-size: 14pt;">// If the queue is to be used by multiple threads, <o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt; margin-left: 15.0pt; margin-right: 15.0pt; margin-top: 0in;"><span lang="RU" style="font-size: 14pt;">// the queue must be wrapped with code to synchronize the methods queue = (LinkedList)Collections.synchronizedList(queue)</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt; margin-left: 15.0pt; margin-right: 15.0pt; margin-top: 0in;"></div><div class="MsoNormal" style="margin-bottom: 6.0pt; margin-left: .75pt; margin-right: 15.0pt; margin-top: 0in; mso-list: l2 level1 lfo3; tab-stops: list .5in; text-indent: 0in;"><b><span style="font-size: 14pt;">13.<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></b><b><span style="font-size: 14pt;">Why Deadlock occurs ? How to avoid it ?<o:p></o:p></span></b></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><span style="font-size: 14pt;">It occurs when multiple threads each acquire multiple locks in different orders.<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><span style="font-size: 14pt;">I lock a, b - Thread A:transferMoney(me, you, 100) U lock b, a - Thread B:transferMoney(you, me, 100).<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><span style="font-size: 14pt;">&nbsp;Synchronized – goes against the OOP principle ! &nbsp;Real tension between object oriented design and lock-based concurrency control !<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><span style="color: blue; font-size: 14pt;">The solution is – to ensure lock ordering as mentioned in the sections for creating Reentrant LOCKs.&nbsp; Lock the smallest possible set of sequential steps :<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><span style="font-size: 14pt;">atomic { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; from.credit(amount) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; to.debit(amount) &nbsp;}<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><b><span style="font-size: 14pt;">14. prefer immutability : prohibit sharing and avoid unnecessary synchonization<o:p></o:p></span></b></div><div class="MsoNormal" style="text-autospace: ideograph-numeric;"><span style="font-size: 14pt;">&nbsp;<span lang="RU">CopyOnWriteArrayList, CopyOnWrite</span></span><span style="font-size: 14pt;">ArraySet provides you thread safety with the added benefit of immutability to deal with data that changes infrequently. <o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: ideograph-numeric;"></div><div class="MsoNormal" style="text-autospace: ideograph-numeric;"><span style="font-size: 14pt;">The CopyOnWriteArrayList behaves much like the ArrayList class, <b>except that when the list is modified, instead of modifying the underlying array, a new array is created and the old array is discarded. <o:p></o:p></b></span></div><div class="MsoNormal" style="text-autospace: ideograph-numeric;"></div><div class="MsoNormal" style="text-autospace: ideograph-numeric;"><span style="font-size: 14pt;">This means that when a caller gets an iterator i.e. </span><i><span style="font-size: 14pt;">copyOnWriteArrayListRef</span></i><span style="font-size: 14pt;">.iterator(</span><span style="font-size: 14pt;">, which internally holds a reference to the underlying CopyOnWriteArrayList object’s array, which is immutable and therefore <b>can be used for traversal without requiring either synchronization on the list </b></span><i><span style="font-size: 14pt;">copyOnWriteArrayListRef </span></i><span style="font-size: 14pt;">or need to clone() the </span><span style="font-size: 14pt;">copyOnWriteArrayListRef </span><span style="font-size: 14pt;">list before traversal (i.e. there is no risk of concurrent modification).<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><b><span style="font-size: 14pt;">15.&nbsp;&nbsp; Replacing synchronized collections with concurrent collections can offer dramatic scalability improvements<o:p></o:p></span></b></div><div class="MsoNormal" style="margin-bottom: 6.0pt; margin-left: .5in; margin-right: 0in; margin-top: 0in; mso-list: l3 level1 lfo4; tab-stops: list .5in; text-indent: -.25in;"><span style="font-family: Symbol; font-size: 14pt;">·<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 14pt;">We have just seen&nbsp; </span><tt><b><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">CopyOnWriteArrayList</span></b></tt><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;"> is</span></tt><span style="font-size: 14pt;"> a replacement for synchronized </span><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">List</span></tt><span style="font-size: 14pt;"> implementations for cases where traversal is the dominant operation.<o:p></o:p></span></div><div class="doctext" style="margin-bottom: 6.0pt; margin-left: .5in; margin-right: 0in; margin-top: 0in; mso-list: l3 level1 lfo4; tab-stops: list .5in; text-indent: -.25in;"><span style="font-family: Symbol; font-size: 14pt;">·<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">ConcurrentMap</span></tt><span style="font-size: 14pt;"> interface adds support for common compound actions such as put-if-absent, replace, and conditional remove.<o:p></o:p></span></div><div class="doctext" style="margin-bottom: 6.0pt; margin-left: .5in; margin-right: 0in; margin-top: 0in; mso-list: l3 level1 lfo4; tab-stops: list .5in; text-indent: -.25in;"><tt><span style="font-family: Symbol; font-size: 14pt;">·<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></tt><tt><b><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">ConcurrentLinkedQueue</span></b></tt><span style="font-size: 14pt;">, a <a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle1461"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle1490"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle1491"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle1493"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle1494"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle1558"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle1937"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle2879"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle2880"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle2887"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle2990"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle3005"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle3044"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle3045"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle3046"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle3047"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle3048"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle3075"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle3116"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle3117"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle3144"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle3153"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle3552"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle3665"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle4062"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle4134"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle4218"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle4219"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle4220"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle4221"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle4331"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle4332"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle4333"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle4334"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle4474"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle4475"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle4502"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle4969"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle4970"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle4971"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle4972"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle5152"></a>traditional FIFO queue, and </span><tt><b><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">PriorityQueue</span></b></tt><span style="font-size: 14pt;">, a (non concurrent) priority ordered queue. </span><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">Queue</span></tt><span style="font-size: 14pt;"> operations do not block; if the queue is empty, the retrieval operation returns </span><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">null</span></tt><span style="font-size: 14pt;">. While you can simulate the behavior of a </span><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">Queue</span></tt><span style="font-size: 14pt;"> with a </span><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">List </span></tt><span style="font-size: 14pt;">in fact, </span><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">LinkedList</span></tt><span style="font-size: 14pt;"> also implements </span><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">Queue.<o:p></o:p></span></tt></div><div class="doctext" style="margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 14.0pt; mso-list: l3 level1 lfo4; tab-stops: list .5in; text-indent: -.25in;"><span lang="RU" style="font-family: Symbol; font-size: 14pt;">·<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 14pt;">I</span><span lang="RU" style="font-size: 14pt;">f we use a <span class="docemphasis">bounded </span></span><span class="docemphasis"><span style="font-size: 14pt;">blocking</span></span><span class="docemphasis"><span lang="RU" style="font-size: 14pt;"> queue</span></span><span lang="RU" style="font-size: 14pt;">, then when the queue fills up the producers block, giving the consumers time to catch up because a blocked producer cannot generate more work<o:p></o:p></span></div><div class="doctext" style="margin-bottom: 14.0pt; margin-left: .5in; margin-right: 0in; margin-top: 0in; mso-list: l4 level1 lfo5; tab-stops: list .5in; text-indent: -.25in;"><tt><span style="font-family: Symbol; font-size: 14pt;">·<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></tt><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">Blocking queues also provide an offer method, which returns a failure status if the item cannot be enqueued. This enables you to create more flexible policies for dealing with overload, such as shedding load, serializing excess work items and writing them to disk, reducing the number of producer threads.<o:p></o:p></span></tt></div><div class="doctext" style="margin-bottom: 6.0pt; margin-left: .5in; margin-right: 0in; margin-top: 0in; mso-list: l4 level1 lfo5; tab-stops: list .5in; text-indent: -.25in;"><tt><span style="font-family: Symbol; font-size: 14pt;">·<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></tt><tt><b><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">LinkedBlockingQueue</span></b></tt><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;"> and <b>ArrayBlockingQueue</b> are FIFO queues, analogous to LinkedList and ArrayList but with better concurrent performance than a synchronized List.<o:p></o:p></span></tt></div><div class="MsoNormal" style="margin-bottom: 6.0pt; margin-left: .5in; margin-right: 0in; margin-top: 0in; mso-list: l4 level1 lfo5; tab-stops: list .5in; text-indent: -.25in;"><tt><span style="font-family: Symbol; font-size: 14pt;">·<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></tt><tt><b><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">PriorityBlockingQueue</span></b></tt><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;"> is a priority-ordered queue, which is useful when you want to process elements in an order other than FIFO. Just like other sorted collections, PriorityBlockingQueue can compare elements according to their natural order (if they implement Comparable) or using a Comparator.<o:p></o:p></span></tt></div><div class="doctext" style="margin-bottom: 6.0pt; margin-left: .5in; margin-right: 0in; margin-top: 0in; mso-list: l4 level1 lfo5; tab-stops: list .5in; text-indent: -.25in;"><tt><span style="font-family: Symbol; font-size: 14pt;">·<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></tt><tt><b><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">ConcurrentHashMap</span></b></tt><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;"> implements a scalable locking strategy. <o:p></o:p></span></tt></div><div class="doctext" style="margin-bottom: 6.0pt; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">Instead of synchronizing every method on a common lock, restricting access to a single thread at a time, it uses a finer-grained locking mechanism called </span></tt><span class="docemphasis"><span style="font-size: 14pt;">lock striping</span></span><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;"> to allow a greater degree of shared access. Arbitrarily many reading threads can access the map concurrently, readers can access the map concurrently with writers, and a limited number of writers can modify the map concurrently.<o:p></o:p></span></tt></div><div class="doctext" style="margin-bottom: 6.0pt; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">It also provides iterators that do not throw ConcurrentModificationException, thus eliminating the need to lock the collection during iteration. The iterators returned by ConcurrentHashMap are </span></tt><span class="docemphasis"><span style="font-size: 14pt;">weakly consistent</span></span><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;"> instead of fail-fast.<o:p></o:p></span></tt></div><div class="MsoNormal" style="margin-bottom: 6.0pt; margin-left: .5in; margin-right: 0in; margin-top: 0in; mso-list: l5 level1 lfo6; tab-stops: list .5in; text-indent: -.25in;"><tt><span style="font-family: Symbol; font-size: 14pt;">·<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></tt><tt><b><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">ConcurrentSkipListMap</span></b></tt><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;"> and <b>ConcurrentSkipListSet</b> are concurrent replacements for a synchronized SortedMap or SortedSet (such as treeMap or TreeSet wrapped with synchronizedMap).<o:p></o:p></span></tt></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><b><span style="font-size: 14pt;">16. Document ThreadSafety<o:p></o:p></span></b></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><span style="font-size: 14pt;">@ThreadSafe public class Account {<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><span style="font-size: 14pt;">&nbsp; @GuardedBy("this") private int balance;<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><span style="font-size: 14pt;">.....<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><span style="font-size: 14pt;">}<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><b><span style="font-size: 14pt;">17.&nbsp; Abide by the practice of deep cloning for ensuring thread-safe immutability<o:p></o:p></span></b></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><span style="font-size: 14pt;">Inside immutable Implementation class / Array , always deep clone inner collections.<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><span style="font-size: 14pt;">Jdk 7 comes handy with Array deepEquals<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><b><span style="font-size: 14pt;">18 . Isolate concurrency in concurrent components such as blocking queues<o:p></o:p></span></b></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><b><span style="font-size: 14pt;">19. Task Completion Notifications<o:p></o:p></span></b></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><b><span style="font-size: 14pt;">&gt;&gt; </span></b><span style="font-size: 14pt;">Use ExecutorCompletionService and customized BlockingQueue. ECS will place the completed tasks in queue so that one can poll with timeout. <o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><span style="font-size: 14pt;">&gt;&gt; Otherwise executorService.invokeAny(allCallables, timeOut) – is very handy for a quick survey of completion status !<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><b><span style="font-size: 14pt;">References :<o:p></o:p></span></b></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><b><span style="font-size: 14pt;">Merge Sort using Concurrency :<o:p></o:p></span></b></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><span lang="RU"><a href="http://www.ibm.com/developerworks/java/library/j-jtp03048.html">http://www.ibm.com/developerworks/java/library/j-jtp03048.html</a></span><b><span style="font-size: 14pt;"> <o:p></o:p></span></b></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><b><span style="font-size: 14pt;">A popular framework<o:p></o:p></span></b></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><span lang="RU"><a href="http://hawtdispatch.fusesource.org/#Overview">http://hawtdispatch.fusesource.org/#Overview</a></span><b><span style="font-size: 14pt;"> <o:p></o:p></span></b></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><b><span style="font-size: 14pt;">A great comparison and discussion<o:p></o:p></span></b></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><span lang="RU"><a href="http://tech.puredanger.com/2011/01/14/comparing-concurrent-frameworks/">http://tech.puredanger.com/2011/01/14/comparing-concurrent-frameworks/</a></span><b><span style="font-size: 14pt;"> <o:p></o:p></span></b></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><b><span style="font-size: 14pt;">Quoting the concise list of concurrency choices from the above link :<o:p></o:p></span></b></div><div class="MsoNormal" style="margin-bottom: 6.0pt; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><b><span style="font-size: 14pt;">“&nbsp; </span></b><strong><span style="font-weight: normal;">Executors</span></strong><strong> (java.util.concurrent)</strong>&nbsp;– put your computations in Runnables or Callables and submit them to an ExecutorService that is backed by a thread pool. Express dependencies by using Futures or other techniques. Two problems here – first, executors generally assume that there is 1 queue and many threads which introduces the queue contention problem mentioned above. Also, it has no way for the work to be scheduled with knowledge of dependencies. It is possible to build that over the top of course, but it’s a lot of work orthogonal to your problem at hand. The queue+threads model can’t scale as is.<o:p></o:p></div><div class="MsoBodyText" style="line-height: 15.0pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 47.25pt; margin-right: 0in; margin-top: 0in; mso-list: l6 level1 lfo7; tab-stops: 0in list .5in; text-indent: -14.15pt;"><span lang="RU" style="font-family: Symbol;">·<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><strong><span lang="RU" style="font-weight: normal;">Fork/join</span></strong><span lang="RU">&nbsp;– create your computations as RecursiveTasks or RecursiveActions and submit them to a ForkJoinPool that is backed by a thread pool. Express dependencies directly using the RecursiveTask apis for fork, join, invoke, etc. Fork/join addresses both of the concerns I mention above. Instead of a single work queue, there is one work queue per thread. This means that at the head of the queue there is no contention – there is only 1 thread reading from it. Fork/join also addresses the dependency concern because it knows that one task is waiting for another to complete – the work/stealing algorithm inherently leverages these dependencies. I would urge you to watch&nbsp;<a href="http://medianetwork.oracle.com/media/show/15507">Doug Lea’s talk</a>&nbsp;from the JVM Language Summit 2010.<o:p></o:p></span></div><div class="MsoBodyText" style="line-height: 15.0pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 47.25pt; margin-right: 0in; margin-top: 0in; mso-list: l7 level1 lfo8; tab-stops: 0in list .5in; text-indent: -14.15pt;"><span lang="RU" style="font-family: Symbol;">·<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><strong><span lang="RU" style="font-weight: normal;">Actors</span></strong><b><span lang="RU">&nbsp;</span></b><span lang="RU">– express your computations as the run loop of an actor. Communicate between actors with messages – this makes the dependencies asynchronous AND somewhat invisible to whomever is scheduling actor invocations except by the arrival of messages in a mailbox. Every actor has a mailbox which effectively means there is one queue per-actor, which lets you decide in your problem how finely to cut it up. Something has to actually schedule the computations of the actors though – note that Scala actors are backed by … a fork/join pool. It seems to me that the actor model obscures the dependency information from fork/join – there is nothing captured at the underlying level when an actor has sent a message to another and is waiting for a response. That’s implicitly captured by having a message in one mailbox and nothing in the waiting actor, but it seems impossible to convey the higher-level dependency structure to the underlying scheduler.<o:p></o:p></span></div><div class="MsoBodyText" style="line-height: 15.0pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 47.25pt; margin-right: 0in; margin-top: 0in; mso-list: l8 level1 lfo9; tab-stops: 0in list .5in; text-indent: -14.15pt;"><span lang="RU" style="font-family: Symbol;">·<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><strong><span lang="RU" style="font-weight: normal;">Continuations</span></strong><b><span lang="RU">&nbsp;</span></b><span lang="RU">– to me, continuations are (at a high level) pretty similar to actors. They have the benefit that can presumably be paused from outside the computation, so an external scheduler might be able to timeslice work in and out in some better way, but it seems like there is a lot of machinery there that adds overhead.<o:p></o:p></span></div><div class="MsoBodyText" style="line-height: 15.0pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 47.25pt; margin-right: 0in; margin-top: 0in; mso-list: l9 level1 lfo10; tab-stops: 0in list .5in; text-indent: -14.15pt;"><span lang="RU" style="font-family: Symbol;">·<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><strong><span lang="RU" style="font-weight: normal;">Data flow</span></strong><span lang="RU">&nbsp;– data flow is a very intriguing model because it lets you explicitly model the data dependencies between tasks. GPars probably has the most interesting implementation of it that I know of. There are a few other variants written for Clojure (that relies on the underlying agent framework) and Scala (that relies on the underlying actor infrastructure). Because those rely on underlying frameworks, I’m pretty sure they don’t optimally leverage the dependency information inherent in data flow tasks. I’d love to see a framework that was optimized to leverage that dependency info though.<o:p></o:p></span></div><div class="MsoBodyText" style="line-height: 15.0pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 47.25pt; margin-right: 0in; margin-top: 0in; mso-list: l10 level1 lfo11; tab-stops: 0in list .5in; text-indent: -14.15pt;"><span style="font-family: Symbol;">·<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><strong><span lang="RU" style="font-weight: normal;">Clojure</span></strong><b><span lang="RU">&nbsp;</span></b><span lang="RU">– Clojure actually has a bunch of different things that work in concert so it’s hard for me to describe it as any one model. Most state is immutable and persistent via structural sharing. When you want to mutate state, there are a variety of features (refs, atoms, agents) that let you choose whether state changes should happen synchronously or asynchronously, and whether they should or should not be coordinated with others. Clojure has STM which allows you to synchronize multiple state changes in a well-ordered way. MVCC lets you see a consistent view during the change (again leveraging the persistent data structures) and transactions are retried in the case of conflict. Reads are always available, again due to the data structures. Clojure agents are backed ultimately by an executor pool (one that is internal and you have no control over). There is work ongoing in Clojure to create a set of functions over sequences (filter, map, etc) that is backed by parallel execution against a fork/join pool and I think that shows great promise to provide easy benefits for a different kind of problem (where you are working with large chunks of data). </span><b>… “<o:p></o:p></b></div></tt></pre></div>http://musings-on-technology.blogspot.com/2011/04/learning-from-jdk-source-and-language.htmlnoreply@blogger.com (Kaniska)0tag:blogger.com,1999:blog-1373851816248476399.post-4536973185898044278Tue, 19 Apr 2011 04:43:00 +00002011-04-19T10:13:43.955+05:30HTML5Road to Openness<div dir="ltr" style="text-align: left;" trbidi="on"><br /> <div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Chorme and Droids opening up the floodgate of amazing possibilities that will capture the imagination of the Netizens !<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Welcome to a new World<span style="mso-spacerun: yes;">&nbsp; </span>free from 'Desktop Vendor Lock-In' and 'Internet Monopoly' !<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">I can't help echoe the following excerpt from Google IO ...<span style="mso-spacerun: yes;">&nbsp;&nbsp; </span>"<b>No longer a nightmare of a draconian future .. of a single vendor single product .. a future without choice ! </b>"<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">A new Revolution had already begun when Web started being treated as Platofrm by Facebook, Zoho , Netflix, Google, LinkedIn, SaleForce, Tumblr, Jigsaw, Scribd and many more who joinined the forces in recent time ! <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">And now today Browsers empowerd with HTML5 are helping Web apps become as powerful as Desktop applications ! <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Essentially its a giant leap forward by Google and likeminded benedictors towards the efforts of<span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>creating powerful Browsers to free the Earth from the bondage of Desktop OS !<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Thanks to HTML5 <b>Server Sent messages</b> for performing this magic of representing Rich Media / High-Perfornace Graphics / Desktop Content / Complex Netwroking / Offline storage etc.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">HTML5 - <b>Web GL</b> is the technology behind rendering GPS on mobile and computer browsers.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Internet at a growth rate of 120% .. has definitely outperformed and outpaced other networking mediums<span style="mso-spacerun: yes;">&nbsp; </span>- tv/radio/magazine/newspaper. <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">HTML5- <b>Workers</b> allow web apps to access and leverage the power of multi-core CPUs boosting the Rich-UI experience to a great extent. <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">As per the Google Prediction, by the end of 2010, the HTML 5 features like -<span style="mso-spacerun: yes;">&nbsp; </span><b>Web Video</b> / Canvas / SVG / <b>AppCache</b> / <b>Web Storage</b> / <b>Web Sockets</b> / <b>Geo Locations </b>..<span style="mso-spacerun: yes;">&nbsp; </span>will be supported<span style="mso-spacerun: yes;">&nbsp; </span>by<span style="mso-spacerun: yes;">&nbsp; </span>all major browsers (<b>Opera</b>, <b>Chrome</b>, <b>Safary</b>, <b>FireFox</b>) .. except ... guess what !.. Yes ..<span style="mso-spacerun: yes;">&nbsp; </span><b>IE</b> .. which will support <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><span style="mso-spacerun: yes;">&nbsp;</span>only Video / SVG and Web Storage<span style="mso-spacerun: yes;">&nbsp; </span>falling behind all other 4 browsers !!<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">So there will be a surge in statrt-ups and new initiatives for developing innovative products on these open standrds !<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Say, DarkRoom (from MugTug)<span style="mso-spacerun: yes;">&nbsp; </span>allows editing photos and applying amzing affects Online .. and pretty fast ! It makes best of 'AppCache' for creating GUI on Web. Even browsers will support creating GUI using local storage in offline mode and then simply synching up once user goes online. <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">So no need to install a 'Photo Editor' on desktop, then download photos locally, apply effect and upload on web and sync back n forth !!<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Great Huh !<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Gmail and many other mail clients had adopted the HTML 5<span style="mso-spacerun: yes;">&nbsp; </span><b>File API</b> and <b>Notification API</b> for<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><span style="mso-spacerun: yes;">&nbsp;</span>Drag-n-Drop of any attachment on the mail. <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">The beauty is - if the proper chrome extension is installed, then while surfing net, users will automcatically get notifcation about gmails even without leaving current page and without starting local mail client!<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Clicker.TV is a great implementor of 'Worker' for pulling a huge amount of TV and Media live streaming and then caching. Its a<span style="mso-spacerun: yes;">&nbsp; </span>huge leap forward !<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><b><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Open Video Codec</span></b><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"> (VP8) offering super quality video streaming through Chrome and Youtube<span style="mso-spacerun: yes;">&nbsp; </span>by taking advanges of multiple cores<span style="mso-spacerun: yes;">&nbsp; </span>and open standrds of DSP.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Google TV will certainly revolutinize the concpet of 'Telecast over Net'<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">How about <b>Animation using CSS</b> <b>and Javascript</b> using html5.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Tooling around CSS and fast network roundtrips (all HTML5 blessings) will open up new possibilities in the Multi-player Online Gaming World !<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Imgaine running any 3d Game written using native Client into the browser !<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><b><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Mashing Up service and online apps</span></b><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"> will also become easier.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">TwitDeck is a great example.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Here one can move the twit widgets and instanly comes to know from where 'certain apps' are coming from. <b>Twit notifications</b> are constantly monitord and pushed from server and corresponding<span style="mso-spacerun: yes;">&nbsp; </span><b>Geo Locations</b> are queried upon to present all the relevant information to the users.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">The big question is once a <b>Magazine is actually represneted as a Magazine</b> in a browser and not as a mere Webpage , then do we really need to invest in iPad or Kindle !<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><b><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Thats the power of openness ! <o:p></o:p></span></b></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Thats what<span style="mso-spacerun: yes;">&nbsp; </span>Chrome is about to do .. just stay tuned to Google Technologies ....<span style="mso-spacerun: yes;">&nbsp; </span>its going to Recrate the same Immersive Experience that you enjoy while reading a newspaper or magazine !<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Imagine how dramatically it will increase the reachability of popular media brands and skyrocket its revenue !<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">HTML 5 will simply metamorphize business models !<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Now there is great gift from Google for the Apps Developers !<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Using HTML 5 google provides <b>Infrasturces as Services on demand and Virtualize existing complex apps</b> through its collboration with VMWare Cloud and SpringSource.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Few commands in Spring Roo Shell will – create a Spring Project, do the Persistence Setup, Create Entities, Services, provide GWT artifcats, package, update GWT .. in couple of minutes (for a small demo app) and Google App Engine Plugins (assuming user installed SpringSource tool Suite)<span style="mso-spacerun: yes;">&nbsp;&nbsp; </span>upload the app in cloud .. also immediately use Spring Insights and Cloud Monitors to provide performance stats !<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Lets all enjoy the freedom of choice and openness offered by HTML5.<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 10.0pt;"><br /> </div></div>http://musings-on-technology.blogspot.com/2011/04/road-to-openness.htmlnoreply@blogger.com (Kaniska)0tag:blogger.com,1999:blog-1373851816248476399.post-2273600851393847839Tue, 19 Apr 2011 04:42:00 +00002011-04-19T10:12:34.158+05:30ArchitectureScalabilityBest Practices of Enterprise System Architecture<div dir="ltr" style="text-align: left;" trbidi="on"><br /> <div class="Standard"><span lang="DE" style="color: maroon; font-size: 24.0pt;">An Enterprise System should be Highly Scalable, Always Available, Easily Manageable, Fast Performer, Auto-Healer and Capable of Super Fast Searching and Intelligent Analysis through Machine Learning.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><br /> </div><div class="Standard"><b><span lang="DE" style="font-size: 14.0pt;">Scalability</span></b><span lang="DE"> means the system does not downgrade even when load increases multiple times.<o:p></o:p></span></div><div class="Standard"><span lang="DE">For example, when number of users of an ecommerce system increases heavily further leading to sudden increase in transactions per user, the system should still keep performing with same SLA and handle the traffic smoothly ensuring that business is not down.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">One of the design choice for large-scale system is to <b>scale out horizontally</b>. Create one DB per Entity (User/ Item/ Product) and store only Key-Value in that table. Replicate the DB in various machines and implement a scheme for data-sharding.<o:p></o:p></span></div><div class="Standard"><span lang="DE">For example, in the Modulo(Entity_Pky, 100) approch, User Bob with id 1000 will be located in machine #10 . So if number of users increases suddenly, new User DB will be created in new machine and the new user info will be inserted automatically.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">There are other data-sharding policies like <b>Range-based partitions</b>, <b>Lookup based approach</b>, <b>Read-Most-Write-Least Model</b>.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><b><span lang="DE">SimpleDB</span></b><span lang="DE"> can be effectively used to manage lookup-orieneted entity info.<o:p></o:p></span></div><div class="Standard"><span lang="DE">This is an out-of-the-box offering from Amazon AWS as a hosted and managed solution administered by Amazon itself. SimpleDB does the heavy-lifting of multi-value data fetching for a key, batch operations, consistent reads.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Its better to delegate the tradional 'data management operations' like 'Relations, Transactions, Locks, Sequences, Constraints' to Application Layer as SimpleDB is meant for handling simple things !!<span style="mso-spacerun: yes;">&nbsp;&nbsp; </span>Such a typical example is eBay DAL layer.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Actually the System Architect should choose the Entities which are meant for mere lookup (like User, Item, Manufacturer, Order) and mark them as best candidates for SimpleDB items. Those entities will be then guarnteed to be highly available. Off course this pattern is not suitable for financial transactions in banking domain and rule-based complex events where every fetch query triggers<span style="mso-spacerun: yes;">&nbsp;&nbsp; </span>sub-query-based rules or procedures.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Discussing further details on implementing SimpleDB is out-of-scope here.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">If we want to handle complex business transactions while updating Entity Info and manage intricate relatiuonships then we should take resort to Cassandra or mongoDB.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">But we should remember that one needs to take care of Scalability in Application layer while adopting NoSQL Dbs.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">&nbsp;If the data are hierarchical in nature - we can leverage a Graph Database (MonogoDB) which is as opposed to conventional sql-db is a de-normalized graph processor.</span><span lang="DE"><o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><b><span lang="DE" style="font-size: 14.0pt;">Availability</span></b><span lang="DE"> : Load-balancing and Clustering are standard practices for making applications available. Normally DNS Resolver routes to a pool of servers for a requested application and Load-balancer picks up one server.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Machines should be load-balanced in such a way the moving the user from one machine to another machine can be achieved easily without shutting down the system.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><b><span lang="DE" style="font-size: 14.0pt;">Fast Searching :<o:p></o:p></span></b></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">NoSql is a must for fast lookup of trillions of<span style="mso-spacerun: yes;">&nbsp; </span>Business Entity data and persisting time-critical entities by locking data storage row for a<span style="mso-spacerun: yes;">&nbsp; </span>negligible amount of time (contrary to traditional RDBMS), yet be able to write-through / broadcast write events to sub0system grids (Search Grid / Analytics Machine / Events Collector etc.)<o:p></o:p></span></div><div class="Standard"><span lang="DE">Cassandra does a very neat job for that matter.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">"The sparse two-dimensional “super-column family” architecture allows for rich data model representations (and better performance) beyond just a simple key-value look up.....<o:p></o:p></span></div><div class="Standard"><span lang="DE">Some of the most attractive features of Cassandra are its uniquely flexible consistency and replication models. Applications can determine at call level what consistency level to use for reads and writes (single, quorum or all replicas). This, combined with customizable replication factor, and special support to determine which cluster nodes to designate as replicas, makes it particularly well suited for cross-datacenter and cross-regional deployments. In effect, a single global Cassandra cluster can simultaneously service applications and asynchronously replicate data across multiple geographic locations...."<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Its worth paying for the learning curve and operational compexities in exchange of the 'scalability, availability and performance advantages of the NoSQL persistence model'....<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">In traditional DB, what happens if one of the node containing one of the table in a join condition is down !<o:p></o:p></span></div><div class="Standard"><span lang="DE">Simple - now the whole application that depends on that join condition is unavailable !<o:p></o:p></span></div><div class="Standard"><span lang="DE">Well there is no join condition in NoSql !! Cassandra is best for cross-regional deployments and scaling with no single points of failure.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Next question – does the NoSql gurantees data-consistency the same way Relational DB vouches for read-after-write consistency at the cost of Blocking the read untill Transaction is finished !<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Well NoSql follows CAP theorem not ACID principle !<o:p></o:p></span></div><div class="Standard"><span lang="DE">So if you think 'immediate consistency' need to be ensured for super-critical tasks like Bidding / Buying, better await till data committed before reading the latest data !<span style="mso-spacerun: yes;">&nbsp; </span>In certain cases of 'Eventual Consistency' like searching data where we expect fast response we may not await for latest data to availble but rather instantly display the pre-computed search result !!<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Also there is no concurrency bottlenecks ! Replicas are mostly Multi-master Highly Available !<o:p></o:p></span></div><div class="Standard"><span lang="DE">NoSql ensures Asynchronous Lock-based Reconciliation as opposed to Synchronous Lock-based Reconciliation bby SQL.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">This means more work but saving time !! Using Message -Multicast do write-behind to replicated database / grid without taouching master db. Then synchronize with master DB after a specific time period. This saves lot of time spent in Index Arrangement and Sequential Updation.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Say you want to search – 'Blue Sony mp3 player' ! NoSql will hold the lock for a row only for couple of milliseconds as opposed to locking the entire table by RDBMS ! NoSql will just lookup the id of next entity (manufatures) against the id of the main entity (product) and move the mesage to the next table !! At the same time, it looks up the product requested by the next user !!<span style="mso-spacerun: yes;">&nbsp; </span>No Joins , Just Intelligent Routing !!<span style="mso-spacerun: yes;">&nbsp; </span>Handling millions of requests concurrently has never looked so esy before !!!<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Which is for What ?<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Memcahed : Static Key-Value Pair<o:p></o:p></span></div><div class="Standard"><span lang="DE">Neo4j<span style="mso-spacerun: yes;">&nbsp; </span>: Network Graph Store<o:p></o:p></span></div><div class="Standard"><span lang="DE">Hbase<span style="mso-spacerun: yes;">&nbsp; </span>: Row-Orieneted Sparse Column Store<o:p></o:p></span></div><div class="Standard"><span lang="DE">MongoDB : (Key, Document) Storage.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Great Document : <a href="http://highscalability.com/blog/2011/2/15/wordnik-10-million-api-requests-a-day-on-mongodb-and-scala.html"><span style="color: windowtext; text-decoration: none; text-underline: none;">http://highscalability.com/blog/2011/2/15/wordnik-10-million-api-requests-a-day-on-mongodb-and-scala.html</span></a><o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><b><span lang="DE" style="font-size: 14.0pt;">Fast Data Analysis<o:p></o:p></span></b></div><div class="Standard"><br /> </div><div class="Standard"><b><span lang="DE">Apache Hbase </span></b><span lang="DE">– best suited for Data Analytics, Data Mining, Enterprise Search and other Data Query Services.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">If the main business is to mine PeraBytes of data and perform parallel range-queries and then combine the results through batch Map-Reduce (say Enterprise Search for Video Content), then one<span style="mso-spacerun: yes;">&nbsp; </span>of the defacto choice is Apache Hbase configured with haddop Jobs, using HDFS as a shared storage platform. Hbase comes with availability trade-off i.e. the persistent domain entities may not immediately available in the Search Result. The reason for this is huge Hadoop Map-Reduce jobs are performed parallely in offline mode so that main source of data is not hogged by Hadoop Jobs and is highly Scalable.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">It should be noted that Hadoop is not meant for searching in real-time. Its actually an offline batch-processing system well-suited for BI analytics, data aggregation, normalization in parallel.<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">Hadoop provides a framework which will automatically take care of interProcess co-ordination, distributed counters, failure detection, automatic restart of failed process, co-ordinated, sorting and much more.<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">There is different stages like mapper, combiner, partitions, reducer etc, instead of we writing from the scratch, the framework takes care of it.<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">Erlang / Scala also provide out-of-the box parallel processing.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Its important to know that there are different tools based on hadoop that serve different purposes :<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Hive : SQL query for MR<o:p></o:p></span></div><div class="Standard"><span lang="DE">Pig : Scripting for MR<o:p></o:p></span></div><div class="Standard"><span lang="DE">HBase : Low-latency, Big Table like database on hadoop<o:p></o:p></span></div><div class="Standard"><span lang="DE">Oozie : Workflo Mgmt on Hadoop<o:p></o:p></span></div><div class="Standard"><span lang="DE">Sqoop - RDBMS import / export<o:p></o:p></span></div><div class="Standard"><span lang="DE">Zookeeper : Fast, distributed, coordination system<o:p></o:p></span></div><div class="Standard"><span lang="DE">Hue : advanced web env. for Hadoop and custom applications<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Here come the ultimate offering from Spring - <a href="http://www.springsource.org/spring-data"><span style="color: windowtext; text-decoration: none; text-underline: none;">http://www.springsource.org/spring-data</span></a><o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Apache has a solution for combining lucene with hadoop for blazing-fast document search.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><b><span lang="DE" style="font-size: 14.0pt;">Fast Cache :<o:p></o:p></span></b></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Implementing a cold cache with minimum memory footprint (MySQL native memory, Memcached, Terracota Ehcahce) is absolutely important.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Application Server should not remeber the state of the Entity rather should just persist in DB. The metadata should be stored in Cold Cache.<span style="mso-spacerun: yes;">&nbsp; </span>The persistent pojo objects should never be cached in memory.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">If queries are mostly read-only, very less updates - the mySQL native memory scores high ! MySQL InnoDB storage engine’s dictionary cache provides blazing fast data acceess. On demand, data blocks are read from disk and stored in memory using LRU chains or other advanced mechanisms(like MySQL’s Midpoint Insertion Strategy) .</span><span lang="DE"><o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">In order to lookup the value for a key, Memcached clients issue multiple parallel requests to memcached servers where keys are sharded across those servers.<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">For a frequently changing data set , Memcahed is surely better than DB Cache<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE">Probably the fastes cache on planet is -<span style="color: black;"> is Ehcache using Terracotta BigMemory </span><a href="http://blog.terracottatech.com/2010/09/bigmemory_explained_a_bit.html"><span style="color: windowtext; text-decoration: none; text-underline: none;">http://blog.terracottatech.com/2010/09/bigmemory_explained_a_bit.html</span></a><o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">Here directly the native byte-buffer of the OS is used bypassing main-memory.<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">A write-optimized data store. Something that aggregates the writes in RAM, and writes out generational updates. Take a look at Google's BigTable paper for a good description of this strategy.</span><span lang="DE"><o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">A very good reference : </span><b style="mso-bidi-font-weight: normal;"><span lang="DE" style="color: black; font-size: 9.5pt; mso-bidi-font-size: 12.0pt;">http://research.yahoo.com/files/sigmod278-silberstein.pdf</span></b><span lang="DE"><o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><br /> </div><div class="Standard"><br /> </div><div class="Standard"><b><span lang="DE" style="font-size: 14.0pt;">Everything Asynchronous<o:p></o:p></span></b></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">All communications in every layer should be asynchronous to reduce the latency.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">There are 2 types of latency.<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">1. <b>user latency</b> - how fast user gets back the control on web site<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">2. <b>execution latency</b> - how fast the execution takes place in backend<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">UI behavior should be completely Ajax and send the main events to queue and schedule for batch updates in offline mode. There is absoulutely no room for a wait_state i.e. all response should be immediate and non-blocking.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Common Flow :<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">-- Submit a job/task to a thread and return to the user immediately.<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">-- The thread should perform the operation in background (it may communicate to LRU cache optimized for concurrent access / Graph Structure / Iry-IIry master-slave replicatioed env / Map-Reduce based sturctures)<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">-- Once done with the opertaion it should return the result thru a CallbackHandler and client will get notification.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">There are multiple patterns for Asynchronous Communications.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">(1) Store all jobs in Event Queue. Select a queue based on a contract/ algo depending on type of task. Then use multiple event brokers/ listeners to handle the jobs from queue (thrid party ESB like Tibco / apache fuse/ apache camel / ...) can be used.<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">(2) Message Multicast - say user enters a new item in system. do not update the iry db immediately. rather send messages to pollers / searchers - that there is a 'New' event. Return to user immedialtely. Now the updater thread will update Iry db. Then searcher will behind the scene query Iry db / data source to find what has been just added and it will add it to its search grid !<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">(3) Batch Processing (schedule offline procesing). Identify which type of job requests can be scheduled for offline processing and do not need immediate attention !<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><br /> </div><div class="Standard"><b><span lang="DE" style="font-size: 14.0pt;">Prallel Threading<o:p></o:p></span></b></div><div class="Standard"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">Use Executor Service to effectively manage pool of threads -&nbsp;<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;"><span style="mso-spacerun: yes;">&nbsp;</span>Remember &nbsp;a simple set of worker threads 'without the manager' - can simply lead to&nbsp;<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;"><span style="mso-spacerun: yes;">&nbsp;</span>(i) Resource Thrashing (each thread is expensive - execution call stack / context switching)<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;"><span style="mso-spacerun: yes;">&nbsp;</span>(ii) Request Overload .. &nbsp;if all requests are provided threads for execution<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;"><span style="mso-spacerun: yes;">&nbsp;</span>(iii) Thread Leakage : sive of threadpool diminishes due to uncaught errors but requests are not served !<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">So there should be a proper manager to allocate threads either FixedThreadPool / ScheduledThreadPool / SingleThreadPool / QueuedThreadPool with proper RejectionPolicy.<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">This manager should also place the completed result in a non-blocking queue from where result can be taken off asynchrounously.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">Thread should not wait to acquire locks - leverage advanced processor optimizations to use LATCH concept to lock/unlock threads at the same time. Locks should be acquired / released in any order.<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">Fork/Join and CountDownLatch are powerful concepts for running threads parallely.<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">You can download and try out the open-source Thrift which is a C++ Fwk for multi-threading and asynchronous processing of job<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><br /> </div><div class="Standard"><b><span lang="DE" style="font-size: 14.0pt;">Auto-Healing and Self-Recovery :<o:p></o:p></span></b></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Systems should be falut-tolernt and should know how to degrade gracefully in the scenario of unprecented load.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">The JMX agents and other Robot Apps should continously monitor the system and gather intelligence to take the best desicion.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">A high-degree of automation is requireed for easily recovering from failures and managing the system smoothly.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Normally automation is driven though Centrallized Logging System and Self-organization Artificial Intelligence. BI tools are used to analyze user experience and provide Best Match through continous inhouse experimentations.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Scalable systems are mangeable if new partitions can be added, DB instance can be horizantally scaled out and new application servers turned on without affecting users of the system.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><b style="mso-bidi-font-weight: normal;"><span lang="DE" style="color: maroon;">Case Study :<o:p></o:p></span></b></div><div class="Standard" style="mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><b style="mso-bidi-font-weight: normal;"><span lang="DE" style="color: maroon;"><span style="mso-spacerun: yes;">&nbsp;</span>Twitter :<o:p></o:p></span></b></div><div class="Standard" style="mso-pagination: widow-orphan;"><b style="mso-bidi-font-weight: normal;"><span lang="DE" style="color: maroon;">1. </span></b><span lang="DE" style="color: maroon;"><a href="http://www.slideshare.net/kevinweil/nosql-at-twitter-nosql-eu-2010"><b style="mso-bidi-font-weight: normal;"><span style="color: maroon; text-decoration: none; text-underline: none;">http://www.slideshare.net/kevinweil/nosql-at-twitter-nosql-eu-2010</span></b></a><o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: maroon;"><a href="http://www.slideshare.net/kevinweil/hadoop-at-twitter-hadoop-summit-2010"></a><o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><b style="mso-bidi-font-weight: normal;"><span lang="DE" style="color: maroon;">2. </span></b><span lang="DE" style="color: maroon;"><a href="http://www.slideshare.net/kevinweil/hadoop-at-twitter-hadoop-summit-2010"><b style="mso-bidi-font-weight: normal;"><span style="color: maroon; text-decoration: none; text-underline: none;">http://www.slideshare.net/kevinweil/hadoop-at-twitter-hadoop-summit-2010</span></b></a><o:p></o:p></span></div><div class="Standard" style="margin-left: 35.3pt; mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="margin-left: 35.3pt; mso-pagination: widow-orphan;"><b style="mso-bidi-font-weight: normal;"><span lang="DE" style="color: black; font-size: 9.5pt; mso-bidi-font-size: 12.0pt;">Twitter Example :<o:p></o:p></span></b></div><div class="Standard" style="margin-left: 35.3pt; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 9.5pt; mso-bidi-font-size: 12.0pt;">user SAM tweets -<o:p></o:p></span></div><div class="Standard" style="margin-left: 35.3pt; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 9.5pt; mso-bidi-font-size: 12.0pt;">&gt; store tweet &gt; iterate social graph<o:p></o:p></span></div><div class="Standard" style="margin-left: 35.3pt; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 9.5pt; mso-bidi-font-size: 12.0pt;">&gt; split chunks into parallel jobs &gt; prepend packet into its memcahced blob / (some other cache) - if not present in cache - talk to db / hadoop<o:p></o:p></span></div><div class="Standard" style="margin-left: 35.3pt; mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="margin-left: 35.3pt; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 9.5pt; mso-bidi-font-size: 12.0pt;">user RAM who follows SAM - sees sam's tweet -<o:p></o:p></span></div><div class="Standard" style="margin-left: 35.3pt; mso-pagination: widow-orphan;"><b style="mso-bidi-font-weight: normal;"><span lang="DE" style="color: black;">&gt; read mysql blob from memcache (or other cache) &gt; deserialze integers &gt; sort &gt; slice &gt; probablistic truncation (fast but may not be all consistent).<o:p></o:p></span></b></div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: maroon;"><br /> 3. <b style="mso-bidi-font-weight: normal;">SalesForce : </b><a href="http://www.infoq.com/interviews/dave-carroll-salesforce-api"><b style="mso-bidi-font-weight: normal;"><span style="color: maroon; text-decoration: none; text-underline: none;">http://www.infoq.com/interviews/dave-carroll-salesforce-api</span></b></a><b style="mso-bidi-font-weight: normal;"><br style="mso-special-character: line-break;" /> <!--[if !supportLineBreakNewLine]--><br style="mso-special-character: line-break;" /> <!--[endif]--></b><o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: maroon;">4. <b>Facebook</b> :<span style="mso-spacerun: yes;">&nbsp; </span></span><span lang="DE"><a href="http://www.infoq.com/presentations/Scale-at-Facebook"><span style="color: windowtext; text-decoration: none; text-underline: none;">http://www.infoq.com/presentations/Scale-at-Facebook</span></a><span style="color: maroon;">&nbsp;.</span><o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="margin-left: 35.3pt; mso-pagination: widow-orphan;"><b><span lang="DE">Facebook Example :<o:p></o:p></span></b></div><div class="Standard" style="margin-left: 35.3pt; mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="margin-left: 35.3pt; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 9.5pt; mso-bidi-font-size: 12.0pt;">Alex friend of bob - logs in&nbsp;<o:p></o:p></span></div><div class="Standard" style="margin-left: 35.3pt; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 9.5pt; mso-bidi-font-size: 12.0pt;">&gt; Web-tier Calls a C++ based Service (thrift)<br /> &gt; Thrift has the user-id of Bob and calls Aggregator to find all friends ids of Alex<br /> &gt; Aggregator in parallel calls the multi-feed leaves.... &nbsp;(each leaf node is one user for which their is one DB .. one DB .. has a key-value pair (uid, user-data) ... no traditional sql (this is like noSql graph db)<o:p></o:p></span></div><div class="Standard" style="margin-left: 35.3pt; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 9.5pt; mso-bidi-font-size: 12.0pt;">&gt; feed result says &nbsp;[Bob, Sam, Paul] - these &nbsp;are all alexe's friends .... returns those ids &nbsp;(multi-feed) - by calling all DB servers in parallel .. finds the Indexes ..<br /> &gt; Aggregator says ..now got &nbsp;ids of 40 most interesting stories .... &nbsp; It .. ranks them ... based on certain criteria .....<o:p></o:p></span></div><div class="Standard" style="margin-left: 35.3pt; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 9.5pt; mso-bidi-font-size: 12.0pt;">&gt; For each Id, .. get the metadata (timestamp, user name, comment..) from memcached (in ur cache it could be any other cache) - parallel query on multi-core Fedorra<br /> &gt;&nbsp;Now&nbsp;web tier renders the data.<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: maroon;">5. <b>Google</b> : </span><span lang="DE"><a href="http://highscalability.com/google-architecture"><span style="color: windowtext; text-decoration: none; text-underline: none;">http://highscalability.com/google-architecture</span></a><o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: maroon;">6.<b>Flickr</b> :<span style="mso-spacerun: yes;">&nbsp; </span></span><span lang="DE"><a href="http://highscalability.com/flickr-architecture"><span style="color: windowtext; text-decoration: none; text-underline: none;">http://highscalability.com/flickr-architecture</span></a><o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><br /> </div></div>http://musings-on-technology.blogspot.com/2011/04/best-practices-of-enterprise-system.htmlnoreply@blogger.com (Kaniska)0tag:blogger.com,1999:blog-1373851816248476399.post-4667292790317710604Tue, 19 Apr 2011 04:30:00 +00002011-04-19T10:08:44.420+05:30HibernateScalabilityHibernate known facts unknown traps<div dir="ltr" style="text-align: left;" trbidi="on"><b><span lang="RU">Why to use ORM ?</span></b><br /> <div class="MsoNormal" style="margin-left: .5in;"><span lang="RU">(i)&nbsp;&nbsp;&nbsp;HQL offers joins and aggregate functions. HQL expressed using Domain Object properties </span>rather <span lang="RU">than DB Colum</span>ns and completely decoupled<span lang="RU"> from DB Schema.&nbsp; SQL power is leveraged at Domain Object level.<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .5in;"><span lang="RU">(ii)&nbsp;&nbsp;Unlike iBatis, Hibernate abstracts underlying DB and Data Model. <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .5in;"><span lang="RU">(iii)&nbsp;Hibernate performs Change detection – via Snapshot Comparisons . <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .5in;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Hibernate <b style="mso-bidi-font-weight: normal;"><span lang="RU">creates runtime proxies for persistent objects thru dynamic byte code generation </span></b><b style="mso-bidi-font-weight: normal;">using </b><span lang="RU">Javaassist. </span>We can change it to CGLib.<o:p></o:p></div><div class="MsoNormal" style="margin-left: .5in;">(iv) <span lang="RU">Unlike jdo – Hibernate does not need to modify persistent objects to observe their state. <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .5in;"><span lang="RU">(v)&nbsp;&nbsp;</span>Unlike EJB, hibernate can be run as a stand alone tool outside jree container.<span lang="RU">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;"><span lang="RU">SessionFactory and Session</span></b><span lang="RU"><br /> The purpose of the Hibernate SessionFactory (called EntityManager in JEE) is to create Sessions, initialize JDBC connections and pool them (using a pluggable provider like C3P0). <o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><span lang="RU">A SessionFactory is immutable </span>cache of compiled mappings (plus associations / inheritence / aggregations) for a single database.<o:p></o:p></div><div class="MsoNormal">It is<span lang="RU"> built from a Configuration holding mapping information, cache information and a lot of other information usually provided by means of a hibernate.cfg.cml file or through a Spring bean configuration.<o:p></o:p></span></div><div class="MsoNormal"><span lang="RU"><br /> A Session is a unit of work at its lowest level - representing a transaction in database </span>lingo.<o:p></o:p></div><div class="MsoNormal">Session is not thread safe and is maintained as a threadlocal value.<o:p></o:p></div><div class="MsoNormal"><span lang="RU">When a Session is created and operations are done on Hibernate entities, e.g. setting an attribute of an entity, Hibernate does not and update the underlying table immediately. Instead Hibernate keeps track of the state of an entity, whether it is dirty or not, and flushes (commits) updates at the end at the end of a unit of work. This is what Hibernate calls the first level cache.<br /> <br /> <b style="mso-bidi-font-weight: normal;">The 1st level cache</b><br /> Definition: The first level cache is where Hibernate keeps track of the possible dirty states of the ongoing Session's loaded and touched entities. The ongoing Session represents a unit of work and is always used and can not be turned of. The purpose of the first level cache is to hinder to many SQL queries or updates beeing made to the database, and instead batch them together at the end of the Session. When you think about the 1st level cache think Session. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <o:p></o:p></span></div><div class="Ol"><span lang="RU">&nbsp; <o:p></o:p></span></div><div class="Ol"><b><span lang="RU">How does Hibernate implement Lazy-Initialization for single-ended collection? <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU">&gt;&gt; Hibernate3 generates proxies (at startup) for all target entities i.e. Persistent classes using runtime-bytecode enhancement (via CGLIB). Then enable them for many-2-one and one-2-many associations. <o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><span lang="RU">&gt;&gt; Hibernate uses a subclass of the original class and the proxied class must implement a default constructor with package visibility ...&nbsp; so all persistent classes should have a default <b style="mso-bidi-font-weight: normal;">constructor</b> <o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><b><span lang="RU">How to improve performance using natural-id ? <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU"><class name="”User”"> <o:p></o:p></class></span></div><div class="MsoNormal">&nbsp;&nbsp; <span lang="RU"><cache usage="”read-write”/"> <o:p></o:p></cache></span></div><div class="MsoNormal"><span lang="RU">&nbsp;&nbsp; <id.........> <o:p></o:p></id.........></span></div><div class="MsoNormal"><span lang="RU">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <natural-id> <o:p></o:p></natural-id></span></div><div class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <property name="”userName”/"> </property><span lang="RU">&nbsp;&nbsp; <b style="mso-bidi-font-weight: normal;">.. should not be mutable ...</b> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ....... <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">session.createCriteria(User.class) <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp; .add(<b style="mso-bidi-font-weight: normal;">Restrictions.naturalId()</b> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp;&nbsp;&nbsp;&nbsp; .set(“name”, “</span>Bob<span lang="RU">”) <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">).<b style="mso-bidi-font-weight: normal;">setCacheable</b>(true) <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">.uniqueResult(); <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">*** <o:p></o:p></span></div><div class="MsoNormal">S<span lang="RU">ince we </span>have <span lang="RU">mention</span>ed<span lang="RU"> that the fields used are natural keys, hibernate query cache is smart enough to understand that we can bypass the uptodate check and depend on the assembling logic for handling it properly. <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><b><span lang="RU">How can I retrieve info about a collection without initializing it ? <o:p></o:p></span></b></div><div class="MsoNormal">F<span lang="RU">etch the size of a collection : <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">((Integer) s.createFilter(collection, “select count(*)”).list().get(0)).intValue() <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt; retrieve a subset of a collection <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : s.createFilter( lazyCollection, “”).setFirstResult(0).setMaxResults(10).list();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><b><span lang="RU">How to benefit from Query-Caching ?<o:p></o:p></span></b></div><div class="Ol">&gt;&gt;&nbsp;&nbsp;&nbsp; C<span lang="RU">heck query cache for the query <o:p></o:p></span></div><div class="Ol"><span lang="RU">&gt;&gt; if results are found, check if they are latest (that is no entry in update timestamps table or one which predates the cache) <o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 14.15pt;"><span lang="RU">&gt;&gt; if they are not up-to-date then assemble the object (assembling involves creating the object from its primary key or group of columns from their values or other strategies) &nbsp; <o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 14.15pt;"><span lang="RU">The query cache works something like this:&nbsp; <a href="http://www.javalobby.org/java/forums/t48846.html">http://www.javalobby.org/java/forums/t48846.html</a></span><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">| ["from Person as p where p.parent.id=? and p.firstName=?", [ 1 , "Joey"] ] -&gt; [&nbsp; 2 ] ] |</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">&nbsp;</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">The combination of the query and the values provided as parameters to that query is used as a key, and the value is the list of identifiers for that query <o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><b><span lang="RU">How Query cache work with 2</span></b><b><sup><span lang="RU" style="font-size: 7.5pt;">nd</span></sup><span lang="RU"> Level Cache ? <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU">Query-Cache : The intention is to cache the results against the query (the sql along with the parameters and their values).....&nbsp; <o:p></o:p></span></div><div class="MsoNormal">We set<span lang="RU"> hibernate.cache.<b style="mso-bidi-font-weight: normal;">use_query_cache </b></span><b style="mso-bidi-font-weight: normal;">= <span lang="RU">true</span></b><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal">Then Hibernate creates 2 memory regions :<o:p></o:p></div><div class="MsoNormal"><span lang="RU">&nbsp; Region1 : one holding cache query result sets<o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp;&nbsp;</span>R<span lang="RU">egion2 : other holding timestamps of the most recent updates to queryable tables ... <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&gt;&gt; it caches only id values and result of value type ...&nbsp; in order to fetch the state of the actual &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; entities from 2</span><sup><span lang="RU" style="font-size: 7.5pt;">nd</span></sup><span lang="RU"> level cache... <o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><span lang="RU">*** <a href="http://pitfalls.wordpress.com/2008/05/05/hibernatequerycache/">http://pitfalls.wordpress.com/2008/05/05/hibernatequerycache/</a> <o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><span lang="RU">&gt;&gt; the safest invalidation logic is to mantain update timestamps for each table. When any value is looked up from the query cache, we would also check if any of the tables involved in this query have been updated since the results were cached, if they were, the safest thing to do is query the db again. This is from a very simplistic point what hibernate does. It maintains the timestamps in the update timestamp cache. <b style="mso-bidi-font-weight: normal;">The query results are cached with the query as its key in the query cache. <o:p></o:p></b></span></div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;"><span lang="RU">stores only the primary key for queries that return results of only one type.<o:p></o:p></span></b></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><span lang="RU">&gt;&gt; A lot of heavily used data is cached at the second level. However, most of this data is looked up using its natural key, the second level cache however would store it using its primary key as the key, so we could go ahead and use the query cache to save this lookup. <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">***&nbsp; <a href="http://acupof.blogspot.com/2008/01/background-hibernate-comes-with-three.html">http://acupof.blogspot.com/2008/01/background-hibernate-comes-with-three.html</a> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">*** <a href="http://docs.google.com/Doc?id=dfxnknzf_89c6m5r3n3">http://docs.google.com/Doc?id=dfxnknzf_89c6m5r3n3&nbsp; </a><o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">few points regarding 2nd-Level-Caching <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp; *** The 2nd level cache is a process scoped cache that is associated with one SessionFactory. It will survive Sessions and can be reused in new Session by same SessionFactory (which usually is one per application). <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">**** The hibernate cache does not store instances of an entity - instead Hibernate uses something called dehydrated state. Hibernate 'dehydrates' query results and persistent objects into their primitive components and identifiers. Conceptually you can think of it as a Map which contains the id as key and an array as value. Or something like below for a cache region: <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">It stores this decomposed data in the L2 and query results cache, and on a cache hit, it rehydrates/recomposes them into the requested persistent object <br /> <br /> { id -&gt; { atribute1, attribute2, attribute3 } } <br /> { 1 -&gt; { "a name", 20, null } }<br /> { 2 -&gt; { "another name", 30, 4 } }<br /> <br /> If the entity holds a collection of other entities then the other entity also needs to be cached. In this case it could look something like:<br /> <br /> { id -&gt; { atribute1, attribute2, attribute3, Set{item1..n} } } <br /> { 1 -&gt; { "a name", 20, null , {1,2,5} } }<br /> { 2 -&gt; { "another name", 30, 4 {4,8}} }<br /> <br /> The actual implementation of the 2nd level cache is not done by Hibernate (there is a simple Hashtable cache available, not aimed for production though). Hibernate instead has a plugin concept for caching providers which is used by e.g. EHCache. <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><b><span lang="RU">In well-designed Hibernate domain models, we should avoid direct many-2-many collections</span></b><span lang="RU"> – and instead use – <b style="mso-bidi-font-weight: normal;">one-to-many associations with inverse=true </b>....&nbsp; For these associations, the update is handled by the many-2-one end of the association ...&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp; <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .5in;"><br /> </div><div class="MsoNormal"><b><span lang="RU">How to get rid of out-of-memory with hibernate cache ? <o:p></o:p></span></b></div><div class="MsoNormal" style="margin-left: .5in;"><span lang="RU">&gt;&gt; Lessons Learned <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">If you use hibernate query caching, and actually want to use memory for caching useful results, and waste as little as possible with overhead, follow some simple advice: <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.35pt;"><span lang="RU" style="font-family: StarSymbol; font-size: 10pt;">•</span><span lang="RU">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Write your HQL queries to use identifiers in any substitutable parameters.WHERE clauses, IN lists, etc. Using full objects results in the objects being kept on the heap for the life of the cache entry. <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.35pt;"><span lang="RU" style="font-family: StarSymbol; font-size: 10pt;">•</span><span lang="RU">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Write your Criteria restrictions to use identifiers as well. <o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 14.15pt; margin-left: 35.35pt; margin-right: 0in; margin-top: 0in;"><span lang="RU" style="font-family: StarSymbol; font-size: 10pt;">•</span><span lang="RU">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Use the 'smart' query cache implementation&nbsp; to eliminate duplicate objects used in query keys. This helps a little if you use the ids in your HQL/Criteria, but if you still must use objects then it helps a lot. <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.35pt;"><span lang="RU" style="font-family: StarSymbol; font-size: 10pt;">•</span><span lang="RU">&nbsp;&nbsp;&nbsp;</span><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">final P</span><span style="font-family: 'Courier New'; font-size: 10pt;">roduct product</span><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">= ...;</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">** Don't do this <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">final String hql = "from </span><span style="font-family: 'Courier New'; font-size: 10pt;">Product </span><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">&nbsp;as </span><span style="font-family: 'Courier New'; font-size: 10pt;">product </span><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">&nbsp;where </span><span style="font-family: 'Courier New'; font-size: 10pt;">product</span><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">.</span><span style="font-family: 'Courier New'; font-size: 10pt;">order</span><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;"> = ?"</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">** Do this</span><span lang="RU"> <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">final String hql = "from </span><span style="font-family: 'Courier New'; font-size: 10pt;">Product</span><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;"> as </span><span style="font-family: 'Courier New'; font-size: 10pt;">product </span><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">&nbsp;where </span><span style="font-family: 'Courier New'; font-size: 10pt;">product</span><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">.</span><span style="font-family: 'Courier New'; font-size: 10pt;">order</span><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">.id = ?"</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">....&nbsp;&nbsp; q.setParameter(0, </span><span style="font-family: 'Courier New'; font-size: 10pt;">order</span><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">.getId());</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">&nbsp;</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">&nbsp;</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">final Query q = session.createQuery(hql);</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">q.setParameter(0, mate);</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 14.15pt;"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">q.setCacheable(true);</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span class="MsoHyperlink">**** </span><span lang="RU"><a href="http://darren.oldag.net/2008/11/hibernate-query-cache-dirty-little_04.html">http://darren.oldag.net/2008/11/hibernate-query-cache-dirty-little_04.html </a><o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><b>Beware of <span lang="RU">fetch-mode=join .. </span></b><b>pitfalls<span lang="RU"> <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU">****&nbsp; <a href="http://www.javalobby.org/articles/hibernate-query-101/">http://www.javalobby.org/articles/hibernate-query-101/</a> <o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><b>Beware of duplicate values :<o:p></o:p></b></div><div class="MsoNormal">*** J<span lang="RU">oin returning duplicate rows .. <o:p></o:p></span></div><div class="MsoNormal">S<span lang="RU">oln. Call method setResultTransformer() on your criteria object prior to execution with argument CriteriaSpecification.DISTINCT_ROOT_ENTITY. <br style="mso-special-character: line-break;" /> <br style="mso-special-character: line-break;" /> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">*** If there are any mapped collections whose elements also contain mapped collections, the results of the query will not only be incorrect, the objects themselves will be incorrect. Each mapped collection may contain repeated elements. <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .5in;"><span lang="RU">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU"><a href="http://www.hibernate.org/hib_docs/v3/api/org/hibernate/criterion/CriteriaSpecification.html#DISTINCT_ROOT_ENTITY&lt;br /&gt;">http://www.hibernate.org/hib_docs/v3/api/org/hibernate/criterion/CriteriaSpecification.html#DISTINCT_ROOT_ENTITY%3Cbr%20/%3E</a> <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .5in;"><span lang="RU">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU"><a href="http://forum.hibernate.org/viewtopic.php?p=2319562&amp;sid=e89cad0d04b103202732da3485437efd">http://forum.hibernate.org/viewtopic.php?p=2319562&amp;sid=e89cad0d04b103202732da3485437efd </a><o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .5in;"><span lang="RU"><a href="http://sacrosanctblood.blogspot.com/2007/07/eager-fetching-in-hibernate-using.html">http://sacrosanctblood.blogspot.com/2007/07/eager-fetching-in-hibernate-using.html </a><o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><b>Avoid N+1 problem :<o:p></o:p></b></div><div class="MsoNormal"><br /> </div><div class="MsoNormal">Lazy Association should be enabled if we want to avoid infamous N+1 problem ! Otherwise we can turn on 'eager fetching' if the data associated with main query is smaller in size. <o:p></o:p></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><b>OpenSessionInViewFilter</b><br /> <br /> We should effectively flush the session by overriding closeSession() of&nbsp;OpenSessionInViewFilter.<br /> In case of Spring MVC we can use Interceptor over the Filter.<br /> <a href="http://72miles.com/blog/spring-opensessioninviewinterceptor-vs-opensessioninviewfilter/">http://72miles.com/blog/spring-opensessioninviewinterceptor-vs-opensessioninviewfilter/</a></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><b>Other Tricks<o:p></o:p></b></div><div class="MsoNormal"><br /> </div><div class="MsoNormal">If we specify <b>'unsaved-value' = null</b> for primary key, then Hibernate will find out when to do insert and when to do update.<o:p></o:p></div><div class="MsoNormal"><br /> </div><div class="MsoNormal">In case session is closed when lots of data getting loaded upfront, then we should implement<o:p></o:p></div><div class="MsoNormal">Open Session in View&nbsp; (anti)pattern. Session will remain opened long enough to perform lazy associations.<o:p></o:p></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><b><span lang="RU">Avoiding out-of-memory in cache <o:p></o:p></span></b></div><div class="MsoNormal"><span class="MsoHyperlink">**** </span><span lang="RU"><a href="http://www.hibernate.org/hib_docs/v3/reference/en/html/batch.html">http://www.hibernate.org/hib_docs/v3/reference/en/html/batch.html </a><o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 14.15pt;"><br /> </div><div class="MsoNormal" style="margin-bottom: 14.15pt;"><span lang="RU">When making new objects persistent, you must </span><span lang="RU" style="font-family: 'Courier New';">flush()</span><span lang="RU"> and then </span><span lang="RU" style="font-family: 'Courier New';">clear()</span><span lang="RU"> the session regularly, to control the size of the first-level cache. <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">Session session = sessionFactory.openSession();</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">Transaction tx = session.beginTransaction();</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">&nbsp;&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">for ( int i=0; i&lt;100000; i++ ) {</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">&nbsp;&nbsp;&nbsp; Customer customer = new Customer(.....);</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">&nbsp;&nbsp;&nbsp; session.save(customer);</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">&nbsp;&nbsp;&nbsp; if ( i % 20 == 0 ) { //20, same as the JDBC batch size</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //flush a batch of inserts and release memory:</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; session.flush();</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; session.clear();</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">&nbsp;&nbsp;&nbsp; }</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">}</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">&nbsp;&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">tx.commit();</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 14.15pt;"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">session.close();</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><b>Optimization for Large Data Sets <o:p></o:p></b></div><div class="MsoNormal"><br /> </div><div class="MsoNormal">Query query = session.createQuery(....);<o:p></o:p></div><div class="MsoNormal">query.setFirstResult(RowsPerPage);<o:p></o:p></div><div class="MsoNormal">query.setMaxResult(PageSize);<o:p></o:p></div><div class="MsoNormal" style="margin-left: .5in;"><br /> </div><div class="MsoNormal"><b>Lightweight Data Pattern : Fetch only what you need<o:p></o:p></b><br /> Scales for millions records.</div><div class="MsoNormal"><span lang="RU"><a href="http://community.jboss.org/wiki/LightweightClass">http://community.jboss.org/wiki/LightweightClass</a><o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><span class="MsoHyperlink"><b>Set Correct Transactional Boundary<o:p></o:p></b></span></div><div class="MsoNormal"><span class="MsoHyperlink">Set @Transactional (readOnly = true) to avoid unnecessary dirty-checking by Hibernate Engine.<o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><span class="MsoHyperlink"><b>Use Hibernate Validator in Domain Model<o:p></o:p></b></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><b>Usage of Proper Caching Strategy<o:p></o:p></b></div><div class="MsoNormal"><br /> </div><div class="MsoNormal">Either use <cache usage="”read-write”"> or @Cache (usage=ConcurrencyStrategy.READ_WRITE)<o:p></o:p></cache></div><div class="MsoNormal">Refer to a properly configured cache region from query.<o:p></o:p></div><div class="MsoNormal">query.setCacheRegion(“query.OrderCache”);<o:p></o:p><br /> <br /> <br /> <b>Multi-Tenancy Support in Hibernate 4</b><br /> <a href="http://opensource.atlassian.com/projects/hibernate/browse/HHH-5697">http://opensource.atlassian.com/projects/hibernate/browse/HHH-5697</a></div></div>http://musings-on-technology.blogspot.com/2011/04/hibernate-known-facts-unknown-traps.htmlnoreply@blogger.com (Kaniska)0tag:blogger.com,1999:blog-1373851816248476399.post-6060655797524953310Mon, 18 Apr 2011 21:50:00 +00002011-04-19T03:20:27.410+05:30Fun with GWT and Google Fusion Table<div dir="ltr" style="text-align: left;" trbidi="on"><br /> <div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Google always strives to make things Simpler to develop and Easier to use !&nbsp;</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br /> </div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">GWT benefited tremendously from the advancement of App Engine !&nbsp;</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Its also blessed by SpringSource which directly integrates into APP Engine through the ground-breaking Spring ROO. So this means less steps to follow and less boiler-plate code to write! save time by avoiding infrastructure-setup&nbsp;</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br /> </div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">It was always simpler to create - say modular, reusable client-side cache, pagination table, model-ui binding API bypassing monolithic javascript libraries ! So easy it is to leverage Spring4GWT 'servlet'-less server side coding and leverage Hibernate-validation !&nbsp;</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br /> </div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Actually it saved months of work in couple of projects !&nbsp;</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br /> </div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">How about&nbsp;scalability&nbsp;and performance ? Its a good time to adopt Ext GWT !</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><a href="http://www.sencha.com/products/extgwt/examples/">http://www.sencha.com/products/extgwt/examples/</a>&nbsp;- lightning-fast traversal of millions of records !</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br /> </div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">How to architect high-performance gwt -&nbsp;<a href="http://www.youtube.com/watch?v=USlUYkBHiHA">http://www.youtube.com/watch?v=USlUYkBHiHA</a></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br /> </div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">GWT integrates with HTML5 -&nbsp;<a href="http://www.youtube.com/watch?v=omBURP0MxcI&amp;feature=relmfu">http://www.youtube.com/watch?v=omBURP0MxcI&amp;feature=relmfu</a></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br /> </div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Test the speed of GWT in Chrome - &nbsp;<a href="http://code.google.com/webtoolkit/speedtracer/">http://code.google.com/webtoolkit/speedtracer/</a></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br /> </div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Some of the links related to GWT.</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><a href="http://www.ajaxmatters.com/articles/gwt/rpc_remote_procedure_calls_example_p1.asp">http://www.ajaxmatters.com/articles/gwt/rpc_remote_procedure_calls_example_p1.asp</a>x&nbsp;</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><a href="http://marakana.com/forums/java/general/118.html">http://marakana.com/forums/java/general/118.html</a></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><a href="http://www.javacodegeeks.com/2010/05/gwt-2-spring-3-jpa-2-hibernate-35.html">http://www.javacodegeeks.com/2010/05/gwt-2-spring-3-jpa-2-hibernate-35.html</a></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br /> </div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">-------------------------------------------------------------------</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br /> </div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Well ! GWT is for Java Geeks ! &nbsp;How'bout common masses who just owns diverse set of data - ranging from &nbsp; &nbsp;- geographical info, traffic data, weather info, chemical properties, physics measurement data, population info - Hey we just want to visualize our data &nbsp;- we hardly care about building an App !!</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br /> </div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Here comes Google Fusion Table - it will load your data into Cloud (read Fusion Tables) and display/ report in Visualizer UI.&nbsp;</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br /> </div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Enjoy the ride -&nbsp;<a href="http://www.google.com/fusiontables/public/tour/index.html">http://www.google.com/fusiontables/public/tour/index.html</a></div></div>http://musings-on-technology.blogspot.com/2011/04/fun-with-gwt-and-google-fusion-table.htmlnoreply@blogger.com (Kaniska)0tag:blogger.com,1999:blog-1373851816248476399.post-4373405763874058313Sat, 16 Apr 2011 14:42:00 +00002011-04-19T10:16:50.837+05:30Data TransformerBest Practices for XML and POJO Binding<div dir="ltr" style="text-align: left;" trbidi="on"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span class="Apple-style-span" style="font-size: 13px; line-height: 15px;"></span></span><br /> <span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"></span><br /> <div style="font-style: normal; font-weight: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: black;"><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-size: x-small;">Here goes few basic guidelines to choose from different Data Binding Technologies :</span></span></span></span></div><div style="font-style: normal; font-weight: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="font-style: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: black;"><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-size: x-small;"><b>XMLBeans :</b></span></span></span></span></div><div style="line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: black;"><span style="font-size: x-small;"><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-style: normal;"><span style="font-weight: normal;">XMLBeans</span></span></span><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-style: normal;"><span style="font-weight: normal;"> is the best candidate - when </span><b>we just depend upon underlying XML for the actual data </b><span style="font-weight: normal;">and don't really need to manipulate the Java code or modify the xml. </span></span></span></span></span> </span></div><div style="font-style: normal; font-weight: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: black;"><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-size: x-small;">Say we just need to convert an WSDL into Java Code and then use the generated Java API for aaceesing WSDL Operations and Interfaces.</span></span></span></span></div><div style="font-style: normal; font-weight: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="font-style: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: black;"><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-size: x-small;">XMLBeans actually stores the entire set of parsed events that represent the document in memory. XMLBeans is <b>very fast for just reading and writing documents.</b> It is<b> really XML-Centric</b>.</span></span></span></span></div><div style="font-style: normal; font-weight: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: #222222;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;"><i>"XMLBeans is based on an efficient XML token stream, and it keeps underlying XML infoset intact. Since XMLBeans keeps the data in memory as XML, overhead of unmarshalling and marshalling is reduced.&nbsp;</i></span></span></span></span></div><div style="line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: #222222;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;"><i>To address varying data access and data transformation requirements, XMLBeans provides a flexibility of navigating through xml data using xPath or xQuery, and manipulating xml data using either xml cursor or XMLBeans generated classes."</i></span></span></span></span></div><div style="font-style: normal; font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="font-style: normal; font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: #222222;"><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-size: x-small;">XMLBeans performs poorly in terms of handling memory &nbsp;because it stores a live mapping of objects and underlying XML Document in memory.</span></span></span></span></div><div style="font-style: normal; font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="font-style: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: #222222;"><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-size: x-small;"><b>JiBX:</b></span></span></span></span></div><div style="font-style: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: #222222;"><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-size: x-small;">If we really want to manipulate <b>the way XML Data should be mapped to Java Objects</b>, JiBX scores high !</span></span></span></span></div><div style="font-style: normal; font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: #222222;"><span style="font-family: Verdana, sans-serif;"><span style="font-size: x-small;"><span style="font-family: arial, verdana, helvetica, sans-serif;">JiBX uses mapped bindings to automatically generate code and does not care much about the XML Schema Support. I</span><span style="font-family: arial, verdana, helvetica, sans-serif;"><b>t is </b></span><span style="color: black;"><span style="font-family: arial, sans-serif;"><b>a </b></span></span><span style="color: black;"><span style="font-family: arial, sans-serif;"><i><b>Java-centric</b></i></span></span><span style="color: black;"><span style="font-family: arial, sans-serif;"><b>&nbsp;approach to data binding</b></span></span><span style="color: black;"><span style="font-family: arial, sans-serif;">. It uses ByteCode enhancement to add XML generation and parsing support directly into the bytecode of Java Class. </span></span></span></span></span> </span></div><div style="font-style: normal; font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="font-style: normal; font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: #222222;"><span style="font-family: Verdana, sans-serif;"><span style="font-size: x-small;"><span style="color: black;"><span style="font-family: arial, verdana, helvetica, sans-serif;">"It does not tie the Java class to the structure of the XML document. Just because an element lives within another element in the document, does not imply that the data contained in the sub element must be an equivalent level down in the Java structure. This allows the deep XML structure (which makes sense in XML) to be mapped easily to a more shallow, but not necessarily flat, structure (which makes sense in the Java object model).</span></span><span style="font-family: arial, verdana, helvetica, sans-serif;">"</span></span></span></span></span></div><div style="font-style: normal; font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: #222222;"><span style="font-family: Verdana, sans-serif;"><span style="font-size: x-small;"><span style="font-family: arial, verdana, helvetica, sans-serif;">It uses fast </span><span style="color: black;"><span style="font-family: arial, verdana, helvetica, sans-serif;">Pull-Parser and has a very compact Runtime Distribution.</span></span></span></span></span></span></div><div style="font-style: normal; font-weight: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: black;"><span style="font-family: arial, sans-serif;"><span style="font-size: x-small;">JiBX isolates XML document formats from Java language object structures.</span></span></span></span></div><div style="font-style: normal; font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="font-style: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: #222222;"><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-size: x-small;"><b>JAXB:</b></span></span></span></span></div><div style="font-style: normal; font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: #222222;"><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-size: x-small;">JAXB generates code from Schema. Very much XML dependent, but still provides ways to manipulate mappings through annotations. Its easy to work but difficult to maintain and is not as elegant as XMLBeans or JiBX. To some extent its between Java-Centric JiBX and XML-Centric XMLBeans. </span></span></span> </span></div><div style="font-style: normal; font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: #222222;"><span style="font-family: Verdana, sans-serif;"><span style="font-size: x-small;"><i><span style="font-family: arial, verdana, helvetica, sans-serif; font-weight: normal;">" </span>JAXB among other things allows you to <b>customize binding through schema annotation</b> such that generated classes are more than just XML containers - they can represent objects with real behavior (and ability to be instantiated from XML)."</i></span></span></span></span></div><div style="font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="font-style: normal; font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: #222222;"><span style="font-family: Verdana, sans-serif;"><span style="font-size: x-small;">JAXB has issues with <span style="color: black;"><span style="font-family: arial, verdana, helvetica, sans-serif;">deeply nested (and large) xsds. It generates too many classes and for large xmls simply grow unmangeable. (</span></span>JAXB does not make any use of inner classes while generatiing code). </span></span></span> </span></div><div style="font-style: normal; font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="font-style: normal; font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: black;"><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-size: x-small;">JAXB generated classes can not parse xmls, whereas XMLBeans allow parsing underlying xml. (its more xml centric)</span></span></span></span></div><div style="font-style: normal; font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="font-style: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: black;"><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-size: x-small;"><b>EMF :</b></span></span></span></span></div><div style="font-style: normal; font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: black;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;"><span style="font-family: arial, verdana, helvetica, sans-serif;">EMF produces an Ecore model given an XML Schema and then uses template-based generator technology to generate a rich Java API (of hand written quality).The XML Schema to Ecore conversion can be tailored, the templates used to generate the Java API can be tailored, and the resulting Java API can be tailored.The generator supports merging regeneration so that it will preserve your hand written changes.In other words, EMF is far richer and more flexible, and supports a broader subset of XML Schema.</span></span></span></span></span></div><div style="font-style: normal; font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="font-style: normal; font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: #222222;"><span style="font-family: Verdana, sans-serif;"><span style="font-size: x-small;"><b>XStream</b> - simplest to use</span></span></span></span></div><div style="line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: black;"><span style="font-family: helvetica, arial, sans-serif;"><span style="font-size: x-small;"><span style="font-style: normal;"><span style="font-weight: normal;">.&nbsp;</span></span></span></span></span><a href="http://www.extreme.indiana.edu/xgws/xsoap/xpp/mxp1/index.html"><span style="color: #006600;"><span style="font-family: helvetica, arial, sans-serif;"><span style="font-size: x-small;"><span style="font-style: normal;"><u><span style="font-weight: normal;">XPP3</span></u></span></span></span></span></a><span style="color: black;"><span style="font-family: helvetica, arial, sans-serif;"><span style="font-size: x-small;"><span style="font-style: normal;"><span style="font-weight: normal;">&nbsp;is a </span><b>very fast XML pull-parser implementation</b><span style="font-weight: normal;">. User is also free to choose any other parser like JAXP DOM inside XStream.</span></span></span></span></span></span></div><div style="line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="font-style: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: black;"><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-size: x-small;">XStream is designed fo<b>r configurationless serialization</b>. This makes it painless to serialize any type of objects, without the need for mappings. Ideal for things like persistence, configuration and over-the-wire transports. However, because there are no mappings, you have little control of how the serialized object is represented.</span></span></span></span></div><div style="line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: black;"><span style="font-size: x-small;"><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-style: normal;"><span style="font-weight: normal;">** solution :&nbsp;</span></span></span><span style="font-family: arial, sans-serif;"><span style="font-style: normal;"><span style="font-weight: normal;">&nbsp;</span></span></span><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-style: normal;"><span style="font-weight: normal;">using XStream this way to process SOAP messages based on complex XML schemas. So XSLT acts as your mapping definition&nbsp;and it is much more powerful than plain declarative "binding" mappings, since it is a full-blown templating language.</span></span></span></span></span></span></div><div style="font-style: normal; font-weight: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="font-style: normal; font-weight: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: black;"><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-size: x-small;">** custom converters are powerful</span></span></span></span></div><div style="font-style: normal; font-weight: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: black;"><span style="font-family: 'Times New Roman';"><span style="font-size: x-small;"><span style="font-family: arial, verdana, helvetica, sans-serif;">**&nbsp;</span><span style="color: #40348c;"><span style="font-family: tahoma, arial, sans-serif;"><b>XStream: how to serialize objects to non XML formats</b></span></span></span></span></span></span></div><div style="font-style: normal; font-weight: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="font-style: normal; font-weight: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: black;"><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-size: x-small;">Xstream can marshal to / unmarshal from not just xml but also json, tree structure etc.</span></span></span></span></div><pre class="western" style="font-style: normal; font-weight: normal; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: black;"><span style="font-family: arial, sans-serif;"><span style="font-size: x-small;">The modular design allows other output formats. XStream ships currently with JSON support and morphing.</span></span></span></span></pre><div style="font-style: normal; font-weight: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: black;"><span style="font-size: x-small;"><span style="font-family: arial, sans-serif;"><span style="font-style: normal;"><span style="font-weight: normal;">So the bottomline - </span></span></span><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-style: normal;"><span style="font-weight: normal;">If you need precise control of how your objects are represented and are happy to spend time defining mappings, use JiBX. Otherwise stick to Xstream.</span></span></span></span></span></span></div><div style="font-style: normal; font-weight: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="font-style: normal; font-weight: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="font-style: normal; font-weight: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;">Reference : <a href="http://www.ibm.com/developerworks/library/x-databd4/"><span style="color: black;"><span style="font-family: 'Times New Roman';"><span style="font-size: x-small;"><span style="font-style: normal;"><span style="font-weight: normal;">http://www.ibm.com/developerworks/library/x-databd4/</span></span></span></span></span></a></span></div><div style="line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"></div></div>http://musings-on-technology.blogspot.com/2011/04/best-practices-for-xml-and-pojo-binding.htmlnoreply@blogger.com (Kaniska)0tag:blogger.com,1999:blog-1373851816248476399.post-601234621184867802Sat, 09 Apr 2011 17:44:00 +00002011-04-09T23:14:14.149+05:30Oreilly Instant Writable API Competition<div dir="ltr" style="text-align: left;" trbidi="on">Planning to get my feet wet with fluidinfo ... Starting off with a simple JavaFX App.<br /> <br /> More Details .. &nbsp;&nbsp;<a href="http://radar.oreilly.com/2011/03/api-competition.html">http://radar.oreilly.com/2011/03/api-competition.html</a><br /> <br /> </div>http://musings-on-technology.blogspot.com/2011/04/oreilly-instant-writable-api.htmlnoreply@blogger.com (Kaniska)0tag:blogger.com,1999:blog-1373851816248476399.post-8489964230347544815Tue, 17 Aug 2010 06:39:00 +00002011-04-19T02:38:39.106+05:30EclipsePerformance MonitoringProductivity ToolsEclipse Apps Performance Tips<div dir="ltr" style="text-align: left;" trbidi="on"><div style="margin-bottom: 0in;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">Lets explore some of the tricks to monitor and improve performance of apps running in Eclipse and also how we can write better API.</span></div><div style="margin-bottom: 0in;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /> </span></div><div style="margin-bottom: 0in;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">1. <b>VisualVM </b>is a great tool to monitor the performance of any eclipse application.&nbsp;Once the plugin is installed, any eclipse app can be launched in the VisualVM Runtime instead of a Java Runtime so that the health of the app can be monitored in real-time.</span></div><div style="margin-bottom: 0in;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">Reference : &nbsp;<a href="https://visualvm.dev.java.net/eclipse-launcher.html">https://visualvm.dev.java.net/eclipse-launcher.html</a></span></div><div style="margin-bottom: 0in;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /> </span></div><div style="margin-bottom: 0in;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">2. If we enable "<b>Show Heap Status</b>" under 'General Preferences', we can periodically <b>enforce GC</b>, which is very important for heap analysis.</span></div><div style="margin-bottom: 0in;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /> </span></div><div style="margin-bottom: 0in;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">3. Now we can really <b>enable in-depth monitoring</b> by turning on <b>Runtime Spy</b> through an&nbsp;.options file e.g.&nbsp;<b>eclipse -debug c:\spy\.options</b></span></div><div style="margin-bottom: 0in;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">Here is the&nbsp;Update site for core tools</span></div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">platform-core - <a href="http://eclipse.org/eclipse/platform-core/updates">http://eclipse.org/eclipse/platform-core/updates</a></span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">References :</span><br /> <a href="http://www.jdg2e.com/ch32.performance/doc/index.html#refs"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">http://www.jdg2e.com/ch32.performance/doc/index.html#refs</span></a><br /> <a href="http://books.google.com/books?id=vxMDuxmSKTsC&amp;pg=PA760&amp;lpg=PA760&amp;dq=Window+%3E+Open+Perspective+%3E+Runtime+Spy&amp;source=bl&amp;ots=KOdIlfzjyi&amp;sig=36CBytt1iqHZFv-G3Q1YlCbFMPc&amp;hl=en&amp;ei=uh7OS4bFG4-QsgOpoaivDg&amp;sa=X&amp;oi=book_result&amp;ct=result&amp;resnum=4&amp;ved=0CBIQ6AEwAw#v=onepage&amp;q=Window%20%3E%20Open%20Perspective%20%3E%20Runtime%20Spy&amp;f=false"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">Google Book</span></a><br /> <a href="http://www.eclipse.org/eclipse/platform-core/downloads/tools/readme.html"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">http://www.eclipse.org/eclipse/platform-core/downloads/tools/readme.html</span></a><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">Sample settings of the&nbsp;Runtime Spy&nbsp;.options file</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">#### Monitoring settings</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"># monitor class loading</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">org.eclipse.osgi/monitor/classes=true</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"># monitor bundle activation</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">org.eclipse.osgi/monitor/activation=true</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"># monitor resource bundle (*.properties) loading</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">org.eclipse.osgi/monitor/resources=true</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">#### Trace settings</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"># trace class loading - snapshot the execution stack when a class is loaded</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">org.eclipse.osgi/trace/classLoading=true</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"># trace location - file in which execution traces are written</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">org.eclipse.osgi/trace/filename=runtime.traces</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"># trace filters - Java properties file defining which classes should</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"># be traced (if trace/classLoading is true)</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">etc........</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">4. Well even after enabling all types of monitoring, we still sometimes can not find out why certain apps leads to OutOfMemory Error ! </span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">Then the only way out is to generate the Heap Dumps and Thread Dumps.</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">We can add this vmarg in eclipse.ini -</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><b>-Xdump:java+heap+system:events=user,opts=CLASSIC+PHD </b>so that whenever SendSignal <pid> is executed&nbsp;corresponding&nbsp;dumps will be generated.</pid></span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">Otherwise we can <b>start eclipse in command prompt </b>as follows and then do Ctrl+break to signal the vm.</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">eclipse -vm <sun_jre>\bin\java.exe -console <b>-consoleLog</b> -vmargs <b>-verbose:class</b> <b>-verbose:dynload </b>-Xms1024m -Xmx1536m -XX:MaxPermSize=128m -Xdump:heap+java:events=user,opts=CLASSIC+PHD -Xgcpolicy:optavgpaus.</sun_jre></span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">Another way to send stop signal to vm - c<span class="Apple-style-span" style="color: #1f497d;">db -p <pid> -c ".dump /ma java.dmp;q" -&nbsp;</pid></span><span class="Apple-style-span" style="color: #1f497d;">Where&nbsp;</span><span class="Apple-style-span" style="color: #1f497d;"><pid> is the integer process Id of the java process.</pid></span></span><br /> <span class="Apple-style-span" style="color: #1f497d; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">5. <span class="Apple-style-span" style="color: #1f497d;">&nbsp;</span>Time to highlight the importance of <b>designing API </b>and <b>SPI </b>using eclipse codebase.&nbsp;</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">&nbsp;&nbsp; &nbsp; This is an invaluable source of knowledge about evolving Eclipse API and proper usage of&nbsp;annotations&nbsp;like&nbsp;</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">&nbsp;&nbsp; &nbsp; @noimplement, @noextend etc.</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">Its a classic :&nbsp;<a href="http://www.eclipse.org/eclipse/development/java-api-evolution.html">http://www.eclipse.org/eclipse/development/java-api-evolution.html</a></span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">6. In order to <b>enforce API Analysis </b>we should refer to -&nbsp;<a href="http://www.eclipse-tips.com/tutorials/26-api-tooling-tutorial">http://www.eclipse-tips.com/tutorials/26-api-tooling-tutorial</a>. After all Eclipse is meant for coding clean interfaces and abstract classes that communicates to users through simple annotations and robust patterns.</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">7. Its not a bad idea to enforce internationalization – using the setting - <span style="color: black;"><span style="font-style: normal;"><b>org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=error</b><span style="font-weight: normal;"> in .settings file.</span></span></span></span><br /> <span style="color: black;"><span style="font-style: normal;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-weight: normal;"><br /> </span></span></span><br /> <span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-style: normal;"><b>Fixing Int issues at the early stage</b><span style="font-weight: normal;"> prevents from wasting a good amount of time and&nbsp;introducing&nbsp;unsolicited bugs at the time of product delivery phase.</span></span></span><br /> <span style="color: black;"><span style="font-style: normal;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-weight: normal;"><br /> </span></span></span><br /> <span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-style: normal;"><span style="font-weight: normal;">8. we should </span><b>flag 'unused imports' as errors</b><span style="font-weight: normal;"> in preference to make it a daily habit getting rid of unnecessary evils.</span></span></span><br /> <span style="color: black;"><span style="font-style: normal;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-weight: normal;"><br /> </span></span></span><br /> <span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-style: normal;"><span style="font-weight: normal;">9. </span><b>Templating try / catch to actually catch and log an exception</b><span style="font-weight: normal;"> is a MUST ! Eclipse should fix this by default providing a exception.printStackTrace() statement. Empty catch blocks are silent killers that remain hidden inside deeply nested api !</span></span></span><br /> <span style="color: black;"><span style="font-style: normal;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-weight: normal;"><br /> </span></span></span><br /> <span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-style: normal;"></span></span><br /> <div align="LEFT" style="margin-bottom: 0in;"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-style: normal;"><span style="color: black;">10.<b> Remote Debugging Options :</b></span></span></span></div></div><div align="LEFT" style="font-weight: normal; margin-bottom: 0in;"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-style: normal;"><span style="color: #333333;"><span style="font-style: normal;"><span style="font-weight: normal;">-vmargs<br /> -Xdebug<br /> -Xnoagent<br /> -Djava.compiler=NONE<br /> -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9000</span></span></span></span></span></div></div><div align="LEFT" style="font-weight: normal; margin-bottom: 0in;"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-style: normal;"><br /> </span></span></div></div><div align="LEFT" style="margin-bottom: 0in;"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-style: normal;"><span style="color: black; font-weight: normal;">11.&nbsp;</span><b>How to enforce annotations for api ?</b></span></span></div></div><div align="LEFT" style="font-weight: normal; margin-bottom: 0in;"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-style: normal;"><span style="color: black;"><span style="color: #333333;"><span style="font-style: normal;"><span style="font-weight: normal;"><a href="http://www.eclipse-tips.com/tutorials/26-api-tooling-tutoria">http://www.eclipse-tips.com/tutorials/26-api-tooling-tutoria</a>l<br /> -- &nbsp;enforce usage of @since, @noimplement annotations</span></span></span></span></span></span></div></div><div align="LEFT" style="font-weight: normal; margin-bottom: 0in;"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-style: normal;"><br /> </span></span></div></div><div align="LEFT" style="margin-bottom: 0in;"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-style: normal;"><span style="color: black;">12. <b>How to view OSGi dependency and search plugin dependency ?</b></span></span></span></div></div><div align="LEFT" style="font-weight: normal;"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-style: normal;"><span style="color: black;"><span style="font-style: normal;"><span style="font-weight: normal;">STS -&nbsp;<a href="http://blog.springsource.com/2009/03/05/osgi-development-tools-in-sts/">http://blog.springsource.com/2009/03/05/osgi-development-tools-in-sts/</a></span></span></span></span></span></div></div><div style="font-weight: normal; margin-bottom: 0in; orphans: 2; widows: 2;"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-style: normal;"><a href="http://blog.springsource.com/wp-content/uploads/2009/03/dependency-graph.png"><span style="color: black;"><span style="font-style: normal;"><span style="font-weight: normal;">http://blog.springsource.com/wp-content/uploads/2009/03/dependency-graph.png</span></span></span></a></span></span></div></div><br /> <span style="color: black;"><span style="font-style: normal;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-weight: normal;"><br /> </span></span></span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span style="color: black;"><span style="font-style: normal;"><span style="font-weight: normal;">13.&nbsp;</span></span></span>The last but not the least <b>FindBug (</b><a href="http://findbugs.cs.umd.edu/eclipse">http://findbugs.cs.umd.edu/eclipse</a>)&nbsp;should be part of development environment and be actively used.</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-style-span">Well ... a bonus tip for hackers :-) ... don't forget the <b>decompiler </b>plugin -</span><b>http://java.decompiler.free.fr/jd-eclipse/update-&nbsp;</b><span class="Apple-style-span">&nbsp;using which you can even debug any class that essentially do not have source base shipped with its tool !&nbsp;</span><b>&nbsp;</b></span><br /> <div align="LEFT" style="font-style: normal; font-weight: normal; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="color: #1f497d; font-family: Arial, sans-serif;"><span class="Apple-style-span" style="font-size: small;"><br /> </span></span></div></div>http://musings-on-technology.blogspot.com/2010/08/eclipse-apps-performance-tips.htmlnoreply@blogger.com (Kaniska)1tag:blogger.com,1999:blog-1373851816248476399.post-7400735685438394502Fri, 14 May 2010 20:52:00 +00002010-05-16T23:40:46.844+05:30Eclipse Modelling 3D EMF ZEST GEFThe Wonderland of ModellingIts a true pleasure to witness the evolution of <b>Modelling API</b> of Eclipse.<br /> <br /> Joshua M. Epstein reflected on the <a href="http://jasss.soc.surrey.ac.uk/11/4/12.html">importance of modelling</a><br /> <br /> <b>The basics:</b><br /> Joshua M. Epstein ... <br /> <blockquote>We're all modelers, but most of our models are implicit, not explicit. <br /> Sometimes we model either to predict or to explain<br /> And there are at least 15 other <b>good reasons to build explicit models . .</b> . <br /> <br /> <blockquote>1.Explain (very distinct from predict) <br /> 2.Guide data collection <br /> 3.Illuminate core dynamics <br /> 4.Suggest dynamical analogies <br /> 5.Discover new questions <br /> 6.Promote a scientific habit of mind <br /> 7.Bound (bracket) outcomes to plausible ranges <br /> 8.Illuminate core uncertainties. <br /> 9.Offer crisis options in near-real time <br /> 10.Demonstrate tradeoffs / suggest efficiencies <br /> 11.Challenge the robustness of prevailing theory through perturbations <br /> 12.Expose prevailing wisdom as incompatible with available data <br /> 13.Train practitioners <br /> 14.Discipline the policy dialogue <br /> 15.Educate the general public <br /> 16.Reveal the apparently simple (complex) to be complex (simple) </blockquote></blockquote><br /> Its just not the fact that Eclipse Modelling has acquired a very <b>high-end Graphical Capabilities</b> with the advancement of GMF and <b>performance boost with CDO</b>; but also the mammoth extensibility and convertibility of EMF from almost any proprietary / domain-specific model into any platform-specific implementation by leveraging model transformation technologies.<br /> <br /> We know that how any type of meta-model / model (UML, Annotated POJO, XSD, WSDL, DB Schema, PRR, PMML, Ontology etc.) can be seamlessly converted into EMF and then be represented into GMF and finally persisted into platform-specific models by applying platform-specific (Finance/telecom/Health etc.) profiles. Here is one post -<br /> <a href="http://musings-on-technology.blogspot.com/2008/06/graphical-model-transformation.html"><b>Graphical Model Transformation</b></a><br /> <br /> M2M (XPand) and TMF (XText) simplified backward compatibilities of models and popularized the usabilities amongst non-modellers who can focus on specific entities of a system.<br /> <br /> Modelling takes a giant step forward with '<a href="http://eclipse.org/amp/">AMP</a>' - <b>Agent Modelling Platform</b>.<br /> <br /> This is what is mentioned in - 'http://www.eclipse.org/proposals/amp/' <br /> :: <br /> <blockquote>Agent-Based Modeling (ABM), an innovative technique used to explore complex phenomenon in many domains, including economics, social sciences, bio-medicine, ecology and business operations.</blockquote><br /> The starting point is the Agent Meta-model Ecore ('ACore') for modelling the Agents.<br /> <blockquote>Agent models share characteristics with object models, but are: <br /> <br /> <b>Spatial</b>: Models have explicit environment(s) in which agents interact. (An environment need not be a physical landscape; other examples of spatial relationships include social networks or positions within a logic system.)<br /> <b>Temporal</b>: Models change over discrete units of time.<br /> <b>Autonomous</b>: Agent behaviors are activated independently from other object requests.<br /> <b>Heterogenous</b>: Agents may share behavior definitions but have apparent and distinct states and behaviors.<br /> <b>Collective</b>: Models contain large communities of agents which exhibit collaborative and competitive behaviors.<br /> <b>Emergent</b>: Agents have collective macro-behaviors that are non-obvious from agent micro-specifications.</blockquote><br /> Agent Model can be of great help where interconnected systems knowingly / unknowingly contribute to the unpredictable behaviour of real-life entities. What could be a better usecase than <a href="http://www.youtube.com/watch?v=lYp7Pq44CNM&amp;feature=related">simulating the behaviour of H1N1 virus</a> <br /> <br /> :: <b>AMP</b> can be used as a independent module in Eclipse and simply use its services (say Agent Graphical Fwk - AGF) for performing business rules, resoning tasks and dynamic visualization support.<br /> <br /> :: <b>AXF</b> - Agent Execution Framework can also be very useful even in contexts outside agents. One can simple adapt to the IEngine service of AXF to leverage the scheduling service provided by the Agent Model Engine and many other features.<br /> <br /> If we want to get your feet wet with this amazing modelling tool - here is how you can <a href="http://eclipse.org/amp/developers/building.php"> Setup AMP Environment</a><br /> <br /> Stay tuned to - http://wiki.eclipse.org/AMP/UserGuide/<br /> <br /> One can delve into the <a href="http://www.youtube.com/watch?v=abPguU0QVqw">Technical Details </a> and understand AMP architecture.<br /> <br /> Its interesting to browse through Lyle Wallis's <a href="http://blog.cause-alities.com/">observations</a> on applying systems science to business, social, and natural systems using Agent Based Modelling.<br /> <br /> Specially, its an absorbing read on <a href="http://hbr.org/2007/11/a-leaders-framework-for-decision-making/ar/1">complex systems</a>.<br /> <br /> Lyle Wallis comments - <br /> <blockquote>So I was excited to see this article in the Harvard Business Review. The authors ... ".. believe the time has come to broaden the traditional approach to leadership and decision making and form a new perspective based on complexity science." <br /> ... we can take effective management action in complex systems and create a surprising level of predictability.</blockquote><br /> Lets now look back into Eclipse modelling itself. One can now create a dynamic graph layout with moveable nodes using <a href="http://www.vogella.de/articles/EclipseZest/article.html">Zest</a><br /> <br /> <b>Reference </b>:<br /> <br /> Eclipse Zest Resources<br /> http://www.eclipse.org/gef/zest/ Eclipse Zest Homepage <br /> http://wiki.eclipse.org/index.php/GEF_Zest_Visualization Eclipse Zest Wiki <br /> http://www.eclipse.org/gef/zest/snippets.php Eclipse Zest Snippets <br /> <a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.gef/test/org.eclipse.zest.tests/src/org/eclipse/zest/tests/swt/AnimationSnippet.java?root=Tools_Project&amp;view=co">Animation using Zest</a><br /> <br /> GEF<br /> http://wiki.eclipse.org/GEF_Description2#Global_principle<br /> http://wiki.eclipse.org/GEF_Troubleshooting_Guide<br /> http://www.eclipse.org/gef/reference/digraph1.php<br /> <br /> AMP<br /> http://www.eclipse.org/amp/<br /> http://www.eclipse.org/amp/documentation/amp.pdf<br /> <br /> Modelling Article<br /> <a href="http://jasss.soc.surrey.ac.uk/11/4/12.html">Why Modelling</a><br /> <br /> All 'Agent' related terminologies @copyright - http://www.eclipse.org/amp/http://musings-on-technology.blogspot.com/2010/05/wonderland-of-modelling.htmlnoreply@blogger.com (Kaniska)0tag:blogger.com,1999:blog-1373851816248476399.post-8297854546180359018Thu, 06 May 2010 21:26:00 +00002010-06-24T03:38:46.763+05:30EclipseMaking Applications work together in EclipseEclipse as we know is a great implementation of plugin-architecture.<br /> <br /> We decouple different components of a system into bundles.<br /> plugin-architecture is very simplistic in nature, highly extensible and modular at the cost of a tricky class-loading policy.<br /> Actually Eclipse is a story of several class-loaders.<br /> It iniataites a chain of class loaders to load the plug-ins lazily as specified in component-specific manifest.mf files. <br /> If we understand its class-loading policy and learn some tricks, then we can make different third-party jars talk to each other and avoid infamous 'ClassNotFound Exception'.<br /> The immediate parent of a plug-in class loader is the Eclipse Boot Class Loader (providing access to boot.jar). The parent is the standard java system class loader which terminates the chain. The Application Class-loader which loads classes from the system's CLASSPATH is not part of the chain.<br /> That's why while loading product components, Eclipse does not look into Classpath in contrast to any other java-based client applications.<br /> On start-up, the eclipse platform builds a shadow of all the plugins by reading all the manifest files into a plug-in registry.<br /> Whenever a plugin com.xyz.myProduct is started by Eclipse Application Class, <br /> the class-loader for com.xyz.myProduct takes-off. <br /> If com.myProduct.xyz tries to access any class from another plugin com.myProduct.abc, <br /> Eclipse invokes the Plug-in Class-loader coresponding to com.myProduct.abc.<br /> That's the essence of Eclipse OSGi.<br /> <br /> Q1. How to use third-party applications while building and running my product ?<br /> Its of no use to specify third-party jars in classpath.<br /> While building the application com.myProduct, we should bundle all the required jars in a single plugin (com.myProduct.library) and expose the apis of the bundled log4j, jpox, xstream etc.<br /> <br /> Q2. How a third-party jar (log4j.jar) can see the classes from com.myProduct.xyz.jar during runtime ?<br /> Lets assume com.abc.myProduct plugin logs messages using log4j.<br /> So during runtime, log4j needs to see the classes from com.myProduct.abc plugin<br /> This can be achieved by registering log4j with Eclipse-Buddy Policy and specifying com.abc.myProduct as a buddy of log4j. <br /> # log4j Manifest.MF<br /> Bundle-Name: org.apache.log4j<br /> Bundle-Version: 1.2.13<br /> ...<br /> Eclipse-BuddyPolicy: registered<br /> <br /> # myplugin Manifest.MF<br /> Bundle-Name: com.abc.myProduct<br /> Bundle-Version: 1.0.0<br /> Requires-Bundle: org.apache.log4j,...<br /> Eclipse-RegisterBuddy: org.apache.log4j<br /> If anyone registers with log4j as its buddy, and log4j needs to find a class com.abc.myProduct.MyComponent then it will check all the buddies before throwing "ClassNotFound" Exception<br /> <br /> Q3. How can users integrate third-party jars with myProduct plugins on-the-fly ?<br /> Lets see how users can actually hack eclipse configuration files to integrate required jars on-the-fly.<br /> &gt;&gt; say user has installed a plugin com.magicScript which allows him to program using any script including jruby. But the product plugin doesn't ship the jruby jars i.e. does not adopt any of the above mechanisms.<br /> So user have to add JRUBY_MOME in eclipse.ini. Now when eclipse will start up it will set jruby home in the path.<br /> Lets assume the com.magicScript plugin already depends on a plugin com.magicScript.library containing a lib folder.<br /> Next the jruby.jar needs to be placed inside the lib folder and the location lib\jruby.jar needs to be specified in the manifest.mf of com.magicScript.library.<br /> Finally, starting eclipse with -clean -Intialization option will automatically first set Jruby path and then invoking magicScript perspective will trigger the classLoader for the bundle com.magicScript.library which in turn will load jruby classes from the jar (as specified in manifest.mf).<br /> Thus user will be able to code/compile/run jruby.<br /> This same trick can be used if we want the user to dynamically specify a DB driver jar and connect to a db using a plugin already installed in his environment.<br /> Say com.myProduct.dbExplorer plugin will load classes from the jar to be specified by users during runtime.<br /> (4) So far we depend only on Eclipse Bundle-ClassLoader and we configure eclipse in such a way (either development-time / runtime) that all required jars will be loaded by the classloader of the bundle in which jars are packed.<br /> But what if we need to access a class which can not be loaded by the bundle-classloader ?<br /> We need to set certain jars in custom classloader so the classes bundled in the jar can be loaded on demand !<br /> <br /> A typical scenario is com.xyz.MyProduct.library contains scriptDebugger.jar (some 3rdparty jar) whose api need to be invoked during runtime and the api class will access some class of jruby.jar (may be specified by user during runtime) which can't be packed inside the product.<br /> //The follwoing piece-of-code should be part of the com.xyz.myProduct.ScriptManager to load classes from jruby jar that user will specify during runtime.<br /> // gather the names and loacation of jars as provided by user through preference page after product is deployed.<br /> String[] jarslist = DynamicJarLoader.getThirdPartyJars();<br /> URL[] jarURLs = new URL[jarslist.length];<br /> JarFileLoader newLoader = new JarFileLoader(jarURLs);<br /> for (int i = 0; i &lt; jarslist.length; i++) {<br /> newLoader.addFile (jarslist[i]); <br /> }<br /> class JarFileLoader extends URLClassLoader<br /> {<br /> public JarFileLoader (URL[] urls)<br /> {<br /> super (urls);<br /> }<br /> <br /> public void addFile (String path) throws MalformedURLException<br /> {<br /> String urlPath = "jar:file://" + path + "!/";<br /> addURL (new URL (urlPath));<br /> }<br /> }<br /> Now swap bundleclassloader with your classloader !<br /> ClassLoader currentLoader = Thread.currentThread().getContextClassLoader();<br /> try {<br /> current.setContextClassLoader( newLoader);<br /> // Either Load reqd. classes and work with them<br /> newLoader.loadClass ("org.jruby.JRubyClient");<br /> newLoader.loadClass ("org.hsqldb.jdbcDriver");<br /> newLoader.loadClass("oracle.jdbc.driver.OracleDriver");<br /> // Or invoke some other api (of scriptRunner.jar which will load JRuby classes to compile/run jruby script) <br /> }catch(Exception exception) {<br /> exception.printStackTrace();<br /> }finally { // Restore Eclipse Bundle Class-loader<br /> current.setContextClassLoader(oldLoader);<br /> }<br /> further reading : http://www.eclipsezone.com/articles/eclipse-vms/http://musings-on-technology.blogspot.com/2010/05/making-applications-work-together-in.htmlnoreply@blogger.com (Kaniska)0
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0">
<channel>
<atom:id>tag:blogger.com,1999:blog-1373851816248476399</atom:id>
<lastBuildDate>Thu, 10 Oct 2024 14:12:24 +0000</lastBuildDate>
<category>Eclipse</category>
<category>Scalability</category>
<category>API Design</category>
<category>Architecture</category>
<category>Big Data</category>
<category>Cache</category>
<category>Core Java</category>
<category>Data Transformer</category>
<category>Eclipse Modelling 3D EMF ZEST GEF</category>
<category>HTML5</category>
<category>Hibernate</category>
<category>JFace Dialog</category>
<category>Multi-Tenancy</category>
<category>PaaS</category>
<category>Performance Monitoring</category>
<category>Productivity Tools</category>
<category>concurrency</category>
<category>enterprise 2.0</category>
<category>jMaki</category>
<category>java ME</category>
<category>javaFX</category>
<category>jdk</category>
<category>mashlet</category>
<category>mashup</category>
<category>mongodb</category>
<title>Musings on Technology</title>
<description/>
<link>http://musings-on-technology.blogspot.com/</link>
<managingEditor>noreply@blogger.com (Kaniska)</managingEditor>
<generator>Blogger</generator>
<openSearch:totalResults>55</openSearch:totalResults>
<openSearch:startIndex>1</openSearch:startIndex>
<openSearch:itemsPerPage>25</openSearch:itemsPerPage>
<item>
<guid isPermaLink="false">tag:blogger.com,1999:blog-1373851816248476399.post-7592655643796574234</guid>
<pubDate>Thu, 01 Mar 2012 05:59:00 +0000</pubDate>
<atom:updated>2012-03-01T11:50:56.576+05:30</atom:updated>
<title>Setup Hadoop and Hbase Environment</title>
<description><div dir="ltr" style="text-align: left;" trbidi="on">Setup Apache BigTop<br /> <br /> <a href="http://apachebigtop.pbworks.com/w/page/48434924/FrontPage">http://apachebigtop.pbworks.com/w/page/48434924/FrontPage</a><br /> <span style="background-color: white; color: #cb182f; font-family: Arial, Helvetica, sans-serif; font-size: 26px; line-height: 28px; text-align: -webkit-auto;"><br /> </span><br /> <span style="background-color: white; font-family: Arial, Helvetica, sans-serif; line-height: 28px; text-align: -webkit-auto;">How to develop Big Data Pipelines for Hadoop</span><br /> <span style="background-color: white; font-family: Arial, Helvetica, sans-serif; line-height: 28px; text-align: -webkit-auto;">I Didn't Know You Could Do All that with Hadoop</span><br /> <span style="background-color: white; font-family: Arial, Helvetica, sans-serif; line-height: 28px; text-align: -webkit-auto;">Storm: distributed and fault-tolerant realtime computation</span><br /> <span style="background-color: white; font-family: Arial, Helvetica, sans-serif; line-height: 28px; text-align: -webkit-auto;">Hadoop Plugin for MongoDB: The Elephant in the Room</span><br /> <span style="background-color: white; font-family: Arial, Helvetica, sans-serif; line-height: 28px; text-align: -webkit-auto;"><br /> </span><br /> <span style="background-color: white; line-height: 28px; text-align: -webkit-auto;"><span style="font-family: Arial, Helvetica, sans-serif;">StrataConf 2012 Hive Tutorial</span></span><br /> <a href="http://assets.en.oreilly.com/1/event/75/Hadoop%20Data%20Warehousing%20with%20Hive%20Paper.pdf">http://assets.en.oreilly.com/1/event/75/Hadoop%20Data%20Warehousing%20with%20Hive%20Paper.pdf</a><br /> <span style="background-color: white; font-family: Arial, Helvetica, sans-serif; line-height: 28px; text-align: -webkit-auto;">Hadoop Data Warehousing with Hive</span><br /> <br /> Cloudera Hbase Training<br /> <a href="http://university.cloudera.com/training/apache_hbase/hbase.html">http://university.cloudera.com/training/apache_hbase/hbase.html</a> <br /> <br /> <br /> <h1 class="firstHeading gumax-firstHeading" id="firstHeading" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: none; background-origin: initial; border-bottom-color: rgb(221, 221, 221); border-bottom-style: solid; border-bottom-width: 1px; color: #0099cc; font-family: 'Trebuchet MS', Arial, Verdana; font-size: 21px; font-weight: normal; line-height: 1.2em; margin-bottom: 0.1em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto;">Hadoop on Amazon AWS</h1><br /> <a href="http://cs.smith.edu/dftwiki/index.php/Hadoop_Tutorial_3_--_Hadoop_on_Amazon_AWS">http://cs.smith.edu/dftwiki/index.php/Hadoop_Tutorial_3_--_Hadoop_on_Amazon_AWS</a> <br /> <br /> <span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 22px; text-align: -webkit-auto;">Build and Run Hadoop Java program with Ant and Maven</span><br /> <br /> <a href="http://stones333.blogspot.com/2012/02/build-and-run-hadoop-java-program-with.html">http://stones333.blogspot.com/2012/02/build-and-run-hadoop-java-program-with.html</a> <br /> <br /> <span style="background-color: white; color: #444444; font-family: 'Segoe UI', 'Lucida Grande', Arial; line-height: 31px;"><b>Machine Learning on Big Data with MapReduce</b></span> <br /> <a href="http://machinelearningbigdata.pbworks.com/w/page/37651454/FrontPage">http://machinelearningbigdata.pbworks.com/w/page/37651454/FrontPage</a> <br /> <br /> <b>Hbase &amp; NoSQL&nbsp;Comparison&nbsp;:</b><br /> <a href="http://kkovacs.eu/cassandra-vs-mongodb-vs-couchdb-vs-redis">http://kkovacs.eu/cassandra-vs-mongodb-vs-couchdb-vs-redis</a> <br /> <a href="http://ria101.wordpress.com/2010/02/24/hbase-vs-cassandra-why-we-moved/">http://ria101.wordpress.com/2010/02/24/hbase-vs-cassandra-why-we-moved/</a> <br /> <a href="http://natishalom.typepad.com/nati_shaloms_blog/hbase/">http://natishalom.typepad.com/nati_shaloms_blog/hbase/</a> <br /> <a href="http://natishalom.typepad.com/nati_shaloms_blog/2011/07/real-time-analytics-for-big-data-an-alternative-approach.html">http://natishalom.typepad.com/nati_shaloms_blog/2011/07/real-time-analytics-for-big-data-an-alternative-approach.html</a> <br /> <br /> Beyond Hadoop : Stream based Messaging (Storm / Kafka )<br /> <a href="http://natishalom.typepad.com/nati_shaloms_blog/2011/07/real-time-analytics-for-big-data-an-alternative-approach-to-facebooks-new-realtime-analytics-system.html">http://natishalom.typepad.com/nati_shaloms_blog/2011/07/real-time-analytics-for-big-data-an-alternative-approach-to-facebooks-new-realtime-analytics-system.html</a> <br /> <br /> </div></description>
<link>http://musings-on-technology.blogspot.com/2012/03/setup-hadoop-and-hbase-environment.html</link>
<author>noreply@blogger.com (Kaniska)</author>
<thr:total>3</thr:total>
</item>
<item>
<guid isPermaLink="false">tag:blogger.com,1999:blog-1373851816248476399.post-3138922585636962718</guid>
<pubDate>Sun, 12 Feb 2012 06:22:00 +0000</pubDate>
<atom:updated>2012-02-12T11:59:14.171+05:30</atom:updated>
<category domain="http://www.blogger.com/atom/ns#">Multi-Tenancy</category>
<title>Building Multi-Tenant Platform for Data Acquisition, Analysis Visualization</title>
<description><div dir="ltr" style="text-align: left;" trbidi="on"><span style="color: #0c343d;"><b>Multi-Tenant Data Access Security :</b></span><br /> Cross-Organization and Cross-Application SSO<br /> <br /> <h3 class="r" style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: medium; font-weight: normal; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: hidden; overflow-y: hidden; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto; text-overflow: ellipsis; white-space: nowrap;"><a class="l" href="http://www.onelogin.com/" style="color: #1122cc; cursor: pointer;"><span style="color: #1122cc;"><span style="cursor: pointer;">Single sign-on for the cloud and SaaS -</span></span><span style="color: #1122cc;"><span style="cursor: pointer;">&nbsp;</span></span><em style="color: #1122cc; cursor: pointer; font-style: normal; font-weight: bold;">OneLogin</em></a></h3><h3 class="r" style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: medium; font-weight: normal; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: hidden; overflow-y: hidden; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto; text-overflow: ellipsis; white-space: nowrap;"><br /> </h3><div><b style="color: #0c343d;">Multi-Tenant&nbsp;</b><b>Data Compliance :</b></div><div><div>&nbsp;Satisfy Data Compliance and Regulations and Data Encryption</div><div>Reference : <a href="http://www.sesamesoftware.com/pdf-docs/Satisfying_Compliance_Regulations_for_CRM_Data.pdf">http://www.sesamesoftware.com/pdf-docs/Satisfying_Compliance_Regulations_for_CRM_Data.pdf&nbsp;</a></div></div><div><br /> </div><div><b style="color: #0c343d;">Multi-Tenant&nbsp;</b><b>Data Acquisition :</b></div><div><div>Multi-Tenant Data Acquisition , MDM, Data Cleansing, Data Mapping - Component :</div><div>Capture data from Multiple Apps for Multiple Tenants through the same 'Integration Platform'</div><div>"If it's Not Multitenant, it's Not Really SaaS." --</div><div><a href="http://www.ebizq.net/blogs/connectedweb/2010/02/why_your_cloud_applications_sh.php">http://www.ebizq.net/blogs/connectedweb/2010/02/why_your_cloud_applications_sh.php</a></div><div><a href="http://www.boomi.com/products/technical/platform_architecture">http://www.boomi.com/products/technical/platform_architecture</a></div><div><a href="http://blogs.boomi.com/bod/2010/06/boomi-suggest-the-power-of-multitenancy.html">http://blogs.boomi.com/bod/2010/06/boomi-suggest-the-power-of-multitenancy.html</a></div></div><div><br /> </div><div>Mule+ion , Boomi+atom, Cast~Iron</div><div><br /> </div><div><b style="color: #0c343d;">Multi-Tenant&nbsp;</b><b>Data Storage :</b></div><div><a href="http://msdn.microsoft.com/en-us/library/aa479086.aspx">http://msdn.microsoft.com/en-us/library/aa479086.aspx</a></div><div>Scalable Elastic NoSQL or Partitioned RDBMS</div><div><br /> <b>Multi-Tenant Metadata Manager and Application Provisioning :</b><br /> <br /> <br /> </div><div><b style="color: #0c343d;">Multi-Tenant&nbsp;</b><b>Data Analysis :</b></div><div>Extensible Rules and Queries - configurable across tenants.</div><div>Tenant-Aware Resource Access Rules</div><div><b><br /> </b></div><div><b style="color: #0c343d;">Multi-Tenant&nbsp;</b><b>Data Service API:</b></div><div>Tenant-aware Resource Access Rules.</div><div>Tenant-aware Server, Sessions and Cache.<br /> Tenant-aware Rest Services , Work-flow and Rules-Engine</div><div><br /> </div><div><b style="color: #0c343d;">Multi-Tenant&nbsp;</b><b>Data Apps Server :</b> (Cloud-enabled and Tenant-aware )</div><div><div>&nbsp;Application Resource Allocation (App Server / DB Connection / Fail-over ) for all the tenants without stepping into each other's resources.</div><div>POD System is a popular recommended Multi-Tenant Model</div><div>-- &nbsp;<a href="http://connectedco.com/2011/04/18/the-future-is-podular/">http://connectedco.com/2011/04/18/the-future-is-podular/</a>&nbsp;</div><div>-- PaaS script will automatically roll out new resources ... &nbsp;its a mini-combo of (app-server, db, vm for a logical group of tenants)</div><div>-- <a href="http://www.cisco.com/en/US/docs/solutions/Enterprise/Data_Center/VMDC/2.0/large_pod_design_guide/Large_Pod_Design_Guide.pdf">http://www.cisco.com/en/US/docs/solutions/Enterprise/Data_Center/VMDC/2.0/large_pod_design_guide/Large_Pod_Design_Guide.pdf</a></div></div><div><br /> </div><div><b style="color: #0c343d;">Multi-Tenant&nbsp;</b><b>Data Viz :</b></div><div>Multi-Tenant Charts/Graphs and Configurable Dashboards.</div><div>Pentaho , YellowFin</div></div></description>
<link>http://musings-on-technology.blogspot.com/2012/02/building-multi-tenant-platform-for-data.html</link>
<author>noreply@blogger.com (Kaniska)</author>
<thr:total>0</thr:total>
</item>
<item>
<guid isPermaLink="false">tag:blogger.com,1999:blog-1373851816248476399.post-2338766022428554270</guid>
<pubDate>Sun, 12 Feb 2012 04:44:00 +0000</pubDate>
<atom:updated>2012-02-12T10:14:04.725+05:30</atom:updated>
<title>Securing Enterprise Application Access : Learning from Salesforce</title>
<description><div dir="ltr" style="text-align: left;" trbidi="on"><br /> <div class="MsoNormal"><span style="color: #1f497d; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;"><o:p>Securing Enterprise Application Access : &nbsp;Learning from Salesforce&nbsp;</o:p></span></div><div class="MsoNormal"><span style="color: #1f497d; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;"><o:p><br /> </o:p></span></div><div class="MsoNormal"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">1 : &nbsp;<b><span style="color: #17375e;">SFDC Tab invokes the following url to access the application :</span></b><span style="color: #17375e;"><o:p></o:p></span></span></div><div class="MsoNormal" style="text-indent: .5in;"><span lang="PT-BR" style="color: #1f497d; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt; mso-ansi-language: PT-BR;">(a)</span><span lang="PT-BR" style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt; mso-ansi-language: PT-BR;"> &nbsp;</span><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;"><a href="http://uat.dellcloudapplications.com/docs/secure_access/validate.php?location=%7B%21API.Partner_Server_URL_220%7D&amp;session_id=%7B%21API.Session_ID%7D" target="_blank"><span lang="PT-BR" style="color: windowtext; mso-ansi-language: PT-BR;">https://mysite.com/secure_access/validate.php?location={!API.Partner_Server_URL_220}&amp;session_id={!API.Session_ID}</span></a></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">2 : &nbsp;</span><b style="font-family: Arial, sans-serif; font-size: 15px;"><span style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #17375e;">Web Request Verification :&nbsp;</span></b><b style="font-family: Arial, sans-serif; font-size: 11pt;"><span style="color: #17375e;">Load Balancer Level :</span></b></div><div class="MsoListParagraph" style="margin-left: 57.0pt; mso-list: l0 level1 lfo1; text-indent: -.25in;"><!--[if !supportLists]--><span style="color: #1f497d; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt; mso-bidi-font-weight: bold; mso-fareast-font-family: Arial;">(a)<span style="font-family: 'Times New Roman'; font-size: 7pt;">&nbsp; </span></span><!--[endif]--><b><span style="color: #953735; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">- We need to perform referral check and IP range check<o:p></o:p></span></b></div><div class="MsoListParagraph" style="margin-left: 57.0pt; mso-list: l0 level1 lfo1; text-indent: -.25in;"><span style="color: #1f497d; font-family: Arial, sans-serif;"><span style="font-size: 15px;"><br /> </span></span></div><div class="MsoNormal"><span style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; font-family: Arial, sans-serif; font-size: 11pt;">Vulnerability Protection :<b>&nbsp;(</b></span><span style="font-family: Arial, sans-serif; font-size: 11pt;"><a href="http://wiki.developerforce.com/index.php/Secure_Coding_Single_Sign_On">http://wiki.developerforce.com/index.php/Secure_Coding_Single_Sign_On</a><span style="color: #1f497d;">&nbsp;</span>)</span></div><div style="font-style: inherit; line-height: 15pt; margin-bottom: 6pt; margin-left: 0.5in; margin-right: 0in; margin-top: 4.8pt; outline-width: 0px;"><span style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; font-family: Arial, sans-serif; font-size: 11pt;">Below is the regular expression to validate legitimate API Partner Server URL servers:<o:p></o:p></span></div><div class="MsoNormal" style="line-height: 15pt; margin-bottom: 1.2pt; margin-left: 0.75in; margin-right: 0in; margin-top: 0in; text-indent: -0.25in;"><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; font-family: Arial, sans-serif; font-size: 11pt;"><a href="https://[%5E/?%5d+\\.(sales|visual\\.)force\\.com/services/(S|s)(O|o)(A|a)(P|p)/(u|c)/.*"><span style="color: windowtext;">https://[^/?]+\\.(sales|visual\\.)force\\.com/services/(S|s)(O|o)(A|a)(P|p)/(u|c)/.*</span></a><o:p></o:p></span></div><div style="font-style: inherit; line-height: 15pt; margin-bottom: 0.0001pt; margin-left: 0.5in; margin-right: 0in; margin-top: 0in; outline-width: 0px;"><span style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; font-family: Arial, sans-serif; font-size: 11pt;">To summarize the above regular expression, it ensures that the URL starts with ‘<a href="https://xn--evg/" target="_blank" title="https://’"><span style="border-bottom-color: windowtext; border-bottom-style: none; border-bottom-width: 1pt; border-image: initial; border-left-color: windowtext; border-left-style: none; border-left-width: 1pt; border-right-color: windowtext; border-right-style: none; border-right-width: 1pt; border-top-color: windowtext; border-top-style: none; border-top-width: 1pt; color: windowtext; padding-bottom: 0in; padding-left: 0in; padding-right: 0in; padding-top: 0in; text-decoration: none;">https://’</span></a>, followed by a character other than ‘/ ‘ or '?' for 1 or more times, followed by a ‘.’, followed by ‘sales’ or ‘visual.’ followed by ‘<a href="http://force.com/services/SOAP/" target="_blank"><span style="color: windowtext;">force.com/services/SOAP/</span></a>’, followed by ‘u’ or ‘c’, followed by ‘/’. This will allow:<o:p></o:p></span></div><div class="MsoNormal" style="line-height: 15pt; margin-left: 0.75in; text-indent: -0.25in;"><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; font-family: Arial, sans-serif; font-size: 11pt;"><a href="https://%2A.salesforce.com/services/SOAP/u/" target="_blank" title="https://*.salesforce.com/services/SOAP/u/"><span style="border-bottom-color: windowtext; border-bottom-style: none; border-bottom-width: 1pt; border-image: initial; border-left-color: windowtext; border-left-style: none; border-left-width: 1pt; border-right-color: windowtext; border-right-style: none; border-right-width: 1pt; border-top-color: windowtext; border-top-style: none; border-top-width: 1pt; color: windowtext; padding-bottom: 0in; padding-left: 0in; padding-right: 0in; padding-top: 0in; text-decoration: none;">https://*.salesforce.com/services/SOAP/u/</span></a><o:p></o:p></span></div><div class="MsoNormal" style="line-height: 15pt; margin-left: 0.75in; text-indent: -0.25in;"><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; font-family: Arial, sans-serif; font-size: 11pt;"><a href="https://%2A.salesforce.com/services/SOAP/c/" target="_blank" title="https://*.salesforce.com/services/SOAP/c/"><span style="border-bottom-color: windowtext; border-bottom-style: none; border-bottom-width: 1pt; border-image: initial; border-left-color: windowtext; border-left-style: none; border-left-width: 1pt; border-right-color: windowtext; border-right-style: none; border-right-width: 1pt; border-top-color: windowtext; border-top-style: none; border-top-width: 1pt; color: windowtext; padding-bottom: 0in; padding-left: 0in; padding-right: 0in; padding-top: 0in; text-decoration: none;">https://*.salesforce.com/services/SOAP/c/</span></a><o:p></o:p></span></div><div class="MsoNormal" style="line-height: 15pt; margin-left: 0.75in; text-indent: -0.25in;"><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; font-family: Arial, sans-serif; font-size: 11pt;"><a href="https://%2A.visual.force.com/services/SOAP/u/" target="_blank" title="https://*.visual.force.com/services/SOAP/u/"><span style="border-bottom-color: windowtext; border-bottom-style: none; border-bottom-width: 1pt; border-image: initial; border-left-color: windowtext; border-left-style: none; border-left-width: 1pt; border-right-color: windowtext; border-right-style: none; border-right-width: 1pt; border-top-color: windowtext; border-top-style: none; border-top-width: 1pt; color: windowtext; padding-bottom: 0in; padding-left: 0in; padding-right: 0in; padding-top: 0in; text-decoration: none;">https://*.visual.force.com/services/SOAP/u/</span></a><o:p></o:p></span></div><div class="MsoNormal" style="line-height: 15pt; margin-left: 0.75in; text-indent: -0.25in;"><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; font-family: Arial, sans-serif; font-size: 11pt;"><a href="https://%2A.visual.force.com/services/SOAP/c/" target="_blank" title="https://*.visual.force.com/services/SOAP/c/"><span style="border-bottom-color: windowtext; border-bottom-style: none; border-bottom-width: 1pt; border-image: initial; border-left-color: windowtext; border-left-style: none; border-left-width: 1pt; border-right-color: windowtext; border-right-style: none; border-right-width: 1pt; border-top-color: windowtext; border-top-style: none; border-top-width: 1pt; color: windowtext; padding-bottom: 0in; padding-left: 0in; padding-right: 0in; padding-top: 0in; text-decoration: none;">https://*.visual.force.com/services/SOAP/c/</span></a></span></div><div class="MsoNormal"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;"><br /> </span></div><div class="MsoNormal"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">3 : <b><span style="color: #17375e;">Delegate the request to validator &nbsp;(php / javascript / servlet filter )&nbsp;</span></b></span></div><div class="MsoNormal"><span style="color: #1f497d; font-family: Arial, sans-serif; font-size: 11pt; text-indent: -0.25in;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(a)<span style="font-family: 'Times New Roman'; font-size: 7pt;">&nbsp; </span></span><span style="font-family: Arial, sans-serif; font-size: 11pt; text-indent: -0.25in;">we can <b><span style="color: #953735;">double-check if request coming from salesforce</span></b></span></div><div class="MsoNormal"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #1f497d;">(b)</span> <b><span style="color: #953735;">validate the session-id by making a reverse call</span></b><span style="color: #953735;"> </span>to SFDC.<o:p></o:p></span></div><div class="MsoNormal"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #1f497d;">i.</span>&nbsp;- simply <b><span style="color: #953735;">retrieve the UserInfo </span></b>for that connection <b><span style="color: #953735;">and extract the user-id.</span></b><o:p></o:p></span></div><div class="MsoNormal"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if there is error condition, then forward to trial page<span style="color: #1f497d;"> or whatever relevant</span>.</span><b style="font-family: Arial, sans-serif; font-size: 11pt;"><span style="color: #953735;">verify if the (c)&nbsp;</span></b><b style="color: #1f497d; font-family: Arial, sans-serif; font-size: 15px;">User Authorization : Verify if&nbsp;</b><b style="font-family: Arial, sans-serif; font-size: 11pt;"><span style="color: #953735;">user-id is registered</span></b><span style="font-family: Arial, sans-serif; font-size: 11pt;">. (highly recommended by salesforce)</span></div><div class="MsoNormal"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #1f497d;">iii</span>&nbsp;- another layer of security <span style="color: #1f497d;">–</span> <b><span style="color: #953735;">verify call is initiated by salesforce by using private security</span></b><span style="color: #953735;"> </span>certificate from SalesForce<o:p></o:p></span></div><div class="MsoNormal"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Include this certificate in every http / soap call to SFDC from validate.php.<o:p></o:p></span></div><div class="MsoNormal"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<o:p></o:p></span><a href="http://wiki.developerforce.com/index.php/Single_Sign_On_for_Composite_Apps" style="font-family: Arial, sans-serif; font-size: 15px;">http://wiki.developerforce.com/index.php/Single_Sign_On_for_Composite_Apps</a><span style="color: #1f497d; font-family: Arial, sans-serif; font-size: 15px;">&nbsp; &nbsp;</span></div><div class="MsoNormal"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;"><br /> </span></div><div class="MsoNormal"><span style="color: #1f497d; font-family: Arial, sans-serif; font-size: 11pt;">4. </span><b><span style="color: #17375e; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">Enable SSL in uat-apache</span></b></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><b><span style="color: #17375e; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">5. U</span></b><b><span style="color: #17375e; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">se SalesForce Certificate :<o:p></o:p></span></b></div><div class="MsoNormal"><span style="background: white; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">This certificate is meant to identify that the request is coming from&nbsp;<a href="http://salesforce.com/" target="_blank"><span style="color: windowtext;">salesforce.com</span></a>, not a specific user.</span><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;"><o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;"><a href="http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_om_outboundmessaging_setting_up.htm#om_user_profile">http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_om_outboundmessaging_setting_up.htm#om_user_profile</a><span style="color: #1f497d;"> </span><o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><span style="background: white; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">Your application (endpoint) server's SSL/TLS may be configured to require client certificates (two-way SSL/TLS), in order to validate the identity of the&nbsp;Salesforce&nbsp;server when it takes the role of client to your server. If this is the case, you can download the&nbsp;Salesforce&nbsp;client certificate from the&nbsp;Salesforce&nbsp;application user interface.&nbsp;</span><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;"><o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><span style="color: #1f497d; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">6. </span><b><span style="color: #17375e; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">Enable SSO (in future)&nbsp;:<o:p></o:p></span></b></div><div class="MsoNormal"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">As per SalesForce : - &nbsp;<a href="https://na7.salesforce.com/help/doc/en/sso_delauthentication_configuring.htm">https://na7.salesforce.com/help/doc/en/sso_delauthentication_configuring.htm</a><span style="color: #1f497d;"> </span><o:p></o:p></span></div><div class="MsoNormal"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">Use -&nbsp;<b><span style="background: white;">Delegated Authentication WSDL</span></b><o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><span style="background: white; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">If Single Sign-On (SSO) is enabled for your organization, users who access the API or a desktop client cannot log in to&nbsp;Salesforce&nbsp;unless their IP address is included on your organization's list of trusted IP addresses or on their profile, if their profile has IP address restrictions set. Futhermore, the delegated authentication authority usually handles login lockout policies for users with the “Uses Single Sign-On” permission. However, if the security token is enabled for your organization, then your organization's login lockout settings determine the number of times a user can attempt to log in with an invalid security token before being locked out of&nbsp;Salesforce. For more information, see “Setting Login Restrictions” and “Setting Password Policies” in the online help.</span><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;"><o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><b><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">More details :&nbsp;</span></b><span style="background: white; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;"><a href="http://www.salesforce.com/docs/developer/cookbook/Content/sso_delegated.htm">http://www.salesforce.com/docs/developer/cookbook/Content/sso_delegated.htm</a></span><span style="color: #1f497d; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;"> </span><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;"><o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><b><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">Broad Topics on application security :</span></b><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;">&nbsp;<a href="http://wiki.developerforce.com/index.php/Apex_and_Visualforce_Security_Tips">http://wiki.developerforce.com/index.php/Apex_and_Visualforce_Security_Tips</a><span style="color: #1f497d;"> </span><o:p></o:p></span></div><div class="MsoNormal"><span style="background: white; color: grey; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt;">1.&nbsp;<a href="http://wiki.developerforce.com/index.php/Secure_Coding_Cross_Site_Scripting" target="_blank" title="http://wiki.developerforce.com/index.php/Secure_Coding_Cross_Site_Scripting"><span style="border: none windowtext 1.0pt; color: #3366bb; font-family: inherit; mso-border-alt: none windowtext 0in; padding: 0in; text-decoration: none; text-underline: none;">Cross-Site Scripting</span></a><br /> 2.&nbsp;<a href="http://wiki.developerforce.com/index.php/Secure_Coding_SQL_Injection" target="_blank" title="http://wiki.developerforce.com/index.php/Secure_Coding_SQL_Injection"><span style="border: none windowtext 1.0pt; color: #3366bb; font-family: inherit; mso-border-alt: none windowtext 0in; padding: 0in; text-decoration: none; text-underline: none;">S(O)QL Injection</span></a><br /> 3.&nbsp;<a href="http://wiki.developerforce.com/index.php/Secure_Coding_Cross_Site_Request_Forgery" target="_blank" title="http://wiki.developerforce.com/index.php/Secure_Coding_Cross_Site_Request_Forgery"><span style="border: none windowtext 1.0pt; color: #3366bb; font-family: inherit; mso-border-alt: none windowtext 0in; padding: 0in; text-decoration: none; text-underline: none;">Cross Site Request Forgery</span></a><br /> 4.&nbsp;<a href="http://wiki.developerforce.com/index.php/Secure_Coding_Secure_Communications" target="_blank" title="http://wiki.developerforce.com/index.php/Secure_Coding_Secure_Communications"><span style="border: none windowtext 1.0pt; color: #3366bb; font-family: inherit; mso-border-alt: none windowtext 0in; padding: 0in; text-decoration: none; text-underline: none;">Secure Communications and Cookies</span></a><br /> 5.&nbsp;<a href="http://wiki.developerforce.com/index.php/Secure_Coding_Storing_Secrets" target="_blank" title="http://wiki.developerforce.com/index.php/Secure_Coding_Storing_Secrets"><span style="border: none windowtext 1.0pt; color: #3366bb; font-family: inherit; mso-border-alt: none windowtext 0in; padding: 0in; text-decoration: none; text-underline: none;">Storing Secrets</span></a><br /> 6.&nbsp;<a href="http://wiki.developerforce.com/index.php/Secure_Coding_Arbitrary_Redirect" target="_blank" title="http://wiki.developerforce.com/index.php/Secure_Coding_Arbitrary_Redirect"><span style="border: none windowtext 1.0pt; color: #3366bb; font-family: inherit; mso-border-alt: none windowtext 0in; padding: 0in; text-decoration: none; text-underline: none;">Arbitrary Redirects</span></a><br /> 7.&nbsp;<a href="http://wiki.developerforce.com/index.php/Secure_Coding_Access_Control" target="_blank" title="http://wiki.developerforce.com/index.php/Secure_Coding_Access_Control"><span style="border: none windowtext 1.0pt; color: #3366bb; font-family: inherit; mso-border-alt: none windowtext 0in; padding: 0in; text-decoration: none; text-underline: none;">Access Control</span></a><br /> 8.&nbsp;<a href="http://wiki.developerforce.com/index.php/Testing_CRUD_and_FLS_Enforcement" target="_blank" title="http://wiki.developerforce.com/index.php/Testing_CRUD_and_FLS_Enforcement"><span style="border: none windowtext 1.0pt; color: #3366bb; font-family: inherit; mso-border-alt: none windowtext 0in; padding: 0in; text-decoration: none; text-underline: none;">Enforcing CRUD and FLS (Force.com)</span></a><br /> 9.&nbsp;<a href="http://wiki.developerforce.com/index.php/Secure_Coding_Single_Sign_On" target="_blank" title="http://wiki.developerforce.com/index.php/Secure_Coding_Single_Sign_On"><span style="border: none windowtext 1.0pt; color: #3366bb; font-family: inherit; mso-border-alt: none windowtext 0in; padding: 0in; text-decoration: none; text-underline: none;">SSO for Composite Apps</span></a>&nbsp;</span><o:p></o:p></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><span style="color: #632523; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 11.0pt;"><o:p>&nbsp;</o:p></span><span style="color: #1f497d; font-family: Calibri, sans-serif; font-size: 11pt;">Just like PHP Toolkit / Java Client API for SalesForce, the ajax toolkit is also very simple to use&nbsp;&nbsp;</span><span style="font-family: Arial, sans-serif; font-size: 11pt;"><a href="http://www.salesforce.com/us/developer/docs/ajax/apex_ajax.pdf%20%0d2"><span style="text-decoration: none;">http://www.salesforce.com/us/developer/docs/ajax/apex_ajax.pdf</span></a></span></div></div></description>
<link>http://musings-on-technology.blogspot.com/2012/02/securing-enterprise-application-access.html</link>
<author>noreply@blogger.com (Kaniska)</author>
<thr:total>0</thr:total>
</item>
<item>
<guid isPermaLink="false">tag:blogger.com,1999:blog-1373851816248476399.post-4886439797205340114</guid>
<pubDate>Sat, 31 Dec 2011 23:06:00 +0000</pubDate>
<atom:updated>2012-01-01T04:36:57.588+05:30</atom:updated>
<title>Online CS Courses</title>
<description><div dir="ltr" style="text-align: left;" trbidi="on"><a href="http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/">http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/</a><br /> <span style="color: #a33033; font-family: Verdana, Arial, Helvetica, sans-serif;">Introduction to Computer Science and Programming</span><br /> <span style="color: #a33033; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 1.6em;"><br /> </span><br /> <a href="http://web.mit.edu/newsoffice/2011/mitx-faq-1219.html">http://web.mit.edu/newsoffice/2011/mitx-faq-1219.html</a> <br /> <br /> <h1 style="background-color: white; font-family: Arial, Helvetica, sans-serif; line-height: 24px; margin-bottom: 5px; margin-top: 0px;"><span style="font-size: small;">What is&nbsp;<i>MITx</i>?</span></h1><div><br /> </div><div><a href="http://academicearth.org/courses/programming-methodology">http://academicearth.org/courses/programming-methodology</a> </div><div><h1 style="background-color: #efefef; color: #333333; font-family: Arial, Helvetica, sans-serif; line-height: 1em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto;"><span style="font-size: x-small;">Computer Science I: Programming Methodology</span></h1></div></div></description>
<link>http://musings-on-technology.blogspot.com/2012/01/online-cs-courses.html</link>
<author>noreply@blogger.com (Kaniska)</author>
<thr:total>0</thr:total>
</item>
<item>
<guid isPermaLink="false">tag:blogger.com,1999:blog-1373851816248476399.post-7705330480673396222</guid>
<pubDate>Sat, 31 Dec 2011 22:48:00 +0000</pubDate>
<atom:updated>2012-01-05T09:56:57.046+05:30</atom:updated>
<title>Lightweight Persistence Service for Dynamic Entities</title>
<description><div dir="ltr" style="text-align: left;" trbidi="on"><br /> <div style="background-color: white; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 19px; margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto;"><strong style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Goal :</strong></div><ul style="background-color: white; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 19px; margin-bottom: 0px; margin-left: 2.6em; margin-right: 0px; margin-top: 1.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto;"><li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Persist incoming stream of Objects of into the Database.</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Parse the incoming XML/Json data to extract "Object of similar type" (i.e. a particular Business Entity) .</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">The Business Entity may have a fixed set of attributes or a dynamically changing set of attributes.</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">We should not create/maintain ORM layer and no need for POJO conversions from/to wsdl/http streams.</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">We should keep the&nbsp; persistence service layer very very light-weight.</li> </ul><div style="background-color: white; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 19px; margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto;"><strong style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Setup :</strong></div><ul style="background-color: white; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 19px; margin-bottom: 0px; margin-left: 2.6em; margin-right: 0px; margin-top: 1.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto;"><li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">mongodb2.0.1 (A database named "staging" needs to be created in MongoDB)</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">spring-data-mongodb 1.0.0.M4, mongo-java-driver 2.5.2 (and all other dependencies specified in pom.xml)</li> </ul><div style="background-color: white; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 19px; margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto;"><strong style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Development Environment :</strong>&nbsp;SpringSource Tool Suite - 2.8.1.RELEASE</div><div style="background-color: white; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 19px; margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto;"><strong style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Implementation Approach :</strong></div><ul style="background-color: white; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 19px; margin-bottom: 0px; margin-left: 2.6em; margin-right: 0px; margin-top: 1.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto;"><li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">SimpleJdbcInsert Command make things really simple when Objects of same type has a fixed set of attributes.</li> </ul><blockquote class="tr_bq"><span style="background-color: #fff2cc;">Create the singleton instance of the SimpleJdbcInsert Command for the corresponding table.</span><span style="background-color: #fff2cc;">Prepare the Map of key-value &nbsp;pairs by parsing the incoming data and simply push the data into the tables against the corresponding columns (keys in the map).</span></blockquote><blockquote class="tr_bq"><span style="background-color: #fff2cc; font-family: Consolas; font-size: 10pt; line-height: 115%;">Number num = insertCommand.executeAndReturnKey(parameters);<br /> </span><span style="background-color: #fff2cc; font-family: Consolas; font-size: 10pt; line-height: 115%;">Or insertCommand.executeBatch(…)&nbsp;&nbsp;</span></blockquote><div class="MsoNormal" style="text-align: left;"><o:p></o:p></div><ul style="background-color: white; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 19px; margin-bottom: 0px; margin-left: 2.6em; margin-right: 0px; margin-top: 1.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto;"><li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">It may be tweaked to leverage DatabaseMetadata and perform DDL on RDBMS programmatically.</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">But its very costly to Create/Update/Delete columns in relational data-store on-the-fly.</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">So finally we take resort to MongoDB.</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">If the Business Entity has a pre-defined set of attributes we should leverage the well-known annotated document object.</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Otherwise if Entity structure is changing constantly to accommodate newer attributes, then just create new DBOnjects and DBRefs.</li> </ul><div style="background-color: white; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 19px; margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto;"><em style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">MongoConfig creates a MongoTemplate against the database "staging"</em>&nbsp;<em style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">MongoDataAccessService provides all CRUD operations.</em><em style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">MongoRestController specifies all the Rest operations.</em></div><div style="background-color: white; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 19px; margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto;">Sneak Peak into the code .. org.jdom.Element rootElement = jdomDocument.getRootElement(); String rootElemName = rootElement.getName();</div><pre style="background-color: white; border-bottom-color: rgb(204, 204, 204); border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-bottom-style: solid; border-bottom-width: 1px; border-image: initial; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-left-radius: 3px; border-top-right-radius: 3px; border-top-style: solid; border-top-width: 1px; font-size: 13px; font: normal normal normal 12px/normal 'Bitstream Vera Sans Mono', Courier, monospace; line-height: 19px; margin-top: 20px; overflow-x: auto; overflow-y: auto; padding-bottom: 6px; padding-left: 10px; padding-right: 10px; padding-top: 6px; text-align: -webkit-auto;"><code style="background-color: transparent; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-left-radius: 3px; border-top-right-radius: 3px; border-top-style: none; border-width: initial; font: normal normal normal 12px/normal 'Bitstream Vera Sans Mono', Courier, monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"> if (!mongoDataAccessService.collectionExists(rootElemName)) { mongoDataAccessService.createCollection(rootElemName); } // we assume the element contains all the values for the table-columns // as the attributes. List list = rootElement.getAttributes(); DBObject parentDocument = new BasicDBObject(); // suppress _ClassName in the DbObject for (Object attr : list) { org.jdom.Attribute source = (org.jdom.Attribute) attr; if (source.getName().equals("Id")) { parentDocument.put("_id", source.getValue()); // use the original incoming Id // candidate for shard key -- TODO } else { parentDocument.put(source.getName(), source.getValue()); } } // Now iterate through the Child Elements and store them as Database // References DBRef childDocumentRef = new DBRef( mongoDataAccessService.getDB("staging"), elementName, elementId); parentDocument.put(elementName + "_ref", childDocumentRef); </code></pre><div style="background-color: white; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 19px; margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto;"><strong style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Runtime Steps :</strong></div><ul style="background-color: white; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 19px; margin-bottom: 0px; margin-left: 2.6em; margin-right: 0px; margin-top: 1.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto;"><li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">target folder already contains a pre-built war file.</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">just drop the war inside an app server context root.</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><em style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">http://localhost:8080/dynamic-data-collection/mongo/entities/add</em></li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Run the MongoRestClient to dynamically extract an entity from XML fragment and add it to the corresponding Collection.</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Simple MongoClient just creates instance of a predefined Mongo Document. This comes handy when Entity has a fixed set of attributes.</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><br /> </li> </ul><span style="font-family: helvetica, arial, freesans, clean, sans-serif;"><span style="font-size: 14px; line-height: 19px;"><b>Code :</b>&nbsp;</span></span> <a href="https://github.com/kaniska/Dynamic-Object-Persistence">https://github.com/kaniska/Dynamic-Object-Persistence</a>&nbsp;<span style="font-family: helvetica, arial, freesans, clean, sans-serif;"><span style="font-size: 14px; line-height: 19px;"><br /> </span></span><br /> <div style="background-color: white; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 19px; margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto;"><strong style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Take Away :</strong></div><ul style="background-color: white; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 19px; margin-bottom: 0px; margin-left: 2.6em; margin-right: 0px; margin-top: 1.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto;"><li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Analyze the Business requirements and accordingly categorize the types of Entities.</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">If all Entities can have pre-defined schema then use SimpleJdbcInsert Command along with MySQL / Oracle for best performance.</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">But in case the Business Process consists of both fixed and dynamic entities, then consider the following approach.</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Define annotated POJO (Mongo Document) for the Entities having a fixed structure.</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">If same type of Entity has different set of attributes for different entities then consider creating them dynamically.</li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">So the choice of database (MongoDB Vs RDBMS) - depends upon how much dynamism one needs to accommodate in the application.</li> </ul><div style="background-color: white; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 19px; margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto;"><b>Future Improvements</b></div><ol style="background-color: white; font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 19px; margin-bottom: 0px; margin-left: 2.6em; margin-right: 0px; margin-top: 1.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left;"><li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><div style="margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Externalize the MongoDB configuration in external properties file. (Tried but somehow it did not work.)</div></li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><div style="margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Use the latest Spring-MongoDB release</div></li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><div style="margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Work with XPathOperations instead of parsing xml fragments manually.</div></li> <li style="margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><div style="margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Figure out if Spring-Data MongoDB API leverages latest Morphia annotations for journal-sync, suppressing _ClassName in objects etc.</div><div style="margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><b>Reference :&nbsp;</b><a href="http://www.springsource.org/spring-data/mongodb">http://www.springsource.org/spring-data/mongodb</a></div></li> </ol></div></description>
<link>http://musings-on-technology.blogspot.com/2012/01/lightweight-persistence-service-for.html</link>
<author>noreply@blogger.com (Kaniska)</author>
<thr:total>0</thr:total>
</item>
<item>
<guid isPermaLink="false">tag:blogger.com,1999:blog-1373851816248476399.post-137478637139424746</guid>
<pubDate>Sun, 18 Sep 2011 20:32:00 +0000</pubDate>
<atom:updated>2011-09-19T02:02:04.771+05:30</atom:updated>
<title>DreamForce Presentations</title>
<description><div dir="ltr" style="text-align: left;" trbidi="on"><br /> <table border="0" cellpadding="0" class="MsoNormalTable" style="width: 600px;"><tbody> <tr> <td style="border-bottom: solid #DEE5EA 1.0pt; border: none; mso-border-bottom-alt: solid #DEE5EA .75pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;" valign="top"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><img alt="Session" id="_x0000_i1025" src="https://dreamevent.my.salesforce.com/img/icon/plane16.png?fromEmail=1" title="Session" />&nbsp;<a href="https://dreamevent.my.salesforce.com/a093000000CeqeV?fromEmail=1"><b>Designing for the Cloud: The 12 Factor App</b></a> — <span class="feeditemtext1"><a href="https://dreamevent.my.salesforce.com/00530000004oi1U?fromEmail=1"><b>Valerie Ringer</b></a> The slides are on Ryan's web page ryandotsmith.heroku.com</span><o:p></o:p></span></div><div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="https://dreamevent.my.salesforce.com/a093000000CeqeV?ChatterFeedItemId=0D53000000RX6vj&amp;fromEmail=1"><span class="feeditemtimestamp1">Saturday, September 17, 2011 4:46 PM</span></a> &nbsp; <a href="https://dreamevent.my.salesforce.com/a093000000CeqeV?OpenCommentForEdit=1&amp;ChatterFeedItemId=0D53000000RX6vj&amp;fromEmail=1"><span class="commentverb1"><span style="font-size: 8.5pt;">Comment</span></span></a><o:p></o:p></span></div></td> </tr> <tr> <td style="border-bottom: solid #DEE5EA 1.0pt; border: none; mso-border-bottom-alt: solid #DEE5EA .75pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;" valign="top"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><img alt="Session" border="0" id="_x0000_i1026" src="https://dreamevent.my.salesforce.com/img/icon/plane16.png?fromEmail=1" title="Session" />&nbsp;<a href="https://dreamevent.my.salesforce.com/a093000000COQgy?fromEmail=1"><b>Using Node.js on Heroku</b></a> — <span class="feeditemtext1"><a href="https://dreamevent.my.salesforce.com/005300000040AgQ?fromEmail=1"><b>Pat Patterson</b></a> Session video on YouTube</span></span><span class="feeditemtext1"><span style="font-size: 9.0pt;"><o:p></o:p></span></span></div><table border="0" cellpadding="0" class="MsoNormalTable"><tbody> <tr> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><img alt="Using Node.js on Heroku" border="0" height="16" id="_x0000_i1027" src="https://dreamevent.my.salesforce.com/img/chatterEmail/link16.png?fromEmail=1" title="Using Node.js on Heroku" width="16" /><o:p></o:p></span></div></td> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="http://www.youtube.com/watch?v=PACwQ632jIE&amp;fromEmail=1" target="_blank"><span title="http://www.youtube.com/watch?v=PACwQ632jIE">Using Node.js on Heroku</span></a><o:p></o:p></span></div></td> </tr> <tr> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><br /> </div></td> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="http://www.youtube.com/watch?v=PACwQ632jIE">http://www.youtube.com/watch?v=PACwQ632jIE</a><o:p></o:p></span></div></td> </tr> </tbody></table><div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="https://dreamevent.my.salesforce.com/a093000000COQgy?ChatterFeedItemId=0D53000000RX5Ej&amp;fromEmail=1"><span class="feeditemtimestamp1">Saturday, September 17, 2011 10:52 AM</span></a> &nbsp; <a href="https://dreamevent.my.salesforce.com/a093000000COQgy?OpenCommentForEdit=1&amp;ChatterFeedItemId=0D53000000RX5Ej&amp;fromEmail=1"><span class="commentverb1"><span style="font-size: 8.5pt;">Comment</span></span></a></span><o:p></o:p></div></td> </tr> <tr> <td style="border-bottom: solid #DEE5EA 1.0pt; border: none; mso-border-bottom-alt: solid #DEE5EA .75pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;" valign="top"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><img alt="Session" border="0" id="_x0000_i1028" src="https://dreamevent.my.salesforce.com/img/icon/plane16.png?fromEmail=1" title="Session" />&nbsp;<a href="https://dreamevent.my.salesforce.com/a0930000009YIQw?fromEmail=1"><b>The Next Step of Evolution in the Force.com REST API</b></a> — <span class="feeditemtext1"><a href="https://dreamevent.my.salesforce.com/005300000040AgQ?fromEmail=1"><b>Pat Patterson</b></a> Session video on YouTube</span></span><span class="feeditemtext1"><span style="font-size: 9.0pt;"><o:p></o:p></span></span></div><table border="0" cellpadding="0" class="MsoNormalTable"><tbody> <tr> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><img alt="The Next Step of Evolution in the Force.com REST API" border="0" height="16" id="_x0000_i1029" src="https://dreamevent.my.salesforce.com/img/chatterEmail/link16.png?fromEmail=1" title="The Next Step of Evolution in the Force.com REST API" width="16" /><o:p></o:p></span></div></td> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="http://www.youtube.com/watch?v=9ur5D1Q-oCQ&amp;fromEmail=1" target="_blank"><span title="http://www.youtube.com/watch?v=9ur5D1Q-oCQ">The Next Step of Evolution in the Force.com REST API</span></a><o:p></o:p></span></div></td> </tr> <tr> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><br /> </div></td> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="http://www.youtube.com/watch?v=9ur5D1Q-oCQ">http://www.youtube.com/watch?v=9ur5D1Q-oCQ</a><o:p></o:p></span></div></td> </tr> </tbody></table><div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="https://dreamevent.my.salesforce.com/a0930000009YIQw?ChatterFeedItemId=0D53000000RX5Ee&amp;fromEmail=1"><span class="feeditemtimestamp1">Saturday, September 17, 2011 10:51 AM</span></a> &nbsp; <a href="https://dreamevent.my.salesforce.com/a0930000009YIQw?OpenCommentForEdit=1&amp;ChatterFeedItemId=0D53000000RX5Ee&amp;fromEmail=1"><span class="commentverb1"><span style="font-size: 8.5pt;">Comment</span></span></a></span><o:p></o:p></div></td> </tr> <tr> <td style="border-bottom: solid #DEE5EA 1.0pt; border: none; mso-border-bottom-alt: solid #DEE5EA .75pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;" valign="top"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><img alt="Session" border="0" id="_x0000_i1030" src="https://dreamevent.my.salesforce.com/img/icon/plane16.png?fromEmail=1" title="Session" />&nbsp;<a href="https://dreamevent.my.salesforce.com/a0930000009YIPB?fromEmail=1"><b>Security and Authentication for Mobile Apps</b></a> — <span class="feeditemtext1"><a href="https://dreamevent.my.salesforce.com/005300000040AgQ?fromEmail=1"><b>Pat Patterson</b></a> Session video on YouTube</span></span><span class="feeditemtext1"><span style="font-size: 9.0pt;"><o:p></o:p></span></span></div><table border="0" cellpadding="0" class="MsoNormalTable"><tbody> <tr> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><img alt="Security and Authentication for Mobile Apps" border="0" height="16" id="_x0000_i1031" src="https://dreamevent.my.salesforce.com/img/chatterEmail/link16.png?fromEmail=1" title="Security and Authentication for Mobile Apps" width="16" /><o:p></o:p></span></div></td> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="http://www.youtube.com/watch?v=ia8yaTtnK0w&amp;fromEmail=1" target="_blank"><span title="http://www.youtube.com/watch?v=ia8yaTtnK0w">Security and Authentication for Mobile Apps</span></a><o:p></o:p></span></div></td> </tr> <tr> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><br /> </div></td> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="http://www.youtube.com/watch?v=ia8yaTtnK0w">http://www.youtube.com/watch?v=ia8yaTtnK0w</a><o:p></o:p></span></div></td> </tr> </tbody></table><div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="https://dreamevent.my.salesforce.com/a0930000009YIPB?ChatterFeedItemId=0D53000000RX4z2&amp;fromEmail=1"><span class="feeditemtimestamp1">Saturday, September 17, 2011 10:32 AM</span></a> &nbsp; <a href="https://dreamevent.my.salesforce.com/a0930000009YIPB?OpenCommentForEdit=1&amp;ChatterFeedItemId=0D53000000RX4z2&amp;fromEmail=1"><span class="commentverb1"><span style="font-size: 8.5pt;">Comment</span></span></a></span><o:p></o:p></div></td> </tr> <tr> <td style="border-bottom: solid #DEE5EA 1.0pt; border: none; mso-border-bottom-alt: solid #DEE5EA .75pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;" valign="top"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><img alt="Session" border="0" id="_x0000_i1032" src="https://dreamevent.my.salesforce.com/img/icon/plane16.png?fromEmail=1" title="Session" />&nbsp;<a href="https://dreamevent.my.salesforce.com/a0930000009YIP3?fromEmail=1"><b>Mashing Up the Cloud with Force.com Toolkits</b></a> — <span class="feeditemtext1"><a href="https://dreamevent.my.salesforce.com/005300000040AgQ?fromEmail=1"><b>Pat Patterson</b></a> Session video on YouTube</span></span><span class="feeditemtext1"><span style="font-size: 9.0pt;"><o:p></o:p></span></span></div><table border="0" cellpadding="0" class="MsoNormalTable"><tbody> <tr> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><img alt="Mashing Up the Cloud with Force.com Toolkits" border="0" height="16" id="_x0000_i1033" src="https://dreamevent.my.salesforce.com/img/chatterEmail/link16.png?fromEmail=1" title="Mashing Up the Cloud with Force.com Toolkits" width="16" /><o:p></o:p></span></div></td> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="http://www.youtube.com/watch?v=pe2Ke4a9zas&amp;fromEmail=1" target="_blank"><span title="http://www.youtube.com/watch?v=pe2Ke4a9zas">Mashing Up the Cloud with Force.com Toolkits</span></a><o:p></o:p></span></div></td> </tr> <tr> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><br /> </div></td> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="http://www.youtube.com/watch?v=pe2Ke4a9zas">http://www.youtube.com/watch?v=pe2Ke4a9zas</a><o:p></o:p></span></div></td> </tr> </tbody></table><div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="https://dreamevent.my.salesforce.com/a0930000009YIP3?ChatterFeedItemId=0D53000000RX55j&amp;fromEmail=1"><span class="feeditemtimestamp1">Saturday, September 17, 2011 10:27 AM</span></a> &nbsp; <a href="https://dreamevent.my.salesforce.com/a0930000009YIP3?OpenCommentForEdit=1&amp;ChatterFeedItemId=0D53000000RX55j&amp;fromEmail=1"><span class="commentverb1"><span style="font-size: 8.5pt;">Comment</span></span></a></span><o:p></o:p></div></td> </tr> <tr> <td style="border-bottom: solid #DEE5EA 1.0pt; border: none; mso-border-bottom-alt: solid #DEE5EA .75pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;" valign="top"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><img alt="Session" border="0" id="_x0000_i1034" src="https://dreamevent.my.salesforce.com/img/icon/plane16.png?fromEmail=1" title="Session" />&nbsp;<a href="https://dreamevent.my.salesforce.com/a093000000BtFdV?fromEmail=1"><b>HTML 5 and Geo-Location Using Visualforce and Apex</b></a> — <span class="feeditemtext1"><a href="https://dreamevent.my.salesforce.com/005300000040AgQ?fromEmail=1"><b>Pat Patterson</b></a> Session video on YouTube</span></span><span class="feeditemtext1"><span style="font-size: 9.0pt;"><o:p></o:p></span></span></div><table border="0" cellpadding="0" class="MsoNormalTable"><tbody> <tr> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><img alt="HTML 5 and Geo-Location Using Visualforce and Apex" border="0" height="16" id="_x0000_i1035" src="https://dreamevent.my.salesforce.com/img/chatterEmail/link16.png?fromEmail=1" title="HTML 5 and Geo-Location Using Visualforce and Apex" width="16" /><o:p></o:p></span></div></td> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="http://www.youtube.com/watch?v=wwTdGqOygBQ&amp;fromEmail=1" target="_blank"><span title="http://www.youtube.com/watch?v=wwTdGqOygBQ">HTML 5 and Geo-Location Using Visualforce and Apex</span></a><o:p></o:p></span></div></td> </tr> <tr> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><br /> </div></td> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="http://www.youtube.com/watch?v=wwTdGqOygBQ">http://www.youtube.com/watch?v=wwTdGqOygBQ</a><o:p></o:p></span></div></td> </tr> </tbody></table><div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="https://dreamevent.my.salesforce.com/a093000000BtFdV?ChatterFeedItemId=0D53000000RX4o3&amp;fromEmail=1"><span class="feeditemtimestamp1">Saturday, September 17, 2011 10:26 AM</span></a> &nbsp; <a href="https://dreamevent.my.salesforce.com/a093000000BtFdV?OpenCommentForEdit=1&amp;ChatterFeedItemId=0D53000000RX4o3&amp;fromEmail=1"><span class="commentverb1"><span style="font-size: 8.5pt;">Comment</span></span></a></span><o:p></o:p></div></td> </tr> <tr> <td style="border-bottom: solid #DEE5EA 1.0pt; border: none; mso-border-bottom-alt: solid #DEE5EA .75pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;" valign="top"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><img alt="Session" border="0" id="_x0000_i1036" src="https://dreamevent.my.salesforce.com/img/icon/plane16.png?fromEmail=1" title="Session" />&nbsp;<a href="https://dreamevent.my.salesforce.com/a0930000009YINh?fromEmail=1"><b>Getting Started with the Force.com Streaming API</b></a> — <span class="feeditemtext1"><a href="https://dreamevent.my.salesforce.com/005300000040AgQ?fromEmail=1"><b>Pat Patterson</b></a> Session video on YouTube</span></span><span class="feeditemtext1"><span style="font-size: 9.0pt;"><o:p></o:p></span></span></div><table border="0" cellpadding="0" class="MsoNormalTable"><tbody> <tr> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><img alt="Getting Started with the Force.com Streaming API" border="0" height="16" id="_x0000_i1037" src="https://dreamevent.my.salesforce.com/img/chatterEmail/link16.png?fromEmail=1" title="Getting Started with the Force.com Streaming API" width="16" /><o:p></o:p></span></div></td> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="http://www.youtube.com/watch?v=8UqeVRiv6-s&amp;fromEmail=1" target="_blank"><span title="http://www.youtube.com/watch?v=8UqeVRiv6-s">Getting Started with the Force.com Streaming API</span></a><o:p></o:p></span></div></td> </tr> <tr> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><br /> </div></td> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="http://www.youtube.com/watch?v=8UqeVRiv6-s">http://www.youtube.com/watch?v=8UqeVRiv6-s</a><o:p></o:p></span></div></td> </tr> </tbody></table><div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="https://dreamevent.my.salesforce.com/a0930000009YINh?ChatterFeedItemId=0D53000000RX50J&amp;fromEmail=1"><span class="feeditemtimestamp1">Saturday, September 17, 2011 10:25 AM</span></a> &nbsp; <a href="https://dreamevent.my.salesforce.com/a0930000009YINh?OpenCommentForEdit=1&amp;ChatterFeedItemId=0D53000000RX50J&amp;fromEmail=1"><span class="commentverb1"><span style="font-size: 8.5pt;">Comment</span></span></a></span><o:p></o:p></div></td> </tr> <tr> <td style="border-bottom: solid #DEE5EA 1.0pt; border: none; mso-border-bottom-alt: solid #DEE5EA .75pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;" valign="top"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><img alt="Session" border="0" id="_x0000_i1038" src="https://dreamevent.my.salesforce.com/img/icon/plane16.png?fromEmail=1" title="Session" />&nbsp;<a href="https://dreamevent.my.salesforce.com/a093000000CPLnH?fromEmail=1"><b>Event-Driven Programming with Node.js and the Force.com Streaming API</b></a> — <span class="feeditemtext1"><a href="https://dreamevent.my.salesforce.com/005300000040AgQ?fromEmail=1"><b>Pat Patterson</b></a> Session video on YouTube</span></span><span class="feeditemtext1"><span style="font-size: 9.0pt;"><o:p></o:p></span></span></div><table border="0" cellpadding="0" class="MsoNormalTable"><tbody> <tr> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><img alt="Event-Driven Programming with Node.js and the Force.com Streaming API" border="0" height="16" id="_x0000_i1039" src="https://dreamevent.my.salesforce.com/img/chatterEmail/link16.png?fromEmail=1" title="Event-Driven Programming with Node.js and the Force.com Streaming API" width="16" /><o:p></o:p></span></div></td> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="http://www.youtube.com/watch?v=_Vt0TPS5HLw&amp;fromEmail=1" target="_blank"><span title="http://www.youtube.com/watch?v=_Vt0TPS5HLw">Event-Driven Programming with Node.js and the Force.com Streaming API</span></a><o:p></o:p></span></div></td> </tr> <tr> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><br /> </div></td> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="http://www.youtube.com/watch?v=_Vt0TPS5HLw">http://www.youtube.com/watch?v=_Vt0TPS5HLw</a><o:p></o:p></span></div></td> </tr> </tbody></table><div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="https://dreamevent.my.salesforce.com/a093000000CPLnH?ChatterFeedItemId=0D53000000RX4z1&amp;fromEmail=1"><span class="feeditemtimestamp1">Saturday, September 17, 2011 10:23 AM</span></a> &nbsp; <a href="https://dreamevent.my.salesforce.com/a093000000CPLnH?OpenCommentForEdit=1&amp;ChatterFeedItemId=0D53000000RX4z1&amp;fromEmail=1"><span class="commentverb1"><span style="font-size: 8.5pt;">Comment</span></span></a></span><o:p></o:p></div></td> </tr> <tr> <td style="border-bottom: solid #DEE5EA 1.0pt; border: none; mso-border-bottom-alt: solid #DEE5EA .75pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;" valign="top"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><img alt="Session" border="0" id="_x0000_i1040" src="https://dreamevent.my.salesforce.com/img/icon/plane16.png?fromEmail=1" title="Session" />&nbsp;<a href="https://dreamevent.my.salesforce.com/a093000000BrGSS?fromEmail=1"><b>Authentication: A Practical Guide</b></a> — <span class="feeditemtext1"><a href="https://dreamevent.my.salesforce.com/005300000040AgQ?fromEmail=1"><b>Pat Patterson</b></a> Session video on YouTube</span></span><span class="feeditemtext1"><span style="font-size: 9.0pt;"><o:p></o:p></span></span></div><table border="0" cellpadding="0" class="MsoNormalTable"><tbody> <tr> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><img alt="Authentication: A Practical Guide" border="0" height="16" id="_x0000_i1041" src="https://dreamevent.my.salesforce.com/img/chatterEmail/link16.png?fromEmail=1" title="Authentication: A Practical Guide" width="16" /><o:p></o:p></span></div></td> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="http://www.youtube.com/watch?v=9McaWgMLprs&amp;fromEmail=1" target="_blank"><span title="http://www.youtube.com/watch?v=9McaWgMLprs">Authentication: A Practical Guide</span></a><o:p></o:p></span></div></td> </tr> <tr> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><br /> </div></td> <td style="padding: .75pt .75pt .75pt .75pt;"> <div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="http://www.youtube.com/watch?v=9McaWgMLprs">http://www.youtube.com/watch?v=9McaWgMLprs</a><o:p></o:p></span></div></td> </tr> </tbody></table><div class="MsoNormal" style="line-height: 11.25pt;"><span style="color: #222222; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; font-size: 9.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><a href="https://dreamevent.my.salesforce.com/a093000000BrGSS?ChatterFeedItemId=0D53000000RX50t&amp;fromEmail=1"><span class="feeditemtimestamp1">Saturday, September 17, 2011 10:02 AM</span></a> &nbsp; <a href="https://dreamevent.my.salesforce.com/a093000000BrGSS?OpenCommentForEdit=1&amp;ChatterFeedItemId=0D53000000RX50t&amp;fromEmail=1"><span class="commentverb1"><span style="font-size: 8.5pt;">Comment</span></span></a></span><o:p></o:p></div></td> </tr> </tbody></table></div></description>
<link>http://musings-on-technology.blogspot.com/2011/09/dreamforce-presentations.html</link>
<author>noreply@blogger.com (Kaniska)</author>
<thr:total>0</thr:total>
</item>
<item>
<guid isPermaLink="false">tag:blogger.com,1999:blog-1373851816248476399.post-4499025359788798362</guid>
<pubDate>Fri, 27 May 2011 06:49:00 +0000</pubDate>
<atom:updated>2011-05-28T08:59:52.996+05:30</atom:updated>
<title>Challenge the Conventional Wisdom : MongoSF 2011</title>
<description><div dir="ltr" style="text-align: left;" trbidi="on"><div class="separator" style="clear: both; text-align: center;"><span class="Apple-style-span" style="font-family: inherit;">||| MongoSF , May 25, 2011 &nbsp;|||</span></div><span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6glsYSlpixPQZMZMORq-2Cmo8jewE10al_gG_quVRg_bTcuxq1XAt6Awh09Pezw7bUIoEv0dkxeqzCIZb-UNqpw4PLZvSZs3_elncbhuOFsqx7Lokc2eabsTQ3Ogbf3Q3cOyrZKmnHg8/s1600/moon_walk.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6glsYSlpixPQZMZMORq-2Cmo8jewE10al_gG_quVRg_bTcuxq1XAt6Awh09Pezw7bUIoEv0dkxeqzCIZb-UNqpw4PLZvSZs3_elncbhuOFsqx7Lokc2eabsTQ3Ogbf3Q3cOyrZKmnHg8/s320/moon_walk.png" width="242" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjQ654AU_DD3iqt3Dxiz9qUrSCZAM812H-GXaY1dYmFnPGIklSZyOsZ12MOW0iiMs54-N0Ym5G4X9lQp8T6P4oZyky8tEBhV3TfeRzLtAjUNl2zemeAVMUsb3qEAJ3Q3_C0UNJUMxg3Kg/s1600/www.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="109" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjQ654AU_DD3iqt3Dxiz9qUrSCZAM812H-GXaY1dYmFnPGIklSZyOsZ12MOW0iiMs54-N0Ym5G4X9lQp8T6P4oZyky8tEBhV3TfeRzLtAjUNl2zemeAVMUsb3qEAJ3Q3_C0UNJUMxg3Kg/s320/www.png" style="cursor: move;" width="320" /></a></span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;">* shamelessly borrowed from Kyle's great slides ... &nbsp;I consider this as the best example to drive home the simple yet strong message from MongoSF Seminar !</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="color: #741b47; font-family: inherit;"><b>Professor Calculus trying to convince Captain Haddock that he should embark upon the Shuttle to Planet MONGO !</b></span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;"><b>Capt. H :</b> <span class="Apple-style-span" style="color: #660000;">My data is not super-transactional , but time-critical and move very fast .. So are you saying <b>I don't need Normalization </b>?</span></span><br /> <span class="Apple-style-span" style="font-family: inherit;"><b>Prof. C :</b> &nbsp;<span class="Apple-style-span" style="color: #20124d;">Exactly ! <b>Design your database as per your usecase</b>. In <b>absence of a schema</b>, no need to build/maintain the lifecycle of a model (conceptual [ERD]-&gt; logical [UML] -&gt; physical [DB] -&gt; sql -&gt; xsd ..)</span></span><br /> <span class="Apple-style-span" style="color: #20124d;"><span class="Apple-style-span" style="font-family: inherit;">Captain! just&nbsp;</span>spell-out your thoughts as</span>..<span class="Apple-style-span" style="color: #38761d;"><b>{vendor_id : "apple", products : ["iphone","ipod", "ipad"] }</b></span><br /> <span class="Apple-style-span" style="font-family: inherit;">Embedded Array is a powerful concept to get a list of associated entities for a specific entity at one go !&nbsp;</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;">With full respect to RDBMS world (which will always be relevant in the Operational Domain like sayManufacturing ...) few imp points to remember :</span><br /> <span class="Apple-style-span" style="font-family: inherit;">&gt;&gt; &nbsp;</span><span class="Apple-style-span" style="color: #20124d;">Tradional DB - Schema has no bias for a specific usecase. It encompasses all possible relationships between the entities (stakeholders) of a domain !</span><br /> <span class="Apple-style-span" style="font-family: inherit;">&gt;&gt; </span><span class="Apple-style-span" style="color: #20124d;"><span class="Apple-style-span" style="font-family: inherit;">So its great for ad-hoc queries and data-rigid ness .... &nbsp;but very very slow for data manipulation and for hopping around !! This trade-off can be equated with the famous trade-offs between 'bloated Wsdl and simplistic Rest' or 'Schematic XML and&nbsp;</span>Schema-less<span class="Apple-style-span" style="font-family: inherit;">&nbsp;Json' !</span></span><br /> <br /> <span class="Apple-style-span" style="font-family: inherit;"><b>Capt. H : </b>&nbsp;<span class="Apple-style-span" style="color: #660000;">Traditionally, first I normalize the data for OLTP and then de-normalize the data for BI .. &nbsp;?</span></span><br /> <span class="Apple-style-span" style="font-family: inherit;"><b>Prof. C :</b> &nbsp;I do understand your pain points ! Welcome to MongoDB &nbsp;!<span class="Apple-style-span" style="color: #4c1130;"> Just fire few aggregation queries on the same document that stores your business model and you extract all the intelligence at no extra cost !</span></span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;"><b>Capt. H :</b><span class="Apple-style-span" style="color: #660000;"> So far so good ! Do I still need&nbsp;a Cache or ORM layer ?</span></span><br /> <span class="Apple-style-span" style="font-family: inherit;"><b>Prof. C :</b> Well.. Captain .. <span class="Apple-style-span" style="color: #4c1130;">Caching was a Work-around for slow lookups from over-burdened database</span> !</span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;">Now the <b>db itself is extremely light weight engine </b>- fast lock-free lookup, aycnchonous parrallel writes, distributed loads on shards etc. etc.</span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;">- ORM is another work-around to abstract rigid SQL and convert pojo from specific framework to db entities ! .. Well .. in most of cases .. no need for any sort of mappng ideally ! MongoDB manadates that Code and Data should reside in seperate layers and each understand one standard i.e. Json!&nbsp;</span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;"><b>It flows so smoothly from front-end &nbsp;(Php/pearl/python/gwt/js .. all understand json) to the json-friendly Rest layer and finally lands on the lap of MongoDB as Bson !</b>&nbsp;</span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;">Rememeber ...&nbsp;we now have a database which itself <b>follows object structure</b> that your app layer is based on ... <b>&nbsp;so no need of any ORM layer</b> !</span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;">Now for the sake of backward&nbsp;compatibility and smooth integration with existing&nbsp;pojo-based apps (which were talking to rdbms), Spring-data provides nice wrappers to NoSqls !</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <b>Capt. H :</b><span class="Apple-style-span" style="color: #660000; font-family: inherit;">Well I love breaking down a large Entity like Product into multiple components like - { line_item, payment, order, etc.. } .. but I pay the heavy price of slow joins ?</span><br /> <b>Prof. C :</b><span class="Apple-style-span" style="font-family: inherit;">&nbsp;<span class="Apple-style-span" style="color: #20124d;">Hmm .. how about creating <b>a Rich Document - Product and then embed sub-documents</b> {line_ites, payment, order..} inside the parent..</span></span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;">Then index on sub documents and perform super-fast asynchrnous atomic updates on a single document</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <b>Capt. H :&nbsp;</b><span class="Apple-style-span" style="color: #660000; font-family: inherit;">Great ! You know .. I love storing the parent-child relationship .. i.e. the Inheritence or.. a Tree-Hierarchy in a single table .... &nbsp;but as a result in RDBMS .. you know .. I have redundant columns !!</span><br /> <b>Prof. C :</b><span class="Apple-style-span" style="font-family: inherit;">&nbsp;<span class="Apple-style-span" style="color: #20124d;">No worries ! in MongoDB,<b> data itself defines its schema</b> ! (metadata free modelling)&nbsp;</span></span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;">So you can specify ...</span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;">db.shapes.find()</span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;">&nbsp; {_id:"1",type:"circle",area: 3.14, radius: 1 }</span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;">&nbsp; {_id:"2",type:"square",area: 4, d: 2 }</span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;">&nbsp; {_id:"3",type:"rect",area: 10, length: 5 , width: 2}</span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;">-- And wait .. you can <b>apply the beautiful 'Sparse Index' to diverse data-set</b> stored inside same collection !</span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;">Did you catch the sweet spot 'radius' - just by its sheer presence as an unique attribute an 'inherent restriction' is applied on the collection.</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;"><b>Capt H:</b> <span class="Apple-style-span" style="color: #660000;">Professor .. You simply Rock ! .. I kinda learnt how to partition my data in rdbms ! But so difficult to maintain when data outgrows the chunks ...</span></span><br /> <span class="Apple-style-span" style="font-family: inherit;"><b>Prof C</b>. .. <span class="Apple-style-span" style="color: #20124d;">Sorry to hear that captain ! ... <b>data-partitioning is a no brainer</b> !</span></span><br /> <span class="Apple-style-span" style="font-family: monospace; line-height: 16px; white-space: pre-wrap;">db.runCommand( { addshard : <span class="code-quote" style="background-color: inherit; color: #009100; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">"localhost:10000"</span> } )</span><br /> <pre class="code-java" style="line-height: 1.3; margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 10px; overflow-x: auto; overflow-y: auto; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; white-space: pre-wrap;"><span class="Apple-style-span" style="font-family: inherit;">{ <span class="code-quote" style="background-color: inherit; color: #009100; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">"shardadded"</span> : <span class="code-quote" style="background-color: inherit; color: #009100; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">"shard0000"</span>, <span class="code-quote" style="background-color: inherit; color: #009100; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">"ok"</span> : 1 } db.runCommand( { addshard : <span class="code-quote" style="background-color: inherit; color: #009100; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">"localhost:10001"</span> } ) { <span class="code-quote" style="background-color: inherit; color: #009100; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">"shardadded"</span> : <span class="code-quote" style="background-color: inherit; color: #009100; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">"shard0001"</span>, <span class="code-quote" style="background-color: inherit; color: #009100; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">"ok"</span> : 1 }</span></pre><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;">All the goodness of&nbsp;sophisticated <b>master-slave nodes allocation, replication, internal node state management, auto-recovery</b> are provided out-of-the box !&nbsp;</span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;"><b>ReplicaSet </b>Mode detects all the hosts every 5 sec.</span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;"><b>Replica1 </b>: {chunk1(user1 - user100) =&gt; shard1, chunk2(user101 - user 200) =&gt; shard1}</span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;"><b>Replica2 </b>: {chunk1(user1 - user100) =&gt; shard1, chunk2(user101 - user 200) =&gt; shard1}</span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;">MongoS process is the load-balancer. Upon startup it finds out which servers are up and based on the latency picks the shard. It routes the chunks between shards in replica sets.</span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;">If new hot chunk is created, MongoS can dynamically allocate the chunk to an available shard - shard2.</span><br /> <span class="Apple-style-span" style="color: #20124d; font-family: inherit;">Otherwise it will spawn new shard by dividing existing shard at its median !</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <b>Capt H:&nbsp;</b><span class="Apple-style-span" style="color: #660000; font-family: inherit;">Very Interesting ! So I can choose whether my <b>query will work on primary or secondary</b>.</span><br /> <b>Prof C:&nbsp;</b><span class="Apple-style-span" style="color: #20124d; font-family: inherit;">You got it right ! For immediate consistency, query from / write into the primary master. For eventual consistency query the slaves ! Reads may go out-of-date on slaves. Its just a tip of iceberg ! So refer to the document for more details !</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <b>Capt H:&nbsp;</b><span class="Apple-style-span" style="color: #20124d; font-family: inherit;">Great ! Now that my app working fine ... need to do some analysis .. So coming to <b>data-crunching in batch</b> ! I am a startup guy and have no time to setup hadoop-hive-mahout on a seperate cluster , neither have the luxury to build the&nbsp;infrastructure&nbsp;of Amazon Elastic Map-Reduce .... &nbsp;so .. I guess .. MongoDB ..</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <b>Prof C:&nbsp;</b><span class="Apple-style-span" style="font-family: inherit;">&nbsp;<span class="Apple-style-span" style="color: #20124d;">Oh ! Yah ! Absolutely ! Right here ... Why as a developer in a fast-paced-env you need to worry about the gory details of data crunching !! <b>Just call map-reduce api</b> ! Stay tuned ! Out-of-the box Aggregation API coming soon ! Remember the key point ... &nbsp;you can now <b>enjoy a real-time streaming analytics with negligible latency </b>!</span></span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <b>Capt H: &nbsp;</b><span class="Apple-style-span" style="color: #660000; font-family: inherit;">I am ecstatic to hear this ! On a different note I love indexed-based searching using lucene-solr .. but just checking in if ..</span><br /> <b>Prof C:&nbsp;</b><span class="Apple-style-span" style="font-family: inherit;">&nbsp;<span class="Apple-style-span" style="color: #20124d;">Sure ! MongoDB hears you ... &nbsp;full-fledged text-searching .. will be released by end of 2011 !</span></span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <b>Capt H:&nbsp;</b><span class="Apple-style-span" style="color: #660000; font-family: inherit;">I love Scala and Node.js .. a big fan of <b>executing requests&nbsp;parallely ..&nbsp;</b>&nbsp;but it gets very tricky to solve table-level and row-level locking issues in Database ....</span><br /> <b>Prof C:</b><span class="Apple-style-span" style="font-family: inherit;">&nbsp;<span class="Apple-style-span" style="color: #20124d;">Absolutely ! <b>Your writes per document are atomic and reads are parallel in nature</b> (cpu cores scaling out not speeding up ... so mongodb native threads just love&nbsp;asynchronous&nbsp;parallel processing) ! But if writes fail .. there is no auto-rollback machanism .. your app should be responsible for data consistency ! &nbsp;No support for distributed transactions ! &nbsp;So use a language of your choice and no need to shard in the app layer !</span></span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <b>Capt H:&nbsp;</b><span class="Apple-style-span" style="color: #660000; font-family: inherit;">A compelling reason for adopting AWS was SimpleDB .. I mean instead of moving my DB to Cloud I tried to &nbsp;access a DB on Cloud .. but sacrificed many features of RDBMS .... &nbsp;So .. is it a Big Ask from Mongo ... ?</span><br /> <b>Prof C:&nbsp;</b><span class="Apple-style-span" style="font-family: inherit;">&nbsp;<span class="Apple-style-span" style="color: #20124d;">Not at all ! &nbsp;MongoDB is <b>Cloud-ready by virtue of its horizontal scalability, multi-tenancy , fail-safe nature, statelessness and atomic transactions. Scale linearly, increase capacity with no down-time.</b></span></span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="color: #741b47; font-family: inherit;"><b>So Captain Welcome Aboard ! Enjoy your journey into Mongo !</b></span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <b><span class="Apple-style-span" style="color: #741b47;">With freedom comes responsibility :</span></b><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;">1. <span class="Apple-style-span" style="color: #20124d;">MongoDB<b> does not encourage storing reverse links in referred documents</b> for implementing many-2-many relationship. </span></span><br /> <span class="Apple-style-span" style="font-family: inherit;">Captain I know you love your language .. you wont mind couple of extra lines of query in app layer :-)</span><br /> <span class="Apple-style-span" style="font-family: inherit;">//All categories for a given product</span><br /> <span class="Apple-style-span" style="font-family: inherit;">product = db.products.find(_id, prod_id);</span><br /> <span class="Apple-style-span" style="font-family: inherit;">db.categories.find({_id: &nbsp;{$in : product.category_ids} })</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;">2. <b><span class="Apple-style-span" style="color: #20124d;">Its not a full-fledged caching solution</span></b> ... so there are pending issues with data-eviction ! Expired objects reportedly sit back in memory ! MongoDB believes in reusing memory rather than suffering from reclaiming-reallocating overhead every now-n -then ! But the garbage collection algo definitely get better and better with community support !</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;">3. The thrust is on 'eventual consistency' for writes. there is <span class="Apple-style-span" style="color: #351c75;"><b>no 'Retries' for writes</b></span> !<b><span class="Apple-style-span" style="color: #20124d;"> So we need to judiciously handle the write-exceptions in app layer.</span></b> We need to remember - if we explicitly mark a 'transaction request' as 'done' then only mongoDB driver will clean-up the connection from the thread-local !</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;">4. While designing the data model, we need to understand where to <b><span class="Apple-style-span" style="color: #073763;">'embed'</span></b> and where to<span class="Apple-style-span" style="color: #0b5394;"><b> 'link</b></span>.</span><br /> <span class="Apple-style-span" style="font-family: inherit;">Definitely 'Linking' has a higher 'cost of relocation' than 'Embedding'. That implies in a Tree we better store the list of&nbsp;descendants&nbsp;directly.</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;">5. The workingSet size should be kept minimal and need to be distributed evenly.</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><span class="Apple-style-span" style="color: #073763;"><b>Pre-splitting for initial bulk loading is always advised.</b></span>&nbsp;</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;">6.<span class="Apple-style-span" style="color: #0b5394;"><b> Queries on sharded key are fastest</b></span>.</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;">7. For pagination we should depend upon stateful cursor_index instead of depending on stateless sharded key.</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="color: #660000; font-family: inherit;"><b>Tips, tricks, references :</b></span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;"><b><span class="Apple-style-span" style="color: blue;">Thought-provoking :</span></b> &nbsp;<a href="http://www.slideshare.net/tackers/moving-from-relational-to-document-store">http://www.slideshare.net/tackers/moving-from-relational-to-document-store</a></span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;"><span class="Apple-style-span" style="color: blue;"><b>Great summary on app-design principles </b></span></span><span class="Apple-style-span" style="font-family: inherit;">:</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><a href="http://speakerdeck.com/u/kbanker/p/the-mongodb-gamut-four-app-designs">http://speakerdeck.com/u/kbanker/p/the-mongodb-gamut-four-app-designs</a></span><br /> <br /> <br /> <span class="Apple-style-span" style="font-family: inherit;"><span class="Apple-style-span" style="font-weight: bold; line-height: 12px;"><a href="http://my.safaribooksonline.com/book/databases/9781449306779" style="outline-color: initial; outline-style: none; outline-width: initial; text-decoration: none;" title="50 Tips and Tricks for MongoDB Developers"><span class="Apple-style-span" style="color: blue;">50 Tips and Tricks for MongoDB Developers</span></a></span><span class="Apple-style-span" style="font-weight: bold; line-height: 12px;"><span class="Apple-style-span" style="color: blue;">&nbsp;:</span></span></span><span class="Apple-style-span" style="font-family: inherit;"><span class="Apple-style-span" style="font-weight: bold; line-height: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><a href="http://my.safaribooksonline.com/book/databases/9781449306779/firstchapter">http://my.safaribooksonline.com/book/databases/9781449306779/firstchapter</a></span><br /> <br /> <br /> <span class="Apple-style-span" style="color: blue; font-family: inherit;"><b>Schema Design Basics :&nbsp;</b></span><span class="Apple-style-span" style="font-family: tahoma, times, serif; font-size: 13px;"><a href="http://speakerdeck.com/u/kbanker/p/mongodb-schema-design-mongosf-2011" rel="nofollow" target="_blank">http://speakerdeck.com/u/kbanker/p/mongodb-schema-design-mongosf-2011</a></span><br /> <span class="Apple-style-span" style="font-family: inherit;"><a href="http://www.slideshare.net/mongodb/mongodb-schema-design-richard-kreuters-mongo-berlin-preso">http://www.slideshare.net/mongodb/mongodb-schema-design-richard-kreuters-mongo-berlin-preso</a></span><br /> <br /> <b><span class="Apple-style-span" style="color: blue;">New Aggregation Features </span></b>:&nbsp;<a href="http://www.slideshare.net/cwestin63/mongodb-aggregation-mongosf-may-2011">http://www.slideshare.net/cwestin63/mongodb-aggregation-mongosf-may-2011</a><br /> <br /> <div class="MsoNormal" style="mso-layout-grid-align: none; mso-pagination: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: inherit;"><span class="Apple-style-span" style="color: blue;"><b>Performance Considerations :</b></span>&nbsp;</span><span class="Apple-style-span" style="font-family: tahoma, times, serif; font-size: 13px;"><a href="http://speakerdeck.com/u/kbanker/p/10-key-mongodb-performance-indicators" rel="nofollow" target="_blank">http://speakerdeck.com/u/kbanker/p/10-key-mongodb-performance-indicators</a></span></div><span class="Apple-style-span" style="color: blue;"><a href="http://blog.zawodny.com/2011/03/06/mongodb-pre-splitting-for-faster-data-loading-and-importing/">http://blog.zawodny.com/2011/03/06/mongodb-pre-splitting-for-faster-data-loading-and-importing/</a></span><br /> <span class="Apple-style-span" style="font-family: inherit;"></span><br /> <div class="MsoNormal" style="mso-layout-grid-align: none; mso-pagination: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: inherit;"><span lang="EN"><br /> </span></span></div><span class="Apple-style-span" style="font-family: inherit;"><span class="Apple-style-span" style="color: blue;"><b>Great Teachings from MongDB Mentor :</b></span>&nbsp;</span><a href="http://www.scribd.com/alvin_richards"><span style="color: blue;">http://www.scribd.com/alvin_richards</span></a><span class="Apple-style-span" style="font-family: inherit;"></span><br /> <div class="MsoNormal" style="mso-layout-grid-align: none; mso-pagination: none; text-autospace: none;"><span class="Apple-style-span" style="font-family: inherit;"><span lang="EN"><br /> </span></span></div><br /> <span class="Apple-style-span" style="font-family: inherit;"><span class="Apple-style-span" style="color: blue;"><b>MongoSF Streaming :</b></span>&nbsp;</span><a href="http://www.justin.tv/mongodb/b/286578814">http://www.justin.tv/mongodb/b/286578814</a><br /> <b><span class="Apple-style-span" style="color: blue;">Webinars :</span></b>&nbsp;<a href="http://www.10gen.com/webinars"><span class="Apple-style-span" style="font-family: inherit;">http://www.10gen.com/webinars</span></a><br /> <span class="Apple-style-span" style="color: blue;"><b>Original Docs :</b></span>&nbsp;<a href="http://www.mongodb.org/display/DOCS/Home">http://www.mongodb.org/display/DOCS/Home</a><br /> <span class="Apple-style-span" style="color: blue;"><b>The little mongo book and Interactive Tutorial :</b></span> &nbsp;<a href="http://mongly.com/">http://mongly.com/</a><br /> <b><span class="Apple-style-span" style="color: blue;">Tools to play with MongoDB :</span></b> &nbsp;<a href="http://mongolab.com/">mongolab.com</a>&nbsp;, &nbsp;<a href="http://mongo.cloudfoundry.com/"><span class="Apple-style-span" style="font-family: inherit;">http://mongo.cloudfoundry.com/</span></a><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <b>CaseStudy :</b> &nbsp;<span class="Apple-style-span" style="color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px;"><span class="h-username" style="border-bottom-width: 0px; border-color: initial; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-style: initial; border-top-width: 0px; color: #0077aa; font-family: inherit; font-size: 12px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none; vertical-align: top;"><a class="userimage-link j-tooltip-bottom" href="http://www.slideshare.net/ggoodale" original-title="ggoodale | Happy-go-lucky hacker. Scale junkie. Chief Janitor at Massively Fun. The internet is full of very cool toys." style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #0077aa; font-family: inherit; font-size: 12px; font-style: inherit; font-weight: 700; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none; vertical-align: baseline;">Grant Goodale</a>&nbsp;has the best collection of MongoDB Slides&nbsp;</span></span><br /> <a href="http://www.slideshare.net/ggoodale/geospatial-indexing-and-querying-with-mongodb">http://www.slideshare.net/ggoodale/geospatial-indexing-and-querying-with-mongodb</a><br /> <br /> </div></description>
<link>http://musings-on-technology.blogspot.com/2011/05/challenge-conventional-wisdom-mongosf.html</link>
<author>noreply@blogger.com (Kaniska)</author>
<media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6glsYSlpixPQZMZMORq-2Cmo8jewE10al_gG_quVRg_bTcuxq1XAt6Awh09Pezw7bUIoEv0dkxeqzCIZb-UNqpw4PLZvSZs3_elncbhuOFsqx7Lokc2eabsTQ3Ogbf3Q3cOyrZKmnHg8/s72-c/moon_walk.png" height="72" width="72"/>
<thr:total>0</thr:total>
</item>
<item>
<guid isPermaLink="false">tag:blogger.com,1999:blog-1373851816248476399.post-996805662522116130</guid>
<pubDate>Thu, 26 May 2011 14:39:00 +0000</pubDate>
<atom:updated>2011-09-09T04:32:26.132+05:30</atom:updated>
<title>CloudFoundry - Simplicity Matters</title>
<description><div dir="ltr" style="text-align: left;" trbidi="on"><span class="Apple-style-span" style="font-family: inherit;">'Simplicity Matters' - is the mantra of <span class="Apple-style-span" style="color: blue;">SpringSource</span>.</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;">Its just amazing to witness how fast SpringSource <span class="Apple-style-span" style="color: blue;">simplifying the access to huge number of heterogeneous service providers</span> based on the ideas of AOP and DI.</span><br /> <span class="Apple-style-span" style="color: #333333;"><span class="Apple-style-span" style="font-size: 15px; line-height: 23px;"><i><br /> </i></span></span><br /> <span class="Apple-style-span" style="font-family: inherit;"><span class="Apple-style-span" style="color: blue;">Spring Roo</span> revolutionized the concept of 'Rapid Application Development' by on-demand resource allocation and service provisioning through load-time-weaving of aspects !</span><br /> <span class="Apple-style-span" style="font-family: inherit;">Couple of lines of commands and the complete gwt-spring-mvc application launched into Google App Engine !</span><br /> <span class="Apple-style-span" style="font-family: inherit;">At the same time, <span class="Apple-style-span" style="color: blue;">MongoDB</span> came up with a 'ridiculously simple' json-based api to provide super-fast asynchronous highly-scalable, available, partitioned data-storage with simple ways to crud, map-reduce, search, index ! It challenged the 'conventional wisdom' of building 'ultra-pathetic', 'super-complex' enterprise OLTP and BI solutions ! <span class="Apple-style-span" style="color: blue;">Redis </span>garnered much excitement by providing a brilliant 'data-structure key-value storage' !</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;">Its no wonder that <span class="Apple-style-span" style="color: blue;">Spring quickly provided a wrapper to access MongoDB, Redis, Riak, Node.js.&nbsp;</span></span><br /> <br /> <div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="color: #333333; font-family: inherit; font-size: 15px; line-height: 23px;"><i>'Spring Data promotes the&nbsp;<span style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">classic</span>&nbsp;Spring values, enhancing developer productivity by removing the API noise, boiler-plate code and resource management and offering a consistent programming model.'</i></span></div><div>Birds of same feather flock together :-)</div><span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;"><span class="Apple-style-span" style="color: blue;"><b>Soon.. SpringSource reached the point of culmination by offering ... CloudFoundry !</b></span>&nbsp;</span><br /> <span class="Apple-style-span" style="font-family: inherit;">Its motto<span class="Apple-style-span" style="color: purple;"> 'Every Programmer is a Hero'</span> !</span><br /> <span class="Apple-style-span" style="font-family: inherit;">Just by hiding gory details of IaaS, PaaS (which hitherto seemed like sole properties of large enterprise companies) ...</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <br /> <div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="font-family: inherit;">It provides the<span class="Apple-style-span" style="color: blue;"> much-awaited magic-touch to launch an user application directly onto cloud, making it always available, fail-safe, scalable, manageable</span> !&nbsp;</span></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="font-family: inherit;">User can simply specify/change/manage what sorts of service it requires (mongodb, redis, grails, node.js etc..) and specify the target (amazon cloud, vmware, cloud foundry , azure, etc..) .. all dynamically !</span></div><br /> <br /> Well ! the only change you need to make is -(1) inside spring-beans xml, specify a <cloud profile...=""> with the name of dataSource that (2) you need to add as a service to your deployed app - on the fly (through STS / CLI) ! Thats it ! WoW !</cloud><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="color: blue;">When Spring Integration is supported in Cloud Foundry</span>, its going to join another long-time friend of developers - Mule ... which has already provided industry's first iPaas (Integration Platform as Service) !<br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;">Enough theory ! Its time to get our hands dirty !</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <b>Build Cloud-ready App using Ruby :</b><br /> <span class="Apple-style-span" style="font-family: inherit;">The CLI Tool - VMC (vmware cloud-controller) can be installed by ruby gem.</span><br /> VMC simply make various rest requests (push / update / target / start / stop ..). Accordingly cloud-controller delegates the requests to droplet execution engine which routes the requests to service providers (allocated by cloud-controllers).<br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;">Here goes the simple steps to push a ruby 'Say hello' app to Cloud !</span><br /> <a href="http://seroter.wordpress.com/2011/05/11/6-quick-steps-for-windows-net-folks-to-try-out-cloud-foundry/"><span class="Apple-style-span" style="font-family: inherit;">http://seroter.wordpress.com/2011/05/11/6-quick-steps-for-windows-net-folks-to-try-out-cloud-foundry/</span></a><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="font-family: inherit;">require 'sinatra'&nbsp;</span></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="font-family: inherit;">get '/' do &nbsp;</span></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="font-family: inherit;">&nbsp; &nbsp; "Welcome ! &nbsp;You are now in Cloud Foundry! "</span></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="font-family: inherit;">end</span></div><span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <b>Launch a Spring-MySql App into Cloud :</b><br /> <br /> <div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="color: blue; font-family: inherit;">Nothing gets more exciting to be able to deploy our very own sample app on cloud !</span></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="font-family: inherit;">Starting point IDE :&nbsp;<a href="http://blog.springsource.com/2011/04/13/using-cloud-foundry-from-sts/">http://blog.springsource.com/2011/04/13/using-cloud-foundry-from-sts/</a></span></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">CLI :&nbsp;<span class="Apple-style-span" style="font-family: tahoma, times, serif; font-size: 13px;"><a href="http://support.cloudfoundry.com/entries/20012337-getting-started-guide-command-line-vmc-users" rel="nofollow" target="_blank">http://support.cloudfoundry.com/entries/20012337-getting-started-guide-command-line-vmc-users</a></span></div><br /> <span class="Apple-style-span" style="font-family: inherit;">1. This sample code 'To-Do List Manager' just works and need no tweaking !</span><br /> <a href="https://github.com/daveys/spring-todo"><span class="Apple-style-span" style="font-family: inherit;">https://github.com/daveys/spring-todo</span></a><br /> <span class="Apple-style-span" style="font-family: inherit;">** Login Credentials specified in security-context.xml</span><br /> <span class="Apple-style-span" style="font-family: inherit;">2. Just need to remember that we should create a 'tododb' service and link it to the application !</span><br /> <span class="Apple-style-span" style="font-family: inherit;">Upon starting the app if it does not work on first chance, we just need to restart it once or twice !</span><br /> <span class="Apple-style-span" style="font-family: inherit;">3. Inspect logs</span><br /> <span class="Apple-style-span" style="color: #333333; font-family: inherit; font-size: 12px; line-height: 17px;"># look at the main logs that contain crash information<br style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" />vmc crashlogs my-app<br style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" /># to inspect other logs (migration.log, staging.log, etc.)<br style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" />vmc files my-app logs/migration.log</span><br /> <span class="Apple-style-span" style="font-family: inherit;">4.Check-out&nbsp;<a href="http://blog.springsource.com/2011/04/12/cloud-foundry-for-spring-developers/">http://blog.springsource.com/2011/04/12/cloud-foundry-for-spring-developers/</a></span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;"><b>Launch a Spring-MongoDB App on the Cloud :</b></span><br /> <span class="Apple-style-span" style="font-family: inherit;">1.</span>&nbsp;Download <b>hello-spring-mongodb</b> from cloudfoundry samples.<br /> <span class="Apple-style-span" style="font-family: inherit;">2. Import the project in <b>STS</b>.</span><br /> <span class="Apple-style-span" style="font-family: inherit;">3. Rename the application to some unique name like <user-name>-<b>mongoapp</b></user-name></span><br /> <span class="Apple-style-span" style="font-family: inherit;">4. Remember to add the mongodb namespace - in <b>root-context.xml</b></span><br /> <span class="Apple-style-span" style="font-family: inherit;">xmlns:mongo="http://www.springframework.org/schema/data/mongo" and specify the schema location</span><br /> <span class="Apple-style-span" style="font-family: inherit;">http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;">5. Now few Command Line tasks..</span><br /> <span class="Apple-style-span" style="font-family: inherit;">6.&nbsp;</span>Package the app : <b>mvn package</b><br /> <span class="Apple-style-span" style="font-family: inherit;">7.&nbsp;</span>Test that vmc target is<b> api.cloudfoundry.com</b><br /> <span class="Apple-style-span" style="font-family: inherit;">8.&nbsp;</span>Next attach a mongoDB service and start the service as shown below...<br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisDAvF8RIdTjX_ysGOyPJmDgXAcvg24Jw2rtYpzvKS-X0LPa-vSwUaXu8CDxl0dr-j4H6QqT-Sfb3AauxVePi1EoPrW6Pgqf3qYTRZQHTlp_B_ivmlOyaKSkhS4QzSuZYr5m4yaXX9fjY/s1600/MongoDBAppDeploy.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span class="Apple-style-span" style="font-family: inherit;"><img border="0" height="427" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisDAvF8RIdTjX_ysGOyPJmDgXAcvg24Jw2rtYpzvKS-X0LPa-vSwUaXu8CDxl0dr-j4H6QqT-Sfb3AauxVePi1EoPrW6Pgqf3qYTRZQHTlp_B_ivmlOyaKSkhS4QzSuZYr5m4yaXX9fjY/s640/MongoDBAppDeploy.JPG" width="640" /></span></a></div><span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;">9. The service name should match with the one specified in '<b>mongoTemplate</b>' e.g. '<b>mongodb-hello-mongo</b>'</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;">10. Finally we should expect the output as specified in -&nbsp;<a href="https://github.com/SpringSource/cloudfoundry-samples/wiki/Spring-Hello-MongoDB-Sample-Application">https://github.com/SpringSource/cloudfoundry-samples/wiki/Spring-Hello-MongoDB-Sample-Application</a></span><br /> <span class="Apple-style-span" style="font-family: inherit;">----------------------------------------------------------------------------</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><b>A ready-to-go powerful web-flow sample :</b></span><br /> <span class="Apple-style-span" style="font-family: inherit;">See Live :&nbsp;</span><a href="http://travel.cloudfoundry.com/">http://travel.cloudfoundry.com</a><br /> ----------------------------------------------------------------------------<br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="color: blue; font-family: inherit;">We can easily tweak any of the above apps in STS to make it a real-life robust app and take full advantage of free cloud !</span><br /> <span class="Apple-style-span" style="font-family: inherit;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: inherit;">For more<span class="Apple-style-span" style="color: blue;"><b> complicated examples involving Social Search, Events and Caching -</b></span> we can consult the following articles : &nbsp;this is a SUPER SHOT ... &nbsp;&nbsp;<a href="http://blog.springsource.com/2011/05/03/using-mongodb-redis-node-js-and-spring-mvc-in-a-single-cloud-foundry-application/">http://blog.springsource.com/2011/05/03/using-mongodb-redis-node-js-and-spring-mvc-in-a-single-cloud-foundry-application/</a>&nbsp; .....</span><br /> <span class="Apple-style-span" style="font-family: inherit;">and another ACTION-PACKED sample ...&nbsp;<a href="http://blog.springsource.com/2011/04/27/getting-started-redis-spring-cloud-foundry/">http://blog.springsource.com/2011/04/27/getting-started-redis-spring-cloud-foundry/</a></span><br /> <br /> <b>A very complex streaming-events sample </b>where external source sends events to redis store. Events are sent to browser using ajax-long-polling (instant update) and also pushed into Mongo for future lookup and &nbsp;analysis (BI) . Cloudfoundry makes it look so simple and easy to learn the concepts !<br /> <br /> Here I show the steps ... &nbsp;(assumption : ticker-analysis mongo service and ticker-stream redis service are already created) :<br /> <br /> <div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg40k8r0RWQsbmCx4Jtz28ZCJ2JtlBMjDNg5CrU9x82rfJXtWn-uOrpl275e7RU9tudUEG1FDlxkGHobyrjp-qREbDiy5pF9vCyzM0SKgLuKdoJchzvpOGvq4IsoTTdTQ9cIPefrZIM7Ww/s1600/streaming_events_flow.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="366" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg40k8r0RWQsbmCx4Jtz28ZCJ2JtlBMjDNg5CrU9x82rfJXtWn-uOrpl275e7RU9tudUEG1FDlxkGHobyrjp-qREbDiy5pF9vCyzM0SKgLuKdoJchzvpOGvq4IsoTTdTQ9cIPefrZIM7Ww/s640/streaming_events_flow.JPG" width="640" /></a></div><br /> See it live :&nbsp;<a href="http://streaming-events.cloudfoundry.com/">http://streaming-events.cloudfoundry.com</a><br /> More food for thoughts :&nbsp;<a href="http://blog.mongodb.org/post/6587009156/cloudfoundry-mongodb-and-nodejs">http://blog.mongodb.org/post/6587009156/cloudfoundry-mongodb-and-nodejs</a><br /> <br /> <span class="Apple-style-span" style="color: blue;"><span class="Apple-style-span" style="font-family: inherit;"><b>References :</b></span><span class="Apple-style-span" style="font-family: inherit;">&nbsp;&nbsp;</span></span><br /> <span class="Apple-style-span" style="font-family: inherit;">Comprehensive List : &nbsp;<a href="http://devstonez.wordpress.com/2011/04/13/all-you-need-to-know-about-cloud-foundry-blogs-articles-reviews-tutorials-videos/">http://devstonez.wordpress.com/2011/04/13/all-you-need-to-know-about-cloud-foundry-blogs-articles-reviews-tutorials-videos/</a></span><br /> Command Line Reference :&nbsp;<a href="https://github.com/cloudfoundry/vmc/blame/master/README.md">https://github.com/cloudfoundry/vmc/blame/master/README.md</a><br /> <br /> <b>Architecture :&nbsp;</b><br /> <a href="http://www.slideshare.net/mccrory-me/cloud-foundry-a-developers-perspective">http://www.slideshare.net/mccrory-me/cloud-foundry-a-developers-perspective</a>&nbsp;<a href="http://www.slideshare.net/lethee/cloud-foundry-practice">http://www.slideshare.net/lethee/cloud-foundry-practice</a><br /> <br /> <b>Ruby on CloudFoundry :&nbsp;</b><br /> <a href="http://support.cloudfoundry.com/entries/20019747-ruby-and-cloudfoundry-things-to-know">http://support.cloudfoundry.com/entries/20019747-ruby-and-cloudfoundry-things-to-know</a><br /> <a href="http://www.slideshare.net/oisin/constructing-web-apis-with-rack-sinatra-and-mongodb">http://www.slideshare.net/oisin/constructing-web-apis-with-rack-sinatra-and-mongodb</a><br /> <br /> <a href="http://docs.aptana.com/docs/index.php/Plugging_Aptana_into_an_existing_Eclipse_configuration">http://docs.aptana.com/docs/index.php/Plugging_Aptana_into_an_existing_Eclipse_configuration</a><br /> <a href="http://update1.aptana.org/rails/1.2.1.23268/index.html">http://update1.aptana.org/rails/1.2.1.23268/index.html</a><br /> <a href="http://www.ibm.com/developerworks/opensource/library/os-rubyeclipse/">http://www.ibm.com/developerworks/opensource/library/os-rubyeclipse/</a><br /> <br /> <b>MongoDB on CLoudFoundry :</b><br /> <br /> <a href="https://github.com/SpringSource/cloudfoundry-samples/wiki/Spring-MongoDB">https://github.com/SpringSource/cloudfoundry-samples/wiki/Spring-MongoDB</a><br /> <a href="http://mongo.cloudfoundry.com/">http://mongo.cloudfoundry.com/</a><br /> <a href="https://github.com/SpringSource/cloudfoundry-samples/wiki/Spring-Hello-MongoDB-Sample-Application">https://github.com/SpringSource/cloudfoundry-samples/wiki/Spring-Hello-MongoDB-Sample-Application</a><br /> <a href="http://www.slideshare.net/lethee/mongo-db-with-spring-data-document">http://www.slideshare.net/lethee/mongo-db-with-spring-data-document</a><br /> <br /> <b>Redis on CloudFoundry in Ubuntu :</b><br /> <a href="http://blog.aestasit.com/taking-vmware-cloud-foundry-on-a-test-drive/">http://blog.aestasit.com/taking-vmware-cloud-foundry-on-a-test-drive/</a><br /> <a href="http://redis.io/topics/twitter-clone">http://redis.io/topics/twitter-clone</a><br /> <a href="http://static.springsource.org/spring-data/data-keyvalue/examples/retwisj/current/#retwisj:design:persistence">http://static.springsource.org/spring-data/data-keyvalue/examples/retwisj/current/#retwisj:design:persistence</a><br /> <br /> <br /> <br /> <br /> <br /> </div></description>
<link>http://musings-on-technology.blogspot.com/2011/05/cloudfoundry-simplicity-matters.html</link>
<author>noreply@blogger.com (Kaniska)</author>
<media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisDAvF8RIdTjX_ysGOyPJmDgXAcvg24Jw2rtYpzvKS-X0LPa-vSwUaXu8CDxl0dr-j4H6QqT-Sfb3AauxVePi1EoPrW6Pgqf3qYTRZQHTlp_B_ivmlOyaKSkhS4QzSuZYr5m4yaXX9fjY/s72-c/MongoDBAppDeploy.JPG" height="72" width="72"/>
<thr:total>0</thr:total>
</item>
<item>
<guid isPermaLink="false">tag:blogger.com,1999:blog-1373851816248476399.post-7896261480984620126</guid>
<pubDate>Mon, 02 May 2011 06:38:00 +0000</pubDate>
<atom:updated>2011-05-03T10:29:15.864+05:30</atom:updated>
<title>Cloud and Big Data Meetup</title>
<description><div dir="ltr" style="text-align: left;" trbidi="on">May 1st, 2011 Micorsoft Campus, Cloud Computing Camp !<br /> A very Rewarding Experience indeed !<br /> <br /> My personal interest was to understand how Cloud Computing, Hadoop, NoSql helping Developers to solve problems from purely a Programmer's Viewpoint.<br /> <br /> <span class="Apple-style-span" style="font-size: large;">Food for thoughts</span><br /> <br /> End of the day, it answered some of the most important questions<br /> - <span class="Apple-style-span" style="color: purple;">how to choose a cloud service provider ?</span><br /> <span class="Apple-style-span" style="color: purple;">- how to leverage PaaS and IaaS and whats the thin line between them?</span> <br /> <span class="Apple-style-span" style="color: purple;">- why companies like Netflix very selectively has chosen Amazon Cloud &nbsp;and how they are creating platform on AWS like Cassandra as a Service ?</span><br /> - <span class="Apple-style-span" style="color: purple;">How to adopt Open Sourced CloudFoundry and Microsoft Azure PaaS ?</span><br /> - <span class="Apple-style-span" style="color: purple;">What OpenStack can offer to individual developer / start-ups to enjoy the fruits of IaaS at little cost ?&nbsp;</span><br /> <br /> And of course there were very thoughtful reflections on how to choose what type of&nbsp;<span class="Apple-style-span" style="background-color: white;"><span class="Apple-style-span" style="color: blue;">CAP model</span></span>, deep-diving into <span class="Apple-style-span" style="color: blue;">MongDB internals</span> and talk on a wonderful array of tools to make op's and dev's life smooth while <span class="Apple-style-span" style="color: blue;">building a</span> <span class="Apple-style-span" style="color: blue;">scalable system</span> !!<br /> <br /> <span class="Apple-style-span" style="font-size: large;">Brush the basics and sky-rocket into Clouds</span><br /> <br /> It all started with a great Keynote Speech from Cisco CTO -<br /> A quick reminder of basic properties of a Cloud Provider -<br /> <span class="Apple-style-span" style="color: blue;">Shared Resource, Scalability, Self-Service, Multiple Data-Centers, Measurable Resources, Design-for-failure, Auto-Recovery and Centralized monitoring.</span><br /> <br /> These are well-known facts. But the most interesting point to note was <span class="Apple-style-span" style="color: purple;">evolution of <b>OpenStack</b></span>.<br /> - <span class="Apple-style-span" style="color: blue;">Open eliminates Vendor Lock-in. Freedom to federate and move between clouds.</span><br /> <br /> The intricate details of Network Virtualization, Hypervisor integration didn't attract me much ! Rather was interested in tools around Open Source Clouding.<br /> <a href="http://www.slideshare.net/socializedsoftware/crash-course-in-open-source-cloud-computin">http://www.slideshare.net/socializedsoftware/crash-course-in-open-source-cloud-computin</a>g<br /> <br /> <span class="Apple-style-span" style="color: purple;">Convergence of Network, Compute and Storage is going to be the driving point</span> for handling information explosion and incredible video transmission in coming years.<br /> <a href="http://www.slideshare.net/lewtucker/openstack-time-is-now-lew-tucker">http://www.slideshare.net/lewtucker/openstack-time-is-now-lew-tucker</a><br /> <br /> <span class="Apple-style-span" style="font-size: large;">Case Study - Simplify life</span><br /> <br /> Netflix being one of the largest Amazon Cloud Consumers, shared its pain points and need for migrating to the Cloud.<br /> <span class="Apple-style-span" style="color: purple;">- How Cloud helps us get rid of the 'indefinite wait-cycle' problem in traditional data-center.</span><br /> <span class="Apple-style-span" style="color: purple;">- Keep waiting for 'Permission Grant', 'More Space Allocation' , 'Re-organize Capacity','Endless meetings with IT' etc. ...&nbsp;</span><br /> <br /> No more waiting ! By 2012 probably Cloud Model will be seamlessly part of every single software maker !!<br /> In case of Netflix -<span class="Apple-style-span" style="color: blue;"> Amazon API is the IT Dept !!</span><br /> The best part is the development to deployment flow -<span class="Apple-style-span" style="color: purple;"> Build, War, Rpm, bakes AMI, launch in cloud! Huh !</span><br /> <span class="Apple-style-span" style="color: purple;">How did Cloud simplify life ?</span><br /> <span class="Apple-style-span" style="color: blue;">Quoting&nbsp;Adrian .... &nbsp; (Cloud Architecture)</span><br /> <blockquote>" Central SQL -&gt; Distributed Key/Value NoSQL<br /> &nbsp;&nbsp;Sticky In-Memory Session &gt; Shared Memcached Session (for Others cold cache like&nbsp;MySQL Native Memory / Terracotta Big-Table)</blockquote><blockquote>&nbsp;Chatty Protocol &gt; Latency Tolerant Protocol<br /> &nbsp;&nbsp;Tangled Service Interface &gt; Layered Service Interface<br /> &nbsp;&nbsp;Components as Jars &gt; Components as Service<br /> &nbsp;&nbsp;Fat Complex objects &gt; Lightweight Serializable Objects .."</blockquote>Here goes the great story - <a href="http://www.slideshare.net/adrianco/migrating-to-public-cloud">http://www.slideshare.net/adrianco/migrating-to-public-cloud</a><br /> <br /> On a different context, another interesting article from Adrian Cockcroft on<span class="Apple-style-span" style="color: purple;"> 'creating NoSql service over Amazon Cloud'</span> - <span class="Apple-style-span" style="color: blue;">http://prezi.com/veagqhsz38u8/nosql-maslows-hierarchy-of-reads-and-writes/</span><br /> <br /> <span class="Apple-style-span" style="font-size: large;">PaaS - the Jewel Box</span><br /> <br /> It was really exciting to know that <span class="Apple-style-span" style="color: purple;">Windows Azure is actually an OS on Web which allows user to run any windows-compatible application like accessing database blobs, NoSql data storage, VPN, CDN, Service Bus, Access Control, Monitoring.</span><br /> <br /> Anyone interested to try out Azure, can just <span class="Apple-style-span" style="color: purple;">login at http://windowsazurepass.com/</span> with passcode '<span class="Apple-style-span" style="color: purple;">meetup</span>'<br /> <br /> Well ! Finally the much-awaited .. <b>CloudFoundry </b>! <br /> <span class="Apple-style-span" style="color: purple;">VMWare-SpringSource means so much for the Java Community after the demise of Sun !!!</span><br /> Now you get Grovvy-on-grals, Redis, Node.js and plenty of other services out-of-the CloudFoundry PaaS !<br /> Tthe open source advocate Ezra gave a lightning talk about the <span class="Apple-style-span" style="color: blue;">internals of CloudFoundry</span> :<br /> <blockquote>"First user develops application foo.<br /> vmc push foo -&gt; talks to Cloud Controller through Rest<br /> Cloud Controller takes a snapshot of the 'foo' app structure.<br /> Converts this application to a Droplet runnable in queue.<br /> Droplet Execution Agent node can sit on Amazon / RackSpace completely abstracted from User.<br /> Staging process finds what runtime to launch and load all infrastructure for example it will introspect a war file &nbsp;and find the require jdbc driver and load it and so on.<br /> Staging process send messages to all DEA nodes to find who is least-loaded and can execute the request.<br /> All components are connected through ESB.<br /> Also there is a HealthManager Tool that polls Status Table and matches with Real World State and broadcasts messages ! &nbsp;..." &nbsp; <span class="Apple-style-span" style="color: blue;">.. &nbsp;Thats &nbsp;a Long Story cut Short !</span></blockquote><blockquote>Here goes the full story - <a href="http://blog.cloudfoundry.com/post/4754582920/cloud-foundry-open-paas-deep-dive">http://blog.cloudfoundry.com/post/4754582920/cloud-foundry-open-paas-deep-dive</a></blockquote>Well if you are lucky to get your CloudFoundry Passcode , you can start playing with it through great STS IDE !<br /> <br /> <span class="Apple-style-span" style="font-size: large;">Build your Dinosaur to crunch Big Data</span><br /> <br /> Okay ! Now that we were surfing long on clouds .. its time to understand<span class="Apple-style-span" style="color: blue;"> best practices of handling Big Data </span>(that eventually may fly on cloud) !<br /> <br /> Paco Nathan of IMVU fame delivered a very valuable lecture !<br /> <a href="http://www.slideshare.net/pacoid/hidden-gems-found-with-hadoop">http://www.slideshare.net/pacoid/hidden-gems-found-with-hadoop</a><br /> <br /> The Take Away message :<br /> - <span class="Apple-style-span" style="color: purple;">Select Data Frameworks based on your Data Access Patterns :</span><br /> <span class="Apple-style-span" style="color: purple;">- Relational Data is not good for Queues, Polling Operations, Social graph, Data Analysis and so on !</span><br /> Just can't resist to highlight the following &nbsp;from the slides !<br /> <span class="Apple-style-span" style="color: blue;">How to apply CAP in various scenarios ?</span><br /> <blockquote>" Financial Transactions - General Ledgerin RDBMS - &nbsp;CAx<br /> ad-hoc queries - hosted MySQL - CAx<br /> log - rotation - Riak - xxP<br /> Search Index - Lucene, Solr &nbsp;- xAP<br /> Static Content Archive - S3 - xAP<br /> Customer facts - Redis , Membase &nbsp;- xAP<br /> Distributed counters, sets - Redis - xAP<br /> CRUD - key/value &nbsp; - CxP<br /> Data preparation - Hadoop/ Hive - CxP<br /> Graph Analysis - Hadoop + Redis + Graph - CxP<br /> Data Mart - Hadoop / Hive / Hbase &nbsp;- CxP.."</blockquote>In the same line of identifying correct methodology for data analysis based on data access pattern, <span class="Apple-style-span" style="color: blue;">Apple threw some light about its in-house analytics flow :</span><br /> <blockquote>"Sensors connect to Cassandra over rest to push data (the Click / Navigation / other User Events).<br /> Aggregators read data from Cassandra Key-Value store then aggregate the data through offline batch and replace the data for the keys (compaction) inside K-V Store..."</blockquote><span class="Apple-style-span" style="font-size: large;">Instrument, Measure , Manage Chaos ! Celebrate !</span><br /> <br /> After the thought-provoking sessions,<span class="Apple-style-span" style="color: purple;"> it was time to ride though the Twitter Roller Coaste</span>r !<br /> The Mantra<br /> - <span class="Apple-style-span" style="color: blue;">'We can be Successful only if We can measure'</span><br /> <span class="Apple-style-span" style="color: blue;">- Adopt this early and correctly as per your enterprise system architecture !</span><br /> - <span class="Apple-style-span" style="color: blue;">Remember to minimize - MTTD (Mean time to Detect) and , MTTR (Mean time to Recover) !</span><br /> - &nbsp;<span class="Apple-style-span" style="color: blue;">Instrument Everything ! Cache all decoupled data layers !&nbsp;</span><br /> -&nbsp;Use the correct tools<br /> &nbsp;- for Ruby on Rails &nbsp;use <span class="Apple-style-span" style="color: purple;">Passenger </span>(apache load-balancer fix) , <span class="Apple-style-span" style="color: purple;">Unicorn </span>(Server) in place of Mongrel, use &nbsp; <br /> <span class="Apple-style-span" style="color: purple;">&nbsp;&nbsp; &nbsp;Google Perf Tool</span>.<br /> &nbsp;&nbsp;- In general use <span class="Apple-style-span" style="color: purple;">Puppet </span>and <span class="Apple-style-span" style="color: purple;">Chef </span>as Configuration Tools.<br /> &nbsp;&nbsp;- Explore these tools and use as per need .. <span class="Apple-style-span" style="color: blue;">Whales</span>, <span class="Apple-style-span" style="color: blue;">RainBird</span>, <span class="Apple-style-span" style="color: blue;">Ivy</span>, <span class="Apple-style-span" style="color: blue;">Artifactory</span>, <span class="Apple-style-span" style="color: blue;">AppDynamics</span>, <span class="Apple-style-span" style="color: blue;">EpicNMS</span>..<br /> <a href="http://www.slideshare.net/mattray/scale-2011-deploying-openstack-with-chef">http://www.slideshare.net/mattray/scale-2011-deploying-openstack-with-chef</a><br /> <br /> Enough of appetizer ... <span class="Apple-style-span" style="color: purple;">the meal is served hot here </span>-&nbsp;<a href="http://www.slideshare.net/netik/john-adams-talk-cloudy">http://www.slideshare.net/netik/john-adams-talk-cloudy</a><br /> <br /> <span class="Apple-style-span" style="font-size: large;">Crash Course - learn MongoDB</span><br /> <br /> Next what could be more enticing than <span class="Apple-style-span" style="color: purple;">plunging into the internals of MongoDB </span>!<br /> Alvin Richards&nbsp;is simply great -- <a href="http://www.scribd.com/doc/50019946/MongoAsia-Scaling">http://www.scribd.com/doc/50019946/MongoAsia-Scaling</a> !<br /> Sharding could be ridiculously simple just by creating a compound key <span class="Apple-style-span" style="color: purple;">{server:1, application:1, time:1}</span> and participating in shard <span class="Apple-style-span" style="color: purple;">- db.runCommand({addshard : &nbsp;"shard1"})</span> ... &nbsp;Huh !<br /> <br /> He reflected on -&nbsp;<span class="Apple-style-span" style="color: purple;">Right-balanced-Indexing, Parallel execution of Queries, &nbsp;Range-based partitions, Automatic Sharding, Consistent Hashing, Replication with asynch master/slave, automatic failover through consensus election and many more !&nbsp;</span><br /> For &nbsp;a <span class="Apple-style-span" style="color: blue;">technical deep-dive into consistency models</span> look into - <a href="http://www.10gen.com/video/mongosv2010/consistency">http://www.10gen.com/video/mongosv2010/consistency</a><br /> For hands on refer to <a href="https://github.com/SpringSource/spring-data-document-exampl">https://github.com/SpringSource/spring-data-document-exampl</a>es and follow <a href="http://www.10gen.com/video/mongosv2010/spring">http://www.10gen.com/video/mongosv2010/spring</a><br /> <br /> <span class="Apple-style-span" style="font-size: large;">Build a successful SaaS Business ! Sweet dreams !</span><br /> <br /> Well ! &nbsp;After the rewarding technical sessions it was just perfect to wrap up the day with some insights into <span class="Apple-style-span" style="color: blue;">building successful SaaS Business !</span><br /> <a href="http://www.slideshare.net/KenRutsky/bridging-to-saas-success-a-basic-blueprint">http://www.slideshare.net/KenRutsky/bridging-to-saas-success-a-basic-blueprint</a><br /> <br /> <span class="Apple-style-span" style="color: #4c1130; font-size: large;">Big thanks to Sebastian and other Event organizers !</span><br /> <br /> References :&nbsp;<a href="http://www.meetup.com/cloudcomputing/events/16701362/">http://www.meetup.com/cloudcomputing/events/16701362/</a><br /> <br /> </div></description>
<link>http://musings-on-technology.blogspot.com/2011/05/cloud-and-big-data-meetup.html</link>
<author>noreply@blogger.com (Kaniska)</author>
<thr:total>0</thr:total>
</item>
<item>
<guid isPermaLink="false">tag:blogger.com,1999:blog-1373851816248476399.post-5257111336353048075</guid>
<pubDate>Fri, 22 Apr 2011 22:56:00 +0000</pubDate>
<atom:updated>2011-04-23T04:26:17.553+05:30</atom:updated>
<title>Build Rapid Fire Cloud Ready Apps</title>
<description><div dir="ltr" style="text-align: left;" trbidi="on"><br /> Build CloudFoundry Apps from STS<br /> <a href="http://blog.springsource.com/2011/04/12/cloud-foundry-for-spring-developers/">http://blog.springsource.com/2011/04/12/cloud-foundry-for-spring-developers/</a><br /> <a href="http://blog.springsource.com/2011/04/13/using-cloud-foundry-from-sts/">http://blog.springsource.com/2011/04/13/using-cloud-foundry-from-sts/</a><br /> <br /> Watch the Webinar and Download the Slides !<br /> <a href="http://www.springsource.com/webinar/getting-started-spring-and-springsource-tool-suite">http://www.springsource.com/webinar/getting-started-spring-and-springsource-tool-suite</a><br /> <br /> Grails-Integration -&nbsp;<a href="http://www.grails.org/STS+Integration">http://www.grails.org/STS+Integration</a><br /> <br /> Spring MVC with STS -&nbsp;<a href="http://www.giantflyingsaucer.com/blog/?p=2373">http://www.giantflyingsaucer.com/blog/?p=2373</a><br /> Great MVC Resource -&nbsp;<a href="http://www1.springsource.com/files/Getting%20Started%20with%20Spring%20and%20STS%203-17-11.pdf">http://www1.springsource.com/files/Getting%20Started%20with%20Spring%20and%20STS%203-17-11.pdf</a><br /> <br /> <br /> Google App Engine with STS -&nbsp;<a href="http://code.google.com/webtoolkit/doc/latest/tutorial/roo-sts.html">http://code.google.com/webtoolkit/doc/latest/tutorial/roo-sts.html</a><br /> <br /> Spring Insight for Monitoring :&nbsp;<a href="http://blog.espenberntsen.net/tag/spring-insight/">http://blog.espenberntsen.net/tag/spring-insight/</a></div></description>
<link>http://musings-on-technology.blogspot.com/2011/04/build-rapid-fire-cloud-ready-apps.html</link>
<author>noreply@blogger.com (Kaniska)</author>
<thr:total>1</thr:total>
</item>
<item>
<guid isPermaLink="false">tag:blogger.com,1999:blog-1373851816248476399.post-839234393668557647</guid>
<pubDate>Tue, 19 Apr 2011 20:05:00 +0000</pubDate>
<atom:updated>2011-04-20T10:55:08.806+05:30</atom:updated>
<category domain="http://www.blogger.com/atom/ns#">PaaS</category>
<title>Another Big Win for App Developers - Cloud Foundry the PaaS Pioneer</title>
<description><div dir="ltr" style="text-align: left;" trbidi="on"><span class="Apple-style-span" style="color: blue;">Big Win for App Developers !</span><br /> <br /> VMWare just inaugurated another road to Openness !&nbsp;Welcome to <b>Cloud Foundry</b> !<br /> <br /> The question is how much to Open Up and how Far to allow the user Explore !!<br /> <br /> Rails , Spring, Django, NoSqls, Node.js -- all developers frameworks usherd&nbsp;in new horizons of Programming Model thriving on core values of Portability,&nbsp;Productivity and Simplicity !<br /> <br /> Now VMWare publishing them as Service ..&nbsp;empowering any developer to build a scalable system !<br /> No longer need to wonder about&nbsp;secrets of great marvels of architecture like Facebook, Twitter, Foursquare !<br /> <br /> As per some of the other PaaS offerings are concerned,&nbsp;Salesforce+Heroku powerpack is defintely more geeky than Google' Simplistic&nbsp;App Engine !<br /> <br /> Well MuleSoft recently launched first iPass i.e. Cloud-ready Integration&nbsp;Platform ! Mule has always been the darling of SMBs, a quick enabler of&nbsp;lightweight integration&nbsp;infrastructure.<br /> Now VMWare's out-of-the box offering of RabbitMQ definitely adds to the&nbsp;delight of Programmers by offering more arsennels to create rapid-fire&nbsp;solutions !!!<br /> <br /> Enough talk . lets see it happening !<br /> <a href="http://www.youtube.com/user/vmwaretv?feature=mhum#p/c/71331D676E1D17CA/3/5nYAlZ1YFTg">http://www.youtube.com/user/vmwaretv?feature=mhum#p/c/71331D676E1D17CA/3/5nYAlZ1YFTg</a><br /> Just import &nbsp;Spring Travel App into STS, start a VMWare Server and deploy to Cloud Foundry.<br /> Zero configuration... Huh !<br /> <br /> Right now CloudFoundry is the most imporatant thing to happen !<br /> <br /> Get your feet dirty -&nbsp;<a href="http://blog.springsource.com/2011/04/13/using-cloud-foundry-from-sts/">http://blog.springsource.com/2011/04/13/using-cloud-foundry-from-sts/</a><br /> <br /> Starting up MongoDB &nbsp;in Cloud Foundry -&nbsp;<a href="http://blog.mongodb.org/post/4719358003/getting-started-with-vmware-cloudfoundry-mongodb-and">http://blog.mongodb.org/post/4719358003/getting-started-with-vmware-cloudfoundry-mongodb-and</a><br /> <br /> Launching Cloud : &nbsp;<a href="http://blog.springsource.com/2011/04/12/launching-cloud-foundry/">http://blog.springsource.com/2011/04/12/launching-cloud-foundry/</a><br /> <br /> Full Story : <a href="http://gigaom.com/cloud/vmware-open-source-cloud/">http://gigaom.com/cloud/vmware-open-source-cloud/</a><br /> FAQ :&nbsp;<a href="http://support.cloudfoundry.com/forums/373015-knowledge-base">http://support.cloudfoundry.com/forums/373015-knowledge-base</a><br /> <a href="http://www.cloudfoundry.com/">http://www.cloudfoundry.com/</a><br /> <a href="http://www.youtube.com/user/vmwaretv?feature=mhum#p/c/71331D676E1D17CA">http://www.youtube.com/user/vmwaretv?feature=mhum#p/c/71331D676E1D17CA</a></div></description>
<link>http://musings-on-technology.blogspot.com/2011/04/another-big-win-for-app-developers.html</link>
<author>noreply@blogger.com (Kaniska)</author>
<thr:total>0</thr:total>
</item>
<item>
<guid isPermaLink="false">tag:blogger.com,1999:blog-1373851816248476399.post-3217436291213391721</guid>
<pubDate>Tue, 19 Apr 2011 06:47:00 +0000</pubDate>
<atom:updated>2011-04-19T12:17:55.420+05:30</atom:updated>
<category domain="http://www.blogger.com/atom/ns#">Big Data</category>
<title>Making sense of Diverse Big Data</title>
<description>Recently watched this amazing video - How Space-Time Makes Sense of Big Data <a href="http://gigaom.com/2011/03/23/jeff-jonas-ibm/">http://gigaom.com/2011/03/23/jeff-jonas-ibm/ </a><br /> <br /> Making sense of Big Data ! - <br /> <a href="http://jeffjonas.typepad.com/jeff_jonas/">http://jeffjonas.typepad.com/jeff_jonas/</a><br /> <br /> Colocating Diverse data in same Observational Space.<br /> <br /> <a href="http://jeffjonas.typepad.com/jeff_jonas/2010/11/general-purpose-sensemaking-systems-and-information-colocation.html">http://jeffjonas.typepad.com/jeff_jonas/2010/11/general-purpose-sensemaking-systems-and-information-colocation.html</a><br /> <br /> Now Data will find Data and Relevance will find You !</description>
<link>http://musings-on-technology.blogspot.com/2011/04/making-sense-of-diverse-big-data.html</link>
<author>noreply@blogger.com (Kaniska)</author>
<thr:total>0</thr:total>
</item>
<item>
<guid isPermaLink="false">tag:blogger.com,1999:blog-1373851816248476399.post-4721267848300044182</guid>
<pubDate>Tue, 19 Apr 2011 06:29:00 +0000</pubDate>
<atom:updated>2011-05-04T23:06:15.952+05:30</atom:updated>
<category domain="http://www.blogger.com/atom/ns#">mongodb</category>
<category domain="http://www.blogger.com/atom/ns#">Scalability</category>
<title>Scalability Stories</title>
<description><div dir="ltr" style="text-align: left;" trbidi="on">'It is not the strongest of species that survives, nor the most intelligent. It is the one that is most adaptable to change' -- This statement is so emphatic in every slide !<br /> <br /> <a href="http://www.slideshare.net/tackers/why-we-chose-mongodb-for-guardiancouk">http://www.slideshare.net/tackers/why-we-chose-mongodb-for-guardiancouk</a><br /> <br /> In a nutshell, the N-tier System swiftly evolved from traditional View-Service-DB architecture to View-Service-Memcached-DB.<br /> <br /> Memcached is a very good candidate for distributed indexing. Extract main id from Web Request and then find related associated index and making fast lookup from mysql storage.<br /> <br /> Hibernate can be effectively tuned to handle large data set specially by leveraging terracotta big data. <br /> <br /> But even if ORM hides complexities, DB has strong influence on domain model.<br /> Still one needs to implement Complex Caching and Optimizations.<br /> Memcached still need lots of writes to DB and Ehcache needs to write-behind the DB.<br /> <br /> Facebook heavily relies upon customized php-thrift-memcached-mysql-cassandra power-packed combo !<br /> <br /> Guardian Architecture highlighted a very simplistic idea ... carrying the JSON from backend to frontend and vice-versa. Json/Rest is the smooth replacement for heavyweight soap/Axis2 in middle-layer. Json such a nice forwardly-extensible structure naturally fitting into to javascript and python. Here comes MongoDB - the Document-oriented Database storing parsed Json documents. The best part is schema can be changed in runtime without any down-time.<br /> <br /> JSON can define different classes as tagged documents, multiple docs part of same collection.<br /> <br /> So where has the DB gone ? Vanished !<br /> <br /> And there is Apache SOLR, Hosted in EC2 [Document Oriented Search Engine, (NO DB .. huh) ..] .. a super fast Read API. <br /> <br /> Its a huge paradigm shift.<br /> <br /> <a href="http://www.slideshare.net/tackers/why-we-chose-mongodb-for-guardiancouk">http://www.slideshare.net/tackers/why-we-chose-mongodb-for-guardiancouk</a><br /> <br /> So far the simplest explanation of CAP theory ..&nbsp;<a href="http://www.slideshare.net/jboner/scalability-availability-stability-patterns">http://www.slideshare.net/jboner/scalability-availability-stability-patterns</a><br /> <br /> This is the best Applicability-Chart of CAP theory - slide 9 of&nbsp;<a href="http://www.slideshare.net/pacoid/hidden-gems-found-with-hadoop">http://www.slideshare.net/pacoid/hidden-gems-found-with-hadoop</a><br /> <br /> Upcoming Event : Register at <a href="http://www.10gen.com/conferences/mongosf2011">http://www.10gen.com/conferences/mongosf2011</a></div></description>
<link>http://musings-on-technology.blogspot.com/2011/04/need-for-more-speed.html</link>
<author>noreply@blogger.com (Kaniska)</author>
<thr:total>1</thr:total>
</item>
<item>
<guid isPermaLink="false">tag:blogger.com,1999:blog-1373851816248476399.post-4851646848554716835</guid>
<pubDate>Tue, 19 Apr 2011 04:50:00 +0000</pubDate>
<atom:updated>2011-04-19T10:20:57.487+05:30</atom:updated>
<category domain="http://www.blogger.com/atom/ns#">Cache</category>
<title>Building High-Speed Cache</title>
<description><div dir="ltr" style="text-align: left;" trbidi="on"><br /> <div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-line-height-alt: 14.25pt; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: maroon; font-size: 24pt;">Recently while developing a caching tool capable of providing access to millions of records in sub-seconds, we analysed some of the existing best practices.<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">&nbsp;<b style="mso-bidi-font-weight: normal;">(1)</b>&nbsp;<b style="mso-bidi-font-weight: normal;">One choice is MySql native memory cache for avoiding GC-pauses</b>.<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">MySQL InnoDB storage engine's dictionary cache provides blazing fast data acceess. On demand, data blocks are read from disk and stored in memory using LRU chains or other advanced mechanisms(like MySQL's Midpoint Insertion Strategy) .<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">When should we use MySQL query cache?<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Here is the summary from -&nbsp;</span><span lang="DE"><a href="http://dev.mysql.com/tech-resources/articles/mysql-query-cache.html"><span style="color: windowtext; font-size: 14pt; text-decoration: none;">http://dev.mysql.com/tech-resources/articles/mysql-query-cache.html</span></a><o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 35.35pt; margin-right: 28.35pt; margin-top: 0in; mso-list: l1 level1 lfo1; mso-pagination: widow-orphan; text-indent: -14.15pt;"><span lang="DE" style="color: black; font-family: OpenSymbol; font-size: 14pt;">•<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Identical queries are issued by the same or multiple clients on a repetitive basis.<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 35.35pt; margin-right: 28.35pt; margin-top: 0in; mso-list: l1 level1 lfo1; mso-pagination: widow-orphan; text-indent: -14.15pt;"><span lang="DE" style="color: black; font-family: OpenSymbol; font-size: 14pt;">•<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">The underlying data being accessed is static or semi-static in nature.<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 35.35pt; margin-right: 28.35pt; margin-top: 0in; mso-list: l1 level1 lfo1; mso-pagination: widow-orphan; text-indent: -14.15pt;"><span lang="DE" style="color: black; font-family: OpenSymbol; font-size: 14pt;">•<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Queries have the potential to be resource-intensive and/or build brief, but complexly computed result sets.<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Data warehouse/business intelligence situations, web-based applications, and traditional OLTP systems all qualify on the surface. The query cache looks for identical queries (spacing, upper/lower case, all come into play), ergo the first point above.<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">For internals of InnoDB Cache, refer to the MySql &nbsp;tutorial.<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">In general, MySQl memory cache provides best performance if&nbsp;the majority of your database queries aresimply SELECT statements.&nbsp;<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b style="mso-bidi-font-weight: normal;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Here the speed gain is definitely due to negligible GC pauses and direct disk access.&nbsp;</span></b><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">This type of caching strategy is popular for eCommerce and bidding platform where data query is more frequent than data updates.<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b style="mso-bidi-font-weight: normal;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">(2) An alternative solution is 'Memcached'</span></b><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">&nbsp;which lives in a different process and manages its own GC (optimized for caching). We know that in order to lookup the value for a key, &nbsp;Memcached cache clents issue multiple&nbsp;parallel&nbsp;requests to memcached servers where keys are sharded across those servers.<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">The value-items resolved by Memcached are usable objects while those returned from&nbsp;the MySQL cache must then be converted into objects.<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">As queries get more complex, Memcached provides more efficient performance.<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">If an application (using mysql cache) is load-balanced over multiple servers, then each web process&nbsp;will maintain a&nbsp;separate&nbsp;duplicate cache unless otherwise customized and optimized specifically. &nbsp;<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">But the advantage of using&nbsp;Memcached is that it creates a single global cache available to all&nbsp;web processes . Individual web&nbsp;processes and threads do not maintain their own caches in this case, but rather use the single global cache. When one web process puts data in the cache, it becomes&nbsp;available for all others to access. It leverages fast Network connections.<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">The detail architecture of Memcahed is out of the scope of this article.<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">The memcached server and clients work together to implement one global cache across as many machines as you have. In fact, it's recommended you run both web nodes (which are typically memory-lite and CPU-hungry)<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">and memcached processes (which are memory-hungry and CPU-lite) on the same machines.<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">For a frequently changing data set , Memcahed is surely better than DB Cache as 'bulk of the data are read from memory&nbsp;rather than disk' . But point to note - it still suffers from GC-pauses however minimal it could be !<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b style="mso-bidi-font-weight: normal;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">(3) Now lets see how 'Ehcache' (leveraging Terracotta BigMemory) has really got the basics right !<o:p></o:p></span></b></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Just by simply adopting a very well known Disk I/O pattern of accessing native memory directly from java, it has simply eliminated the 'GC' factor and proved to be the fastest caching option !<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Now the choice is ours - (a) whether to adopt a caching strategy that requires&nbsp;"build a bigger computer with huge RAMs" (b) or use the faster cache in a machine with smaller RAM.<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">The bottom line is - the cache must be outside GC's control. There is no GC mechanism available as of now (unless we leverage JDK 7 'Garbage First' ) -&nbsp;which provides a relief from 'Stop-of the World' stuation.<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">The trick is to implement a smart&nbsp;serialization&nbsp;technique&nbsp;by storing key, value pairs into&nbsp;Direct Byte Buffer.<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Here are some insights -&nbsp;</span><span lang="DE"><a href="http://www.ibm.com/developerworks/java/library/j-nativememory-linux/"><span style="color: windowtext; font-size: 14pt; text-decoration: none;">http://www.ibm.com/developerworks/java/library/j-nativememory-linux/</span></a><o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Direct ByteBuffers (allocated using the java.nio.ByteBuffer.allocateDirect() method) that are backed by native memory rather than Java heap. Direct ByteBuffers can be passed directly to native OS library functions for performing I/O — making them significantly faster in some scenarios because they can avoid copying data between Java heap and native heap.<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">It's easy to become confused about where direct ByteBuffer data is being stored. The application still uses an object on the Java heap to orchestrate I/O operations, but the buffer that holds the data is held in native memory — the Java heap object only contains a reference to the native heap buffer.<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 0in; margin-right: 28.35pt; margin-top: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">&nbsp;A non-direct ByteBuffer holds its data in a byte[] array on the Java heap.<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">A small prototype using ButeBuffer really yielded high performance.<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Here is a sample code for creating direct-buffer-based cache (of course its just for learning, no where close to actual ehcahe implementation).&nbsp;<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-family: Arial, sans-serif; font-size: 9.5pt;"><a href="http://tusharkhairnar.blogspot.com/2010/09/bigmemory-memory-with-no-garbage.html"><span style="color: black; font-family: 'Times New Roman', serif; font-size: 14pt; text-decoration: none;">http://tusharkhairnar.blogspot.com/2010/09/bigmemory-memory-with-no-garbage.html</span></a><o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">This is how Terracotta Bigmemory got the basics of caching right by implementing ByteBuffer and bypassing GC pauses !&nbsp;<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE"><a href="http://blog.terracottatech.com/2010/09/bigmemory_explained_a_bit.html"><span style="color: windowtext; font-size: 14pt; text-decoration: none;">http://blog.terracottatech.com/2010/09/bigmemory_explained_a_bit.html</span></a><o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 0in; margin-right: 28.35pt; margin-top: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">“ ConcurrentMarkSweep collectors can run for hours w/ no full pauses and then&nbsp; <o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 0in; margin-right: 28.35pt; margin-top: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">&nbsp;&nbsp;&nbsp;&nbsp; suddenly stop the world for 30 minutes trying to catch up to the mess they<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 0in; margin-right: 28.35pt; margin-top: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">&nbsp;&nbsp;&nbsp;&nbsp; have made.<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 0in; margin-right: 28.35pt; margin-top: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .... if (k1, v1) is in cache in Ehcache BigMemory, it has no references to (k2,<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 0in; margin-right: 28.35pt; margin-top: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v2). They cannot refer to each other.<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Which means I don't have to walk the cache looking for cross-references in the data like a GC does. No mark-and-sweep. I merely wait for the dev to call cache.remove( element ) or for the evictor to evict stale data. The evictor and the remove() API are signaling my MemoryManager explicitly just like new() and delete() or malloc() and free(). There is no notion of garbage or collection. Only memory re-use and fragmentation over time.&nbsp; ”<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">If we want to enjoy the fruits of fastest cache we have to perform some simple steps :<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">&nbsp;</span><span lang="DE"><a href="http://ehcache.org/documentation/offheap_store.html"><span style="color: windowtext; text-decoration: none;">http://ehcache.org/documentation/offheap_store.html</span></a><o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">(i) Update the Java classpath to include the new&nbsp;ehcache jar<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">(ii) Modify the App Jvm settings to allocate enough direct byte buffer<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">-XX:MaxDirectMemorySize affect the memory available with this call<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; java.nio.ByteBuffer.allocateDirect(int).<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">(iii) Update the ehcache.xml to set the size of the<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">BigMemory off-heap store.<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;"><ehcache><o:p></o:p></ehcache></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;"><cache <o:p="" maxelementsinmemory="10000" name="mycache"></cache></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">overflowToOffHeap="true" maxMemoryOffHeap="4G"/&gt;<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;"><o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Here in this link -&nbsp;</span><span lang="DE"><a href="http://code.google.com/p/lucene-bytebuffer/"><span style="color: windowtext; font-size: 14pt; text-decoration: none;">http://code.google.com/p/lucene-bytebuffer/</span></a></span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">&nbsp;,&nbsp;we can see how Lucene Buffers bypasses memory intensive slow java&nbsp;garbage collector. &nbsp;The objects whose life-cycle is known beforehand can be effectively cleaned up through simple manual process instead of relying on GC.</span><span lang="DE"><o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">The basic advantages of a direct-buffer-based cache (like BigMemory) is :<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">1. Bigmemory takes away all cache data from gc-managed memory to its own bytebuffer-managed world !<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">2. No need to tune GC<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">3. Low hardware cost and operational simplicity.<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">User can have one 16 GB RAM and and make use of all that memory with only 1 JVM. This saves the user from the huge effort of maintaining multiple JVMs to create a distributed cache. User can still go fot it and utilize every byte of the RAM without waiting for GC pause.... “<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">On a different note, though any one can implement a fast cache (as discussed above) using nio package in jdk 1.6; but if the app involes heavy file handling (index files or web resources or jars) then for faster experience we should use jdk 1.7 nio2.<o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Here are reasons : (</span><span lang="DE"><a href="http://download.oracle.com/javase/tutorial/essential/io/legacy.html#mapping"><span style="color: windowtext; font-size: 14pt; text-decoration: none;">http://download.oracle.com/javase/tutorial/essential/io/legacy.html#mapping</span></a></span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">&nbsp;)</span><span lang="DE"><o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Prior to the JDK7 release, the&nbsp;</span><span class="SourceText"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">java.io.File</span></span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">&nbsp;class was the mechanism used for file I/O, but it had several drawbacks.</span><span lang="DE"><o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 35.35pt; margin-right: 28.35pt; margin-top: 0in; mso-list: l0 level1 lfo2; mso-pagination: widow-orphan; text-indent: -14.15pt;"><span lang="DE" style="color: black; font-family: OpenSymbol; font-size: 14pt;">•<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Many methods didn't throw exceptions when they failed, so it was impossible to obtain a useful error message. For example, if a file deletion failed, the program would receive a "delete fail" but wouldn't know if it was because the file didn't exist, the user didn't have permissions, or there was some other problem.<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 35.35pt; margin-right: 28.35pt; margin-top: 0in; mso-list: l0 level1 lfo2; mso-pagination: widow-orphan; text-indent: -14.15pt;"><span lang="DE" style="font-family: OpenSymbol;">•<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">The&nbsp;</span><span class="SourceText"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">rename</span></span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">&nbsp;method didn't work consistently across platforms.</span><span lang="DE"><o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 35.35pt; margin-right: 28.35pt; margin-top: 0in; mso-list: l0 level1 lfo2; mso-pagination: widow-orphan; text-indent: -14.15pt;"><span lang="DE" style="color: black; font-family: OpenSymbol; font-size: 14pt;">•<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">There was no real support for symbolic links.<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 35.35pt; margin-right: 28.35pt; margin-top: 0in; mso-list: l0 level1 lfo2; mso-pagination: widow-orphan; text-indent: -14.15pt;"><span lang="DE" style="color: black; font-family: OpenSymbol; font-size: 14pt;">•<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">More support for metadata was desired, such as file permissions, file owner, and other security attributes.<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 35.35pt; margin-right: 28.35pt; margin-top: 0in; mso-list: l0 level1 lfo2; mso-pagination: widow-orphan; text-indent: -14.15pt;"><span lang="DE" style="color: black; font-family: OpenSymbol; font-size: 14pt;">•<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Accessing file metadata was inefficient.<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 35.35pt; margin-right: 28.35pt; margin-top: 0in; mso-list: l0 level1 lfo2; mso-pagination: widow-orphan; text-indent: -14.15pt;"><span lang="DE" style="font-family: OpenSymbol;">•<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Many of the&nbsp;</span><span class="SourceText"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">File</span></span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">&nbsp;methods didn't scale. Requesting a large directory listing over a server could result in a hang. Large directories could also cause memory resource problems, resulting in a denial of service.</span><span lang="DE"><o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 35.35pt; margin-right: 28.35pt; margin-top: 0in; mso-list: l0 level1 lfo2; mso-pagination: widow-orphan; text-indent: -14.15pt;"><span lang="DE" style="color: black; font-family: OpenSymbol; font-size: 14pt;">•<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">It was not possible to write reliable code that could recursively walk a file tree and respond appropriately if there were circular symbolic links.<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">Jdk 1.7 has great many changes to improve developer's productvity and app's performance - (</span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-family: Arial, sans-serif; font-size: 9.5pt;"><a href="http://tech.puredanger.com/java7/"><span style="color: black; font-family: 'Times New Roman', serif; font-size: 14pt; text-decoration: none;">http://tech.puredanger.com/java7/</span></a></span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;"> )<br style="mso-special-character: line-break;" /> <br style="mso-special-character: line-break;" /> </span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-family: Arial, sans-serif; font-size: 9.5pt;"><o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">The last but not the least, since we are discussing handling of direct byte buffers, its worth keeping in mind the recommendations (IO bound cache) posted at - </span><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-family: Arial, sans-serif; font-size: 9.5pt;"><a href="http://nadeausoftware.com/articles/2008/02/java_tip_how_read_files_quickly"><span style="color: black; font-family: 'Times New Roman', serif; font-size: 14pt; text-decoration: none;">http://nadeausoftware.com/articles/2008/02/java_tip_how_read_files_quickly</span></a><o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">(a) Minimize I/O operations by reading an array at a time, not a byte at a time.&nbsp;An 8Kbyte array is a good size.<br /> (b) Minimize method calls by getting data an array at a time, not a byte at a time.&nbsp;Use array indexing to get at bytes in the array.<br /> (c) Minimize thread synchronization locks if you don't need thread safety.&nbsp;Either make fewer method calls to a thread-safe class, or use a non-thread-safe class like&nbsp;FileChanneland&nbsp;MappedByteBuffer.<br /> (d) Minimize data copying between the JVM/OS, internal buffers, and application arrays.&nbsp;Use&nbsp;FileChannel&nbsp;with memory mapping, or a direct or wrapped array&nbsp;ByteBuffer.<o:p></o:p></span></div><div class="Quotations" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: black; font-size: 14pt;">References :<o:p></o:p></span></b></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE"><a href="http://blog.terracottatech.com/2010/09/bigmemory_explained_a_bit.html"><span style="color: windowtext; text-decoration: none;">http://blog.terracottatech.com/2010/09/bigmemory_explained_a_bit.html</span></a><o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE"><a href="http://ehcache.org/documentation/offheap_store.html"><span style="color: windowtext; text-decoration: none;">http://ehcache.org/documentation/offheap_store.html</span></a><o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE"><a href="http://www.ibm.com/developerworks/java/library/j-nativememory-linux/"><span style="color: windowtext; text-decoration: none;">http://www.ibm.com/developerworks/java/library/j-nativememory-linux/</span></a><o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE"><a href="http://developers.sun.com/learning/javaoneonline/2008/pdf/TS-5419.pdf"><span style="color: windowtext; text-decoration: none;">http://developers.sun.com/learning/javaoneonline/2008/pdf/TS-5419.pdf</span></a><o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE"><a href="http://tusharkhairnar.blogspot.com/2010/09/bigmemory-memory-with-no-garbage.html"><span style="color: windowtext; text-decoration: none;">http://tusharkhairnar.blogspot.com/2010/09/bigmemory-memory-with-no-garbage.html</span></a><o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE"><a href="http://download.oracle.com/javase/tutorial/essential/io/legacy.html#mapping"><span style="color: windowtext; text-decoration: none;">http://download.oracle.com/javase/tutorial/essential/io/legacy.html#mapping</span></a><o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE"><a href="http://java.sun.com/developer/technicalArticles/javase/nio/"><span style="color: windowtext; text-decoration: none;">http://java.sun.com/developer/technicalArticles/javase/nio/</span></a><o:p></o:p></span></div><div class="Textbody" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE"><a href="http://tech.puredanger.com/java7/"><span style="color: windowtext; text-decoration: none;">http://tech.puredanger.com/java7/</span></a><o:p></o:p></span></div><div class="Standard"><br /> </div></div></description>
<link>http://musings-on-technology.blogspot.com/2011/04/building-high-speed-cache.html</link>
<author>noreply@blogger.com (Kaniska)</author>
<thr:total>0</thr:total>
</item>
<item>
<guid isPermaLink="false">tag:blogger.com,1999:blog-1373851816248476399.post-873084490185190088</guid>
<pubDate>Tue, 19 Apr 2011 04:45:00 +0000</pubDate>
<atom:updated>2011-04-19T10:17:06.859+05:30</atom:updated>
<category domain="http://www.blogger.com/atom/ns#">API Design</category>
<title>Designing Better API</title>
<description><div dir="ltr" style="text-align: left;" trbidi="on"><br /> <div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">1.<b>Each API Interface should be the concise Cover Story of What / How User can achieve out of the API.</b></span><span lang="DE" style="font-size: 14pt;"><o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">We should Code the Use-Case as API.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Each class/interface/method should clearly specify if the implementor / extender needs to do something additional to ensure Performance, State management and Threading. It should say&nbsp; how to use it.&nbsp; <o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">It should spell out clearly – what varargs / enums are being used to serve what purpose.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Here are the guidelines provided in </span><span lang="DE"><a href="http://wiki.eclipse.org/Evolving_Java-based_APIs"><span style="color: windowtext; font-size: 14pt; text-decoration: none;">http://wiki.eclipse.org/Evolving_Java-based_APIs</span></a></span><span lang="DE" style="font-size: 14pt;"> <span style="color: black;">&nbsp;- what I call as </span></span><span lang="DE"><a href="http://wiki.eclipse.org/Evolving_Java-based_APIs"><span style="color: windowtext; text-decoration: none;">Bible for API Architects</span></a></span><span lang="DE" style="color: black; font-size: 14pt;"> - Courtecy : Jim des Rivières, IBM</span><span lang="DE"><o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">We should think deeply how the external world going to provide the service for a requirement.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">When we design the requirement as interface if in doubt about an operation we should leave it !<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">2.How to mark an existing API as obsolete ?<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">How to advertise that a new API method is available ?<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">should use @deprecated<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">3. How to communicate to users whether to extend or not ?<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">@noextend&nbsp; (Eclipse API annotation)<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">4. What can be exposed ?<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Only public static final primitive, string constants, enum values and immutable object references.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">5. Document thread-safety of super class methods<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">@ThreadSafe public class Account {<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">&nbsp; @GuardedBy("this") private int balance;<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">,......<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">}<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Make it very clear if a Task needs to wait or scheduled in future.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">ExecutorService service = Executors.newSingleThreadExecutor();<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">// scheduling is quite different<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Future task = service.submit(someRunnable);<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">// compared to waiting<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">task.get(1000, TimeUnit.MILLISECONDS);<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">This builds on the expected knowledge that waiting is something that can cause deadlocks and that<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">developers should do so with care.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">6. <b>An API can be evolved easily if we expose Factory methods instead of Constructors.</b><o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Advantages :<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">(i) we can return a sub-class / interface from the static factory method . so there will not be any tight coupling with a concrete class.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">(ii) we can cache instances<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">(iii) a factory method can be synchronized as a whole, including<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">potential code before the object creation, the code that creates the instances, as well as the<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">rest of the code that runs after the object is created. This isn’t possible in a constructor at all.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">(iv) Factory methods are not constrained by the type of the enclosing class.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">7. In API class / Interface we should not specify setter method.<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">For example&nbsp;javax.swing.Action has&nbsp;setEnabled(boolean) method - which should be placed in the class AbstractAction .. because this method is specific to implementation not the skeleton api i.e. while creating an Action user need not invoke setEnabled(boolean). In some special cases, if user needs to invoke setEnabled(false) then he should use AbstractAction.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="font-size: 14pt;">8. API is all about good names ! Thats it !<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">&nbsp;if (car.speed() &gt; 1.5*SPEED_LIMIT)<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">&nbsp;&nbsp; alertDriver("Watch out for Cops");<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">Bad Example :<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">Thread.interrupted() -- just a horrific name !&nbsp; It should be a present-tense verb like -clearInteruptStatus() !!<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">Good Example :<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">public interface List {<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">List subList(int fromIndex, int toIndex);<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">}<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Very powerful. easy to remember ...without document<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin: 0in; mso-list: l0 level1 lfo1; mso-pagination: widow-orphan; text-indent: 0in;"><b><span lang="DE" style="color: black; font-size: 14pt;">8.<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></b><b><span lang="DE" style="color: black; font-size: 14pt;">Forbid access to the package containing implementation classes .<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&nbsp;Do this on the class-loading level, - by suffixing pkg name 'internal' when developing bundles inside Eclipse or make them pkg-private for non-osgi environment.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">9. Always introduce an intermediate bridge interface to maintain backward compatibility<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&nbsp;If we have &nbsp;class say - public abstract class HelloVisitor with 2 methods<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&nbsp;&nbsp;- helloAll()<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&nbsp;&nbsp;- helloVisitor(Visitor visitor)<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&nbsp;In next release, you decided to introduce new class- public abstract HelloAll with only one method - helloAll()<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Then for backward compatibility make &nbsp;HelloVisitor extend HelloAll.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">10.&nbsp;Use Builder pattern as a method is better than a variable.<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">docInfo</span></b><span lang="DE" style="color: black; font-size: 14pt;">= DocumentInfo.empty().nameProvider(p).urlProvider(p).normalize(p);<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Never allow more than 3 parameters in arg list<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&gt;&gt; break up into smaller methods .. Builder Pattern .. Named params<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&gt;&gt; Create helper class to hold params<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">11.&nbsp; Clear seperation between API and SPI<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">An API is something that Clients call and an SPI is something that Providers<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">implement.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">For example, in case of the FileSystem API, the FileObject is there to be called, while the<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">LocalFileSystem and JarFileSystem are there to be implemented.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Adding a new method in API delights its client. Whereas adding a new method in SPI breaks the provider's codebase !!<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin: 0in; mso-list: l3 level1 lfo2; mso-pagination: widow-orphan; text-indent: 0in;"><b><span lang="DE" style="font-size: 14pt;">12.<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></b><b><span lang="DE" style="font-size: 14pt;">Catch the exceptions early as part of Pre Condition Validation.<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Remember to throw an Exception at a Consistent Level of Abstraction :<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">class Employee {<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&nbsp;public TaxId getTaxId() throws EmployeeDataNotAvailable {....}<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">}<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">We should not throw a SQLException inside a BankAccountService API rather throw AccountNotAvailable exception.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">13. We should adopt 'Annotation' over 'Configuration'.<o:p></o:p></span></b></div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Spring 2.5 takes a huge step in this direction by providing you with the option<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">to annotate implementation classes:<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">@Service<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">public class SimpleScramblerAnnotated extends SimpleScrambler {<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">public SimpleScramblerAnnotated() {<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">}<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan; tab-stops: -4.5pt;"><span lang="DE" style="color: black; font-size: 14pt;">}<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">@Service<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">public class StaticWordLibraryAnnotated extends StaticWordLibrary {<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">public StaticWordLibraryAnnotated() {<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">}<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">}<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">@Service("ui")<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">public class AnagramsAnnotated extends AnagramsWithConstructor {<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">@Autowired<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">public AnagramsAnnotated(WordLibrary library, Scrambler scrambler) {<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">super(library, scrambler);<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">}<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">}<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">You use an indication that identifies the exported beans, their names, and potentially also<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">their dependencies on other APIs that need to be provided for the implementation to work<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">correctly. The final assembler no longer needs to write a configuration file with references to<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">all names of implementation classes, but rather can instruct the Spring Framework to use the<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">provided annotations.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">It’s still necessary to know the name of the packages that contain all the implementations.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">However, that is significantly less knowledge than knowing all the classes and their parameters.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="font-size: 14pt;">14. Public Concrete&nbsp; Class should be Final and Immutable.<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; A Classic example of Non-Immutable Class is Calender which should have been designed a Mutable because its job is to just mutate Date.&nbsp; Another bad example in Java is Collection Classes which should have been declared Final as they should never be extended rather decorated !<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">Classical design mistakes :: Stack is not a vector .. it has a vector ...<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">Similarly Properties is not HashTable, but it still extends HashTable.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">clone(), readObject(), constructor should never invoke overridable method.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="font-size: 14pt;">15. Avoid Overloading !! Yes thats true !!<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">Avoid overloading .. always use meaningful method names !!<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">Bad Example :<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">1. public TreeSet(Collection c) // Ignores order<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">&nbsp;&gt;&gt; creates a new comparator<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">2. public TreeSet(SortedSet s) // respects order<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">&nbsp;&gt;&gt; uses the comparator of SortedSet<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">Imagine client calls ..<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">SortedSet mySet = ..<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">TreeSet tset = new TreeSet((Collection)mySet)<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">#1 will be invoked .. and the order already present in SortedSet will be ignored .. as it will use a new comparator ..<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">If the behaviors of two methods differ, it's better to give them different names<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">The above confusion arises due to the fact that – Collection Fwk tried to be Flexible by providing overloaded constructors !!!!<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">AbstractSet, AbstractList are good examples !<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="font-size: 14pt;">16.&nbsp; In API, paramerts should be ordered in meaningful fashion :<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">java.util.concurrent provides good examples : .. long delay, TimeUnit unit<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin: 0in; mso-list: l5 level1 lfo3; mso-pagination: widow-orphan; text-indent: 0in;"><b><span lang="DE" style="color: black; font-size: 14pt;">17.<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></b><b><span lang="DE" style="color: black; font-size: 14pt;">Be careful while making super class methods thread safe.<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">The suggested way is to use synchronized in the definition of a method. Fine, that can work for me.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">I am able to write my code in one class without deadlocks. But what if somebody subclasses my object and<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">also uses synchronized methods? Well, in that case it uses the same lock as mine, usually without any<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">knowledge as to how I should use the lock, because my synchronized methods can be private and thus not<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">of interest to subclasses. The result? Deadlocks everywhere.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Subclassing and using synchronized methods sneaks into the superclass’s own synchronization<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">model.That can completely invalidate any synchronization assumptions the<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">superclass has made. Doing so is just plain dangerous.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="font-size: 14pt;">18. API should provide toString implementation<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">Provide programmatic access to all data available in string form. Otherwise, programmers will be forced to parse strings, which is painful. Worse, the string forms will turn into de facto APIs.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="font-size: 14pt;">Good StackTrace[] getStackTrace()<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">19.&nbsp; "It’s good to be reminded that the sole</span></b><b><span lang="DE" style="font-size: 14pt;"><o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">purpose of overridable methods is to replace a table mapping method name with actual code<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">snippets."<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">java.util.Arrays has many toString methods, each accepting<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">different array types, such as byte[], short[], and Object[]. These methods are therefore<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">overloaded. When called, the compiler chooses the best one depending on the type of the<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">parameter that is passed for method invocation.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">20. <b>API should encpsulate boilerplate code</b> ..<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&nbsp;&nbsp; User need not bear the burden of heavy-lifting the bulk of logic , say implementing a Transformer to transform a Dom model etc.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&nbsp;There should be a simple method writeDoc(...)&nbsp; which should hide the details.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">21. Return zero-length array or empty collection - not NULL<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">NULL Patterns ::<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">class Service {<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&nbsp; private final Log log;<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&nbsp; Service() {<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&nbsp;&nbsp;&nbsp; this.log = new NullLog();<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&nbsp; }<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">}<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">public final class NullLog implements Log {<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&nbsp; public void write(String messageToLog) {<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&nbsp;&nbsp;&nbsp; // do nothing<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&nbsp; }<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">}<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">22.&nbsp; Contrary to popular belief – do not throw CheckedException so frequently rather throw it very sparingly !<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Bad Enforcement JDK !!!<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">we know it will succeed .. but still client have to catch it ..<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">try {<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Foo f = (Foo) super.clone();<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">} catch(CloneNotSupportedExceptio e) {<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">}<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin: 0in; mso-list: l1 level1 lfo4; mso-pagination: widow-orphan; text-indent: 0in;"><b><span lang="DE" style="color: black; font-size: 14pt;">23.<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></b><b><span lang="DE" style="color: black; font-size: 14pt;">Make everything Final then open up / expose on need basis.<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin: 0in; mso-list: l2 level1 lfo5; mso-pagination: widow-orphan; text-indent: 0in;"><b><span lang="DE" style="color: black; font-size: 14pt;">24.<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></b><b><span lang="DE" style="color: black; font-size: 14pt;">Implemenation Class must be Immutable<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Do not provide a getter method like getValues() that exposes private internal mutable object state<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">without defensively copying the state.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Collections.unmodifiableList(Arrays.asList(items));<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">25. API should not wait for response rather it should strive to reduce latency<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Defer the processing logic in Provider API and return immedialtely to Client<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Create a client API that will post a Future task to a Provider API wrapping up a Single Processor Executor. When user will call the client API either return immediately or time-out.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">26. While resolving Classes for supporting Multiple APIs always use compliant solution.<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">"Two classes are the same class (and consequently the same type) if they are loaded by the same<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">class loader and they have the same fully qualified name" [JVMSpec 1999].<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Noncompliant --<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&gt;&gt; if (auth.getClass().getName().equals("com.application.auth.DefaultAuthenticationHandler")) {<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&nbsp; // ...<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">}<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Compliant&nbsp; --<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&gt;&gt; if (auth.getClass() == this.getClassLoader().loadClass<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">("com.application.auth.DefaultAuthenticationHandler")) {<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">&nbsp; // ...<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">}<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin: 0in; mso-list: l4 level1 lfo6; mso-pagination: widow-orphan; text-indent: 0in;"><span lang="DE" style="color: black; font-size: 14pt;">27.<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><b><span lang="DE" style="color: black; font-size: 14pt;">Design Composition and Aggregation inside API </span></b><span lang="DE" style="color: black; font-size: 14pt;">using Decorator and Delegate patterns.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Identify where responsibility can be attached in runtime using Decorator by discouraging the usage of Inheritence.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">28.&nbsp;&nbsp;&nbsp; <b>Handle memory-leak scenarios in Base Implemnetaion Classes</b><o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Its important to encapsulate the core logic of managing listeners, indexes, caches, data-binding, thread-executors, validators etc. Inside base framework classes.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 14pt;">Its absolutely essential to identify the scenarios of using WeakHashmap, cleaning up resources, visitor patterns to minimize 'instance-of' checking, static inner classes.<o:p></o:p></span></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><b><span lang="DE" style="color: black; font-size: 14pt;">References :<o:p></o:p></span></b></div><div class="Textbody" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-pagination: widow-orphan;"><br /> </div><div class="Standard"><span lang="DE"><a href="http://www.infoq.com/presentations/effective-api-design"><span style="color: windowtext; font-size: 14pt; text-decoration: none;">http://www.infoq.com/presentations/effective-api-design</span></a><o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><b style="mso-bidi-font-weight: normal;"><span lang="DE" style="color: #333333; font-size: 14pt;">API Design and Evolution<o:p></o:p></span></b></div><div class="Standard"><span lang="DE"><a href="http://www.eclipsecon.org/2010/sessions/sessions?id=1427"><span style="color: windowtext; font-size: 14pt; text-decoration: none;">http://www.eclipsecon.org/2010/sessions/sessions?id=1427</span></a></span><span lang="DE" style="font-size: 14pt;">&nbsp; </span><span lang="DE"><o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><b><span lang="DE" style="font-size: 14pt;">Java Coding Practice Guidelines<o:p></o:p></span></b></div><div class="Standard"><span lang="DE"><a href="https://www.securecoding.cert.org/confluence/display/java/The+CERT+Oracle+Secure+Coding+Standard+for+Java"><span style="color: windowtext; font-size: 14pt; text-decoration: none;">https://www.securecoding.cert.org/confluence/display/java/The+CERT+Oracle+Secure+Coding+Standard+for+Java</span></a><o:p></o:p></span></div></div></description>
<link>http://musings-on-technology.blogspot.com/2011/04/designing-better-api.html</link>
<author>noreply@blogger.com (Kaniska)</author>
<thr:total>0</thr:total>
</item>
<item>
<guid isPermaLink="false">tag:blogger.com,1999:blog-1373851816248476399.post-1238470004471331437</guid>
<pubDate>Tue, 19 Apr 2011 04:44:00 +0000</pubDate>
<atom:updated>2011-04-19T10:17:43.397+05:30</atom:updated>
<category domain="http://www.blogger.com/atom/ns#">concurrency</category>
<category domain="http://www.blogger.com/atom/ns#">jdk</category>
<title>Learning from JDK Source and Language Specs</title>
<description><div dir="ltr" style="text-align: left;" trbidi="on"><br /> <div class="MsoNormal" style="text-align: justify;"><b>Excerpts from Java Language Framework, Concurrency API Documents, following Websites and personal learning :<o:p></o:p></b></div><div class="MsoNormal" style="text-align: justify;"><br /> </div><div class="MsoNormal" style="text-align: justify;"><span lang="RU" style="font-size: 14pt;">JSR 133 (Java Memory Model) FAQ : <o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span lang="RU" style="font-size: 14pt;">&nbsp;</span><span lang="RU"><a href="http://www.cs.umd.edu/~pugh/java/memoryModel/jsr-133-faq.html">http://www.cs.umd.edu/~pugh/java/memoryModel/jsr-133-faq.html</a></span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span lang="RU" style="font-size: 14pt;">&nbsp;Concurrency Simplified :<o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span lang="RU" style="font-size: 14pt;">&nbsp;</span><span lang="RU"><a href="http://gee.cs.oswego.edu/dl/concurrency-interest/jsr166-slides.pdf">http://gee.cs.oswego.edu/dl/concurrency-interest/jsr166-slides.pdf</a></span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span lang="RU" style="font-size: 14pt;">&nbsp;</span><span lang="RU"><a href="http://www.ibm.com/developerworks/java/library/j-jtp0618.html">http://www.ibm.com/developerworks/java/library/j-jtp0618.html</a></span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><b><span lang="RU" style="font-size: 14pt;">1. </span></b><b><span style="font-size: 14pt;">Recollecting of Basic Concepts :<o:p></o:p></span></b></div><div class="MsoNormal" style="text-align: justify;"><br /> </div><div class="MsoNormal" style="text-align: justify;"><span lang="RU" style="font-size: 14pt;">“Each thread is a different stream of control that can execute its instructions independently, allowing a <o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span lang="RU" style="font-size: 14pt;">multithreaded process to perform numerous tasks concurrently. One thread can run the GUI while <o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span lang="RU" style="font-size: 14pt;">a second thread does some I/O and a third performs calculations. <o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span lang="RU" style="font-size: 14pt;">It is the program state that gets scheduled on a CPU; it is the "thing" that does the work. If a process comprises data, code, kernel state, and a set of CPU registers, then a thread is embodied in the contents of those registers—the program counter, the general registers, the stack pointer, etc., and the stack. A thread, viewed at an instant of time, is the state of the computation.” <o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span lang="RU" style="font-size: 14pt;">– </span><span lang="RU"><a href="http://books.google.com/books?id=bIchilfV3bcC&amp;pg=PT38&amp;lpg=PT38&amp;dq=">Multithreaded programming with Java technology</a></span><i style="mso-bidi-font-style: normal;"><span lang="RU" style="font-size: 14pt;"> , </span></i><span lang="RU" style="font-size: 14pt;">Bil Lewis, Daniel J. Berg <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-align: justify;"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">A thread is a lightweight entity, comprising the registers, stack, and some other data. The rest of the process structure is shared by all threads: the address space, file descriptors, etc. Much (and sometimes all) of the thread structure is in user space, allowing for very fast access. <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-align: justify;"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">The main benefits of writing multithreaded programs are: <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">• Performance gains from multiprocessing hardware (parallelism) <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">• Increased application throughput <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">• Increased application responsiveness <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">• Replacing process-to-process communications <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">• Efficient use of system resources <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">• One binary that runs well on both uniprocessors and multiprocessors <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-align: justify;"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><b><span style="font-size: 14pt;">2. Properties of</span></b><b><span style="font-size: 14pt;"> </span></b><b><span style="font-size: 14pt;">typical</span></b><b><span style="font-size: 14pt;"> </span></b><b><span style="font-size: 14pt;">MultiThreaded</span></b><b><span style="font-size: 14pt;"> </span></b><b><span style="font-size: 14pt;">Program</span></b><b><span lang="RU" style="font-size: 14pt;">: <o:p></o:p></span></b></div><div class="MsoNormal"><b><span lang="RU" style="font-size: 14pt;">Independent tasks <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">A debugger needs to run and monitor a program, keep its GUI active, and display an interactive data inspector, dynamic call grapher, and performance monitor—all in the same address space, all at the same time. <o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><span style="font-size: 14pt;">For example, a </span><span lang="RU" style="font-size: 14pt;">&nbsp;server needs to handle numerous overlapping requests simultaneously. NFS®, NIS, DBMSs,&nbsp; stock quotation servers, etc., all receive large numbers of requests that require the server to do some I/O, then process the results and return answers. Completing one request at a time would be very slow. <o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><b><span lang="RU" style="font-size: 14pt;">Repetitive tasks <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">A simulator needs to simulate the interactions of numerous different elements that operate simultaneously. CAD, structural analysis, weather prediction, etc., all model tiny pieces first, then combine the results to produce an overall picture. <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">-------------------------------------------------------- <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><b><span lang="RU" style="font-size: 14pt;">3.&nbsp;&nbsp;&nbsp; How does the Synchronization work in Memory ? <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">Ref: </span><span lang="RU"><a href="http://www.cs.umd.edu/~pugh/java/memoryModel/jsr-133-faq.html">http://www.cs.umd.edu/~pugh/java/memoryModel/jsr-133-faq.html</a></span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><span lang="RU" style="font-size: 14pt;">“Synchronization has several aspects. The most well-understood is <b>mutual exclusion</b> -- only one thread can hold a monitor at once, so synchronizing on a monitor means that once one thread enters a synchronized block protected by a monitor, no other thread can enter a block protected by that monitor until the first thread exits the synchronized block. <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">But there is more to synchronization than mutual exclusion. <b>Synchronization ensures that memory writes by a thread before or during a synchronized block are made visible in a predictable manner to other threads which synchronize on the same monitor.</b> After we exit a synchronized block, we&nbsp;release&nbsp;the monitor, which has the effect of flushing the cache to main memory, so that writes made by this thread can be visible to other threads. Before we can enter a synchronized block, we&nbsp;acquire&nbsp;the monitor, which has the effect of invalidating the local processor cache so that variables will be reloaded from main memory. We will then be able to see all of the writes made visible by the previous release.” <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><b><span style="font-size: 14pt;">4.</span></b><b><span style="font-size: 14pt;"> <span lang="RU">How Volatile can be used to avoid excessive synchronization <o:p></o:p></span></span></b></div><div class="MsoNormal"><b><span lang="RU" style="font-size: 14pt;">&nbsp;&nbsp;&nbsp; and implement non-blocking operation ? <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">Volatile fields are special fields which are used for communicating state between threads. <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">The compiler and runtime are prohibited from allocating them in registers. They must also ensure that after they are written, they are flushed out of the cache to main memory, so they can immediately become visible to other threads. (executes a WRITE BARRIER like memory writes for UNLOCKING MONITOR). <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">Similarly, before a volatile field is read, the cache must be invalidated so that the value in main memory, not the local processor cache, is the one seen. Even if the volatile field is assigned any value in the reader thread, that value will be replaced by the latest value written by writer thread i.e. it will excute a READ_BARRIER to refresh local value with the ones in main memory. <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">This is how, each read of a volatile will see the last write to that volatile by any thread; in effect, they are designated by the programmer as fields for which it is never acceptable to see a "stale" value as a result of caching or reordering. <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">Each read or write of a volatile field acts like "half" a synchronization, for purposes of visibility. <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">The best example is ConcurrentHashMap </span><span style="font-size: 14pt;">which uses volatile to decide whether to acquire a partial lock on segment of keys or go ahead with direct lookup !!<o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><b><span style="font-size: 14pt;">Now lets look into the usage of Java Synchronizers : Modern non-blocking lock-contention free wait-optimized multi-threading tools<o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><b><span style="font-size: 14pt;">5. How to signal effectively between Consumer and Worker instead of wasting CPU Cycles ?<o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">Condition – can be used to signal between Consumer and Worker threads. <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp;&nbsp;&nbsp; Instead of making consumer thread wait() in while() loop. <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp;&nbsp;&nbsp; This is specially useful for BlockingQueue. <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp;&nbsp; final BlockingQueue<string> msgQ = new LinkedBlockingQueue<string>(); <o:p></o:p></string></string></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp;&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp;&nbsp; public void produceWork() throws InterruptedException { <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String message =&nbsp; get the message from source …. <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; msgQ.put(message); <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp;&nbsp; } <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp; public LoggedService() { // start background thread <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp; Runnable logr = new Runnable() { <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp;&nbsp; public void run() { <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp;&nbsp; try { <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(;;) <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(msqQ.take()); <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp;&nbsp; } catch(InterruptedException ie) {} }}; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp; Executors.newSingleThreadExecutor().execute(logr); <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp; } <o:p></o:p></span></div><div class="MsoNormal"><b><span lang="RU" style="color: blue; font-size: 14pt;">Condition notFull = lock.newCondition(); <o:p></o:p></span></b></div><div class="MsoNormal"><b><span lang="RU" style="color: blue; font-size: 14pt;">Condition notEmpty = lock.newCondition(); <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp; <b>msgQ.take() - will wait till an element is available in Queue. <o:p></o:p></b></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp; while (count == 0) <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; notEmpty.await(); <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><b><span lang="RU" style="color: blue; font-size: 14pt;">msgQ.poll(time..) </span></b><span lang="RU" style="color: blue; font-size: 14pt;">- wait till an element is available after a specified time. <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">msgQ.put(E) – will wait till queue length ls less than capacity. <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp; while (count == items.length) <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b> notFull.await(); <o:p></o:p></b></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><b><span style="color: blue; font-size: 14pt;">**** Lock.lock() replacement for synchronized {…} ; Condition.await()-signal()-signalAll()... replacement for wait()-notify()-nitofyAll() ...<o:p></o:p></span></b></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><b><span style="font-size: 14pt;">This is a wonderful permission system – where N threads can hold a lock at any point of time !!<o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><b><span style="font-size: 14pt;">6</span></b><b><span lang="RU" style="font-size: 14pt;">&nbsp; LOCK – offers significant advantage over 'synchronizing a block of code' i.e. does not force blocking a&nbsp;&nbsp; 'structured locking/unlocking' <o:p></o:p></span></b></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><span style="font-size: 14pt;">Lets go through the Code Comments in LOCK.java<o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp;&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">{@code Lock}</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">implementations</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">provide</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">more</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">extensive</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">locking</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">operations</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">than</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">can</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">be</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">obtained</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">using</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">{@code synchronized}</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">methods</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">and</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">statements.&nbsp; They</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">allow</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">more</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">flexible</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">structuring,</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">may</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">have</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">quite</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">different</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">properties,</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">and</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">may</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">support</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">multiple</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">associated</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">{@link Condition}</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">objects.</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp;</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><b><span lang="RU" style="font-size: 14pt;">Main problem with 'synchronized' </span></b><span lang="RU" style="font-size: 14pt;">-&nbsp; </span><span lang="RU" style="font-size: 14pt;">methods</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">or</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">statements</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">provides</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">access</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">to</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">the</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">implicit</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">monitor</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">lock</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">associated</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">with</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">every</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">object,</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">but</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">forces</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">all</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">lock</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">acquisition</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">and</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">release</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">to</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">occur</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">in</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">a</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">block-structured</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">way</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><b><span lang="RU" style="font-size: 14pt;">– Bigger Scope <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp;</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><b><span lang="RU" style="font-size: 14pt;">Lock </span></b><b><span style="font-size: 14pt;">has the advantage of </span></b><b><span lang="RU" style="font-size: 14pt;">smaller scope</span></b><span lang="RU" style="font-size: 14pt;"> </span><span style="font-size: 14pt;">-<o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">acquire</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">the</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">lock</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">of</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">node</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">A,</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">then</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">node</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">B,</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">then</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">release</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">A</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">and</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">acquire</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">C,</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">then</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">release</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">B</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">and</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">acquire</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">D</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">and</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">so</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">on. (Hand Over Hand / Chain Lock) Implementations</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">of</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">the <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">{@code Lock}</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">interface</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">enable</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">the</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">use</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">of</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">such</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">techniques</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">by</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">allowing</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">a</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">lock</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">to</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">be</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">acquired</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">and</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">released</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">in</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">different</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">scopes <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><b><span lang="RU" style="font-size: 14pt;">Another problem with 'synchronized' – <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">when</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">multiple</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">locks</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">are</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">acquired</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">they</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">must</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">be</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">released</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">in</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">the</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">opposite</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">order,</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">and</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">all</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">locks</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">must</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">be</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">released</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">in</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">the</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">same</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">lexical</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">scope</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">in</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">which</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">they</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">were</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">acquired.</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp;</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><b><span style="font-size: 14pt;">Advantage of</span></b><b><span lang="RU" style="font-size: 14pt;"> 'Lock' </span></b><b><span style="font-size: 14pt;">can be</span></b><b><span lang="RU" style="font-size: 14pt;">- </span></b><b><span lang="RU" style="font-size: 14pt;">released</span></b><b><span lang="RU" style="font-size: 14pt;"> </span></b><b><span lang="RU" style="font-size: 14pt;">in</span></b><b><span lang="RU" style="font-size: 14pt;"> </span></b><b><span lang="RU" style="font-size: 14pt;">any order.</span></b><b><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp;</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><b><span lang="RU" style="font-size: 14pt;">Problem with Lock&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <o:p></o:p></span></b></div><div class="MsoNormal"><span style="font-size: 14pt;">- </span><span lang="RU" style="font-size: 14pt;">With</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">this</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">increased</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">flexibility</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">comes</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">additional</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">responsibility.</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">absence</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">of</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">block-structured</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">locking</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">removes</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">the</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">automatic</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">release</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">of</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">locks</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">that</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">occurs</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">with</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">{@code synchronized}</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">methods</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">and</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">statements.</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">In</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">most</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">cases,</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">the</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">following</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">idiom</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">should</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">be</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">used:</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;"></span></div><pre><tt>&nbsp;&nbsp;&nbsp;&nbsp; Lock<span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">l</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">=</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">...;</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span> <div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp; l.lock();</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp; try</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">{</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">access</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">the</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">resource</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">protected</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">by</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">this</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">lock</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp; }</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">finally</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">{</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; l.unlock();</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp; }</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">**** </span><span style="color: blue; font-size: 14pt;">So now JVM will spend less time in SCHEDULING THREADS and more time in EXECUTING them! <o:p></o:p></span></div><div class="MsoNormal"><span style="color: blue; font-size: 14pt;">**** Lock Contentions can be profiled in a much better way to spot bottlenecks !!<o:p></o:p></span></div><div class="MsoNormal"></div><div class="MsoNormal"><b><span style="font-size: 14pt;">How to e</span></b><b><span lang="RU" style="font-size: 14pt;">nsure Non-Blocking Behaviour <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">an</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">attempt</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">to</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">acquire</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">the</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">lock</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">that</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">can</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">be</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .5in; mso-list: l1 level1 lfo2; tab-stops: list .5in; text-indent: -.25in;"><span lang="RU" style="font-family: Symbol; font-size: 14pt;">·<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span lang="RU" style="font-size: 14pt;">interrupted</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">({@link #lockInterruptibly},<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .5in; mso-list: l1 level1 lfo2; tab-stops: list .5in; text-indent: -.25in;"><span lang="RU" style="font-family: Symbol; font-size: 14pt;">·<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span lang="RU" style="font-size: 14pt;">and</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">an</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">attempt</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">to</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">acquire</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">the</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">lock</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">that</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">can</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">timeout</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">({@link #tryLock(long, TimeUnit)}).<o:p></o:p></span></div><div class="MsoNormal"></div><div class="MsoNormal"><b><span style="font-size: 14pt;">How to ensure </span></b><b><span lang="RU" style="font-size: 14pt;">Concurrent Access </span></b><b><span style="font-size: 14pt;">using Locks </span></b><b><span lang="RU" style="font-size: 14pt;">?<o:p></o:p></span></b></div><div class="MsoNormal"></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">some</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">locks</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">may</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">allow</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">concurrent</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">access</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">to</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">a</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">shared</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">resource,</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">such</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">as</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">the</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">read</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">lock</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">of</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">a</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">{@link ReadWriteLock}.</span><span lang="RU" style="font-size: 14pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">Use ReentrantReadWriteLock&nbsp; for enforcing multiple-reader, single-writer access. <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Write lock can “downgrade” to read lock (not vice-versa). <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><b><span style="font-size: 14pt;">7. How to signal multiple threads simultaneously ?<o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">CountDownLatch </span><span style="font-size: 14pt;">is </span><span style="font-size: 14pt;">- a</span><span style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">synchronization</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">aid</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">that</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">allows</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">one</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">or</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">more</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">threads</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">to</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">wait</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">until</span><span lang="RU" style="font-size: 14pt;">&nbsp; </span><span lang="RU" style="font-size: 14pt;">a</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">set</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">of</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">operations</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">being</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">performed</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">in</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">other</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">threads</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">completes.</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"></div><div class="MsoNormal"><span style="font-size: 14pt;">Example from CounDownLatch.java<o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp;</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp; class</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">Driver</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">{</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">//</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">...</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp; void</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">main()</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">throws</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">InterruptedException</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">{</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp; CountDownLatch</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">startSignal</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">=</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">new</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">CountDownLatch(1);</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp; CountDownLatch</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">doneSignal</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">=</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">new</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">CountDownLatch(N);</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp; for</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">(int</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">i</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">=</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">0;</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">i</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">&lt; N; ++i) // create and start threads</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">Thread(new</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">Worker(startSignal,</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">doneSignal)).start();</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp; doSomethingElse();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">don't</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">let</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">run</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">yet <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp; startSignal.countDown();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">let</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">all</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">threads</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">proceed</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp; doSomethingElse();</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp; <b>doneSignal.await();&nbsp;&nbsp;&nbsp;</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">wait</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">for</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">all</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">to</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">finish</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp; }</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">}</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"></div><div class="MsoNormal"><b><span style="font-size: 14pt;">**** This also exemplifies – how instead of polling and wasting cpu resources, the thread&nbsp; just receives a signal when it is good to proceed !!<o:p></o:p></span></b></div><div class="MsoNormal"></div><div class="MsoNormal"><b><span style="font-size: 14pt;">**** No need to call join multiple times !!<o:p></o:p></span></b></div><div class="MsoNormal"></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">class</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">Worker</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">implements</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">Runnable</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">{</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp; private</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">final</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">CountDownLatch</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">startSignal;</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp; private</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">final</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">CountDownLatch</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">doneSignal;</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp; Worker(CountDownLatch</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">startSignal,</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">CountDownLatch</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">doneSignal)</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">{</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.startSignal</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">=</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">startSignal;</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.doneSignal</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">=</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">doneSignal;</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp; }</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp; public</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">void</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">run()</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">{</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">{</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; startSignal.await(); – this thread can't proceed till Driver calls <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; countDown ..</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; doWork();</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; doneSignal.countDown(); - <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">catch</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">(InterruptedException</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">ex)</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">{}</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">//</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">return;</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp; }</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*&nbsp;&nbsp; void</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">doWork()</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">{</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">...</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">}</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*</span><span lang="RU" style="color: blue; font-size: 14pt;"> </span><span lang="RU" style="color: blue; font-size: 14pt;">}</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">*</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; </span><span lang="RU" style="font-size: 14pt;">Another</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">typical</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">usage</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">would</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">be</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">to</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">divide</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">a</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">problem</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">into</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">N</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">parts,</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">describe</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">each</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">part</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">with</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">a</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">Runnable</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">that</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">executes</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">that</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">portion</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">and</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">counts</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">down</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">on</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">the</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">latch,</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">and</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">queue</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">all</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">the</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">Runnables</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">to</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">an</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">Executor.&nbsp; When</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">all</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">sub-parts</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">are</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">complete,</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">the</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">coordinating</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">thread</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">*</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">will</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">be</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">able</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">to</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">pass</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">through</span><span lang="RU" style="font-size: 14pt;"> </span><span lang="RU" style="font-size: 14pt;">await.</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><b><span lang="RU" style="font-size: 14pt;">8.&nbsp;</span></b><b><span style="font-size: 14pt;">How to implement non-blocking</span></b><b><span lang="RU" style="font-size: 14pt;">&nbsp; </span></b><b><span lang="RU" style="font-size: 14pt;">Optimistic </span></b><b><span style="font-size: 14pt;">Data Structure </span></b><b><span lang="RU" style="font-size: 14pt;">?</span></b><b><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></b></div><div class="MsoNormal"></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">class OptimisticLinkedList { // incomplete</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">static class Node {</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">volatile Object item;</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">final AtomicReference<node> next;</node></span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">Node(Object x, Node n) {</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">item = x; next = new AtomicReference(n); }</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">}</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">final AtomicReference head = new AtomicReference(null);</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">public void prepend(Object x) {</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">if (x == null) throw new IllegalArgumentException();</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">for(;;) {</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">Node h = head.get();</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">if (head.compareAndSet(h, new Node(x, h)) return;</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">}</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">}</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">public boolean search(Object x) {</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">Node p = head.get();</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">while (p != null &amp;&amp; x != null &amp;&amp; !p.item.equals(x))</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">p = p.next.get();</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">return p != null &amp;&amp; x != null;</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">}</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">}</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp;</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><b><span lang="RU" style="font-size: 14pt;">9.&nbsp;&nbsp;&nbsp; How final fields can offer thread-safety : <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">All threads will read the final value so long as it is guaranteed to be assigned before the object could be made visible to other threads.</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp;&nbsp;</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><b><span lang="RU" style="font-size: 14pt;">10.</span></b><b><span lang="RU" style="font-size: 14pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></b><b><span lang="RU" style="font-size: 14pt;">Perform operations asynchronously </span></b><b><span style="font-size: 14pt;">using Futures <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">when</span><span lang="RU" style="font-size: 14pt;"> </span><span style="font-size: 14pt;">time-consuming independent tasks need to be performed in Main thread.<o:p></o:p></span></div><div class="MsoNormal"></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">class ImageRenderer { Image render(byte[] raw); }</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">class App { // ...</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">Executor executor = ...; // any executor</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span style="color: blue; font-size: 14pt;">DocumentReader</span><span style="color: blue; font-size: 14pt;"> </span><span style="color: blue; font-size: 14pt;">docReader</span><span lang="RU" style="color: blue; font-size: 14pt;"> = new </span><span style="color: blue; font-size: 14pt;">DocumentReader</span><span lang="RU" style="color: blue; font-size: 14pt;">();</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">public void display(final byte[] </span><span style="color: blue; font-size: 14pt;">document</span><span lang="RU" style="color: blue; font-size: 14pt;">) {</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">try {</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">Future&lt;</span><span style="color: blue; font-size: 14pt;">Document</span><span lang="RU" style="color: blue; font-size: 14pt;">&gt; </span><span style="color: blue; font-size: 14pt;">document</span><span lang="RU" style="color: blue; font-size: 14pt;">= Executors.invoke(executor,</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">new Callable&lt;</span><span style="color: blue; font-size: 14pt;">Document</span><span lang="RU" style="color: blue; font-size: 14pt;">&gt;(){</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">public </span><span style="color: blue; font-size: 14pt;">Document</span><span lang="RU" style="color: blue; font-size: 14pt;"> call() {</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">return renderer.render(</span><span style="color: blue; font-size: 14pt;">document</span><span lang="RU" style="color: blue; font-size: 14pt;">);</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">}});</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span style="color: blue; font-size: 14pt;">preparePanel</span><span lang="RU" style="color: blue; font-size: 14pt;">(); // do other things </span><span style="color: blue; font-size: 14pt;">in main thread<o:p></o:p></span></div><div class="MsoNormal"><span style="color: blue; font-size: 14pt;">preparePageCaptions</span><span lang="RU" style="color: blue; font-size: 14pt;">(); // ... while </span><span style="color: blue; font-size: 14pt;">fetching the actual document in a different thread<o:p></o:p></span></div><div class="MsoNormal"><span style="color: blue; font-size: 14pt;">showDocument</span><span lang="RU" style="color: blue; font-size: 14pt;">(</span><span style="color: blue; font-size: 14pt;">document</span><span lang="RU" style="color: blue; font-size: 14pt;">.get()); // </span><span style="color: blue; font-size: 14pt;">block till document is fetched by</span><span lang="RU" style="color: blue; font-size: 14pt;"> future</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">}</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">catch (Exception ex) {</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">cleanup();</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">return;</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">}</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="color: blue; font-size: 14pt;">} }</span><span lang="RU" style="color: blue; font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><b><span lang="RU" style="font-size: 14pt;">11.&nbsp;&nbsp;&nbsp;How static fields can be used to guarantee thread-safety : <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><span lang="RU" style="font-size: 14pt;">use the Initialization On Demand Holder idiom, which is thread-safe and a lot easier to understand: <o:p></o:p></span></div><div class="MsoNormal" style="background: silver; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 15.0pt; margin-top: 0in;"><span lang="RU" style="font-size: 14pt;">private static class Lazy</span><span style="font-size: 14pt;">Model</span><span lang="RU" style="font-size: 14pt;">Holder {</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="background: silver; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 15.0pt; margin-top: 0in;"><span lang="RU" style="font-size: 14pt;">&nbsp; public static </span><span style="font-size: 14pt;">Model</span><span style="font-size: 14pt;"> </span><span style="font-size: 14pt;">model</span><span lang="RU" style="font-size: 14pt;"> = new </span><span style="font-size: 14pt;">Model</span><span lang="RU" style="font-size: 14pt;">();</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="background: silver; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 15.0pt; margin-top: 0in;"><span lang="RU" style="font-size: 14pt;">}</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="background: silver; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 15.0pt; margin-top: 0in;"><span lang="RU" style="font-size: 14pt;">&nbsp;</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="background: silver; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 15.0pt; margin-top: 0in;"><span lang="RU" style="font-size: 14pt;">public static </span><span style="font-size: 14pt;">Model</span><span lang="RU" style="font-size: 14pt;"> getInstance() {</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="background: silver; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 15.0pt; margin-top: 0in;"><span lang="RU" style="font-size: 14pt;">&nbsp; return Lazy</span><span style="font-size: 14pt;">Model</span><span lang="RU" style="font-size: 14pt;">Holder.something;</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="background: silver; margin-bottom: 14.15pt; margin-left: .5in; margin-right: 15.0pt; margin-top: 0in;"><span lang="RU" style="font-size: 14pt;">}</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt; margin-left: 15.0pt; margin-right: 15.0pt; margin-top: 0in;"><span lang="RU" style="font-size: 14pt;">This code is guaranteed to be correct because of the initialization guarantees for static fields; if a field is set in a static initializer, it is guaranteed to be made visible, correctly, to any thread that accesses that class. <o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt; margin-left: 15.0pt; margin-right: 15.0pt; margin-top: 0in;"><span lang="RU" style="font-size: 14pt;">&nbsp; <o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt; margin-left: 15.0pt; margin-right: 15.0pt; margin-top: 0in;"><b><span style="font-size: 14pt;">12</span></b><b><span lang="RU" style="font-size: 14pt;">. </span></b><b><span style="font-size: 14pt;">If not sure of fine-grained theading tools,&nbsp; take resort to traditional synchronization <o:p></o:p></span></b></div><div class="MsoNormal" style="margin-bottom: 6.0pt; margin-left: 15.0pt; margin-right: 15.0pt; margin-top: 0in;"><span lang="RU" style="font-size: 14pt;">LinkedList queue = new LinkedList(); <o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt; margin-left: 15.0pt; margin-right: 15.0pt; margin-top: 0in;"><span lang="RU" style="font-size: 14pt;">// Add to end of queue queue.add(<i style="mso-bidi-font-style: normal;">object</i>); <o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt; margin-left: 15.0pt; margin-right: 15.0pt; margin-top: 0in;"><span lang="RU" style="font-size: 14pt;">// Get head of queue Object o = queue.removeFirst(); <o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt; margin-left: 15.0pt; margin-right: 15.0pt; margin-top: 0in;"><span lang="RU" style="font-size: 14pt;">// If the queue is to be used by multiple threads, <o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt; margin-left: 15.0pt; margin-right: 15.0pt; margin-top: 0in;"><span lang="RU" style="font-size: 14pt;">// the queue must be wrapped with code to synchronize the methods queue = (LinkedList)Collections.synchronizedList(queue)</span><span lang="RU" style="font-size: 14pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt; margin-left: 15.0pt; margin-right: 15.0pt; margin-top: 0in;"></div><div class="MsoNormal" style="margin-bottom: 6.0pt; margin-left: .75pt; margin-right: 15.0pt; margin-top: 0in; mso-list: l2 level1 lfo3; tab-stops: list .5in; text-indent: 0in;"><b><span style="font-size: 14pt;">13.<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></b><b><span style="font-size: 14pt;">Why Deadlock occurs ? How to avoid it ?<o:p></o:p></span></b></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><span style="font-size: 14pt;">It occurs when multiple threads each acquire multiple locks in different orders.<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><span style="font-size: 14pt;">I lock a, b - Thread A:transferMoney(me, you, 100) U lock b, a - Thread B:transferMoney(you, me, 100).<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><span style="font-size: 14pt;">&nbsp;Synchronized – goes against the OOP principle ! &nbsp;Real tension between object oriented design and lock-based concurrency control !<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><span style="color: blue; font-size: 14pt;">The solution is – to ensure lock ordering as mentioned in the sections for creating Reentrant LOCKs.&nbsp; Lock the smallest possible set of sequential steps :<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><span style="font-size: 14pt;">atomic { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; from.credit(amount) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; to.debit(amount) &nbsp;}<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><b><span style="font-size: 14pt;">14. prefer immutability : prohibit sharing and avoid unnecessary synchonization<o:p></o:p></span></b></div><div class="MsoNormal" style="text-autospace: ideograph-numeric;"><span style="font-size: 14pt;">&nbsp;<span lang="RU">CopyOnWriteArrayList, CopyOnWrite</span></span><span style="font-size: 14pt;">ArraySet provides you thread safety with the added benefit of immutability to deal with data that changes infrequently. <o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: ideograph-numeric;"></div><div class="MsoNormal" style="text-autospace: ideograph-numeric;"><span style="font-size: 14pt;">The CopyOnWriteArrayList behaves much like the ArrayList class, <b>except that when the list is modified, instead of modifying the underlying array, a new array is created and the old array is discarded. <o:p></o:p></b></span></div><div class="MsoNormal" style="text-autospace: ideograph-numeric;"></div><div class="MsoNormal" style="text-autospace: ideograph-numeric;"><span style="font-size: 14pt;">This means that when a caller gets an iterator i.e. </span><i><span style="font-size: 14pt;">copyOnWriteArrayListRef</span></i><span style="font-size: 14pt;">.iterator(</span><span style="font-size: 14pt;">, which internally holds a reference to the underlying CopyOnWriteArrayList object’s array, which is immutable and therefore <b>can be used for traversal without requiring either synchronization on the list </b></span><i><span style="font-size: 14pt;">copyOnWriteArrayListRef </span></i><span style="font-size: 14pt;">or need to clone() the </span><span style="font-size: 14pt;">copyOnWriteArrayListRef </span><span style="font-size: 14pt;">list before traversal (i.e. there is no risk of concurrent modification).<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><b><span style="font-size: 14pt;">15.&nbsp;&nbsp; Replacing synchronized collections with concurrent collections can offer dramatic scalability improvements<o:p></o:p></span></b></div><div class="MsoNormal" style="margin-bottom: 6.0pt; margin-left: .5in; margin-right: 0in; margin-top: 0in; mso-list: l3 level1 lfo4; tab-stops: list .5in; text-indent: -.25in;"><span style="font-family: Symbol; font-size: 14pt;">·<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 14pt;">We have just seen&nbsp; </span><tt><b><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">CopyOnWriteArrayList</span></b></tt><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;"> is</span></tt><span style="font-size: 14pt;"> a replacement for synchronized </span><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">List</span></tt><span style="font-size: 14pt;"> implementations for cases where traversal is the dominant operation.<o:p></o:p></span></div><div class="doctext" style="margin-bottom: 6.0pt; margin-left: .5in; margin-right: 0in; margin-top: 0in; mso-list: l3 level1 lfo4; tab-stops: list .5in; text-indent: -.25in;"><span style="font-family: Symbol; font-size: 14pt;">·<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">ConcurrentMap</span></tt><span style="font-size: 14pt;"> interface adds support for common compound actions such as put-if-absent, replace, and conditional remove.<o:p></o:p></span></div><div class="doctext" style="margin-bottom: 6.0pt; margin-left: .5in; margin-right: 0in; margin-top: 0in; mso-list: l3 level1 lfo4; tab-stops: list .5in; text-indent: -.25in;"><tt><span style="font-family: Symbol; font-size: 14pt;">·<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></tt><tt><b><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">ConcurrentLinkedQueue</span></b></tt><span style="font-size: 14pt;">, a <a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle1461"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle1490"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle1491"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle1493"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle1494"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle1558"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle1937"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle2879"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle2880"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle2887"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle2990"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle3005"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle3044"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle3045"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle3046"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle3047"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle3048"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle3075"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle3116"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle3117"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle3144"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle3153"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle3552"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle3665"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle4062"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle4134"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle4218"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle4219"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle4220"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle4221"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle4331"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle4332"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle4333"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle4334"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle4474"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle4475"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle4502"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle4969"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle4970"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle4971"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle4972"></a><a href="http://www.blogger.com/post-edit.g?blogID=1373851816248476399&amp;postID=1238470004471331437" name="iddle5152"></a>traditional FIFO queue, and </span><tt><b><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">PriorityQueue</span></b></tt><span style="font-size: 14pt;">, a (non concurrent) priority ordered queue. </span><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">Queue</span></tt><span style="font-size: 14pt;"> operations do not block; if the queue is empty, the retrieval operation returns </span><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">null</span></tt><span style="font-size: 14pt;">. While you can simulate the behavior of a </span><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">Queue</span></tt><span style="font-size: 14pt;"> with a </span><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">List </span></tt><span style="font-size: 14pt;">in fact, </span><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">LinkedList</span></tt><span style="font-size: 14pt;"> also implements </span><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">Queue.<o:p></o:p></span></tt></div><div class="doctext" style="margin-bottom: .0001pt; margin-bottom: 0in; margin-left: .5in; margin-right: 0in; margin-top: 14.0pt; mso-list: l3 level1 lfo4; tab-stops: list .5in; text-indent: -.25in;"><span lang="RU" style="font-family: Symbol; font-size: 14pt;">·<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 14pt;">I</span><span lang="RU" style="font-size: 14pt;">f we use a <span class="docemphasis">bounded </span></span><span class="docemphasis"><span style="font-size: 14pt;">blocking</span></span><span class="docemphasis"><span lang="RU" style="font-size: 14pt;"> queue</span></span><span lang="RU" style="font-size: 14pt;">, then when the queue fills up the producers block, giving the consumers time to catch up because a blocked producer cannot generate more work<o:p></o:p></span></div><div class="doctext" style="margin-bottom: 14.0pt; margin-left: .5in; margin-right: 0in; margin-top: 0in; mso-list: l4 level1 lfo5; tab-stops: list .5in; text-indent: -.25in;"><tt><span style="font-family: Symbol; font-size: 14pt;">·<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></tt><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">Blocking queues also provide an offer method, which returns a failure status if the item cannot be enqueued. This enables you to create more flexible policies for dealing with overload, such as shedding load, serializing excess work items and writing them to disk, reducing the number of producer threads.<o:p></o:p></span></tt></div><div class="doctext" style="margin-bottom: 6.0pt; margin-left: .5in; margin-right: 0in; margin-top: 0in; mso-list: l4 level1 lfo5; tab-stops: list .5in; text-indent: -.25in;"><tt><span style="font-family: Symbol; font-size: 14pt;">·<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></tt><tt><b><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">LinkedBlockingQueue</span></b></tt><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;"> and <b>ArrayBlockingQueue</b> are FIFO queues, analogous to LinkedList and ArrayList but with better concurrent performance than a synchronized List.<o:p></o:p></span></tt></div><div class="MsoNormal" style="margin-bottom: 6.0pt; margin-left: .5in; margin-right: 0in; margin-top: 0in; mso-list: l4 level1 lfo5; tab-stops: list .5in; text-indent: -.25in;"><tt><span style="font-family: Symbol; font-size: 14pt;">·<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></tt><tt><b><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">PriorityBlockingQueue</span></b></tt><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;"> is a priority-ordered queue, which is useful when you want to process elements in an order other than FIFO. Just like other sorted collections, PriorityBlockingQueue can compare elements according to their natural order (if they implement Comparable) or using a Comparator.<o:p></o:p></span></tt></div><div class="doctext" style="margin-bottom: 6.0pt; margin-left: .5in; margin-right: 0in; margin-top: 0in; mso-list: l4 level1 lfo5; tab-stops: list .5in; text-indent: -.25in;"><tt><span style="font-family: Symbol; font-size: 14pt;">·<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></tt><tt><b><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">ConcurrentHashMap</span></b></tt><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;"> implements a scalable locking strategy. <o:p></o:p></span></tt></div><div class="doctext" style="margin-bottom: 6.0pt; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">Instead of synchronizing every method on a common lock, restricting access to a single thread at a time, it uses a finer-grained locking mechanism called </span></tt><span class="docemphasis"><span style="font-size: 14pt;">lock striping</span></span><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;"> to allow a greater degree of shared access. Arbitrarily many reading threads can access the map concurrently, readers can access the map concurrently with writers, and a limited number of writers can modify the map concurrently.<o:p></o:p></span></tt></div><div class="doctext" style="margin-bottom: 6.0pt; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">It also provides iterators that do not throw ConcurrentModificationException, thus eliminating the need to lock the collection during iteration. The iterators returned by ConcurrentHashMap are </span></tt><span class="docemphasis"><span style="font-size: 14pt;">weakly consistent</span></span><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;"> instead of fail-fast.<o:p></o:p></span></tt></div><div class="MsoNormal" style="margin-bottom: 6.0pt; margin-left: .5in; margin-right: 0in; margin-top: 0in; mso-list: l5 level1 lfo6; tab-stops: list .5in; text-indent: -.25in;"><tt><span style="font-family: Symbol; font-size: 14pt;">·<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></tt><tt><b><span style="font-family: 'Times New Roman', serif; font-size: 14pt;">ConcurrentSkipListMap</span></b></tt><tt><span style="font-family: 'Times New Roman', serif; font-size: 14pt;"> and <b>ConcurrentSkipListSet</b> are concurrent replacements for a synchronized SortedMap or SortedSet (such as treeMap or TreeSet wrapped with synchronizedMap).<o:p></o:p></span></tt></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><b><span style="font-size: 14pt;">16. Document ThreadSafety<o:p></o:p></span></b></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><span style="font-size: 14pt;">@ThreadSafe public class Account {<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><span style="font-size: 14pt;">&nbsp; @GuardedBy("this") private int balance;<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><span style="font-size: 14pt;">.....<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><span style="font-size: 14pt;">}<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><b><span style="font-size: 14pt;">17.&nbsp; Abide by the practice of deep cloning for ensuring thread-safe immutability<o:p></o:p></span></b></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><span style="font-size: 14pt;">Inside immutable Implementation class / Array , always deep clone inner collections.<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><span style="font-size: 14pt;">Jdk 7 comes handy with Array deepEquals<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><b><span style="font-size: 14pt;">18 . Isolate concurrency in concurrent components such as blocking queues<o:p></o:p></span></b></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><b><span style="font-size: 14pt;">19. Task Completion Notifications<o:p></o:p></span></b></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><b><span style="font-size: 14pt;">&gt;&gt; </span></b><span style="font-size: 14pt;">Use ExecutorCompletionService and customized BlockingQueue. ECS will place the completed tasks in queue so that one can poll with timeout. <o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><span style="font-size: 14pt;">&gt;&gt; Otherwise executorService.invokeAny(allCallables, timeOut) – is very handy for a quick survey of completion status !<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><b><span style="font-size: 14pt;">References :<o:p></o:p></span></b></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><b><span style="font-size: 14pt;">Merge Sort using Concurrency :<o:p></o:p></span></b></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><span lang="RU"><a href="http://www.ibm.com/developerworks/java/library/j-jtp03048.html">http://www.ibm.com/developerworks/java/library/j-jtp03048.html</a></span><b><span style="font-size: 14pt;"> <o:p></o:p></span></b></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><b><span style="font-size: 14pt;">A popular framework<o:p></o:p></span></b></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><span lang="RU"><a href="http://hawtdispatch.fusesource.org/#Overview">http://hawtdispatch.fusesource.org/#Overview</a></span><b><span style="font-size: 14pt;"> <o:p></o:p></span></b></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><b><span style="font-size: 14pt;">A great comparison and discussion<o:p></o:p></span></b></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><span lang="RU"><a href="http://tech.puredanger.com/2011/01/14/comparing-concurrent-frameworks/">http://tech.puredanger.com/2011/01/14/comparing-concurrent-frameworks/</a></span><b><span style="font-size: 14pt;"> <o:p></o:p></span></b></div><div class="MsoNormal" style="margin-bottom: 6.0pt;"><b><span style="font-size: 14pt;">Quoting the concise list of concurrency choices from the above link :<o:p></o:p></span></b></div><div class="MsoNormal" style="margin-bottom: 6.0pt; margin-left: .5in; margin-right: 0in; margin-top: 0in;"><b><span style="font-size: 14pt;">“&nbsp; </span></b><strong><span style="font-weight: normal;">Executors</span></strong><strong> (java.util.concurrent)</strong>&nbsp;– put your computations in Runnables or Callables and submit them to an ExecutorService that is backed by a thread pool. Express dependencies by using Futures or other techniques. Two problems here – first, executors generally assume that there is 1 queue and many threads which introduces the queue contention problem mentioned above. Also, it has no way for the work to be scheduled with knowledge of dependencies. It is possible to build that over the top of course, but it’s a lot of work orthogonal to your problem at hand. The queue+threads model can’t scale as is.<o:p></o:p></div><div class="MsoBodyText" style="line-height: 15.0pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 47.25pt; margin-right: 0in; margin-top: 0in; mso-list: l6 level1 lfo7; tab-stops: 0in list .5in; text-indent: -14.15pt;"><span lang="RU" style="font-family: Symbol;">·<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><strong><span lang="RU" style="font-weight: normal;">Fork/join</span></strong><span lang="RU">&nbsp;– create your computations as RecursiveTasks or RecursiveActions and submit them to a ForkJoinPool that is backed by a thread pool. Express dependencies directly using the RecursiveTask apis for fork, join, invoke, etc. Fork/join addresses both of the concerns I mention above. Instead of a single work queue, there is one work queue per thread. This means that at the head of the queue there is no contention – there is only 1 thread reading from it. Fork/join also addresses the dependency concern because it knows that one task is waiting for another to complete – the work/stealing algorithm inherently leverages these dependencies. I would urge you to watch&nbsp;<a href="http://medianetwork.oracle.com/media/show/15507">Doug Lea’s talk</a>&nbsp;from the JVM Language Summit 2010.<o:p></o:p></span></div><div class="MsoBodyText" style="line-height: 15.0pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 47.25pt; margin-right: 0in; margin-top: 0in; mso-list: l7 level1 lfo8; tab-stops: 0in list .5in; text-indent: -14.15pt;"><span lang="RU" style="font-family: Symbol;">·<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><strong><span lang="RU" style="font-weight: normal;">Actors</span></strong><b><span lang="RU">&nbsp;</span></b><span lang="RU">– express your computations as the run loop of an actor. Communicate between actors with messages – this makes the dependencies asynchronous AND somewhat invisible to whomever is scheduling actor invocations except by the arrival of messages in a mailbox. Every actor has a mailbox which effectively means there is one queue per-actor, which lets you decide in your problem how finely to cut it up. Something has to actually schedule the computations of the actors though – note that Scala actors are backed by … a fork/join pool. It seems to me that the actor model obscures the dependency information from fork/join – there is nothing captured at the underlying level when an actor has sent a message to another and is waiting for a response. That’s implicitly captured by having a message in one mailbox and nothing in the waiting actor, but it seems impossible to convey the higher-level dependency structure to the underlying scheduler.<o:p></o:p></span></div><div class="MsoBodyText" style="line-height: 15.0pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 47.25pt; margin-right: 0in; margin-top: 0in; mso-list: l8 level1 lfo9; tab-stops: 0in list .5in; text-indent: -14.15pt;"><span lang="RU" style="font-family: Symbol;">·<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><strong><span lang="RU" style="font-weight: normal;">Continuations</span></strong><b><span lang="RU">&nbsp;</span></b><span lang="RU">– to me, continuations are (at a high level) pretty similar to actors. They have the benefit that can presumably be paused from outside the computation, so an external scheduler might be able to timeslice work in and out in some better way, but it seems like there is a lot of machinery there that adds overhead.<o:p></o:p></span></div><div class="MsoBodyText" style="line-height: 15.0pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 47.25pt; margin-right: 0in; margin-top: 0in; mso-list: l9 level1 lfo10; tab-stops: 0in list .5in; text-indent: -14.15pt;"><span lang="RU" style="font-family: Symbol;">·<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><strong><span lang="RU" style="font-weight: normal;">Data flow</span></strong><span lang="RU">&nbsp;– data flow is a very intriguing model because it lets you explicitly model the data dependencies between tasks. GPars probably has the most interesting implementation of it that I know of. There are a few other variants written for Clojure (that relies on the underlying agent framework) and Scala (that relies on the underlying actor infrastructure). Because those rely on underlying frameworks, I’m pretty sure they don’t optimally leverage the dependency information inherent in data flow tasks. I’d love to see a framework that was optimized to leverage that dependency info though.<o:p></o:p></span></div><div class="MsoBodyText" style="line-height: 15.0pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 47.25pt; margin-right: 0in; margin-top: 0in; mso-list: l10 level1 lfo11; tab-stops: 0in list .5in; text-indent: -14.15pt;"><span style="font-family: Symbol;">·<span style="font: normal normal normal 7pt/normal 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><strong><span lang="RU" style="font-weight: normal;">Clojure</span></strong><b><span lang="RU">&nbsp;</span></b><span lang="RU">– Clojure actually has a bunch of different things that work in concert so it’s hard for me to describe it as any one model. Most state is immutable and persistent via structural sharing. When you want to mutate state, there are a variety of features (refs, atoms, agents) that let you choose whether state changes should happen synchronously or asynchronously, and whether they should or should not be coordinated with others. Clojure has STM which allows you to synchronize multiple state changes in a well-ordered way. MVCC lets you see a consistent view during the change (again leveraging the persistent data structures) and transactions are retried in the case of conflict. Reads are always available, again due to the data structures. Clojure agents are backed ultimately by an executor pool (one that is internal and you have no control over). There is work ongoing in Clojure to create a set of functions over sequences (filter, map, etc) that is backed by parallel execution against a fork/join pool and I think that shows great promise to provide easy benefits for a different kind of problem (where you are working with large chunks of data). </span><b>… “<o:p></o:p></b></div></tt></pre></div></description>
<link>http://musings-on-technology.blogspot.com/2011/04/learning-from-jdk-source-and-language.html</link>
<author>noreply@blogger.com (Kaniska)</author>
<thr:total>0</thr:total>
</item>
<item>
<guid isPermaLink="false">tag:blogger.com,1999:blog-1373851816248476399.post-4536973185898044278</guid>
<pubDate>Tue, 19 Apr 2011 04:43:00 +0000</pubDate>
<atom:updated>2011-04-19T10:13:43.955+05:30</atom:updated>
<category domain="http://www.blogger.com/atom/ns#">HTML5</category>
<title>Road to Openness</title>
<description><div dir="ltr" style="text-align: left;" trbidi="on"><br /> <div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Chorme and Droids opening up the floodgate of amazing possibilities that will capture the imagination of the Netizens !<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Welcome to a new World<span style="mso-spacerun: yes;">&nbsp; </span>free from 'Desktop Vendor Lock-In' and 'Internet Monopoly' !<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">I can't help echoe the following excerpt from Google IO ...<span style="mso-spacerun: yes;">&nbsp;&nbsp; </span>"<b>No longer a nightmare of a draconian future .. of a single vendor single product .. a future without choice ! </b>"<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">A new Revolution had already begun when Web started being treated as Platofrm by Facebook, Zoho , Netflix, Google, LinkedIn, SaleForce, Tumblr, Jigsaw, Scribd and many more who joinined the forces in recent time ! <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">And now today Browsers empowerd with HTML5 are helping Web apps become as powerful as Desktop applications ! <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Essentially its a giant leap forward by Google and likeminded benedictors towards the efforts of<span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>creating powerful Browsers to free the Earth from the bondage of Desktop OS !<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Thanks to HTML5 <b>Server Sent messages</b> for performing this magic of representing Rich Media / High-Perfornace Graphics / Desktop Content / Complex Netwroking / Offline storage etc.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">HTML5 - <b>Web GL</b> is the technology behind rendering GPS on mobile and computer browsers.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Internet at a growth rate of 120% .. has definitely outperformed and outpaced other networking mediums<span style="mso-spacerun: yes;">&nbsp; </span>- tv/radio/magazine/newspaper. <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">HTML5- <b>Workers</b> allow web apps to access and leverage the power of multi-core CPUs boosting the Rich-UI experience to a great extent. <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">As per the Google Prediction, by the end of 2010, the HTML 5 features like -<span style="mso-spacerun: yes;">&nbsp; </span><b>Web Video</b> / Canvas / SVG / <b>AppCache</b> / <b>Web Storage</b> / <b>Web Sockets</b> / <b>Geo Locations </b>..<span style="mso-spacerun: yes;">&nbsp; </span>will be supported<span style="mso-spacerun: yes;">&nbsp; </span>by<span style="mso-spacerun: yes;">&nbsp; </span>all major browsers (<b>Opera</b>, <b>Chrome</b>, <b>Safary</b>, <b>FireFox</b>) .. except ... guess what !.. Yes ..<span style="mso-spacerun: yes;">&nbsp; </span><b>IE</b> .. which will support <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><span style="mso-spacerun: yes;">&nbsp;</span>only Video / SVG and Web Storage<span style="mso-spacerun: yes;">&nbsp; </span>falling behind all other 4 browsers !!<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">So there will be a surge in statrt-ups and new initiatives for developing innovative products on these open standrds !<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Say, DarkRoom (from MugTug)<span style="mso-spacerun: yes;">&nbsp; </span>allows editing photos and applying amzing affects Online .. and pretty fast ! It makes best of 'AppCache' for creating GUI on Web. Even browsers will support creating GUI using local storage in offline mode and then simply synching up once user goes online. <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">So no need to install a 'Photo Editor' on desktop, then download photos locally, apply effect and upload on web and sync back n forth !!<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Great Huh !<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Gmail and many other mail clients had adopted the HTML 5<span style="mso-spacerun: yes;">&nbsp; </span><b>File API</b> and <b>Notification API</b> for<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"><span style="mso-spacerun: yes;">&nbsp;</span>Drag-n-Drop of any attachment on the mail. <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">The beauty is - if the proper chrome extension is installed, then while surfing net, users will automcatically get notifcation about gmails even without leaving current page and without starting local mail client!<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Clicker.TV is a great implementor of 'Worker' for pulling a huge amount of TV and Media live streaming and then caching. Its a<span style="mso-spacerun: yes;">&nbsp; </span>huge leap forward !<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><b><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Open Video Codec</span></b><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"> (VP8) offering super quality video streaming through Chrome and Youtube<span style="mso-spacerun: yes;">&nbsp; </span>by taking advanges of multiple cores<span style="mso-spacerun: yes;">&nbsp; </span>and open standrds of DSP.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Google TV will certainly revolutinize the concpet of 'Telecast over Net'<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">How about <b>Animation using CSS</b> <b>and Javascript</b> using html5.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Tooling around CSS and fast network roundtrips (all HTML5 blessings) will open up new possibilities in the Multi-player Online Gaming World !<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Imgaine running any 3d Game written using native Client into the browser !<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><b><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Mashing Up service and online apps</span></b><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;"> will also become easier.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">TwitDeck is a great example.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Here one can move the twit widgets and instanly comes to know from where 'certain apps' are coming from. <b>Twit notifications</b> are constantly monitord and pushed from server and corresponding<span style="mso-spacerun: yes;">&nbsp; </span><b>Geo Locations</b> are queried upon to present all the relevant information to the users.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">The big question is once a <b>Magazine is actually represneted as a Magazine</b> in a browser and not as a mere Webpage , then do we really need to invest in iPad or Kindle !<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><b><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Thats the power of openness ! <o:p></o:p></span></b></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Thats what<span style="mso-spacerun: yes;">&nbsp; </span>Chrome is about to do .. just stay tuned to Google Technologies ....<span style="mso-spacerun: yes;">&nbsp; </span>its going to Recrate the same Immersive Experience that you enjoy while reading a newspaper or magazine !<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Imagine how dramatically it will increase the reachability of popular media brands and skyrocket its revenue !<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">HTML 5 will simply metamorphize business models !<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Now there is great gift from Google for the Apps Developers !<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Using HTML 5 google provides <b>Infrasturces as Services on demand and Virtualize existing complex apps</b> through its collboration with VMWare Cloud and SpringSource.<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Few commands in Spring Roo Shell will – create a Spring Project, do the Persistence Setup, Create Entities, Services, provide GWT artifcats, package, update GWT .. in couple of minutes (for a small demo app) and Google App Engine Plugins (assuming user installed SpringSource tool Suite)<span style="mso-spacerun: yes;">&nbsp;&nbsp; </span>upload the app in cloud .. also immediately use Spring Insights and Cloud Monitors to provide performance stats !<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal;"><br /> </div><div class="MsoNormal" style="line-height: normal;"><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; font-size: 14.0pt; mso-fareast-font-family: &quot;Times New Roman&quot;;">Lets all enjoy the freedom of choice and openness offered by HTML5.<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 10.0pt;"><br /> </div></div></description>
<link>http://musings-on-technology.blogspot.com/2011/04/road-to-openness.html</link>
<author>noreply@blogger.com (Kaniska)</author>
<thr:total>0</thr:total>
</item>
<item>
<guid isPermaLink="false">tag:blogger.com,1999:blog-1373851816248476399.post-2273600851393847839</guid>
<pubDate>Tue, 19 Apr 2011 04:42:00 +0000</pubDate>
<atom:updated>2011-04-19T10:12:34.158+05:30</atom:updated>
<category domain="http://www.blogger.com/atom/ns#">Architecture</category>
<category domain="http://www.blogger.com/atom/ns#">Scalability</category>
<title>Best Practices of Enterprise System Architecture</title>
<description><div dir="ltr" style="text-align: left;" trbidi="on"><br /> <div class="Standard"><span lang="DE" style="color: maroon; font-size: 24.0pt;">An Enterprise System should be Highly Scalable, Always Available, Easily Manageable, Fast Performer, Auto-Healer and Capable of Super Fast Searching and Intelligent Analysis through Machine Learning.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><br /> </div><div class="Standard"><b><span lang="DE" style="font-size: 14.0pt;">Scalability</span></b><span lang="DE"> means the system does not downgrade even when load increases multiple times.<o:p></o:p></span></div><div class="Standard"><span lang="DE">For example, when number of users of an ecommerce system increases heavily further leading to sudden increase in transactions per user, the system should still keep performing with same SLA and handle the traffic smoothly ensuring that business is not down.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">One of the design choice for large-scale system is to <b>scale out horizontally</b>. Create one DB per Entity (User/ Item/ Product) and store only Key-Value in that table. Replicate the DB in various machines and implement a scheme for data-sharding.<o:p></o:p></span></div><div class="Standard"><span lang="DE">For example, in the Modulo(Entity_Pky, 100) approch, User Bob with id 1000 will be located in machine #10 . So if number of users increases suddenly, new User DB will be created in new machine and the new user info will be inserted automatically.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">There are other data-sharding policies like <b>Range-based partitions</b>, <b>Lookup based approach</b>, <b>Read-Most-Write-Least Model</b>.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><b><span lang="DE">SimpleDB</span></b><span lang="DE"> can be effectively used to manage lookup-orieneted entity info.<o:p></o:p></span></div><div class="Standard"><span lang="DE">This is an out-of-the-box offering from Amazon AWS as a hosted and managed solution administered by Amazon itself. SimpleDB does the heavy-lifting of multi-value data fetching for a key, batch operations, consistent reads.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Its better to delegate the tradional 'data management operations' like 'Relations, Transactions, Locks, Sequences, Constraints' to Application Layer as SimpleDB is meant for handling simple things !!<span style="mso-spacerun: yes;">&nbsp;&nbsp; </span>Such a typical example is eBay DAL layer.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Actually the System Architect should choose the Entities which are meant for mere lookup (like User, Item, Manufacturer, Order) and mark them as best candidates for SimpleDB items. Those entities will be then guarnteed to be highly available. Off course this pattern is not suitable for financial transactions in banking domain and rule-based complex events where every fetch query triggers<span style="mso-spacerun: yes;">&nbsp;&nbsp; </span>sub-query-based rules or procedures.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Discussing further details on implementing SimpleDB is out-of-scope here.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">If we want to handle complex business transactions while updating Entity Info and manage intricate relatiuonships then we should take resort to Cassandra or mongoDB.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">But we should remember that one needs to take care of Scalability in Application layer while adopting NoSQL Dbs.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">&nbsp;If the data are hierarchical in nature - we can leverage a Graph Database (MonogoDB) which is as opposed to conventional sql-db is a de-normalized graph processor.</span><span lang="DE"><o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><b><span lang="DE" style="font-size: 14.0pt;">Availability</span></b><span lang="DE"> : Load-balancing and Clustering are standard practices for making applications available. Normally DNS Resolver routes to a pool of servers for a requested application and Load-balancer picks up one server.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Machines should be load-balanced in such a way the moving the user from one machine to another machine can be achieved easily without shutting down the system.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><b><span lang="DE" style="font-size: 14.0pt;">Fast Searching :<o:p></o:p></span></b></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">NoSql is a must for fast lookup of trillions of<span style="mso-spacerun: yes;">&nbsp; </span>Business Entity data and persisting time-critical entities by locking data storage row for a<span style="mso-spacerun: yes;">&nbsp; </span>negligible amount of time (contrary to traditional RDBMS), yet be able to write-through / broadcast write events to sub0system grids (Search Grid / Analytics Machine / Events Collector etc.)<o:p></o:p></span></div><div class="Standard"><span lang="DE">Cassandra does a very neat job for that matter.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">"The sparse two-dimensional “super-column family” architecture allows for rich data model representations (and better performance) beyond just a simple key-value look up.....<o:p></o:p></span></div><div class="Standard"><span lang="DE">Some of the most attractive features of Cassandra are its uniquely flexible consistency and replication models. Applications can determine at call level what consistency level to use for reads and writes (single, quorum or all replicas). This, combined with customizable replication factor, and special support to determine which cluster nodes to designate as replicas, makes it particularly well suited for cross-datacenter and cross-regional deployments. In effect, a single global Cassandra cluster can simultaneously service applications and asynchronously replicate data across multiple geographic locations...."<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Its worth paying for the learning curve and operational compexities in exchange of the 'scalability, availability and performance advantages of the NoSQL persistence model'....<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">In traditional DB, what happens if one of the node containing one of the table in a join condition is down !<o:p></o:p></span></div><div class="Standard"><span lang="DE">Simple - now the whole application that depends on that join condition is unavailable !<o:p></o:p></span></div><div class="Standard"><span lang="DE">Well there is no join condition in NoSql !! Cassandra is best for cross-regional deployments and scaling with no single points of failure.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Next question – does the NoSql gurantees data-consistency the same way Relational DB vouches for read-after-write consistency at the cost of Blocking the read untill Transaction is finished !<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Well NoSql follows CAP theorem not ACID principle !<o:p></o:p></span></div><div class="Standard"><span lang="DE">So if you think 'immediate consistency' need to be ensured for super-critical tasks like Bidding / Buying, better await till data committed before reading the latest data !<span style="mso-spacerun: yes;">&nbsp; </span>In certain cases of 'Eventual Consistency' like searching data where we expect fast response we may not await for latest data to availble but rather instantly display the pre-computed search result !!<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Also there is no concurrency bottlenecks ! Replicas are mostly Multi-master Highly Available !<o:p></o:p></span></div><div class="Standard"><span lang="DE">NoSql ensures Asynchronous Lock-based Reconciliation as opposed to Synchronous Lock-based Reconciliation bby SQL.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">This means more work but saving time !! Using Message -Multicast do write-behind to replicated database / grid without taouching master db. Then synchronize with master DB after a specific time period. This saves lot of time spent in Index Arrangement and Sequential Updation.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Say you want to search – 'Blue Sony mp3 player' ! NoSql will hold the lock for a row only for couple of milliseconds as opposed to locking the entire table by RDBMS ! NoSql will just lookup the id of next entity (manufatures) against the id of the main entity (product) and move the mesage to the next table !! At the same time, it looks up the product requested by the next user !!<span style="mso-spacerun: yes;">&nbsp; </span>No Joins , Just Intelligent Routing !!<span style="mso-spacerun: yes;">&nbsp; </span>Handling millions of requests concurrently has never looked so esy before !!!<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Which is for What ?<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Memcahed : Static Key-Value Pair<o:p></o:p></span></div><div class="Standard"><span lang="DE">Neo4j<span style="mso-spacerun: yes;">&nbsp; </span>: Network Graph Store<o:p></o:p></span></div><div class="Standard"><span lang="DE">Hbase<span style="mso-spacerun: yes;">&nbsp; </span>: Row-Orieneted Sparse Column Store<o:p></o:p></span></div><div class="Standard"><span lang="DE">MongoDB : (Key, Document) Storage.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Great Document : <a href="http://highscalability.com/blog/2011/2/15/wordnik-10-million-api-requests-a-day-on-mongodb-and-scala.html"><span style="color: windowtext; text-decoration: none; text-underline: none;">http://highscalability.com/blog/2011/2/15/wordnik-10-million-api-requests-a-day-on-mongodb-and-scala.html</span></a><o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><b><span lang="DE" style="font-size: 14.0pt;">Fast Data Analysis<o:p></o:p></span></b></div><div class="Standard"><br /> </div><div class="Standard"><b><span lang="DE">Apache Hbase </span></b><span lang="DE">– best suited for Data Analytics, Data Mining, Enterprise Search and other Data Query Services.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">If the main business is to mine PeraBytes of data and perform parallel range-queries and then combine the results through batch Map-Reduce (say Enterprise Search for Video Content), then one<span style="mso-spacerun: yes;">&nbsp; </span>of the defacto choice is Apache Hbase configured with haddop Jobs, using HDFS as a shared storage platform. Hbase comes with availability trade-off i.e. the persistent domain entities may not immediately available in the Search Result. The reason for this is huge Hadoop Map-Reduce jobs are performed parallely in offline mode so that main source of data is not hogged by Hadoop Jobs and is highly Scalable.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">It should be noted that Hadoop is not meant for searching in real-time. Its actually an offline batch-processing system well-suited for BI analytics, data aggregation, normalization in parallel.<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">Hadoop provides a framework which will automatically take care of interProcess co-ordination, distributed counters, failure detection, automatic restart of failed process, co-ordinated, sorting and much more.<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">There is different stages like mapper, combiner, partitions, reducer etc, instead of we writing from the scratch, the framework takes care of it.<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">Erlang / Scala also provide out-of-the box parallel processing.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Its important to know that there are different tools based on hadoop that serve different purposes :<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Hive : SQL query for MR<o:p></o:p></span></div><div class="Standard"><span lang="DE">Pig : Scripting for MR<o:p></o:p></span></div><div class="Standard"><span lang="DE">HBase : Low-latency, Big Table like database on hadoop<o:p></o:p></span></div><div class="Standard"><span lang="DE">Oozie : Workflo Mgmt on Hadoop<o:p></o:p></span></div><div class="Standard"><span lang="DE">Sqoop - RDBMS import / export<o:p></o:p></span></div><div class="Standard"><span lang="DE">Zookeeper : Fast, distributed, coordination system<o:p></o:p></span></div><div class="Standard"><span lang="DE">Hue : advanced web env. for Hadoop and custom applications<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Here come the ultimate offering from Spring - <a href="http://www.springsource.org/spring-data"><span style="color: windowtext; text-decoration: none; text-underline: none;">http://www.springsource.org/spring-data</span></a><o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Apache has a solution for combining lucene with hadoop for blazing-fast document search.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><b><span lang="DE" style="font-size: 14.0pt;">Fast Cache :<o:p></o:p></span></b></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Implementing a cold cache with minimum memory footprint (MySQL native memory, Memcached, Terracota Ehcahce) is absolutely important.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Application Server should not remeber the state of the Entity rather should just persist in DB. The metadata should be stored in Cold Cache.<span style="mso-spacerun: yes;">&nbsp; </span>The persistent pojo objects should never be cached in memory.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">If queries are mostly read-only, very less updates - the mySQL native memory scores high ! MySQL InnoDB storage engine’s dictionary cache provides blazing fast data acceess. On demand, data blocks are read from disk and stored in memory using LRU chains or other advanced mechanisms(like MySQL’s Midpoint Insertion Strategy) .</span><span lang="DE"><o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">In order to lookup the value for a key, Memcached clients issue multiple parallel requests to memcached servers where keys are sharded across those servers.<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">For a frequently changing data set , Memcahed is surely better than DB Cache<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE">Probably the fastes cache on planet is -<span style="color: black;"> is Ehcache using Terracotta BigMemory </span><a href="http://blog.terracottatech.com/2010/09/bigmemory_explained_a_bit.html"><span style="color: windowtext; text-decoration: none; text-underline: none;">http://blog.terracottatech.com/2010/09/bigmemory_explained_a_bit.html</span></a><o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">Here directly the native byte-buffer of the OS is used bypassing main-memory.<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">A write-optimized data store. Something that aggregates the writes in RAM, and writes out generational updates. Take a look at Google's BigTable paper for a good description of this strategy.</span><span lang="DE"><o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">A very good reference : </span><b style="mso-bidi-font-weight: normal;"><span lang="DE" style="color: black; font-size: 9.5pt; mso-bidi-font-size: 12.0pt;">http://research.yahoo.com/files/sigmod278-silberstein.pdf</span></b><span lang="DE"><o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><br /> </div><div class="Standard"><br /> </div><div class="Standard"><b><span lang="DE" style="font-size: 14.0pt;">Everything Asynchronous<o:p></o:p></span></b></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">All communications in every layer should be asynchronous to reduce the latency.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">There are 2 types of latency.<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">1. <b>user latency</b> - how fast user gets back the control on web site<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">2. <b>execution latency</b> - how fast the execution takes place in backend<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">UI behavior should be completely Ajax and send the main events to queue and schedule for batch updates in offline mode. There is absoulutely no room for a wait_state i.e. all response should be immediate and non-blocking.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Common Flow :<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">-- Submit a job/task to a thread and return to the user immediately.<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">-- The thread should perform the operation in background (it may communicate to LRU cache optimized for concurrent access / Graph Structure / Iry-IIry master-slave replicatioed env / Map-Reduce based sturctures)<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">-- Once done with the opertaion it should return the result thru a CallbackHandler and client will get notification.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">There are multiple patterns for Asynchronous Communications.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">(1) Store all jobs in Event Queue. Select a queue based on a contract/ algo depending on type of task. Then use multiple event brokers/ listeners to handle the jobs from queue (thrid party ESB like Tibco / apache fuse/ apache camel / ...) can be used.<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">(2) Message Multicast - say user enters a new item in system. do not update the iry db immediately. rather send messages to pollers / searchers - that there is a 'New' event. Return to user immedialtely. Now the updater thread will update Iry db. Then searcher will behind the scene query Iry db / data source to find what has been just added and it will add it to its search grid !<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">(3) Batch Processing (schedule offline procesing). Identify which type of job requests can be scheduled for offline processing and do not need immediate attention !<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><br /> </div><div class="Standard"><b><span lang="DE" style="font-size: 14.0pt;">Prallel Threading<o:p></o:p></span></b></div><div class="Standard"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">Use Executor Service to effectively manage pool of threads -&nbsp;<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;"><span style="mso-spacerun: yes;">&nbsp;</span>Remember &nbsp;a simple set of worker threads 'without the manager' - can simply lead to&nbsp;<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;"><span style="mso-spacerun: yes;">&nbsp;</span>(i) Resource Thrashing (each thread is expensive - execution call stack / context switching)<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;"><span style="mso-spacerun: yes;">&nbsp;</span>(ii) Request Overload .. &nbsp;if all requests are provided threads for execution<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;"><span style="mso-spacerun: yes;">&nbsp;</span>(iii) Thread Leakage : sive of threadpool diminishes due to uncaught errors but requests are not served !<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">So there should be a proper manager to allocate threads either FixedThreadPool / ScheduledThreadPool / SingleThreadPool / QueuedThreadPool with proper RejectionPolicy.<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">This manager should also place the completed result in a non-blocking queue from where result can be taken off asynchrounously.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">Thread should not wait to acquire locks - leverage advanced processor optimizations to use LATCH concept to lock/unlock threads at the same time. Locks should be acquired / released in any order.<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">Fork/Join and CountDownLatch are powerful concepts for running threads parallely.<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: black;">You can download and try out the open-source Thrift which is a C++ Fwk for multi-threading and asynchronous processing of job<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><br /> </div><div class="Standard"><b><span lang="DE" style="font-size: 14.0pt;">Auto-Healing and Self-Recovery :<o:p></o:p></span></b></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Systems should be falut-tolernt and should know how to degrade gracefully in the scenario of unprecented load.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">The JMX agents and other Robot Apps should continously monitor the system and gather intelligence to take the best desicion.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">A high-degree of automation is requireed for easily recovering from failures and managing the system smoothly.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Normally automation is driven though Centrallized Logging System and Self-organization Artificial Intelligence. BI tools are used to analyze user experience and provide Best Match through continous inhouse experimentations.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard"><span lang="DE">Scalable systems are mangeable if new partitions can be added, DB instance can be horizantally scaled out and new application servers turned on without affecting users of the system.<o:p></o:p></span></div><div class="Standard"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><b style="mso-bidi-font-weight: normal;"><span lang="DE" style="color: maroon;">Case Study :<o:p></o:p></span></b></div><div class="Standard" style="mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><b style="mso-bidi-font-weight: normal;"><span lang="DE" style="color: maroon;"><span style="mso-spacerun: yes;">&nbsp;</span>Twitter :<o:p></o:p></span></b></div><div class="Standard" style="mso-pagination: widow-orphan;"><b style="mso-bidi-font-weight: normal;"><span lang="DE" style="color: maroon;">1. </span></b><span lang="DE" style="color: maroon;"><a href="http://www.slideshare.net/kevinweil/nosql-at-twitter-nosql-eu-2010"><b style="mso-bidi-font-weight: normal;"><span style="color: maroon; text-decoration: none; text-underline: none;">http://www.slideshare.net/kevinweil/nosql-at-twitter-nosql-eu-2010</span></b></a><o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: maroon;"><a href="http://www.slideshare.net/kevinweil/hadoop-at-twitter-hadoop-summit-2010"></a><o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><b style="mso-bidi-font-weight: normal;"><span lang="DE" style="color: maroon;">2. </span></b><span lang="DE" style="color: maroon;"><a href="http://www.slideshare.net/kevinweil/hadoop-at-twitter-hadoop-summit-2010"><b style="mso-bidi-font-weight: normal;"><span style="color: maroon; text-decoration: none; text-underline: none;">http://www.slideshare.net/kevinweil/hadoop-at-twitter-hadoop-summit-2010</span></b></a><o:p></o:p></span></div><div class="Standard" style="margin-left: 35.3pt; mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="margin-left: 35.3pt; mso-pagination: widow-orphan;"><b style="mso-bidi-font-weight: normal;"><span lang="DE" style="color: black; font-size: 9.5pt; mso-bidi-font-size: 12.0pt;">Twitter Example :<o:p></o:p></span></b></div><div class="Standard" style="margin-left: 35.3pt; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 9.5pt; mso-bidi-font-size: 12.0pt;">user SAM tweets -<o:p></o:p></span></div><div class="Standard" style="margin-left: 35.3pt; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 9.5pt; mso-bidi-font-size: 12.0pt;">&gt; store tweet &gt; iterate social graph<o:p></o:p></span></div><div class="Standard" style="margin-left: 35.3pt; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 9.5pt; mso-bidi-font-size: 12.0pt;">&gt; split chunks into parallel jobs &gt; prepend packet into its memcahced blob / (some other cache) - if not present in cache - talk to db / hadoop<o:p></o:p></span></div><div class="Standard" style="margin-left: 35.3pt; mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="margin-left: 35.3pt; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 9.5pt; mso-bidi-font-size: 12.0pt;">user RAM who follows SAM - sees sam's tweet -<o:p></o:p></span></div><div class="Standard" style="margin-left: 35.3pt; mso-pagination: widow-orphan;"><b style="mso-bidi-font-weight: normal;"><span lang="DE" style="color: black;">&gt; read mysql blob from memcache (or other cache) &gt; deserialze integers &gt; sort &gt; slice &gt; probablistic truncation (fast but may not be all consistent).<o:p></o:p></span></b></div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: maroon;"><br /> 3. <b style="mso-bidi-font-weight: normal;">SalesForce : </b><a href="http://www.infoq.com/interviews/dave-carroll-salesforce-api"><b style="mso-bidi-font-weight: normal;"><span style="color: maroon; text-decoration: none; text-underline: none;">http://www.infoq.com/interviews/dave-carroll-salesforce-api</span></b></a><b style="mso-bidi-font-weight: normal;"><br style="mso-special-character: line-break;" /> <!--[if !supportLineBreakNewLine]--><br style="mso-special-character: line-break;" /> <!--[endif]--></b><o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: maroon;">4. <b>Facebook</b> :<span style="mso-spacerun: yes;">&nbsp; </span></span><span lang="DE"><a href="http://www.infoq.com/presentations/Scale-at-Facebook"><span style="color: windowtext; text-decoration: none; text-underline: none;">http://www.infoq.com/presentations/Scale-at-Facebook</span></a><span style="color: maroon;">&nbsp;.</span><o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="margin-left: 35.3pt; mso-pagination: widow-orphan;"><b><span lang="DE">Facebook Example :<o:p></o:p></span></b></div><div class="Standard" style="margin-left: 35.3pt; mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="margin-left: 35.3pt; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 9.5pt; mso-bidi-font-size: 12.0pt;">Alex friend of bob - logs in&nbsp;<o:p></o:p></span></div><div class="Standard" style="margin-left: 35.3pt; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 9.5pt; mso-bidi-font-size: 12.0pt;">&gt; Web-tier Calls a C++ based Service (thrift)<br /> &gt; Thrift has the user-id of Bob and calls Aggregator to find all friends ids of Alex<br /> &gt; Aggregator in parallel calls the multi-feed leaves.... &nbsp;(each leaf node is one user for which their is one DB .. one DB .. has a key-value pair (uid, user-data) ... no traditional sql (this is like noSql graph db)<o:p></o:p></span></div><div class="Standard" style="margin-left: 35.3pt; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 9.5pt; mso-bidi-font-size: 12.0pt;">&gt; feed result says &nbsp;[Bob, Sam, Paul] - these &nbsp;are all alexe's friends .... returns those ids &nbsp;(multi-feed) - by calling all DB servers in parallel .. finds the Indexes ..<br /> &gt; Aggregator says ..now got &nbsp;ids of 40 most interesting stories .... &nbsp; It .. ranks them ... based on certain criteria .....<o:p></o:p></span></div><div class="Standard" style="margin-left: 35.3pt; mso-pagination: widow-orphan;"><span lang="DE" style="color: black; font-size: 9.5pt; mso-bidi-font-size: 12.0pt;">&gt; For each Id, .. get the metadata (timestamp, user name, comment..) from memcached (in ur cache it could be any other cache) - parallel query on multi-core Fedorra<br /> &gt;&nbsp;Now&nbsp;web tier renders the data.<o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: maroon;">5. <b>Google</b> : </span><span lang="DE"><a href="http://highscalability.com/google-architecture"><span style="color: windowtext; text-decoration: none; text-underline: none;">http://highscalability.com/google-architecture</span></a><o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><span lang="DE" style="color: maroon;">6.<b>Flickr</b> :<span style="mso-spacerun: yes;">&nbsp; </span></span><span lang="DE"><a href="http://highscalability.com/flickr-architecture"><span style="color: windowtext; text-decoration: none; text-underline: none;">http://highscalability.com/flickr-architecture</span></a><o:p></o:p></span></div><div class="Standard" style="mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><br /> </div><div class="Standard" style="mso-pagination: widow-orphan;"><br /> </div></div></description>
<link>http://musings-on-technology.blogspot.com/2011/04/best-practices-of-enterprise-system.html</link>
<author>noreply@blogger.com (Kaniska)</author>
<thr:total>0</thr:total>
</item>
<item>
<guid isPermaLink="false">tag:blogger.com,1999:blog-1373851816248476399.post-4667292790317710604</guid>
<pubDate>Tue, 19 Apr 2011 04:30:00 +0000</pubDate>
<atom:updated>2011-04-19T10:08:44.420+05:30</atom:updated>
<category domain="http://www.blogger.com/atom/ns#">Hibernate</category>
<category domain="http://www.blogger.com/atom/ns#">Scalability</category>
<title>Hibernate known facts unknown traps</title>
<description><div dir="ltr" style="text-align: left;" trbidi="on"><b><span lang="RU">Why to use ORM ?</span></b><br /> <div class="MsoNormal" style="margin-left: .5in;"><span lang="RU">(i)&nbsp;&nbsp;&nbsp;HQL offers joins and aggregate functions. HQL expressed using Domain Object properties </span>rather <span lang="RU">than DB Colum</span>ns and completely decoupled<span lang="RU"> from DB Schema.&nbsp; SQL power is leveraged at Domain Object level.<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .5in;"><span lang="RU">(ii)&nbsp;&nbsp;Unlike iBatis, Hibernate abstracts underlying DB and Data Model. <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .5in;"><span lang="RU">(iii)&nbsp;Hibernate performs Change detection – via Snapshot Comparisons . <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .5in;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Hibernate <b style="mso-bidi-font-weight: normal;"><span lang="RU">creates runtime proxies for persistent objects thru dynamic byte code generation </span></b><b style="mso-bidi-font-weight: normal;">using </b><span lang="RU">Javaassist. </span>We can change it to CGLib.<o:p></o:p></div><div class="MsoNormal" style="margin-left: .5in;">(iv) <span lang="RU">Unlike jdo – Hibernate does not need to modify persistent objects to observe their state. <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .5in;"><span lang="RU">(v)&nbsp;&nbsp;</span>Unlike EJB, hibernate can be run as a stand alone tool outside jree container.<span lang="RU">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;"><span lang="RU">SessionFactory and Session</span></b><span lang="RU"><br /> The purpose of the Hibernate SessionFactory (called EntityManager in JEE) is to create Sessions, initialize JDBC connections and pool them (using a pluggable provider like C3P0). <o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><span lang="RU">A SessionFactory is immutable </span>cache of compiled mappings (plus associations / inheritence / aggregations) for a single database.<o:p></o:p></div><div class="MsoNormal">It is<span lang="RU"> built from a Configuration holding mapping information, cache information and a lot of other information usually provided by means of a hibernate.cfg.cml file or through a Spring bean configuration.<o:p></o:p></span></div><div class="MsoNormal"><span lang="RU"><br /> A Session is a unit of work at its lowest level - representing a transaction in database </span>lingo.<o:p></o:p></div><div class="MsoNormal">Session is not thread safe and is maintained as a threadlocal value.<o:p></o:p></div><div class="MsoNormal"><span lang="RU">When a Session is created and operations are done on Hibernate entities, e.g. setting an attribute of an entity, Hibernate does not and update the underlying table immediately. Instead Hibernate keeps track of the state of an entity, whether it is dirty or not, and flushes (commits) updates at the end at the end of a unit of work. This is what Hibernate calls the first level cache.<br /> <br /> <b style="mso-bidi-font-weight: normal;">The 1st level cache</b><br /> Definition: The first level cache is where Hibernate keeps track of the possible dirty states of the ongoing Session's loaded and touched entities. The ongoing Session represents a unit of work and is always used and can not be turned of. The purpose of the first level cache is to hinder to many SQL queries or updates beeing made to the database, and instead batch them together at the end of the Session. When you think about the 1st level cache think Session. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <o:p></o:p></span></div><div class="Ol"><span lang="RU">&nbsp; <o:p></o:p></span></div><div class="Ol"><b><span lang="RU">How does Hibernate implement Lazy-Initialization for single-ended collection? <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU">&gt;&gt; Hibernate3 generates proxies (at startup) for all target entities i.e. Persistent classes using runtime-bytecode enhancement (via CGLIB). Then enable them for many-2-one and one-2-many associations. <o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><span lang="RU">&gt;&gt; Hibernate uses a subclass of the original class and the proxied class must implement a default constructor with package visibility ...&nbsp; so all persistent classes should have a default <b style="mso-bidi-font-weight: normal;">constructor</b> <o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><b><span lang="RU">How to improve performance using natural-id ? <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU"><class name="”User”"> <o:p></o:p></class></span></div><div class="MsoNormal">&nbsp;&nbsp; <span lang="RU"><cache usage="”read-write”/"> <o:p></o:p></cache></span></div><div class="MsoNormal"><span lang="RU">&nbsp;&nbsp; <id.........> <o:p></o:p></id.........></span></div><div class="MsoNormal"><span lang="RU">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <natural-id> <o:p></o:p></natural-id></span></div><div class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <property name="”userName”/"> </property><span lang="RU">&nbsp;&nbsp; <b style="mso-bidi-font-weight: normal;">.. should not be mutable ...</b> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ....... <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">session.createCriteria(User.class) <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp; .add(<b style="mso-bidi-font-weight: normal;">Restrictions.naturalId()</b> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp;&nbsp;&nbsp;&nbsp; .set(“name”, “</span>Bob<span lang="RU">”) <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">).<b style="mso-bidi-font-weight: normal;">setCacheable</b>(true) <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">.uniqueResult(); <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">*** <o:p></o:p></span></div><div class="MsoNormal">S<span lang="RU">ince we </span>have <span lang="RU">mention</span>ed<span lang="RU"> that the fields used are natural keys, hibernate query cache is smart enough to understand that we can bypass the uptodate check and depend on the assembling logic for handling it properly. <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><b><span lang="RU">How can I retrieve info about a collection without initializing it ? <o:p></o:p></span></b></div><div class="MsoNormal">F<span lang="RU">etch the size of a collection : <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">((Integer) s.createFilter(collection, “select count(*)”).list().get(0)).intValue() <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt; retrieve a subset of a collection <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : s.createFilter( lazyCollection, “”).setFirstResult(0).setMaxResults(10).list();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><b><span lang="RU">How to benefit from Query-Caching ?<o:p></o:p></span></b></div><div class="Ol">&gt;&gt;&nbsp;&nbsp;&nbsp; C<span lang="RU">heck query cache for the query <o:p></o:p></span></div><div class="Ol"><span lang="RU">&gt;&gt; if results are found, check if they are latest (that is no entry in update timestamps table or one which predates the cache) <o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 14.15pt;"><span lang="RU">&gt;&gt; if they are not up-to-date then assemble the object (assembling involves creating the object from its primary key or group of columns from their values or other strategies) &nbsp; <o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 14.15pt;"><span lang="RU">The query cache works something like this:&nbsp; <a href="http://www.javalobby.org/java/forums/t48846.html">http://www.javalobby.org/java/forums/t48846.html</a></span><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">| ["from Person as p where p.parent.id=? and p.firstName=?", [ 1 , "Joey"] ] -&gt; [&nbsp; 2 ] ] |</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">&nbsp;</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">The combination of the query and the values provided as parameters to that query is used as a key, and the value is the list of identifiers for that query <o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><b><span lang="RU">How Query cache work with 2</span></b><b><sup><span lang="RU" style="font-size: 7.5pt;">nd</span></sup><span lang="RU"> Level Cache ? <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU">Query-Cache : The intention is to cache the results against the query (the sql along with the parameters and their values).....&nbsp; <o:p></o:p></span></div><div class="MsoNormal">We set<span lang="RU"> hibernate.cache.<b style="mso-bidi-font-weight: normal;">use_query_cache </b></span><b style="mso-bidi-font-weight: normal;">= <span lang="RU">true</span></b><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal">Then Hibernate creates 2 memory regions :<o:p></o:p></div><div class="MsoNormal"><span lang="RU">&nbsp; Region1 : one holding cache query result sets<o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp;&nbsp;</span>R<span lang="RU">egion2 : other holding timestamps of the most recent updates to queryable tables ... <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&gt;&gt; it caches only id values and result of value type ...&nbsp; in order to fetch the state of the actual &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; entities from 2</span><sup><span lang="RU" style="font-size: 7.5pt;">nd</span></sup><span lang="RU"> level cache... <o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><span lang="RU">*** <a href="http://pitfalls.wordpress.com/2008/05/05/hibernatequerycache/">http://pitfalls.wordpress.com/2008/05/05/hibernatequerycache/</a> <o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><span lang="RU">&gt;&gt; the safest invalidation logic is to mantain update timestamps for each table. When any value is looked up from the query cache, we would also check if any of the tables involved in this query have been updated since the results were cached, if they were, the safest thing to do is query the db again. This is from a very simplistic point what hibernate does. It maintains the timestamps in the update timestamp cache. <b style="mso-bidi-font-weight: normal;">The query results are cached with the query as its key in the query cache. <o:p></o:p></b></span></div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;"><span lang="RU">stores only the primary key for queries that return results of only one type.<o:p></o:p></span></b></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><span lang="RU">&gt;&gt; A lot of heavily used data is cached at the second level. However, most of this data is looked up using its natural key, the second level cache however would store it using its primary key as the key, so we could go ahead and use the query cache to save this lookup. <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">***&nbsp; <a href="http://acupof.blogspot.com/2008/01/background-hibernate-comes-with-three.html">http://acupof.blogspot.com/2008/01/background-hibernate-comes-with-three.html</a> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">*** <a href="http://docs.google.com/Doc?id=dfxnknzf_89c6m5r3n3">http://docs.google.com/Doc?id=dfxnknzf_89c6m5r3n3&nbsp; </a><o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">few points regarding 2nd-Level-Caching <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp; *** The 2nd level cache is a process scoped cache that is associated with one SessionFactory. It will survive Sessions and can be reused in new Session by same SessionFactory (which usually is one per application). <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">**** The hibernate cache does not store instances of an entity - instead Hibernate uses something called dehydrated state. Hibernate 'dehydrates' query results and persistent objects into their primitive components and identifiers. Conceptually you can think of it as a Map which contains the id as key and an array as value. Or something like below for a cache region: <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">It stores this decomposed data in the L2 and query results cache, and on a cache hit, it rehydrates/recomposes them into the requested persistent object <br /> <br /> { id -&gt; { atribute1, attribute2, attribute3 } } <br /> { 1 -&gt; { "a name", 20, null } }<br /> { 2 -&gt; { "another name", 30, 4 } }<br /> <br /> If the entity holds a collection of other entities then the other entity also needs to be cached. In this case it could look something like:<br /> <br /> { id -&gt; { atribute1, attribute2, attribute3, Set{item1..n} } } <br /> { 1 -&gt; { "a name", 20, null , {1,2,5} } }<br /> { 2 -&gt; { "another name", 30, 4 {4,8}} }<br /> <br /> The actual implementation of the 2nd level cache is not done by Hibernate (there is a simple Hashtable cache available, not aimed for production though). Hibernate instead has a plugin concept for caching providers which is used by e.g. EHCache. <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><b><span lang="RU">In well-designed Hibernate domain models, we should avoid direct many-2-many collections</span></b><span lang="RU"> – and instead use – <b style="mso-bidi-font-weight: normal;">one-to-many associations with inverse=true </b>....&nbsp; For these associations, the update is handled by the many-2-one end of the association ...&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp; <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .5in;"><br /> </div><div class="MsoNormal"><b><span lang="RU">How to get rid of out-of-memory with hibernate cache ? <o:p></o:p></span></b></div><div class="MsoNormal" style="margin-left: .5in;"><span lang="RU">&gt;&gt; Lessons Learned <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">If you use hibernate query caching, and actually want to use memory for caching useful results, and waste as little as possible with overhead, follow some simple advice: <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.35pt;"><span lang="RU" style="font-family: StarSymbol; font-size: 10pt;">•</span><span lang="RU">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Write your HQL queries to use identifiers in any substitutable parameters.WHERE clauses, IN lists, etc. Using full objects results in the objects being kept on the heap for the life of the cache entry. <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.35pt;"><span lang="RU" style="font-family: StarSymbol; font-size: 10pt;">•</span><span lang="RU">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Write your Criteria restrictions to use identifiers as well. <o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 14.15pt; margin-left: 35.35pt; margin-right: 0in; margin-top: 0in;"><span lang="RU" style="font-family: StarSymbol; font-size: 10pt;">•</span><span lang="RU">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Use the 'smart' query cache implementation&nbsp; to eliminate duplicate objects used in query keys. This helps a little if you use the ids in your HQL/Criteria, but if you still must use objects then it helps a lot. <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 35.35pt;"><span lang="RU" style="font-family: StarSymbol; font-size: 10pt;">•</span><span lang="RU">&nbsp;&nbsp;&nbsp;</span><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">final P</span><span style="font-family: 'Courier New'; font-size: 10pt;">roduct product</span><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">= ...;</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">** Don't do this <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">final String hql = "from </span><span style="font-family: 'Courier New'; font-size: 10pt;">Product </span><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">&nbsp;as </span><span style="font-family: 'Courier New'; font-size: 10pt;">product </span><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">&nbsp;where </span><span style="font-family: 'Courier New'; font-size: 10pt;">product</span><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">.</span><span style="font-family: 'Courier New'; font-size: 10pt;">order</span><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;"> = ?"</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">** Do this</span><span lang="RU"> <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">final String hql = "from </span><span style="font-family: 'Courier New'; font-size: 10pt;">Product</span><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;"> as </span><span style="font-family: 'Courier New'; font-size: 10pt;">product </span><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">&nbsp;where </span><span style="font-family: 'Courier New'; font-size: 10pt;">product</span><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">.</span><span style="font-family: 'Courier New'; font-size: 10pt;">order</span><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">.id = ?"</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">....&nbsp;&nbsp; q.setParameter(0, </span><span style="font-family: 'Courier New'; font-size: 10pt;">order</span><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">.getId());</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">&nbsp;</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">&nbsp;</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">final Query q = session.createQuery(hql);</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">q.setParameter(0, mate);</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 14.15pt;"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">q.setCacheable(true);</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span class="MsoHyperlink">**** </span><span lang="RU"><a href="http://darren.oldag.net/2008/11/hibernate-query-cache-dirty-little_04.html">http://darren.oldag.net/2008/11/hibernate-query-cache-dirty-little_04.html </a><o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><b>Beware of <span lang="RU">fetch-mode=join .. </span></b><b>pitfalls<span lang="RU"> <o:p></o:p></span></b></div><div class="MsoNormal"><span lang="RU">****&nbsp; <a href="http://www.javalobby.org/articles/hibernate-query-101/">http://www.javalobby.org/articles/hibernate-query-101/</a> <o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><b>Beware of duplicate values :<o:p></o:p></b></div><div class="MsoNormal">*** J<span lang="RU">oin returning duplicate rows .. <o:p></o:p></span></div><div class="MsoNormal">S<span lang="RU">oln. Call method setResultTransformer() on your criteria object prior to execution with argument CriteriaSpecification.DISTINCT_ROOT_ENTITY. <br style="mso-special-character: line-break;" /> <br style="mso-special-character: line-break;" /> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">*** If there are any mapped collections whose elements also contain mapped collections, the results of the query will not only be incorrect, the objects themselves will be incorrect. Each mapped collection may contain repeated elements. <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .5in;"><span lang="RU">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU"><a href="http://www.hibernate.org/hib_docs/v3/api/org/hibernate/criterion/CriteriaSpecification.html#DISTINCT_ROOT_ENTITY&lt;br /&gt;">http://www.hibernate.org/hib_docs/v3/api/org/hibernate/criterion/CriteriaSpecification.html#DISTINCT_ROOT_ENTITY%3Cbr%20/%3E</a> <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .5in;"><span lang="RU">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU"><a href="http://forum.hibernate.org/viewtopic.php?p=2319562&amp;sid=e89cad0d04b103202732da3485437efd">http://forum.hibernate.org/viewtopic.php?p=2319562&amp;sid=e89cad0d04b103202732da3485437efd </a><o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .5in;"><span lang="RU"><a href="http://sacrosanctblood.blogspot.com/2007/07/eager-fetching-in-hibernate-using.html">http://sacrosanctblood.blogspot.com/2007/07/eager-fetching-in-hibernate-using.html </a><o:p></o:p></span></div><div class="MsoNormal"><span lang="RU">&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><b>Avoid N+1 problem :<o:p></o:p></b></div><div class="MsoNormal"><br /> </div><div class="MsoNormal">Lazy Association should be enabled if we want to avoid infamous N+1 problem ! Otherwise we can turn on 'eager fetching' if the data associated with main query is smaller in size. <o:p></o:p></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><b>OpenSessionInViewFilter</b><br /> <br /> We should effectively flush the session by overriding closeSession() of&nbsp;OpenSessionInViewFilter.<br /> In case of Spring MVC we can use Interceptor over the Filter.<br /> <a href="http://72miles.com/blog/spring-opensessioninviewinterceptor-vs-opensessioninviewfilter/">http://72miles.com/blog/spring-opensessioninviewinterceptor-vs-opensessioninviewfilter/</a></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><b>Other Tricks<o:p></o:p></b></div><div class="MsoNormal"><br /> </div><div class="MsoNormal">If we specify <b>'unsaved-value' = null</b> for primary key, then Hibernate will find out when to do insert and when to do update.<o:p></o:p></div><div class="MsoNormal"><br /> </div><div class="MsoNormal">In case session is closed when lots of data getting loaded upfront, then we should implement<o:p></o:p></div><div class="MsoNormal">Open Session in View&nbsp; (anti)pattern. Session will remain opened long enough to perform lazy associations.<o:p></o:p></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><b><span lang="RU">Avoiding out-of-memory in cache <o:p></o:p></span></b></div><div class="MsoNormal"><span class="MsoHyperlink">**** </span><span lang="RU"><a href="http://www.hibernate.org/hib_docs/v3/reference/en/html/batch.html">http://www.hibernate.org/hib_docs/v3/reference/en/html/batch.html </a><o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 14.15pt;"><br /> </div><div class="MsoNormal" style="margin-bottom: 14.15pt;"><span lang="RU">When making new objects persistent, you must </span><span lang="RU" style="font-family: 'Courier New';">flush()</span><span lang="RU"> and then </span><span lang="RU" style="font-family: 'Courier New';">clear()</span><span lang="RU"> the session regularly, to control the size of the first-level cache. <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">Session session = sessionFactory.openSession();</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">Transaction tx = session.beginTransaction();</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">&nbsp;&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">for ( int i=0; i&lt;100000; i++ ) {</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">&nbsp;&nbsp;&nbsp; Customer customer = new Customer(.....);</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">&nbsp;&nbsp;&nbsp; session.save(customer);</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">&nbsp;&nbsp;&nbsp; if ( i % 20 == 0 ) { //20, same as the JDBC batch size</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //flush a batch of inserts and release memory:</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; session.flush();</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; session.clear();</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">&nbsp;&nbsp;&nbsp; }</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">}</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">&nbsp;&nbsp; <o:p></o:p></span></div><div class="MsoNormal"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">tx.commit();</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 14.15pt;"><span lang="RU" style="font-family: 'Courier New'; font-size: 10pt;">session.close();</span><span lang="RU"> <o:p></o:p></span></div><div class="MsoNormal"><b>Optimization for Large Data Sets <o:p></o:p></b></div><div class="MsoNormal"><br /> </div><div class="MsoNormal">Query query = session.createQuery(....);<o:p></o:p></div><div class="MsoNormal">query.setFirstResult(RowsPerPage);<o:p></o:p></div><div class="MsoNormal">query.setMaxResult(PageSize);<o:p></o:p></div><div class="MsoNormal" style="margin-left: .5in;"><br /> </div><div class="MsoNormal"><b>Lightweight Data Pattern : Fetch only what you need<o:p></o:p></b><br /> Scales for millions records.</div><div class="MsoNormal"><span lang="RU"><a href="http://community.jboss.org/wiki/LightweightClass">http://community.jboss.org/wiki/LightweightClass</a><o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><span class="MsoHyperlink"><b>Set Correct Transactional Boundary<o:p></o:p></b></span></div><div class="MsoNormal"><span class="MsoHyperlink">Set @Transactional (readOnly = true) to avoid unnecessary dirty-checking by Hibernate Engine.<o:p></o:p></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><span class="MsoHyperlink"><b>Use Hibernate Validator in Domain Model<o:p></o:p></b></span></div><div class="MsoNormal"><br /> </div><div class="MsoNormal"><b>Usage of Proper Caching Strategy<o:p></o:p></b></div><div class="MsoNormal"><br /> </div><div class="MsoNormal">Either use <cache usage="”read-write”"> or @Cache (usage=ConcurrencyStrategy.READ_WRITE)<o:p></o:p></cache></div><div class="MsoNormal">Refer to a properly configured cache region from query.<o:p></o:p></div><div class="MsoNormal">query.setCacheRegion(“query.OrderCache”);<o:p></o:p><br /> <br /> <br /> <b>Multi-Tenancy Support in Hibernate 4</b><br /> <a href="http://opensource.atlassian.com/projects/hibernate/browse/HHH-5697">http://opensource.atlassian.com/projects/hibernate/browse/HHH-5697</a></div></div></description>
<link>http://musings-on-technology.blogspot.com/2011/04/hibernate-known-facts-unknown-traps.html</link>
<author>noreply@blogger.com (Kaniska)</author>
<thr:total>0</thr:total>
</item>
<item>
<guid isPermaLink="false">tag:blogger.com,1999:blog-1373851816248476399.post-6060655797524953310</guid>
<pubDate>Mon, 18 Apr 2011 21:50:00 +0000</pubDate>
<atom:updated>2011-04-19T03:20:27.410+05:30</atom:updated>
<title>Fun with GWT and Google Fusion Table</title>
<description><div dir="ltr" style="text-align: left;" trbidi="on"><br /> <div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Google always strives to make things Simpler to develop and Easier to use !&nbsp;</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br /> </div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">GWT benefited tremendously from the advancement of App Engine !&nbsp;</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Its also blessed by SpringSource which directly integrates into APP Engine through the ground-breaking Spring ROO. So this means less steps to follow and less boiler-plate code to write! save time by avoiding infrastructure-setup&nbsp;</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br /> </div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">It was always simpler to create - say modular, reusable client-side cache, pagination table, model-ui binding API bypassing monolithic javascript libraries ! So easy it is to leverage Spring4GWT 'servlet'-less server side coding and leverage Hibernate-validation !&nbsp;</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br /> </div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Actually it saved months of work in couple of projects !&nbsp;</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br /> </div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">How about&nbsp;scalability&nbsp;and performance ? Its a good time to adopt Ext GWT !</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><a href="http://www.sencha.com/products/extgwt/examples/">http://www.sencha.com/products/extgwt/examples/</a>&nbsp;- lightning-fast traversal of millions of records !</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br /> </div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">How to architect high-performance gwt -&nbsp;<a href="http://www.youtube.com/watch?v=USlUYkBHiHA">http://www.youtube.com/watch?v=USlUYkBHiHA</a></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br /> </div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">GWT integrates with HTML5 -&nbsp;<a href="http://www.youtube.com/watch?v=omBURP0MxcI&amp;feature=relmfu">http://www.youtube.com/watch?v=omBURP0MxcI&amp;feature=relmfu</a></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br /> </div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Test the speed of GWT in Chrome - &nbsp;<a href="http://code.google.com/webtoolkit/speedtracer/">http://code.google.com/webtoolkit/speedtracer/</a></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br /> </div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Some of the links related to GWT.</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><a href="http://www.ajaxmatters.com/articles/gwt/rpc_remote_procedure_calls_example_p1.asp">http://www.ajaxmatters.com/articles/gwt/rpc_remote_procedure_calls_example_p1.asp</a>x&nbsp;</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><a href="http://marakana.com/forums/java/general/118.html">http://marakana.com/forums/java/general/118.html</a></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><a href="http://www.javacodegeeks.com/2010/05/gwt-2-spring-3-jpa-2-hibernate-35.html">http://www.javacodegeeks.com/2010/05/gwt-2-spring-3-jpa-2-hibernate-35.html</a></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br /> </div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">-------------------------------------------------------------------</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br /> </div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Well ! GWT is for Java Geeks ! &nbsp;How'bout common masses who just owns diverse set of data - ranging from &nbsp; &nbsp;- geographical info, traffic data, weather info, chemical properties, physics measurement data, population info - Hey we just want to visualize our data &nbsp;- we hardly care about building an App !!</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br /> </div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Here comes Google Fusion Table - it will load your data into Cloud (read Fusion Tables) and display/ report in Visualizer UI.&nbsp;</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br /> </div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Enjoy the ride -&nbsp;<a href="http://www.google.com/fusiontables/public/tour/index.html">http://www.google.com/fusiontables/public/tour/index.html</a></div></div></description>
<link>http://musings-on-technology.blogspot.com/2011/04/fun-with-gwt-and-google-fusion-table.html</link>
<author>noreply@blogger.com (Kaniska)</author>
<thr:total>0</thr:total>
</item>
<item>
<guid isPermaLink="false">tag:blogger.com,1999:blog-1373851816248476399.post-4373405763874058313</guid>
<pubDate>Sat, 16 Apr 2011 14:42:00 +0000</pubDate>
<atom:updated>2011-04-19T10:16:50.837+05:30</atom:updated>
<category domain="http://www.blogger.com/atom/ns#">Data Transformer</category>
<title>Best Practices for XML and POJO Binding</title>
<description><div dir="ltr" style="text-align: left;" trbidi="on"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span class="Apple-style-span" style="font-size: 13px; line-height: 15px;"></span></span><br /> <span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"></span><br /> <div style="font-style: normal; font-weight: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: black;"><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-size: x-small;">Here goes few basic guidelines to choose from different Data Binding Technologies :</span></span></span></span></div><div style="font-style: normal; font-weight: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="font-style: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: black;"><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-size: x-small;"><b>XMLBeans :</b></span></span></span></span></div><div style="line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: black;"><span style="font-size: x-small;"><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-style: normal;"><span style="font-weight: normal;">XMLBeans</span></span></span><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-style: normal;"><span style="font-weight: normal;"> is the best candidate - when </span><b>we just depend upon underlying XML for the actual data </b><span style="font-weight: normal;">and don't really need to manipulate the Java code or modify the xml. </span></span></span></span></span> </span></div><div style="font-style: normal; font-weight: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: black;"><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-size: x-small;">Say we just need to convert an WSDL into Java Code and then use the generated Java API for aaceesing WSDL Operations and Interfaces.</span></span></span></span></div><div style="font-style: normal; font-weight: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="font-style: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: black;"><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-size: x-small;">XMLBeans actually stores the entire set of parsed events that represent the document in memory. XMLBeans is <b>very fast for just reading and writing documents.</b> It is<b> really XML-Centric</b>.</span></span></span></span></div><div style="font-style: normal; font-weight: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: #222222;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;"><i>"XMLBeans is based on an efficient XML token stream, and it keeps underlying XML infoset intact. Since XMLBeans keeps the data in memory as XML, overhead of unmarshalling and marshalling is reduced.&nbsp;</i></span></span></span></span></div><div style="line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: #222222;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;"><i>To address varying data access and data transformation requirements, XMLBeans provides a flexibility of navigating through xml data using xPath or xQuery, and manipulating xml data using either xml cursor or XMLBeans generated classes."</i></span></span></span></span></div><div style="font-style: normal; font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="font-style: normal; font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: #222222;"><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-size: x-small;">XMLBeans performs poorly in terms of handling memory &nbsp;because it stores a live mapping of objects and underlying XML Document in memory.</span></span></span></span></div><div style="font-style: normal; font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="font-style: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: #222222;"><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-size: x-small;"><b>JiBX:</b></span></span></span></span></div><div style="font-style: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: #222222;"><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-size: x-small;">If we really want to manipulate <b>the way XML Data should be mapped to Java Objects</b>, JiBX scores high !</span></span></span></span></div><div style="font-style: normal; font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: #222222;"><span style="font-family: Verdana, sans-serif;"><span style="font-size: x-small;"><span style="font-family: arial, verdana, helvetica, sans-serif;">JiBX uses mapped bindings to automatically generate code and does not care much about the XML Schema Support. I</span><span style="font-family: arial, verdana, helvetica, sans-serif;"><b>t is </b></span><span style="color: black;"><span style="font-family: arial, sans-serif;"><b>a </b></span></span><span style="color: black;"><span style="font-family: arial, sans-serif;"><i><b>Java-centric</b></i></span></span><span style="color: black;"><span style="font-family: arial, sans-serif;"><b>&nbsp;approach to data binding</b></span></span><span style="color: black;"><span style="font-family: arial, sans-serif;">. It uses ByteCode enhancement to add XML generation and parsing support directly into the bytecode of Java Class. </span></span></span></span></span> </span></div><div style="font-style: normal; font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="font-style: normal; font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: #222222;"><span style="font-family: Verdana, sans-serif;"><span style="font-size: x-small;"><span style="color: black;"><span style="font-family: arial, verdana, helvetica, sans-serif;">"It does not tie the Java class to the structure of the XML document. Just because an element lives within another element in the document, does not imply that the data contained in the sub element must be an equivalent level down in the Java structure. This allows the deep XML structure (which makes sense in XML) to be mapped easily to a more shallow, but not necessarily flat, structure (which makes sense in the Java object model).</span></span><span style="font-family: arial, verdana, helvetica, sans-serif;">"</span></span></span></span></span></div><div style="font-style: normal; font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: #222222;"><span style="font-family: Verdana, sans-serif;"><span style="font-size: x-small;"><span style="font-family: arial, verdana, helvetica, sans-serif;">It uses fast </span><span style="color: black;"><span style="font-family: arial, verdana, helvetica, sans-serif;">Pull-Parser and has a very compact Runtime Distribution.</span></span></span></span></span></span></div><div style="font-style: normal; font-weight: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: black;"><span style="font-family: arial, sans-serif;"><span style="font-size: x-small;">JiBX isolates XML document formats from Java language object structures.</span></span></span></span></div><div style="font-style: normal; font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="font-style: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: #222222;"><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-size: x-small;"><b>JAXB:</b></span></span></span></span></div><div style="font-style: normal; font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: #222222;"><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-size: x-small;">JAXB generates code from Schema. Very much XML dependent, but still provides ways to manipulate mappings through annotations. Its easy to work but difficult to maintain and is not as elegant as XMLBeans or JiBX. To some extent its between Java-Centric JiBX and XML-Centric XMLBeans. </span></span></span> </span></div><div style="font-style: normal; font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: #222222;"><span style="font-family: Verdana, sans-serif;"><span style="font-size: x-small;"><i><span style="font-family: arial, verdana, helvetica, sans-serif; font-weight: normal;">" </span>JAXB among other things allows you to <b>customize binding through schema annotation</b> such that generated classes are more than just XML containers - they can represent objects with real behavior (and ability to be instantiated from XML)."</i></span></span></span></span></div><div style="font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="font-style: normal; font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: #222222;"><span style="font-family: Verdana, sans-serif;"><span style="font-size: x-small;">JAXB has issues with <span style="color: black;"><span style="font-family: arial, verdana, helvetica, sans-serif;">deeply nested (and large) xsds. It generates too many classes and for large xmls simply grow unmangeable. (</span></span>JAXB does not make any use of inner classes while generatiing code). </span></span></span> </span></div><div style="font-style: normal; font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="font-style: normal; font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: black;"><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-size: x-small;">JAXB generated classes can not parse xmls, whereas XMLBeans allow parsing underlying xml. (its more xml centric)</span></span></span></span></div><div style="font-style: normal; font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="font-style: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: black;"><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-size: x-small;"><b>EMF :</b></span></span></span></span></div><div style="font-style: normal; font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: black;"><span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;"><span style="font-family: arial, verdana, helvetica, sans-serif;">EMF produces an Ecore model given an XML Schema and then uses template-based generator technology to generate a rich Java API (of hand written quality).The XML Schema to Ecore conversion can be tailored, the templates used to generate the Java API can be tailored, and the resulting Java API can be tailored.The generator supports merging regeneration so that it will preserve your hand written changes.In other words, EMF is far richer and more flexible, and supports a broader subset of XML Schema.</span></span></span></span></span></div><div style="font-style: normal; font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="font-style: normal; font-weight: normal; line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: #222222;"><span style="font-family: Verdana, sans-serif;"><span style="font-size: x-small;"><b>XStream</b> - simplest to use</span></span></span></span></div><div style="line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: black;"><span style="font-family: helvetica, arial, sans-serif;"><span style="font-size: x-small;"><span style="font-style: normal;"><span style="font-weight: normal;">.&nbsp;</span></span></span></span></span><a href="http://www.extreme.indiana.edu/xgws/xsoap/xpp/mxp1/index.html"><span style="color: #006600;"><span style="font-family: helvetica, arial, sans-serif;"><span style="font-size: x-small;"><span style="font-style: normal;"><u><span style="font-weight: normal;">XPP3</span></u></span></span></span></span></a><span style="color: black;"><span style="font-family: helvetica, arial, sans-serif;"><span style="font-size: x-small;"><span style="font-style: normal;"><span style="font-weight: normal;">&nbsp;is a </span><b>very fast XML pull-parser implementation</b><span style="font-weight: normal;">. User is also free to choose any other parser like JAXP DOM inside XStream.</span></span></span></span></span></span></div><div style="line-height: 0.2in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="font-style: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: black;"><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-size: x-small;">XStream is designed fo<b>r configurationless serialization</b>. This makes it painless to serialize any type of objects, without the need for mappings. Ideal for things like persistence, configuration and over-the-wire transports. However, because there are no mappings, you have little control of how the serialized object is represented.</span></span></span></span></div><div style="line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: black;"><span style="font-size: x-small;"><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-style: normal;"><span style="font-weight: normal;">** solution :&nbsp;</span></span></span><span style="font-family: arial, sans-serif;"><span style="font-style: normal;"><span style="font-weight: normal;">&nbsp;</span></span></span><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-style: normal;"><span style="font-weight: normal;">using XStream this way to process SOAP messages based on complex XML schemas. So XSLT acts as your mapping definition&nbsp;and it is much more powerful than plain declarative "binding" mappings, since it is a full-blown templating language.</span></span></span></span></span></span></div><div style="font-style: normal; font-weight: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="font-style: normal; font-weight: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: black;"><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-size: x-small;">** custom converters are powerful</span></span></span></span></div><div style="font-style: normal; font-weight: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: black;"><span style="font-family: 'Times New Roman';"><span style="font-size: x-small;"><span style="font-family: arial, verdana, helvetica, sans-serif;">**&nbsp;</span><span style="color: #40348c;"><span style="font-family: tahoma, arial, sans-serif;"><b>XStream: how to serialize objects to non XML formats</b></span></span></span></span></span></span></div><div style="font-style: normal; font-weight: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="font-style: normal; font-weight: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: black;"><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-size: x-small;">Xstream can marshal to / unmarshal from not just xml but also json, tree structure etc.</span></span></span></span></div><pre class="western" style="font-style: normal; font-weight: normal; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: black;"><span style="font-family: arial, sans-serif;"><span style="font-size: x-small;">The modular design allows other output formats. XStream ships currently with JSON support and morphing.</span></span></span></span></pre><div style="font-style: normal; font-weight: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><span style="color: black;"><span style="font-size: x-small;"><span style="font-family: arial, sans-serif;"><span style="font-style: normal;"><span style="font-weight: normal;">So the bottomline - </span></span></span><span style="font-family: arial, verdana, helvetica, sans-serif;"><span style="font-style: normal;"><span style="font-weight: normal;">If you need precise control of how your objects are represented and are happy to spend time defining mappings, use JiBX. Otherwise stick to Xstream.</span></span></span></span></span></span></div><div style="font-style: normal; font-weight: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="font-style: normal; font-weight: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="font-style: normal; font-weight: normal; line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"><br /> </span></div><div style="line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;">Reference : <a href="http://www.ibm.com/developerworks/library/x-databd4/"><span style="color: black;"><span style="font-family: 'Times New Roman';"><span style="font-size: x-small;"><span style="font-style: normal;"><span style="font-weight: normal;">http://www.ibm.com/developerworks/library/x-databd4/</span></span></span></span></span></a></span></div><div style="line-height: 0.16in; margin-bottom: 0in; orphans: 2; widows: 2;"></div></div></description>
<link>http://musings-on-technology.blogspot.com/2011/04/best-practices-for-xml-and-pojo-binding.html</link>
<author>noreply@blogger.com (Kaniska)</author>
<thr:total>0</thr:total>
</item>
<item>
<guid isPermaLink="false">tag:blogger.com,1999:blog-1373851816248476399.post-601234621184867802</guid>
<pubDate>Sat, 09 Apr 2011 17:44:00 +0000</pubDate>
<atom:updated>2011-04-09T23:14:14.149+05:30</atom:updated>
<title>Oreilly Instant Writable API Competition</title>
<description><div dir="ltr" style="text-align: left;" trbidi="on">Planning to get my feet wet with fluidinfo ... Starting off with a simple JavaFX App.<br /> <br /> More Details .. &nbsp;&nbsp;<a href="http://radar.oreilly.com/2011/03/api-competition.html">http://radar.oreilly.com/2011/03/api-competition.html</a><br /> <br /> </div></description>
<link>http://musings-on-technology.blogspot.com/2011/04/oreilly-instant-writable-api.html</link>
<author>noreply@blogger.com (Kaniska)</author>
<thr:total>0</thr:total>
</item>
<item>
<guid isPermaLink="false">tag:blogger.com,1999:blog-1373851816248476399.post-8489964230347544815</guid>
<pubDate>Tue, 17 Aug 2010 06:39:00 +0000</pubDate>
<atom:updated>2011-04-19T02:38:39.106+05:30</atom:updated>
<category domain="http://www.blogger.com/atom/ns#">Eclipse</category>
<category domain="http://www.blogger.com/atom/ns#">Performance Monitoring</category>
<category domain="http://www.blogger.com/atom/ns#">Productivity Tools</category>
<title>Eclipse Apps Performance Tips</title>
<description><div dir="ltr" style="text-align: left;" trbidi="on"><div style="margin-bottom: 0in;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">Lets explore some of the tricks to monitor and improve performance of apps running in Eclipse and also how we can write better API.</span></div><div style="margin-bottom: 0in;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /> </span></div><div style="margin-bottom: 0in;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">1. <b>VisualVM </b>is a great tool to monitor the performance of any eclipse application.&nbsp;Once the plugin is installed, any eclipse app can be launched in the VisualVM Runtime instead of a Java Runtime so that the health of the app can be monitored in real-time.</span></div><div style="margin-bottom: 0in;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">Reference : &nbsp;<a href="https://visualvm.dev.java.net/eclipse-launcher.html">https://visualvm.dev.java.net/eclipse-launcher.html</a></span></div><div style="margin-bottom: 0in;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /> </span></div><div style="margin-bottom: 0in;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">2. If we enable "<b>Show Heap Status</b>" under 'General Preferences', we can periodically <b>enforce GC</b>, which is very important for heap analysis.</span></div><div style="margin-bottom: 0in;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /> </span></div><div style="margin-bottom: 0in;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">3. Now we can really <b>enable in-depth monitoring</b> by turning on <b>Runtime Spy</b> through an&nbsp;.options file e.g.&nbsp;<b>eclipse -debug c:\spy\.options</b></span></div><div style="margin-bottom: 0in;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">Here is the&nbsp;Update site for core tools</span></div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">platform-core - <a href="http://eclipse.org/eclipse/platform-core/updates">http://eclipse.org/eclipse/platform-core/updates</a></span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">References :</span><br /> <a href="http://www.jdg2e.com/ch32.performance/doc/index.html#refs"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">http://www.jdg2e.com/ch32.performance/doc/index.html#refs</span></a><br /> <a href="http://books.google.com/books?id=vxMDuxmSKTsC&amp;pg=PA760&amp;lpg=PA760&amp;dq=Window+%3E+Open+Perspective+%3E+Runtime+Spy&amp;source=bl&amp;ots=KOdIlfzjyi&amp;sig=36CBytt1iqHZFv-G3Q1YlCbFMPc&amp;hl=en&amp;ei=uh7OS4bFG4-QsgOpoaivDg&amp;sa=X&amp;oi=book_result&amp;ct=result&amp;resnum=4&amp;ved=0CBIQ6AEwAw#v=onepage&amp;q=Window%20%3E%20Open%20Perspective%20%3E%20Runtime%20Spy&amp;f=false"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">Google Book</span></a><br /> <a href="http://www.eclipse.org/eclipse/platform-core/downloads/tools/readme.html"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">http://www.eclipse.org/eclipse/platform-core/downloads/tools/readme.html</span></a><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">Sample settings of the&nbsp;Runtime Spy&nbsp;.options file</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">#### Monitoring settings</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"># monitor class loading</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">org.eclipse.osgi/monitor/classes=true</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"># monitor bundle activation</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">org.eclipse.osgi/monitor/activation=true</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"># monitor resource bundle (*.properties) loading</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">org.eclipse.osgi/monitor/resources=true</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">#### Trace settings</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"># trace class loading - snapshot the execution stack when a class is loaded</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">org.eclipse.osgi/trace/classLoading=true</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"># trace location - file in which execution traces are written</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">org.eclipse.osgi/trace/filename=runtime.traces</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"># trace filters - Java properties file defining which classes should</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"># be traced (if trace/classLoading is true)</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">etc........</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">4. Well even after enabling all types of monitoring, we still sometimes can not find out why certain apps leads to OutOfMemory Error ! </span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">Then the only way out is to generate the Heap Dumps and Thread Dumps.</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">We can add this vmarg in eclipse.ini -</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><b>-Xdump:java+heap+system:events=user,opts=CLASSIC+PHD </b>so that whenever SendSignal <pid> is executed&nbsp;corresponding&nbsp;dumps will be generated.</pid></span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">Otherwise we can <b>start eclipse in command prompt </b>as follows and then do Ctrl+break to signal the vm.</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">eclipse -vm <sun_jre>\bin\java.exe -console <b>-consoleLog</b> -vmargs <b>-verbose:class</b> <b>-verbose:dynload </b>-Xms1024m -Xmx1536m -XX:MaxPermSize=128m -Xdump:heap+java:events=user,opts=CLASSIC+PHD -Xgcpolicy:optavgpaus.</sun_jre></span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">Another way to send stop signal to vm - c<span class="Apple-style-span" style="color: #1f497d;">db -p <pid> -c ".dump /ma java.dmp;q" -&nbsp;</pid></span><span class="Apple-style-span" style="color: #1f497d;">Where&nbsp;</span><span class="Apple-style-span" style="color: #1f497d;"><pid> is the integer process Id of the java process.</pid></span></span><br /> <span class="Apple-style-span" style="color: #1f497d; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">5. <span class="Apple-style-span" style="color: #1f497d;">&nbsp;</span>Time to highlight the importance of <b>designing API </b>and <b>SPI </b>using eclipse codebase.&nbsp;</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">&nbsp;&nbsp; &nbsp; This is an invaluable source of knowledge about evolving Eclipse API and proper usage of&nbsp;annotations&nbsp;like&nbsp;</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">&nbsp;&nbsp; &nbsp; @noimplement, @noextend etc.</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">Its a classic :&nbsp;<a href="http://www.eclipse.org/eclipse/development/java-api-evolution.html">http://www.eclipse.org/eclipse/development/java-api-evolution.html</a></span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">6. In order to <b>enforce API Analysis </b>we should refer to -&nbsp;<a href="http://www.eclipse-tips.com/tutorials/26-api-tooling-tutorial">http://www.eclipse-tips.com/tutorials/26-api-tooling-tutorial</a>. After all Eclipse is meant for coding clean interfaces and abstract classes that communicates to users through simple annotations and robust patterns.</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">7. Its not a bad idea to enforce internationalization – using the setting - <span style="color: black;"><span style="font-style: normal;"><b>org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=error</b><span style="font-weight: normal;"> in .settings file.</span></span></span></span><br /> <span style="color: black;"><span style="font-style: normal;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-weight: normal;"><br /> </span></span></span><br /> <span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-style: normal;"><b>Fixing Int issues at the early stage</b><span style="font-weight: normal;"> prevents from wasting a good amount of time and&nbsp;introducing&nbsp;unsolicited bugs at the time of product delivery phase.</span></span></span><br /> <span style="color: black;"><span style="font-style: normal;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-weight: normal;"><br /> </span></span></span><br /> <span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-style: normal;"><span style="font-weight: normal;">8. we should </span><b>flag 'unused imports' as errors</b><span style="font-weight: normal;"> in preference to make it a daily habit getting rid of unnecessary evils.</span></span></span><br /> <span style="color: black;"><span style="font-style: normal;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-weight: normal;"><br /> </span></span></span><br /> <span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-style: normal;"><span style="font-weight: normal;">9. </span><b>Templating try / catch to actually catch and log an exception</b><span style="font-weight: normal;"> is a MUST ! Eclipse should fix this by default providing a exception.printStackTrace() statement. Empty catch blocks are silent killers that remain hidden inside deeply nested api !</span></span></span><br /> <span style="color: black;"><span style="font-style: normal;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-weight: normal;"><br /> </span></span></span><br /> <span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-style: normal;"></span></span><br /> <div align="LEFT" style="margin-bottom: 0in;"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-style: normal;"><span style="color: black;">10.<b> Remote Debugging Options :</b></span></span></span></div></div><div align="LEFT" style="font-weight: normal; margin-bottom: 0in;"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-style: normal;"><span style="color: #333333;"><span style="font-style: normal;"><span style="font-weight: normal;">-vmargs<br /> -Xdebug<br /> -Xnoagent<br /> -Djava.compiler=NONE<br /> -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9000</span></span></span></span></span></div></div><div align="LEFT" style="font-weight: normal; margin-bottom: 0in;"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-style: normal;"><br /> </span></span></div></div><div align="LEFT" style="margin-bottom: 0in;"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-style: normal;"><span style="color: black; font-weight: normal;">11.&nbsp;</span><b>How to enforce annotations for api ?</b></span></span></div></div><div align="LEFT" style="font-weight: normal; margin-bottom: 0in;"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-style: normal;"><span style="color: black;"><span style="color: #333333;"><span style="font-style: normal;"><span style="font-weight: normal;"><a href="http://www.eclipse-tips.com/tutorials/26-api-tooling-tutoria">http://www.eclipse-tips.com/tutorials/26-api-tooling-tutoria</a>l<br /> -- &nbsp;enforce usage of @since, @noimplement annotations</span></span></span></span></span></span></div></div><div align="LEFT" style="font-weight: normal; margin-bottom: 0in;"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-style: normal;"><br /> </span></span></div></div><div align="LEFT" style="margin-bottom: 0in;"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-style: normal;"><span style="color: black;">12. <b>How to view OSGi dependency and search plugin dependency ?</b></span></span></span></div></div><div align="LEFT" style="font-weight: normal;"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-style: normal;"><span style="color: black;"><span style="font-style: normal;"><span style="font-weight: normal;">STS -&nbsp;<a href="http://blog.springsource.com/2009/03/05/osgi-development-tools-in-sts/">http://blog.springsource.com/2009/03/05/osgi-development-tools-in-sts/</a></span></span></span></span></span></div></div><div style="font-weight: normal; margin-bottom: 0in; orphans: 2; widows: 2;"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-style: normal;"><a href="http://blog.springsource.com/wp-content/uploads/2009/03/dependency-graph.png"><span style="color: black;"><span style="font-style: normal;"><span style="font-weight: normal;">http://blog.springsource.com/wp-content/uploads/2009/03/dependency-graph.png</span></span></span></a></span></span></div></div><br /> <span style="color: black;"><span style="font-style: normal;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-weight: normal;"><br /> </span></span></span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span style="color: black;"><span style="font-style: normal;"><span style="font-weight: normal;">13.&nbsp;</span></span></span>The last but not the least <b>FindBug (</b><a href="http://findbugs.cs.umd.edu/eclipse">http://findbugs.cs.umd.edu/eclipse</a>)&nbsp;should be part of development environment and be actively used.</span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /> </span><br /> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-style-span">Well ... a bonus tip for hackers :-) ... don't forget the <b>decompiler </b>plugin -</span><b>http://java.decompiler.free.fr/jd-eclipse/update-&nbsp;</b><span class="Apple-style-span">&nbsp;using which you can even debug any class that essentially do not have source base shipped with its tool !&nbsp;</span><b>&nbsp;</b></span><br /> <div align="LEFT" style="font-style: normal; font-weight: normal; margin-bottom: 0in; orphans: 2; widows: 2;"><span class="Apple-style-span" style="color: #1f497d; font-family: Arial, sans-serif;"><span class="Apple-style-span" style="font-size: small;"><br /> </span></span></div></div></description>
<link>http://musings-on-technology.blogspot.com/2010/08/eclipse-apps-performance-tips.html</link>
<author>noreply@blogger.com (Kaniska)</author>
<thr:total>1</thr:total>
</item>
<item>
<guid isPermaLink="false">tag:blogger.com,1999:blog-1373851816248476399.post-7400735685438394502</guid>
<pubDate>Fri, 14 May 2010 20:52:00 +0000</pubDate>
<atom:updated>2010-05-16T23:40:46.844+05:30</atom:updated>
<category domain="http://www.blogger.com/atom/ns#">Eclipse Modelling 3D EMF ZEST GEF</category>
<title>The Wonderland of Modelling</title>
<description>Its a true pleasure to witness the evolution of <b>Modelling API</b> of Eclipse.<br /> <br /> Joshua M. Epstein reflected on the <a href="http://jasss.soc.surrey.ac.uk/11/4/12.html">importance of modelling</a><br /> <br /> <b>The basics:</b><br /> Joshua M. Epstein ... <br /> <blockquote>We're all modelers, but most of our models are implicit, not explicit. <br /> Sometimes we model either to predict or to explain<br /> And there are at least 15 other <b>good reasons to build explicit models . .</b> . <br /> <br /> <blockquote>1.Explain (very distinct from predict) <br /> 2.Guide data collection <br /> 3.Illuminate core dynamics <br /> 4.Suggest dynamical analogies <br /> 5.Discover new questions <br /> 6.Promote a scientific habit of mind <br /> 7.Bound (bracket) outcomes to plausible ranges <br /> 8.Illuminate core uncertainties. <br /> 9.Offer crisis options in near-real time <br /> 10.Demonstrate tradeoffs / suggest efficiencies <br /> 11.Challenge the robustness of prevailing theory through perturbations <br /> 12.Expose prevailing wisdom as incompatible with available data <br /> 13.Train practitioners <br /> 14.Discipline the policy dialogue <br /> 15.Educate the general public <br /> 16.Reveal the apparently simple (complex) to be complex (simple) </blockquote></blockquote><br /> Its just not the fact that Eclipse Modelling has acquired a very <b>high-end Graphical Capabilities</b> with the advancement of GMF and <b>performance boost with CDO</b>; but also the mammoth extensibility and convertibility of EMF from almost any proprietary / domain-specific model into any platform-specific implementation by leveraging model transformation technologies.<br /> <br /> We know that how any type of meta-model / model (UML, Annotated POJO, XSD, WSDL, DB Schema, PRR, PMML, Ontology etc.) can be seamlessly converted into EMF and then be represented into GMF and finally persisted into platform-specific models by applying platform-specific (Finance/telecom/Health etc.) profiles. Here is one post -<br /> <a href="http://musings-on-technology.blogspot.com/2008/06/graphical-model-transformation.html"><b>Graphical Model Transformation</b></a><br /> <br /> M2M (XPand) and TMF (XText) simplified backward compatibilities of models and popularized the usabilities amongst non-modellers who can focus on specific entities of a system.<br /> <br /> Modelling takes a giant step forward with '<a href="http://eclipse.org/amp/">AMP</a>' - <b>Agent Modelling Platform</b>.<br /> <br /> This is what is mentioned in - 'http://www.eclipse.org/proposals/amp/' <br /> :: <br /> <blockquote>Agent-Based Modeling (ABM), an innovative technique used to explore complex phenomenon in many domains, including economics, social sciences, bio-medicine, ecology and business operations.</blockquote><br /> The starting point is the Agent Meta-model Ecore ('ACore') for modelling the Agents.<br /> <blockquote>Agent models share characteristics with object models, but are: <br /> <br /> <b>Spatial</b>: Models have explicit environment(s) in which agents interact. (An environment need not be a physical landscape; other examples of spatial relationships include social networks or positions within a logic system.)<br /> <b>Temporal</b>: Models change over discrete units of time.<br /> <b>Autonomous</b>: Agent behaviors are activated independently from other object requests.<br /> <b>Heterogenous</b>: Agents may share behavior definitions but have apparent and distinct states and behaviors.<br /> <b>Collective</b>: Models contain large communities of agents which exhibit collaborative and competitive behaviors.<br /> <b>Emergent</b>: Agents have collective macro-behaviors that are non-obvious from agent micro-specifications.</blockquote><br /> Agent Model can be of great help where interconnected systems knowingly / unknowingly contribute to the unpredictable behaviour of real-life entities. What could be a better usecase than <a href="http://www.youtube.com/watch?v=lYp7Pq44CNM&amp;feature=related">simulating the behaviour of H1N1 virus</a> <br /> <br /> :: <b>AMP</b> can be used as a independent module in Eclipse and simply use its services (say Agent Graphical Fwk - AGF) for performing business rules, resoning tasks and dynamic visualization support.<br /> <br /> :: <b>AXF</b> - Agent Execution Framework can also be very useful even in contexts outside agents. One can simple adapt to the IEngine service of AXF to leverage the scheduling service provided by the Agent Model Engine and many other features.<br /> <br /> If we want to get your feet wet with this amazing modelling tool - here is how you can <a href="http://eclipse.org/amp/developers/building.php"> Setup AMP Environment</a><br /> <br /> Stay tuned to - http://wiki.eclipse.org/AMP/UserGuide/<br /> <br /> One can delve into the <a href="http://www.youtube.com/watch?v=abPguU0QVqw">Technical Details </a> and understand AMP architecture.<br /> <br /> Its interesting to browse through Lyle Wallis's <a href="http://blog.cause-alities.com/">observations</a> on applying systems science to business, social, and natural systems using Agent Based Modelling.<br /> <br /> Specially, its an absorbing read on <a href="http://hbr.org/2007/11/a-leaders-framework-for-decision-making/ar/1">complex systems</a>.<br /> <br /> Lyle Wallis comments - <br /> <blockquote>So I was excited to see this article in the Harvard Business Review. The authors ... ".. believe the time has come to broaden the traditional approach to leadership and decision making and form a new perspective based on complexity science." <br /> ... we can take effective management action in complex systems and create a surprising level of predictability.</blockquote><br /> Lets now look back into Eclipse modelling itself. One can now create a dynamic graph layout with moveable nodes using <a href="http://www.vogella.de/articles/EclipseZest/article.html">Zest</a><br /> <br /> <b>Reference </b>:<br /> <br /> Eclipse Zest Resources<br /> http://www.eclipse.org/gef/zest/ Eclipse Zest Homepage <br /> http://wiki.eclipse.org/index.php/GEF_Zest_Visualization Eclipse Zest Wiki <br /> http://www.eclipse.org/gef/zest/snippets.php Eclipse Zest Snippets <br /> <a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.gef/test/org.eclipse.zest.tests/src/org/eclipse/zest/tests/swt/AnimationSnippet.java?root=Tools_Project&amp;view=co">Animation using Zest</a><br /> <br /> GEF<br /> http://wiki.eclipse.org/GEF_Description2#Global_principle<br /> http://wiki.eclipse.org/GEF_Troubleshooting_Guide<br /> http://www.eclipse.org/gef/reference/digraph1.php<br /> <br /> AMP<br /> http://www.eclipse.org/amp/<br /> http://www.eclipse.org/amp/documentation/amp.pdf<br /> <br /> Modelling Article<br /> <a href="http://jasss.soc.surrey.ac.uk/11/4/12.html">Why Modelling</a><br /> <br /> All 'Agent' related terminologies @copyright - http://www.eclipse.org/amp/</description>
<link>http://musings-on-technology.blogspot.com/2010/05/wonderland-of-modelling.html</link>
<author>noreply@blogger.com (Kaniska)</author>
<thr:total>0</thr:total>
</item>
<item>
<guid isPermaLink="false">tag:blogger.com,1999:blog-1373851816248476399.post-8297854546180359018</guid>
<pubDate>Thu, 06 May 2010 21:26:00 +0000</pubDate>
<atom:updated>2010-06-24T03:38:46.763+05:30</atom:updated>
<category domain="http://www.blogger.com/atom/ns#">Eclipse</category>
<title>Making Applications work together in Eclipse</title>
<description>Eclipse as we know is a great implementation of plugin-architecture.<br /> <br /> We decouple different components of a system into bundles.<br /> plugin-architecture is very simplistic in nature, highly extensible and modular at the cost of a tricky class-loading policy.<br /> Actually Eclipse is a story of several class-loaders.<br /> It iniataites a chain of class loaders to load the plug-ins lazily as specified in component-specific manifest.mf files. <br /> If we understand its class-loading policy and learn some tricks, then we can make different third-party jars talk to each other and avoid infamous 'ClassNotFound Exception'.<br /> The immediate parent of a plug-in class loader is the Eclipse Boot Class Loader (providing access to boot.jar). The parent is the standard java system class loader which terminates the chain. The Application Class-loader which loads classes from the system's CLASSPATH is not part of the chain.<br /> That's why while loading product components, Eclipse does not look into Classpath in contrast to any other java-based client applications.<br /> On start-up, the eclipse platform builds a shadow of all the plugins by reading all the manifest files into a plug-in registry.<br /> Whenever a plugin com.xyz.myProduct is started by Eclipse Application Class, <br /> the class-loader for com.xyz.myProduct takes-off. <br /> If com.myProduct.xyz tries to access any class from another plugin com.myProduct.abc, <br /> Eclipse invokes the Plug-in Class-loader coresponding to com.myProduct.abc.<br /> That's the essence of Eclipse OSGi.<br /> <br /> Q1. How to use third-party applications while building and running my product ?<br /> Its of no use to specify third-party jars in classpath.<br /> While building the application com.myProduct, we should bundle all the required jars in a single plugin (com.myProduct.library) and expose the apis of the bundled log4j, jpox, xstream etc.<br /> <br /> Q2. How a third-party jar (log4j.jar) can see the classes from com.myProduct.xyz.jar during runtime ?<br /> Lets assume com.abc.myProduct plugin logs messages using log4j.<br /> So during runtime, log4j needs to see the classes from com.myProduct.abc plugin<br /> This can be achieved by registering log4j with Eclipse-Buddy Policy and specifying com.abc.myProduct as a buddy of log4j. <br /> # log4j Manifest.MF<br /> Bundle-Name: org.apache.log4j<br /> Bundle-Version: 1.2.13<br /> ...<br /> Eclipse-BuddyPolicy: registered<br /> <br /> # myplugin Manifest.MF<br /> Bundle-Name: com.abc.myProduct<br /> Bundle-Version: 1.0.0<br /> Requires-Bundle: org.apache.log4j,...<br /> Eclipse-RegisterBuddy: org.apache.log4j<br /> If anyone registers with log4j as its buddy, and log4j needs to find a class com.abc.myProduct.MyComponent then it will check all the buddies before throwing "ClassNotFound" Exception<br /> <br /> Q3. How can users integrate third-party jars with myProduct plugins on-the-fly ?<br /> Lets see how users can actually hack eclipse configuration files to integrate required jars on-the-fly.<br /> &gt;&gt; say user has installed a plugin com.magicScript which allows him to program using any script including jruby. But the product plugin doesn't ship the jruby jars i.e. does not adopt any of the above mechanisms.<br /> So user have to add JRUBY_MOME in eclipse.ini. Now when eclipse will start up it will set jruby home in the path.<br /> Lets assume the com.magicScript plugin already depends on a plugin com.magicScript.library containing a lib folder.<br /> Next the jruby.jar needs to be placed inside the lib folder and the location lib\jruby.jar needs to be specified in the manifest.mf of com.magicScript.library.<br /> Finally, starting eclipse with -clean -Intialization option will automatically first set Jruby path and then invoking magicScript perspective will trigger the classLoader for the bundle com.magicScript.library which in turn will load jruby classes from the jar (as specified in manifest.mf).<br /> Thus user will be able to code/compile/run jruby.<br /> This same trick can be used if we want the user to dynamically specify a DB driver jar and connect to a db using a plugin already installed in his environment.<br /> Say com.myProduct.dbExplorer plugin will load classes from the jar to be specified by users during runtime.<br /> (4) So far we depend only on Eclipse Bundle-ClassLoader and we configure eclipse in such a way (either development-time / runtime) that all required jars will be loaded by the classloader of the bundle in which jars are packed.<br /> But what if we need to access a class which can not be loaded by the bundle-classloader ?<br /> We need to set certain jars in custom classloader so the classes bundled in the jar can be loaded on demand !<br /> <br /> A typical scenario is com.xyz.MyProduct.library contains scriptDebugger.jar (some 3rdparty jar) whose api need to be invoked during runtime and the api class will access some class of jruby.jar (may be specified by user during runtime) which can't be packed inside the product.<br /> //The follwoing piece-of-code should be part of the com.xyz.myProduct.ScriptManager to load classes from jruby jar that user will specify during runtime.<br /> // gather the names and loacation of jars as provided by user through preference page after product is deployed.<br /> String[] jarslist = DynamicJarLoader.getThirdPartyJars();<br /> URL[] jarURLs = new URL[jarslist.length];<br /> JarFileLoader newLoader = new JarFileLoader(jarURLs);<br /> for (int i = 0; i &lt; jarslist.length; i++) {<br /> newLoader.addFile (jarslist[i]); <br /> }<br /> class JarFileLoader extends URLClassLoader<br /> {<br /> public JarFileLoader (URL[] urls)<br /> {<br /> super (urls);<br /> }<br /> <br /> public void addFile (String path) throws MalformedURLException<br /> {<br /> String urlPath = "jar:file://" + path + "!/";<br /> addURL (new URL (urlPath));<br /> }<br /> }<br /> Now swap bundleclassloader with your classloader !<br /> ClassLoader currentLoader = Thread.currentThread().getContextClassLoader();<br /> try {<br /> current.setContextClassLoader( newLoader);<br /> // Either Load reqd. classes and work with them<br /> newLoader.loadClass ("org.jruby.JRubyClient");<br /> newLoader.loadClass ("org.hsqldb.jdbcDriver");<br /> newLoader.loadClass("oracle.jdbc.driver.OracleDriver");<br /> // Or invoke some other api (of scriptRunner.jar which will load JRuby classes to compile/run jruby script) <br /> }catch(Exception exception) {<br /> exception.printStackTrace();<br /> }finally { // Restore Eclipse Bundle Class-loader<br /> current.setContextClassLoader(oldLoader);<br /> }<br /> further reading : http://www.eclipsezone.com/articles/eclipse-vms/</description>
<link>http://musings-on-technology.blogspot.com/2010/05/making-applications-work-together-in.html</link>
<author>noreply@blogger.com (Kaniska)</author>
<thr:total>0</thr:total>
</item>
</channel>
</rss>