1 7 15 16 package com.sun.corba.se.impl.util; 17 18 import java.util.Stack ; 19 import java.util.Hashtable ; 20 import java.util.EmptyStackException ; 21 import java.util.Enumeration ; 22 23 class RepositoryIdPool extends Stack { 25 26 private static int MAX_CACHE_SIZE = 4; 27 private RepositoryIdCache cache; 28 29 public final synchronized RepositoryId popId() { 30 31 try { 32 return (RepositoryId)super.pop(); 33 } 34 catch(EmptyStackException e) { 35 increasePool(5); 36 return (RepositoryId)super.pop(); 37 } 38 39 } 40 41 final void increasePool(int size) { 43 for (int i = size; i > 0; i--) 45 push(new RepositoryId()); 46 63 } 64 65 final void setCaches(RepositoryIdCache cache) { 66 this.cache = cache; 67 } 68 69 } 70 71 public class RepositoryIdCache extends Hashtable { 72 73 private RepositoryIdPool pool = new RepositoryIdPool(); 74 75 public RepositoryIdCache() { 76 pool.setCaches(this); 77 } 78 79 public final synchronized RepositoryId getId(String key) { 80 RepositoryId repId = (RepositoryId)super.get(key); 81 82 if (repId != null) 83 return repId; 84 else { 85 repId = new RepositoryId(key); 87 put(key, repId); 88 return repId; 89 } 90 91 } 92 } 93 94 95 | Popular Tags |