Produced by Araxis Merge on 12/5/2017 12:06:43 PM Central Standard Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\ImagingCacheImpl\main\src\java\gov\va\med\imaging\storage\cache\impl | PersistentSet.java | Mon Dec 4 21:35:26 2017 UTC |
| 2 | IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\ImagingCacheImpl\main\src\java\gov\va\med\imaging\storage\cache\impl | PersistentSet.java | Mon Dec 4 22:01:35 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 1492 |
| Changed | 1 | 2 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| Whitespace | |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
| 1 | /** | |
| 2 | * | |
| 3 | */ | |
| 4 | package go v.va.med.i maging.sto rage.cache .impl; | |
| 5 | ||
| 6 | import gov .va.med.im aging.stor age.cache. EvictionJu dge; | |
| 7 | import gov .va.med.im aging.stor age.cache. InstanceBy teChannelF actory; | |
| 8 | import gov .va.med.im aging.stor age.cache. MutableNam edObject; | |
| 9 | import gov .va.med.im aging.stor age.cache. exceptions .CacheExce ption; | |
| 10 | ||
| 11 | import jav a.lang.ref .Reference ; | |
| 12 | import jav a.lang.ref .Reference Queue; | |
| 13 | import jav a.lang.ref .SoftRefer ence; | |
| 14 | import jav a.util.*; | |
| 15 | import jav a.util.con current.Ti meUnit; | |
| 16 | import jav a.util.con current.lo cks.Lock; | |
| 17 | import jav a.util.con current.lo cks.Reentr antReadWri teLock; | |
| 18 | import jav a.util.con current.lo cks.Reentr antReadWri teLock.Rea dLock; | |
| 19 | import jav a.util.con current.lo cks.Reentr antReadWri teLock.Wri teLock; | |
| 20 | ||
| 21 | import org .apache.lo gging.log4 j.LogManag er; | |
| 22 | import org .apache.lo gging.log4 j.Logger; | |
| 23 | ||
| 24 | /** | |
| 25 | * @author
|
|
| 26 | * | |
| 27 | * An abst ract class that repr esents a s et of pers istent ins tances in a cache im plementati on. | |
| 28 | * This cl ass is res ponsible f or synchro nizing the persisten t and the internal ( transient) | |
| 29 | * set ref erences. | |
| 30 | * In prac tical term s, this cl ass and it s subclass es, keep t he file in stances sy nchronized | |
| 31 | * with th e internal reference s. | |
| 32 | * | |
| 33 | * NOTE: m ethods tha t may make changes t o the Set are declar ed as fina l so that the lockin g | |
| 34 | * can be relied on. | |
| 35 | * | |
| 36 | * Known D erivations : | |
| 37 | * @see go v.va.med.i maging.sto rage.cache .impl.file system.Fil eSystemGro upSet | |
| 38 | */ | |
| 39 | public abs tract clas s Persiste ntSet<T ex tends Muta bleNamedOb ject> | |
| 40 | extends Ha shSet<Soft Reference< ? extends T>> | |
| 41 | { | |
| 42 | pr ivate Logg er log = L ogManager. getLogger( this.getCl ass()); | |
| 43 | // protected Set<SoftRe ference<? extends T> > childGro ups = new HashSet<So ftReferenc e<? extend s T>>(); / / the tran sient copy of the se t members | |
| 44 | pr ivate Reen trantReadW riteLock a ccessLock = new Reen trantReadW riteLock() ; // a rea d write lo ck proteci ng against simultane ous access where cha nges may o ccur | |
| 45 | ||
| 46 | pr ivate Inst anceByteCh annelFacto ry byteCha nnelFactor y = null; // passed to the Gro up instanc es created within he re so they can creat e Instance s, which n eed the fa ctory | |
| 47 | pr ivate int secondsRea dWaitsForW riteComple tion; | |
| 48 | pr ivate bool ean setMod ificationT imeOnRead; | |
| 49 | ||
| 50 | // set to tr ue to queu e soft ref erences wh en they ar e GC'd and print a l og message | |
| 51 | pr ivate stat ic boolean monitorSo ftReferenc es = false ; | |
| 52 | pr ivate stat ic Referen ceQueue de referenced Members; | |
| 53 | pr ivate stat ic Referen ceQueueNot ification queueNotif ication; | |
| 54 | ||
| 55 | st atic | |
| 56 | { | |
| 57 | if(m onitorSoft References ) | |
| 58 | { | |
| 59 | derefe rencedMemb ers = new ReferenceQ ueue(); | |
| 60 | queueN otificatio n = new Re ferenceQue ueNotifica tion(deref erencedMem bers); | |
| 61 | ||
| 62 | (new T hread(queu eNotificat ion)).star t(); | |
| 63 | } | |
| 64 | } | |
| 65 | ||
| 66 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== = | |
| 67 | // Construct ors | |
| 68 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== = | |
| 69 | pr otected Pe rsistentSe t( | |
| 70 | Inst anceByteCh annelFacto ry byteCha nnelFactor y, | |
| 71 | int secondsRea dWaitsForW riteComple tion, | |
| 72 | bool ean setMod ificationT imeOnRead) | |
| 73 | { | |
| 74 | this .byteChann elFactory = byteChan nelFactory ; | |
| 75 | this .secondsRe adWaitsFor WriteCompl etion = se condsReadW aitsForWri teCompleti on; | |
| 76 | this .setModifi cationTime OnRead = s etModifica tionTimeOn Read; | |
| 77 | } | |
| 78 | ||
| 79 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== = | |
| 80 | // Property Accessors | |
| 81 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== = | |
| 82 | pu blic Insta nceByteCha nnelFactor y getByteC hannelFact ory() | |
| 83 | { | |
| 84 | retu rn this.by teChannelF actory; | |
| 85 | } | |
| 86 | ||
| 87 | pu blic int g etSecondsR eadWaitsFo rWriteComp letion() | |
| 88 | { | |
| 89 | retu rn this.se condsReadW aitsForWri teCompleti on; | |
| 90 | } | |
| 91 | ||
| 92 | pu blic boole an isSetMo dification TimeOnRead () | |
| 93 | { | |
| 94 | retu rn this.se tModificat ionTimeOnR ead; | |
| 95 | } | |
| 96 | ||
| 97 | pr ivate Reen trantReadW riteLock g etAccessLo ck() | |
| 98 | { | |
| 99 | retu rn this.ac cessLock; | |
| 100 | } | |
| 101 | ||
| 102 | pr ivate Read Lock getRe adLock() | |
| 103 | { | |
| 104 | retu rn getAcce ssLock().r eadLock(); | |
| 105 | } | |
| 106 | ||
| 107 | pr ivate Writ eLock getW riteLock() | |
| 108 | { | |
| 109 | retu rn getAcce ssLock().w riteLock() ; | |
| 110 | } | |
| 111 | ||
| 112 | pu blic boole an isWrite Locked() | |
| 113 | th rows Inter ruptedExce ption | |
| 114 | { | |
| 115 | bool ean lockAc quired = g etWriteLoc k().tryLoc k(0L, Time Unit.SECON DS); | |
| 116 | if(l ockAcquire d) | |
| 117 | getWri teLock().u nlock(); | |
| 118 | ||
| 119 | retu rn !lockAc quired; | |
| 120 | } | |
| 121 | ||
| 122 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== = | |
| 123 | // Abstract (type spec ific) | |
| 124 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== = | |
| 125 | /* * | |
| 126 | * May creat e an imple mentation specific g roup or in stance, so an abstra ct method | |
| 127 | * | |
| 128 | * @param na me | |
| 129 | * @param cr eate | |
| 130 | * @return | |
| 131 | * @throws C acheExcept ion | |
| 132 | * / | |
| 133 | pr otected ab stract T g etOrCreate (String na me, boolea n create) | |
| 134 | th rows Cache Exception; | |
| 135 | ||
| 136 | /* * | |
| 137 | * Method in the deriv ed class t hat actual ly does th e persiste nt to | |
| 138 | * transient synchroni zation. | |
| 139 | * | |
| 140 | * @throws C acheExcept ion | |
| 141 | * / | |
| 142 | pr otected ab stract voi d internal Synchroniz eChildren( ) | |
| 143 | th rows Cache Exception; | |
| 144 | ||
| 145 | /* * | |
| 146 | * Assure th at the int ernal repr esentation of child instances matches | |
| 147 | * what is i n the pers istent sto rage (file system). | |
| 148 | * | |
| 149 | * @throws C acheExcept ion | |
| 150 | * / | |
| 151 | pr ivate fina l void syn chronizeCh ildren() | |
| 152 | th rows Cache Exception | |
| 153 | { | |
| 154 | getW riteLock() .lock(); | |
| 155 | try | |
| 156 | { | |
| 157 | intern alSynchron izeChildre n(); | |
| 158 | } | |
| 159 | fina lly | |
| 160 | { | |
| 161 | getWri teLock().u nlock(); | |
| 162 | } | |
| 163 | ||
| 164 | } | |
| 165 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== = | |
| 166 | // Overrides to provid e locking as require d | |
| 167 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== = | |
| 168 | /* * | |
| 169 | * @se e java.uti l.HashSet# add(java.l ang.Object ) | |
| 170 | */ | |
| 171 | @Overr ide | |
| 172 | public boolean a dd(SoftRef erence<? e xtends T> e) | |
| 173 | { | |
| 174 | ge tWriteLock ().lock(); | |
| 175 | tr y | |
| 176 | { | |
| 177 | retu rn super.a dd(e); | |
| 178 | } | |
| 179 | fi nally | |
| 180 | { | |
| 181 | getW riteLock() .unlock(); | |
| 182 | } | |
| 183 | } | |
| 184 | ||
| 185 | /* * | |
| 186 | * @se e java.uti l.HashSet# clear() | |
| 187 | */ | |
| 188 | @Overr ide | |
| 189 | public void clea r() | |
| 190 | { | |
| 191 | ge tWriteLock ().lock(); | |
| 192 | tr y | |
| 193 | { | |
| 194 | supe r.clear(); | |
| 195 | } | |
| 196 | fi nally | |
| 197 | { | |
| 198 | getW riteLock() .unlock(); | |
| 199 | } | |
| 200 | } | |
| 201 | ||
| 202 | /* * | |
| 203 | * @se e java.uti l.HashSet# remove(jav a.lang.Obj ect) | |
| 204 | */ | |
| 205 | @Overr ide | |
| 206 | public boolean r emove(Obje ct o) | |
| 207 | { | |
| 208 | ge tWriteLock ().lock(); | |
| 209 | tr y | |
| 210 | { | |
| 211 | return s uper.remov e(o); | |
| 212 | } | |
| 213 | fi nally | |
| 214 | { | |
| 215 | getW riteLock() .unlock(); | |
| 216 | } | |
| 217 | } | |
| 218 | ||
| 219 | /** | |
| 220 | * Rem ove the ob ject that has the gi ven that h as the nam e given fr om the Set . | |
| 221 | * | |
| 222 | * @pa ram name | |
| 223 | * @re turn | |
| 224 | */ | |
| 225 | public boolean r emoveByNam e(String n ame) | |
| 226 | { | |
| 227 | if (name == n ull) | |
| 228 | retu rn false; | |
| 229 | ||
| 230 | ge tWriteLock ().lock(); | |
| 231 | tr y | |
| 232 | { | |
| 233 | for( SoftRefere nce<? exte nds T> mem ber : this ) | |
| 234 | { | |
| 235 | T refe rent = mem ber.get(); | |
| 236 | if( re ferent != null && na me.equals( referent.g etName()) ) | |
| 237 | { | |
| 238 | this.rem ove(member ); | |
| 239 | return t rue; | |
| 240 | } | |
| 241 | } | |
| 242 | retu rn false; | |
| 243 | } | |
| 244 | fi nally | |
| 245 | { | |
| 246 | getW riteLock() .unlock(); | |
| 247 | } | |
| 248 | } | |
| 249 | ||
| 250 | /* * | |
| 251 | * @se e java.uti l.Abstract Set#remove All(java.u til.Collec tion) | |
| 252 | */ | |
| 253 | @Overr ide | |
| 254 | public boolean r emoveAll(C ollection< ?> c) | |
| 255 | { | |
| 256 | ge tWriteLock ().lock(); | |
| 257 | tr y | |
| 258 | { | |
| 259 | return s uper.remov eAll(c); | |
| 260 | } | |
| 261 | fi nally | |
| 262 | { | |
| 263 | getW riteLock() .unlock(); | |
| 264 | } | |
| 265 | } | |
| 266 | ||
| 267 | /* * | |
| 268 | * @se e java.uti l.Abstract Collection #addAll(ja va.util.Co llection) | |
| 269 | */ | |
| 270 | @Overr ide | |
| 271 | public boolean a ddAll(Coll ection<? e xtends Sof tReference <? extends T>> c) | |
| 272 | { | |
| 273 | ge tWriteLock ().lock(); | |
| 274 | tr y | |
| 275 | { | |
| 276 | return s uper.addAl l(c); | |
| 277 | } | |
| 278 | fi nally | |
| 279 | { | |
| 280 | getW riteLock() .unlock(); | |
| 281 | } | |
| 282 | } | |
| 283 | ||
| 284 | /* * | |
| 285 | * @se e java.uti l.Abstract Collection #containsA ll(java.ut il.Collect ion) | |
| 286 | */ | |
| 287 | @Overr ide | |
| 288 | public boolean c ontainsAll (Collectio n<?> c) | |
| 289 | { | |
| 290 | ge tReadLock( ).lock(); | |
| 291 | tr y | |
| 292 | { | |
| 293 | return s uper.conta insAll(c); | |
| 294 | } | |
| 295 | fi nally | |
| 296 | { | |
| 297 | getR eadLock(). unlock(); | |
| 298 | } | |
| 299 | } | |
| 300 | ||
| 301 | /* * | |
| 302 | * @se e java.uti l.Abstract Collection #retainAll (java.util .Collectio n) | |
| 303 | */ | |
| 304 | @Overr ide | |
| 305 | public boolean r etainAll(C ollection< ?> c) | |
| 306 | { | |
| 307 | ge tWriteLock ().lock(); | |
| 308 | tr y | |
| 309 | { | |
| 310 | return s uper.retai nAll(c); | |
| 311 | } | |
| 312 | fi nally | |
| 313 | { | |
| 314 | getW riteLock() .unlock(); | |
| 315 | } | |
| 316 | } | |
| 317 | ||
| 318 | /* * | |
| 319 | * @se e java.uti l.HashSet# clone() | |
| 320 | */ | |
| 321 | @Overr ide | |
| 322 | public Object cl one() | |
| 323 | { | |
| 324 | ge tReadLock( ).lock(); | |
| 325 | tr y | |
| 326 | { | |
| 327 | retu rn super.c lone(); | |
| 328 | } | |
| 329 | fi nally | |
| 330 | { | |
| 331 | getR eadLock(). unlock(); | |
| 332 | } | |
| 333 | } | |
| 334 | ||
| 335 | /* * | |
| 336 | * @se e java.uti l.HashSet# contains(j ava.lang.O bject) | |
| 337 | */ | |
| 338 | @Overr ide | |
| 339 | public boolean c ontains(Ob ject o) | |
| 340 | { | |
| 341 | ge tReadLock( ).lock(); | |
| 342 | tr y | |
| 343 | { | |
| 344 | retu rn super.c ontains(o) ; | |
| 345 | } | |
| 346 | fi nally | |
| 347 | { | |
| 348 | getR eadLock(). unlock(); | |
| 349 | } | |
| 350 | } | |
| 351 | ||
| 352 | /* * | |
| 353 | * @se e java.uti l.HashSet# isEmpty() | |
| 354 | */ | |
| 355 | @Overr ide | |
| 356 | public boolean i sEmpty() | |
| 357 | { | |
| 358 | ge tReadLock( ).lock(); | |
| 359 | tr y | |
| 360 | { | |
| 361 | retu rn super.i sEmpty(); | |
| 362 | } | |
| 363 | fi nally | |
| 364 | { | |
| 365 | getR eadLock(). unlock(); | |
| 366 | } | |
| 367 | } | |
| 368 | ||
| 369 | /* * | |
| 370 | * @se e java.uti l.HashSet# size() | |
| 371 | */ | |
| 372 | @Overr ide | |
| 373 | public int size( ) | |
| 374 | { | |
| 375 | ge tReadLock( ).lock(); | |
| 376 | tr y | |
| 377 | { | |
| 378 | retu rn super.s ize(); | |
| 379 | } | |
| 380 | fi nally | |
| 381 | { | |
| 382 | getR eadLock(). unlock(); | |
| 383 | } | |
| 384 | } | |
| 385 | ||
| 386 | /* * | |
| 387 | * @se e java.uti l.Abstract Collection #toArray() | |
| 388 | */ | |
| 389 | @Overr ide | |
| 390 | public Object[] toArray() | |
| 391 | { | |
| 392 | ge tReadLock( ).lock(); | |
| 393 | tr y | |
| 394 | { | |
| 395 | retu rn super.t oArray(); | |
| 396 | } | |
| 397 | fi nally | |
| 398 | { | |
| 399 | getR eadLock(). unlock(); | |
| 400 | } | |
| 401 | } | |
| 402 | ||
| 403 | /* * | |
| 404 | * @se e java.uti l.Abstract Collection #toArray(T []) | |
| 405 | */ | |
| 406 | @Overr ide | |
| 407 | public <S> S[] t oArray(S[] a) | |
| 408 | { | |
| 409 | ge tReadLock( ).lock(); | |
| 410 | tr y | |
| 411 | { | |
| 412 | retu rn super.t oArray(a); | |
| 413 | } | |
| 414 | fi nally | |
| 415 | { | |
| 416 | getR eadLock(). unlock(); | |
| 417 | } | |
| 418 | } | |
| 419 | ||
| 420 | /** | |
| 421 | * Ove rride the iterator a nd throw U nsuppporte dOperation Exception when | |
| 422 | * cal ling remov e() so tha t Concurre ntModifica tionExcept ion cannot occur. | |
| 423 | */ | |
| 424 | @O verride | |
| 425 | pu blic Itera tor<SoftRe ference<? extends T> > iterator () | |
| 426 | { | |
| 427 | retu rn new Ite rator<Soft Reference< ? extends T>>() | |
| 428 | { | |
| 429 | privat e Iterator <SoftRefer ence<? ext ends T>> w rappedIter = Persist entSet.sup er.iterato r(); | |
| 430 | ||
| 431 | @Overr ide | |
| 432 | public boolean h asNext() | |
| 433 | { | |
| 434 | return w rappedIter .hasNext() ; | |
| 435 | } | |
| 436 | ||
| 437 | @Overr ide | |
| 438 | public SoftRefer ence<? ext ends T> ne xt() | |
| 439 | { | |
| 440 | return w rappedIter .next(); | |
| 441 | } | |
| 442 | ||
| 443 | @Overr ide | |
| 444 | public void remo ve() | |
| 445 | { | |
| 446 | Persiste ntSet.this .getWriteL ock().lock (); | |
| 447 | try | |
| 448 | { | |
| 449 | wrappedIte r.remove() ; | |
| 450 | } | |
| 451 | finally | |
| 452 | { | |
| 453 | Persistent Set.this.g etWriteLoc k().unlock (); | |
| 454 | } | |
| 455 | //throw new Unsupp ortedOpera tionExcept ion("Persi stentSet.I terator do es not sup port remov e() operat ion."); | |
| 456 | } | |
| 457 | }; | |
| 458 | } | |
| 459 | ||
| 460 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== = | |
| 461 | // Business Methods (c hild group s instance managemen t) | |
| 462 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== = | |
| 463 | /* * | |
| 464 | * Get, and possibly c reate, a c hild Insta nce. Sync hronize th e transien t and pers istent | |
| 465 | * Instances . | |
| 466 | * | |
| 467 | * @param in stanceName | |
| 468 | * @param cr eate | |
| 469 | * @return | |
| 470 | * @throws C acheExcept ion | |
| 471 | * / | |
| 472 | pu blic final T getChil d(String n ame, boole an create) | |
| 473 | th rows Cache Exception | |
| 474 | { | |
| 475 | if(n ame == nul l) | |
| 476 | return null; | |
| 477 | ||
| 478 | // l ock for wr ite always , we canno t upgrade a read-loc k and we m ust | |
| 479 | // h ave a writ e lock to add to the set | |
| 480 | getW riteLock() .lock(); | |
| 481 | ||
| 482 | try | |
| 483 | { | |
| 484 | T chil d = getTra nsient(nam e); | |
| 485 | if(chi ld != null ) | |
| 486 | return c hild; | |
| 487 | ||
| 488 | child = getOrCre ate(name, create); | |
| 489 | ||
| 490 | add( | |
| 491 | monitorS oftReferen ces ? | |
| 492 | new Soft Reference< T>(child, dereferenc edMembers) : | |
| 493 | new Soft Reference< T>(child) | |
| 494 | ); | |
| 495 | ||
| 496 | return child; | |
| 497 | } | |
| 498 | fina lly | |
| 499 | { | |
| 500 | getWri teLock().u nlock(); | |
| 501 | } | |
| 502 | } | |
| 503 | ||
| 504 | /* * | |
| 505 | * Get the c hild insta nce from t ransient ( memory), i f it is lo aded. | |
| 506 | * DO NOT LO AD FROM PE RSISTENT S TORAGE. | |
| 507 | * | |
| 508 | * @param in stanceName | |
| 509 | * @return | |
| 510 | * / | |
| 511 | pr otected T getTransie nt(String name) | |
| 512 | { | |
| 513 | Soft Reference< ? extends T> childRe f = getTra nsientRefe rence(name ); | |
| 514 | retu rn childRe f == null ? null : c hildRef.ge t(); | |
| 515 | } | |
| 516 | ||
| 517 | /* * | |
| 518 | * Get a ref erence to a transien t instance if it is loaded. | |
| 519 | * Not that this just gets the S oftReferen ce, the ex istence of the refer ent Instan ce is | |
| 520 | * not guara nteed, tho ugh it is very likel y to be th ere. | |
| 521 | * | |
| 522 | * @param in stanceName | |
| 523 | * @return | |
| 524 | * / | |
| 525 | pr otected fi nal SoftRe ference<? extends T> getTransi entReferen ce(String name) | |
| 526 | { | |
| 527 | // S ynchronize access so that othe r threads cannot mod ify it whi le we are searching. | |
| 528 | getR eadLock(). lock(); | |
| 529 | try | |
| 530 | { | |
| 531 | for(So ftReferenc e<? extend s T> group WeakRef : this ) | |
| 532 | { | |
| 533 | T child = groupWea kRef.get() ; | |
| 534 | if( chil d != null && child.g etName().e quals(name ) ) | |
| 535 | return gro upWeakRef; | |
| 536 | } | |
| 537 | } | |
| 538 | fina lly | |
| 539 | { | |
| 540 | getRea dLock().un lock(); | |
| 541 | } | |
| 542 | retu rn null; | |
| 543 | } | |
| 544 | ||
| 545 | /* * | |
| 546 | * @throws C acheExcept ion | |
| 547 | * | |
| 548 | * / | |
| 549 | pu blic final void dele teChild(T child) | |
| 550 | th rows Cache Exception | |
| 551 | { | |
| 552 | if(c hild==null ) | |
| 553 | return ; | |
| 554 | ||
| 555 | getW riteLock() .lock(); | |
| 556 | try | |
| 557 | { | |
| 558 | SoftRe ference<? extends T> ref = get TransientR eference(c hild.getNa me()); | |
| 559 | remove (ref); | |
| 560 | child. remove(); // r emove the correspond ing file | |
| 561 | } | |
| 562 | fina lly | |
| 563 | { | |
| 564 | getWri teLock().u nlock(); | |
| 565 | } | |
| 566 | } | |
| 567 | ||
| 568 | pu blic final void dele teAll() | |
| 569 | th rows Cache Exception | |
| 570 | { | |
| 571 | getW riteLock() .lock(); | |
| 572 | sync hronizeChi ldren(); | |
| 573 | try | |
| 574 | { | |
| 575 | for(So ftReferenc e<? extend s T> child : this) | |
| 576 | { | |
| 577 | T childR ef = child .get(); | |
| 578 | // if th e referenc e still ex ists, remo ve it | |
| 579 | if(child Ref != nul l) | |
| 580 | childRef.r emove(); | |
| 581 | } | |
| 582 | clear( ); | |
| 583 | } | |
| 584 | fina lly | |
| 585 | { | |
| 586 | getWri teLock().u nlock(); | |
| 587 | } | |
| 588 | } | |
| 589 | ||
| 590 | pu blic final long getS ize() | |
| 591 | th rows Cache Exception | |
| 592 | { | |
| 593 | sync hronizeChi ldren(); | |
| 594 | retu rn size(); | |
| 595 | } | |
| 596 | ||
| 597 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ====== | |
| 598 | // The evict ion group as determi ned by the given evi ction judg e | |
| 599 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ====== | |
| 600 | /* * | |
| 601 | * Return th e Set of G roup insta nces that are evicta ble accord ing to the | |
| 602 | * given Evi ctionJudge . | |
| 603 | * NOTE: thi s is not a recursive method. The descen dant group s, that ma y be | |
| 604 | * evictable , are not included i n this lis t. | |
| 605 | * | |
| 606 | * @param ju dge | |
| 607 | * @return | |
| 608 | * / | |
| 609 | pu blic final Set<T> ev ictableChi ldren(Evic tionJudge< T> judge) | |
| 610 | { | |
| 611 | Set< T> evictab leChildren = null; | |
| 612 | ||
| 613 | // w ait a very short tim e for a re ad lock | |
| 614 | // i f we can't get it re turn an em pty set of evictable | |
| 615 | // g roups | |
| 616 | try | |
| 617 | { | |
| 618 | if( ge tReadLock( ).tryLock( 1, TimeUni t.SECONDS) ) | |
| 619 | { | |
| 620 | try | |
| 621 | { | |
| 622 | evictableC hildren = internalEv ictableGro ups(judge) ; | |
| 623 | } | |
| 624 | catch(Co ncurrentMo dification Exception cmX) | |
| 625 | { | |
| 626 | log.warn(" Concurrent modificat ion of chi ld groups while runn ing an evi ction swee p. Region not compl etely clea ned but su bsequent s weeps will do so. ") ; | |
| 627 | } | |
| 628 | finally | |
| 629 | { | |
| 630 | getReadLoc k().unlock (); | |
| 631 | } | |
| 632 | } | |
| 633 | } | |
| 634 | catc h (Interru ptedExcept ion e) | |
| 635 | { | |
| 636 | log.wa rn(e); | |
| 637 | } | |
| 638 | ||
| 639 | retu rn evictab leChildren ; | |
| 640 | } | |
| 641 | ||
| 642 | /* * | |
| 643 | * @param ju dge | |
| 644 | * @param ev ictableChi ldren | |
| 645 | * / | |
| 646 | pr ivate Set< T> interna lEvictable Groups(Evi ctionJudge <T> judge) | |
| 647 | { | |
| 648 | Set< T> evictab leChildren = new Has hSet<T>(); | |
| 649 | ||
| 650 | for( SoftRefere nce<? exte nds T> chi ldRef : th is) | |
| 651 | { | |
| 652 | T chil d = childR ef.get(); | |
| 653 | ||
| 654 | // the child gro up may no longer be referenced | |
| 655 | if(chi ld != null ) | |
| 656 | { | |
| 657 | try | |
| 658 | { | |
| 659 | if( judge. isEvictabl e(child) ) | |
| 660 | { | |
| 661 | lo g.info("Qu eueing gro up '" + ch ild.getNam e() + " fo r eviction ."); | |
| 662 | ev ictableChi ldren.add( child); | |
| 663 | } | |
| 664 | } | |
| 665 | catch (C acheExcept ion e) | |
| 666 | { | |
| 667 | log.error( "CacheExce ption eval uating evi ction crit eria for g roup '" + child.toSt ring() + " ', which m ay have to be manual ly deleted .", e); | |
| 668 | } | |
| 669 | } | |
| 670 | } | |
| 671 | ||
| 672 | retu rn evictab leChildren ; | |
| 673 | } | |
| 674 | ||
| 675 | ||
| 676 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ====== | |
| 677 | // The group iterator and the it erator cla ss | |
| 678 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ====== | |
| 679 | ||
| 680 | pu blic Itera tor<T> har dReference Iterator() | |
| 681 | { | |
| 682 | try | |
| 683 | { | |
| 684 | return new Persi stentSetIt erator<T>( this); | |
| 685 | } | |
| 686 | catc h (CacheEx ception e) | |
| 687 | { | |
| 688 | log.er ror(e); | |
| 689 | return null; | |
| 690 | } | |
| 691 | } | |
| 692 | ||
| 693 | cl ass Persis tentSetIte rator<S ex tends Muta bleNamedOb ject> | |
| 694 | im plements I terator<S> | |
| 695 | { | |
| 696 | priv ate Iterat or<SoftRef erence<? e xtends S>> wrappedIt erator = n ull; | |
| 697 | ||
| 698 | Pers istentSetI terator(Pe rsistentSe t<S> paren t) | |
| 699 | thro ws CacheEx ception | |
| 700 | { | |
| 701 | intern alSynchron izeChildre n(); | |
| 702 | wrappe dIterator = parent.i terator(); | |
| 703 | } | |
| 704 | ||
| 705 | publ ic boolean hasNext() | |
| 706 | { | |
| 707 | return wrappedIt erator.has Next(); | |
| 708 | } | |
| 709 | ||
| 710 | publ ic S next( ) | |
| 711 | { | |
| 712 | SoftRe ference<? extends S> ref = wra ppedIterat or.next(); | |
| 713 | return ref.get() ; | |
| 714 | } | |
| 715 | ||
| 716 | publ ic void re move() | |
| 717 | { | |
| 718 | throw new Unsupp ortedOpera tionExcept ion(); | |
| 719 | } | |
| 720 | }; | |
| 721 | ||
| 722 | st atic class Reference QueueNotif ication | |
| 723 | im plements R unnable | |
| 724 | { | |
| 725 | priv ate static final lon g serialVe rsionUID = 1L; | |
| 726 | priv ate final ReferenceQ ueue queue ; | |
| 727 | ||
| 728 | publ ic Referen ceQueueNot ification( ReferenceQ ueue queue ) | |
| 729 | { | |
| 730 | this.q ueue = que ue; | |
| 731 | } | |
| 732 | ||
| 733 | publ ic void ru n() | |
| 734 | { | |
| 735 | try | |
| 736 | { | |
| 737 | for( Ref erence ref = queue.r emove(); r ef != null ; ref = qu eue.remove () ) | |
| 738 | System.out .println( "Persisten tSet refer ence queue freed " + ref.getCl ass().getN ame() ); | |
| 739 | } | |
| 740 | catch (Exception x) | |
| 741 | { | |
| 742 | // ignor e it | |
| 743 | } | |
| 744 | } | |
| 745 | } | |
| 746 | ||
| 747 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.