Running multiple instance of JBoss AS
September 25th, 2007 Radim Marek Posted in Administration |
Either setting up clustered environment for development/testing, need to isolate different application, or necessity of running different version of JBoss AS on the same machine. No matter what is the reason for running multiple instances of JBoss AS, for most users it’s quite a daunting task. Most common technique how to achieve it is complicated manual change of all ports numbers to be different. But what to do during upgrade? Do you really want to go through it all over again?
JBoss AS provides a simple mechanism how to run several (by default up to 4) instances. The Binding Manager is a service that enables centralized management of ports by its ability to configure other services before any of their lifecycle methods are invoked.
The service is not used by default, and you need it to enable it within <configuration>/conf/jboss-service.xml file. Sample configuration is following:
<mbean code="org.jboss.services.binding.ServiceBindingManager" name="jboss.system:service=ServiceBindingManager">
<attribute name="ServerName">ports-01</attribute>
<attribute name="StoreURL">${jboss.home.url}/docs/examples/binding-manager/sample-bindings.xml</attribute>
<attribute name="StoreFactoryClassName"> org.jboss.services.binding.XMLServicesStoreFactory</attribute>
</mbean>
Where ServerName is unique name assigned to an instance, and configured within store available at StoreURL. As the example shows sample binding configuration is available in binding-manager.xml file at /docs/examples/binding-manager folder of your JBoss AS installation.
To use this service, create two or more server configuration, enable the binding manager for each of them and assign a unique server name for binding manager. Sample bindings file includes these server profiles:
- default
- ports-01
- ports-02
- ports-03
Once the service is setup, you can start all your configurations at the same time without conflicts – no more
java.net.BindException: Address already in use: JVM_Bind
In case you’re using DefaultDS with Hypersonic Database, you need to switch this local database to use TCP setup (by settings InProcessMode to true, within hsqldb-ds.xml) and enable Hypersonic related services override manually within bindings configuration for selected ServerName.
In the production environment your system administrator will most likely place binding’s configuration file somewhere within system wide configuration location. Please, don’t forget StoreURL is link to file, not a simple file system path.
Custom service override
Binding Manager is easily configurable to override custom services. Easiest option is use of Attribute mapping delegation, where the port is replaced within service’s attribute.
<service-config name="my.custom:service=SomeService" delegateClass="org.jboss.services.binding.AttributeMappingDelegate">
<delegate-config portName="Port"/>
<binding port="6789" />
</service-config>
If the configuration you want to override is included within XML configuration file and not as service’s attribute, you have to use XSLTConfigDelegate that expects a delegate-config element of the form:
<delegate-config>
<xslt-config configName="ConfigurationElement"><![CDATA[
Any XSL document contents... ]]> </xslt-config>
<xslt-param name="param-name">param-value</xslt-param>
<!-- ... -->
</delegate-config>
Example available within sample-bindings.xml for Hypersonic related services.
Leave a Reply