<?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>Gerbrand on ICT &#187; jboss</title>
	<atom:link href="http://www.gerbrand-ict.nl/tag/jboss/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gerbrand-ict.nl</link>
	<description>Weblog on JEE and software-engineering</description>
	<lastBuildDate>Wed, 11 Aug 2010 20:51:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Proxying authentication using JBoss</title>
		<link>http://www.gerbrand-ict.nl/2010/06/proxying-authentication-using-jboss/</link>
		<comments>http://www.gerbrand-ict.nl/2010/06/proxying-authentication-using-jboss/#comments</comments>
		<pubDate>Mon, 21 Jun 2010 23:00:19 +0000</pubDate>
		<dc:creator>gerbrand</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jboss]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.gerbrand-ict.nl/?p=264</guid>
		<description><![CDATA[Wouldn&#8217;t it be nice if the connection to the database is done using the same username as the username used to login to a (JEE) application? Oracle has a solution for that: proxy authentication.  When using proxy authentication, every application user is also a database user: meaning when someone logins to your JEE webapplication using [...]]]></description>
			<content:encoded><![CDATA[<p>Wouldn&#8217;t it be nice if the connection to the database is done using the same username as the username used to login to a (JEE) application? Oracle has a solution for that: <a href="http://download.oracle.com/docs/cd/B28359_01/java.111/b31224/proxya.htm">proxy authentication</a>.  When using proxy authentication, every application user is also a database user: meaning when someone logins to your JEE webapplication using username john, he&#8217;ll also access the database as user john. This way all actions of the user are logged at the database-level: an administrator or auditer can see exactly what data a certain user modified or accessed during a JEE session.</p>
<p><span id="more-264"></span></p>
<p>Also, this allows for fine-grained security at database level: <a href="http://www.oracle.com/technology/deploy/security/database-security-10g/virtual-private-database/index.html">Virtual Private Database</a>.</p>
<div id="attachment_297" class="wp-caption alignnone" style="width: 466px"><a href="http://www.oracle.com/technology/deploy/security/database-security-10g/virtual-private-database/index.html"><img class="size-full wp-image-297" title="virtual-private-database1" src="http://www.gerbrand-ict.nl/wp-content/uploads/2009/06/virtual-private-database1.gif" alt="Virtual private database" width="456" height="175" /></a><p class="wp-caption-text">(c) Oracle</p></div>
<p>As described in the above image and referenced article, the user identified by userid 106 (let&#8217;s say that&#8217;s user john) will access the database using a private database connection. The user can only access rows that have that userid as primary or foreign key.  John can&#8217;t see the passwords, orders, credit card data or anything of other users even if he would somehow hack the webapplication. How to set up this finegrained securiy is beyond this article, but I hope the above example explains what the purpose VPD is.</p>
<p>If you develop your JEE software using Oracle software  proxy authentication requires only a bit of configuration, for example, see the following article how to setup proxy authentication using <a href="http://blogs.oracle.com/jheadstart/2008/01/28/">JHeadstart</a>.</p>
<p>However, what if you&#8217;re JEE applicication consists of non-oracle software? Can you still use proxy authentication when you use software like JBoss, Hibernate, IBatis, MyFaces, Wicket etc? Yes you can! I&#8217;ll explain below how to set up proxy authentication using JBoss in such a way you don&#8217;t have to modify any of the code that uses JDBC, directly or indirectly.</p>
<ul>
<li>First a way is needed to set a username for each (JDBC) database connection retrieved. <a href="http://www.it-eye.nl/weblog/2005/09/12/oracle-proxy-users-by-example/">It-eye weblog</a> explains how to open a connection to a database using java, and then switch to another username.</li>
<li>Secondly, in your application users should authenticate them self using the default mechanism of J2EE 1.4 (and higher) application, using <a href="http://java.sun.com/javase/technologies/security/">JAAS</a>. Usually creating a security policy inside your web.xml or inside your ear is enough. Here&#8217;s the information how to do this under JBoss: <a href="http://www.jboss.org/community/wiki/SecureAWebApplicationUsingACustomForm">Secure a webapplication</a>.<br />
Since we&#8217;re using a database, the best option would be to use database based authentication, meaning user information comes out of a database table. There&#8217;s a lot of documentation on the web how to do add security, so I won&#8217;t repeat that here.</li>
<li>Database connection in JBoss are retrieved using connection pooling, as is custom in any JEE server.  You can create a custom connection pool, that changes the switches to the user name that is currently logged in at the webapplication. That way, every action on the database is done under a database user that is currently logged in.Do to be able to do that, first, you&#8217;ll need a custom connection factory that extends the default connection factory. Our connection factory will return a customized datasource that modifies code.Here&#8217;s a code listing:
<pre class="brush: java;">package nl.gerbrandict.dbconnaudit;

import java.sql.SQLException;
import javax.resource.ResourceException;
import javax.resource.spi.ConnectionManager;

import org.apache.log4j.Logger;
import org.apache.commons.lang.StringUtils;
import org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory;

/**
 * An extended connection factory, that uses the Oracle feature to change the username of an existing connection
 *

 * When a user authenticated on the application server, the database connection will switch to that username.
 * This allows for better auditing and potentially for improved security.
 *
 * Properties (get'ers and set'ters) can be set via the configuration section of the -ds file
 * @author gvdieijen
 */
public class DBConnAuditConnectionFactory extends LocalManagedConnectionFactory {

    private String defaultProxyUser;

    public DBConnAuditConnectionFactory() throws SQLException {
        super();

    }

    @Override
    public Object createConnectionFactory(ConnectionManager cm) throws ResourceException {
        return new OracleWrapperDataSource(this, cm);
    }

    public void setEnableProxySession(Boolean enableProxySession) {
        this.enableDbConnAudit = enableProxySession;
    }

    public void setDefaultProxyUser(final String defaultProxyUser) {
        if (StringUtils.isEmpty(defaultProxyUser)) {
            this.defaultProxyUser=null;
        } else {
             this.defaultProxyUser = defaultProxyUser;
        }
    }

    /**
     * Default db user to open proxy session for, when no authenticated user is active
     * @return
     */
    public String getDefaultProxyUser() {
    	return this.defaultProxyUser;
    }
}</pre>
<p>As you can see, the file returns a OracleWrapperDatasource. That&#8217;s custom class, that extends the default WrapperDatasource of JBoss, and changes the user of jdbc connection just before the connection is handed of to the application. To speak in terms of the fine book</li>
<li>Now, How can you use that new class? They have to be packed into a rar file. Functionally, that&#8217;s a Resource Adapter, a module that allows a J2EE application to use resources. Technically (and practically), it&#8217;s just a jar-archive similar to a war, with a different extension. Maven can create these files automatically for you, if you set the packaging type to rar instead of jar (which is the default).</li>
<li>When you download JBoss, you&#8217;ll get a sample connection pool for a in-memory database: default-ds.xml, located in the server/default/deploy directory of jboss. To use the custom classses, copy the file into (for example) myoracleproxy-ds.xml and create a minor modification so a custom connection factory is used &#8211; update the managedconnectionfactory property, that a custom connectionfactory is used, that returns the proxied connections:
<pre class="brush: xml;">&lt;managedconnectionfactory-class&gt;nl.gerbrandict.dbconnaudit.DBConnAuditConnectionFactory&lt;/managedconnectionfactory-class&gt;</pre>
</li>
</ul>
<p>All in all, after some tweaking, all queries and updates to your Oracle database are done under the J2EE username. This means when user Joe logs in, all his database access will be logged under user Joe as well. This can improve auditing as well as security.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gerbrand-ict.nl/2010/06/proxying-authentication-using-jboss/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JBoss on Linux</title>
		<link>http://www.gerbrand-ict.nl/2009/07/jboss-on-linux/</link>
		<comments>http://www.gerbrand-ict.nl/2009/07/jboss-on-linux/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 11:21:26 +0000</pubDate>
		<dc:creator>gerbrand</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jboss]]></category>

		<guid isPermaLink="false">http://www.gerbrand-ict.nl/?p=342</guid>
		<description><![CDATA[Lately I tried to run JBoss on my Linux-installation (KUBuntu 9). I got lots of java.lang.OutOfMemoryError: PermGen space errors while starting JBoss 5. First I thought that had something to do with Linux. I google&#8217;d the error, and from what I read, permgen errors are caused by bugs in either JBoss or the JavaVM. So [...]]]></description>
			<content:encoded><![CDATA[<p>Lately I tried to run JBoss on my Linux-installation (KUBuntu 9). I got lots of  <code>java.lang.OutOfMemoryError: PermGen</code> space errors while starting JBoss 5. First I thought that had something to do with Linux. I google&#8217;d the error, and from what I read, permgen errors are caused by bugs in either JBoss or the JavaVM. So increasing memory won&#8217;t help, besides, JBoss ran fine on my Windows installation.<br />
Then I remembered JBoss had a separate package for Java JDK 1.5 and JDK 1.6. I used the JBoss- version for JDK 1.5, but I have JDK 1.6 installed on my Linux installation. After I switched to the JBoss 5.0 version for JDK 1.5, JBoss ran smoothly!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gerbrand-ict.nl/2009/07/jboss-on-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Threads-alternative in JEE: using the timerservice</title>
		<link>http://www.gerbrand-ict.nl/2009/04/threads-alternative-in-jee-using-the-timerservice/</link>
		<comments>http://www.gerbrand-ict.nl/2009/04/threads-alternative-in-jee-using-the-timerservice/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 15:14:46 +0000</pubDate>
		<dc:creator>gerbrand</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jboss]]></category>
		<category><![CDATA[jee]]></category>

		<guid isPermaLink="false">http://www.gerbrand-ict.nl/?p=171</guid>
		<description><![CDATA[A common problem in in developing Java Enterprise (JEE or J2EE) application is working with threads, or more generally executing code asynchronously. Starting and instantiating threads in the old-fashioned java way is not allowed. The reason: within JEE you work with EJB&#8217;s: Java Beans with managed resources. Databaseconnections, transactions, sessions, all of these resources are [...]]]></description>
			<content:encoded><![CDATA[<p>A common problem in in developing Java Enterprise (JEE or J2EE) application is working with threads, or more generally executing code asynchronously. Starting and instantiating threads in the old-fashioned java way is not allowed.<br />
The reason: within JEE you work with EJB&#8217;s: Java Beans with managed resources. Databaseconnections, transactions, sessions, all of these resources are managed by the application server. Usually resources such as databaseconnections are not thread-safe. The application server will take of any issues related to thread-safefety, as long as you don&#8217;t instantiate threads yourself. That being said, <em><strong>what is the JEE-alternative to using threads</strong></em>?</p>
<p>There are several possible answers to that question:</p>
<ul>
<li>Using a JMS, Java Messing Service. How to setup is beyond the scope of this weblog posting.</li>
<li>Use of the Timerservice. The timerservice is part of JEE-spec (since 1.4). Using a few annotations you can have the same functionality as you would have when using threads &#8211; but compliant with the JEE-spec. I&#8217;ll explain how to use the TimerService, so you can stop worrying about not being JEE compliant (with regard to threads)!</li>
</ul>
<p>The <a href="http://java.sun.com/javaee/5/docs/api/javax/ejb/TimerService.html">TimerService </a>can only be used within a stateless EJB bean. So to start you&#8217;ll have to define one, by adding the right annotations:</p>
<pre class="brush: java;">..

@Stateless
public class MyTimerExampleBean implements MyTimerExample {

}
...
public interface MyTimerExample {
}</pre>
<p>Within the bean you can inject the timerservice using the Resource annotation. As soon as the bean is deployed within an application server like JBoss, the bean is instantiated and the resources are injected and available for use.</p>
<pre class="brush: java;">    @Resource
    private TimerService timerService;</pre>
<p>Now we&#8217;ll use our timerservice. We define a method called <em>startMe </em>and a method <em>runMe</em>. The startMe method will define a timer. The timer will then execute the runMe method after a predefined time.</p>
<p>When the <em>runMe </em>method is to be executed, the bean is newly instantiated. This means, if you set any local variables within your bean, those values will be lost. For that reason, we use the <em><strong>myInfo </strong></em>class to transfer parameters, in this case a delay and the message we want to print to the screen.</p>
<pre class="brush: java;">class HelloWorldInfo implements Serializable {
   String message;
   long delay;
   int counter;
}
public void startMe() {
    long waitTime =60*1000; //60 seconds, 1 minute
    HelloWorldInfo taskInformation=new HelloWorldInfo();
   taskInformation.message="Hello world";
   taskInformation.delay=12*1000; //12 seconds
   taskInformation.counter=0;

   Timer timer = timerService.createTimer(waitTime, taskInformation);

}
    @Timeout
    public synchronized void runMe(Timer timer) {

      final HelloWorldInfo myInfo = (HelloWorldInfo ) timer.getInfo();

      System.out.println("Going to do something important");
      Thread.wait(5000);
      System.out.println(myInfo.delay);
      System.out.println(myInfo.message);
  }</pre>
<p>That&#8217;s all there is! Using the above code, will allow you to run code asynchronously in a similar fashion when using Thread and Runnable classes. You could for example call a remote webservice, or run a batch job on the database. The method runMe will run within a separate transaction &#8211; in case an error is thrown within the the runMe method, the transaction is rolled back. Since the bean is instantiated using the JEE-container, any resources associated with the bean will be discarded.</p>
<p>If you want want to execute the run method again, the easiest way is to call the startMe method again:</p>
<pre class="brush: java;">   public synchronized void runMe(Timer timer) {
     ...

   myInfo.counter++;
   myInfo.message="Doing hello world again for the "+myInfo.counter;
   myInfo.delay=6*1000; //now after 6 seconds

   Timer timer = timerService.createTimer(waitTime , myInfo
);
  }</pre>
<p>The myInfo is modified and passed again to the timerserver. So next time the bean is instantiated and the run method is executed, it&#8217;ll display &#8216;Doing hello world again 1&#8242;, and will do so with an incrementing number until the application server is shut down. You can pass any information on, as long as the the class containing the information is serializable.</p>
<hr />
<table width='100%'>
<tr>
<td>
<iframe src="http://rcm.amazon.com/e/cm?t=geonic-20&#038;o=1&#038;p=8&#038;l=as1&#038;asins=1933988029&#038;fc1=000000&#038;IS2=1&#038;lt1=_blank&#038;m=amazon&#038;lc1=0000FF&#038;bc1=000000&#038;bg1=FFFFFF&#038;f=ifr&#038;nou=1" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>
</td>
<td border='1' align='right'><strong>Bol.com</strong><br/><br />
<A HREF="http://clk.tradedoubler.com/click?a=1601917&#038;p=67859&#038;g=17297702&#038;epi=1001004005604637" TARGET="_BLANK"><IMG SRC="http://www.bol.com/imgbase0/thumb/BOOKCOVER/FC/1/9/3/3/9/1933988029.gif" ALT="Jboss in Action" BORDER="0"><BR>Jboss in Action<BR>Javid Jamae &#038; Peter Johnson<BR></A>
 </td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.gerbrand-ict.nl/2009/04/threads-alternative-in-jee-using-the-timerservice/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Open JMX consoles</title>
		<link>http://www.gerbrand-ict.nl/2009/03/open-jmx-consoles/</link>
		<comments>http://www.gerbrand-ict.nl/2009/03/open-jmx-consoles/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 13:24:21 +0000</pubDate>
		<dc:creator>gerbrand</dc:creator>
				<category><![CDATA[Various]]></category>
		<category><![CDATA[jboss]]></category>

		<guid isPermaLink="false">http://www.gerbrand-ict.nl/?p=151</guid>
		<description><![CDATA[If you search on google on DummyResourceAdapter, you&#8217;ll find (at least currently) a lot of open administration consoles of JBoss, the JMX-console. These consoles should not be available to the open internet, but I guess someone forgot the close them. Take for example the console of the website called www.ccidgroup.net: what would happen when you [...]]]></description>
			<content:encoded><![CDATA[<p>If you search on google on <a href="http://www.google.nl/search?q=DummyResourceAdapter">DummyResourceAdapter</a>, you&#8217;ll find (at least currently) a lot of open administration consoles of JBoss, the JMX-console. These consoles should not be available to the open internet, but I guess someone forgot the close them.</p>
<p>Take for example the console of the website called <a href="http://www.ccidgroup.net">www.ccidgroup.net</a>: what would happen when you hit destroy button on the <a href="http://www.ccidgroup.net/jmx-console/HtmlAdaptor?action=inspectMBean&amp;name=jboss.management.local%3AJ2EEApplication%3Djbossweb-tomcat55.sar%2CJ2EEServer%3DLocal%2Cj2eeType%3DWebModule%2Cname%3DROOT.war">MBean Inspector of the ROOT.war</a> ?</p>
<table border="0">
<tbody>
<tr>
<td><img src="http://www.gerbrand-ict.nl/wp-content/uploads/2009/03/logo.gif" border="0" alt="JBoss" align="left" /></td>
<td valign="middle">
<h1>JMX MBean View</h1>
</td>
</tr>
</tbody>
</table>
<table border="0">
<tbody>
<tr>
<td>MBean Name:</td>
<td><strong>Domain Name:</strong></td>
<td>jboss.management.local</td>
</tr>
<tr>
<td></td>
<td><strong>name: </strong></td>
<td>ROOT.war</td>
</tr>
<tr>
<td></td>
<td><strong>J2EEServer: </strong></td>
<td>Local</td>
</tr>
<tr>
<td></td>
<td><strong>J2EEApplication: </strong></td>
<td>jbossweb-tomcat55.sar</td>
</tr>
<tr>
<td></td>
<td><strong>j2eeType: </strong></td>
<td>WebModule</td>
</tr>
<tr>
<td>MBean Java Class:</td>
<td colspan="3">org.jboss.management.j2ee.WebModule</td>
</tr>
</tbody>
</table>
<p>&#8230;</p>
<p><img class="alignnone size-full wp-image-152" title="destroy" src="http://www.gerbrand-ict.nl/wp-content/uploads/2009/03/destroy.jpg" alt="destroy" width="142" height="102" /></p>
<p>I haven&#8217;t tried and I&#8217;ve sent a mail to webmaster@domain &#8211; but I&#8217;m slightly curious.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gerbrand-ict.nl/2009/03/open-jmx-consoles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Distributed software with JGroups</title>
		<link>http://www.gerbrand-ict.nl/2009/03/shared-state-with-jgroups/</link>
		<comments>http://www.gerbrand-ict.nl/2009/03/shared-state-with-jgroups/#comments</comments>
		<pubDate>Wed, 11 Mar 2009 08:59:48 +0000</pubDate>
		<dc:creator>gerbrand</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jboss]]></category>

		<guid isPermaLink="false">http://www.gerbrand-ict.nl/?p=85</guid>
		<description><![CDATA[JGroups A distributed application, where nodes of the application communicate with each other over a LAN using UDP. Each nodes discovers other nodes automatically, when a node crashes or shuts down, all nodes give notice automatically. And this is all possible without any application server, complicated configuration or what-ever-else with JGroups! There are quite some [...]]]></description>
			<content:encoded><![CDATA[<p><!-- 	 	 --></p>
<h1>JGroups</h1>
<p>A distributed application, where nodes of the application communicate with each other over a LAN using UDP. Each nodes discovers other nodes automatically, when a node crashes or shuts down, all nodes give notice automatically. And this is all possible without any application server, complicated configuration or what-ever-else with JGroups!</p>
<p>There are quite some tutorials, so I just list the basic steps to get started, most notably the maven dependencies.</p>
<h2>Download JGroups</h2>
<p>First download JGroups. You can get the latest version from the website <a href="http://www.jgroups.org/">JGroups</a>. Alternatively, you can use Maven. First set up a maven-project, which is beyond the scope of this tutorial.</p>
<p>Add the JBoss repository, by adding 	the following entry to the repositories section of the maven project 	file (pom.xml):</p>
<pre>&lt;repository&gt;

&lt;id&gt;maven.jboss.org&lt;/id&gt;

&lt;name&gt;JBoss Maven Repository&lt;/name&gt;

&lt;url&gt;http://repository.jboss.com/maven2&lt;/url&gt;

&lt;/repository&gt;</pre>
<p>After that add the following dependencies to the 	Maven for the jgroups artifact (I use the current latest 	versions):</p>
<pre>&lt;dependency&gt;

&lt;groupId&gt;jgroups&lt;/groupId&gt;

&lt;artifactId&gt;jgroups&lt;/artifactId&gt;

&lt;version&gt;2.7.0.GA&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;

&lt;groupId&gt;log4j&lt;/groupId&gt;

&lt;artifactId&gt;log4j&lt;/artifactId&gt;

&lt;version&gt;1.2.15&lt;/version&gt;

&lt;/dependency&gt;</pre>
<h2>Setting up a channel</h2>
<p>To start using JGroups, no configuration or application server is necessary. In this posting very briefly a class will be that uses JGroups to transmit messages over nodes:</p>
<p>First import the necessary classes:</p>
<pre class="java">import org.jgroups.*;</pre>
<p>Now set up a channel:</p>
<pre class="java">JChannel ch = new JChannel();</pre>
<p>The code below you can put in a constructor of your class, so the JChannel is initalized only once. That&#8217;s all there is! When you run the application multiple times inside the network (or on your own machine, for testing), JGroups will automatically detect other nodes.</p>
<p>Now you can add a receiver to channel, to start receiving messages and being updated of new nodes.</p>
<p>This is possible by implementing the Receiver interface, as demonstrated below:</p>
<pre class="java">public class JGroupStart implements Receiver {

	private final static String CLUSTERNAME = "JGroups tutorial cluster";

	public JGroupStart() throws Exception {

		JChannel ch = new JChannel();
		ch.setReceiver(this);

		ch.connect(CLUSTERNAME);

        System.out.println("JGroups cluster is gestart");

        Thread.sleep(10000);

        Message m = new Message();
		m.setObject(new String("Hello world from node "+ch.getLocalAddressAsString()));
        ch.send(m);
	}

	public byte[] getState() {
        return null;
	}

	public void receive(Message message) {
		System.out.println("Messsage received: " + message.getObject());
	}

	public void setState(byte[] state) {

	}

	public void block() {
	}

	public void suspect(Address address) {
	}

	public void viewAccepted(View view) {
		System.out.println("A node has appeared or disappeared, got a new view: " + view);
		for (Address a : view.getMembers()) {
			System.out.println("Member address " + a);
		}
	}

	public static void main(String [] args) throws Exception {
		JGroupStart app=new JGroupStart();
	}
}</pre>
<p>The class contains a main method so we can start it. After starting, a JGroups server &#8211; a node &#8211; in our network:</p>
<pre>-------------------------------------------------------
GMS: address is 172.168.11.109:1999
-------------------------------------------------------
A node has appeared or disappeared, got a new view: [172.168.11.109:1999|0] [172.168.11.109:1999]
Member address 172.168.11.109:1999
JGroups cluster is gestart</pre>
<p>To send a message over a channel, you can use the following code:</p>
<pre class="java">Message m = new Message();
		m.setObject("Hello world");
ch.send(m);</pre>
<p>The setObject method accepts any Serializable class, in this case I just sent a simple String. All other nodes will receive this message:</p>
<p><em>Messsage received: Hello world</em></p>
<p>Allthough simple as that seems, the concept is powerful. As said, nodes discover eachother automatically. When a node crashes or disappears, other nodes are notified automatically. Naturally there are much more advanced examples then what I listed above. On the JGroups site there&#8217;s a article how to set up <a href="http://www.jgroups.org/taskdistribution.html">A simple clustered task distribution system</a>.<br />
Furthermore, <a href="http://www.jboss.org/projects">JBoss</a> 5.0GA contains a Cache: <a href="http://www.jboss.org/jbosscache">JBoss Cache</a>. The distributed cache is built on top of JGroups. Using the JBoss Cache, JBoss can run distributed on multiple servers &#8211; this means if one server crashes or goes down for maintaince, another server takes over. Users or visitors of your site won&#8217;t even notice &#8211; except that the whole site might be a bit slower.<br />
Of course the cache can be used outsite JBoss too. JBoss cache can be used <a href="http://www.jboss.org/jbosscache">standalone</a>, allowing any Java application &#8211; standalone or not &#8211; to take advantage of this nice powerful open source technology.</p>
<hr />
<iframe src="http://rcm.amazon.com/e/cm?t=geonic-20&#038;o=1&#038;p=8&#038;l=as1&#038;asins=1933988029&#038;fc1=000000&#038;IS2=1&#038;lt1=_blank&#038;m=amazon&#038;lc1=0000FF&#038;bc1=000000&#038;bg1=FFFFFF&#038;f=ifr&#038;nou=1" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gerbrand-ict.nl/2009/03/shared-state-with-jgroups/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lessons learnt using JBoss 5 clustering</title>
		<link>http://www.gerbrand-ict.nl/2009/03/lessons-learnt-using-jboss-500ga-clustering/</link>
		<comments>http://www.gerbrand-ict.nl/2009/03/lessons-learnt-using-jboss-500ga-clustering/#comments</comments>
		<pubDate>Wed, 04 Mar 2009 21:55:56 +0000</pubDate>
		<dc:creator>gerbrand</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jboss]]></category>

		<guid isPermaLink="false">http://www.gerbrand-ict.nl/?p=91</guid>
		<description><![CDATA[Last week I spent some time getting clustering to work using JBoss 5.0.0 GA. I made a few mistakes and I thought I share them &#8211; even though they were rather obvious: In JBoss you have have a few standard configurations &#8211; limited, default, all . I tried to get clustering to work on the [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I spent some time getting clustering to work using JBoss 5.0.0 GA. I made a few mistakes and I thought I share them &#8211; even though they were rather obvious:</p>
<ol>
<li>In JBoss you have have a few standard configurations &#8211; 	limited, default, all . I tried to get clustering to work on the 	default configuration. I installed the pojocache, but then I had I 	had some problems getting @Replicated annotation to work (see also 	the posting below). After some <a href="http://www.jboss.org/index.html?module=bb&amp;op=viewtopic&amp;t=146826" target="_blank">Google&#8217;ing 	jboss errors</a> something like AOP seemed have to be enabled.The 	Pojocache I got working, by downloading and adding the libraries 	myself. Then I found these libraries were already included in the 	all configuration.<br />
Still, the @Replicateble tag didn&#8217;t work. Just recently someone replied at my (slightly too frustrated) post <a href="http://www.jboss.org/index.html?module=bb&amp;op=viewtopic&amp;p=4223159#4223159">at JBoss forum</a>.<br />
The following options still need to be added to the <strong>run.sh</strong> or<strong> run.bat </strong>in the bin directory:</p>
<pre>set JAVA_OPTS=-Dsun.rmi.dgc.server.gcInterval=3600000 -Dsun.lang.ClassLoader.allowArraySyntax=true -Djboss.platform.mbeanserver  -javaagent:%JBOSS_HOME%/server/all/deployers/jboss-aop-jboss5.deployer/pluggable-instrumentor.jar %JAVA_OPTS%</pre>
<p>I haven&#8217;t tried the above option yet &#8211; I used the Serializable interface, although that&#8217;s a whole lot less powerful of course.<br />
Note you can use <a href="http://javahowto.blogspot.com/2006/07/javaagent-option.html">multiple java agents</a>, so in case you use another agent like <a href="http://www.zeroturnaround.com/javarebel/">javarebel</a>, that shouldn&#8217;t be a problem.</li>
<li>A nice thing in JBoss seemed the PojoCache. To get it to 	work, you&#8217;ll have to create a pojocache-service.xml (see <a href="http://www.jboss.org/file-access/default/members/jbosscache/freezone/docs/2.0.0.GA/PojoCache/en/html/configuration.html" target="_top">PojoCache 	manual</a>) and put the file in the server\all\deploy directory of 	your jboss-directory. After that you can reference the PojoCache 	using the following code:
<pre class="brush: java;">MBeanServer server = MBeanServerLocator.locateJBoss();

ObjectName on = null;

try {

on = new ObjectName("jboss.cache:service=PojoCache");

} catch (MalformedObjectNameException e) {

throw new ContinuAansturingException("Cache service niet correct geconfigureerd.", e);

}

PojoCacheJmxWrapperMBean cacheWrapper = (PojoCacheJmxWrapperMBean)

MBeanServerInvocationHandler.newProxyInstance(server, on,

PojoCacheJmxWrapperMBean.class, false);

PojoCache cache = cacheWrapper.getPojoCache();
</pre>
<li>Clustering 	Session beans -I needed a share state, for the time the application 	was running (no need for persistence). Using a clustered cache 	seemed perfect for that. I decided to use the @Clustered annotation, 	that works out-of-the-box, I do not have to configure the 	pojocache. Due to my lack of EJB-knowledge and hindsight, I 	thought to annotate a Stateful bean &#8211; seemed reasonable to get a 	shared state. As people with slightly more EJB experience known &#8211; 	a Stateful bean isn&#8217;t meant for that! The state is only kept inside 	a (user) transaction. As soon as the transaction is commit&#8217;ed or 	rolled back, the state is lost.<br />
Cost my some time before I 	figured that out, after a few null references.</li>
<li>Setting up the right node id and listening to right network interface &#8211; For nodes to discover each other, they have to listen to a network interface that connects them to eachother. By default JBoss will listen to localhost, so only nodes running on the same server will be detected. Naturally, you normally don&#8217;t nodes to discover eachother. This is possible by adding the following command-line arguments:<em> –b <strong>10.0.0.53</strong></em> (where you can replace<strong> 10.0.0.53</strong> with the correct network -address)<br />
Furthermore, all nodes in the network have to have a unique nodeid. This can be set by the following command-line argument: <em>-Djboss.messaging.ServerPeerID=<strong>2 </strong></em>where you can replace the 2 with any unique identifier.<br />
As listed above, you need the &#8216;all&#8217; configuration, or a copy there of. So an example of complete command to run jboss on windows would be:</p>
<pre>run -c all –b 10.0.0.53 -Djboss.messaging.ServerPeerID=2</pre>
</li>
</ol>
<p>All in all, having a good book sooner would have saved me quite some time before. I now have the very recently released <a href="http://www.amazon.com/gp/product/1933988029?ie=UTF8&amp;tag=geonic-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=1933988029">JBoss in Action</a>. The book helps a lot in understanding and using JBoss because the JBoss site is seriously lacking in good documentation. Maybe that&#8217;s the price you pay for using open-source: the only way Redhat can make money on JBoss is on support.</p>
<hr />
<table width='100%'>
<tr>
<td>
<iframe src="http://rcm.amazon.com/e/cm?t=geonic-20&#038;o=1&#038;p=8&#038;l=as1&#038;asins=1933988029&#038;fc1=000000&#038;IS2=1&#038;lt1=_blank&#038;m=amazon&#038;lc1=0000FF&#038;bc1=000000&#038;bg1=FFFFFF&#038;f=ifr&#038;nou=1" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>
</td>
<td border='1' align='right'><strong>Bol.com</strong><br/><br />
<A HREF="http://clk.tradedoubler.com/click?a=1601917&#038;p=67859&#038;g=17297702&#038;epi=1001004005604637" TARGET="_BLANK"><IMG SRC="http://www.bol.com/imgbase0/thumb/BOOKCOVER/FC/1/9/3/3/9/1933988029.gif" ALT="Jboss in Action" BORDER="0"><BR>Jboss in Action<BR>Javid Jamae &#038; Peter Johnson<BR></A>
 </td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.gerbrand-ict.nl/2009/03/lessons-learnt-using-jboss-500ga-clustering/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Frustation on JBoss</title>
		<link>http://www.gerbrand-ict.nl/2009/02/frustation-on-jboss/</link>
		<comments>http://www.gerbrand-ict.nl/2009/02/frustation-on-jboss/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 20:41:07 +0000</pubDate>
		<dc:creator>gerbrand</dc:creator>
				<category><![CDATA[Reviews]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jboss]]></category>

		<guid isPermaLink="false">http://www.gerbrand-ict.nl/?p=82</guid>
		<description><![CDATA[For some application I need a notion of &#8216;shared state&#8217; within a cluster of computers within a network. The software will have to run on JBoss. Yesterday I had successfully setup a JGroups using the default configuration. Using a fine tutorial I had set up a shared state. JGroups provided a lot functionality so that [...]]]></description>
			<content:encoded><![CDATA[<p>For some application I need a notion of &#8216;shared state&#8217; within a cluster of computers within a network. The software will have to run on JBoss. Yesterday I had successfully setup a JGroups using the default configuration. Using a fine tutorial I had set up a shared state. JGroups provided a lot functionality so that I not have to work with sockets, multicast, discovery, etc. myself. However, transactions, 2 phase commits, serialization wasn’t standard functionality, which I needed too. I didn’t want to reinvent the wheel, so I decided to use JBoss Cache, which is built on top on JGroups.</p>
<p>I could successfully instantiate a cache, using the default factory class. However, a more proper way would be to have JBoss instantiate and manage the cache, since the application has to run on top of JBoss.</p>
<p>In the <a href="http://www.jboss.org/file-access/default/members/jbosscache/freezone/docs/3.0.2.GA/userguide_en/html_single/index.html">JBoss Cache documentation</a> I’ve found the following entry:</p>
<pre class="brush: java;">CacheFactory factory = new DefaultCacheFactory();

// Build but don't start the cache

// (although it would work OK if we started it)

Cache cache = factory.createCache("cache-configuration.xml");

MBeanServer server = getMBeanServer(); // however you do it

ObjectName on = new ObjectName("jboss.cache:service=Cache");

JmxRegistrationManager jmxManager = new JmxRegistrationManager(server, cache, on);

jmxManager.registerAllMBeans();

... use the cache

... on application shutdown

jmxManager.unregisterAllMBeans();

cache.stop();</pre>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;"> </span></p>
<p class="MsoNormal"><span lang="EN-US"> </span></p>
<p class="MsoNormal"><span lang="EN-US">Sounds great doesn’t it? Well, first of all, it’s an awful lot of code just to get access to the cache. Secondly, there’s a reference to a configuration file you first have to place somewhere, and thirdly there’s the line that’s commented with:<br />
</span></p>
<pre class="brush: java;">// however you do it</pre>
<p>Arg! Why can’t those people of JBoss just explain *how* I have to do that. You might say, a clustered cache is complicated stuff. Transactions, commits over network, multi casts. That’s all pretty complicated. However, this configuration crap has nothing to do with that. I *hate* configuration. I *hate* xml. I just want working stuff.</p>
<p>O well, most closed source software isn’t much better, if not much worse. Probably what the people behind JBoss wants users to do, is buy a support contract. Still a lot less expensive than software like Weblogic or Websphere.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gerbrand-ict.nl/2009/02/frustation-on-jboss/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
