Mercurial > hg > blitz_stable
view src/org/dancres/blitz/oid/AllocatorFactory.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.oid; import java.io.File; import java.io.IOException; import java.util.Map; import java.util.HashMap; import net.jini.config.ConfigurationException; import org.dancres.blitz.disk.DiskTxn; import org.dancres.blitz.config.ConfigurationFactory; import org.dancres.blitz.meta.RegistryFactory; import org.dancres.blitz.meta.Registry; public class AllocatorFactory { private static int DEFAULT_MAX_ALLOCATORS; static { try { DEFAULT_MAX_ALLOCATORS = ((Integer) ConfigurationFactory.getEntry("maxOidAllocators", int.class, new Integer(4))).intValue(); } catch (ConfigurationException aCE) { } } private static Map theAllocators = new HashMap(); public static Allocator get(String aName, boolean isFifo) throws IOException { return get(aName, DEFAULT_MAX_ALLOCATORS, isFifo); } public static Allocator get(String aName, int anAllocSpaceSize, boolean isFifo) throws IOException { return getImpl(aName, anAllocSpaceSize, isFifo); } static Allocator getImpl(String aName, int anAllocSpaceSize, boolean isFifo) throws IOException { synchronized(theAllocators) { Allocator myData = (Allocator) theAllocators.get(aName); if (myData == null) { myData = newAllocator(aName, anAllocSpaceSize, isFifo); theAllocators.put(aName, myData); } return myData; } } public static void delete(String aName) throws IOException { synchronized(theAllocators) { AllocatorAdmin myData = (AllocatorAdmin) theAllocators.remove(aName); if (myData != null) myData.delete(); } } private static Allocator newAllocator(String aName, int anAllocSpaceSize, boolean isFifo) throws IOException { if (isFifo) return new FIFOAllocatorImpl(aName); else return new AllocatorImpl(aName, anAllocSpaceSize); } }