See if these help:
EJB3 tutorial for JBoss AS5:
Caching EJB3 entities tutorial:
CacheManager service for AS5 wiki:
Thanks a lot jaikiran, the "CacheManager service for AS5 wiki" seems very helpful.
Now I created an alias (to try to not change my code) in the configAlias property like this:
<entry> <key>my.cache:service=MyCache</key> <value>mvcc-shared</value> </entry>
I'm pointing for mvcc-shared just to test.
Then I'm trying to look up for it like I was doing in JBoss 4:
MBeanServer mbserver = MBeanServerLocator.locateJBoss();
ObjectName objName = new ObjectName("my.cache:service=MyCache");
myCache = (Cache) mbserver.getAttribute(objName, "Instance");
But with no success. I get an "InstanceNotFoundException".
The way to look up for the cache changed also in JBoss5 ?
Lot's of stuff here. :)
First, at the very bottom of
https://www.jboss.org/community/docs/DOC-12928 there is a file attachment which includes a zipped draft of updated (but still very much draft) AS 5 clustering docs. See section 9.2 for more on the CacheManager.
Second, I'm assuming you're working with the CacheManager because your EJB3 app needs it -- i.e. you're talking about the cache used for a clustered EJB3 SFSB or a JPA/Hibernate second level cache. If not, if this is a custom cache used by your app, you don't need to use the CacheManager if you don't want to. Chapter 9 of the docs zip referenced above has more on this.
Third, your cache will not be created or registered in JMX until someone calls into the CacheManager and requests it via a call to getCache("my.cache:service=MyCache", true). This is one of the purposes of the CacheManager -- avoiding deploying caches that no service actually uses. Normally the getCache() call would be done by a container that's managing a JEE component that needs the cache (i.e. the JBossWeb session Manager for a clustered webapp; the EJB container for a clustered EJB3 SFSB; the Hibernate SessionFactory for JPA/Hibernate with second level caching enabled.)
Fourth, once your cache is created, if you want to access your cache via JMX, you would do this:
MBeanServer mbserver = MBeanServerLocator.locateJBoss(); ObjectName objName = new ObjectName("jboss.cache:service=Cache,config=mvcc-shared"); myCache = (Cache) mbserver.getAttribute(objName, "Cache");
The CacheManager registers the cache in JMX by constructing an ObjectName from the config name a la the above pattern. Note that in JBC 3 the name of the mbean attribute that gives you a ref to the cache itself is now "Cache" instead of "Instance".
Fifth, you can also get a ref to the cache via the CacheManager. See the docs zip for details.