<?xml version="1.0"?><rss version="2.0">
<channel>
  <title>Java Beans dot Asia - clustering category</title>
  <link>http://javabeans.asia/categories/clustering/</link>
  <description>Just a few simple tutorials</description>
  <language>en</language>
  <copyright>Alexander Zagniotov</copyright>
  <lastBuildDate>Tue, 23 Feb 2010 11:04:00 GMT</lastBuildDate>
  <generator>Pebble (http://pebble.sourceforge.net)</generator>
  <docs>http://backend.userland.com/rss</docs>
  <image>
    <url>/images/blog-image.jpg</url>
    <title>Java Beans dot Asia (clustering category)</title>
    <link>http://javabeans.asia/</link>
  </image>
  <item>
    <title>JBoss Clustering Architecture - Distributed Replicant Manager</title>
    <link>http://javabeans.asia/2008/05/31/jboss_clustering_architecture_distributed_replicant_manager.html</link>
	 <description>
        My understanding of Distributed Replicant Manager (DRM) is that it allows you to attach some serialized data (stub) to a cluster node and manage it. &lt;br /&gt;
&lt;br /&gt;
Examples of this data include the list of stubs for a given RMI server. Each node has a stub to share with other nodes. The DRM enables the sharing of these stubs in the cluster, and allows one to know which node each stub belongs to.&lt;br /&gt;
&lt;br /&gt;
In case one of the nodes leaves the cluster, its stub is automatically removed from the list of replicants (stubs) that DRM maintains. &lt;br /&gt;
&lt;br /&gt;
Also for each set of replicants DRM holds an id, which is identical on all nodes in the cluster.&lt;br /&gt;
&lt;br /&gt;
I used DRM to attach a replicant to a node in the cluster. The replicant contains a String which holds a node IP that i get from &lt;em&gt;jboss.bind.address &lt;/em&gt;property. Every time my cluster is going through a topology changes, my service bean on the master node will prints out replicant list.&lt;br /&gt;
&lt;br /&gt;
My service MBean as follows:
&lt;pre name=&#034;code&#034; class=&#034;java:firstline[1]&#034;&gt;package com.example;&lt;br /&gt;&lt;br /&gt;public class CoordinatorHAService extends &lt;br /&gt;	HASingletonSupport implements &lt;br /&gt;			CoordinatorHAServiceMBean  {&lt;br /&gt;&lt;br /&gt;    private static Logger logger = &lt;br /&gt;	Logger.getLogger(CoordinatorHAService.class);&lt;br /&gt; &lt;br /&gt;	/**&lt;br /&gt;	 * Can be used instead of the constructor &lt;br /&gt;	 * defined in jboss-service.xml&lt;br /&gt;	 */&lt;br /&gt;	private static final String BIND_ADDRESS = &lt;br /&gt;		System.getProperty(&amp;quot;jboss.bind.address&amp;quot;);&lt;br /&gt;&lt;br /&gt;	/**&lt;br /&gt;	 * Custom name for this HA partition, overrides &lt;br /&gt;	 * the default HA partition name which is &lt;br /&gt;	 * canonical name of this MBean&lt;br /&gt;	 */&lt;br /&gt;	private final static &lt;br /&gt;	String COORDINATOR_HA_SERVICE_NAME = &lt;br /&gt;		&amp;quot;ServiceName:CoordinatorHAService&amp;quot;;&lt;br /&gt;	&lt;br /&gt;	/**&lt;br /&gt;	 * Current node IP&lt;br /&gt;	 */&lt;br /&gt;	private String nodeIp = null;&lt;br /&gt;&lt;br /&gt;	/**&lt;br /&gt;	 * Constructor that gets value of this node IP &lt;br /&gt;	 * from &#039;jboss.bind.address&#039; property&lt;br /&gt;	 * defined in jboss-service.xml&lt;br /&gt;	 * &lt;br /&gt;	 */&lt;br /&gt;	public CoordinatorHAService(String nodeIp) {&lt;br /&gt;		this.nodeIp = nodeIp;&lt;br /&gt;&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	public void startService() throws Exception {&lt;br /&gt;&lt;br /&gt;	try {&lt;br /&gt;	/**&lt;br /&gt;	 * Call for super must be done before getting&lt;br /&gt;	 * HAPartition. If super is not called, HAPartition&lt;br /&gt;	 * will be &#039;null&#039;&lt;br /&gt;	 *&lt;br /&gt;	 * Alternatively you can use InitialContext to get &lt;br /&gt;	 * default partition, then you dont have to make &lt;br /&gt;	 * a call for super.startService(). I havent&lt;br /&gt;	 * tested it, so I am not sure of the results. &lt;br /&gt;	 *&lt;br /&gt;	 *&lt;br /&gt;	 * InitialContext ic = new InitialContext();&lt;br /&gt;	 * String partitionName = ServerConfigUtil.getDefaultPartitionName();&lt;br /&gt;	 * String partitionJndi = &amp;quot;/HAPartition/&amp;quot; + partitionName;&lt;br /&gt;	 * HAPartition partition = (HAPartition) ic.lookup(partitionJndi);&lt;br /&gt;	 */&lt;br /&gt;		super.startService();&lt;br /&gt;&lt;br /&gt;	/**&lt;br /&gt;	 * HAPartition gives access to the replicant manager,&lt;br /&gt;	 * which I am using to add node replicants to.&lt;br /&gt;	 */&lt;br /&gt;		HAPartition partition = super.getPartition();&lt;br /&gt;&lt;br /&gt;		if (partition != null) {&lt;br /&gt;			partition.getDistributedReplicantManager().add(&lt;br /&gt;					this.getServiceHAName(), this.getNodeIp());&lt;br /&gt;		}&lt;br /&gt;&lt;br /&gt;		} catch (Exception e) {&lt;br /&gt;			this.stopService();&lt;br /&gt;		}&lt;br /&gt;&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	synchronized public void stopService() throws Exception {&lt;br /&gt;		super.stopService();&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	public boolean isMasterNode() {&lt;br /&gt;		return super.isMasterNode();&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	/**&lt;br /&gt;	 * Called when node is elected as a master node&lt;br /&gt;	 */&lt;br /&gt;	public void startSingleton() {&lt;br /&gt;	&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	/**&lt;br /&gt;	 * Called when node stops acting as a master node&lt;br /&gt;	 */&lt;br /&gt;	public void stopSingleton() {&lt;br /&gt;&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	/**&lt;br /&gt;	 * Override this method only if you need to provide &lt;br /&gt;	 * a custom partition wide unique service name. &lt;br /&gt;	 * The default implementation will usually work,&lt;br /&gt;	 * provided that the getServiceName() method returns &lt;br /&gt;	 * a unique canonical MBean name.&lt;br /&gt;	 * &lt;br /&gt;	 */&lt;br /&gt;	public String getServiceHAName() {&lt;br /&gt;		// return super.getServiceHAName();&lt;br /&gt;		return CoordinatorHAService.COORDINATOR_HA_SERVICE_NAME;&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	/**&lt;br /&gt;	 * Called when there are topology changes in the cluster.&lt;br /&gt;	 */&lt;br /&gt;	public void partitionTopologyChanged(List newReplicants, &lt;br /&gt;												int newViewID) {&lt;br /&gt;		super.partitionTopologyChanged(newReplicants, &lt;br /&gt;												newViewID);&lt;br /&gt;&lt;br /&gt;		/**&lt;br /&gt;		 * If current service is the master node - &lt;br /&gt;		 * print replicants in the cluster&lt;br /&gt;		 */&lt;br /&gt;		if (this.isMasterNode()) {&lt;br /&gt;			&lt;br /&gt;			List&lt;string&gt; clusterNodeIps = &lt;br /&gt;				new LinkedList&lt;string&gt;(newReplicants);&lt;br /&gt;&lt;br /&gt;			for (String clusterNodeIp : clusterNodeIps) {&lt;br /&gt;				logger.info(&amp;quot;Replicant IP: &amp;quot; + clusterNodeIp);	&lt;br /&gt;			}&lt;br /&gt;		}&lt;br /&gt;&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	/**&lt;br /&gt;	 * Gets current node&#039;s IP&lt;br /&gt;	 */&lt;br /&gt;	public String getNodeIp() {&lt;br /&gt;		return nodeIp;&lt;br /&gt;	}&lt;br /&gt;} &lt;/string&gt;&lt;/string&gt;&lt;/pre&gt;
..and this is my &lt;em&gt;jboss-service.xml&lt;/em&gt; below:
&lt;pre class=&#034;xml:firstline[1]&#034; name=&#034;code&#034;&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;server&amp;gt;&lt;br /&gt;    &amp;lt;mbean&lt;br /&gt;	code=&amp;quot;com.example.CoordinatorHAService&amp;quot;&lt;br /&gt;	name=&amp;quot;com.example:service=CoordinatorHAService&amp;quot;&amp;gt;&lt;br /&gt;	&amp;lt;constructor&amp;gt;&lt;br /&gt;	&amp;lt;arg type=&amp;quot;java.lang.String&amp;quot;&lt;br /&gt;		value=&amp;quot;${jboss.bind.address:127.0.0.1}&amp;quot; /&amp;gt;&lt;br /&gt;	  &amp;lt;/constructor&amp;gt;&lt;br /&gt;     &amp;lt;/mbean&amp;gt;&lt;br /&gt;&amp;lt;/server&amp;gt;&lt;/pre&gt;
In JBoss clustering architecture, DRM sits on top of HAPartition which abstracts the communication framework.&lt;br /&gt;
&lt;br /&gt;
Maybe this is not the most right way to do it, but I do find DRM useful if I want to manage information about my cluster nodes, and I dont want to rely on HAPartition to provide me with such information. &lt;br /&gt;
&lt;br /&gt;
The moment a new node joins the cluster, I insert its IP to my set of replicants. So I always have accurate and recent information about nodes in my cluster. In case of a dead node, my list of replicants gets updated with IP of the dead node removed from the list. The source code is attached to this post or you can just do copy/paste if you feel like it.&lt;br /&gt;
&lt;br /&gt;
JBoss clustering is a very big topic. So if someone is interested, JBoss group provides a PDF book called &lt;a href=&#034;http://docs.jboss.org/jbossas/clustering/JBossClustering7.pdf&#034; target=&#034;_blank&#034;&gt;JBoss AS Clustering&lt;/a&gt; on their website, its really useful and easy to understand. It walks through and talks about fundamental concepts of clustering. The book is a bit long but worth while to have a look ;)&lt;br /&gt;
&lt;br /&gt;
Any comments or/and flames about this post are welcomed ...&lt;br /&gt;
&lt;br /&gt;
cheers&lt;div class=&#034;tags&#034;&gt;&lt;span&gt;Social Bookmarks : &lt;/span&gt;&amp;nbsp;&lt;a href=&#034;http://slashdot.org/bookmark.pl?url=http://javabeans.asia/2008/05/31/jboss_clustering_architecture_distributed_replicant_manager.html&amp;amp;title=JBoss Clustering Architecture - Distributed Replicant Manager&#034; target=&#034;_blank&#034; title=&#034;Add this post to Slash Dot&#034;&gt;&lt;img src=&#034;common/images/slashdot.png&#034; alt=&#034;Add this post to Slashdot&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://digg.com/submit?url=http://javabeans.asia/2008/05/31/jboss_clustering_architecture_distributed_replicant_manager.html&amp;amp;title=JBoss Clustering Architecture - Distributed Replicant Manager&#034; target=&#034;_blank&#034; title=&#034;Digg this post&#034;&gt;&lt;img src=&#034;common/images/digg.png&#034; alt=&#034;Add this post to Digg&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://reddit.com/submit?url=http://javabeans.asia/2008/05/31/jboss_clustering_architecture_distributed_replicant_manager.html&amp;amp;title=JBoss Clustering Architecture - Distributed Replicant Manager&#034; target=&#034;_blank&#034; title=&#034;Add this post to Reddit&#034;&gt;&lt;img src=&#034;common/images/reddit.png&#034; alt=&#034;Add this post to Reddit&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://del.icio.us/post?url=http://javabeans.asia/2008/05/31/jboss_clustering_architecture_distributed_replicant_manager.html&amp;amp;title=JBoss Clustering Architecture - Distributed Replicant Manager&#034; target=&#034;_blank&#034; title=&#034;Save this post to Del.icio.us&#034;&gt;&lt;img src=&#034;common/images/delicious.png&#034; alt=&#034;Add this post to Delicious&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.stumbleupon.com/submit?url=http://javabeans.asia/2008/05/31/jboss_clustering_architecture_distributed_replicant_manager.html&amp;amp;title=JBoss Clustering Architecture - Distributed Replicant Manager&#034; target=&#034;_blank&#034; title=&#034;Stumble this post&#034;&gt;&lt;img src=&#034;common/images/stumbleupon.png&#034; alt=&#034;Add this post to Stumble it&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.google.com/bookmarks/mark?op=edit&amp;amp;bkmk=http://javabeans.asia/2008/05/31/jboss_clustering_architecture_distributed_replicant_manager.html&amp;amp;title=JBoss Clustering Architecture - Distributed Replicant Manager&#034; target=&#034;_blank&#034; title=&#034;Add this post to Google&#034;&gt;&lt;img src=&#034;common/images/google.png&#034; alt=&#034;Add this post to Google&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://technorati.com/faves?add=http://javabeans.asia/2008/05/31/jboss_clustering_architecture_distributed_replicant_manager.html&#034; target=&#034;_blank&#034; title=&#034;Add this post to Technorati&#034;&gt;&lt;img src=&#034;common/images/technorati.png&#034; alt=&#034;Add this post to Technorati&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.bloglines.com/sub/http://javabeans.asia/2008/05/31/jboss_clustering_architecture_distributed_replicant_manager.html&#034; target=&#034;_blank&#034; title=&#034;Add this post to Bloglines&#034;&gt;&lt;img src=&#034;common/images/bloglines.png&#034; alt=&#034;Add this post to Bloglines&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.facebook.com/share.php?u=http://javabeans.asia/2008/05/31/jboss_clustering_architecture_distributed_replicant_manager.html&#034; target=&#034;_blank&#034; title=&#034;Add this post to Facebook&#034;&gt;&lt;img src=&#034;common/images/facebook.png&#034; alt=&#034;Add this post to Facebook&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.furl.net/storeIt.jsp?u=http://javabeans.asia/2008/05/31/jboss_clustering_architecture_distributed_replicant_manager.html&amp;amp;t=JBoss Clustering Architecture - Distributed Replicant Manager&#034; target=&#034;_blank&#034; title=&#034;Add this post to Furl&#034;&gt;&lt;img src=&#034;common/images/furl.png&#034; alt=&#034;Add this post to Furl&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;https://favorites.live.com/quickadd.aspx?mkt=en-us&amp;amp;url=http://javabeans.asia/2008/05/31/jboss_clustering_architecture_distributed_replicant_manager.html&amp;amp;title=JBoss Clustering Architecture - Distributed Replicant Manager&#034; target=&#034;_blank&#034; title=&#034;Add this post to Windows Live&#034;&gt;&lt;img src=&#034;common/images/windowslive.png&#034; alt=&#034;Add this post to Windows Live&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://bookmarks.yahoo.com/toolbar/savebm?opener=tb&amp;amp;u=http://javabeans.asia/2008/05/31/jboss_clustering_architecture_distributed_replicant_manager.html&amp;amp;t=JBoss Clustering Architecture - Distributed Replicant Manager&#034; target=&#034;_blank&#034; title=&#034;Add this post to Yahoo!&#034;&gt;&lt;img src=&#034;common/images/yahoo.png&#034; alt=&#034;Add this post to Yahoo!&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;&lt;b&gt;Related Posts&lt;/b&gt;&lt;br /&gt;&lt;a href=&#034;http://javabeans.asia/2009/08/27/jboss_security_jmx_console.html&#034; rel=&#034;bookmark&#034; title=&#034;JBoss Security - JMX Console&#034;&gt;JBoss Security - JMX Console&lt;/a&gt;&lt;br /&gt;&lt;a href=&#034;http://javabeans.asia/2008/10/24/drools_tutorial_on_writing_dsl_template.html&#034; rel=&#034;bookmark&#034; title=&#034;Drools - tutorial on writing DSL template&#034;&gt;Drools - tutorial on writing DSL template&lt;/a&gt;&lt;br /&gt;&lt;a href=&#034;http://javabeans.asia/2008/06/09/drools_stop_executing_current_agenda_group_and_all_rules.html&#034; rel=&#034;bookmark&#034; title=&#034;Drools - Stop executing current agenda group and all rules&#034;&gt;Drools - Stop executing current agenda group and all rules&lt;/a&gt;&lt;br /&gt;&lt;a href=&#034;http://javabeans.asia/2008/05/01/using_template_to_deploy_a_jboss_queue.html&#034; rel=&#034;bookmark&#034; title=&#034;Using template to deploy a JBoss queue&#034;&gt;Using template to deploy a JBoss queue&lt;/a&gt;&lt;br /&gt;&lt;a href=&#034;http://javabeans.asia/2008/05/03/deployment_of_mbean_separately_to_its_interface.html&#034; rel=&#034;bookmark&#034; title=&#034;Deployment of mbean separately to its interface&#034;&gt;Deployment of mbean separately to its interface&lt;/a&gt;&lt;br /&gt;&lt;a href=&#034;http://javabeans.asia/2008/05/08/jboss_clustering_hasingleton_service.html&#034; rel=&#034;bookmark&#034; title=&#034;JBoss Clustering - HASingleton service&#034;&gt;JBoss Clustering - HASingleton service&lt;/a&gt;&lt;br /&gt;&lt;a href=&#034;http://javabeans.asia/2008/05/11/drools_working_with_stateless_session.html&#034; rel=&#034;bookmark&#034; title=&#034;Drools - working with Stateless session&#034;&gt;Drools - working with Stateless session&lt;/a&gt;&lt;br /&gt;&lt;a href=&#034;http://javabeans.asia/2008/05/11/stateless_beans_and_annotations.html&#034; rel=&#034;bookmark&#034; title=&#034;Stateless beans and annotations&#034;&gt;Stateless beans and annotations&lt;/a&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;</description>
	<!--
    <description>
          My understanding of Distributed Replicant Manager (DRM) is that it allows you to attach some serialized data (stub) to a cluster node and manage it.   Examples of this data include the list of stubs for a given RMI server. Each node has a stub to share with other nodes. The DRM enables the sharing of these stubs in ...&lt;p&gt;&lt;a href=&#034;http://javabeans.asia/2008/05/31/jboss_clustering_architecture_distributed_replicant_manager.html&#034;&gt;Read more...&lt;/a&gt;&lt;/p&gt;&lt;div class=&#034;tags&#034;&gt;&lt;span&gt;Social Bookmarks : &lt;/span&gt;&amp;nbsp;&lt;a href=&#034;http://slashdot.org/bookmark.pl?url=http://javabeans.asia/2008/05/31/jboss_clustering_architecture_distributed_replicant_manager.html&amp;amp;title=JBoss Clustering Architecture - Distributed Replicant Manager&#034; target=&#034;_blank&#034; title=&#034;Add this post to Slash Dot&#034;&gt;&lt;img src=&#034;common/images/slashdot.png&#034; alt=&#034;Add this post to Slashdot&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://digg.com/submit?url=http://javabeans.asia/2008/05/31/jboss_clustering_architecture_distributed_replicant_manager.html&amp;amp;title=JBoss Clustering Architecture - Distributed Replicant Manager&#034; target=&#034;_blank&#034; title=&#034;Digg this post&#034;&gt;&lt;img src=&#034;common/images/digg.png&#034; alt=&#034;Add this post to Digg&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://reddit.com/submit?url=http://javabeans.asia/2008/05/31/jboss_clustering_architecture_distributed_replicant_manager.html&amp;amp;title=JBoss Clustering Architecture - Distributed Replicant Manager&#034; target=&#034;_blank&#034; title=&#034;Add this post to Reddit&#034;&gt;&lt;img src=&#034;common/images/reddit.png&#034; alt=&#034;Add this post to Reddit&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://del.icio.us/post?url=http://javabeans.asia/2008/05/31/jboss_clustering_architecture_distributed_replicant_manager.html&amp;amp;title=JBoss Clustering Architecture - Distributed Replicant Manager&#034; target=&#034;_blank&#034; title=&#034;Save this post to Del.icio.us&#034;&gt;&lt;img src=&#034;common/images/delicious.png&#034; alt=&#034;Add this post to Delicious&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.stumbleupon.com/submit?url=http://javabeans.asia/2008/05/31/jboss_clustering_architecture_distributed_replicant_manager.html&amp;amp;title=JBoss Clustering Architecture - Distributed Replicant Manager&#034; target=&#034;_blank&#034; title=&#034;Stumble this post&#034;&gt;&lt;img src=&#034;common/images/stumbleupon.png&#034; alt=&#034;Add this post to Stumble it&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.google.com/bookmarks/mark?op=edit&amp;amp;bkmk=http://javabeans.asia/2008/05/31/jboss_clustering_architecture_distributed_replicant_manager.html&amp;amp;title=JBoss Clustering Architecture - Distributed Replicant Manager&#034; target=&#034;_blank&#034; title=&#034;Add this post to Google&#034;&gt;&lt;img src=&#034;common/images/google.png&#034; alt=&#034;Add this post to Google&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://technorati.com/faves?add=http://javabeans.asia/2008/05/31/jboss_clustering_architecture_distributed_replicant_manager.html&#034; target=&#034;_blank&#034; title=&#034;Add this post to Technorati&#034;&gt;&lt;img src=&#034;common/images/technorati.png&#034; alt=&#034;Add this post to Technorati&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.bloglines.com/sub/http://javabeans.asia/2008/05/31/jboss_clustering_architecture_distributed_replicant_manager.html&#034; target=&#034;_blank&#034; title=&#034;Add this post to Bloglines&#034;&gt;&lt;img src=&#034;common/images/bloglines.png&#034; alt=&#034;Add this post to Bloglines&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.facebook.com/share.php?u=http://javabeans.asia/2008/05/31/jboss_clustering_architecture_distributed_replicant_manager.html&#034; target=&#034;_blank&#034; title=&#034;Add this post to Facebook&#034;&gt;&lt;img src=&#034;common/images/facebook.png&#034; alt=&#034;Add this post to Facebook&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.furl.net/storeIt.jsp?u=http://javabeans.asia/2008/05/31/jboss_clustering_architecture_distributed_replicant_manager.html&amp;amp;t=JBoss Clustering Architecture - Distributed Replicant Manager&#034; target=&#034;_blank&#034; title=&#034;Add this post to Furl&#034;&gt;&lt;img src=&#034;common/images/furl.png&#034; alt=&#034;Add this post to Furl&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;https://favorites.live.com/quickadd.aspx?mkt=en-us&amp;amp;url=http://javabeans.asia/2008/05/31/jboss_clustering_architecture_distributed_replicant_manager.html&amp;amp;title=JBoss Clustering Architecture - Distributed Replicant Manager&#034; target=&#034;_blank&#034; title=&#034;Add this post to Windows Live&#034;&gt;&lt;img src=&#034;common/images/windowslive.png&#034; alt=&#034;Add this post to Windows Live&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://bookmarks.yahoo.com/toolbar/savebm?opener=tb&amp;amp;u=http://javabeans.asia/2008/05/31/jboss_clustering_architecture_distributed_replicant_manager.html&amp;amp;t=JBoss Clustering Architecture - Distributed Replicant Manager&#034; target=&#034;_blank&#034; title=&#034;Add this post to Yahoo!&#034;&gt;&lt;img src=&#034;common/images/yahoo.png&#034; alt=&#034;Add this post to Yahoo!&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&lt;/div&gt;</description>
      
	-->
    <enclosure url="http://javabeans.asia/files/src/jboss_clustering_replicant_manager.zip" length="1737" type="application/zip" />
    <category>clustering</category>
    <category>jboss</category>
    <category>management beans</category>
    <comments>http://javabeans.asia/2008/05/31/jboss_clustering_architecture_distributed_replicant_manager.html#comments</comments>
    <guid isPermaLink="true">http://javabeans.asia/2008/05/31/jboss_clustering_architecture_distributed_replicant_manager.html</guid>
    <pubDate>Sat, 31 May 2008 07:37:00 GMT</pubDate>
  </item>
  <item>
    <title>JBoss Clustering - Shared state across cluster partition</title>
    <link>http://javabeans.asia/2008/05/16/jboss_clustering_shared_state_across_cluster_partition.html</link>
	 <description>
        Did you know that if you have a JBoss cluster, HA singletons service beans on each can share a common memory state? State is a memory space shared by all HA singletons service beans in a cluster. It is possible save an object to the state using HA singleton service bean on one node, and to retrieve that object on another node.&lt;br /&gt;
&lt;br /&gt;
The implementation is very easy. Lets assume you have two nodes in a cluster, on each node you have HA singleton service bean running. Lets call them &amp;quot;&lt;em&gt;service A&lt;/em&gt;&amp;quot; and &amp;quot;&lt;em&gt;service B&lt;/em&gt;&amp;quot;. Your service beans should extend from &lt;em&gt;HASingletonSupport &lt;/em&gt;class. &lt;em&gt;HASingletonSupport&lt;/em&gt; in its turn extends from &lt;em&gt;HAServiceMBeanSupport. &lt;/em&gt;The latter gives you access to two methods:
&lt;pre class=&#034;codeSample&#034;&gt;public void setDistributedState(String key,&lt;br /&gt;                                Serializable value)&lt;br /&gt;                         throws Exception&lt;br /&gt;&lt;/pre&gt;
and
&lt;pre class=&#034;codeSample&#034;&gt;public Serializable getDistributedState(String key)&lt;br /&gt;&lt;/pre&gt;
These are convenience which allow you to save and retrieve objects from shared state. It can be whatever you want - primitive data types or even POJOs.&lt;br /&gt;
&lt;br /&gt;
Lets say somewhere inside you &lt;em&gt;service A&lt;/em&gt;, you have the following method:
&lt;pre name=&#034;code&#034; class=&#034;java:nocontrols:firstline[1]&#034;&gt;public void setObjectToSharedState()  {&lt;br /&gt;      String key = &amp;quot;test-1&amp;quot;;&lt;br /&gt;      String value = &amp;quot;Testing memory state&amp;quot;;&lt;br /&gt;&lt;br /&gt; 	try {&lt;br /&gt;	    this.setDistributedState(key, value);&lt;br /&gt;	}&lt;br /&gt;	catch (Exception e)  {&lt;br /&gt;		e.printStackTrace();&lt;br /&gt;	}&lt;br /&gt;}&lt;/pre&gt;
Now, what has happened is that you, by using your &lt;em&gt;service A&lt;/em&gt; saved into the shared memory a String value, under a key name &amp;quot;&lt;em&gt;test-1&lt;/em&gt;&amp;quot;. This key name you can use in your &lt;em&gt;service B&lt;/em&gt; to retrieve its corresponding value from the shared memory, in this case a String. Lets say the following method is sitting somewhere in your &lt;em&gt;service B&lt;/em&gt; bean, on another node in the cluster:&lt;br /&gt;
&lt;pre name=&#034;code&#034; class=&#034;java:nocontrols:firstline[1]&#034;&gt;public void getObjectFromSharedState()  {&lt;br /&gt;      String key = &amp;quot;test-1&amp;quot;;&lt;br /&gt;      String value = (String) this.getDistributedState(key);&lt;br /&gt;      System.out.println(&amp;quot;The value is: &amp;quot; + value);&lt;br /&gt;}&lt;/pre&gt;
By specifying a key name, you can retrieve back from the shared memory what ever is saved under that key. You just have to know the type to cast it back to. &lt;br /&gt;
Also keep in mind: if you specify wrong key name, the retrieved object will be &lt;em&gt;null&lt;/em&gt;.&lt;br /&gt;
&lt;br /&gt;
Shared memory state is another option, if you want to share something between your nodes, and for some reason you don&#039;t want to use JBoss cache.&lt;div class=&#034;tags&#034;&gt;&lt;span&gt;Social Bookmarks : &lt;/span&gt;&amp;nbsp;&lt;a href=&#034;http://slashdot.org/bookmark.pl?url=http://javabeans.asia/2008/05/16/jboss_clustering_shared_state_across_cluster_partition.html&amp;amp;title=JBoss Clustering - Shared state across cluster partition&#034; target=&#034;_blank&#034; title=&#034;Add this post to Slash Dot&#034;&gt;&lt;img src=&#034;common/images/slashdot.png&#034; alt=&#034;Add this post to Slashdot&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://digg.com/submit?url=http://javabeans.asia/2008/05/16/jboss_clustering_shared_state_across_cluster_partition.html&amp;amp;title=JBoss Clustering - Shared state across cluster partition&#034; target=&#034;_blank&#034; title=&#034;Digg this post&#034;&gt;&lt;img src=&#034;common/images/digg.png&#034; alt=&#034;Add this post to Digg&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://reddit.com/submit?url=http://javabeans.asia/2008/05/16/jboss_clustering_shared_state_across_cluster_partition.html&amp;amp;title=JBoss Clustering - Shared state across cluster partition&#034; target=&#034;_blank&#034; title=&#034;Add this post to Reddit&#034;&gt;&lt;img src=&#034;common/images/reddit.png&#034; alt=&#034;Add this post to Reddit&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://del.icio.us/post?url=http://javabeans.asia/2008/05/16/jboss_clustering_shared_state_across_cluster_partition.html&amp;amp;title=JBoss Clustering - Shared state across cluster partition&#034; target=&#034;_blank&#034; title=&#034;Save this post to Del.icio.us&#034;&gt;&lt;img src=&#034;common/images/delicious.png&#034; alt=&#034;Add this post to Delicious&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.stumbleupon.com/submit?url=http://javabeans.asia/2008/05/16/jboss_clustering_shared_state_across_cluster_partition.html&amp;amp;title=JBoss Clustering - Shared state across cluster partition&#034; target=&#034;_blank&#034; title=&#034;Stumble this post&#034;&gt;&lt;img src=&#034;common/images/stumbleupon.png&#034; alt=&#034;Add this post to Stumble it&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.google.com/bookmarks/mark?op=edit&amp;amp;bkmk=http://javabeans.asia/2008/05/16/jboss_clustering_shared_state_across_cluster_partition.html&amp;amp;title=JBoss Clustering - Shared state across cluster partition&#034; target=&#034;_blank&#034; title=&#034;Add this post to Google&#034;&gt;&lt;img src=&#034;common/images/google.png&#034; alt=&#034;Add this post to Google&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://technorati.com/faves?add=http://javabeans.asia/2008/05/16/jboss_clustering_shared_state_across_cluster_partition.html&#034; target=&#034;_blank&#034; title=&#034;Add this post to Technorati&#034;&gt;&lt;img src=&#034;common/images/technorati.png&#034; alt=&#034;Add this post to Technorati&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.bloglines.com/sub/http://javabeans.asia/2008/05/16/jboss_clustering_shared_state_across_cluster_partition.html&#034; target=&#034;_blank&#034; title=&#034;Add this post to Bloglines&#034;&gt;&lt;img src=&#034;common/images/bloglines.png&#034; alt=&#034;Add this post to Bloglines&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.facebook.com/share.php?u=http://javabeans.asia/2008/05/16/jboss_clustering_shared_state_across_cluster_partition.html&#034; target=&#034;_blank&#034; title=&#034;Add this post to Facebook&#034;&gt;&lt;img src=&#034;common/images/facebook.png&#034; alt=&#034;Add this post to Facebook&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.furl.net/storeIt.jsp?u=http://javabeans.asia/2008/05/16/jboss_clustering_shared_state_across_cluster_partition.html&amp;amp;t=JBoss Clustering - Shared state across cluster partition&#034; target=&#034;_blank&#034; title=&#034;Add this post to Furl&#034;&gt;&lt;img src=&#034;common/images/furl.png&#034; alt=&#034;Add this post to Furl&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;https://favorites.live.com/quickadd.aspx?mkt=en-us&amp;amp;url=http://javabeans.asia/2008/05/16/jboss_clustering_shared_state_across_cluster_partition.html&amp;amp;title=JBoss Clustering - Shared state across cluster partition&#034; target=&#034;_blank&#034; title=&#034;Add this post to Windows Live&#034;&gt;&lt;img src=&#034;common/images/windowslive.png&#034; alt=&#034;Add this post to Windows Live&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://bookmarks.yahoo.com/toolbar/savebm?opener=tb&amp;amp;u=http://javabeans.asia/2008/05/16/jboss_clustering_shared_state_across_cluster_partition.html&amp;amp;t=JBoss Clustering - Shared state across cluster partition&#034; target=&#034;_blank&#034; title=&#034;Add this post to Yahoo!&#034;&gt;&lt;img src=&#034;common/images/yahoo.png&#034; alt=&#034;Add this post to Yahoo!&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;&lt;b&gt;Related Posts&lt;/b&gt;&lt;br /&gt;&lt;a href=&#034;http://javabeans.asia/2009/08/27/jboss_security_jmx_console.html&#034; rel=&#034;bookmark&#034; title=&#034;JBoss Security - JMX Console&#034;&gt;JBoss Security - JMX Console&lt;/a&gt;&lt;br /&gt;&lt;a href=&#034;http://javabeans.asia/2008/10/24/drools_tutorial_on_writing_dsl_template.html&#034; rel=&#034;bookmark&#034; title=&#034;Drools - tutorial on writing DSL template&#034;&gt;Drools - tutorial on writing DSL template&lt;/a&gt;&lt;br /&gt;&lt;a href=&#034;http://javabeans.asia/2008/06/09/drools_stop_executing_current_agenda_group_and_all_rules.html&#034; rel=&#034;bookmark&#034; title=&#034;Drools - Stop executing current agenda group and all rules&#034;&gt;Drools - Stop executing current agenda group and all rules&lt;/a&gt;&lt;br /&gt;&lt;a href=&#034;http://javabeans.asia/2008/05/01/using_template_to_deploy_a_jboss_queue.html&#034; rel=&#034;bookmark&#034; title=&#034;Using template to deploy a JBoss queue&#034;&gt;Using template to deploy a JBoss queue&lt;/a&gt;&lt;br /&gt;&lt;a href=&#034;http://javabeans.asia/2008/05/03/deployment_of_mbean_separately_to_its_interface.html&#034; rel=&#034;bookmark&#034; title=&#034;Deployment of mbean separately to its interface&#034;&gt;Deployment of mbean separately to its interface&lt;/a&gt;&lt;br /&gt;&lt;a href=&#034;http://javabeans.asia/2008/05/08/jboss_clustering_hasingleton_service.html&#034; rel=&#034;bookmark&#034; title=&#034;JBoss Clustering - HASingleton service&#034;&gt;JBoss Clustering - HASingleton service&lt;/a&gt;&lt;br /&gt;&lt;a href=&#034;http://javabeans.asia/2008/05/11/drools_working_with_stateless_session.html&#034; rel=&#034;bookmark&#034; title=&#034;Drools - working with Stateless session&#034;&gt;Drools - working with Stateless session&lt;/a&gt;&lt;br /&gt;&lt;a href=&#034;http://javabeans.asia/2008/05/11/stateless_beans_and_annotations.html&#034; rel=&#034;bookmark&#034; title=&#034;Stateless beans and annotations&#034;&gt;Stateless beans and annotations&lt;/a&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;</description>
	<!--
    <description>
          Did you know that if you have a JBoss cluster, HA singletons service beans on each can share a common memory state? State is a memory space shared by all HA singletons service beans in a cluster. It is possible save an object to the state using HA singleton service bean on one node, and to retrieve that object on ...&lt;p&gt;&lt;a href=&#034;http://javabeans.asia/2008/05/16/jboss_clustering_shared_state_across_cluster_partition.html&#034;&gt;Read more...&lt;/a&gt;&lt;/p&gt;&lt;div class=&#034;tags&#034;&gt;&lt;span&gt;Social Bookmarks : &lt;/span&gt;&amp;nbsp;&lt;a href=&#034;http://slashdot.org/bookmark.pl?url=http://javabeans.asia/2008/05/16/jboss_clustering_shared_state_across_cluster_partition.html&amp;amp;title=JBoss Clustering - Shared state across cluster partition&#034; target=&#034;_blank&#034; title=&#034;Add this post to Slash Dot&#034;&gt;&lt;img src=&#034;common/images/slashdot.png&#034; alt=&#034;Add this post to Slashdot&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://digg.com/submit?url=http://javabeans.asia/2008/05/16/jboss_clustering_shared_state_across_cluster_partition.html&amp;amp;title=JBoss Clustering - Shared state across cluster partition&#034; target=&#034;_blank&#034; title=&#034;Digg this post&#034;&gt;&lt;img src=&#034;common/images/digg.png&#034; alt=&#034;Add this post to Digg&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://reddit.com/submit?url=http://javabeans.asia/2008/05/16/jboss_clustering_shared_state_across_cluster_partition.html&amp;amp;title=JBoss Clustering - Shared state across cluster partition&#034; target=&#034;_blank&#034; title=&#034;Add this post to Reddit&#034;&gt;&lt;img src=&#034;common/images/reddit.png&#034; alt=&#034;Add this post to Reddit&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://del.icio.us/post?url=http://javabeans.asia/2008/05/16/jboss_clustering_shared_state_across_cluster_partition.html&amp;amp;title=JBoss Clustering - Shared state across cluster partition&#034; target=&#034;_blank&#034; title=&#034;Save this post to Del.icio.us&#034;&gt;&lt;img src=&#034;common/images/delicious.png&#034; alt=&#034;Add this post to Delicious&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.stumbleupon.com/submit?url=http://javabeans.asia/2008/05/16/jboss_clustering_shared_state_across_cluster_partition.html&amp;amp;title=JBoss Clustering - Shared state across cluster partition&#034; target=&#034;_blank&#034; title=&#034;Stumble this post&#034;&gt;&lt;img src=&#034;common/images/stumbleupon.png&#034; alt=&#034;Add this post to Stumble it&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.google.com/bookmarks/mark?op=edit&amp;amp;bkmk=http://javabeans.asia/2008/05/16/jboss_clustering_shared_state_across_cluster_partition.html&amp;amp;title=JBoss Clustering - Shared state across cluster partition&#034; target=&#034;_blank&#034; title=&#034;Add this post to Google&#034;&gt;&lt;img src=&#034;common/images/google.png&#034; alt=&#034;Add this post to Google&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://technorati.com/faves?add=http://javabeans.asia/2008/05/16/jboss_clustering_shared_state_across_cluster_partition.html&#034; target=&#034;_blank&#034; title=&#034;Add this post to Technorati&#034;&gt;&lt;img src=&#034;common/images/technorati.png&#034; alt=&#034;Add this post to Technorati&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.bloglines.com/sub/http://javabeans.asia/2008/05/16/jboss_clustering_shared_state_across_cluster_partition.html&#034; target=&#034;_blank&#034; title=&#034;Add this post to Bloglines&#034;&gt;&lt;img src=&#034;common/images/bloglines.png&#034; alt=&#034;Add this post to Bloglines&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.facebook.com/share.php?u=http://javabeans.asia/2008/05/16/jboss_clustering_shared_state_across_cluster_partition.html&#034; target=&#034;_blank&#034; title=&#034;Add this post to Facebook&#034;&gt;&lt;img src=&#034;common/images/facebook.png&#034; alt=&#034;Add this post to Facebook&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.furl.net/storeIt.jsp?u=http://javabeans.asia/2008/05/16/jboss_clustering_shared_state_across_cluster_partition.html&amp;amp;t=JBoss Clustering - Shared state across cluster partition&#034; target=&#034;_blank&#034; title=&#034;Add this post to Furl&#034;&gt;&lt;img src=&#034;common/images/furl.png&#034; alt=&#034;Add this post to Furl&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;https://favorites.live.com/quickadd.aspx?mkt=en-us&amp;amp;url=http://javabeans.asia/2008/05/16/jboss_clustering_shared_state_across_cluster_partition.html&amp;amp;title=JBoss Clustering - Shared state across cluster partition&#034; target=&#034;_blank&#034; title=&#034;Add this post to Windows Live&#034;&gt;&lt;img src=&#034;common/images/windowslive.png&#034; alt=&#034;Add this post to Windows Live&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://bookmarks.yahoo.com/toolbar/savebm?opener=tb&amp;amp;u=http://javabeans.asia/2008/05/16/jboss_clustering_shared_state_across_cluster_partition.html&amp;amp;t=JBoss Clustering - Shared state across cluster partition&#034; target=&#034;_blank&#034; title=&#034;Add this post to Yahoo!&#034;&gt;&lt;img src=&#034;common/images/yahoo.png&#034; alt=&#034;Add this post to Yahoo!&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&lt;/div&gt;</description>
      
	-->
    <category>clustering</category>
    <category>jboss</category>
    <category>management beans</category>
    <comments>http://javabeans.asia/2008/05/16/jboss_clustering_shared_state_across_cluster_partition.html#comments</comments>
    <guid isPermaLink="true">http://javabeans.asia/2008/05/16/jboss_clustering_shared_state_across_cluster_partition.html</guid>
    <pubDate>Fri, 16 May 2008 13:15:00 GMT</pubDate>
  </item>
  <item>
    <title>JBoss Clustering - How many nodes in the cluster?</title>
    <link>http://javabeans.asia/2008/05/14/jboss_clustering_how_many_nodes_in_the_cluster.html</link>
	 <description>
        If you want to know how many nodes there are in the current cluster partition, all you have to do is to ask &lt;em&gt;HAPartition&lt;/em&gt; for the node list. &lt;em&gt;HAPartition&lt;/em&gt; represents your cluster partition, and it contains all the information you need to know about your cluster and the nodes: their host names, IPs, position in the cluster view.&lt;br /&gt;
&lt;br /&gt;
Lets assume you have a service bean that extends from &lt;em&gt;HASingletonSupport&lt;/em&gt;. &lt;em&gt;HASingletonSupport &lt;/em&gt;in its turn extends from &lt;em&gt;HAServiceMBeanSupport. &lt;br /&gt;
&lt;br /&gt;
&lt;/em&gt;&lt;em&gt;HAServiceMBeanSupport &lt;/em&gt;is the one who gives you access&lt;em&gt; to HAPartition &lt;/em&gt;object. &lt;br /&gt;
&lt;br /&gt;
The code to request for HAPartition object and node list that you see below , you can put somewhere in your service bean:
&lt;pre class=&#034;codeSample&#034;&gt;HAPartition partition = getPartition();&lt;br /&gt;ClusterNode[] nodes = partition.getClusterNodes();&lt;br /&gt;System.out.println(nodes.length);&lt;br /&gt;&lt;/pre&gt;
&lt;em&gt;ClusterNode&lt;/em&gt; object represents your node in the cluster. It contains information about node&#039;s host name, its internet address and a few more things. &lt;em&gt;getClusterNodes()&lt;/em&gt;, returns to you an array contains as many &lt;em&gt;ClusterNode&lt;/em&gt; objects as you have currently in your cluster. So by getting the value of array length, you will know how many nodes your cluster has.&lt;br /&gt;
&lt;br /&gt;
Another way, is to do practically the same, but to request from a HAPartition a current view of your cluster:
&lt;pre class=&#034;codeSample&#034;&gt;HAPartition partition = getPartition();&lt;br /&gt;Vector v = partition.getCurrentView();&lt;br /&gt;&lt;br /&gt;System.out.println(partition.getCurrentView().size());&lt;br /&gt;&lt;br /&gt;for (Object o : v) {&lt;br /&gt;   System.out.println(o.toString());&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;
The view, which is a Vector contains information about node sockets. When printed, it will return to you a String representation of node ip + port:&amp;nbsp; xxx.xxx.xxx.xxx:port. Also by printing size of the Vector, you will get number of nodes in the cluster. &lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Important note&lt;/strong&gt;: &lt;br /&gt;
I noticed there is some delay happening from the time when node leaves the cluster to the time when HAPartition returns an updated view. In another words - after node has left the cluster and topology change has occurred, the HAPartition may return to you an old view still containing the dead node. So be careful. &lt;br /&gt;
&lt;br /&gt;
Also, &lt;em&gt;getPartition()&lt;/em&gt; may return null, if &lt;em&gt;super.startService()&lt;/em&gt; hasnt been called. Have a look at implementation of &lt;a href=&#034;http://docs.jboss.org/jbossas/javadoc/4.0.2/org/jboss/ha/jmx/HAServiceMBeanSupport.java.html&#034; target=&#034;_blank&#034;&gt;HAServiceMBeanSupport&lt;/a&gt; and my other post &lt;a href=&#034;http://javabeans.asia/2008/05/08/jboss_clustering_hasingleton_service.html&#034;&gt;JBoss Clustering - HASingleton service&lt;/a&gt;. &lt;br /&gt;
&lt;br /&gt;
Thats it.&lt;div class=&#034;tags&#034;&gt;&lt;span&gt;Social Bookmarks : &lt;/span&gt;&amp;nbsp;&lt;a href=&#034;http://slashdot.org/bookmark.pl?url=http://javabeans.asia/2008/05/14/jboss_clustering_how_many_nodes_in_the_cluster.html&amp;amp;title=JBoss Clustering - How many nodes in the cluster?&#034; target=&#034;_blank&#034; title=&#034;Add this post to Slash Dot&#034;&gt;&lt;img src=&#034;common/images/slashdot.png&#034; alt=&#034;Add this post to Slashdot&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://digg.com/submit?url=http://javabeans.asia/2008/05/14/jboss_clustering_how_many_nodes_in_the_cluster.html&amp;amp;title=JBoss Clustering - How many nodes in the cluster?&#034; target=&#034;_blank&#034; title=&#034;Digg this post&#034;&gt;&lt;img src=&#034;common/images/digg.png&#034; alt=&#034;Add this post to Digg&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://reddit.com/submit?url=http://javabeans.asia/2008/05/14/jboss_clustering_how_many_nodes_in_the_cluster.html&amp;amp;title=JBoss Clustering - How many nodes in the cluster?&#034; target=&#034;_blank&#034; title=&#034;Add this post to Reddit&#034;&gt;&lt;img src=&#034;common/images/reddit.png&#034; alt=&#034;Add this post to Reddit&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://del.icio.us/post?url=http://javabeans.asia/2008/05/14/jboss_clustering_how_many_nodes_in_the_cluster.html&amp;amp;title=JBoss Clustering - How many nodes in the cluster?&#034; target=&#034;_blank&#034; title=&#034;Save this post to Del.icio.us&#034;&gt;&lt;img src=&#034;common/images/delicious.png&#034; alt=&#034;Add this post to Delicious&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.stumbleupon.com/submit?url=http://javabeans.asia/2008/05/14/jboss_clustering_how_many_nodes_in_the_cluster.html&amp;amp;title=JBoss Clustering - How many nodes in the cluster?&#034; target=&#034;_blank&#034; title=&#034;Stumble this post&#034;&gt;&lt;img src=&#034;common/images/stumbleupon.png&#034; alt=&#034;Add this post to Stumble it&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.google.com/bookmarks/mark?op=edit&amp;amp;bkmk=http://javabeans.asia/2008/05/14/jboss_clustering_how_many_nodes_in_the_cluster.html&amp;amp;title=JBoss Clustering - How many nodes in the cluster?&#034; target=&#034;_blank&#034; title=&#034;Add this post to Google&#034;&gt;&lt;img src=&#034;common/images/google.png&#034; alt=&#034;Add this post to Google&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://technorati.com/faves?add=http://javabeans.asia/2008/05/14/jboss_clustering_how_many_nodes_in_the_cluster.html&#034; target=&#034;_blank&#034; title=&#034;Add this post to Technorati&#034;&gt;&lt;img src=&#034;common/images/technorati.png&#034; alt=&#034;Add this post to Technorati&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.bloglines.com/sub/http://javabeans.asia/2008/05/14/jboss_clustering_how_many_nodes_in_the_cluster.html&#034; target=&#034;_blank&#034; title=&#034;Add this post to Bloglines&#034;&gt;&lt;img src=&#034;common/images/bloglines.png&#034; alt=&#034;Add this post to Bloglines&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.facebook.com/share.php?u=http://javabeans.asia/2008/05/14/jboss_clustering_how_many_nodes_in_the_cluster.html&#034; target=&#034;_blank&#034; title=&#034;Add this post to Facebook&#034;&gt;&lt;img src=&#034;common/images/facebook.png&#034; alt=&#034;Add this post to Facebook&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.furl.net/storeIt.jsp?u=http://javabeans.asia/2008/05/14/jboss_clustering_how_many_nodes_in_the_cluster.html&amp;amp;t=JBoss Clustering - How many nodes in the cluster?&#034; target=&#034;_blank&#034; title=&#034;Add this post to Furl&#034;&gt;&lt;img src=&#034;common/images/furl.png&#034; alt=&#034;Add this post to Furl&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;https://favorites.live.com/quickadd.aspx?mkt=en-us&amp;amp;url=http://javabeans.asia/2008/05/14/jboss_clustering_how_many_nodes_in_the_cluster.html&amp;amp;title=JBoss Clustering - How many nodes in the cluster?&#034; target=&#034;_blank&#034; title=&#034;Add this post to Windows Live&#034;&gt;&lt;img src=&#034;common/images/windowslive.png&#034; alt=&#034;Add this post to Windows Live&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://bookmarks.yahoo.com/toolbar/savebm?opener=tb&amp;amp;u=http://javabeans.asia/2008/05/14/jboss_clustering_how_many_nodes_in_the_cluster.html&amp;amp;t=JBoss Clustering - How many nodes in the cluster?&#034; target=&#034;_blank&#034; title=&#034;Add this post to Yahoo!&#034;&gt;&lt;img src=&#034;common/images/yahoo.png&#034; alt=&#034;Add this post to Yahoo!&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;&lt;b&gt;Related Posts&lt;/b&gt;&lt;br /&gt;&lt;a href=&#034;http://javabeans.asia/2009/08/27/jboss_security_jmx_console.html&#034; rel=&#034;bookmark&#034; title=&#034;JBoss Security - JMX Console&#034;&gt;JBoss Security - JMX Console&lt;/a&gt;&lt;br /&gt;&lt;a href=&#034;http://javabeans.asia/2008/10/24/drools_tutorial_on_writing_dsl_template.html&#034; rel=&#034;bookmark&#034; title=&#034;Drools - tutorial on writing DSL template&#034;&gt;Drools - tutorial on writing DSL template&lt;/a&gt;&lt;br /&gt;&lt;a href=&#034;http://javabeans.asia/2008/06/09/drools_stop_executing_current_agenda_group_and_all_rules.html&#034; rel=&#034;bookmark&#034; title=&#034;Drools - Stop executing current agenda group and all rules&#034;&gt;Drools - Stop executing current agenda group and all rules&lt;/a&gt;&lt;br /&gt;&lt;a href=&#034;http://javabeans.asia/2008/05/01/using_template_to_deploy_a_jboss_queue.html&#034; rel=&#034;bookmark&#034; title=&#034;Using template to deploy a JBoss queue&#034;&gt;Using template to deploy a JBoss queue&lt;/a&gt;&lt;br /&gt;&lt;a href=&#034;http://javabeans.asia/2008/05/03/deployment_of_mbean_separately_to_its_interface.html&#034; rel=&#034;bookmark&#034; title=&#034;Deployment of mbean separately to its interface&#034;&gt;Deployment of mbean separately to its interface&lt;/a&gt;&lt;br /&gt;&lt;a href=&#034;http://javabeans.asia/2008/05/08/jboss_clustering_hasingleton_service.html&#034; rel=&#034;bookmark&#034; title=&#034;JBoss Clustering - HASingleton service&#034;&gt;JBoss Clustering - HASingleton service&lt;/a&gt;&lt;br /&gt;&lt;a href=&#034;http://javabeans.asia/2008/05/11/drools_working_with_stateless_session.html&#034; rel=&#034;bookmark&#034; title=&#034;Drools - working with Stateless session&#034;&gt;Drools - working with Stateless session&lt;/a&gt;&lt;br /&gt;&lt;a href=&#034;http://javabeans.asia/2008/05/11/stateless_beans_and_annotations.html&#034; rel=&#034;bookmark&#034; title=&#034;Stateless beans and annotations&#034;&gt;Stateless beans and annotations&lt;/a&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;</description>
	<!--
    <description>
          If you want to know how many nodes there are in the current cluster partition, all you have to do is to ask HAPartition for the node list. HAPartition represents your cluster partition, and it contains all the information you need to know about your cluster and the nodes: their host names, IPs, position in the ...&lt;p&gt;&lt;a href=&#034;http://javabeans.asia/2008/05/14/jboss_clustering_how_many_nodes_in_the_cluster.html&#034;&gt;Read more...&lt;/a&gt;&lt;/p&gt;&lt;div class=&#034;tags&#034;&gt;&lt;span&gt;Social Bookmarks : &lt;/span&gt;&amp;nbsp;&lt;a href=&#034;http://slashdot.org/bookmark.pl?url=http://javabeans.asia/2008/05/14/jboss_clustering_how_many_nodes_in_the_cluster.html&amp;amp;title=JBoss Clustering - How many nodes in the cluster?&#034; target=&#034;_blank&#034; title=&#034;Add this post to Slash Dot&#034;&gt;&lt;img src=&#034;common/images/slashdot.png&#034; alt=&#034;Add this post to Slashdot&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://digg.com/submit?url=http://javabeans.asia/2008/05/14/jboss_clustering_how_many_nodes_in_the_cluster.html&amp;amp;title=JBoss Clustering - How many nodes in the cluster?&#034; target=&#034;_blank&#034; title=&#034;Digg this post&#034;&gt;&lt;img src=&#034;common/images/digg.png&#034; alt=&#034;Add this post to Digg&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://reddit.com/submit?url=http://javabeans.asia/2008/05/14/jboss_clustering_how_many_nodes_in_the_cluster.html&amp;amp;title=JBoss Clustering - How many nodes in the cluster?&#034; target=&#034;_blank&#034; title=&#034;Add this post to Reddit&#034;&gt;&lt;img src=&#034;common/images/reddit.png&#034; alt=&#034;Add this post to Reddit&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://del.icio.us/post?url=http://javabeans.asia/2008/05/14/jboss_clustering_how_many_nodes_in_the_cluster.html&amp;amp;title=JBoss Clustering - How many nodes in the cluster?&#034; target=&#034;_blank&#034; title=&#034;Save this post to Del.icio.us&#034;&gt;&lt;img src=&#034;common/images/delicious.png&#034; alt=&#034;Add this post to Delicious&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.stumbleupon.com/submit?url=http://javabeans.asia/2008/05/14/jboss_clustering_how_many_nodes_in_the_cluster.html&amp;amp;title=JBoss Clustering - How many nodes in the cluster?&#034; target=&#034;_blank&#034; title=&#034;Stumble this post&#034;&gt;&lt;img src=&#034;common/images/stumbleupon.png&#034; alt=&#034;Add this post to Stumble it&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.google.com/bookmarks/mark?op=edit&amp;amp;bkmk=http://javabeans.asia/2008/05/14/jboss_clustering_how_many_nodes_in_the_cluster.html&amp;amp;title=JBoss Clustering - How many nodes in the cluster?&#034; target=&#034;_blank&#034; title=&#034;Add this post to Google&#034;&gt;&lt;img src=&#034;common/images/google.png&#034; alt=&#034;Add this post to Google&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://technorati.com/faves?add=http://javabeans.asia/2008/05/14/jboss_clustering_how_many_nodes_in_the_cluster.html&#034; target=&#034;_blank&#034; title=&#034;Add this post to Technorati&#034;&gt;&lt;img src=&#034;common/images/technorati.png&#034; alt=&#034;Add this post to Technorati&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.bloglines.com/sub/http://javabeans.asia/2008/05/14/jboss_clustering_how_many_nodes_in_the_cluster.html&#034; target=&#034;_blank&#034; title=&#034;Add this post to Bloglines&#034;&gt;&lt;img src=&#034;common/images/bloglines.png&#034; alt=&#034;Add this post to Bloglines&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.facebook.com/share.php?u=http://javabeans.asia/2008/05/14/jboss_clustering_how_many_nodes_in_the_cluster.html&#034; target=&#034;_blank&#034; title=&#034;Add this post to Facebook&#034;&gt;&lt;img src=&#034;common/images/facebook.png&#034; alt=&#034;Add this post to Facebook&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.furl.net/storeIt.jsp?u=http://javabeans.asia/2008/05/14/jboss_clustering_how_many_nodes_in_the_cluster.html&amp;amp;t=JBoss Clustering - How many nodes in the cluster?&#034; target=&#034;_blank&#034; title=&#034;Add this post to Furl&#034;&gt;&lt;img src=&#034;common/images/furl.png&#034; alt=&#034;Add this post to Furl&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;https://favorites.live.com/quickadd.aspx?mkt=en-us&amp;amp;url=http://javabeans.asia/2008/05/14/jboss_clustering_how_many_nodes_in_the_cluster.html&amp;amp;title=JBoss Clustering - How many nodes in the cluster?&#034; target=&#034;_blank&#034; title=&#034;Add this post to Windows Live&#034;&gt;&lt;img src=&#034;common/images/windowslive.png&#034; alt=&#034;Add this post to Windows Live&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://bookmarks.yahoo.com/toolbar/savebm?opener=tb&amp;amp;u=http://javabeans.asia/2008/05/14/jboss_clustering_how_many_nodes_in_the_cluster.html&amp;amp;t=JBoss Clustering - How many nodes in the cluster?&#034; target=&#034;_blank&#034; title=&#034;Add this post to Yahoo!&#034;&gt;&lt;img src=&#034;common/images/yahoo.png&#034; alt=&#034;Add this post to Yahoo!&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&lt;/div&gt;</description>
      
	-->
    <category>clustering</category>
    <category>jboss</category>
    <category>management beans</category>
    <comments>http://javabeans.asia/2008/05/14/jboss_clustering_how_many_nodes_in_the_cluster.html#comments</comments>
    <guid isPermaLink="true">http://javabeans.asia/2008/05/14/jboss_clustering_how_many_nodes_in_the_cluster.html</guid>
    <pubDate>Wed, 14 May 2008 08:36:00 GMT</pubDate>
  </item>
  <item>
    <title>JBoss Clustering - HASingleton service</title>
    <link>http://javabeans.asia/2008/05/08/jboss_clustering_hasingleton_service.html</link>
	 <description>
        Have you ever dealt with clustered singleton service? How to determine which cluster node is the master? Well, if I am the current node, I can simply ask whether I am the master or not. But what if I already know that the current node is not the master, and I want to determine which node among other nodes in the cluster is the master? &lt;br /&gt;
&lt;br /&gt;
First I would like to give brief summary about &lt;em&gt;HASingleton&lt;/em&gt; service (HA stands for High Availability).&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Summary:&lt;/strong&gt;&lt;br /&gt;
HASingleton service, is a service that is deployed on every node in a cluster, but runs only on one node, while the other nodes remain passive. The node that the service runs on, is the master node. &lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;How does JBoss selects the master node? &lt;/strong&gt;&lt;br /&gt;
Well the first node in a cluster will become master node. If existing master node will leave the cluster as a result of a shutdown for example, another node is selected as master from the remaining nodes.&lt;br /&gt;
&lt;br /&gt;
Master node can control which tasks will get executed, and how many times. HASingletons also have the ability to share a memory state across clustered partition. Something like caching ...&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Solution:&lt;/strong&gt;&lt;br /&gt;
Lets assume that I have a service bean that extends from &lt;em&gt;HASingletonSupport&lt;/em&gt; class. &lt;em&gt;HASingletonSupport &lt;/em&gt;in its turn extends from &lt;em&gt;HAServiceMBeanSupport&lt;/em&gt;&lt;br /&gt;
and implements two interfaces: &lt;em&gt;HASingletonMBean&lt;/em&gt; and &lt;em&gt;HASingleton. &lt;/em&gt;All of them give me those wonderful APIs that can tell me whether the current node is the master or not, what the status of my cluster, how many nodes etc. etc.&lt;br /&gt;
&lt;pre class=&#034;java:nocontrols:firstline[1]&#034; name=&#034;code&#034;&gt;public class MyHAService extends HASingletonSupport implements&lt;br /&gt;        MyHAServiceMBean {&lt;br /&gt;&lt;br /&gt;private static Logger logger = &lt;br /&gt;		Logger.getLogger(MyHAService.class);&lt;br /&gt;&lt;br /&gt; public void startService() throws Exception {&lt;br /&gt;        logger.info(&amp;quot; *** STARTED MY SINGLETON SERVICE *** &amp;quot;);&lt;br /&gt;        super.startService();&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public void stopService() throws Exception {&lt;br /&gt;        logger.info(&amp;quot; *** STOPPED MY SINGLETON SERVICE *** &amp;quot;);&lt;br /&gt;        super.stopService();&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;public boolean isMasterNode() {&lt;br /&gt;        return super.isMasterNode();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;   &lt;br /&gt;public void startSingleton() {&lt;br /&gt;        logger.info(&amp;quot; *** CURRENT NODE IP:&amp;quot;&lt;br /&gt;                + this.getPartition().getClusterNode()&lt;br /&gt;			.getIpAddress().getHostAddress() + &lt;br /&gt;			&amp;quot; ELECTED AS A MASTER NODE *** &amp;quot;);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;    &lt;br /&gt;public void stopSingleton() {&lt;br /&gt;        logger.info(&amp;quot; *** CURRENT NODE IP:&amp;quot;&lt;br /&gt;                + this.getPartition().getClusterNode()&lt;br /&gt;			.getIpAddress().getHostAddress()&lt;br /&gt;                + &amp;quot; STOPPED ACTING AS A MASTER NODE *** &amp;quot;);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public void partitionTopologyChanged(List newReplicants, int newViewID) {&lt;br /&gt;        logger.info(&amp;quot; *** TOPOLOGY CHANGE STARTING *** &amp;quot;);&lt;br /&gt;        super.partitionTopologyChanged(newReplicants, newViewID);&lt;br /&gt;&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;
&lt;em&gt;startSingleton()&lt;/em&gt; - invoked when the current node elected as a master.&lt;br /&gt;
&lt;em&gt;stopSingleton()&lt;/em&gt; - invoked when the current node stops acting as a master.&lt;br /&gt;
&lt;em&gt;partitionTopologyChanged()&lt;/em&gt; - invoked when new node joins or leaves the cluster.&lt;br /&gt;
&lt;br /&gt;
As i mentioned before, I have the ability to know whether the current node is the master node, by calling &lt;em&gt;isMasterNode(). &lt;/em&gt;The method will return true if the node is master and false if its not. &lt;br /&gt;
&lt;br /&gt;
In case I already know that the current node is not the master, I can ask the clustered partition (the cluster) which node is the master. For example I can request the current view of my cluster.&lt;br /&gt;
&lt;br /&gt;
The implementation can be similar to the method below which you can have inside your service bean:
&lt;pre class=&#034;java:nocontrols:firstline[1]&#034; name=&#034;code&#034;&gt;private String getMasterSocket() {&lt;br /&gt;&lt;br /&gt;        HAPartition partition = this.getPartition();&lt;br /&gt;&lt;br /&gt;        if (partition != null) {&lt;br /&gt;&lt;br /&gt;            if (partition.getCurrentView() != null) {&lt;br /&gt;                return partition.getCurrentView().get(0).toString();&lt;br /&gt;&lt;br /&gt;            } else {&lt;br /&gt;                return null;&lt;br /&gt;            }&lt;br /&gt;        } else {&lt;br /&gt;            return null;&lt;br /&gt;        }&lt;br /&gt;    }&lt;/pre&gt;
The method above will return me a string contains port and ip of the master node, for example:&lt;br /&gt;
&lt;pre class=&#034;codeSample&#034;&gt;192.168.62.12:1099&lt;br /&gt;&lt;/pre&gt;
The &lt;em&gt;HAPartition&lt;/em&gt; service maintains across cluster a registry of nodes in a view order. Now, keep in mind that an order of the nodes in the view, does not necessary reflect the order nodes have joined the cluster.&lt;br /&gt;
&lt;br /&gt;
So the first node in the view as you can see beloew, will be the master node. &lt;br /&gt;
Simple as that.
&lt;pre class=&#034;codeSample&#034;&gt;return partition.getCurrentView().get(0).toString();&lt;/pre&gt;
&lt;strong&gt;Please note&lt;/strong&gt;:&lt;br /&gt;
Method &lt;em&gt;getPartition()&lt;/em&gt; may return null, if &lt;em&gt;super.startService()&lt;/em&gt; hasnt been called. Have a look at implementation of &lt;a href=&#034;http://docs.jboss.org/jbossas/javadoc/4.0.2/org/jboss/ha/jmx/HAServiceMBeanSupport.java.html&#034; target=&#034;_blank&#034;&gt;HAServiceMBeanSupport&lt;/a&gt; and my other post &lt;a href=&#034;http://javabeans.asia/2008/05/14/jboss_clustering_how_many_nodes_in_the_cluster.html&#034;&gt;JBoss Clustering - How many nodes in the cluster?&lt;/a&gt;.&lt;div class=&#034;tags&#034;&gt;&lt;span&gt;Social Bookmarks : &lt;/span&gt;&amp;nbsp;&lt;a href=&#034;http://slashdot.org/bookmark.pl?url=http://javabeans.asia/2008/05/08/jboss_clustering_hasingleton_service.html&amp;amp;title=JBoss Clustering - HASingleton service&#034; target=&#034;_blank&#034; title=&#034;Add this post to Slash Dot&#034;&gt;&lt;img src=&#034;common/images/slashdot.png&#034; alt=&#034;Add this post to Slashdot&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://digg.com/submit?url=http://javabeans.asia/2008/05/08/jboss_clustering_hasingleton_service.html&amp;amp;title=JBoss Clustering - HASingleton service&#034; target=&#034;_blank&#034; title=&#034;Digg this post&#034;&gt;&lt;img src=&#034;common/images/digg.png&#034; alt=&#034;Add this post to Digg&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://reddit.com/submit?url=http://javabeans.asia/2008/05/08/jboss_clustering_hasingleton_service.html&amp;amp;title=JBoss Clustering - HASingleton service&#034; target=&#034;_blank&#034; title=&#034;Add this post to Reddit&#034;&gt;&lt;img src=&#034;common/images/reddit.png&#034; alt=&#034;Add this post to Reddit&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://del.icio.us/post?url=http://javabeans.asia/2008/05/08/jboss_clustering_hasingleton_service.html&amp;amp;title=JBoss Clustering - HASingleton service&#034; target=&#034;_blank&#034; title=&#034;Save this post to Del.icio.us&#034;&gt;&lt;img src=&#034;common/images/delicious.png&#034; alt=&#034;Add this post to Delicious&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.stumbleupon.com/submit?url=http://javabeans.asia/2008/05/08/jboss_clustering_hasingleton_service.html&amp;amp;title=JBoss Clustering - HASingleton service&#034; target=&#034;_blank&#034; title=&#034;Stumble this post&#034;&gt;&lt;img src=&#034;common/images/stumbleupon.png&#034; alt=&#034;Add this post to Stumble it&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.google.com/bookmarks/mark?op=edit&amp;amp;bkmk=http://javabeans.asia/2008/05/08/jboss_clustering_hasingleton_service.html&amp;amp;title=JBoss Clustering - HASingleton service&#034; target=&#034;_blank&#034; title=&#034;Add this post to Google&#034;&gt;&lt;img src=&#034;common/images/google.png&#034; alt=&#034;Add this post to Google&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://technorati.com/faves?add=http://javabeans.asia/2008/05/08/jboss_clustering_hasingleton_service.html&#034; target=&#034;_blank&#034; title=&#034;Add this post to Technorati&#034;&gt;&lt;img src=&#034;common/images/technorati.png&#034; alt=&#034;Add this post to Technorati&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.bloglines.com/sub/http://javabeans.asia/2008/05/08/jboss_clustering_hasingleton_service.html&#034; target=&#034;_blank&#034; title=&#034;Add this post to Bloglines&#034;&gt;&lt;img src=&#034;common/images/bloglines.png&#034; alt=&#034;Add this post to Bloglines&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.facebook.com/share.php?u=http://javabeans.asia/2008/05/08/jboss_clustering_hasingleton_service.html&#034; target=&#034;_blank&#034; title=&#034;Add this post to Facebook&#034;&gt;&lt;img src=&#034;common/images/facebook.png&#034; alt=&#034;Add this post to Facebook&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.furl.net/storeIt.jsp?u=http://javabeans.asia/2008/05/08/jboss_clustering_hasingleton_service.html&amp;amp;t=JBoss Clustering - HASingleton service&#034; target=&#034;_blank&#034; title=&#034;Add this post to Furl&#034;&gt;&lt;img src=&#034;common/images/furl.png&#034; alt=&#034;Add this post to Furl&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;https://favorites.live.com/quickadd.aspx?mkt=en-us&amp;amp;url=http://javabeans.asia/2008/05/08/jboss_clustering_hasingleton_service.html&amp;amp;title=JBoss Clustering - HASingleton service&#034; target=&#034;_blank&#034; title=&#034;Add this post to Windows Live&#034;&gt;&lt;img src=&#034;common/images/windowslive.png&#034; alt=&#034;Add this post to Windows Live&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://bookmarks.yahoo.com/toolbar/savebm?opener=tb&amp;amp;u=http://javabeans.asia/2008/05/08/jboss_clustering_hasingleton_service.html&amp;amp;t=JBoss Clustering - HASingleton service&#034; target=&#034;_blank&#034; title=&#034;Add this post to Yahoo!&#034;&gt;&lt;img src=&#034;common/images/yahoo.png&#034; alt=&#034;Add this post to Yahoo!&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;&lt;b&gt;Related Posts&lt;/b&gt;&lt;br /&gt;&lt;a href=&#034;http://javabeans.asia/2009/08/27/jboss_security_jmx_console.html&#034; rel=&#034;bookmark&#034; title=&#034;JBoss Security - JMX Console&#034;&gt;JBoss Security - JMX Console&lt;/a&gt;&lt;br /&gt;&lt;a href=&#034;http://javabeans.asia/2008/10/24/drools_tutorial_on_writing_dsl_template.html&#034; rel=&#034;bookmark&#034; title=&#034;Drools - tutorial on writing DSL template&#034;&gt;Drools - tutorial on writing DSL template&lt;/a&gt;&lt;br /&gt;&lt;a href=&#034;http://javabeans.asia/2008/06/04/marshalling_vs_serialization.html&#034; rel=&#034;bookmark&#034; title=&#034;Marshalling VS Serialization&#034;&gt;Marshalling VS Serialization&lt;/a&gt;&lt;br /&gt;&lt;a href=&#034;http://javabeans.asia/2008/06/07/ouch.html&#034; rel=&#034;bookmark&#034; title=&#034;Ouch!&#034;&gt;Ouch!&lt;/a&gt;&lt;br /&gt;&lt;a href=&#034;http://javabeans.asia/2008/06/09/drools_stop_executing_current_agenda_group_and_all_rules.html&#034; rel=&#034;bookmark&#034; title=&#034;Drools - Stop executing current agenda group and all rules&#034;&gt;Drools - Stop executing current agenda group and all rules&lt;/a&gt;&lt;br /&gt;&lt;a href=&#034;http://javabeans.asia/2008/05/01/using_template_to_deploy_a_jboss_queue.html&#034; rel=&#034;bookmark&#034; title=&#034;Using template to deploy a JBoss queue&#034;&gt;Using template to deploy a JBoss queue&lt;/a&gt;&lt;br /&gt;&lt;a href=&#034;http://javabeans.asia/2008/05/03/deployment_of_mbean_separately_to_its_interface.html&#034; rel=&#034;bookmark&#034; title=&#034;Deployment of mbean separately to its interface&#034;&gt;Deployment of mbean separately to its interface&lt;/a&gt;&lt;br /&gt;&lt;a href=&#034;http://javabeans.asia/2008/05/05/multiple_return_statements.html&#034; rel=&#034;bookmark&#034; title=&#034;Multiple return statements&#034;&gt;Multiple return statements&lt;/a&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;</description>
	<!--
    <description>
          Have you ever dealt with clustered singleton service? How to determine which cluster node is the master? Well, if I am the current node, I can simply ask whether I am the master or not. But what if I already know that the current node is not the master, and I want to determine which node among other nodes in the ...&lt;p&gt;&lt;a href=&#034;http://javabeans.asia/2008/05/08/jboss_clustering_hasingleton_service.html&#034;&gt;Read more...&lt;/a&gt;&lt;/p&gt;&lt;div class=&#034;tags&#034;&gt;&lt;span&gt;Social Bookmarks : &lt;/span&gt;&amp;nbsp;&lt;a href=&#034;http://slashdot.org/bookmark.pl?url=http://javabeans.asia/2008/05/08/jboss_clustering_hasingleton_service.html&amp;amp;title=JBoss Clustering - HASingleton service&#034; target=&#034;_blank&#034; title=&#034;Add this post to Slash Dot&#034;&gt;&lt;img src=&#034;common/images/slashdot.png&#034; alt=&#034;Add this post to Slashdot&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://digg.com/submit?url=http://javabeans.asia/2008/05/08/jboss_clustering_hasingleton_service.html&amp;amp;title=JBoss Clustering - HASingleton service&#034; target=&#034;_blank&#034; title=&#034;Digg this post&#034;&gt;&lt;img src=&#034;common/images/digg.png&#034; alt=&#034;Add this post to Digg&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://reddit.com/submit?url=http://javabeans.asia/2008/05/08/jboss_clustering_hasingleton_service.html&amp;amp;title=JBoss Clustering - HASingleton service&#034; target=&#034;_blank&#034; title=&#034;Add this post to Reddit&#034;&gt;&lt;img src=&#034;common/images/reddit.png&#034; alt=&#034;Add this post to Reddit&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://del.icio.us/post?url=http://javabeans.asia/2008/05/08/jboss_clustering_hasingleton_service.html&amp;amp;title=JBoss Clustering - HASingleton service&#034; target=&#034;_blank&#034; title=&#034;Save this post to Del.icio.us&#034;&gt;&lt;img src=&#034;common/images/delicious.png&#034; alt=&#034;Add this post to Delicious&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.stumbleupon.com/submit?url=http://javabeans.asia/2008/05/08/jboss_clustering_hasingleton_service.html&amp;amp;title=JBoss Clustering - HASingleton service&#034; target=&#034;_blank&#034; title=&#034;Stumble this post&#034;&gt;&lt;img src=&#034;common/images/stumbleupon.png&#034; alt=&#034;Add this post to Stumble it&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.google.com/bookmarks/mark?op=edit&amp;amp;bkmk=http://javabeans.asia/2008/05/08/jboss_clustering_hasingleton_service.html&amp;amp;title=JBoss Clustering - HASingleton service&#034; target=&#034;_blank&#034; title=&#034;Add this post to Google&#034;&gt;&lt;img src=&#034;common/images/google.png&#034; alt=&#034;Add this post to Google&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://technorati.com/faves?add=http://javabeans.asia/2008/05/08/jboss_clustering_hasingleton_service.html&#034; target=&#034;_blank&#034; title=&#034;Add this post to Technorati&#034;&gt;&lt;img src=&#034;common/images/technorati.png&#034; alt=&#034;Add this post to Technorati&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.bloglines.com/sub/http://javabeans.asia/2008/05/08/jboss_clustering_hasingleton_service.html&#034; target=&#034;_blank&#034; title=&#034;Add this post to Bloglines&#034;&gt;&lt;img src=&#034;common/images/bloglines.png&#034; alt=&#034;Add this post to Bloglines&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.facebook.com/share.php?u=http://javabeans.asia/2008/05/08/jboss_clustering_hasingleton_service.html&#034; target=&#034;_blank&#034; title=&#034;Add this post to Facebook&#034;&gt;&lt;img src=&#034;common/images/facebook.png&#034; alt=&#034;Add this post to Facebook&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://www.furl.net/storeIt.jsp?u=http://javabeans.asia/2008/05/08/jboss_clustering_hasingleton_service.html&amp;amp;t=JBoss Clustering - HASingleton service&#034; target=&#034;_blank&#034; title=&#034;Add this post to Furl&#034;&gt;&lt;img src=&#034;common/images/furl.png&#034; alt=&#034;Add this post to Furl&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;https://favorites.live.com/quickadd.aspx?mkt=en-us&amp;amp;url=http://javabeans.asia/2008/05/08/jboss_clustering_hasingleton_service.html&amp;amp;title=JBoss Clustering - HASingleton service&#034; target=&#034;_blank&#034; title=&#034;Add this post to Windows Live&#034;&gt;&lt;img src=&#034;common/images/windowslive.png&#034; alt=&#034;Add this post to Windows Live&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&#034;http://bookmarks.yahoo.com/toolbar/savebm?opener=tb&amp;amp;u=http://javabeans.asia/2008/05/08/jboss_clustering_hasingleton_service.html&amp;amp;t=JBoss Clustering - HASingleton service&#034; target=&#034;_blank&#034; title=&#034;Add this post to Yahoo!&#034;&gt;&lt;img src=&#034;common/images/yahoo.png&#034; alt=&#034;Add this post to Yahoo!&#034; border=&#034;0&#034; /&gt;&lt;/a&gt;&lt;/div&gt;</description>
      
	-->
    <category>clustering</category>
    <category>jboss</category>
    <comments>http://javabeans.asia/2008/05/08/jboss_clustering_hasingleton_service.html#comments</comments>
    <guid isPermaLink="true">http://javabeans.asia/2008/05/08/jboss_clustering_hasingleton_service.html</guid>
    <pubDate>Thu, 08 May 2008 09:22:00 GMT</pubDate>
  </item>
  </channel>
</rss>
