1 package com.protomatter.util; 2 3 52 53 import java.util.*; 54 import com.protomatter.pool.*; 55 import com.protomatter.syslog.Syslog; 56 57 61 public final class BlockingQueue 62 extends GrowingObjectPool 63 { 64 67 public BlockingQueue() 68 { 69 super(false); 70 try 71 { 72 init(new Hashtable()); 73 } 74 catch (Exception x) 75 { 76 Syslog.log(this, x); 78 } 79 } 80 81 public ObjectPoolObject createObjectPoolObject() 82 { 83 return null; 84 } 85 86 90 public int getQueueLength() 91 { 92 return getObjectPoolSize(); 93 } 94 95 99 public final Object getNextObject() 100 { 101 BlockingQueueOPO o = null; 102 while (true) 103 { 104 try 105 { 106 o = (BlockingQueueOPO)checkout(); 107 } 108 catch (Exception x) 109 { 110 ; } 112 if (o != null) 113 return o.getObject(); 114 Thread.yield(); 115 } 116 } 117 118 122 public final void add(Object object) 123 { 124 try 125 { 126 checkin(new BlockingQueueOPO(object)); 127 } 128 catch (Exception x) 129 { 130 Syslog.log(this, x); 132 } 133 } 134 135 private class BlockingQueueOPO 136 implements ObjectPoolObject 137 { 138 private Object object = null; 139 private boolean valid = true; 140 141 public BlockingQueueOPO(Object o) 142 { 143 this.object = o; 144 this.valid = true; 145 } 146 147 public Object getObject() 148 { 149 return this.object; 150 } 151 152 public void deleteObjectPoolObject() 153 { 154 this.valid = false; 155 } 156 157 public boolean isObjectPoolObjectValid() 158 { 159 return this.valid; 160 } 161 162 public void beforeObjectPoolObjectCheckout() 163 { 164 } 165 166 public void afterObjectPoolObjectCheckin() 167 { 168 } 169 } 170 } 171 | Popular Tags |