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