You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ken Pullin <kp...@yahoo.com> on 2004/07/14 15:53:45 UTC

MessageResources Question

I've been looking into extending the MessageResources class and providing my own MessageResourcesFactory.  The end goal is to house the ApplicationResource files in a database table.  The issue I'm noticing is that the MessageResources class maintains a HashMap of key/values called 'formats'.  So any class that extends MessageResources only get's called when the particular value is not in the cache(hashmap) in the MessageResource class.  This is the method that gets called in the MessageResources class:

String formatKey = messageKey(locale, key);
 synchronized (formats) {
     format = (MessageFormat) formats.get(formatKey);
     if (format == null) {
  String formatString = getMessage(locale, key);
  if (formatString == null) {
      if (returnNull)
   return (null);
      else
   return ("???" + formatKey + "???");
  }
  format = new MessageFormat(escape(formatString));
  formats.put(formatKey, format);
     }

 }

Notice how the 1st step is to check to see if the formats hashmap contains the key.  If it doesn't it then calls the getMessage(locale,key) which is provided by my implemenation class.  At that point, it gets back a value and then puts it on the HashMap.

The problem I'm having is when I want to update a value.  How do you tell the MessageResources class to refresh it's cache.  This becomes even more complicated if the application resides in a clustered environment.  You could use OJB or even Entity Bean to retrieve the data from the database in the Custom Implemenation, but you still have the problem with the MessageResources class maintaining a seperate cache.  The EJB or OJB classes would contain the correct values, but the cache at the parent level would not.  I basically need a way when a value gets updated to tell the MessageResources class to either 1) clear it's cache all together or 2) take the value off of the HashMap so the next call to it would go to my custom implementation.

I hope this wasn't 2 confusing....

Thanks


		
---------------------------------
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!

Re: MessageResources Question

Posted by Ken Pullin <kp...@yahoo.com>.
Yeah - I've reviewed that package but it doesn't appear to solve the real issue.  The getMessage() call in the OJBMessageResources class clears the cache of the MessageResources class.  That's fine, but as soon as you return the value back up to MessageResources, it's going to put it on the cache again.  So the next call into the getMessage() of the MessageResources class happens, it's going to 1) look onto it's cache and then 2) get the value off without ever going to the subclass.  
 
The problem here is that the messageResources class is maintaining a cache.  Why not let the implementation actually control the cache?  We end up having 2 caches with any approach...

Bill Siggelkow <bi...@bellsouth.net> wrote:
http://sourceforge.net/project/showfiles.php?group_id=49385&package_id=76369



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


		
---------------------------------
Do you Yahoo!?
Yahoo! Mail is new and improved - Check it out!

Re: MessageResources Question

Posted by Bill Siggelkow <bi...@bellsouth.net>.
http://sourceforge.net/project/showfiles.php?group_id=49385&package_id=76369



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: MessageResources Question

Posted by Nick Heudecker <ni...@systemmobile.com>.
Hi Ken:

A JDBCMessageResources class already exists.  I believe that James 
Mitchell wrote it.  After a quick search, I couldn't find any additional 
links to it, however.

Ken Pullin wrote:
> I've been looking into extending the MessageResources class and providing my own MessageResourcesFactory.  The end goal is to house the ApplicationResource files in a database table.  The issue I'm noticing is that the MessageResources class maintains a HashMap of key/values called 'formats'.  So any class that extends MessageResources only get's called when the particular value is not in the cache(hashmap) in the MessageResource class.  This is the method that gets called in the MessageResources class:
> 
> String formatKey = messageKey(locale, key);
>  synchronized (formats) {
>      format = (MessageFormat) formats.get(formatKey);
>      if (format == null) {
>   String formatString = getMessage(locale, key);
>   if (formatString == null) {
>       if (returnNull)
>    return (null);
>       else
>    return ("???" + formatKey + "???");
>   }
>   format = new MessageFormat(escape(formatString));
>   formats.put(formatKey, format);
>      }
> 
>  }
> 
> Notice how the 1st step is to check to see if the formats hashmap contains the key.  If it doesn't it then calls the getMessage(locale,key) which is provided by my implemenation class.  At that point, it gets back a value and then puts it on the HashMap.
> 
> The problem I'm having is when I want to update a value.  How do you tell the MessageResources class to refresh it's cache.  This becomes even more complicated if the application resides in a clustered environment.  You could use OJB or even Entity Bean to retrieve the data from the database in the Custom Implemenation, but you still have the problem with the MessageResources class maintaining a seperate cache.  The EJB or OJB classes would contain the correct values, but the cache at the parent level would not.  I basically need a way when a value gets updated to tell the MessageResources class to either 1) clear it's cache all together or 2) take the value off of the HashMap so the next call to it would go to my custom implementation.
> 
> I hope this wasn't 2 confusing....
> 
> Thanks
> 
> 
> 		
> ---------------------------------
> Do you Yahoo!?
> New and Improved Yahoo! Mail - Send 10MB messages!


-- 
Nick Heudecker
System Mobile, Inc.
Email: nick@systemmobile.com
Web: http://www.systemmobile.com

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org