This chapter discusses useful MBean services that are not discussed elsewhere either because they are utility services not necessary for running JBoss, or they don't fit into a current section of the book.
The management of system properties can be done using the org.jboss.varia.property.SystemPropertiesService MBean. It supports setting of the VM global property values just as java.lang.System.setProperty method and the -Dproperty=value VM command line arguments do.
Its configurable attributes include:
Both attributes are illustrated in See An example SystemPropertiesService jboss-service descriptor..
<mbean code="org.jboss.varia.property.SystemPropertiesService"
name="jboss.util:type=Service,name=SystemProperties">
<!-- Load properties from each of the given comma seperated URLs -->
http://somehost/some-location.properties,
<!-- Set propertuies using the properties file style. -->
property1=This is the value of my property
Support for managing java.bean.PropertyEditor instances is available through the org.jboss.varia.property.PropertyEditorManagerService MBean. This is a simple service that help define PropertyEditors using the java.bean.PropertyEditorManager class. This service is used in the main jboss-service.xml file to preload the custom JBoss PropertyEditor implementations. This is necessary for some JDK1.3.0 VMs that will only load PropertyEditors from the system classpath.
Its supported attributes include:
With all of the independently deployed services available in JBoss, running multiple instances on a given machine can be a tedious exercise in configuration file editing. The binding service, org.jboss.services.binding.ServiceBindingManager , allows one to map service attribute values from a central location. After a service's descriptor file is parsed and the initial attribute values have been applied to the service, the ServiceConfigurator queries the ServiceBindingManager to apply any overrides that may exist for the service. The ServicesBindingManager acts a coordinator between the ServiceConfigurator , a store of configuration overrides, the service configuration, and a configuration delegate that knows how to apply a configuration to a service. The classes in this act are shown in See Class diagram for the org.jboss.services.binding package of the ServiceBindingManager..
The first thing to note about the ServiceBindingManager is that it implements the JMX MBeanRegistration interface methods as its life cycle notification interface rather than the JBoss service interface. This is necessary because the ServiceBindingManager operates on other services attribute values. Attributes are set before any JBoss service life cycle methods are called, and so the ServiceBindingManager must be active as soon as it is registered with the MBeanServer . The setup of the ServiceBindingManager occurs in the postRegister(Boolean) callback method.
The ServiceBindingManager is associated with a ServicesStore through a ServicesStoreFactory . The ServicesStoreFactory is set through an attribute of the ServiceBindingManager . The set of configurable attributes of the ServiceBindingManager include:
A ServicesStore is just a collection of ServiceConfig objects keyed by a JBoss instance name and the JMX ObjectName of the service. A ServiceConfig is a collection of ServiceBinding objects and a ServicesConfigDelegate that knows how to map a ServiceBinding onto a target MBean. The ServiceConfig may also contain an arbitrary configuration for the delegate. A ServiceBinding is a named (interface, port) pair.
So what happens when the ServiceBindingManager is asked to override a service's configuration? The sequence of events is illustrated by See How the ServiceConfigurator queries the ServiceBindingManager..
That is the generic overview of the ServiceBindingManager . Let's take a look at how you can use this service to bring up two JBoss instances of the default configuration set of services on the same machine to make this more concrete.
JBoss ships with a service configuration ServiceBindingManager for the along with a sample ServicesStore XML file for starting two JBoss instances on the same host. Here we will walk through the steps to bring up the two instances and look at the sample configuration. Start by making two server configuration file sets called jboss0 and jboss1 by running the following command from the book examples directory:
[nr@toki examples]$ ant -Dchap=chap10 -Dex=1 run-example
[echo] Preparing jboss0 configuration fileset
[mkdir] Created dir: /tmp/jboss-3.2.3/server/jboss0
[copy] Copying 148 files to /tmp/jboss-3.2.3/server/jboss0
[copy] Copied 2 empty directories to /tmp/jboss-3.2.3/server/jboss0
[copy] Copying 1 file to /tmp/jboss-3.2.3/server/jboss0/conf
[copy] Copying 1 file to /tmp/jboss-3.2.3/server
[echo] Preparing jboss1 configuration fileset
[mkdir] Created dir: /tmp/jboss-3.2.3/server/jboss1
[copy] Copying 148 files to /tmp/jboss-3.2.3/server/jboss1
[copy] Copied 2 empty directories to /tmp/jboss-3.2.3/server/jboss1
This creates duplicates of the server/default configuration file sets as server/jboss0 and server/jboss1, and then replaces the conf/jboss-service.xml descriptor with one that has the ServiceBindingManager configuration enabled as follows:
<mbean code="org.jboss.services.binding.ServiceBindingManager"
name="jboss.system:service=ServiceBindingManager">
<attribute name="ServerName">${jboss.server.name}</attribute>
<attribute name="StoreURL">${jboss.server.base.dir}/chap10ex1-bindings.xml</attribute>
<attribute name="StoreFactoryClassName">
org.jboss.services.binding.XMLServicesStoreFactory
The chap10ex1-bindings.xml file contains two server configurations named jboss0 and jboss1. The jboss0 configuration uses the default settings for the ports, while the jboss1 configuration adds 100 to each port number. The bindings file is a duplicate of the docs/examples.binding-service.sample-bindings.xml with jboss0 and jboss1 as the server names.
The DTD showin in See The binding service XMLServicesStoreFactory DTD. is the one supported by the XMLServicesStoreFactory class. The elements are:
The two ServicesConfigDelegate are AttributeMappingDelegate and XSLTConfigDelegate . The AttributeMappingDelegate class is an implementation of the ServicesConfigDelegate that expects a delegate-config element of the form:
<delegate-config portName="portAttrName" hostName="hostAttrName">
<attribute name="someAttrName">someHostPortExpr</attribute>
where the portAttrName is the attribute name of the MBean service to which the binding port value should be applied, and the hostAttrName is the attribute name of the MBean service to which the binding host value should be applied. If the portName attribute is not specified then the binding port is not applied. Likewise, if the hostName attribute is not specified then the binding host is not applied. The optional attribute element(s) specify arbitrary MBean attribute names whose values are a function of the host and/or port settings. Any reference to ${host} in the attribute content is replaced with the host binding and any ${port} reference is replaced with the port binding. As of the 3.2.2RC4 release, the portName, hostName attribute values and attribute element content may reference system properties using the ${x} syntax that is supported by the JBoss services descriptor.
From the sample listing, lines 7-12 illustrate an example of the AttributeMappingDelegate usage:
<service-config name="jboss:service=Naming"
delegateClass="org.jboss.services.binding.AttributeMappingDelegate"
<delegate-config portName="Port"/>
Here the "jboss:service=Naming" MBean service has its Port attribute value overridden to 1099. The corresponding setting from the jboss1 server configuration overrides the port to 1199.
The XSLTConfigDelegate class is an implementation of the ServicesConfigDelegate that expects a delegate-config element of the form:
<xslt-config configName="ConfigurationElement"><![CDATA[
<xslt-param name="param-name">param-value</xslt-param>
The xslt-config child element content specifies an arbitrary XSL script fragment that is to be applied to the MBean service attribute named by the configName attribute. The named attribute must be of type org.w3c.dom.Element . The optional xslt-param elements specify XSL script parameter values for parameters used in the script. There are two XSL parameters defined by default called host and port, and their values are set to the configuration host and port bindings.
The XSLTConfigDelegate is used to transform services whose port/interface configuration is specified using a nested XML fragment. The following illustrates an example from the jboss1 server section which maps the Tomcat servlet container listening port to 8180 and maps the AJP listening port to 8109:
<!-- ********************* jbossweb-tomcat41.sar ***************** -->
<service-config name="jboss.web:service=WebServer"
delegateClass="org.jboss.services.binding.XSLTConfigDelegate"
<xslt-config configName="Config"><![CDATA[
xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>
<xsl:variable name="portAJP" select="$port - 71"/>
<xsl:template match = "Connector">
<xsl:when test="(name() = 'port' and . = '8080')">
<xsl:attribute name="port"><xsl:value-of select="$port" /></xsl:attribute>
<xsl:when test="(name() = 'port' and . = '8009')">
<xsl:attribute name="port"><xsl:value-of select="$portAJP" /></xsl:attribute>
<xsl:attribute name="{name()}"><xsl:value-of select="." /></xsl:attribute>
<xsl:apply-templates select="@*|node()"/>
To test the sample configuration, start two JBoss instances using the jboss0 and jboss1 configuration file sets created previously by running the chap10 example1 build. Looking at the console for the service port numbers you should see the overridden mappings. For the jboss1 server for example, here are some of the non-standard ports that show up:
2004-05-06 13:39:27,346 INFO [org.jboss.naming.NamingService] Started jnpPort=1299, rmiPort=1298, backlog=50, bindAddress=/0.0.0.0, Client SocketFactory=null, Server SocketFactory=org.jboss.net.sockets.DefaultSocketFactory@ad093076
2004-05-06 13:39:27,445 INFO [org.jboss.naming.NamingService] Listening on port 1299
2004-05-06 13:39:36,152 DEBUG [org.apache.coyote.http11.Http11Protocol] Attribute port: 8280
2004-05-06 13:39:36,208 INFO [org.apache.coyote.http11.Http11Protocol] Initializing Coyote HTTP/1.1 on port 8280
2004-05-06 13:39:36,422 INFO [org.apache.coyote.http11.Http11Protocol] Starting Coyote HTTP/1.1 on port 8280
2004-05-06 13:39:36,645 DEBUG [org.apache.jk.server.JkCoyoteHandler] setProperty port 8209
2004-05-06 13:39:36,900 DEBUG [org.apache.jk.server.JkMain] Substituting port channelSocket.port 8209
2004-05-06 13:39:36,978 DEBUG [org.apache.jk.server.JkMain] Processing channelSocket::channelSocket port
2004-05-06 13:39:36,978 DEBUG [org.apache.jk.server.JkMain] Setting port on channelSocket org.apache.jk.common.ChannelSocket@1ee2de
2004-05-06 13:39:36,978 DEBUG [org.apache.jk.server.JkMain] setProperty org.apache.jk.common.ChannelSocket@1ee2de port=8209
Java includes a simple timer based capability through the java.util.Timer and java.util.TimerTask utility classes. JMX also includes a mechanism for scheduling JMX notifications at a given time with an optional repeat interval as the javax.management.timer.TimerMBean agent service.
JBoss includes two variations of the JMX timer service in the org.jboss.varia.scheduler.Scheduler and org.jboss.varia.scheduler.ScheduleManager MBeans. Both MBeans rely on the JMX timer service for the basic scheduling. They extend the behavior of the timer service as described in the following sections.
The Scheduler differs from the TimerMBean in that the Scheduler directly invokes a callback on an instance of a user defined class, or an operation of a user specified MBean.
For example, if you start your Schedulable everyday at Noon and you restart your JBoss server then it will start at the next Noon (the same if started before Noon or the next day if start after Noon).
A given Scheduler instance only support a single schedulable instance. If you need to configure multiple scheduled events you would use multiple Scheduler instances, each with a unique ObjectName . 10-2 gives an example of configuring a Scheduler to call a Schedulable implementation as well as a configuration for calling a MBean.
<mbean code="org.jboss.varia.scheduler.Scheduler"
name="jboss.docs.chap10:service=Scheduler">
<attribute name="StartAtStartup">true</attribute>
<attribute name="SchedulableClass">org.jboss.chap10.ex2.ExSchedulable</attribute>
<attribute name="SchedulableArguments">TheName,123456789</attribute>
<attribute name="SchedulableArgumentTypes">java.lang.String,long</attribute>
<attribute name="InitialStartDate">NOW</attribute>
<attribute name="SchedulePeriod">60000</attribute>
<attribute name="InitialRepetitions">-1</attribute>
The SchedulableClass org.jboss.chap10.ex2.ExSchedulable example class is given in See The Listing 10-2 ExSchedulable class code..
import org.jboss.varia.scheduler.Schedulable;
import org.apache.log4j.Logger;
/** A simple Schedulable example.
* @author [email protected]
public class ExSchedulable implements Schedulable
private static final Logger log = Logger.getLogger(ExSchedulable.class);
public ExSchedulable(String name, long value)
log.info("ctor, name: " + name + ", value: " + value);
public void perform(Date now, long remainingRepetitions)
log.info("perform, now: " + now +
", remainingRepetitions: " + remainingRepetitions +
", name: " + name + ", value: " + value);
Deploy the timer sar by running:
[nr@toki examples]$ ant -Dchap=chap10 -Dex=2 run-example
[copy] Copying 1 file to /tmp/jboss-3.2.3/server/default/deploy
The server console shows the following which includes the first two timer invocations, seperated by 60 seconds:
19:05:01,760 INFO [MainDeployer] Starting deployment of package: file:/private/tmp/jboss-3.2.3/server/default/deploy/chap10-ex2.sar
19:05:02,047 INFO [ExSchedulable] ctor, name: TheName, value: 123456789
19:05:02,071 INFO [Scheduler] Started jboss.docs.chap10:service=Scheduler
19:05:02,167 INFO [MainDeployer] Deployed package: file:/private/tmp/jboss-3.2.3/server/default/deploy/chap10-ex2.sar
19:05:03,050 INFO [ExSchedulable] perform, now: Tue May 04 19:05:03 CDT 2004, remainingRepetitions: -1, name: TheName, value: 123456789
19:06:03,049 INFO [ExSchedulable] perform, now: Tue May 04 19:06:03 CDT 2004, remainingRepetitions: -1, name: TheName, value: 123456789
19:07:03,050 INFO [ExSchedulable] perform, now: Tue May 04 19:07:03 CDT 2004, remainingRepetitions: -1, name: TheName, value: 123456789
In 3.2 the logging framework has been generalized to allow for any particular framework implementation. The JBoss classes themselves use the org.jboss.logging.Logger as the factory and logging interface. This class is essentially identical to the Log4j org.apache.log4j.Logger class, with the one addition support for a trace level priority. In 3.2, the Logger class delegated to a LoggerPlugin instance rather than an org.apache.log4j.Logger as was the case in 3.0. The class diagram for the Logger and LoggerPlugin are shown in See The JBoss logging framework classes...
By default we continue to use the Log4j framework as the underlying logging implementation, and this is what the org.jboss.logging.Log4jLoggerPlugin provides. To integrate an alternate logging implementation, you would provide an implementation of the LoggerPlugin interface and specify that it should be used by setting the org.jboss.logging.Logger.pluginClass system property to implementation class name. To disable all logging, you can use the org.jboss.logging.NullLoggerPlugin . This implementation simply provides empty versions of the LoggerPlugin methods.
The Log4jService MBean configures the Apache log4j system. JBoss uses the log4j framework as its internal logging API.
The WebService MBean provides dynamic class loading for RMI access to the server EJBs. The configurable attributes for the WebService are as follows: