| Author |
Not able to initialise a cache in EHCache
|
Abhishek Dwaraki
Ranch Hand
Joined: Feb 13, 2006
Posts: 44
|
|
|
I'm currently using EHCache to cache my data in Java. The problem is after creating a cache and adding it to the cache manager, I'm not able to use the cache since it has not been initialised. The concept is that the initialise() method in the class Cache initialises the MemoryStore and DiskStore for the cache by calling the methods in class MemoryStore and class DiskStore. The problem is that the specifiers for these methods is default and are not available in my package and hence the IDE says the method is not visible. Its a catch-22 situation sinceI need to initialise my cache because I cannot use it without initialising it. Someone please advice on a possible work around to this problem. For info, the documentation is available on http://ehcache.sourceforge.net. Thanks in advance.
|
Regards,
Abhishek Dwaraki
Dept of Electrical and Comp Engg
University of Massachusetts, Amherst
|
 |
Peter Petrov
Greenhorn
Joined: Feb 03, 2006
Posts: 17
|
|
I am not very sure but I think with Java Reflection you can basically call any method no matter private or default or whatever the access modifier is. I know it is ugly idea but maybe it could do the job. Another solution is also possible. If that EHCache product is free and open source you can just patch the binary distribution by changing these access modifiers in the appropriate source file and then just recompile the source. Then put the recompiled version of your patched class before the EHCache distribution (probably it's some JAR I guess) in your classpath and that's it. I do not think this is any violation of their licence as you do not redestribute the original EHCache product. Hope one of these two ideas could help. Regards. [ March 09, 2006: Message edited by: Peter Petrov ]
|
 |
Reid M. Pinchback
Ranch Hand
Joined: Jan 25, 2002
Posts: 775
|
|
|
I'm pretty sure reflection all by itself doesn't give you any powers that you don't normally have. Reflection will tell you the structure of things known to the class loader, but that doesn't cause the JVM to execute code or access data you aren't allowed to. If this weren't the case, anybody could write an applet to hack any browser just by using reflection to bypass the security manager.
|
Reid - SCJP2 (April 2002)
|
 |
steve souza
Ranch Hand
Joined: Jun 26, 2002
Posts: 852
|
|
This isn't a performance question. You should post on the forum of EHCache https://sourceforge.net/forum/forum.php?forum_id=322278
|
http://www.jamonapi.com/ - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
|
 |
Peter Petrov
Greenhorn
Joined: Feb 03, 2006
Posts: 17
|
|
Seems Reid M. Pinchback is right about the reflection. Maybe in the previous versions of Java (before 1.4) there was such option to call methods which you normally have no access to via Java Reflection, I don't know. I don't remember why I have left with that impression. Maybe I've had a slightly different scenario. The second solution though which I offered above should work as I have had the same problem many times before. Just take the source files you want to change, change the access modifiers from default to public, then recompile only those source files and put them somewhere in the classpath before the normal/original library class (jar) files of EHCache. This should do the job. And yes, I agree this is not a performance question Regards. [ March 10, 2006: Message edited by: Peter Petrov ]
|
 |
Stefan Wagner
Ranch Hand
Joined: Jun 02, 2003
Posts: 1923
|
|
You can use reflection to gain access to private members, but it will throw a SecurityAccessViolationException or something similar if done in applets i.e. In general, I would rarely use such a technique to make things work. Either you don't understand how the api is intended to be used, or the developer did a bad job, in which case it might not be a good idea to use it at all. Asking at sourceforge would be my answer too in this case.
|
http://home.arcor.de/hirnstrom/bewerbung
|
 |
 |
|
|
subject: Not able to initialise a cache in EHCache
|
|
|