1. /*
  2. * @(#)RepositoryIdCache_1_3.java 1.3 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. /*
  8. * Licensed Materials - Property of IBM
  9. * RMI-IIOP v1.0
  10. * Copyright IBM Corp. 1998 1999 All Rights Reserved
  11. *
  12. * US Government Users Restricted Rights - Use, duplication or
  13. * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  14. */
  15. package com.sun.corba.se.internal.orbutil;
  16. import java.util.Stack;
  17. import java.util.Hashtable;
  18. import java.util.EmptyStackException;
  19. import java.util.Enumeration;
  20. // Really limited pool - in this case just creating several at a time...
  21. class RepositoryIdPool_1_3 extends Stack {
  22. private static int MAX_CACHE_SIZE = 4;
  23. private RepositoryIdCache_1_3 cache;
  24. public final synchronized RepositoryId_1_3 popId() {
  25. try {
  26. return (RepositoryId_1_3)super.pop();
  27. }
  28. catch(EmptyStackException e) {
  29. increasePool(5);
  30. return (RepositoryId_1_3)super.pop();
  31. }
  32. }
  33. // Pool management
  34. final void increasePool(int size) {
  35. //if (cache.size() <= MAX_CACHE_SIZE)
  36. for (int i = size; i > 0; i--)
  37. push(new RepositoryId_1_3());
  38. /*
  39. // _REVISIT_ This will not work w/out either thread tracing or weak references. I am
  40. // betting that thread tracing almost completely negates benefit of reuse. Until either
  41. // 1.2 only inclusion or proof to the contrary, I'll leave it this way...
  42. else {
  43. int numToReclaim = cache.size() / 2;
  44. Enumeration keys = cache.keys();
  45. Enumeration elements = cache.elements();
  46. for (int i = numToReclaim; i > 0; i--) {
  47. Object key = keys.nextElement();
  48. Object element = elements.nextElement();
  49. push(element);
  50. cache.remove(key);
  51. }
  52. }
  53. */
  54. }
  55. final void setCaches(RepositoryIdCache_1_3 cache) {
  56. this.cache = cache;
  57. }
  58. }
  59. public class RepositoryIdCache_1_3 extends Hashtable {
  60. private RepositoryIdPool_1_3 pool = new RepositoryIdPool_1_3();
  61. public RepositoryIdCache_1_3() {
  62. pool.setCaches(this);
  63. }
  64. public final synchronized RepositoryId_1_3 getId(String key) {
  65. RepositoryId_1_3 repId = (RepositoryId_1_3)super.get(key);
  66. if (repId != null)
  67. return repId;
  68. else {
  69. //repId = pool.popId().init(key);
  70. repId = new RepositoryId_1_3(key);
  71. put(key, repId);
  72. return repId;
  73. }
  74. }
  75. }