4 Replies Latest reply on Nov 28, 2004 8:04 PM by ben.wang

    Lookup of JBossCache via JNDI

    belaban

      FYI,

      I have re-enabled this and checked my changes into CVS head and 3.2. You can simply use JndiName, e.g.
      MyTreeCache.

      So now we have 2 ways of looking up an instance of TreeCache:
      1. JNDI
      2. JMX

      Bela

        • 1. Re: Lookup of JBossCache via JNDI
          celticprince

          Can you provide a quick sample on how to connect to the JBossCache from a client running outside the container?

          • 2. Re: Lookup of JBossCache via JNDI
            belaban

            Here's an excerpt from cache/docs/TreeCache.xml, for the upcoming 1.2 release (check it out yourself if the text below is unreadable):

            <section>
             <title>Running and using TreeCache inside JBoss</title>
            
             <para>If TreeCache is run inside JBoss then TreeCache is deployed as an
             MBean. The steps below illustrate how to do this. We do not deploy as a
             Service Archive (SAR), but as a JAR (jboss-cache.jar in the lib dir) and
             an XML file defining the MBean. But of course, TreeCache could also be
             deployed as a SAR, or even as part of a WAR, EJB or EAR.</para>
            
             <para>First, the jboss-cache.jar file has to be copied to the lib
             directory and JBoss has to be restarted. Then a regular TreeCache
             configuration file in XML format has to be copied to the /deploy
             directory. The XML file format is the same as discussed in
             Configuration.</para>
            
             <para>In order to be used from a client, e.g. a servlet in the Tomcat web
             container inside the same JBoss container, there are 2 ways: either JNDI
             or JMX. If JNDI is to be used, then the XML file for the cache has to
             define the name of the TreeCache MBean, e.g.</para>
            
             <programlisting><?xml version="1.0" encoding="UTF-8" ?>
            <server>
             <classpath codebase="./lib" archives="jboss-cache.jar, jgroups.jar" />
            
             <!-- ==================================================================== -->
             <!-- Defines TreeCache configuration -->
             <!-- ==================================================================== -->
             <mbean code="org.jboss.cache.TreeCache" name="<emphasis>jboss.cache:service=TreeCache</emphasis>">
             ...
             <attribute name="JndiName"><emphasis>MyTreeCache</emphasis></attribute>
             ...
             </mbean>
            </server> </programlisting>
            
             <para>To lookup and use the TreeCache MBean via JNDI, a simple JNDI lookup
             for MyTreeCache has to be done.</para>
            
             <para>To use the TreeCache MBean through JMX, the following code can be
             used:</para>
            
             <programlisting>MBeanServer server=MBeanServerLocator.locate();
            TreeCacheMBean cache;
            cache=(TreeCacheMBean)MBeanProxyExt.create(TreeCacheMBean.class, "jboss.cache:service=TreeCache", server);
            cache.put("/a/b/c", null);</programlisting>
            
             <para>The MBeanServerLocator class is a helper to find the (only) JBoss
             MBean server inside the current VM. The static create() method creates a
             dynamic proxy to the given interface and uses JMX to dynamically dispatch
             methods invoked against the generated interface. The name used to lookup
             the MBean is the same as defined in the configuration file.</para>
            


            Bela


            • 3. Re: Lookup of JBossCache via JNDI
              peja

              So if I understood you correctly, this change is not going to be released as the part of version 1.1.1? It will be officaly released with 1.2?

              Cheers,

              Peja

              • 4. Re: Lookup of JBossCache via JNDI

                Yes.