Produced by Araxis Merge on 12/5/2017 12:06:42 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\jcifs | JcifsCache.java | Mon Dec 4 21:35:34 2017 UTC |
| 2 | IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\ImagingCacheImpl\main\src\java\gov\va\med\imaging\storage\cache\impl\jcifs | JcifsCache.java | Mon Dec 4 22:01:39 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 760 |
| 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.jcif s; | |
| 5 | ||
| 6 | import gov .va.med.im aging.stor age.cache. *; | |
| 7 | import gov .va.med.im aging.stor age.cache. exceptions .*; | |
| 8 | import gov .va.med.im aging.stor age.cache. impl.Abstr actCacheIm pl; | |
| 9 | import gov .va.med.im aging.stor age.cache. impl.evict ion.Evicti onStrategy Factory; | |
| 10 | import gov .va.med.im aging.stor age.cache. impl.evict ion.LastAc cessedEvic tionStrate gy; | |
| 11 | import gov .va.med.im aging.stor age.cache. impl.evict ion.LastAc cessedEvic tionStrate gyMemento; | |
| 12 | import gov .va.med.im aging.stor age.cache. impl.jcifs .memento.J cifsCacheM emento; | |
| 13 | import gov .va.med.im aging.stor age.cache. impl.memen to.Persist entRegionM emento; | |
| 14 | import gov .va.med.im aging.stor age.cache. memento.Ca cheMemento ; | |
| 15 | import gov .va.med.im aging.stor age.cache. memento.Ev ictionStra tegyMement o; | |
| 16 | import gov .va.med.im aging.stor age.cache. memento.Re gionMement o; | |
| 17 | import gov .va.med.im aging.stor age.cache. timer.Evic tionTimerI mpl; | |
| 18 | ||
| 19 | import jav a.io.IOExc eption; | |
| 20 | import jav a.net.Malf ormedURLEx ception; | |
| 21 | import jav a.net.URI; | |
| 22 | import jav a.net.URL; | |
| 23 | import jav a.util.Arr ayList; | |
| 24 | import jav a.util.Lis t; | |
| 25 | ||
| 26 | import jci fs.smb.Smb Exception; | |
| 27 | import jci fs.smb.Smb File; | |
| 28 | ||
| 29 | import org .apache.lo gging.log4 j.LogManag er; | |
| 30 | import org .apache.lo gging.log4 j.Logger; | |
| 31 | ||
| 32 | /** | |
| 33 | * @author
|
|
| 34 | * | |
| 35 | */ | |
| 36 | public cla ss JcifsCa che | |
| 37 | extends Ab stractCach eImpl | |
| 38 | implements Cache | |
| 39 | { | |
| 40 | pu blic final static St ring proto col = "smb "; | |
| 41 | pr ivate Logg er logger = LogManag er.getLogg er(this.ge tClass()); | |
| 42 | pr ivate URL smbLocatio nUrl; // the root location a s a valid SMB format ted URL | |
| 43 | pr ivate SmbF ile rootDi rectory; | |
| 44 | pr ivate Stri ng host; | |
| 45 | pr ivate int port; | |
| 46 | pr ivate Stri ng userId; | |
| 47 | pr ivate Stri ng userPwd ; | |
| 48 | pr ivate Stri ng file; | |
| 49 | ||
| 50 | st atic | |
| 51 | { | |
| 52 | // r egister th e SMB URL handler | |
| 53 | jcif s.Config.r egisterSmb URLHandler (); | |
| 54 | ||
| 55 | LogM anager.get Logger(Jci fsCache.cl ass).info( "Registere d protocol handlers are '" + S ystem.getP roperty("j ava.protoc ol.handler .pkgs") + "'."); | |
| 56 | } | |
| 57 | ||
| 58 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ======== | |
| 59 | // Create (f actory) me thods | |
| 60 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ======== | |
| 61 | /* * | |
| 62 | * | |
| 63 | * @param na me | |
| 64 | * @param lo cationUri | |
| 65 | * @return | |
| 66 | * @throws C acheExcept ion | |
| 67 | * / | |
| 68 | pu blic stati c JcifsCac he create( String nam e, URI loc ationUri) | |
| 69 | th rows Cache Exception | |
| 70 | { | |
| 71 | Jcif sCacheConf igurator c onfigurato r = new Jc ifsCacheCo nfigurator (); | |
| 72 | Evic tionTimerI mpl evicti onTimer = EvictionTi merImpl.cr eate(confi gurator.ge tEvictionT imerSweepI ntervalMap ()); | |
| 73 | ||
| 74 | retu rn new Jci fsCache(na me, locati onUri, evi ctionTimer , JcifsByt eChannelFa ctory.crea te()); | |
| 75 | } | |
| 76 | ||
| 77 | /* * | |
| 78 | * | |
| 79 | * @param na me | |
| 80 | * @param lo cationUri | |
| 81 | * @param ev ictionTime r | |
| 82 | * @return | |
| 83 | * @throws C acheExcept ion | |
| 84 | * / | |
| 85 | pu blic stati c JcifsCac he create( String nam e, URI loc ationUri, EvictionTi mer evicti onTimer) | |
| 86 | th rows Cache Exception | |
| 87 | { | |
| 88 | retu rn new Jci fsCache(na me, locati onUri, evi ctionTimer , JcifsByt eChannelFa ctory.crea te()); | |
| 89 | } | |
| 90 | ||
| 91 | /* * | |
| 92 | * | |
| 93 | * @param me mento | |
| 94 | * @return | |
| 95 | * @throws C acheExcept ion | |
| 96 | * / | |
| 97 | pu blic stati c JcifsCac he create( CacheMemen to memento ) | |
| 98 | th rows Cache Exception | |
| 99 | { | |
| 100 | retu rn new Jci fsCache(me mento); | |
| 101 | } | |
| 102 | ||
| 103 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ======== | |
| 104 | // Construct ors, note that they are all pr ivate, use the facto ry methods to create instances . | |
| 105 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ======== | |
| 106 | pr ivate Jcif sCache(Str ing name, URI locati onUri, Evi ctionTimer evictionT imer, Inst anceByteCh annelFacto ry<SmbFile > byteChan nelFactory ) | |
| 107 | th rows Cache Exception | |
| 108 | { | |
| 109 | supe r(name, lo cationUri, evictionT imer, byte ChannelFac tory); | |
| 110 | } | |
| 111 | ||
| 112 | pr ivate Jcif sCache(Cac heMemento memento) | |
| 113 | th rows Cache Exception | |
| 114 | { | |
| 115 | supe r(memento) ; | |
| 116 | ||
| 117 | if ( memento in stanceof J cifsCacheM emento) | |
| 118 | restor eFromMemen to((JcifsC acheMement o) memento ); | |
| 119 | } | |
| 120 | ||
| 121 | @O verride | |
| 122 | pr otected vo id parseLo cationUri( URI locati onUri) | |
| 123 | th rows Cache Initializa tionExcept ion | |
| 124 | { | |
| 125 | // T he primary reason we parse the locationU ri is to h ave some a ssurance | |
| 126 | // t hat it is valid and log some m essages as to where the cache lives. | |
| 127 | // W e should n ot log the entire lo cationUri as it may include | |
| 128 | // t he user ID and passw ord. | |
| 129 | try | |
| 130 | { | |
| 131 | smbLoc ationUrl = locationU ri.toURL() ; | |
| 132 | if(smb LocationUr l.getUserI nfo() != n ull) | |
| 133 | { | |
| 134 | String[] userInfo = smbLocat ionUrl.get UserInfo() .split(":" ); | |
| 135 | userId = userInfo .length > 0 ? userIn fo[0] : nu ll; | |
| 136 | userPwd = userInf o.length > 1 ? userI nfo[1] : n ull; | |
| 137 | } | |
| 138 | ||
| 139 | host = smbLocati onUrl.getH ost(); | |
| 140 | port = smbLocati onUrl.getP ort(); | |
| 141 | file = smbLocati onUrl.getF ile(); | |
| 142 | ||
| 143 | if(hos t == null) | |
| 144 | throw ne w CacheIni tializatio nException ( | |
| 145 | "The given location URI '" + l ocationUri .toString( ) + "' doe s not incl ude a host name." | |
| 146 | ); | |
| 147 | ||
| 148 | if(fil e == null) | |
| 149 | throw ne w CacheIni tializatio nException ( | |
| 150 | "The given location URI '" + l ocationUri .toString( ) + "' doe s not incl ude a file (share)." | |
| 151 | ); | |
| 152 | ||
| 153 | LogMan ager.getLo gger(Jcifs Cache.clas s).info("S MB Locatio n URL pars ed as foll ows: userI d='" + use rId + | |
| 154 | "', userPw d is " + ( userPwd == null ? "n ull" : "no t null") + | |
| 155 | " host='" + host + | |
| 156 | "' port='" + port + | |
| 157 | "' file='" + file + "'"); | |
| 158 | ||
| 159 | if( fi le.lastInd exOf('/') != file.le ngth()-1 ) | |
| 160 | throw ne w CacheIni tializatio nException ( | |
| 161 | "The given location URI '" + l ocationUri .toString( ) + "' doe s not end with a sha re name an d it must. The URI must end w ith a alas h characte r '/' to b e valid." | |
| 162 | ); | |
| 163 | ||
| 164 | } | |
| 165 | catc h (Malform edURLExcep tion x) | |
| 166 | { | |
| 167 | logger .error(x); | |
| 168 | throw new CacheI nitializat ionExcepti on( | |
| 169 | "Unable to parse the location URI '" + l ocationUri .toString( ) + "' int o a valid SMB URL.\n " + | |
| 170 | "The corre ct syntax is 'smb:// [[[domain; ]username[ :password] @]server[: port]/[[sh are/[dir/] file]]][?[ param=valu e[param2=v alue2[...] ]]'\n" + | |
| 171 | "A complet e descript ion of the format ma y be found at http:/ /jcifs.sam ba.org/src /docs/api/ jcifs/smb/ SmbFile.ht ml \n", | |
| 172 | x); | |
| 173 | } | |
| 174 | } | |
| 175 | ||
| 176 | pu blic URL g etSmbLocat ionUrl() | |
| 177 | { | |
| 178 | retu rn this.sm bLocationU rl; | |
| 179 | } | |
| 180 | ||
| 181 | pu blic SmbFi le getRoot Directory( ) | |
| 182 | th rows Cache StateExcep tion | |
| 183 | { | |
| 184 | // C heck wheth er the roo tDirectory has been set rather than whet her the ca che has be en initial ized | |
| 185 | // b ecause, in ternally, this metho d must ret urn the ro ot directo ry before initializa tion is co mplete. | |
| 186 | // E xternally, isInitial ized() and the exist ence of a non-null r oot direct ory are ne arly synon omous. | |
| 187 | if( rootDirect ory == nul l ) | |
| 188 | throw new CacheS tateExcept ion("JCIFS Cache mus t be initi alized bef ore the ro ot directo ry is avai lable."); | |
| 189 | ||
| 190 | retu rn rootDir ectory; | |
| 191 | } | |
| 192 | ||
| 193 | pr ivate void setRootDi rectory(Sm bFile root Directory) | |
| 194 | { | |
| 195 | this .rootDirec tory = roo tDirectory ; | |
| 196 | } | |
| 197 | ||
| 198 | @O verride | |
| 199 | pu blic void internalIn itialize() | |
| 200 | th rows Initi alizationE xception, CacheState Exception | |
| 201 | { | |
| 202 | try | |
| 203 | { | |
| 204 | SmbFil e root = n ew SmbFile (getSmbLoc ationUrl() ); | |
| 205 | //Ntlm PasswordAu thenticati on ntPassA uth = new NtlmPasswo rdAuthenti cation(nul l, "jcifs" , "Raptor9 99"); | |
| 206 | //SmbF ile root = new SmbFi le("smb:// jcifs:Rapt or999@Isw- beckeyc/jc ifs-cache/ "); | |
| 207 | ||
| 208 | root.c onnect(); | |
| 209 | ||
| 210 | if( ! root.exist s() ) | |
| 211 | throw ne w CacheIni tializatio nException ("Cache ro ot '" + ge tSmbLocati onUrl().to ExternalFo rm() + "' does not e xist."); | |
| 212 | ||
| 213 | if( ! root.canRe ad() ) | |
| 214 | throw ne w CacheIni tializatio nException ("Cache ro ot '" + ge tSmbLocati onUrl().to ExternalFo rm() + "' exists but is not re adable."); | |
| 215 | ||
| 216 | // the directory reports b ack as un- writable r egardless of whether we can wr ite to it | |
| 217 | //if( ! root.can Write() ) | |
| 218 | // throw ne w CacheIni tializatio nException ("Cache ro ot '" + ge tSmbLocati onUrl().to ExternalFo rm() + "' exists but is not wr itable."); | |
| 219 | ||
| 220 | if( ! root.isDir ectory() ) | |
| 221 | throw ne w CacheIni tializatio nException ("Cache ro ot '" + ge tSmbLocati onUrl().to ExternalFo rm() + "' exists but is not a directory. "); | |
| 222 | ||
| 223 | logger .info( "'" + getSmbL ocationUrl ().toExter nalForm() + " has " + root.get DiskFreeSp ace() + " bytes free ." ); | |
| 224 | ||
| 225 | setRoo tDirectory (root); // i f everythi ng works t hen set th e root dir ectory | |
| 226 | } | |
| 227 | catc h (SmbExce ption x) | |
| 228 | { | |
| 229 | logger .error(x); | |
| 230 | throw new CacheI nitializat ionExcepti on("Unable to access the cache root '" + getSmbLoc ationUrl() .toExterna lForm() + "'.", x); | |
| 231 | } | |
| 232 | catc h (IOExcep tion x) | |
| 233 | { | |
| 234 | logger .error(x); | |
| 235 | throw new CacheI nitializat ionExcepti on("Unable to connec t to root '" + getSm bLocationU rl().toExt ernalForm( ) + "'.", x); | |
| 236 | } | |
| 237 | } | |
| 238 | ||
| 239 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ===== | |
| 240 | // | |
| 241 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ===== | |
| 242 | ||
| 243 | /* | |
| 244 | * (non-Java doc) | |
| 245 | * | |
| 246 | * @see gov. va.med.ima ging.stora ge.cache.i mpl.Abstra ctCacheImp l#createRe gion(java. lang.Strin g) | |
| 247 | * / | |
| 248 | @O verride | |
| 249 | pu blic Regio n createRe gion(Strin g name, St ring[] evi ctionStrat egyNames) | |
| 250 | th rows Regio nInitializ ationExcep tion | |
| 251 | { | |
| 252 | Jcif sRegion re gion = Jci fsRegion.c reate(this , name, ev ictionStra tegyNames, defaultSe condsReadW aitsForWri teCompleti on, defaul tSetModifi cationTime OnRead); | |
| 253 | ||
| 254 | retu rn region; | |
| 255 | } | |
| 256 | ||
| 257 | /* | |
| 258 | * (non-Java doc) | |
| 259 | * | |
| 260 | * @see gov. va.med.ima ging.stora ge.cache.i mpl.Abstra ctCacheImp l#createRe gion(gov.v a.med.imag ing.storag e.cache.me mento.Regi onMemento) | |
| 261 | * / | |
| 262 | @O verride | |
| 263 | pu blic Regio n createRe gion(Regio nMemento r egionMemen to) | |
| 264 | th rows Regio nInitializ ationExcep tion | |
| 265 | { | |
| 266 | if(r egionMemen to instanc eof Persis tentRegion Memento) | |
| 267 | return JcifsRegi on.create( this, (Per sistentReg ionMemento )regionMem ento); | |
| 268 | ||
| 269 | thro w new Regi onInitiali zationExce ption("Giv en region memento of type '" + regionMem ento.getCl ass().getN ame() + "' cannot be used to c onstruct a JCIFS Reg ion"); | |
| 270 | } | |
| 271 | ||
| 272 | /* | |
| 273 | * (non-Java doc) | |
| 274 | * | |
| 275 | * @see gov. va.med.ima ging.stora ge.cache.i mpl.Abstra ctCacheImp l#validate RegionType (gov.va.me d.imaging. storage.ca che.Region ) | |
| 276 | * / | |
| 277 | @O verride | |
| 278 | pr otected vo id validat eRegionTyp e(Region r egion) | |
| 279 | th rows Incom patibleReg ionExcepti on | |
| 280 | { | |
| 281 | if(! (region i nstanceof JcifsRegio n) ) | |
| 282 | throw new Incomp atibleRegi onExceptio n("Region of type '" + region. getClass() .getName() + "' is i ncompatibl e with cah e of type '"+ this.g etClass(). getName() + "'."); | |
| 283 | } | |
| 284 | ||
| 285 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ===== | |
| 286 | // | |
| 287 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ===== | |
| 288 | ||
| 289 | /* * | |
| 290 | * @see gov. va.med.ima ging.stora ge.cache.i mpl.Abstra ctCacheImp l#createMe mento() | |
| 291 | * / | |
| 292 | @O verride | |
| 293 | pu blic Cache Memento cr eateMement o() | |
| 294 | { | |
| 295 | Jcif sCacheMeme nto mement o = new Jc ifsCacheMe mento(); | |
| 296 | ||
| 297 | meme nto.setEvi ctionTimer Memento(de faultEvict ionTimer.c reateMemen to()); | |
| 298 | ||
| 299 | meme nto.setNam e(getName( )); | |
| 300 | meme nto.setLoc ationUri(g etLocation Uri().toSt ring()); | |
| 301 | meme nto.setEna bled(isEna bled()); | |
| 302 | meme nto.setIni tialized(i sInitializ ed()); | |
| 303 | ||
| 304 | if(g etInstance ByteChanne lFactory() instanceo f JcifsByt eChannelFa ctory) | |
| 305 | mement o.setByteC hannelFact oryMemento ( ((Jcifs ByteChanne lFactory)g etInstance ByteChanne lFactory() ).createMe mento() ); | |
| 306 | meme nto.setEvi ctionStrat egyMemento s(createEv ictionStra tegyMement os()); | |
| 307 | meme nto.setReg ionMemento s(createRe gionMement os()); | |
| 308 | ||
| 309 | retu rn memento ; | |
| 310 | } | |
| 311 | ||
| 312 | pr otected Li st<LastAcc essedEvict ionStrateg yMemento> createEvic tionStrate gyMementos () | |
| 313 | { | |
| 314 | List <LastAcces sedEvictio nStrategyM emento> ev ictionStra tegyMement os = new A rrayList<L astAccesse dEvictionS trategyMem ento>(); | |
| 315 | for( EvictionSt rategy evi ctionStrat egy:getEvi ctionStrat egies()) | |
| 316 | { | |
| 317 | if(evi ctionStrat egy instan ceof LastA ccessedEvi ctionStrat egy) | |
| 318 | eviction StrategyMe mentos.add ( ((LastAc cessedEvic tionStrate gy)evictio nStrategy) .createMem ento() ); | |
| 319 | else | |
| 320 | logger.e rror("An e viction st rategy of type '" + evictionSt rategy.get Class().ge tName() + "' was enc ountered.\ n" + | |
| 321 | "C onfigurati on persist ence of th is class i n unknown. "); | |
| 322 | } | |
| 323 | retu rn evictio nStrategyM ementos; | |
| 324 | } | |
| 325 | ||
| 326 | pr otected Li st<Persist entRegionM emento> cr eateRegion Mementos() | |
| 327 | { | |
| 328 | List <Persisten tRegionMem ento> regi onMementos = new Arr ayList<Per sistentReg ionMemento >(); | |
| 329 | for( Region reg ion:getReg ions()) | |
| 330 | region Mementos.a dd( (Persi stentRegio nMemento)r egion.crea teMemento( ) ); | |
| 331 | ||
| 332 | retu rn regionM ementos; | |
| 333 | } | |
| 334 | ||
| 335 | /* * | |
| 336 | * The cache must be re stored fro m a mement o in the f ollowing o rder: | |
| 337 | * 0.) the d efault evi ction time r | |
| 338 | * 1.) root directory name | |
| 339 | * 2.) insta nce byte c hannel | |
| 340 | * 3.) evict ion strate gies | |
| 341 | * 4.) regio ns (needs instance b yte channe l and evic tion strat egies) | |
| 342 | * 5.) initi alized fla g | |
| 343 | * 6.) enabl ed flag | |
| 344 | * 7.) the S TART signa l may be a cted upon, sending t he START i s the resp onsibility of | |
| 345 | * the F ileSystemC acheManage r | |
| 346 | * | |
| 347 | * @param me mento | |
| 348 | * / | |
| 349 | pr ivate void restoreFr omMemento( JcifsCache Memento me mento) | |
| 350 | th rows Cache Exception | |
| 351 | { | |
| 352 | // r estore the byte chan nel factor y | |
| 353 | setI nstanceByt eChannelFa ctory( Jci fsByteChan nelFactory .create(me mento.getB yteChannel FactoryMem ento()) ); | |
| 354 | ||
| 355 | for( EvictionS trategyMem ento evict ionStrateg yMemento:m emento.get EvictionSt rategyMeme ntos() ) | |
| 356 | { | |
| 357 | Evicti onStrategy evictionS trategy = | |
| 358 | Eviction StrategyFa ctory.getS ingleton() .createEvi ctionStrat egy(evicti onStrategy Memento, d efaultEvic tionTimer) ; | |
| 359 | addEvi ctionStrat egy(evicti onStrategy ); | |
| 360 | } | |
| 361 | ||
| 362 | for( RegionMeme nto region Memento:me mento.getR egionMemen tos()) | |
| 363 | { | |
| 364 | if(reg ionMemento instanceo f Persiste ntRegionMe mento) | |
| 365 | { | |
| 366 | JcifsReg ion region = JcifsRe gion.creat e( | |
| 367 | this, | |
| 368 | (Persisten tRegionMem ento)regio nMemento | |
| 369 | ); | |
| 370 | addRegio n(region); | |
| 371 | } | |
| 372 | } | |
| 373 | ||
| 374 | // n ote that s et initial ized to tr ue is much more than a simple bit flip | |
| 375 | if(m emento.isI nitialized ()) | |
| 376 | setIni tialized(t rue); | |
| 377 | // s etting ena bled to tr ue is pret ty much a simple bit flip | |
| 378 | if(m emento.isE nabled()) | |
| 379 | setEna bled(true) ; | |
| 380 | } | |
| 381 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.