Produced by Araxis Merge on 12/5/2017 12:06:35 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\CacheImpl\main\src\java\gov\va\med\imaging\storage\cache\impl | KnownCacheList.java | Mon Dec 4 21:35:18 2017 UTC |
| 2 | IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\CacheImpl\main\src\java\gov\va\med\imaging\storage\cache\impl | KnownCacheList.java | Mon Dec 4 21:57:34 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 3 | 854 |
| Changed | 2 | 4 |
| 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 | package go v.va.med.i maging.sto rage.cache .impl; | |
| 2 | ||
| 3 | import gov .va.med.im aging.stor age.cache. Cache; | |
| 4 | import gov .va.med.im aging.stor age.cache. exceptions .CacheExce ption; | |
| 5 | import gov .va.med.im aging.stor age.cache. exceptions .CacheInit ialization Exception; | |
| 6 | import gov .va.med.im aging.stor age.cache. memento.Ca cheMemento ; | |
| 7 | ||
| 8 | import jav a.beans.XM LDecoder; | |
| 9 | import jav a.beans.XM LEncoder; | |
| 10 | import jav a.io.*; | |
| 11 | import jav a.net.URI; | |
| 12 | import jav a.util.Arr ayList; | |
| 13 | import jav a.util.Ite rator; | |
| 14 | import jav a.util.Lis t; | |
| 15 | ||
| 16 | import jav ax.naming. OperationN otSupporte dException ; | |
| 17 | ||
| 18 | import org .apache.lo gging.log4 j.LogManag er; | |
| 19 | import org .apache.lo gging.log4 j.Logger; | |
| 20 | ||
| 21 | /** | |
| 22 | * @author
|
|
| 23 | * | |
| 24 | * A Cache specific list that: | |
| 25 | * is appr opriately synchroniz ed | |
| 26 | * prevent s duplicat e entries (same name ) | |
| 27 | * maintai ns synchro nization w ith the pe rsistent s torage | |
| 28 | * | |
| 29 | * NOTE: i n general public met hods shoul d be synch ronized to assure th at | |
| 30 | * this cl ass can ke ep the con fig files and the in ternal kno wn file | |
| 31 | * list in synch. | |
| 32 | * | |
| 33 | * | |
| 34 | */ | |
| 35 | public cla ss KnownCa cheList | |
| 36 | implements Iterable< Cache> | |
| 37 | { | |
| 38 | pu blic stati c final St ring cache ConfigFile NameSuffix = "-cache .xml"; | |
| 39 | ||
| 40 | pr ivate Logg er logger = LogManag er.getLogg er(this.ge tClass()); | |
| 41 | pr ivate File configura tionDirect ory; | |
| 42 | pr ivate List <Cache> wr appedList = new Arra yList<Cach e>(); | |
| 43 | pr ivate stat ic final l ong serial VersionUID = 1L; | |
| 44 | ||
| 45 | /* * | |
| 46 | * | |
| 47 | * @param co nfiguratio nDirectory | |
| 48 | * @param ca cheFactory | |
| 49 | * / | |
| 50 | Kn ownCacheLi st(File co nfiguratio nDirectory ) | |
| 51 | { | |
| 52 | this .configura tionDirect ory = conf igurationD irectory; | |
| 53 | load All(); | |
| 54 | } | |
| 55 | ||
| 56 | Fi le getConf igurationD irectory() | |
| 57 | { | |
| 58 | retu rn this.co nfiguratio nDirectory ; | |
| 59 | } | |
| 60 | ||
| 61 | /* * | |
| 62 | * | |
| 63 | * / | |
| 64 | pu blic Itera tor<Cache> iterator( ) | |
| 65 | { | |
| 66 | retu rn wrapped List.itera tor(); | |
| 67 | } | |
| 68 | ||
| 69 | pu blic boole an isKnown Cache(Cach e cache) | |
| 70 | { | |
| 71 | retu rn wrapped List.conta ins(cache) ; | |
| 72 | } | |
| 73 | ||
| 74 | /* * | |
| 75 | * Add an ex isting cac he to this list. | |
| 76 | * | |
| 77 | * @param ca che | |
| 78 | * @return | |
| 79 | * @throws I OException | |
| 80 | * / | |
| 81 | pr ivate sync hronized b oolean add (Cache cac he) | |
| 82 | th rows IOExc eption | |
| 83 | { | |
| 84 | if(c ache == nu ll) | |
| 85 | return false; | |
| 86 | ||
| 87 | // p revent dup licate nam es | |
| 88 | if( get(cache. getName()) != null) | |
| 89 | return false; | |
| 90 | ||
| 91 | Cach eMemento m emento = c ache.creat eMemento() ; | |
| 92 | File mementoFi le = getCa cheMemento File(cache .getName() ); | |
| 93 | ||
| 94 | // i f we fail to save th e file the n the cach e will not get | |
| 95 | // s aved in th e known li st | |
| 96 | stor eCacheMeme nto(mement o, memento File); | |
| 97 | ||
| 98 | retu rn wrapped List.add(c ache); | |
| 99 | } | |
| 100 | ||
| 101 | /* * | |
| 102 | * Create a cache inst ance that supports t he protoco l specifie d by the U RI scheme | |
| 103 | * and then saves the cache inst ance in th is list. Configure the new ca che with n o | |
| 104 | * regions a nd no evic tion strat egies. | |
| 105 | * | |
| 106 | * @param ca cheName | |
| 107 | * @param lo cationUri | |
| 108 | * @return | |
| 109 | * @throws C acheExcept ion | |
| 110 | * @throws I OException | |
| 111 | * / | |
| 112 | pu blic synch ronized Ca che create (String ca cheName, U RI locatio nUri) | |
| 113 | th rows Cache Exception, IOExcepti on | |
| 114 | { | |
| 115 | retu rn create( cacheName, locationU ri, (Strin g)null); | |
| 116 | } | |
| 117 | ||
| 118 | /* * | |
| 119 | * Create a cache inst ance that supports t he protoco l specifie d by the U RI scheme | |
| 120 | * and then saves the cache inst ance in th is list. Configure the new ca che as spe cified | |
| 121 | * by the cr eateMode. | |
| 122 | * | |
| 123 | * @param na me | |
| 124 | * @param lo cationUri | |
| 125 | * @return | |
| 126 | * @throws C acheExcept ion | |
| 127 | * @throws I OException | |
| 128 | * / | |
| 129 | pu blic synch ronized Ca che create (String ca cheName, U RI locatio nUri, Stri ng configu rationStra tegyName) | |
| 130 | th rows Cache Exception, IOExcepti on | |
| 131 | { | |
| 132 | if(c acheName = = null || locationUr i == null) | |
| 133 | return null; | |
| 134 | ||
| 135 | Cach e cache = CacheFacto ry.getSing leton().cr eateCache( cacheName, locationU ri, config urationStr ategyName) ; | |
| 136 | ||
| 137 | add( cache); | |
| 138 | ||
| 139 | retu rn cache; | |
| 140 | } | |
| 141 | ||
| 142 | /* * | |
| 143 | * This meth od require s that all parameter s be non-n ull | |
| 144 | * | |
| 145 | * @param na me | |
| 146 | * @param lo cationUri | |
| 147 | * @param pr ototype | |
| 148 | * @return | |
| 149 | * / | |
| 150 | pu blic Cache create(St ring cache Name, URI locationUr i, InputSt ream proto type) | |
| 151 | th rows Cache Exception, IOExcepti on | |
| 152 | { | |
| 153 | if(c acheName = = null || locationUr i == null || prototy pe == null ) | |
| 154 | return null; | |
| 155 | ||
| 156 | Cach e cache = CacheFacto ry.getSing leton().cr eateCache( cacheName, locationU ri, protot ype); | |
| 157 | ||
| 158 | add( cache); | |
| 159 | ||
| 160 | retu rn cache; | |
| 161 | } | |
| 162 | ||
| 163 | /* * | |
| 164 | * | |
| 165 | * @param ca cheName | |
| 166 | * @return | |
| 167 | * / | |
| 168 | pu blic synch ronized Ca che get(St ring cache Name) | |
| 169 | { | |
| 170 | if(c acheName = = null) | |
| 171 | return null; | |
| 172 | ||
| 173 | for( Cache cach e: wrapped List) | |
| 174 | if(cac heName.equ als(cache. getName()) ) | |
| 175 | return c ache; | |
| 176 | ||
| 177 | retu rn null; | |
| 178 | } | |
| 179 | ||
| 180 | sy nchronized boolean r emove(Stri ng cacheNa me) | |
| 181 | { | |
| 182 | Cach e deadManW alking = n ull; | |
| 183 | ||
| 184 | if(c acheName = = null) | |
| 185 | return false; | |
| 186 | ||
| 187 | for( Cache cach e: wrapped List) | |
| 188 | if(cac heName.equ als(cache. getName()) ) | |
| 189 | { | |
| 190 | deadManW alking = c ache; | |
| 191 | break; | |
| 192 | } | |
| 193 | ||
| 194 | if(d eadManWalk ing != nul l && wrapp edList.rem ove(deadMa nWalking) ) | |
| 195 | { | |
| 196 | delete Configurat ion(deadMa nWalking.g etName()); | |
| 197 | return true; | |
| 198 | } | |
| 199 | ||
| 200 | retu rn false; | |
| 201 | } | |
| 202 | ||
| 203 | pu blic synch ronized vo id storeAl l() throws IOExcepti on | |
| 204 | { | |
| 205 | for( Cache cach e : wrappe dList ) | |
| 206 | store( cache); | |
| 207 | } | |
| 208 | ||
| 209 | pu blic synch ronized vo id store(C ache cache ) | |
| 210 | th rows IOExc eption | |
| 211 | { | |
| 212 | Stri ng cacheNa me = cache .getName() ; | |
| 213 | Cach eMemento c acheMement o = cache. createMeme nto(); | |
| 214 | ||
| 215 | File mementoFi le = getCa cheMemento File(cache Name); | |
| 216 | stor eCacheMeme nto(cacheM emento, me mentoFile) ; | |
| 217 | } | |
| 218 | ||
| 219 | /* * | |
| 220 | * Load all of the kno wn Cache f rom the co nfiguratio n files. | |
| 221 | * @throws C acheInitia lizationEx ception | |
| 222 | * | |
| 223 | * / | |
| 224 | pr ivate void loadAll() | |
| 225 | { | |
| 226 | Cach eConfigura tionFiles files = ne w CacheCon figuration Files(conf igurationD irectory); | |
| 227 | for( File memen toFile : f iles) | |
| 228 | { | |
| 229 | try | |
| 230 | { | |
| 231 | CacheMem ento memen to = loadC acheMement o(mementoF ile); | |
| 232 | Cache ca che = Cach eFactory.g etSingleto n().create Cache(meme nto); | |
| 233 | ||
| 234 | wrappedL ist.add(ca che); | |
| 235 | } | |
| 236 | catch( CacheIniti alizationE xception x ) | |
| 237 | { | |
| 238 | logger.e rror(x); | |
| 239 | } | |
| 240 | catch (FileNotFo undExcepti on x) | |
| 241 | { | |
| 242 | logger.e rror(x); | |
| 243 | } | |
| 244 | catch (IOExcepti on x) | |
| 245 | { | |
| 246 | logger.e rror(x); | |
| 247 | } | |
| 248 | } | |
| 249 | } | |
| 250 | ||
| 251 | /* * | |
| 252 | * | |
| 253 | * @param me mento | |
| 254 | * @param me mentoFile | |
| 255 | * @throws I OException | |
| 256 | * / | |
| 257 | pr ivate void storeCach eMemento(C acheMement o memento, File meme ntoFile) | |
| 258 | th rows IOExc eption | |
| 259 | { | |
| 260 | // T he XMLEnco der uses t he current threads c ontext cla ssloader t o | |
| 261 | // l oad classe s it needs to serial ize. You would kind a' think t hat | |
| 262 | // s ince it is handed a fully popu lated obje ct to seri alize ir w ouldn't | |
| 263 | // n eed to loa d anything but it do es. | |
| 264 | // U nfortunate ly, in a T omcat serv er at leas t, the thr ead is an RMI handli ng thread | |
| 265 | // w hose conte xt class l oader does not have access to the mement o classes. | |
| 266 | // H ence this garbage ab out settin g the thre ad's conte xt class l oader, and then | |
| 267 | // s etting it back when we're done . The cla ss loader that loade d the cach e must | |
| 268 | // h ave access to the me mento clas ses, since it create d the inst ances, so that is | |
| 269 | // w hy it is u sed. | |
| 270 | Clas sLoader co ntextClass Loader = T hread.curr entThread( ).getConte xtClassLoa der(); | |
| 271 | ||
| 272 | XMLE ncoder enc oder = nul l; | |
| 273 | ||
| 274 | try | |
| 275 | { | |
| 276 | Thread .currentTh read().set ContextCla ssLoader( memento.ge tClass().g etClassLoa der() ); | |
| 277 | logger .info("Sto ring confi guration t o '" + mem entoFile.g etCanonica lPath() + "'."); | |
| 278 | ||
| 279 | encode r = new XM LEncoder(n ew FileOut putStream( mementoFil e)); | |
| 280 | logger .info("Con figuration encoder ' " + encode r.getClass ().getName () + "' cr eated, wri ting memen to object. "); | |
| 281 | ||
| 282 | encode r.writeObj ect(mement o); | |
| 283 | } | |
| 284 | fina lly | |
| 285 | { | |
| 286 | try{en coder.clos e();}catch (Throwable x){} // eat a ny excepti ons | |
| 287 | Thread .currentTh read().set ContextCla ssLoader( contextCla ssLoader ) ; | |
| 288 | } | |
| 289 | } | |
| 290 | ||
| 291 | /* * | |
| 292 | * | |
| 293 | * @param me mentoFile | |
| 294 | * @return | |
| 295 | * @throws F ileNotFoun dException | |
| 296 | * @throws I OException | |
| 297 | * / | |
| 298 | pr ivate Cach eMemento l oadCacheMe mento(File mementoFi le) | |
| 299 | th rows FileN otFoundExc eption, IO Exception | |
| 300 | { | |
| 301 | XMLD ecoder enc oder = nul l; | |
| 302 | ||
| 303 | // s ee comment in storeM emento() o n class lo ading | |
| 304 | //Cl assLoader contextCla ssLoader = Thread.cu rrentThrea d().getCon textClassL oader(); | |
| 305 | ||
| 306 | try | |
| 307 | { | |
| 308 | //if(g etCache() != null ) | |
| 309 | // Thread.c urrentThre ad().setCo ntextClass Loader( ge tCache().g etClass(). getClassLo ader() ); | |
| 310 | logger .info("Loa ding confi guration f rom '" + m ementoFile .getCanoni calPath() + "'."); | |
| 311 | ||
| 312 | encode r = new XM LDecoder(n ew FileInp utStream(m ementoFile )); | |
| 313 | ||
| 314 | return (CacheMem ento)encod er.readObj ect(); | |
| 315 | } | |
| 316 | catc h (FileNot FoundExcep tion fnfX) | |
| 317 | { | |
| 318 | logger .error("Co nfiguratio n file not accessibl e", fnfX); | |
| 319 | throw fnfX; | |
| 320 | } | |
| 321 | catc h (IOExcep tion ioX) | |
| 322 | { | |
| 323 | logger .error("Co nfiguratio n file not accessibl e", ioX); | |
| 324 | throw ioX; | |
| 325 | } | |
| 326 | catc h (ClassCa stExceptio n ccX) | |
| 327 | { | |
| 328 | logger .error("Co nfiguratio n file doe s not cont ain FileSy stemCacheM emento", c cX); | |
| 329 | throw ccX; | |
| 330 | } | |
| 331 | fina lly | |
| 332 | { | |
| 333 | try{en coder.clos e();}catch (Throwable x){} // eat a ny excepti ons | |
| 334 | //if(g etCache() != null ) | |
| 335 | // Thread.c urrentThre ad().setCo ntextClass Loader( co ntextClass Loader ); | |
| 336 | } | |
| 337 | } | |
| 338 | ||
| 339 | /* * | |
| 340 | * Maps a ca che name t o the conf iguration file name. | |
| 341 | * | |
| 342 | * @return | |
| 343 | * / | |
| 344 | pr ivate Stri ng getCach eMementoFi lename(Str ing cacheN ame) | |
| 345 | { | |
| 346 | retu rn cacheNa me + cache ConfigFile NameSuffix ; | |
| 347 | } | |
| 348 | ||
| 349 | /* * | |
| 350 | * Get the c ache confi guration f ile given the cache name. | |
| 351 | * | |
| 352 | * @param ca cheName | |
| 353 | * @return | |
| 354 | * / | |
| 355 | pr ivate File getCacheM ementoFile (String ca cheName) | |
| 356 | { | |
| 357 | retu rn new Fil e( configu rationDire ctory, get CacheMemen toFilename (cacheName ) ); | |
| 358 | } | |
| 359 | ||
| 360 | /* * | |
| 361 | * This is r eally only here for testing be cause this is the on ly class t hat knows | |
| 362 | * where the memento f iles are k ept. | |
| 363 | * This dele tes the pe rsistent c ache state file (i.e . the conf iguration) . Don't | |
| 364 | * call it i f you don' t mean it 'cause it will delet e the file . | |
| 365 | * / | |
| 366 | pr ivate void deleteCon figuration (String ca cheName) | |
| 367 | { | |
| 368 | File mementoFi le = getCa cheMemento File(cache Name); | |
| 369 | ||
| 370 | logg er.warn("D eleting me mento file '" + meme ntoFile.ge tAbsoluteP ath() + "' ."); | |
| 371 | meme ntoFile.de lete(); | |
| 372 | logg er.warn("D eleted mem ento file '" + memen toFile.get AbsolutePa th() + "'. "); | |
| 373 | } | |
| 374 | ||
| 375 | ||
| 376 | /* * | |
| 377 | * The Cache Configurat ionFiles c lass is an Iterable class over the | |
| 378 | * configura tion files that exis ted when t he instanc e was init ialized. | |
| 379 | * | |
| 380 | * @author
|
|
| 381 | * | |
| 382 | * / | |
| 383 | pr ivate clas s CacheCon figuration Files | |
| 384 | im plements I terable<Fi le> | |
| 385 | { | |
| 386 | priv ate File[] configFil es; | |
| 387 | Cach eConfigura tionFiles( File confi gurationDi rectory) | |
| 388 | { | |
| 389 | config Files = co nfiguratio nDirectory .listFiles ( | |
| 390 | new File nameFilter () | |
| 391 | { | |
| 392 | public boo lean accep t(File dir , String n ame) | |
| 393 | { | |
| 394 | re turn name. endsWith(c acheConfig FileNameSu ffix); | |
| 395 | } | |
| 396 | } | |
| 397 | ); | |
| 398 | } | |
| 399 | ||
| 400 | /** | |
| 401 | * @ see java.l ang.Iterab le#iterato r() | |
| 402 | */ | |
| 403 | publ ic Iterato r<File> it erator() | |
| 404 | { | |
| 405 | return new Itera tor<File>( ) | |
| 406 | { | |
| 407 | private int index = 0; | |
| 408 | public b oolean has Next() | |
| 409 | { | |
| 410 | return ind ex < confi gFiles.len gth; | |
| 411 | } | |
| 412 | ||
| 413 | public F ile next() | |
| 414 | { | |
| 415 | return con figFiles[i ndex++]; | |
| 416 | } | |
| 417 | ||
| 418 | /** | |
| 419 | * @thro ws Operati onNotSuppo rtedExcept ion | |
| 420 | */ | |
| 421 | public v oid remove () | |
| 422 | { | |
| 423 | throw new Unsupporte dOperation Exception( ); | |
| 424 | } | |
| 425 | ||
| 426 | }; | |
| 427 | } | |
| 428 | } | |
| 429 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.