More Books
JBoss 4.0 The Official Guide
JBoss® 4.0 The Official Guide
Table of Contents
Copyright
About the Authors
We Want to Hear from You!
Introduction
What This Book Covers
About JBoss
About Open Source
About Professional Open Source
What's New in JBoss 4.0
Chapter 1.  Installing and Building the JBoss Server
Getting the Binary Files
Installing the Binary Package
Basic Installation Testing
Booting from a Network Server
Building the Server from Source Code
Chapter 2.  The JBoss JMX Microkernel
JMX
The JBoss JMX Implementation Architecture
Connecting to the JMX Server
Using JMX as a Microkernel
The JBoss Deployer Architecture
Exposing MBean Events via SNMP
Remote Access to Services, Detached Invokers
Chapter 3.  Naming on JBoss
An Overview of JNDI
The JBossNS Architecture
Chapter 4.  Transactions on JBoss
Transaction and JTA Overview
JBoss Transaction Internals
Chapter 5.  EJBs on JBoss
The EJB Client-Side View
The EJB Server-Side View
The EJB Container
Entity Bean Locking and Deadlock Detection
Chapter 6.  Messaging on JBoss
JMS Examples
JBossMQ Overview
JBossMQ Configuration and MBeans
Specifying the MDB JMS Provider
Chapter 7.  Connectors on JBoss
JCA Overview
An Overview of the JBossCX Architecture
Configuring JDBC Datasources
Configuring Generic JCA Adaptors
Chapter 8.  Security on JBoss
J2EE Declarative Security Overview
An Introduction to JAAS
The JBoss Security Model
The JBossSX Architecture
The Secure Remote Password (SRP) Protocol
Running JBoss with a Java 2 Security Manager
Using SSL with JBoss and JSSE
Configuring JBoss for Use Behind a Firewall
Securing the JBoss Server
Chapter 9.  Web Applications
The Tomcat Service
The Tomcat server.xml File
The Engine Element
The Host Element
Using SSL with the JBoss/Tomcat Bundle
Setting the Context Root of a Web Application
Setting Up Virtual Hosts
Serving Static Content
Using Apache with Tomcat
Using Clustering
Integrating Third-Party Servlet Containers
Chapter 10.  MBean Services Miscellany
System Properties Management
Property Editor Management
Services Binding Management
Scheduling Tasks
The Log4j Service MBean
RMI Dynamic Class Loading
Chapter 11.  The CMP Engine
Example Code
The jbosscmp-jdbc Structure
Entity Beans
CMP Fields
Container-Managed Relationships
Declaring Queries
Optimized Loading
The Loading Process
Transactions
Optimistic Locking
Entity Commands and Primary Key Generation
JBoss Global Defaults
Datasource Customization
Chapter 12.  Web Services
JAX-RPC Service Endpoints
Enterprise JavaBean Endpoints
Web Services ClientsA JAX-RPC Client
Service References
Chapter 13.  Hibernate
The Hibernate MBean
Hibernate Archives
Using Hibernate Objects
Using a HAR File Inside an EAR File
The HAR Deployer
Chapter 14.  Aspect-Oriented Programming (AOP) Support
JBoss AOP: EJB-Style Services for Plain Java Objects
Why AOP?
Basic Concepts of AOP
Building JBoss AOP Applications
The JBoss AOP Deployer
Packaging and Deploying AOP Applications to JBoss
Appendix A.  The GNU Lesser General Public License (LGPL)
GNU General Public License
Appendix B.  Example Installation
Index
SYMBOL
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X

Specifying the MDB JMS Provider

Up to this point we have looked at the standard JMS client/server architecture. The JMS specification defines an advanced set of interfaces that allow for concurrent processing of a destination's messages, and collectively this functionality is referred to as application server facilities (ASF). Two of the interfaces that support concurrent message processing, javax.jms.ServerSessionPool and javax.jms.ServerSession, must be provided by the application server in which the processing will occur. Thus, the set of components that make up the JBossMQ ASF involves both JBossMQ components and JBoss server components. The JBoss server MDB container utilizes the JMS service's ASF to concurrently process messages sent to MDBs.

The responsibilities of the ASF domains are well defined by the JMS specification, so we won't go into a discussion of how the ASF components are implemented. Rather, we'll discuss how ASF components used by the JBoss MDB layer are integrated, using MBeans that allow either the application server interfaces or the JMS provider interfaces to be replaced with alternate implementations.

Let's start with the org.jboss.jms.jndi.JMSProviderLoader MBean. This MBean is responsible for loading an instance of the org.jboss.jms.jndi.JMSProviderAdaptor interface into the JBoss server and binding it into JNDI. The JMSProviderAdaptor interface is an abstraction that defines how to get the root JNDI context for the JMS provider, and an interface for getting and setting the JNDI names for the Context.PROVIDER_URL for the root InitialContext, and the QueueConnectionFactory and TopicConnectionFactory locations in the root context.

This is all that is really necessary to bootstrap use of a JMS provider. By abstracting this information into an interface, you can use alternate JMS ASF provider implementations with the JBoss MDB container. org.jboss.jms.jndi.JBossMQProvider is the default implementation of the JMSProviderAdaptor interface, and it provides the adaptor for the JBossMQ JMS provider. To replace the JBossMQ provider with an alternate JMS ASF implementation, you simply create an implementation of the JMSProviderAdaptor interface and configure the JMSProviderLoader with the classname of the implementation. You'll see an example of this later in this chapter.

In addition to being able to replace the JMS provider used for MDBs, you can also replace the javax.jms.ServerSessionPool interface implementation. This is possible by configuring the classname of the org.jboss.jms.asf.ServerSessionPoolFactory implementation, using the org.jboss.jms.asf.ServerSessionPoolLoader MBean PoolFactoryClass attribute. The default ServerSessionPoolFactory factory implementation is the JBoss org.jboss.jms.asf.StdServerSessionPoolFactory class.

The org.jboss.jms.jndi.JMSProviderLoader MBean

The JMSProviderLoader MBean service creates a JMS provider adaptor and binds it into JNDI. A JMS provider adaptor is a class that implements the org.jboss.jms.jndi.JMSProviderAdaptor interface. It is used by the MDB container to access a JMS service provider in a provider-independent manner. The configurable attributes of the JMSProviderLoader service are as follows:

  • ProviderName A unique name for the JMS provider. This will be used to bind the JMSProviderAdaptor instance into JNDI under java :/<ProviderName> unless it is overridden by the AdapterJNDIName attribute.

  • ProviderAdapterClass The fully qualified classname of the org.jboss.jms.jndi.JMSProviderAdaptor interface to create an instance of. To use an alternate JMS provider, such as SonicMQ, you create an implementation of the JMSProviderAdaptor interface that allows the administration of the InitialContext provider URL, and the locations of the QueueConnectionFactory and TopicConnectionFactory in JNDI.

  • AdapterJNDIName The exact JNDI name under which the JMSProviderAdaptor instance will be bound.

  • ProviderURL The JNDI Context.PROVIDER_URL value to use when creating the JMS provider root InitialContext.

  • QueueFactoryRef The JNDI name under which the provider javax.jms.QueueConnectionFactory will be bound.

  • TopicFactoryRef The JNDI name under which the javax.jms.TopicConnectionFactory will be bound.

Listing 6.13 shows a JMSProviderLoader for accessing a remote JBossMQ server.

Listing 6.13. A JMSProviderLoader for Accessing a Remote JBossMQ Server
<mbean code="org.jboss.jms.jndi.JMSProviderLoader"
       name="jboss.mq:service=JMSProviderLoader,name=RemoteJBossMQProvider">
    <attribute name="ProviderName">RemoteJMSProvider</attribute>
    <attribute name="ProviderUrl">jnp://remotehost:1099</attribute>
    <attribute name="ProviderAdapterClass">
        org.jboss.jms.jndi.JBossMQProvider
    </attribute>
    <attribute name="QueueFactoryRef">XAConnectionFactory</attribute>
    <attribute name="TopicFactoryRef">XAConnectionFactory</attribute>
</mbean>

The RemoteJMSProvider can be referenced on the MDB invoker config, as shown in the jboss.xml fragment in Listing 6.14.

Listing 6.14. A jboss.xml Fragment for Specifying the MDB JMSProviderAdapter
<proxy-factory-config>
    <JMSProviderAdaptorJNDI>RemoteJMSProvider</JMSProviderAdaptorJNDI>
    <ServerSessionPoolFactoryJNDI>StdJMSPool</ServerSessionPoolFactoryJNDI>
    <MaximumSize>15</MaximumSize>
    <MaxMessages>1</MaxMessages>
    <MDBConfig>
        <ReconnectIntervalSec>10</ReconnectIntervalSec>
        <DLQConfig>
            <DestinationQueue>queue/DLQ</DestinationQueue>
            <MaxTimesRedelivered>10</MaxTimesRedelivered>
            <TimeToLive>0</TimeToLive>
        </DLQConfig>
    </MDBConfig>
</proxy-factory-config>

Incidentally, being able to specify multiple invoker-proxy-binding elements allows an MDB to listen to the same queue/topic on multiple servers because you can configure multiple bindings with different JMSProviderAdaptorJNDI settings. Alternatively, you can integrate the JMS provider by using a JCA configuration like the one shown in Listing 6.15.

Listing 6.15. A jms-ds.xml Descriptor for Integrating a JMSProviderAdapter via JCA
<tx-connection-factory>
    <jndi-name>RemoteJmsXA</jndi-name>
    <xa-transaction/>
    <adapter-display-name>JMS Adapter</adapter-display-name>
    <config-property name="JMSProviderAdaptorJNDI"
                     type="java.lang.String">RemoteJMSProvider</config-property>
    <config-property name="SessionDefaultType"
                     type="java.lang.String">javax.jms.Topic</config-property>

    <security-domain-and-application>JmsXARealm</security-domain-and-application>
</tx-connection-factory>

The org.jboss.jms.asf.ServerSessionPoolLoader MBean

The ServerSessionPoolLoader MBean manages a factory for javax.jms.ServerSessionPool objects used by the MDB container. The configurable attributes of the ServerSessionPoolLoader service are as follows:

  • PoolName A unique name for the session pool. This will be used to bind the ServerSessionPoolFactory instance into JNDI under java:/PoolName.

  • PoolFactoryClass The fully qualified classname of the org.jboss.jms.asf.ServerSessionPoolFactory interface to create an instance of.

  • XidFactory The JMX ObjectName of the service to use for generating javax.transaction.xa.Xid values for local transactions when a two-phase commit is not required. The XidFactory MBean must provide an Instance operation that returns a org.jboss.tm.XidFactoryMBean instance.

Integrating Non-JBoss JMS Providers

As mentioned previously in this chapter, you can replace the JBossMQ JMS implementation with a foreign implementation. You can take a variety of approaches to doing the replacement:

  • Change the JMSProviderLoader from the JBossMQProvider class to one that instantiates the correct JNDI context for communicating with the foreign JMS provider's managed objects.

  • Use the ExternalContext MBean to federate the foreign JMS provider's managed objects into the JBoss JNDI tree.

  • Use MBeans to instantiate the foreign JMS objects into the JBoss JNDI tree. An example of this approach can be found for Websphere MQ at http://sourceforge.net/tracker/index.php?func=detail&aid=753022&group_id=22866&atid=376687.