Mercurial > hg > blitz_stable
view src/org/dancres/blitz/BootContext.java @ 23:b7e52953b7a6
Add some cache/memory statistics to help spot potential exhaustion and other tuning issues.
author | Dan Creswell <dan.creswell@gmail.com> |
---|---|
date | Fri, 28 Aug 2009 17:23:33 +0100 |
parents | 3dc0c5604566 |
children |
line wrap: on
line source
package org.dancres.blitz; import java.util.List; import java.util.LinkedList; import java.util.Iterator; /** Various components within Blitz require access to certain specific bits of information concerning Boot state. BootContext is responsible for holding all these bits of information and making them available to the components. */ public class BootContext { private static List theContext = new LinkedList(); public static void add(BootInfo anInfo) { synchronized(theContext) { theContext.add(anInfo); } } public static BootInfo get(Class aClass) { validate(aClass); synchronized(theContext) { Iterator myInfos = theContext.iterator(); while (myInfos.hasNext()) { BootInfo myInfo = (BootInfo) myInfos.next(); if (aClass.isInstance(myInfo)) return myInfo; } } return null; } private static void validate(Class aClass) { Class[] myInterfaces = aClass.getInterfaces(); for (int i = 0 ; i < myInterfaces.length; i++) { if (myInterfaces[i].equals(BootInfo.class)) return; } throw new RuntimeException("Attempt to store object which is not a BootInfo"); } }