<?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>@InitBinder &#187; management beans</title>
	<atom:link href="http://initbinder.com/categories/beans/management-beans/feed" rel="self" type="application/rss+xml" />
	<link>http://initbinder.com</link>
	<description>My thoughts, notes and ideas as a passionate software engineer</description>
	<lastBuildDate>Sat, 24 Mar 2012 13:29:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>JBoss Clustering Architecture &#8211; Distributed Replicant Manager</title>
		<link>http://initbinder.com/articles/jboss_clustering_architecture_distributed_replicant_manager.html</link>
		<comments>http://initbinder.com/articles/jboss_clustering_architecture_distributed_replicant_manager.html#comments</comments>
		<pubDate>Sat, 31 May 2008 07:37:00 +0000</pubDate>
		<dc:creator>Alexander Zagniotov</dc:creator>
				<category><![CDATA[clustering]]></category>
		<category><![CDATA[jboss]]></category>
		<category><![CDATA[management beans]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[distributed]]></category>
		<category><![CDATA[ejb]]></category>
		<category><![CDATA[j2ee]]></category>
		<category><![CDATA[services]]></category>

		<guid isPermaLink="false">http://javabeans.asia/2008/05/31/jboss_clustering_architecture_distributed_replicant_manager.html</guid>
		<description><![CDATA[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 &#8230; <a href="http://initbinder.com/articles/jboss_clustering_architecture_distributed_replicant_manager.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>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.</p>
<p>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.</p>
<p>In case one of the nodes leaves the cluster, its stub is automatically removed from the list of replicants (stubs) that DRM maintains.</p>
<p>Also for each set of replicants DRM holds an id, which is identical on all nodes in the cluster.</p>
<p>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 jboss.bind.address property. Every time my cluster is going through a topology changes, my service bean on the master node will prints out replicant list.</p>
<p>My service MBean as follows:</p>
<p>[java]<br />
package com.example;</p>
<p>public class CoordinatorHAService extends<br />
	HASingletonSupport implements<br />
			CoordinatorHAServiceMBean  {</p>
<p>    private static Logger logger =<br />
	Logger.getLogger(CoordinatorHAService.class);</p>
<p>	/**<br />
	 * Can be used instead of the constructor<br />
	 * defined in jboss-service.xml<br />
	 */<br />
	private static final String BIND_ADDRESS =<br />
		System.getProperty(&quot;jboss.bind.address&quot;);</p>
<p>	/**<br />
	 * Custom name for this HA partition, overrides<br />
	 * the default HA partition name which is<br />
	 * canonical name of this MBean<br />
	 */<br />
	private final static<br />
	String COORDINATOR_HA_SERVICE_NAME =<br />
		&quot;ServiceName:CoordinatorHAService&quot;;</p>
<p>	/**<br />
	 * Current node IP<br />
	 */<br />
	private String nodeIp = null;</p>
<p>	/**<br />
	 * Constructor that gets value of this node IP<br />
	 * from &#8216;jboss.bind.address&#8217; property<br />
	 * defined in jboss-service.xml<br />
	 *<br />
	 */<br />
	public CoordinatorHAService(String nodeIp) {<br />
		this.nodeIp = nodeIp;</p>
<p>	}</p>
<p>	public void startService() throws Exception {</p>
<p>	try {<br />
	/**<br />
	 * Call for super must be done before getting<br />
	 * HAPartition. If super is not called, HAPartition<br />
	 * will be &#8216;null&#8217;<br />
	 *<br />
	 * Alternatively you can use InitialContext to get<br />
	 * default partition, then you dont have to make<br />
	 * a call for super.startService(). I havent<br />
	 * tested it, so I am not sure of the results.<br />
	 *<br />
	 *<br />
	 * InitialContext ic = new InitialContext();<br />
	 * String partitionName = ServerConfigUtil.getDefaultPartitionName();<br />
	 * String partitionJndi = &quot;/HAPartition/&quot; + partitionName;<br />
	 * HAPartition partition = (HAPartition) ic.lookup(partitionJndi);<br />
	 */<br />
		super.startService();</p>
<p>	/**<br />
	 * HAPartition gives access to the replicant manager,<br />
	 * which I am using to add node replicants to.<br />
	 */<br />
		HAPartition partition = super.getPartition();</p>
<p>		if (partition != null) {<br />
			partition.getDistributedReplicantManager().add(<br />
					this.getServiceHAName(), this.getNodeIp());<br />
		}</p>
<p>		} catch (Exception e) {<br />
			this.stopService();<br />
		}</p>
<p>	}</p>
<p>	synchronized public void stopService() throws Exception {<br />
		super.stopService();<br />
	}</p>
<p>	public boolean isMasterNode() {<br />
		return super.isMasterNode();<br />
	}</p>
<p>	/**<br />
	 * Called when node is elected as a master node<br />
	 */<br />
	public void startSingleton() {</p>
<p>	}</p>
<p>	/**<br />
	 * Called when node stops acting as a master node<br />
	 */<br />
	public void stopSingleton() {</p>
<p>	}</p>
<p>	/**<br />
	 * Override this method only if you need to provide<br />
	 * a custom partition wide unique service name.<br />
	 * The default implementation will usually work,<br />
	 * provided that the getServiceName() method returns<br />
	 * a unique canonical MBean name.<br />
	 *<br />
	 */<br />
	public String getServiceHAName() {<br />
		// return super.getServiceHAName();<br />
		return CoordinatorHAService.COORDINATOR_HA_SERVICE_NAME;<br />
	}</p>
<p>	/**<br />
	 * Called when there are topology changes in the cluster.<br />
	 */<br />
	public void partitionTopologyChanged(List newReplicants,<br />
												int newViewID) {<br />
		super.partitionTopologyChanged(newReplicants,<br />
												newViewID);</p>
<p>		/**<br />
		 * If current service is the master node -<br />
		 * print replicants in the cluster<br />
		 */<br />
		if (this.isMasterNode()) {</p>
<p>			List clusterNodeIps =<br />
				new LinkedList(newReplicants);</p>
<p>			for (String clusterNodeIp : clusterNodeIps) {<br />
				logger.info(&quot;Replicant IP: &quot; + clusterNodeIp);<br />
			}<br />
		}</p>
<p>	}</p>
<p>	/**<br />
	 * Gets current node&#8217;s IP<br />
	 */<br />
	public String getNodeIp() {<br />
		return nodeIp;<br />
	}<br />
}<br />
[/java]</p>
<p>..and this is my jboss-service.xml below:</p>
<p>[xml]<br />
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</p>
<p>&lt;server&gt;<br />
    &lt;mbean<br />
	code=&quot;com.example.CoordinatorHAService&quot;<br />
	name=&quot;com.example:service=CoordinatorHAService&quot;&gt;<br />
	&lt;constructor&gt;<br />
	&lt;arg type=&quot;java.lang.String&quot;<br />
		value=&quot;${jboss.bind.address:127.0.0.1}&quot; /&gt;<br />
	  &lt;/constructor&gt;<br />
     &lt;/mbean&gt;<br />
&lt;/server&gt;<br />
[/xml]</p>
<p>In JBoss clustering architecture, DRM sits on top of HAPartition which abstracts the communication framework.</p>
<p>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.</p>
<p>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.</p>
<p>JBoss clustering is a very big topic. So if someone is interested, JBoss group provides a PDF book called <a href="http://docs.jboss.org/jbossas/clustering/JBossClustering7.pdf" target="_blank">JBoss AS Clustering</a> 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 <img src='http://initbinder.com/bunker/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Any comments or/and flames about this post are welcomed &#8230;</p>
<p>cheers</p>
<p><a href="http://initbinder.com/bunker/wp-content/uploads/2008/05/jboss_clustering_replicant_manager.zip">jboss clustering replicant manager sourcecode</a></p>
]]></content:encoded>
			<wfw:commentRss>http://initbinder.com/articles/jboss_clustering_architecture_distributed_replicant_manager.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JBoss Clustering &#8211; Shared State Across Cluster Partition</title>
		<link>http://initbinder.com/articles/jboss_clustering_shared_state_across_cluster_partition.html</link>
		<comments>http://initbinder.com/articles/jboss_clustering_shared_state_across_cluster_partition.html#comments</comments>
		<pubDate>Fri, 16 May 2008 13:15:00 +0000</pubDate>
		<dc:creator>Alexander Zagniotov</dc:creator>
				<category><![CDATA[clustering]]></category>
		<category><![CDATA[jboss]]></category>
		<category><![CDATA[management beans]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[distributed]]></category>
		<category><![CDATA[ejb]]></category>
		<category><![CDATA[j2ee]]></category>
		<category><![CDATA[services]]></category>

		<guid isPermaLink="false">http://javabeans.asia/2008/05/16/jboss_clustering_shared_state_across_cluster_partition.html</guid>
		<description><![CDATA[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 &#8230; <a href="http://initbinder.com/articles/jboss_clustering_shared_state_across_cluster_partition.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>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.</p>
<p>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 &#8220;<em>service A</em>&#8221; and &#8220;<em>service B</em>&#8220;. Your service beans should extend from <em>HASingletonSupport </em>class. <em>HASingletonSupport</em> in its turn extends from <em>HAServiceMBeanSupport. </em>The latter gives you access to two methods:</p>
<p>[java]<br />
public void setDistributedState(String key, Serializable value) throws Exception<br />
[/java]</p>
<p>and</p>
<p>[java]<br />
public Serializable getDistributedState(String key)<br />
[/java]</p>
<p>These are convenience which allow you to save and retrieve objects from shared state. It can be whatever you want &#8211; primitive data types or even POJOs.</p>
<p>Lets say somewhere inside you <em>service A</em>, you have the following method:</p>
<p>[java]<br />
public void setObjectToSharedState()  {<br />
	String key = &quot;test-1&quot;;<br />
	String value = &quot;Testing memory state&quot;;</p>
<p> 	try {<br />
		this.setDistributedState(key, value);<br />
		}<br />
	catch (Exception e)  {<br />
		e.printStackTrace();<br />
		}<br />
}<br />
[/java]</p>
<p>Now, what has happened is that you, by using your <em>service A</em> saved into the shared memory a String value, under a key name &#8220;<em>test-1</em>&#8220;. This key name you can use in your <em>service B</em> to retrieve its corresponding value from the shared memory, in this case a String. Lets say the following method is sitting somewhere in your <em>service B</em> bean, on another node in the cluster:</p>
<p>[java]<br />
	public void getObjectFromSharedState()  {<br />
		String key = &quot;test-1&quot;;<br />
		String value = (String) this.getDistributedState(key);<br />
		System.out.println(&quot;The value is: &quot; + value);<br />
	}<br />
[/java]</p>
<p>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.<br />
Also keep in mind: if you specify wrong key name, the retrieved object will be <em>null</em>.</p>
<p>Shared memory state is another option, if you want to share something between your nodes, and for some reason you don&#8217;t want to use JBoss cache.</p>
]]></content:encoded>
			<wfw:commentRss>http://initbinder.com/articles/jboss_clustering_shared_state_across_cluster_partition.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JBoss Clustering &#8211; How Many Nodes in the Cluster?</title>
		<link>http://initbinder.com/articles/jboss_clustering_how_many_nodes_in_the_cluster.html</link>
		<comments>http://initbinder.com/articles/jboss_clustering_how_many_nodes_in_the_cluster.html#comments</comments>
		<pubDate>Wed, 14 May 2008 08:36:00 +0000</pubDate>
		<dc:creator>Alexander Zagniotov</dc:creator>
				<category><![CDATA[clustering]]></category>
		<category><![CDATA[jboss]]></category>
		<category><![CDATA[management beans]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[distributed]]></category>
		<category><![CDATA[ejb]]></category>
		<category><![CDATA[j2ee]]></category>
		<category><![CDATA[nodes]]></category>
		<category><![CDATA[services]]></category>

		<guid isPermaLink="false">http://javabeans.asia/2008/05/14/jboss_clustering_how_many_nodes_in_the_cluster.html</guid>
		<description><![CDATA[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 &#8230; <a href="http://initbinder.com/articles/jboss_clustering_how_many_nodes_in_the_cluster.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you want to know how many nodes there are in the current cluster partition, all you have to do is to ask <em>HAPartition</em> for the node list. <em>HAPartition</em> 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.</p>
<p>Lets assume you have a service bean that extends from <em>HASingletonSupport</em>. <em>HASingletonSupport </em>in its turn extends from <em>HAServiceMBeanSupport. </em></p>
<p><em></em><em>HAServiceMBeanSupport </em>is the one who gives you access<em> to HAPartition </em>object.</p>
<p>The code to request for HAPartition object and node list that you see below , you can put somewhere in your service bean:</p>
<p>[java]<br />
	HAPartition partition = getPartition();<br />
	ClusterNode[] nodes = partition.getClusterNodes();<br />
	System.out.println(nodes.length);<br />
[/java]</p>
<p><em>ClusterNode</em> object represents your node in the cluster. It contains information about node&#8217;s host name, its internet address and a few more things. <em>getClusterNodes()</em>, returns to you an array contains as many <em>ClusterNode</em> 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.</p>
<p>Another way, is to do practically the same, but to request from a HAPartition a current view of your cluster:</p>
<p>[java]<br />
	HAPartition partition = getPartition();Vector v = partition.getCurrentView();</p>
<p>	System.out.println(partition.getCurrentView().size());</p>
<p>	for (Object o : v) {<br />
		System.out.println(o.toString());<br />
	}<br />
[/java]</p>
<p>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: xxx.xxx.xxx.xxx:port. Also by printing size of the Vector, you will get number of nodes in the cluster.</p>
<p><strong>Important note</strong>:<br />
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 &#8211; 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.</p>
<p>Also, <em>getPartition()</em> may return null, if <em>super.startService()</em> hasnt been called. Have a look at implementation of <a href="http://docs.jboss.org/jbossas/javadoc/4.0.2/org/jboss/ha/jmx/HAServiceMBeanSupport.java.html" target="_blank">HAServiceMBeanSupport</a> and my other post <a title="jBoss Clustering HA Singleton Service" href="http://initbinder.com/articles/jboss_clustering_hasingleton_service.html" target="_blank">JBoss Clustering &#8211; HASingleton service</a>.</p>
<p>Thats it <img src='http://initbinder.com/bunker/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://initbinder.com/articles/jboss_clustering_how_many_nodes_in_the_cluster.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Deployment of MBean Separately to Its Interface</title>
		<link>http://initbinder.com/articles/deployment_of_mbean_separately_to_its_interface.html</link>
		<comments>http://initbinder.com/articles/deployment_of_mbean_separately_to_its_interface.html#comments</comments>
		<pubDate>Sat, 03 May 2008 09:51:00 +0000</pubDate>
		<dc:creator>Alexander Zagniotov</dc:creator>
				<category><![CDATA[beans]]></category>
		<category><![CDATA[jboss]]></category>
		<category><![CDATA[management beans]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[ejb]]></category>
		<category><![CDATA[exceptions]]></category>
		<category><![CDATA[j2ee]]></category>

		<guid isPermaLink="false">http://javabeans.asia/2008/05/03/deployment_of_mbean_separately_to_its_interface.html</guid>
		<description><![CDATA[Few days ago i came across a little nasty thing during mbean deployment. What I did was separation of my mbean class and its interface in to two archives. So first i would deploy an archive contained my interfaces and &#8230; <a href="http://initbinder.com/articles/deployment_of_mbean_separately_to_its_interface.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Few days ago i came across a little nasty thing during mbean deployment. What I did was separation of my mbean class and its interface in to two archives. So first i would deploy an archive contained my interfaces and then i would deploy an archive contained my bean classes.</p>
<p><strong> Why did i do it this way?</strong></p>
<p>Well to minimize chances having <em>ClassCastException. </em>Since JBoss creates a proxy to the bean from its interface. Having the interfaces deployed seperately from the bean itself, allows me easily to modify business logic in the bean (if needed). Therefore, I will have to redeploy only the bean itself, without the need to redeploy also the interface, which will not affect my proxies to the bean in the system.</p>
<p>To my big surprise i got an exception:</p>
<p>[java]<br />
	org.jboss.deployment.DeploymentException: Class does not expose a management interface:<br />
	java.lang.Object; &#8211; nested throwable:<br />
	(javax.management.NotCompliantMBeanException:Class does not expose a management interface: java.lang.Object)<br />
[/java]</p>
<p>I could not understand where did I go wrong. I had my mbean class:</p>
<p>[java]<br />
public class MyService 	extends ServiceMBeanSupport implements MyServiceMBean {</p>
<p>	public void startService() throws Exception {<br />
		&#8230;<br />
	}</p>
<p>	public void stopService() {<br />
		&#8230;<br />
	}<br />
}<br />
[/java]</p>
<p>I had my interface with extension &#8216;MBean&#8217;. The interface must have this extension, otherwise, you will receive a <em>Class does not expose a management interface</em> exception :</p>
<p>[java]<br />
	public interface MyServiceMBean extends ServiceMBean {	&#8230;}<br />
[/java]</p>
<p>I had my jboss-service.xml:</p>
<p>[xml]<br />
	&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br />
		&lt;server&gt;<br />
			&lt;mbean code=&quot;com.example.MyService&quot; name=&quot;com.example:service=MyService&quot;&gt;<br />
			&lt;/mbean&gt;<br />
		&lt;/server&gt;<br />
[/xml]</p>
<p>Finally, i discovered that it was because of the way i did the packaging. If you ever going to package mbean and its interface in two separate archives, they (mbean and its interface) must sit under <em><strong>the same package name</strong></em>!</p>
<p>For example: if I in archive A, put my mbean class under the package name &#8220;<em>com.example.test</em>&#8220;, then in archive B I have to put its interface also under  &#8220;<em>com.example.test</em>&#8220;.</p>
]]></content:encoded>
			<wfw:commentRss>http://initbinder.com/articles/deployment_of_mbean_separately_to_its_interface.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  initbinder.com/categories/beans/management-beans/feed ) in 0.23481 seconds, on May 18th, 2012 at 1:45 pm UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on May 18th, 2012 at 2:45 pm UTC -->
