-
1. Re: Cache not accessible from different methods ?
brucespringfield Sep 26, 2007 10:05 AM (in response to jacobeukes)I couldn't reproduce your error. But I have POJO Cache deployed as an Mbean service on the JBoss server.
When I run your test, the object is returned.
If you are deploying the cache from a jar file within a web application, I'm not sure what the results would be. -
2. Re: Cache not accessible from different methods ?
jacobeukes Oct 1, 2007 10:07 AM (in response to jacobeukes)Thank you for the reply.
Would it be possible to post the configuration file (in which you specify the MBean configuration) ? I have to use JBossCache for a project at work and have been at it for a while now, without any success - the object is just never returned in the second method in the code above. This is getting critical. I have tried to configure and deploy it as an MBean and also tried running it as a standalone application (as part of a test), but I am just not having any luck.
Thank you for the help - it is much appreciated. -
3. Re: Cache not accessible from different methods ?
manik Oct 5, 2007 4:45 AM (in response to jacobeukes)The reason is that in both methods (populateCache and displayCacheContents) you're creating a new cache instance. And if these instances are not configured to be clustered, they won't see state in each other.
Bruce's case probably worked since when you retrieve the cache from an MBean server rather than create a new one each tme, both cases use the same cache.
So what you want is probably something like this:private PojoCache pojoCache; private void createCache() { pojoCache = PojoCacheFactory.createCache("META-INF/service.xml", true); } private void populateCache() { Person person = new Person("Chris","Harris",32); pojoCache.attach("/cachedobjects/person", person); Person dummyPerson = (Person)pojoCache.find("/cachedobjects/person"); log.info("Name = " + dummyPerson.getName()); } private void displayCacheContents() { Person person = (Person)pojoCache.find("/cachedobjects/person"); log.info("Name = " + person.getName()); } public static void main(String args[]) { MyApp app = new MyApp(); myApp.createCache(); myApp.populateCache(); myApp.displayCacheContents(); }
-
4. Re: Cache not accessible from different methods ?
brucespringfield Oct 5, 2007 7:54 AM (in response to jacobeukes)Out of curiosity, which version of POJO Cache are you using?
"jacobeukes" wrote:
Would it be possible to post the configuration file (in which you specify the MBean configuration) ?
Here is a minimal config you could use to deploy POJO Cache as an MBean. It is for POJO Cache version 1.4.1 which is the default POJO Cache that comes with JBoss 4.2.1<?xml version="1.0" encoding="UTF-8"?> <server> <mbean code="org.jboss.cache.aop.PojoCache" name="jboss.cache:service=PojoCache"> <depends>jboss:service=Naming</depends> <depends>jboss:service=TransactionManager</depends> <attribute name="TransactionManagerLookupClass">org.jboss.cache.JBossTransactionManagerLookup</attribute> <attribute name="NodeLockingScheme">OPTIMISTIC</attribute> <attribute name="CacheMode">LOCAL</attribute> <attribute name="LockAcquisitionTimeout">1000</attribute> <attribute name="BuddyReplicationConfig"> <config> <buddyReplicationEnabled>false</buddyReplicationEnabled> </config> </attribute> </mbean> </server>
"jacobeukes" wrote:
I have tried to configure and deploy it as an MBean and also tried running it as a standalone application (as part of a test), but I am just not having any luck.
The MBean deployment can be quite dependent on getting the right config attributes. If the attibutes or settings aren't quite right, you can get a lot of errors or unexpected behaviour."manik.surtani@jboss.com" wrote:
Bruce's case probably worked since when you retrieve the cache from an MBean server rather than create a new one each tme, both cases use the same cache.
Manik is absolutely correct. With an MBean deployment, every access to the cache is accessing the same MBean.