Configuring Applications For Both Clustered And Non Clustered Environments

Version 5

    The aim of this wiki is to explain how to configure applications so that they can be deployed both as clustered and as non-clustered applications in the most efficient way.


    Do I Really Need To Do This?

    It's worth noting that often, one of the reasons to deploy a clustered application in a non-clustered environment is for development purpouses. Maintaining a network where different developers are creating their clusters can be quite tricky from a multicast traffic management perspective but there're workarounds available to disable multicast traffic from landing on the network. Tricks like JBossASClusteringTestsuite or setting clustering traffic ttl to 0 via -Djgroups.udp.ip_ttl=0, constrain multicast traffic to the local machine, hence allowing developers to run their own clusters locally without affecting others. If you feel you still need to configure your application for both clustered and non-clustered environments, please read ahead.


    EJB2 or EJB3 Deployments

    The easiest way to get EJBs deployed in as clustered in clustered environments and as non-clustered in non-clustered environments, is to define the clustering aspect via META-INF/jboss.xml rather than using @Clustered annotation in the case of EJB3s. JBoss has the capability of substituting pieces of XML with a specific value defined as a system property. So, for example, the following META-INF/jboss.xml allows you to control whether EJBs are deployed as clustered or not depending on whether is defined or not. If is passed when the server is started up, TimeTellerEjb will be deployed as clustered. If is passed or no system property is defined on startup, the EJB will be deployed as non-clustered:

    <?xml version="1.0"?>
    <!DOCTYPE jboss PUBLIC -//JBoss//DTD JBOSS 4.0//EN


    Unfortunately, there's currently no way of defining globally whether EJBs should be deployed as clustered or non-clustered.


    Web Deployments

    In the of case WAR deployments, the way a web application is marked as clustered is by setting <distributable/> XML configuration element in WEB-INF/web.xml. Unfortunately, <distributable/> is an empty element and hence the same trick used with EJBs cannot be used. However, there's no problem in deploying a web application marked as <distributable/> in a non-clustered environment. Worst case scenario you'll get a WARN message like this during deployment but the application will work fine:

    16:32:58,567 WARN  [TomcatDeployer] Failed to setup clustering, clustering disabled. NoClassDefFoundError: org/jgroups/blocks/MethodCall