This content has been marked as final.
Show 4 replies
-
1. Re: Lookup of JBossCache via JNDI
celticprince Nov 17, 2004 12:50 PM (in response to belaban)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 Nov 18, 2004 4:14 AM (in response to 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 Nov 19, 2004 5:39 PM (in response to belaban)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 -