1 Reply Latest reply on Dec 22, 2008 1:41 PM by Brian Stansberry

    Need to move Jboss cache config to Spring - pls help

    u c Newbie

      I am using JBC 3.0. My config looks as below. I need to move the config to Spring because I have to use the connection pooling object from some other Spring config or if I cant use the connection pooling object I will have to get the Database connection stuff(server:port user password) from some other Spring config and be able to create the cache object. Does anybody have any example to show how to do that

      <?xml version="1.0" encoding="UTF-8"?>
      <jbosscache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       <locking isolationLevel="REPEATABLE_READ" lockParentForChildInsertRemove="true" lockAcquisitionTimeout="15000" nodeLockingScheme="mvcc"/>
       <eviction wakeUpInterval="60000">
       <!-- Cache wide default -->
       <default algorithmClass="org.jboss.cache.eviction.LRUAlgorithm" eventQueueSize="200000">
       <attribute name="maxNodes">5000</attribute>
       <attribute name="timeToLive">1000000</attribute>
       <region name="/root/cache" algorithmClass="org.jboss.cache.eviction.LRUAlgorithm" eventQueueSize="200000">
       <attribute name="maxNodes">5</attribute>
       <attribute name="timeToLive">1000</attribute>
       <loaders passivation="false" shared="true">
       <!-- if passivation is true, only the first cache loader is used; the rest are ignored -->
       <loader class="org.jboss.cache.loader.JDBCCacheLoader" async="true" fetchPersistentState="true"
       ignoreModifications="false" purgeOnStartup="false">

        • 1. Re: Need to move Jboss cache config to Spring - pls help
          Brian Stansberry Master

          Below is not what you asked for, but it does much the same thing and with it and your knowledge of Spring you should be able to get where you want.

          JBC parses its config file into a instance of org.jboss.cache.config.Configuration. Configuration is a Java Bean that uses property injection, so Spring should have no trouble creating one. See http://www.jboss.org/file-access/default/members/jbosscache/freezone/docs/3.0.1.GA/userguide_en/html/configuration.html particularly section 3.3 for more.

          http://www.jboss.org/file-access/default/members/jbosscache/freezone/docs/3.0.1.GA/userguide_en/html/deployment.html#deployment.microcontainer shows an example of using JBoss Microcontainer to create a Configuration object and then using that object to create a cache. The example uses JBoss MC and its XML schema, but what it's doing is all basic IOC stuff that Spring does too; you just need to modify the example to use the Spring schema.

          Here's another example of building a Configuration using the JBoss MC schema. It includes all the complex stuff: buddy replication, cache loading and eviction. Perhaps a better example than what's in the JBC User Guide, since I know it works -- JBoss AS 5 uses it. Again, just conver to the Spring schema.

           <bean name="StandardSFSBCacheConfig" class="org.jboss.cache.config.Configuration">
           <!-- No transaction manager lookup -->
           <!-- Name of cluster. Needs to be the same for all members -->
           <property name="clusterName">${jboss.partition.name:DefaultPartition}-SFSBCache</property>
           <!-- Use a UDP (multicast) based stack. Need JGroups flow control (FC)
           because we are using asynchronous replication. -->
           <property name="multiplexerStack">${jboss.default.jgroups.stack:udp}</property>
           <property name="fetchInMemoryState">true</property>
           <property name="nodeLockingScheme">PESSIMISTIC</property>
           <property name="isolationLevel">REPEATABLE_READ</property>
           <property name="cacheMode">REPL_ASYNC</property>
           <!-- Number of milliseconds to wait until all responses for a
           synchronous call have been received. Make this longer
           than lockAcquisitionTimeout.-->
           <property name="syncReplTimeout">17500</property>
           <!-- Max number of milliseconds to wait for a lock acquisition -->
           <property name="lockAcquisitionTimeout">15000</property>
           <!-- The max amount of time (in milliseconds) we wait until the
           state (ie. the contents of the cache) are retrieved from
           existing members at startup. -->
           <property name="stateRetrievalTimeout">60000</property>
           SFSBs use region-based marshalling to provide for partial state
           transfer during deployment/undeployment.
           <property name="useRegionBasedMarshalling">false</property>
           <!-- Must match the value of "useRegionBasedMarshalling" -->
           <property name="inactiveOnStartup">false</property>
           <!-- Disable asynchronous RPC marshalling/sending -->
           <property name="serializationExecutorPoolSize">0</property>
           <!-- We have no asynchronous notification listeners -->
           <property name="listenerAsyncPoolSize">0</property>
           <property name="exposeManagementStatistics">true</property>
           <property name="buddyReplicationConfig">
           <bean class="org.jboss.cache.config.BuddyReplicationConfig">
           <!-- Just set to true to turn on buddy replication -->
           <property name="enabled">false</property>
           <!-- A way to specify a preferred replication group. We try
           and pick a buddy who shares the same pool name (falling
           back to other buddies if not available). -->
           <property name="buddyPoolName">default</property>
           <property name="buddyCommunicationTimeout">17500</property>
           <!-- Do not change these -->
           <property name="autoDataGravitation">false</property>
           <property name="dataGravitationRemoveOnFind">true</property>
           <property name="dataGravitationSearchBackupTrees">true</property>
           <property name="buddyLocatorConfig">
           <bean class="org.jboss.cache.buddyreplication.NextMemberBuddyLocatorConfig">
           <!-- The number of backup nodes we maintain -->
           <property name="numBuddies">1</property>
           <!-- Means that each node will *try* to select a buddy on
           a different physical host. If not able to do so
           though, it will fall back to colocated nodes. -->
           <property name="ignoreColocatedBuddies">true</property>
           <property name="cacheLoaderConfig">
           <bean class="org.jboss.cache.config.CacheLoaderConfig">
           <!-- Do not change these -->
           <property name="passivation">true</property>
           <property name="shared">false</property>
           <property name="individualCacheLoaderConfigs">
           <bean class="org.jboss.cache.loader.FileCacheLoaderConfig">
           <!-- Where passivated sessions are stored -->
           <property name="location">${jboss.server.data.dir}${/}sfsb</property>
           <!-- Do not change these -->
           <property name="async">false</property>
           <property name="fetchPersistentState">true</property>
           <property name="purgeOnStartup">true</property>
           <property name="ignoreModifications">false</property>
           <property name="checkCharacterPortability">false</property>
           <!-- EJBs use JBoss Cache eviction -->
           <property name="evictionConfig">
           <bean class="org.jboss.cache.config.EvictionConfig">
           <property name="wakeupInterval">5000</property>
           <!-- Overall default -->
           <property name="defaultEvictionRegionConfig">
           <bean class="org.jboss.cache.config.EvictionRegionConfig">
           <property name="regionName">/</property>
           <property name="evictionAlgorithmConfig">
           <bean class="org.jboss.cache.eviction.NullEvictionAlgorithmConfig"/>
           <!-- EJB3 integration code will programatically create
           other regions as beans are deployed -->