Mercurial > hg > blitz_condensed
comparison src/org/dancres/blitz/oid/AllocatorFactory.java @ 0:3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
author | Dan Creswell <dan.creswell@gmail.com> |
---|---|
date | Sat, 21 Mar 2009 11:00:06 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3dc0c5604566 |
---|---|
1 package org.dancres.blitz.oid; | |
2 | |
3 import java.io.File; | |
4 import java.io.IOException; | |
5 | |
6 import java.util.Map; | |
7 import java.util.HashMap; | |
8 | |
9 import net.jini.config.ConfigurationException; | |
10 | |
11 import org.dancres.blitz.disk.DiskTxn; | |
12 | |
13 import org.dancres.blitz.config.ConfigurationFactory; | |
14 | |
15 import org.dancres.blitz.meta.RegistryFactory; | |
16 import org.dancres.blitz.meta.Registry; | |
17 | |
18 public class AllocatorFactory { | |
19 | |
20 private static int DEFAULT_MAX_ALLOCATORS; | |
21 | |
22 static { | |
23 try { | |
24 DEFAULT_MAX_ALLOCATORS = | |
25 ((Integer) | |
26 ConfigurationFactory.getEntry("maxOidAllocators", | |
27 int.class, | |
28 new Integer(4))).intValue(); | |
29 } catch (ConfigurationException aCE) { | |
30 } | |
31 } | |
32 | |
33 private static Map theAllocators = new HashMap(); | |
34 | |
35 public static Allocator get(String aName, boolean isFifo) | |
36 throws IOException { | |
37 return get(aName, DEFAULT_MAX_ALLOCATORS, isFifo); | |
38 } | |
39 | |
40 public static Allocator get(String aName, int anAllocSpaceSize, | |
41 boolean isFifo) | |
42 throws IOException { | |
43 return getImpl(aName, anAllocSpaceSize, isFifo); | |
44 } | |
45 | |
46 static Allocator getImpl(String aName, int anAllocSpaceSize, | |
47 boolean isFifo) | |
48 throws IOException { | |
49 | |
50 synchronized(theAllocators) { | |
51 Allocator myData = (Allocator) theAllocators.get(aName); | |
52 | |
53 if (myData == null) { | |
54 myData = newAllocator(aName, anAllocSpaceSize, isFifo); | |
55 theAllocators.put(aName, myData); | |
56 } | |
57 | |
58 return myData; | |
59 } | |
60 } | |
61 | |
62 public static void delete(String aName) throws IOException { | |
63 synchronized(theAllocators) { | |
64 AllocatorAdmin myData = | |
65 (AllocatorAdmin) theAllocators.remove(aName); | |
66 | |
67 if (myData != null) | |
68 myData.delete(); | |
69 } | |
70 } | |
71 | |
72 private static Allocator newAllocator(String aName, | |
73 int anAllocSpaceSize, | |
74 boolean isFifo) | |
75 throws IOException { | |
76 | |
77 if (isFifo) | |
78 return new FIFOAllocatorImpl(aName); | |
79 else | |
80 return new AllocatorImpl(aName, anAllocSpaceSize); | |
81 } | |
82 } |