5.2. Via JBoss Microcontainer (EAP 5.x)
Beginning with version 5, EAP supports deployment of POJO services via deployment of a file whose name ends with
-jboss-beans.xml
. A POJO service is one whose implementation is via a "Plain Old Java Object", meaning a simple java bean that is not required to implement any special interfaces or extend any particular superclass. A Cache
is a POJO service, and all the components in a Configuration
are also POJOs, so deploying a cache in this way is a natural step.
Deployment of the cache is done using the JBoss Microcontainer that forms the core of EAP. JBoss Microcontainer is a sophisticated IOC framework similar to Spring. A
-jboss-beans.xml
file is basically a descriptor that tells the IOC framework how to assemble the various beans that make up a POJO service.
For each configurable option exposed by the
Configuration
components, a getter/setter must be defined in the configuration class. This is required so that JBoss Microcontainer can, in typical IOC way, call these methods when the corresponding properties have been configured.
You need to ensure that the
jbosscache-core.jar
and jgroups.jar
libraries are in your server's lib
directory. This is usually the case when you use EAP in its all
configuration. Note that you will have to bring in any optional jars you require, such as jdbm.jar
based on your cache configuration.
The following is an example
-beans.xml
file. If you look in the server/all/deploy
directory of a EAP 5 installation, you can find several more examples.
<?xml version="1.0" encoding="UTF-8"?> <deployment xmlns="urn:jboss:bean-deployer:2.0"> <!-- First we create a Configuration object for the cache --> <bean name="ExampleCacheConfig" class="org.jboss.cache.config.Configuration"> <!-- Externally injected services --> <property name="runtimeConfig"> <bean class="org.jboss.cache.config.RuntimeConfig"> <property name="transactionManager"> <inject bean="jboss:service=TransactionManager" property="TransactionManager"/> </property> <property name="muxChannelFactory"><inject bean="JChannelFactory"/></property> </bean> </property> <property name="multiplexerStack">udp</property> <property name="clusterName">Example-EntityCache</property> <property name="isolationLevel">REPEATABLE_READ</property> <property name="cacheMode">REPL_SYNC</property> <property name="stateRetrievalTimeout">15000</property> <property name="syncReplTimeout">20000</property> <property name="lockAcquisitionTimeout">15000</property> <property name="exposeManagementStatistics">true</property> </bean> <!-- Factory to build the Cache. --> <bean name="DefaultCacheFactory" class="org.jboss.cache.DefaultCacheFactory"> <constructor factoryClass="org.jboss.cache.DefaultCacheFactory" factoryMethod="getInstance" /> </bean> <!-- The cache itself --> <bean name="ExampleCache" class="org.jboss.cache.Cache"> <constructor factoryMethod="createCache"> <factory bean="DefaultCacheFactory"/> <parameter class="org.jboss.cache.config.Configuration"><inject bean="ExampleCacheConfig"/></parameter> <parameter class="boolean">false</parameter> </constructor> </bean> </deployment>
See the JBoss Microcontainer documentation for details on the above syntax. Basically, each
bean
element represents an object and is used to create a Configuration
and its Section 3.3, “Composition of a Configuration
Object ” The DefaultCacheFactory
bean constructs the cache, conceptually doing the same thing as is shown in the Section 2.2, “Instantiating and Starting the Cache” chapter.
An interesting thing to note in the above example is the use of the
RuntimeConfig
object. External resources like a TransactionManager
and a JGroups ChannelFactory
that are visible to the microcontainer are dependency injected into the RuntimeConfig
. The assumption here is that in some other deployment descriptor in the AS, the referenced beans have already been described.