[jboss-cvs] JBossAS SVN: r83676 - projects/docs/community/5/Clustering_Guide/en-US.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jan 30 08:17:23 EST 2009


Author: bstansberry at jboss.com
Date: 2009-01-30 08:17:23 -0500 (Fri, 30 Jan 2009)
New Revision: 83676

Modified:
   projects/docs/community/5/Clustering_Guide/en-US/Clustering_Guide_JBoss_Cache.xml
Log:
[JBAS-6350] More stuff

Modified: projects/docs/community/5/Clustering_Guide/en-US/Clustering_Guide_JBoss_Cache.xml
===================================================================
--- projects/docs/community/5/Clustering_Guide/en-US/Clustering_Guide_JBoss_Cache.xml	2009-01-30 13:16:50 UTC (rev 83675)
+++ projects/docs/community/5/Clustering_Guide/en-US/Clustering_Guide_JBoss_Cache.xml	2009-01-30 13:17:23 UTC (rev 83676)
@@ -813,7 +813,7 @@
        <para><xref linkend="jbosscache-configuration-cachemanager"/> shows
        the configuration of the CacheManager's "CacheConfigurationRegistry" bean.
        To add a new configuration, you would add an additional element inside 
-       that bean's <literal>newConfigurations</literal> &lt;map&gt;:.</para>
+       that bean's <literal>newConfigurations</literal> &lt;map&gt;:</para>
        
        <programlisting><![CDATA[
 <bean name="CacheConfigurationRegistry" 
@@ -834,11 +834,130 @@
        
        <para>See <xref linkend="jbosscache-configuration-cachemanager"/>
        for an example configuration.</para>
-       
+              
        <!-- <section id="jbosscache-custom-deployment-cachemgr-cacheconfigs">
 	       <title>Using <literal>jboss-cache-configs.xml</literal></title>
 	       <para></para>
        </section>-->
+       
+       <section>
+          <title>Accessing the CacheManager</title>
+          <para>Once you've added your cache configuration to the CacheManager,
+          the next step is to provide a reference to the CacheManager to your
+          application.  There are three ways to do this:</para>
+          
+          <itemizedlist>
+             <listitem><para><emphasis role="bold">Dependency Injection</emphasis></para>
+             <para>If your application uses the JBoss Microcontainer for configuration,
+             the simplest mechanism is to have it inject the CacheManager into
+             your service.</para>
+             
+             <programlisting><![CDATA[
+<bean name="MyService" class="com.example.MyService">
+   <property name="cacheManager"><inject bean="CacheManager"/></property>
+</bean>]]></programlisting>
+             </listitem>
+             <listitem><para><emphasis role="bold">JNDI Lookup</emphasis></para>
+             <para>Alternatively, you can find look up the CacheManger is
+             JNDI. It is bound under <literal>java:CacheManager</literal>.</para>
+             
+             <programlisting><![CDATA[
+import org.jboss.ha.cachemanager.CacheManager;
+
+public class MyService {
+   private CacheManager cacheManager;
+   
+   public void start() throws Exception {
+       Context ctx = new InitialContext();
+       cacheManager = (CacheManager) ctx.lookup("java:CacheManager");
+   }
+}]]></programlisting>
+             </listitem>
+             <listitem><para><emphasis role="bold">CacheManagerLocator</emphasis></para>
+             <para>JBoss AS also provides a service locator object that can 
+             be used to access the CacheManager.</para>
+             
+             <programlisting><![CDATA[
+import org.jboss.ha.cachemanager.CacheManager;
+import org.jboss.ha.framework.server.CacheManagerLocator;
+
+public class MyService {
+   private CacheManager cacheManager;
+   
+   public void start() throws Exception {
+       CacheManagerLocator locator = CacheManagerLocator.getCacheManagerLocator();
+       // Locator accepts as param a set of JNDI properties to help in lookup;
+       // this isn't necessary inside the AS
+       cacheManager = locator.getCacheManager(null);
+   }
+}]]></programlisting>
+             </listitem>
+          </itemizedlist>
+          
+          <para>Once a reference to the CacheManager is obtained; usage is simple.
+          Access a cache by passing in the name of the desired configuration.
+          The CacheManager will not start the cache; this is the responsibility
+          of the application. The cache may, however, have been started by
+          another application running in the cache server; the cache may be
+          shared.  When the application is done using the cache, it should not 
+          stop.  Just inform the CacheManager that the cache is no longer being 
+          used; the manager will stop the cache when all callers that have asked
+          for the cache have released it.</para>
+             
+             <programlisting><![CDATA[
+import org.jboss.cache.Cache;
+import org.jboss.ha.cachemanager.CacheManager;
+import org.jboss.ha.framework.server.CacheManagerLocator;
+
+public class MyService {
+   private CacheManager cacheManager;
+   private Cache cache;
+   
+   public void start() throws Exception {
+       Context ctx = new InitialContext();
+       cacheManager = (CacheManager) ctx.lookup("java:CacheManager");
+       
+       // "true" param tells the manager to instantiate the cache if
+       // it doesn't exist yet
+       cache = cacheManager.getCache("my-cache-config", true);
+       
+       cache.start();
+   }
+   
+   public void stop() throws Exception {
+       cacheManager.releaseCache("my-cache-config");
+   }
+}]]></programlisting>
+          
+          <para>The CacheManager can also be used to access instances of
+          POJO Cache.</para>
+             
+             <programlisting><![CDATA[
+import org.jboss.cache.pojo.PojoCache;
+import org.jboss.ha.cachemanager.CacheManager;
+import org.jboss.ha.framework.server.CacheManagerLocator;
+
+public class MyService {
+   private CacheManager cacheManager;
+   private PojoCache pojoCache;
+   
+   public void start() throws Exception {
+       Context ctx = new InitialContext();
+       cacheManager = (CacheManager) ctx.lookup("java:CacheManager");
+       
+       // "true" param tells the manager to instantiate the cache if
+       // it doesn't exist yet
+       pojoCache = cacheManager.getPojoCache("my-cache-config", true);
+       
+       pojoCache.start();
+   }
+   
+   public void stop() throws Exception {
+       cacheManager.releasePojoCache("my-cache-config");
+   }
+}]]></programlisting>
+          
+       </section>
      </section>
      
      <section id="jbosscache-custom-deployment-service.xml">




More information about the jboss-cvs-commits mailing list