• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Caching Design

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Guys,
I am currently involved in developing a caching component, that will have the following features,
1. During startup load all the config data(from XML files) into memory.
2. There are a few objects which are used by many components, hence I need to cache them... The caching component should hold these components.
3. The cached data should be easily accesible, for example if I want to get address of a resource, I should be able get it as simple as
"Cache.get(myresource)"
4. When the system is up and running, there is a possibility that a part of the config data(xml files) are modified. These should be reflected in the cache, without involving any restart of the system.
5. It should be independent of any container or appserver
I need inputs on how to develop the above component.
Thanks,
Mohamed Zafer
 
Ranch Hand
Posts: 977
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
My 2c ok.
you can use a kind of javabeans(1 for each xml file) that are populated by the data in the xml file during startup, than you store the java beans in a HashTable using for example the names of the xml files, when you need to get some data you can consult the object on the HashTable in memory avoiding parsing the xml again, this solves topics 1,2 and 3 from your post as HashTables are very easy to consult and maintain.
Now the solution to item 4 is to build a thread that checks the xml files with some interval to see if they are changed and in that case this thread should in some way notify the component who holds the hashtable to remove the data relative to the xml and parse it again puting it back on the hashtable.
About the item 5, well I think this is more a fact about you having the correct parsers registered.
hope this helps.
 
mohamed zafer
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Marcos,
To get started, your solution is simple and easy. I want to include more features like..
1. The component should be like a service, so that I can plug to any server and use the service..
2. Depending upon the purpose and usage the cached data can be grouped, they may follow a hierarchy. I want this hierarchy/grouping to be preserved. Also the user should be able to access the data with ease irrespective of the grouping etc..
3. The caching should be generic and configurable as far as possible.. like maintaining a pool of objects or a singleton etc..
4. The caching service should be available across cluster's.. As it may hold handle's to critical resources. failover condition should also be taken into consideration.
5. I should be able to add security to the cache.like I don't want everyone to get a handle to some critical objects form the cache..
Please add your ideas on the above issues..
Mohamed Zafer
 
Marcos Maia
Ranch Hand
Posts: 977
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, ok my opinion:
1 - This one I would have to do a research to answer but I think I would start taking a better look at xml services and JMX, you may find the solution there.
2 and 3 - this remembers me of using a builder pattern with an Abstract Factory to return a director from some group of the builder, this should solve the problem, take a look on design patterns catalog for that.
4 - This one must be a bit harder to implement but is the one I most like(I love distributed computing)
well, to be available across clusters I believe the better solution is implement some kind of peer to peer comunication using sockets or rmi(maybe implementing agents) to replicate the service in the cluster, now to implement failover you can use multicast comunication that broadcast the messages to check the available servers and this can be done using a thread that sends a "heartbeat" with some interval and some component of your application should listen to that, than you can implement a time out to determine that some server is not active anymore, you should also consider monitoring the ip sockets I�ve mentioned.
5. Well this is a subject that I also have to research better but I think you should take a look at JAAS to acomplish that.
hope this helps a bit.
regards.
 
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a new product that does some pretty sophisticated caching in a J2EE environment, see Coherence
 
mohamed zafer
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Marcos,
If u r still following the thread, I need your suggestion. Currently I am working on caching of the config files(xml). Consider that my config file is of the following structure
<config>
<logging>
<channel>
<database>
<name>LogDB</name>
<table>logtable<table>
</database>
<flatfile>
<path>c:\log.txt<path>
</flatfile>
</channel>
</logging>
</config>
I want to load this config into the cache. Once done I should be able to acces the leaf nodes/values with ease, It should NOT be something like this
ConfigCache cc = CacheFactory.getConfigCache();
String logPath = cc.get("logging").get("channel").get("flatfile").get("path");
I WANT it to be something like this
ConfigCache cc = CacheFactory.getConfigCache();
String logPath = cc.get("loggingPath");
Though I use minimal method's to access the "path", internally in the cache, the hierarchy of the xml structure should be maintained.
How can this be done, in other words I want to map the XML structure with a suitable Key-Pair values (or some other structure). One option is to concatenate all the node names and use it as a key to retrieve the value, i.e,
String logPath = cc.get("loggingChannelflatfilePath");
But I feel that there can be better alternative to this.
Mohamed Zafer
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic