|
From: <rm...@hy...> - 2007-03-08 21:41:27
|
Author: rmorgan Date: 2007-03-08 13:41:23 -0800 (Thu, 08 Mar 2007) New Revision: 3669 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=3669 Modified: trunk/src/org/hyperic/hq/measurement/server/session/SRNCache.java trunk/src/org/hyperic/hq/measurement/server/session/SRNManagerEJBImpl.java Log: Move SRN loading to SRNCache rather than reportAgentSRNs Modified: trunk/src/org/hyperic/hq/measurement/server/session/SRNCache.java =================================================================== --- trunk/src/org/hyperic/hq/measurement/server/session/SRNCache.java 2007-03-08 19:54:08 UTC (rev 3668) +++ trunk/src/org/hyperic/hq/measurement/server/session/SRNCache.java 2007-03-08 21:41:23 UTC (rev 3669) @@ -29,6 +29,7 @@ import net.sf.ehcache.CacheManager; import net.sf.ehcache.Element; import org.hyperic.hq.appdef.shared.AppdefEntityID; +import org.hyperic.dao.DAOFactory; import java.util.List; @@ -68,12 +69,24 @@ return get(id); } + /** + * Get the SRN entry from the cache falling back to loading from the + * database if the SRN is not found. Since the SRNCache is pre-populated + * the fallback to the database should only occur in clustered setups. + */ public ScheduleRevNum get(SrnId id) { Element el = _cache.get(id); if (el != null) { return (ScheduleRevNum)el.getObjectValue(); } - return null; + + ScheduleRevNumDAO dao = + DAOFactory.getDAOFactory().getScheduleRevNumDAO(); + ScheduleRevNum srn = dao.findById(id); + if (srn != null) { + this.put(srn); + } + return srn; } public boolean remove(SrnId id) { Modified: trunk/src/org/hyperic/hq/measurement/server/session/SRNManagerEJBImpl.java =================================================================== --- trunk/src/org/hyperic/hq/measurement/server/session/SRNManagerEJBImpl.java 2007-03-08 19:54:08 UTC (rev 3668) +++ trunk/src/org/hyperic/hq/measurement/server/session/SRNManagerEJBImpl.java 2007-03-08 21:41:23 UTC (rev 3669) @@ -195,23 +195,13 @@ HashSet nonEntities = new HashSet(); for (int i = 0; i < srns.length; i++) { - AppdefEntityID id = srns[i].getEntity(); - ScheduleRevNum srn = cache.get(id); + ScheduleRevNum srn = cache.get(srns[i].getEntity()); if (srn == null) { - // Attempt load from database, we pre-load the SRNCache, but - // in clustered environments we'll need to reload from the - // database. - SrnId srnId = new SrnId(id.getType(), id.getID()); - srn = getScheduleRevNumDAO().findById(srnId); - if (srn == null) { - _log.error("Agent's reporting for non-existing entity: " - + srns[i].getEntity()); - nonEntities.add(srns[i].getEntity()); - continue; - } else { - cache.put(srn); - } + _log.error("Agent's reporting for non-existing entity: " + + srns[i].getEntity()); + nonEntities.add(srns[i].getEntity()); + continue; } synchronized (srn) { |