-
1. Re: configuration of cache when moving from JBoss 4.2.3 to J
jaikiran Feb 19, 2009 5:48 AM (in response to tugman)See if these help:
EJB3 tutorial for JBoss AS5:
http://www.jboss.org/jbossejb3/docs/
Caching EJB3 entities tutorial:
http://www.jboss.org/file-access/default/members/jbossejb3/freezone/docs/tutorial/1.0.0/html/Caching_EJB3_Entities.html
CacheManager service for AS5 wiki:
http://www.jboss.org/community/docs/DOC-13185 -
2. Re: configuration of cache when moving from JBoss 4.2.3 to J
tugman Feb 19, 2009 6:21 AM (in response to tugman)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 ? -
3. Re: configuration of cache when moving from JBoss 4.2.3 to J
brian.stansberry Feb 19, 2009 6:00 PM (in response to tugman)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.