7.4.7. RmiDelegatingCacheLoader

7.4.7. RmiDelegatingCacheLoader

Similar to the TcpDelegatingCacheLoader, the RmiDelegatingCacheLoader uses RMI as a method of communicating with a remote cache.

An RmiDelegatingCacheLoader talks to a remote RmiCacheServer, which is a standalone process. The RmiCacheServer has a reference to another JBossCache, which it can create itself, or which is given to it (e.g. by JBoss, using dependency injection).

The RmiDelegatingCacheLoader is configured with the host, port of the remote RMI server and the bind name of the RmiCacheServer, and uses this to communicate.

An example set of an RmiCacheServer running inside of JBoss is shown below:

<server>

   <classpath codebase="./lib" archives="jboss-cache.jar"/>

   <mbean code="org.jboss.cache.loader.rmi.RmiCacheServer" 
      name="jboss.cache:service=RmiCacheServer">
       <depends optional-attribute-name="Cache"
       proxy-type="attribute">jboss.cache:service=TreeCache</depends>
       <!-- the address and port of the RMI server. -->
       <attribute name="BindAddress">${jboss.bind.address:localhost}</attribute>
       <attribute name="Port">1098</attribute>
       <attribute name="BindName">MyRmiCacheServer</attribute>
       <attribute name="MBeanServerName"></attribute>
       <!--<attribute name="CacheName">jboss.cache:service=TreeCache</attribute>-->
   </mbean>

</server>         

The BindAddress and Port should point to an already-running RMI server and the BindName is the name the object is bound to in the RMI server. An existing JBossCache MBean is injected into it (assigned to 'Cache'). This means that all requests from the TcpDelegatingCacheLoader will be received by this instance and forwarded to the JBossCache MBean.

Note that there is also a 'Config' attribute which points to a config XML file for JBossCache. If it is set, then the RmiCacheServer will create its own instance of JBossCache and configure it according to the Config attribute.

The client side looks as follow:

<attribute name="CacheLoaderConfiguration">
   <config>
       <cacheloader>
           <class>org.jboss.cache.loader.RmiDelegatingCacheLoader</class>
               <properties>
                   host=localhost
                   port=1098
   		   name=MyRmiCacheServer
               </properties>
       </cacheloader>
   </config>
</attribute>

This means this instance of JBossCache will delegate all load and store requests to the remote RmiCacheServer running as MyRmiCacheServer on an RMI server running on localhost:1098.

Very similar use case scenarios that apply to TcpDelegatingCacheLoaders above apply to RmiDelegatingCacheLoaders as well.