Lessons learnt using JBoss 5 clustering

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 – even though they were rather obvious:

  1. In JBoss you have have a few standard configurations – 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 Google’ing jboss errors 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.
    Still, the @Replicateble tag didn’t work. Just recently someone replied at my (slightly too frustrated) post at JBoss forum.
    The following options still need to be added to the run.sh or run.bat in the bin directory:

    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%

    I haven’t tried the above option yet – I used the Serializable interface, although that’s a whole lot less powerful of course.
    Note you can use multiple java agents, so in case you use another agent like javarebel, that shouldn’t be a problem.

  2. A nice thing in JBoss seemed the PojoCache. To get it to work, you’ll have to create a pojocache-service.xml (see PojoCache manual) and put the file in the serveralldeploy directory of your jboss-directory. After that you can reference the PojoCache using the following code:
    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();
  3. 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 – seemed reasonable to get a shared state. As people with slightly more EJB experience known – a Stateful bean isn’t meant for that! The state is only kept inside a (user) transaction. As soon as the transaction is commit’ed or rolled back, the state is lost.
    Cost my some time before I figured that out, after a few null references.
  4. Setting up the right node id and listening to right network interface – 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’t nodes to discover eachother. This is possible by adding the following command-line arguments: –b (where you can replace with the correct network -address)
    Furthermore, all nodes in the network have to have a unique nodeid. This can be set by the following command-line argument: -Djboss.messaging.ServerPeerID=2 where you can replace the 2 with any unique identifier.
    As listed above, you need the ‘all’ configuration, or a copy there of. So an example of complete command to run jboss on windows would be:

    run -c all –b -Djboss.messaging.ServerPeerID=2

All in all, having a good book sooner would have saved me quite some time before. I now have the very recently released JBoss in Action. The book helps a lot in understanding and using JBoss because the JBoss site is seriously lacking in good documentation. Maybe that’s the price you pay for using open-source: the only way Redhat can make money on JBoss is on support.

Jboss in Action
Jboss in Action
Javid Jamae & Peter Johnson

3 Replies to “Lessons learnt using JBoss 5 clustering”

  1. Dear Gerbrand
    I am in urgent need to cluster JBoss AS instances . I also need to cluster JMS queue , JMS connectionfactory and Datasource.

    I dont have proper guide or manual to cluster .

    Please provide me if you have any good guide or let me know if i can call you and discuss the same.

  2. I don’t think your mistakes where that obvious. IMO documentation regarding the usage of PojoCache in JBoss AS (5) is very hard to find. It took me almost two days as well. I appreciate your information about the JBossAOP loadtime weaving.

    While searching for answers I found information that might be useful for others as well:

    In JBoss AS 5 one can also use a CacheManager to obtain caches (both core caches ande POJO caches). The CacheManager is defined in “server/all/deploy/cluster/jboss-cache-manager.sar/META-INF/jboss-cache-manager-jboss-beans.xml”. The CacheManager will (by default) be registered in JNDI under the name “java:/CacheManager” (and in JMX as well), IMO obtaining it via JNDI is cleaner.