Mercurial > hg > blitz_stable
view src/org/dancres/blitz/BootContext.java @ 35:6f68e94c1fb8 default tip
Add CondensedStats monitoring utility, equivalent to vmstat
author | Dominic Cleal <dominic-cleal@cdo2.com> |
---|---|
date | Thu, 05 Aug 2010 11:07:25 +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"); } }