<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>~pperalta &#187; Coherence</title>
	<atom:link href="https://blackbeanbag.net/wp/category/coherence/feed/" rel="self" type="application/rss+xml" />
	<link>https://blackbeanbag.net/wp</link>
	<description>Thoughts on software development and other stuff</description>
	<lastBuildDate>Thu, 22 May 2014 18:55:26 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=3.9.40</generator>
	<item>
		<title>The Live Object Pattern &#8211; Coming to a SIG Near You</title>
		<link>https://blackbeanbag.net/wp/2011/10/20/the-live-object-pattern-coming-to-a-sig-near-you/</link>
		<comments>https://blackbeanbag.net/wp/2011/10/20/the-live-object-pattern-coming-to-a-sig-near-you/#comments</comments>
		<pubDate>Fri, 21 Oct 2011 02:27:25 +0000</pubDate>
		<dc:creator><![CDATA[Patrick Peralta]]></dc:creator>
				<category><![CDATA[Coherence]]></category>

		<guid isPermaLink="false">http://blackbeanbag.net/wp/?p=519</guid>
		<description><![CDATA[In spite of this blog being dormant for over a year, things have been busier than ever over in Coherence land! We just released version 3.7.1 which is packed with new features. Some of the highlights: REST support in the proxy. In addition to Java, C# and C++, now you can access the grid with [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-521" style="margin-left: 5px; margin-right: 5px;" title="Live Objects" src="http://blackbeanbag.net/wp/wp-content/uploads/2011/10/liveobject.jpg" alt="" width="199" height="132" />In spite of this blog being dormant for over a year, things have been busier than ever over in Coherence land! We just released version 3.7.1 which is packed with new features. Some of the highlights:</p>
<ul>
<li>REST support in the proxy. In addition to Java, C# and C++, now you can access the grid with any language that has a REST API.</li>
<li>POF enhancements, including annotations and the ability to eliminate Java key classes (for pure C# and C++ applications)</li>
<li>Query Explain Plan. If you&#8217;ve ever had a problem with a production application missing indexes (because you won&#8217;t notice it in development and you may not notice it during testing) you&#8217;ll be interested in this feature. It analyzes queries (filter based or CohQL) and indicates where indexes are used (and not used.)</li>
</ul>
<p>We&#8217;ve been adding screencasts to the <a href="http://www.youtube.com/user/OracleCoherence">Coherence YouTube channel</a> going over these features &#8211; in most cases the screencasts are delivered by the architect/developer responsible for the feature.</p>
<p>We also just wrapped up JavaOne and Oracle Open World a few weeks ago. I had the privilege of co-presenting the Live Object Pattern with <a href="http://brianoliver.wordpress.com/">Brian Oliver</a>. The <a href="https://oracleus.wingateweb.com/scheduler/modifySession.do?SESSION_ID=25144">description</a> and <a href="https://oracleus.wingateweb.com/published/oracleus2011/sessions/25144/25144_Cho2550380.pdf">PDF</a> can be downloaded from the JavaOne site.</p>
<p>If you didn&#8217;t get to see the talk, you&#8217;re in luck if you&#8217;re in New York or London. Noah Arliss, who worked with Brian on the Live Objects concept and the abstract of the JavaOne talk, will be presenting on this topic at the <a href="http://coherence.oracle.com/display/CSIG/28+Oct+2011+-+New+York%2C+NY">New York SIG</a> on October 28th and the <a href="http://coherence.oracle.com/display/CSIG/4+November+2011+-+London%2C+UK">London SIG</a> on November 4th.</p>
<p>All of the SIGs this fall (including the <a href="http://coherence.oracle.com/display/CSIG/3+Nov+2011+-+Redwood+Shores%2C+CA">Bay Area SIG</a> on November 3rd) will cover the new features in Coherence 3.7.1. Come out and join us!</p>
]]></content:encoded>
			<wfw:commentRss>https://blackbeanbag.net/wp/2011/10/20/the-live-object-pattern-coming-to-a-sig-near-you/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oracle Enterprise Pack for Eclipse now supports Coherence</title>
		<link>https://blackbeanbag.net/wp/2010/08/09/oracle-enterprise-pack-for-eclipse-now-supports-coherence/</link>
		<comments>https://blackbeanbag.net/wp/2010/08/09/oracle-enterprise-pack-for-eclipse-now-supports-coherence/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 17:05:39 +0000</pubDate>
		<dc:creator><![CDATA[Patrick Peralta]]></dc:creator>
				<category><![CDATA[Coherence]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://blackbeanbag.net/wp/?p=479</guid>
		<description><![CDATA[The latest release of Oracle Enterprise Pack for Eclipse (OEPE) now includes a Coherence Facet. This makes it convenient to quickly start up a Coherence project and launch nodes right in the IDE. Recently I took it for a test drive and took some notes to help users of Eclipse and Coherence get started. Note [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>The latest release of <a href="http://www.oracle.com/us/products/tools/enterprise-eclipse-pack-161756.html">Oracle Enterprise Pack for Eclipse (OEPE)</a> now includes a Coherence Facet. This makes it convenient to quickly start up a Coherence project and launch nodes right in the IDE. Recently I took it for a test drive and took some notes to help users of Eclipse and Coherence get started.</p>
<p><em>Note that all images below are thumbnails; click on the images to expand.</em></p>
<p>You have the option of downloading <a href="http://www.oracle.com/technetwork/developer-tools/eclipse/downloads/oepe-1116-161753.html">Eclipse with the OEPE plugins pre-installed</a>, but I already had a copy of Eclipse Helios 3.6; therefore I went for the plugin install. The plugin install is straight forward, similar to any other Eclipse plugin. These instructions are lifted <a href="http://download.oracle.com/docs/cd/E15315_06/help/oracle.eclipse.tools.common.doc/html/install.html">straight from the doc</a>:</p>
<ol>
<li>Select Help &gt; Install New Software.</li>
<li>Click Add to add a new update site.</li>
<li>In the Add Repository dialog, enter the location as http://download.oracle.com/otn_software/oepe/helios, and then click OK.</li>
<li>Select Oracle Enterprise Pack for Eclipse, verify that all of the subcomponents are selected, and then click Next.</li>
<li>Confirm information presented in the Install Details, and then click Finish.</li>
</ol>
<p><a href="http://blackbeanbag.net/wp/wp-content/uploads/2010/08/1.png"><img class="alignnone size-medium wp-image-481" style="border-style: initial; border-color: initial; border-width: 0px;" title="1" src="http://blackbeanbag.net/wp/wp-content/uploads/2010/08/1-300x263.png" alt="" width="300" height="263" /></a><br />
Once the install is complete and you&#8217;ve restarted Eclipse, the next step is to install Coherence as a User Library. I&#8217;ve got the latest 3.6 bits from our source code repository, so I&#8217;ll install that as a library. Note that the plugin also supports Coherence 3.5.2.<br />
<a href="http://blackbeanbag.net/wp/wp-content/uploads/2010/08/2.png"><img class="alignnone size-medium wp-image-485" title="2" style="border-style: initial; border-color: initial; border-width: 0px;" src="http://blackbeanbag.net/wp/wp-content/uploads/2010/08/2-300x263.png" alt="" width="300" height="263" /></a><br />
Now, let&#8217;s create a new Java project. As part of the project creation, add Coherence as a project library.<br />
<a href="http://blackbeanbag.net/wp/wp-content/uploads/2010/08/3.png"><img class="alignnone size-medium wp-image-487" title="3" style="border-style: initial; border-color: initial; border-width: 0px;" src="http://blackbeanbag.net/wp/wp-content/uploads/2010/08/3-278x300.png" alt="" width="278" height="300" /></a><br />
After the project is created, we&#8217;ll have to enable Facets to use the Coherence plugin. Bring up the project properties window and search for &#8220;Facets&#8221; in the search field.<br />
<a href="http://blackbeanbag.net/wp/wp-content/uploads/2010/08/4.png"><img class="alignnone size-medium wp-image-488" title="4" style="border-style: initial; border-color: initial; border-width: 0px;" src="http://blackbeanbag.net/wp/wp-content/uploads/2010/08/4-300x214.png" alt="" width="300" height="214" /></a><br />
Once Facets are enabled, select Oracle Coherence.<br />
<a href="http://blackbeanbag.net/wp/wp-content/uploads/2010/08/5.png"><img class="alignnone size-medium wp-image-490" title="5" src="http://blackbeanbag.net/wp/wp-content/uploads/2010/08/5-300x214.png" style="border-style: initial; border-color: initial; border-width: 0px;" alt="" width="300" height="214" /></a><br />
Upon selection, a link indicating that further configuration is required will appear. Click on the link. Select the &#8220;Oracle Coherence 3.6&#8243; library. Note how it provides the option to generate configuration files. Let&#8217;s leave all of the checkboxes selected.<br />
<a href="http://blackbeanbag.net/wp/wp-content/uploads/2010/08/6.png"><img class="alignnone size-medium wp-image-492" title="6" style="border-style: initial; border-color: initial; border-width: 0px;" src="http://blackbeanbag.net/wp/wp-content/uploads/2010/08/6-300x266.png" alt="" width="300" height="266" /></a><br />
Now we are ready to start a cache server. Select File | Run Configurations to bring up the Run Configurations dialog. First select &#8220;Oracle Coherence&#8221; under the list of run configurations. Next, select the &#8220;New&#8221; button on the upper left portion of the dialog to create a new run configuration.<br />
<a href="http://blackbeanbag.net/wp/wp-content/uploads/2010/08/7.png"><img class="alignnone size-medium wp-image-493" title="7" style="border-style: initial; border-color: initial; border-width: 0px;" src="http://blackbeanbag.net/wp/wp-content/uploads/2010/08/7-300x203.png" alt="" width="300" height="203" /></a><br />
Under the &#8220;Main&#8221; tab, enter <tt>com.tangosol.net.DefaultCacheServer</tt> as the main class. Of course you are free to create configurations with your own classes; however this example will focus on starting up a cache server.</p>
<p>Note the presence of a &#8220;Coherence&#8221; tab. This tab allows for operational configuration (items typically found in <tt>tangosol-coherence-override.xml</tt>) such as the cache configuration file name, multicast address configuration, management/JMX, and so on. Here I decided to leave all of the defaults as is.<br />
<a href="http://blackbeanbag.net/wp/wp-content/uploads/2010/08/8.png"><img class="alignnone size-medium wp-image-496" title="8" style="border-style: initial; border-color: initial; border-width: 0px;" src="http://blackbeanbag.net/wp/wp-content/uploads/2010/08/8-300x251.png" alt="" width="300" height="251" /></a><br />
After clicking on &#8220;Run&#8221;, here&#8217;s what I get:<br />
<a href="http://blackbeanbag.net/wp/wp-content/uploads/2010/08/9.png"><img class="alignnone size-medium wp-image-498" title="9" style="border-style: initial; border-color: initial; border-width: 0px;" src="http://blackbeanbag.net/wp/wp-content/uploads/2010/08/9-300x230.png" alt="" width="300" height="230" /></a><br />
We can see that the node started up and formed a cluster, but there are no services listed. This is because the OEPE plugin generated a cache configuration file that defaults to all caches being local. Next, let&#8217;s examine the cache configuration file (located under <tt>src</tt> and add a distributed/partitioned cache to the configuration.<br />
<a href="http://blackbeanbag.net/wp/wp-content/uploads/2010/08/10.png"><img class="alignnone size-medium wp-image-499" title="10" style="border-style: initial; border-color: initial; border-width: 0px;" src="http://blackbeanbag.net/wp/wp-content/uploads/2010/08/10-300x225.png" alt="" width="300" height="225" /></a><br />
One of the nice features the plugin provides is pre-configured auto complete for Coherence configuration files via the DTD.</p>
<p>Here&#8217;s the cache configuration file I used:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!--?xml version=&quot;1.0&quot;?--&gt;</span>
&nbsp;
      *
      partitioned
&nbsp;
      partitioned
&nbsp;
      true</pre></td></tr></table></div>

<p>With the modified cache configuration, we now see the partitioned cache service start up:</p>
<p><a href="http://blackbeanbag.net/wp/wp-content/uploads/2010/08/11.png"><img class="alignnone size-medium wp-image-505" title="11" style="border-style: initial; border-color: initial; border-width: 0px;" src="http://blackbeanbag.net/wp/wp-content/uploads/2010/08/11-300x253.png" alt="" width="300" height="253" /></a></p>
<p>I can see the Coherence plugin for OEPE being quite useful for Coherence developers on Eclipse not only for quickly starting up a Coherence project (since config files are generated) but also for enabling configuration validation out of the box.</p>
]]></content:encoded>
			<wfw:commentRss>https://blackbeanbag.net/wp/2010/08/09/oracle-enterprise-pack-for-eclipse-now-supports-coherence/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Partitions, Backing Maps, and Services&#8230;Oh My!</title>
		<link>https://blackbeanbag.net/wp/2010/07/01/partitions-backing-maps-and-services-oh-my/</link>
		<comments>https://blackbeanbag.net/wp/2010/07/01/partitions-backing-maps-and-services-oh-my/#comments</comments>
		<pubDate>Thu, 01 Jul 2010 20:12:58 +0000</pubDate>
		<dc:creator><![CDATA[Patrick Peralta]]></dc:creator>
				<category><![CDATA[Coherence]]></category>

		<guid isPermaLink="false">http://blackbeanbag.net/wp/?p=454</guid>
		<description><![CDATA[Recently I was asked the following question: What is the relationship between a partition, cache, and a backing map?  To answer this, first we should go through some definitions: Cache: An object that maps keys to values. In Coherence, caches are referred to by name (thus the interface NamedCache.) Caches are also typically clustered, i.e. [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/rockinfree/2814780379/"><img src="http://blackbeanbag.net/wp/wp-content/uploads/2010/07/road.jpg" alt="Yellow Brick Road (Credit: _rockinfree)" title="Yellow Brick Road (Credit: _rockinfree)" width="134" height="129" style="border-style: initial; border-color: initial; border-width: 0px;" class="alignright size-full wp-image-470" style="margin:15px 15px"/></a><br />
Recently I was asked the following question:</p>
<blockquote><p>What is the relationship between a partition, cache, and a backing map? </p></blockquote>
<p>To answer this, first we should go through some definitions:</p>
<p><strong>Cache:</strong> An object that maps keys to values.  In Coherence, caches are referred to by name (thus the interface NamedCache.)  Caches are also typically clustered, i.e. they can be accessed and modified from any member of a Coherence cluster.</p>
<p><strong>Partition:</strong> A unit of transfer for a partitioned/distributed cache.  (In Coherence terminology, partitioned and distributed are used interchangeably, with preference towards the former.)  </p>
<p><strong>Backing Map:</strong> Data structure used by a storage node to hold contents of a cache.  For partitioned caches, this data is in binary (serialized) form.</p>
<p>I&#8217;ll add one more term for completeness: </p>
<p><strong>Service:</strong> Set of threads dedicated to handling requests; a cache service handles requests such as put, get, etc.  The DistributedCache service is present on all members of the cluster that read/write/store cache data, even if the node is storage disabled.</p>
<p>Now let&#8217;s put these concepts together to see how a clustered partitioned cache works.</p>
<p>First we&#8217;ll start with a backing map.  It is a straight forward data structure, usually an instance of <a href="http://download.oracle.com/otn_hosted_doc/coherence/353/com/tangosol/net/cache/LocalCache.html">LocalCache</a>:</p>
<p><a href="http://blackbeanbag.net/wp/wp-content/uploads/2010/07/SimpleBackingMap.png"><img src="http://blackbeanbag.net/wp/wp-content/uploads/2010/07/SimpleBackingMap.png" alt="" title="SimpleBackingMap" width="99" height="151" class="aligncenter size-full wp-image-457" /></a></p>
<p>The contents of this map are managed by a partitioned cache service.  In a typical thread dump, this would be the &#8220;DistributedCache&#8221; thread:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="none" style="font-family:monospace;">&quot;DistributedCache&quot; daemon prio=5 tid=101a91800 nid=0x118445000 in Object.wait() [118444000]</pre></td></tr></table></div>

<p>A single cache service can manage multiple backing maps.  This is the default behavior if multiple services are not specified in the cache configuration file.  (Multiple partitioned cache services are beyond the scope of this post; this topic will be addressed in a future posting.)</p>
<p><a href="http://blackbeanbag.net/wp/wp-content/uploads/2010/07/PCBM.png"><img src="http://blackbeanbag.net/wp/wp-content/uploads/2010/07/PCBM.png" alt="" title="PCBM" width="365" height="272" class="aligncenter size-full wp-image-461" /></a></p>
<p>So how do partitions come into play?  Each backing map is logically split into partitions:</p>
<p><a href="http://blackbeanbag.net/wp/wp-content/uploads/2010/07/PCBM-partitioned.png"><img src="http://blackbeanbag.net/wp/wp-content/uploads/2010/07/PCBM-partitioned.png" alt="" title="PCBM-partitioned" width="365" height="306" class="aligncenter size-full wp-image-463" /></a></p>
<p>This splitting is used for transferring data between storage enabled members.  Here are log file snippets of data transfer between two nodes:</p>
<p><strong>Member 1:</strong></p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="none" style="font-family:monospace;">(thread=DistributedCache, member=1): 3&gt; Transferring 128 out of 257 primary partitions to member 2 requesting 128</pre></td></tr></table></div>

<p><strong>Member 2:</strong></p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="none" style="font-family:monospace;">(thread=DistributedCache, member=2): Asking member 1 for 128 primary partitions</pre></td></tr></table></div>

<p>As members are added to the cluster, the partitions are split up amongst the members.  Note that this includes backup copies of each partition.</p>
<p><a href="http://blackbeanbag.net/wp/wp-content/uploads/2010/07/Distribution.png"><img src="http://blackbeanbag.net/wp/wp-content/uploads/2010/07/Distribution.png" alt="" title="Distribution" width="424" height="307" class="aligncenter size-full wp-image-466" /></a></p>
<p>As of Coherence 3.5, it is possible to configure backing maps to <a href="http://coherence.oracle.com/display/COH35UG/Storage+and+Backing+Map">physically split partitions into their own respective backing maps</a>.  This configuration may be desirable for backing maps that are stored off heap (i.e. NIO direct memory or disk) as it will make data transfer more efficient.</p>
<p><a href="http://blackbeanbag.net/wp/wp-content/uploads/2010/07/SplitBackingMap.png"><img src="http://blackbeanbag.net/wp/wp-content/uploads/2010/07/SplitBackingMap.png" alt="" title="SplitBackingMap" width="365" height="369" class="aligncenter size-full wp-image-468" /></a></p>
]]></content:encoded>
			<wfw:commentRss>https://blackbeanbag.net/wp/2010/07/01/partitions-backing-maps-and-services-oh-my/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Florida JUGs Next Week</title>
		<link>https://blackbeanbag.net/wp/2010/06/16/florida-jugs-next-week/</link>
		<comments>https://blackbeanbag.net/wp/2010/06/16/florida-jugs-next-week/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 18:09:43 +0000</pubDate>
		<dc:creator><![CDATA[Patrick Peralta]]></dc:creator>
				<category><![CDATA[Coherence]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://blackbeanbag.net/wp/?p=447</guid>
		<description><![CDATA[I will be in central Florida next week presenting at the following user groups: An Introduction to Data Grids for Database developers (GatorJUG June 23rd) This talk will introduce the concept of data grids to developers that have experience with Java EE and relational databases such as Oracle. The programming model will be explored (including [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>I will be in central Florida next week presenting at the following user groups:</p>
<p><strong><a href="http://www.codetown.us/events/gatorjug-2">An Introduction to Data Grids for Database developers (GatorJUG June 23rd)</a></strong></p>
<p><em>This talk will introduce the concept of data grids to developers that have experience with Java EE and relational databases such as Oracle. The programming model will be explored (including caching patterns and similarities to NoSQL) as well as the performance &#038; scalability improvements a data grid offers.</em></p>
<p><strong><a href="http://www.codetown.us/events/orlandojug-2">From IDE to Data Center &#8211; What Every Developer Should Know About Deploying Distributed Systems to Production (Orlando JUG June 24th)</a><br />
</strong></p>
<p><em>Taking a distributed system from development into a working production environment is a challenge that many developers take for granted. This talk will explore these challenges, especially scenarios that are not typically seen in a development setting.<br />
</em></p>
<p>I&#8217;m especially excited about the OJUG talk as I think it will cover many topics of interest to Developers and OPS guys.  It is a set of general guidelines that came about from seeing dozens of Coherence applications in production.  We will cover such things as:</p>
<ul>
<li>What to look for when using <tt>vmstat</tt>
<li>Must-have production level JVM settings/flags
<li>Developer Do&#8217;s and Dont&#8217;s
<li>Crash course on thread dumps and heap dumps
</ul>
<p>We will also be giving away a copy of <a href="http://www.amazon.com/gp/product/1847196128/ref=s9_simh_gw_p14_i1?pf_rd_m=ATVPDKIKX0DER&#038;pf_rd_s=center-2&#038;pf_rd_r=0F55S1X7P530YBMX67RX&#038;pf_rd_t=101&#038;pf_rd_p=470938631&#038;pf_rd_i=507846">Oracle Coherence 3.5</a> at each event!  If you are coming please follow the links to the events above and RSVP (you need to be a member of <a href="http://www.codetown.us/">CodeTown</a> to sign up, but registration is free and painless.)</p>
]]></content:encoded>
			<wfw:commentRss>https://blackbeanbag.net/wp/2010/06/16/florida-jugs-next-week/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Coherence Key HOWTO</title>
		<link>https://blackbeanbag.net/wp/2010/06/06/coherence-key-howto/</link>
		<comments>https://blackbeanbag.net/wp/2010/06/06/coherence-key-howto/#comments</comments>
		<pubDate>Mon, 07 Jun 2010 02:28:31 +0000</pubDate>
		<dc:creator><![CDATA[Patrick Peralta]]></dc:creator>
				<category><![CDATA[Coherence]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://blackbeanbag.net/wp/?p=409</guid>
		<description><![CDATA[On occasion I am asked about best practices for creating classes to be used as keys in Coherence. This usually comes about due to unexpected behavior that can be explained by incorrect key implementations. First and foremost, equals and hashCode need to be implemented correctly for any type used as a key. I won&#8217;t describe [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/brenda-starr/3509344100/in/set-72157617806022838"><img src="http://blackbeanbag.net/wp/wp-content/uploads/2010/06/3509344100_ebf565abe7_m.jpg" alt="Image credit: Brenda Starr" title="Image credit: Brenda Starr" width="162" height="109" class="alignright size-full wp-image-425" style="margin:10px 10px" /></a></p>
<p>On occasion I am asked about best practices for creating classes to be used as keys in Coherence.  This usually comes about due to unexpected behavior that can be explained by incorrect key implementations.</p>
<p>First and foremost, <code>equals</code> and <code>hashCode</code> need to be implemented correctly for any type used as a key.  I won&#8217;t describe how to do this &#8211; instead I&#8217;ll defer to Josh Bloch who has written <a href="http://java.sun.com/developer/Books/effectivejava/Chapter3.pdf">the definitive guide on this topic</a>.</p>
<p>There is an additional requirement that needs to be addressed.  <strong>All serializable (non transient) fields in the key class must be used in the <code>equals</code> implementation.</strong>  To understand this requirement, let&#8217;s explore how Coherence works behind the scenes.</p>
<p>First, let&#8217;s try the following experiment:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> <span style="color: #003399;">Key</span>
        <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">Serializable</span>
    <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Key</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> id, <span style="color: #003399;">String</span> zip<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
        m_id <span style="color: #339933;">=</span> id<span style="color: #339933;">;</span>
        m_zip <span style="color: #339933;">=</span> zip<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//...</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> equals<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> o<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// print stack trace</span>
        <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Throwable</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;equals debug&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span> <span style="color: #339933;">==</span> o<span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>o <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">||</span> getClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> o.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003399;">Key</span> key <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Key</span><span style="color: #009900;">&#41;</span> o<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>m_id <span style="color: #339933;">!=</span> key.<span style="color: #006633;">m_id</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>m_zip <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">?</span> <span style="color: #339933;">!</span>m_zip.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>key.<span style="color: #006633;">m_zip</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> key.<span style="color: #006633;">m_zip</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> hashCode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// print stack trace</span>
        <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Throwable</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hashCode debug&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>        
        <span style="color: #000066; font-weight: bold;">int</span> result <span style="color: #339933;">=</span> m_id<span style="color: #339933;">;</span>
        result <span style="color: #339933;">=</span> <span style="color: #cc66cc;">31</span> <span style="color: #339933;">*</span> result <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>m_zip <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">?</span> m_zip.<span style="color: #006633;">hashCode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> result<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> m_id<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> m_zip<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>This key prints out stack traces in <code>equals</code> and <code>hashCode</code>.  Now use this key with a HashMap:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> testKey<span style="color: #009900;">&#40;</span><span style="color: #003399;">Map</span> m<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
    <span style="color: #003399;">Key</span> key <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Key</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span>, <span style="color: #0000ff;">&quot;12345&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    m.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>key, <span style="color: #0000ff;">&quot;value&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    m.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>key<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//...</span>
&nbsp;
testKey<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">HashMap</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Output is as follows:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="none" style="font-family:monospace;">java.lang.Throwable: hashCode debug
	at oracle.coherence.idedc.Key.hashCode(Key.java:60)
	at java.util.HashMap.put(HashMap.java:372)
	at oracle.coherence.idedc.KeyTest.testKey(KeyTest.java:46)
	at oracle.coherence.idedc.KeyTest.testKey(KeyTest.java:52)
	at oracle.coherence.idedc.KeyTest.main(KeyTest.java:18)
java.lang.Throwable: hashCode debug
	at oracle.coherence.idedc.Key.hashCode(Key.java:60)
	at java.util.HashMap.get(HashMap.java:300)
	at oracle.coherence.idedc.KeyTest.testKey(KeyTest.java:47)
	at oracle.coherence.idedc.KeyTest.testKey(KeyTest.java:52)
	at oracle.coherence.idedc.KeyTest.main(KeyTest.java:18)</pre></td></tr></table></div>

<p>Try it again with a partitioned cache this time:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">testKey<span style="color: #009900;">&#40;</span>CacheFactory.<span style="color: #006633;">getCache</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;dist-test&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Note the absence of stack traces this time.  Does this mean Coherence is not using the key&#8217;s <code>equals</code> and <code>hashCode</code>?  The short answer (for now) is yes.  Here is the flow of events that occur when executing a put with a partitioned cache:</p>
<ol>
<li> Invoke NamedCache.put
<li> Key and value are serialized
<li> Hash is executed on serialized key to determine which partition the key belongs to
<li> Key and value are transferred to the storage node (likely over the network)
<li> Cache entry is placed into backing map in binary form
</ol>
<p><img src="http://blackbeanbag.net/wp/wp-content/uploads/2010/06/keys.png" class="aligncenter size-medium wp-image-423" /></p>
<p>Note that objects are <strong>not</strong> deserialized before placement into the backing map &#8211; objects are stored in their serialized binary format.  As a result, this means that two keys that are equal to each other in object form <strong>must</strong> be equal to each other in binary form so that the keys can be later be used to retrieve entries from the backing map.  The most common way to violate this principle is to exclude non transient fields from <code>equals</code>.  For example:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> BrokenKey
        <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">Serializable</span>
    <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> BrokenKey<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> id, <span style="color: #003399;">String</span> zip<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
        m_id <span style="color: #339933;">=</span> id<span style="color: #339933;">;</span>
        m_zip <span style="color: #339933;">=</span> zip<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//...</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> equals<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> o<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span> <span style="color: #339933;">==</span> o<span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>o <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">||</span> getClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> o.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
        BrokenKey brokenKey <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>BrokenKey<span style="color: #009900;">&#41;</span> o<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>m_id <span style="color: #339933;">!=</span> brokenKey.<span style="color: #006633;">m_id</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> hashCode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">int</span> result <span style="color: #339933;">=</span> m_id<span style="color: #339933;">;</span>
        result <span style="color: #339933;">=</span> <span style="color: #cc66cc;">31</span> <span style="color: #339933;">*</span> result<span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> result<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Note this key has two fields (id and zip) but it only uses id in the <code>equals</code>/<code>hashCode</code> implementation.  I have the following method to test this key:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> testBrokenKey<span style="color: #009900;">&#40;</span><span style="color: #003399;">Map</span> m<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
    BrokenKey keyPut <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> BrokenKey<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span>, <span style="color: #0000ff;">&quot;11111&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    BrokenKey keyGet <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> BrokenKey<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span>, <span style="color: #0000ff;">&quot;22222&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    m.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>keyPut<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    m.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>keyPut, <span style="color: #0000ff;">&quot;value&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>m.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>keyPut<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>m.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>keyGet<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Output using HashMap:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="none" style="font-family:monospace;">value
value</pre></td></tr></table></div>

<p>Output using partitioned cache:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="none" style="font-family:monospace;">value
null</pre></td></tr></table></div>

<p>This makes sense, since <code>keyPut</code> and <code>keyGet</code> will serialize to different binaries.  However, things get really interesting when combining partitioned cache with a near cache.  Running the example using a near cache gives the following results:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="none" style="font-family:monospace;">value
value</pre></td></tr></table></div>

<p>What happened?  In this case, the first get resulted in a near cache miss, resulting in a read through to the backing partitioned cache.  The second get resulted in a near cache <strong>hit</strong> because the object&#8217;s equals/hashCode was used (since near caches store data in object form.)</p>
<p>In addition to <code>equals</code>/<code>hashCode</code>, keep the following in mind:</p>
<ul>
<li>Keys should be immutable.  Modifying a key while it is in a map generally isn&#8217;t a good idea, and it certainly won&#8217;t work in a distributed/partitioned cache.
<li>Key should be as small as possible.  Many operations performed by Coherence assume that keys are very light weight (such as the key based listeners that are used for near cache invalidation.)
<li>Built in types (String, Integer, Long, etc) fit all of this criteria.  If possible, consider using one of these existing classes.)
</ul>
]]></content:encoded>
			<wfw:commentRss>https://blackbeanbag.net/wp/2010/06/06/coherence-key-howto/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Springtime for Coherence</title>
		<link>https://blackbeanbag.net/wp/2010/04/18/springtime-for-coherence/</link>
		<comments>https://blackbeanbag.net/wp/2010/04/18/springtime-for-coherence/#comments</comments>
		<pubDate>Sun, 18 Apr 2010 09:50:12 +0000</pubDate>
		<dc:creator><![CDATA[Patrick Peralta]]></dc:creator>
				<category><![CDATA[Coherence]]></category>

		<guid isPermaLink="false">http://blackbeanbag.net/wp/?p=401</guid>
		<description><![CDATA[As I type this I am 35,000 feet over Alaska (no I can’t see Putin’s backyard from here) en route to QCon Tokyo. Brian was scheduled to talk but was unable to make it so I’m stepping in to present a talk on spanning multiple data grids across disparate data centers. (You can see Brian [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>As I type this I am 35,000 feet over Alaska (no I can’t see Putin’s backyard from here) en route to <a href="http://qcontokyo.com/">QCon Tokyo</a>.  Brian was scheduled to talk but was unable to make it so I’m stepping in to present a talk on <a href="http://qcontokyo.com/speaker_PatrickPeralta.html">spanning multiple data grids across disparate data centers</a>.  (You can see Brian describing this talk at QCon SF <a href="http://www.youtube.com/watch?v=hHURxMmsAJ8">here</a>.)  In addition to this presentation, I’m looking forward to sampling the food and culture in Japan.  As a big city guy I’ve always wanted to visit Tokyo so I’m quite fortunate to have the chance.</p>
<p>As they say, when it rains it pours.  I just came back from the <a href="http://coherence.oracle.com/display/CSIG/15+Apr+2010+-+New+York%2C+NY">New York SIG</a> where I talked about real world challenges in customer deployments and passed along lessons that we learned in solving these problems.  After leaving Tokyo, I will be joining Cameron and Noah in Toronto for the <a href="http://coherence.oracle.com/display/CSIG/23+Apr+2010+-+Mississauga%2C+ON">inaugural SIG</a> where I will deliver the same presentation I gave in NY.  Cameron will talk about the past and future of Coherence, and Noah will give an update on the latest innovations in the Coherence Incubator project.</p>
<p>Has everyone received their copy of the <a href="http://www.amazon.com/gp/product/1847196128/ref=s9_simh_gw_p14_i1?pf_rd_m=ATVPDKIKX0DER&#038;pf_rd_s=center-2&#038;pf_rd_r=0F55S1X7P530YBMX67RX&#038;pf_rd_t=101&#038;pf_rd_p=470938631&#038;pf_rd_i=507846">Coherence book</a> yet?  One of my favorite parts of the book is the very beginning where Aleks describes what it takes to build scalable applications.  In fact a good portion of the first chapter doesn’t even mention Coherence; it just talks about aspects of scalability that developers and architects of high scale systems should be familiar with.  A copy of this book was raffled at the NY SIG, and more copies will be given away at the Bay SIG and Toronto SIG.</p>
]]></content:encoded>
			<wfw:commentRss>https://blackbeanbag.net/wp/2010/04/18/springtime-for-coherence/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What&#8217;s happening in the world of Coherence?</title>
		<link>https://blackbeanbag.net/wp/2010/02/19/whats-happening-in-the-world-of-coherence/</link>
		<comments>https://blackbeanbag.net/wp/2010/02/19/whats-happening-in-the-world-of-coherence/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 18:28:23 +0000</pubDate>
		<dc:creator><![CDATA[Patrick Peralta]]></dc:creator>
				<category><![CDATA[Coherence]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://blackbeanbag.net/wp/?p=395</guid>
		<description><![CDATA[It has been a while since I&#8217;ve posted, so I figured it would be a good time to give an update on what is happening in Coherence land. New Coherence Bloggers We have two new bloggers sharing their experiences with Coherence! The first is by Oracle JDBC expert Pas Apicella who recently took on Coherence. [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>It has been a while since I&#8217;ve posted, so I figured it would be a good time to give an update on what is happening in Coherence land.</p>
<h3>New Coherence Bloggers</h3>
<p>We have two new bloggers sharing their experiences with Coherence!</p>
<p>The first is by Oracle JDBC expert Pas Apicella who recently took on Coherence.  Upon his introduction to Coherence he immediately proceeded to create a <a href="http://theblasfrompas.blogspot.com/2009/11/oracle-coherence.html">CacheStore example using PL/SQL</a>, followed by an example of using the <a href="http://www.oracle.com/technology/obe/11gr1_db/appdev/dcn/dcn.htm">Oracle JDBC Data Change Notification</a> mechanism to <a href="http://theblasfrompas.blogspot.com/2010/02/using-database-change-notification-dcn.html">push updates from the database to a cache</a>.</p>
<p>Additionally we have Coherence architect Andy Nguyen debuting with a detailed description of a <a href="http://cohfu.wordpress.com/2010/01/06/bulk-loading-a-coherence-cache-from-an-oracle-database/">sophisticated distributed bulk loading technique</a> he&#8217;s employed on several customer projects.</p>
<h3>Coherence Book in March</h3>
<p>After many months of blood, sweat, and blisters from too much typing, <a href="http://coherence.seovic.com/">Aleksandar Seovic</a> has completed the highly anticipated <a href="http://www.packtpub.com/oracle-coherence-3-5/book">Coherence book</a> published by <a href="http://www.packtpub.com">Packt</a>.  Having worked closely with Aleks on reviews and contributions, I believe this book will be a terrific resource for developers and architects that need to write scalable applications.  Both experienced users of Coherence and new users will find relevant and useful content.  Aleks was recently interviewed by Cameron Purdy about the book which can be downloaded as an <a href="http://streaming.oracle.com/ebn/podcasts/media/8458541_Aleksander_Seovic_020310.mp3">MP3</a>.</p>
<h3>User Group Meetings</h3>
<p>The UK SIG in London is the last Coherence user group meeting for the winter, it is coming up on <a href="http://brianoliver.wordpress.com/2010/02/01/london-coherence-sig-winter-edition-26th-february-2010-2/">February 26th</a>.  The spring events are currently being planned; stay tuned for details!</p>
<p>Also coming up on February 24th is the first <a href="http://www.bostonsug.org/">Boston SUG</a> meeting of the year.  Although the topic won&#8217;t be Coherence this time, it will be of interest for developers and architects interested in scalable systems.  We&#8217;ll be meeting up for drinks and snacks at Bertucci&#8217;s afterwards.  And I&#8217;ll be there if anyone wants to chat about Coherence or any other topic!</p>
]]></content:encoded>
			<wfw:commentRss>https://blackbeanbag.net/wp/2010/02/19/whats-happening-in-the-world-of-coherence/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Next NY Coherence SIG on October 1st</title>
		<link>https://blackbeanbag.net/wp/2009/09/17/next-ny-coherence-sig-on-october-1st/</link>
		<comments>https://blackbeanbag.net/wp/2009/09/17/next-ny-coherence-sig-on-october-1st/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 12:35:30 +0000</pubDate>
		<dc:creator><![CDATA[Patrick Peralta]]></dc:creator>
				<category><![CDATA[Coherence]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://blackbeanbag.net/wp/?p=383</guid>
		<description><![CDATA[The next NY Coherence SIG is on October 1st (two weeks from today) and it promises to be a great event. For those of you who follow my blog, I previously introduced these two gentlemen a few months ago when they started blogging. The first talk will be by Aleksandar Seovic who has an extensive [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>The next <a href="http://coherence.oracle.com/display/CSIG/1+Oct+2009+-+New+York%2C+NY">NY Coherence SIG</a> is on October 1st (two weeks from today) and it <a href="http://craigblitz.typepad.com/rawpower/2009/09/fall-edition-of-the-new-york-coherence-sig.html">promises to be a great event</a>.  For those of you who follow my blog, I previously <a href="http://blackbeanbag.net/wp/2009/05/27/two-new-coherence-blogs/">introduced these two gentlemen</a> a few months ago when they started blogging.  </p>
<p>The first talk will be by <a href="http://coherence.seovic.com/">Aleksandar Seovic</a> who has an extensive Coherence resume.  In addition to implementing POF in .NET, he is also the author of an upcoming <a href="http://www.packtpub.com/oracle-coherence-3-5/book">book on Coherence</a>.  In his spare time (insert tongue in cheek) he runs <a href="http://www.s4hc.com/">S4HC</a>, a consulting company specializing in Spring, Coherence, and other technologies.  </p>
<p><i>If you&#8217;re in Tampa, you can also check out his <a href="http://www.tampajug.org/wordpress/?p=133">upcoming talk at Tampa JUG</a> on September 29th.</i></p>
<p>We will also have <a href="http://markfalco.wordpress.com/">Mark Falco</a>, one of our rock star engineers who concentrates on our network protocol (TCMP), C++, and other areas.  Mark is usually the first (and last) person I reach out to when I have questions about Coherence networking &#8211; so if you have any questions of your own be sure to bring them.  He will talk to us about TCMP and how to optimize your machines and network for optimum performance.</p>
<p>Finally, yours truly will talk about configuring Coherence to work with an external data source (usually relational databases.)  I&#8217;ll describe in detail how each of the external connectivity features work (including many features you&#8217;ve probably never heard of), best practices, and good old fashioned war stories.  (Shout out to <a href="http://calmerthanur.wordpress.com/">Rob</a> for helping with the Omni Graffle diagrams!)  This is the same talk that I will present in mid October at <a href="http://www.oracle.com/openworld/index.html">Oracle Open World</a> in San Francisco.  I&#8217;ll provide more detail on this later; for now you can check out the <a href="http://www.oracle.com/technology/products/coherence/pdf/focuson_appgrid_openworld_2009.pdf">Application Grid</a> lineup &#8211; which includes WebLogic Server, Coherence, JRockit, Tuxedo and Enterprise Manager.</p>
]]></content:encoded>
			<wfw:commentRss>https://blackbeanbag.net/wp/2009/09/17/next-ny-coherence-sig-on-october-1st/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Coherence 3.5: POF Extractor/Updater</title>
		<link>https://blackbeanbag.net/wp/2009/07/21/coherence-3-5-pof-extractorupdater/</link>
		<comments>https://blackbeanbag.net/wp/2009/07/21/coherence-3-5-pof-extractorupdater/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 14:59:45 +0000</pubDate>
		<dc:creator><![CDATA[Patrick Peralta]]></dc:creator>
				<category><![CDATA[Coherence]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://blackbeanbag.net/wp/?p=287</guid>
		<description><![CDATA[This article is part 3 of a 3 part series on my favorite new features in Coherence 3.5. Ever since Coherence added support for .NET (and more recently C++, which can be implied when discussing .NET below) clients, we&#8217;ve always been asked this question: When do I have to provide both .NET and Java implementations [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><i>This article is part 3 of a 3 part series on my <a href="/wp/2009/07/20/my-favorite-new-features-in-coherence-3-5/">favorite new features in Coherence 3.5.</a></i></p>
<p>Ever since Coherence added support for .NET (and more recently C++, which can be implied when discussing .NET below) clients, we&#8217;ve always been asked this question:</p>
<blockquote><p>
<i>When do I have to provide both .NET and Java implementations of my classes?</i>
</p></blockquote>
<p>With each new release of Coherence, it becomes less of a requirement  to provide .NET and Java implementations of cache objects.  Here is a timeline of the evolution of multi language support:</p>
<h3>Coherence 3.2/3.3</h3>
<p>Support for .NET clients.  .NET objects are serialized into a platform neutral serialization format (POF) and sent over TCP to a proxy server.  The proxy server deserializes these objects and serializes them into Java format before sending into the grid for storage, thus the requirement for .NET and Java versions of each type.</p>
<h3>Coherence 3.4</h3>
<p>Support for .NET and C++ clients.  Grid is enhanced to allow for POF binaries to be stored natively in the grid, thus removing the deserialization/serialization step previously required in the proxy servers.  .NET and Java versions of cached objects are required for:</p>
<ul>
<li>Entry processors
<li>Queries
<li>Cache Store
<li>Key association
</ul>
<p>For applications with .NET clients that only do puts and gets, there is no need for Java versions of their objects in the grid.</p>
<h3>Coherence 3.5</h3>
<p>New in 3.5 is the ability for cache servers to extract and update data in POF binaries without deserializing the binary into an object.  This is done via <a href="http://coherence.oracle.com/display/COH35UG/PofExtractors+and+PofUpdaters">PofExtractors and PofUpdaters</a>.   A <a href="http://download.oracle.com/otn_hosted_doc/coherence/350/com/tangosol/util/extractor/PofExtractor.html">PofExtractor</a> is an implementation of <a href="http://download.oracle.com/otn_hosted_doc/coherence/350/com/tangosol/util/ValueExtractor.html">ValueExtractor</a>, which is an interface that defines how to extract data from objects.  The most common extractor in use today is <a href="http://download.oracle.com/otn_hosted_doc/coherence/350/com/tangosol/util/extractor/ReflectionExtractor.html">ReflectionExtractor</a>, which simply means that the provided method will be invoked on the target object, and the result from that method is returned.</p>
<p>This means that operations that rely on extractors (such as queries and some entry processors) can now be executed on the server side without needing Java classes to represent the data types.</p>
<p>Here is an example.  Let&#8217;s say you have the following type (I wrote it in Java, but this could also be done in .NET)</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Person
        <span style="color: #000000; font-weight: bold;">implements</span> PortableObject
    <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> Person<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> Person<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> sFirstName, <span style="color: #003399;">String</span> sLastName, <span style="color: #003399;">String</span> sEmail<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
        m_sFirstName <span style="color: #339933;">=</span> sFirstName<span style="color: #339933;">;</span>
        m_sLastName <span style="color: #339933;">=</span> sLastName<span style="color: #339933;">;</span>
        m_sEmail <span style="color: #339933;">=</span> sEmail<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// getters and setters omitted.. </span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> readExternal<span style="color: #009900;">&#40;</span>PofReader in<span style="color: #009900;">&#41;</span>
            <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span>
        <span style="color: #009900;">&#123;</span>
        m_sFirstName <span style="color: #339933;">=</span> in.<span style="color: #006633;">readString</span><span style="color: #009900;">&#40;</span>FIRST_NAME<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        m_sLastName  <span style="color: #339933;">=</span> in.<span style="color: #006633;">readString</span><span style="color: #009900;">&#40;</span>LAST_NAME<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        m_sEmail     <span style="color: #339933;">=</span> in.<span style="color: #006633;">readString</span><span style="color: #009900;">&#40;</span>EMAIL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> writeExternal<span style="color: #009900;">&#40;</span>PofWriter out<span style="color: #009900;">&#41;</span>
            <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span>
        <span style="color: #009900;">&#123;</span>
        out.<span style="color: #006633;">writeString</span><span style="color: #009900;">&#40;</span>FIRST_NAME, m_sFirstName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        out.<span style="color: #006633;">writeString</span><span style="color: #009900;">&#40;</span>LAST_NAME, m_sLastName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        out.<span style="color: #006633;">writeString</span><span style="color: #009900;">&#40;</span>EMAIL, m_sEmail<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> m_sFirstName<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> m_sLastName<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> m_sEmail<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> FIRST_NAME <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> LAST_NAME  <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> EMAIL      <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Now for some sample code on executing a query:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">NamedCache pofCache <span style="color: #339933;">=</span> CacheFactory.<span style="color: #006633;">getCache</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;pof&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// These names are fictitious: any resemblence to real people</span>
<span style="color: #666666; font-style: italic;">// is coincidental!</span>
pofCache.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span>, <span style="color: #000000; font-weight: bold;">new</span> Person<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Bob&quot;</span>, <span style="color: #0000ff;">&quot;Smith&quot;</span>, <span style="color: #0000ff;">&quot;bob.smith@google.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
pofCache.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span>, <span style="color: #000000; font-weight: bold;">new</span> Person<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Jane&quot;</span>, <span style="color: #0000ff;">&quot;Doe&quot;</span>, <span style="color: #0000ff;">&quot;jane.doe@yahoo.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
pofCache.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span>, <span style="color: #000000; font-weight: bold;">new</span> Person<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Fred&quot;</span>, <span style="color: #0000ff;">&quot;James&quot;</span>, <span style="color: #0000ff;">&quot;fred.james@oracle.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
pofCache.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">4</span>, <span style="color: #000000; font-weight: bold;">new</span> Person<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Amy&quot;</span>, <span style="color: #0000ff;">&quot;Jones&quot;</span>, <span style="color: #0000ff;">&quot;amy.jones@oracle.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
pofCache.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span>, <span style="color: #000000; font-weight: bold;">new</span> Person<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Ted&quot;</span>, <span style="color: #0000ff;">&quot;Black&quot;</span>, <span style="color: #0000ff;">&quot;ted.black@google.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Query for oracle.com addresses</span>
<span style="color: #003399;">Set</span> keys <span style="color: #339933;">=</span> pofCache.<span style="color: #006633;">keySet</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> LikeFilter<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> PofExtractor<span style="color: #009900;">&#40;</span>Person.<span style="color: #006633;">EMAIL</span><span style="color: #009900;">&#41;</span>, 
        <span style="color: #0000ff;">&quot;%@oracle.com&quot;</span>, <span style="color: #0000ff;">'<span style="color: #000099; font-weight: bold;">\\</span>'</span>, <span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">assert</span> keys.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">assert</span> keys.<span style="color: #006633;">contains</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">assert</span> keys.<span style="color: #006633;">contains</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The cache configuration (note the system-property override in the serializer config; this comes into play later):</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
&nbsp;
<span style="color: #00bbdd;">&lt;!DOCTYPE cache-config SYSTEM &quot;cache-config.dtd&quot;&gt;</span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cache-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;caching-scheme-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cache-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cache-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>pof<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cache-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;scheme-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>pof<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/scheme-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cache-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/caching-scheme-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;caching-schemes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;distributed-scheme<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;scheme-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>pof<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/scheme-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;serializer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.tangosol.io.pof.ConfigurablePofContext<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/class-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;init-params<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>string<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-value</span> <span style="color: #000066;">system-property</span>=<span style="color: #ff0000;">&quot;pof.config&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>pof-config.xml<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/init-params<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/serializer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;service-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>PofDistributedService<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/service-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;backing-map-scheme<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;local-scheme</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/backing-map-scheme<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;autostart<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/autostart<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/distributed-scheme<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/caching-schemes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cache-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>And, the POF configuration on the client:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE pof-config SYSTEM &quot;pof-config.dtd&quot;&gt;</span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pof-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;user-type-list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>coherence-pof-config.xml<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/include<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;user-type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;type-id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>10001<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/type-id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.tangosol.examples.pof.Person<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/class-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/user-type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/user-type-list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pof-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>To run this, I set up a cache server without adding any extra classes to the classpath.  I only provided the above cache configuration, and I supplied the following to the command line:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="txt" style="font-family:monospace;">-Dpof.config=coherence-pof-config.xml</pre></td></tr></table></div>

<p>Why did I do this?  This is because the server side does not need to know about the client&#8217;s POF configuration since it does not need to deserialize the objects.  Therefore I&#8217;m simply supplying the default cache configuration that ships with Coherence.</p>
<p>Given the addition of this new feature, we can modify the list from 3.4 as such:</p>
<ul>
<li><s>Entry processors</s>
<li><s>Queries</s>
<li>Cache Store
<li>Key association
</ul>
<p>To summarize, the introduction of POF extractors and updaters means that .NET clients only need Java implementations of their respective classes when performing <a href="http://coherence.oracle.com/display/COH35UG/Read-Through%2C+Write-Through%2C+Write-Behind+and+Refresh-Ahead+Caching">CacheStore</a> operations and/or <a href="http://coherence.oracle.com/display/COH35UG/Data+Affinity">key association</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://blackbeanbag.net/wp/2009/07/21/coherence-3-5-pof-extractorupdater/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Coherence 3.5: Service Guardian (Deadlock Detection)</title>
		<link>https://blackbeanbag.net/wp/2009/07/20/coherence-3-5-service-guardian-deadlock-detection/</link>
		<comments>https://blackbeanbag.net/wp/2009/07/20/coherence-3-5-service-guardian-deadlock-detection/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 01:49:08 +0000</pubDate>
		<dc:creator><![CDATA[Patrick Peralta]]></dc:creator>
				<category><![CDATA[Coherence]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://blackbeanbag.net/wp/?p=258</guid>
		<description><![CDATA[This article is part 2 of a 3 part series on my favorite new features in Coherence 3.5. One of the great benefits of using a modern JVM is deadlock detection. At my previous job I remember helping to track down an intermittent issue with our Swing desktop client that was eventually solved by providing [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><i>This article is part 2 of a 3 part series on my <a href="/wp/2009/07/20/my-favorite-new-features-in-coherence-3-5/">favorite new features in Coherence 3.5.</a></i></p>
<p>One of the great benefits of using a modern JVM is deadlock detection.   At my previous job I remember helping to track down an intermittent issue with our Swing desktop client that was eventually solved by providing instructions to our support/QA staff on how to generate a thread dump when the issue surfaced (which is much harder on Windows than on Unix/Linux based OSes.)  Once they sent us the thread dump (which so conveniently printed the threads that were deadlocked at the bottom), fixing the issue was trivial.</p>
<p>Deadlocks can and do happen in distributed systems, and unfortunately there isn&#8217;t a good mechanism to detect distributed deadlocks.  However, Oracle Coherence 3.5 does bring us closer with a new feature we call the <a href="http://wiki.tangosol.com/display/COH35UG/service-guardian">Service Guardian</a>.  The concept behind the guardian is to ensure that each of the threads under our control are responsive; and when they&#8217;re not then the cluster node should take action.  Out of the box you can configure it to remove the node from the cluster (default) or shut down the JVM.  You can also provide an implementation of <code><a href="http://download.oracle.com/otn_hosted_doc/coherence/350/com/tangosol/net/ServiceFailurePolicy.html">ServiceFailurePolicy</a> </code> to provide custom handling of detected deadlocks.</p>
<p>Deadlocks can have especially bad consequences in a distributed system since there are inherent dependencies between nodes.  In my experience, I&#8217;ve seen deadlocks in clusters due to one of three reasons:</p>
<h3>Bugs in customer code</h3>
<p>Concurrent programming is difficult enough; mix it in with distributed computing and you can get into some sticky situations.  Several times in the past I&#8217;ve seen deadlocks occur within event handling code.  Here&#8217;s one way that event handlers can deadlock:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * @author pperalta Jul 20, 2009
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> GuardianDemo
        <span style="color: #000000; font-weight: bold;">implements</span> MapListener
    <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
        NamedCache cache <span style="color: #339933;">=</span> CacheFactory.<span style="color: #006633;">getCache</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;test&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        cache.<span style="color: #006633;">addMapListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> GuardianDemo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">int</span> nKey <span style="color: #339933;">=</span> RANDOM.<span style="color: #006633;">nextInt</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">try</span>
                <span style="color: #009900;">&#123;</span>
                cache.<span style="color: #006633;">lock</span><span style="color: #009900;">&#40;</span>nKey, <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #003399;">List</span> listValue <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">List</span><span style="color: #009900;">&#41;</span> cache.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>nKey<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>listValue <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
                    <span style="color: #009900;">&#123;</span>
                    listValue <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ArrayList</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
                listValue.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">System</span>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                cache.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>nKey, listValue<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #000000; font-weight: bold;">finally</span>
                <span style="color: #009900;">&#123;</span>
                cache.<span style="color: #006633;">unlock</span><span style="color: #009900;">&#40;</span>nKey<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> entryInserted<span style="color: #009900;">&#40;</span>MapEvent evt<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> entryUpdated<span style="color: #009900;">&#40;</span>MapEvent evt<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
        NamedCache cache <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>NamedCache<span style="color: #009900;">&#41;</span> evt.<span style="color: #006633;">getSource</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">Object</span>     nKey  <span style="color: #339933;">=</span> evt.<span style="color: #006633;">getKey</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">try</span>
            <span style="color: #009900;">&#123;</span>
            cache.<span style="color: #006633;">lock</span><span style="color: #009900;">&#40;</span>nKey, <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #003399;">List</span> listValue <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">List</span><span style="color: #009900;">&#41;</span> cache.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>nKey<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>listValue.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#123;</span>
                <span style="color: #003399;">Object</span> lValue <span style="color: #339933;">=</span> listValue.<span style="color: #006633;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                cache.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>nKey, listValue<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Removed &quot;</span> <span style="color: #339933;">+</span> lValue <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; from &quot;</span> <span style="color: #339933;">+</span> nKey<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">finally</span>
            <span style="color: #009900;">&#123;</span>
            cache.<span style="color: #006633;">unlock</span><span style="color: #009900;">&#40;</span>nKey<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> entryDeleted<span style="color: #009900;">&#40;</span>MapEvent evt<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">Random</span> RANDOM <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Random</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">System</span>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>When registering a map listener with Coherence, a background thread will be spawned to handle events.  Upon receiving an event, Coherence will queue it up for the event handler (the customer provided implementation of <code>MapListener</code>) to process.  If we notice that events are being handled slower than they are being generated, then we will attempt to throttle the creation of new events so as to not allow the event queue to grow unbounded (and eventually exhaust the heap.)<br />
<i><br />
A bit of a digression: the event throttling is not a new feature of Coherence; it has been around since at least 3.2.<br />
</i></p>
<p>When I ran this code with Coherence 3.4, it ran for a while but eventually stopped:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="txt" style="font-family:monospace;">Oracle Coherence Version 3.4.2/411p7
 Grid Edition: Development mode
Copyright (c) 2000-2009 Oracle. All rights reserved.
...
Removed 1248134614674 from 9
Removed 1248134614692 from 9
Removed 1248134614697 from 9
Removed 1248134614699 from 9
Removed 1248134614703 from 9
Removed 1248134614706 from 9
Removed 1248134614717 from 9
Removed 1248134614708 from 6
Removed 1248134614713 from 3
Removed 1248134614719 from 6
Removed 1248134614727 from 6
Removed 1248134614723 from 3
Removed 1248134614701 from 5
Removed 1248134614709 from 8
Removed 1248134614732 from 8
Removed 1248134614736 from 3
Removed 1248134614725 from 7
Removed 1248134614729 from 5
Removed 1248134614745 from 3
Removed 1248134614733 from 8
...</pre></td></tr></table></div>

<p>When it stopped running, I captured a thread dump:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="txt" style="font-family:monospace;">&quot;DistributedCache:EventDispatcher&quot; daemon prio=5 tid=0x01019e40 nid=0x83e200 in Object.wait() [0xb1113000..0xb1113d90]
	at java.lang.Object.wait(Native Method)
	at java.lang.Object.wait(Object.java:474)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.poll(Grid.CDB:31)
	- locked &lt;0x295b8d88&gt; (a com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$LockRequest$Poll)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.poll(Grid.CDB:11)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$BinaryMap.lock(DistributedCache.CDB:37)
	at com.tangosol.util.ConverterCollections$ConverterConcurrentMap.lock(ConverterCollections.java:2024)
	at com.tangosol.util.ConverterCollections$ConverterNamedCache.lock(ConverterCollections.java:2539)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$ViewMap.lock(DistributedCache.CDB:1)
	at com.tangosol.coherence.component.util.SafeNamedCache.lock(SafeNamedCache.CDB:1)
	at com.tangosol.examples.guardian.GuardianDemo.entryUpdated(GuardianDemo.java:56)
	at com.tangosol.util.MapEvent.dispatch(MapEvent.java:195)
	at com.tangosol.util.MapEvent.dispatch(MapEvent.java:164)
	at com.tangosol.util.MapListenerSupport.fireEvent(MapListenerSupport.java:556)
	at com.tangosol.coherence.component.util.SafeNamedCache.translateMapEvent(SafeNamedCache.CDB:7)
	at com.tangosol.coherence.component.util.SafeNamedCache.entryUpdated(SafeNamedCache.CDB:1)
	at com.tangosol.util.MapEvent.dispatch(MapEvent.java:195)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$ViewMap$ProxyListener.dispatch(DistributedCache.CDB:22)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$ViewMap$ProxyListener.entryUpdated(DistributedCache.CDB:1)
	at com.tangosol.util.MapEvent.dispatch(MapEvent.java:195)
	at com.tangosol.coherence.component.util.CacheEvent.run(CacheEvent.CDB:18)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.Service$EventDispatcher.onNotify(Service.CDB:19)
	at com.tangosol.coherence.component.util.Daemon.run(Daemon.CDB:37)
	at java.lang.Thread.run(Thread.java:613)
&nbsp;
...
&nbsp;
&quot;main&quot; prio=5 tid=0x01001480 nid=0xb0801000 waiting on condition [0xb07ff000..0xb0800148]
	at java.lang.Thread.sleep(Native Method)
	at com.tangosol.coherence.component.util.Daemon.sleep(Daemon.CDB:9)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid$EventDispatcher.drainOverflow(Grid.CDB:15)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.post(Grid.CDB:17)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.send(Grid.CDB:1)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.poll(Grid.CDB:12)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.poll(Grid.CDB:11)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$BinaryMap.unlock(DistributedCache.CDB:32)
	at com.tangosol.util.ConverterCollections$ConverterConcurrentMap.unlock(ConverterCollections.java:2032)
	at com.tangosol.util.ConverterCollections$ConverterNamedCache.unlock(ConverterCollections.java:2555)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$ViewMap.unlock(DistributedCache.CDB:1)
	at com.tangosol.coherence.component.util.SafeNamedCache.unlock(SafeNamedCache.CDB:1)
	at com.tangosol.examples.guardian.GuardianDemo.main(GuardianDemo.java:40)</pre></td></tr></table></div>

<p>We can see that the event dispatcher thread is waiting to acquire a lock for a key.  However, the main thread has that key locked and (in a bit of an ironic twist) is attempting to release the lock.  However, the throttling mechanism has kicked in, and it won&#8217;t allow for any more operations on the cache until the event queue is drained, which will never happen since the queue responsible for draining the event queue is stuck waiting for a lock to be released.</p>
<p>Now, let&#8217;s run it with Coherence 3.5:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="txt" style="font-family:monospace;">Oracle Coherence Version 3.5/459
 Grid Edition: Development mode
Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved.
...
Removed 1248136418346 from 2
Removed 1248136418361 from 2
Removed 1248136418363 from 6
Removed 1248136418365 from 3
Removed 1248136418366 from 6
Removed 1248136418369 from 2
Removed 1248136418367 from 3
Removed 1248136418371 from 6
Removed 1248136418376 from 6
Removed 1248136418389 from 2
Removed 1248136418383 from 6
Removed 1248136418384 from 3
...
Removed 1248136419975 from 3
Removed 1248136420113 from 2
Removed 1248136420114 from 7
Removed 1248136420116 from 2
2009-07-20 20:33:40.473/6.683 Oracle Coherence GE 3.5/459 &lt;Warning&gt; (thread=main, member=1): The event queue appears to be stuck.
Removed 1248136420076 from 12009-07-20 20:33:40.475/6.685 Oracle Coherence GE 3.5/459 &lt;Error&gt; (thread=main, member=1): Full Thread Dump
...
Thread[DistributedCache:EventDispatcher,5,Cluster]
        java.lang.Object.wait(Native Method)
        java.lang.Object.wait(Object.java:474)
        com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.poll(Grid.CDB:31)
        com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.poll(Grid.CDB:11)
        com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$BinaryMap.lock(DistributedCache.CDB:37)
        com.tangosol.util.ConverterCollections$ConverterConcurrentMap.lock(ConverterCollections.java:2024)
        com.tangosol.util.ConverterCollections$ConverterNamedCache.lock(ConverterCollections.java:2539)
        com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$ViewMap.lock(DistributedCache.CDB:1)
        com.tangosol.coherence.component.util.SafeNamedCache.lock(SafeNamedCache.CDB:1)
        com.tangosol.examples.guardian.GuardianDemo.entryUpdated(GuardianDemo.java:56)
        com.tangosol.util.MapEvent.dispatch(MapEvent.java:210)
        com.tangosol.util.MapEvent.dispatch(MapEvent.java:166)
        com.tangosol.util.MapListenerSupport.fireEvent(MapListenerSupport.java:556)
        com.tangosol.coherence.component.util.SafeNamedCache.translateMapEvent(SafeNamedCache.CDB:7)
        com.tangosol.coherence.component.util.SafeNamedCache.entryUpdated(SafeNamedCache.CDB:1)
        com.tangosol.util.MapEvent.dispatch(MapEvent.java:210)
        com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$ViewMap$ProxyListener.dispatch(DistributedCache.CDB:22)
        com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$ViewMap$ProxyListener.entryUpdated(DistributedCache.CDB:1)
        com.tangosol.util.MapEvent.dispatch(MapEvent.java:210)
        com.tangosol.coherence.component.util.CacheEvent.run(CacheEvent.CDB:18)
        com.tangosol.coherence.component.util.daemon.queueProcessor.Service$EventDispatcher.onNotify(Service.CDB:26)
        com.tangosol.coherence.component.util.Daemon.run(Daemon.CDB:42)
        java.lang.Thread.run(Thread.java:613)
...
Thread[main,5,main]
        java.lang.Thread.dumpThreads(Native Method)
        java.lang.Thread.getAllStackTraces(Thread.java:1460)
        sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        java.lang.reflect.Method.invoke(Method.java:585)
        com.tangosol.net.GuardSupport.logStackTraces(GuardSupport.java:791)
        com.tangosol.coherence.component.util.daemon.queueProcessor.Service$EventDispatcher.drainOverflow(Service.CDB:45)
        com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid$EventDispatcher.drainOverflow(Grid.CDB:9)
        com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.post(Grid.CDB:17)
        com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.send(Grid.CDB:1)
        com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.poll(Grid.CDB:12)
        com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.poll(Grid.CDB:11)
        com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$BinaryMap.unlock(DistributedCache.CDB:32)
        com.tangosol.util.ConverterCollections$ConverterConcurrentMap.unlock(ConverterCollections.java:2032)
        com.tangosol.util.ConverterCollections$ConverterNamedCache.unlock(ConverterCollections.java:2555)
        com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$ViewMap.unlock(DistributedCache.CDB:1)
        com.tangosol.coherence.component.util.SafeNamedCache.unlock(SafeNamedCache.CDB:1)
        com.tangosol.examples.guardian.GuardianDemo.main(GuardianDemo.java:40)</pre></td></tr></table></div>

<p>Here the guardian took the following actions:</p>
<ol>
<li>Detected the stuck event dispatcher thread: <code>&lt;Warning&gt; (thread=main, member=1): The event queue appears to be stuck.</code>
<li>Printed the stacks of each thread
<li>Restarted the cluster threads in order to keep the node up and running
</ol>
<p>Much nicer than having a deadlocked node!</p>
<h3>Bugs in Coherence code</h3>
<p>Despite our best efforts, bugs (including deadlocks) do occasionally appear in Coherence (just like any other product.)  In particular, the kind of deadlock that has the worse consequences is a deadlock that involves a Service thread.  Everything in Coherence (the clustering logic, replicated caches, distributed caches, remote invocations, statistics, etc) is implemented internally using queues and threads that are responsible for processing messages in queues.  These are the service threads, and they are the lifeblood of Coherence.  If this type of defect should slip into any future versions of Coherence, the guardian will detect this condition and take corrective action to allow the node (and the cluster) to continue to function.</p>
<h3>Bugs in the JVM/Operating System</h3>
<p>In the absence of bugs in customer or Coherence code, we do occasionally see bugs in the JVM and/or the operating system that result in locked up service threads.  Perhaps the most notorious of these is with early versions of <a href="http://coherence.oracle.com/display/COH35UG/Deployment+Considerations+-+Linux">NPTL on Linux</a>.  In a nutshell, we saw that threads occasionally missed notifications (in other words, threads that were in <code>Object.wait()</code> would never receive the <code>Object.notify()</code> or <code>Object.notifyAll()</code> that we sent to it.)  I&#8217;ve also seen older JVMs with buggy implementations of the wait/notify mechanism with the same results.</p>
<p>One of our goals with Coherence is to keep your application up and running at all times, even when components of the system fail (hardware, databases, etc.)  This is yet one more tool in our arsenal to bring us closer to that goal.</p>
]]></content:encoded>
			<wfw:commentRss>https://blackbeanbag.net/wp/2009/07/20/coherence-3-5-service-guardian-deadlock-detection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
