Produced by Araxis Merge on 10/18/2018 2:02:17 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\DataSourceServiceProvider\main\src\java\gov\va\med\imaging\datasource | VersionableServiceProviderFactory.java | Thu Oct 11 13:30:13 2018 UTC |
2 | VIX_SIV_v3_0_patch_201_build_8.zip\v3.0_patch_201_build_8\VISA\Java\DataSourceServiceProvider\main\src\java\gov\va\med\imaging\datasource | VersionableServiceProviderFactory.java | Wed Oct 17 18:47:39 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 2 | 1094 |
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.dat asource; | |
5 | ||
6 | import gov .va.med.im aging.Date Util; | |
7 | import gov .va.med.im aging.arti factsource .ArtifactS ource; | |
8 | import gov .va.med.im aging.arti factsource .ResolvedA rtifactSou rce; | |
9 | import gov .va.med.im aging.core .interface s.DataSour ceExceptio nHandler; | |
10 | import gov .va.med.im aging.core .interface s.exceptio ns.Configu rationErro r; | |
11 | import gov .va.med.im aging.core .interface s.exceptio ns.Connect ionExcepti on; | |
12 | import gov .va.med.im aging.data source.exc eptions.No ValidServi ceConstruc torError; | |
13 | import jav a.lang.ref lect.Invoc ationTarge tException ; | |
14 | import jav a.util.Has hMap; | |
15 | import jav a.util.Map ; | |
16 | import jav a.util.Sor tedSet; | |
17 | ||
18 | import org .apache.lo gging.log4 j.Level; | |
19 | ||
20 | /** | |
21 | * | |
22 | * @author PII | |
23 | * | |
24 | * @param <T> | |
25 | */ | |
26 | class Vers ionableSer viceProvid erFactory< T extends Versionabl eDataSourc eSpi> | |
27 | extends Se rviceProvi derFactory <T> | |
28 | { | |
29 | pr ivate fina l static i nt maximum Connection ExceptionR etryCount = 3; | |
30 | ||
31 | // the facto ry methods can look like eithe r: | |
32 | // public st atic <S ex tends Data SourceSpi> S create( | |
33 | // Class<S> dataSource Class, Res olvedArtif actSource artifactSo urce, Stri ng protoco l | |
34 | // ) | |
35 | // -or- | |
36 | // public st atic <S ex tends Data SourceSpi> S create( | |
37 | // ResolvedA rtifactSou rce artifa ctSource, String pro tocol | |
38 | // ) | |
39 | ||
40 | pu blic final static Cl ass<?>[] R EQUIRED_TY PEDCREATE_ METHOD_TYP ES = new C lass[] | |
41 | { Class.clas s, Resolve dArtifactS ource.clas s, String. class }; | |
42 | pu blic final static Cl ass<?>[] R EQUIRED_CR EATE_METHO D_TYPES = new Class[ ] | |
43 | { ResolvedAr tifactSour ce.class, String.cla ss }; | |
44 | pu blic final static Cl ass<?>[] R EQUIRED_CO NSTRUCTOR_ TYPES = ne w Class[] | |
45 | { ResolvedAr tifactSour ce.class, String.cla ss }; | |
46 | ||
47 | /* * | |
48 | * | |
49 | * @param pa rentProvid er | |
50 | * @param fa ctoryServi ceType | |
51 | * / | |
52 | Ve rsionableS erviceProv iderFactor y(Provider parentPro vider, Cla ss<? exten ds Version ableDataSo urceSpi> s piType) | |
53 | { | |
54 | supe r(parentPr ovider, sp iType); | |
55 | } | |
56 | ||
57 | pu blic T cre ateDataSou rce( | |
58 | Reso lvedArtifa ctSource r esolvedArt ifactSourc e, | |
59 | Stri ng protoco l, | |
60 | Data SourceExce ptionHandl er... data SourceExce ptionHandl ers) | |
61 | th rows Conne ctionExcep tion | |
62 | { | |
63 | if(r esolvedArt ifactSourc e == null || protoco l == null) | |
64 | throw new Illega lArgumentE xception(" Both the R esolvedArt ifactSourc e and the protocol m ust be pro vided to c reate a da ta source. "); | |
65 | ||
66 | // c heck the c ache here to see if we know wh at protoco l version that | |
67 | // t his | |
68 | // U RL speaks | |
69 | Prov iderServic e cachedSe rvice = ge tCachedPro viderServi ce(resolve dArtifactS ource, pro tocol); | |
70 | ||
71 | if ( cachedServ ice != nul l) | |
72 | { | |
73 | Provid er.logger. debug("Fou nd cached Service fo r " + getP roductType Name() + " provider using prot ocol '" + protocol + "' access ing '" + | |
74 | (resolve dArtifactS ource == n ull ? "no ResolvedAr tifactSour ce" : reso lvedArtifa ctSource.t oString()) + | |
75 | "'."); | |
76 | T data Source = c reateDataS ourceInsta nce(resolv edArtifact Source, pr otocol, ca chedServic e); | |
77 | Provid er.logger. info("Crea ted DataSo urce provi der access ing '" + | |
78 | (resolve dArtifactS ource == n ull ? "no ResolvedAr tifactSour ce" : reso lvedArtifa ctSource.t oString()) + | |
79 | "'."); | |
80 | ||
81 | return dataSourc e; | |
82 | } | |
83 | else | |
84 | { | |
85 | Provid er.logger. info("Crea ting " + g etProductT ypeName() + " provid er using p rotocol '" + protoco l + "' acc essing '" | |
86 | + (resol vedArtifac tSource == null ? "n o Resolved ArtifactSo urce" : re solvedArti factSource .toString( )) + "'.") ; | |
87 | Sorted Set<Provid erService> services = getParen tProvider( ).findProv iderServic es(this.ge tSpiType() , protocol ); | |
88 | Provid er.logger. info(getPr oductTypeN ame() + ", the numbe r of poten tial servi ce impleme ntations i s " | |
89 | + (servi ces == nul l ? "none" : service s.size()) + "'."); | |
90 | if (se rvices == null) | |
91 | { | |
92 | Provider .logger.in fo("Applic able servi ce impleme ntations o f type '" | |
93 | + getProdu ctTypeName () + "' fo r '" + res olvedArtif actSource. toString() | |
94 | + "' are N OT availab le."); | |
95 | ||
96 | return n ull; | |
97 | } | |
98 | ||
99 | // for each of t he Provide r.Service (service i mplementat ions) | |
100 | // fou nd | |
101 | for (P roviderSer vice servi ce : servi ces) | |
102 | { | |
103 | T dataSo urce = cre ateDataSou rceInstanc e(resolved ArtifactSo urce, prot ocol, serv ice); | |
104 | if (data Source != null) | |
105 | { | |
106 | Provider.l ogger.info ("Created " + getPro ductTypeNa me() + " p rovider ac cessing '" | |
107 | + (resolvedA rtifactSou rce == nul l ? "no UR L" : resol vedArtifac tSource.to String()) + "'."); | |
108 | ||
109 | // isVersi onCompatib le() is po tentially an expensi ve | |
110 | // operati on, | |
111 | // the Pro vider.Serv ice cachin g is imple mented to reduce | |
112 | // the nee d to call it. | |
113 | int retryC ount = 0; | |
114 | while (ret ryCount < maximumCon nectionExc eptionRetr yCount) | |
115 | { | |
116 | tr y | |
117 | { | |
118 | if ( dataSource .isVersion Compatible ()) | |
119 | { | |
120 | Provid er.logger. info("Crea ted " + ge tProductTy peName() | |
121 | + " prov ider acces sing '" + (resolvedA rtifactSou rce == nul l ? "no UR L" : resol vedArtifac tSource.to String()) | |
122 | + "' is version co mpatible." ); | |
123 | // cac he the Ser vice mappe d to the U RL | |
124 | putPro viderServi ceToCache( resolvedAr tifactSour ce, protoc ol, servic e); | |
125 | return dataSourc e; | |
126 | } | |
127 | // n ot version Compatible , break fr om while l oop | |
128 | brea k; | |
129 | } | |
130 | // can only handle con nection ba sed except ions in | |
131 | // this way | |
132 | ca tch (Conne ctionExcep tion cX) | |
133 | { | |
134 | retr yCount++; | |
135 | bool ean handle d = false; | |
136 | if ( dataSource ExceptionH andlers != null) | |
137 | { | |
138 | for (D ataSourceE xceptionHa ndler dseh : dataSou rceExcepti onHandlers ) | |
139 | { | |
140 | if (dseh .isExcepti onHandled( cX)) | |
141 | { | |
142 | if (dseh.h andleExcep tion(cX)) | |
143 | { | |
144 | ha ndled = tr ue; | |
145 | br eak; | |
146 | } | |
147 | } | |
148 | } | |
149 | } | |
150 | // i f the exce ption is n ot handled (no excep tion | |
151 | // h andler) | |
152 | // t hen simply throw the exception , don't ma ke | |
153 | // a ny retry a ttempts | |
154 | if ( !handled) | |
155 | throw cX; | |
156 | } | |
157 | } | |
158 | } | |
159 | else | |
160 | Provider.l ogger.erro r("Failed to create " + | |
161 | ge tProductTy peName() + " provide r accessin g '" | |
162 | + (resolvedA rtifactSou rce == nul l ? "no UR L" : resol vedArtifac tSource.to String()) + | |
163 | "' ."); | |
164 | } | |
165 | ||
166 | Provid er.logger. info("Appl icable ser vice imple mentations of type ' " + | |
167 | getProdu ctTypeName () + | |
168 | "' for ' " + resolv edArtifact Source.toS tring() + | |
169 | "' are a vailable b ut version s are inco mpatible." ); | |
170 | ||
171 | return null; | |
172 | } | |
173 | } | |
174 | ||
175 | /* * | |
176 | * Create an instance of the dat a source o f the requ ested type , | |
177 | * connectin g to the g iven URL. Create the instance using one of (in | |
178 | * order of preference ): public static cre ate(URL, S ite) publi c static | |
179 | * create(UR L) public ctor(URL, Site) publ ic ctor(UR L) public ctor() | |
180 | * | |
181 | * @param ur l | |
182 | * @param si te | |
183 | * @param se rvice | |
184 | * @return R eturns an instance o f the requ ested data source or throws an | |
185 | * e xception. | |
186 | * @throws C onnectionE xception | |
187 | * @throws C onfigurati onError - | |
188 | * if a se rvice impl ementation is improp erly imple mented or | |
189 | * if a se rvice impl ementation cannot be found or an | |
190 | * instanc e created then this method wil l throw a | |
191 | * Configu rationErro r, which i s an unche cked excep tion | |
192 | * / | |
193 | pr ivate T cr eateDataSo urceInstan ce( | |
194 | Reso lvedArtifa ctSource r esolvedArt ifactSourc e, | |
195 | Stri ng protoco l, | |
196 | Prov iderServic e service) | |
197 | th rows Conne ctionExcep tion | |
198 | { | |
199 | Clas s<?> imple mentingCla ss = servi ce.getImpl ementingCl ass(); | |
200 | if(i mplementin gClass == null) | |
201 | throw new Illega lArgumentE xception(" The implem enting cla ss in '" + service.t oString() + "' is nu ll and mus t not be." ); | |
202 | ||
203 | // a message f ragment us ed in many logging m essages | |
204 | Stri ng message = | |
205 | "Creat ing instan ce of " + (implement ingClass = = null ? " null" : im plementing Class.getN ame()) + " .\n" + | |
206 | "Using protocol " + protoc ol + ".\n" + | |
207 | "Acces sing " + ( resolvedAr tifactSour ce == null ? "null" : resolved ArtifactSo urce.toStr ing()) + " .\n"; | |
208 | ||
209 | T da taSource = null; | |
210 | ||
211 | try | |
212 | { | |
213 | // Ver sionableDa taSourceSP I realizat ions must implement a | |
214 | // sta tic create () method or a const ructor wit h | |
215 | // a R esolvedArt ifactSourc e and a St ring (prot ocol) para meter | |
216 | // the static cr eate metho d may also have a pa rameter th at indicat es the ser vice | |
217 | // typ e to creat e, this al lows for d ynamic pro xy impleme ntations o f | |
218 | // dat a sources. | |
219 | try | |
220 | { | |
221 | dataSour ce = creat eInstanceU singStatic CreateMeth od( | |
222 | implementi ngClass, | |
223 | service, | |
224 | REQUIRED_T YPEDCREATE _METHOD_TY PES, | |
225 | new Object []{ servic e.getSpiTy pe(), reso lvedArtifa ctSource, protocol } ); | |
226 | ||
227 | Provider .logger.lo g( | |
228 | (dataSourc e == null ? Level.ER ROR : Leve l.DEBUG), | |
229 | dataSource == null ? | |
230 | "c reate(Clas s, Resolve dArtifactS ource, Str ing) retur ned null. This is a coding err or and MUS T be addre ssed." : | |
231 | "S uccessfull y created instance o f '" + dat aSource.ge tClass().g etName() + "' using create(Cla ss, Resolv edArtifact Source, St ring)." | |
232 | ); | |
233 | } | |
234 | catch (NoSuchMet hodExcepti on nsmX1) | |
235 | { | |
236 | Provider .logger.de bug("Unabl e to creat e data sou rce provid er using c reate(Clas s, Resolve dArtifactS ource, Str ing), cont inuing..." ); | |
237 | try | |
238 | { | |
239 | dataSource = createI nstanceUsi ngStaticCr eateMethod ( | |
240 | im plementing Class, | |
241 | se rvice, | |
242 | RE QUIRED_CRE ATE_METHOD _TYPES, | |
243 | ne w Object[] { resolved ArtifactSo urce, prot ocol }); | |
244 | ||
245 | Provider.l ogger.log( | |
246 | (d ataSource == null ? Level.ERRO R : Level. DEBUG), | |
247 | da taSource = = null ? | |
248 | "cre ate(Resolv edArtifact Source, St ring) retu rned null. This is a coding er ror and MU ST be addr essed." : | |
249 | "Suc cessfully created in stance of '" + dataS ource.getC lass().get Name() + " ' using cr eate(Resol vedArtifac tSource, S tring)." | |
250 | ); | |
251 | } | |
252 | catch(No SuchMethod Exception nsmX2) | |
253 | { | |
254 | Provider.l ogger.debu g("Unable to create data sourc e provider using cre ate(Resolv edArtifact Source, St ring), con tinuing... " ); | |
255 | dataSource = createI nstanceUsi ngConstruc tor( | |
256 | im plementing Class, | |
257 | se rvice, | |
258 | RE QUIRED_CON STRUCTOR_T YPES, | |
259 | ne w Object[] { resolved ArtifactSo urce, prot ocol }); | |
260 | Provider.l ogger.debu g( | |
261 | "S uccessfull y created instance o f '" + dat aSource.ge tClass().g etName() + "' using <ctor>(Res olvedArtif actSource, String)." | |
262 | ); | |
263 | } | |
264 | } | |
265 | } | |
266 | catc h (java.la ng.Securit yException e) | |
267 | { | |
268 | Provid er.logger. error(e + message); | |
269 | throw new NoVali dServiceCo nstructorE rror(imple mentingCla ss.getName (), e); | |
270 | } | |
271 | ||
272 | // T his NoSuch MethodExce ption inst ance is th rown only after all of | |
273 | // t he potenti al instant iation met hods have been tried . | |
274 | // I n other wo rds, there is no val id service factory m ethod or | |
275 | // c onstructor . | |
276 | catc h (NoSuchM ethodExcep tion e) | |
277 | { | |
278 | Provid er.logger. error(e +" "+ messag e); | |
279 | throw new NoVali dServiceCo nstructorE rror(imple mentingCla ss.getName (), e); | |
280 | } | |
281 | catc h (Illegal ArgumentEx ception e) | |
282 | { | |
283 | Provid er.logger. error(e +" "+ messag e); | |
284 | throw new NoVali dServiceCo nstructorE rror(imple mentingCla ss.getName (), e); | |
285 | } | |
286 | catc h (Instant iationExce ption e) | |
287 | { | |
288 | Provid er.logger. error(e +" "+ messag e); | |
289 | throw new NoVali dServiceCo nstructorE rror(imple mentingCla ss.getName (), e); | |
290 | } | |
291 | catc h (Illegal AccessExce ption e) | |
292 | { | |
293 | Provid er.logger. error(e +" "+ messag e); | |
294 | throw new NoVali dServiceCo nstructorE rror(imple mentingCla ss.getName (), e); | |
295 | } | |
296 | catc h (Invocat ionTargetE xception e ) | |
297 | { | |
298 | Provid er.logger. error(e +" "+ messag e); | |
299 | // if there is a wrapped C onnectionE xception t hen unwrap it and | |
300 | // thr ow it | |
301 | // the construct ors of a s ervice imp lementatio n are expr essly | |
302 | // per mitted | |
303 | // to throw a Co nnectionEx ception | |
304 | if (e. getCause() != null & & e.getCau se() insta nceof Conn ectionExce ption) | |
305 | { | |
306 | Provider .logger.er ror(e.getC ause()); | |
307 | throw (C onnectionE xception) e.getCause (); | |
308 | } | |
309 | // If the servic e failed t o instanti ate for so me interna l reason | |
310 | // tha t is not a Connectio nException then thro w a | |
311 | // NoV alidServic eConstruct orExceptio n. | |
312 | throw new NoVali dServiceCo nstructorE rror(imple mentingCla ss.getName (), e); | |
313 | } | |
314 | // a create me thod was d efined but the retur n was not castable t o | |
315 | // t he | |
316 | // s ervice typ e requeste d | |
317 | catc h (ClassCa stExceptio n e) | |
318 | { | |
319 | Provid er.logger. error(e); | |
320 | throw new NoVali dServiceCo nstructorE rror(imple mentingCla ss.getName (), e); | |
321 | } | |
322 | ||
323 | retu rn dataSou rce; | |
324 | } | |
325 | ||
326 | // ========= ========== ========== ========== ========== ========== ========== ======== | |
327 | // Service V ersion cac hing | |
328 | // ========= ========== ========== ========== ========== ========== ========== ======== | |
329 | ||
330 | // Retains t he Resolve dArtifactS ource (whe re the req uest is be ing sent) and the | |
331 | // protocol being used . These a re the key s used to select a S PI realiza tion. | |
332 | pr ivate clas s ServiceC acheKey | |
333 | { | |
334 | priv ate final ResolvedAr tifactSour ce resolve dArtifactS ource; | |
335 | priv ate final String pro tocol; | |
336 | /** | |
337 | * @ param reso lvedArtifa ctSource | |
338 | * @ param prot ocol | |
339 | */ | |
340 | publ ic Service CacheKey(R esolvedArt ifactSourc e resolved ArtifactSo urce, Stri ng protoco l) | |
341 | { | |
342 | super( ); | |
343 | this.r esolvedArt ifactSourc e = resolv edArtifact Source; | |
344 | this.p rotocol = protocol; | |
345 | } | |
346 | publ ic Resolve dArtifactS ource getR esolvedArt ifactSourc e() | |
347 | { | |
348 | return this.reso lvedArtifa ctSource; | |
349 | } | |
350 | publ ic String getProtoco l() | |
351 | { | |
352 | return this.prot ocol; | |
353 | } | |
354 | @Ove rride | |
355 | publ ic int has hCode() | |
356 | { | |
357 | final int prime = 31; | |
358 | int re sult = 1; | |
359 | result = prime * result + getOuterTy pe().hashC ode(); | |
360 | result = prime * result | |
361 | + ((protoc ol == null ) ? 0 : pr otocol.has hCode()); | |
362 | if(res olvedArtif actSource != null) | |
363 | { | |
364 | // use t he details of the Ar tifactSour ce to crea te the has hcode | |
365 | Artifact Source art ifactSourc e = resolv edArtifact Source.get ArtifactSo urce(); | |
366 | if(artif actSource != null) | |
367 | { | |
368 | result = p rime | |
369 | * result | |
370 | + ((artifact Source.get HomeCommun ityId() == null) ? 0 | |
371 | : arti factSource .getHomeCo mmunityId( ).hashCode ()); | |
372 | result = p rime | |
373 | * result | |
374 | + ((artifa ctSource.g etReposito ryId() == null) ? 0 | |
375 | : ar tifactSour ce.getRepo sitoryId() .hashCode( )); | |
376 | } | |
377 | } | |
378 | return result; | |
379 | } | |
380 | @Ove rride | |
381 | publ ic boolean equals(Ob ject obj) | |
382 | { | |
383 | if (th is == obj) | |
384 | return t rue; | |
385 | if (ob j == null) | |
386 | return f alse; | |
387 | if (ge tClass() ! = obj.getC lass()) | |
388 | return f alse; | |
389 | Servic eCacheKey other = (S erviceCach eKey) obj; | |
390 | if (!g etOuterTyp e().equals (other.get OuterType( ))) | |
391 | return f alse; | |
392 | if (pr otocol == null) | |
393 | { | |
394 | if (othe r.protocol != null) | |
395 | return fal se; | |
396 | } | |
397 | else i f (!protoc ol.equals( other.prot ocol)) | |
398 | return f alse; | |
399 | if (re solvedArti factSource == null) | |
400 | { | |
401 | if (othe r.resolved ArtifactSo urce != nu ll) | |
402 | return fal se; | |
403 | } | |
404 | else | |
405 | { | |
406 | if(other .resolvedA rtifactSou rce == nul l) | |
407 | return fal se; | |
408 | if(resol vedArtifac tSource.ge tArtifactS ource() == null) | |
409 | { | |
410 | if(other.r esolvedArt ifactSourc e.getArtif actSource( ) != null) | |
411 | re turn false ; | |
412 | } | |
413 | else | |
414 | { | |
415 | // use the details o f the Arti factSource to determ ine equali ty | |
416 | // both ha ve Artifac tSources | |
417 | ArtifactSo urce thisA rtifactsou rce = reso lvedArtifa ctSource.g etArtifact Source(); | |
418 | ArtifactSo urce other ArtifactSo urce = oth er.resolve dArtifactS ource.getA rtifactSou rce(); | |
419 | if(thisArt ifactsourc e.getRepos itoryId() == null) | |
420 | { | |
421 | if (otherArti factSource .getReposi toryId() ! = null) | |
422 | retu rn false; | |
423 | } | |
424 | else if(!t hisArtifac tsource.ge tRepositor yId().equa ls(otherAr tifactSour ce.getRepo sitoryId() )) | |
425 | re turn false ; | |
426 | ||
427 | if(thisArt ifactsourc e.getHomeC ommunityId () == null ) | |
428 | { | |
429 | if (otherArti factSource .getHomeCo mmunityId( ) != null) | |
430 | retu rn false; | |
431 | } | |
432 | else if(!t hisArtifac tsource.ge tHomeCommu nityId().e quals(othe rArtifactS ource.getH omeCommuni tyId())) | |
433 | re turn false ; | |
434 | } | |
435 | } | |
436 | return true; | |
437 | } | |
438 | priv ate Versio nableServi ceProvider Factory ge tOuterType () | |
439 | { | |
440 | return Versionab leServiceP roviderFac tory.this; | |
441 | } | |
442 | ||
443 | }; | |
444 | ||
445 | // Retains t he Provide r.Service (the servi ce descrip tion) and the time t hat | |
446 | // it was ca ched. | |
447 | pr ivate clas s ServiceV ersionCach eValue | |
448 | { | |
449 | priv ate Provid erService service; | |
450 | priv ate long p utTime = S ystem.curr entTimeMil lis(); | |
451 | ||
452 | Serv iceVersion CacheValue (ProviderS ervice ser vice) | |
453 | { | |
454 | this.s ervice = s ervice; | |
455 | } | |
456 | ||
457 | publ ic Provide rService g etService( ) | |
458 | { | |
459 | return service; | |
460 | } | |
461 | ||
462 | publ ic long ge tPutTime() | |
463 | { | |
464 | return putTime; | |
465 | } | |
466 | ||
467 | @Ove rride | |
468 | publ ic int has hCode() | |
469 | { | |
470 | final int prime = 31; | |
471 | int re sult = 1; | |
472 | result = prime * result + (int) (thi s.putTime ^ (this.pu tTime >>> 32)); | |
473 | result = prime * result + ((this.ser vice == nu ll) ? 0 : this.servi ce.hashCod e()); | |
474 | return result; | |
475 | } | |
476 | ||
477 | @Ove rride | |
478 | publ ic boolean equals(Ob ject obj) | |
479 | { | |
480 | if (th is == obj) | |
481 | return t rue; | |
482 | if (ob j == null) | |
483 | return f alse; | |
484 | if (ge tClass() ! = obj.getC lass()) | |
485 | return f alse; | |
486 | final ServiceVer sionCacheV alue other = (Servic eVersionCa cheValue) obj; | |
487 | if (th is.putTime != other. putTime) | |
488 | return f alse; | |
489 | if (th is.service == null) | |
490 | { | |
491 | if (othe r.service != null) | |
492 | return fal se; | |
493 | } | |
494 | else i f (!this.s ervice.equ als(other. service)) | |
495 | return f alse; | |
496 | return true; | |
497 | } | |
498 | } | |
499 | ||
500 | pr ivate Map< ServiceCac heKey, Ser viceVersio nCacheValu e> urlServ iceVersion Cache = | |
501 | new HashMap<Se rviceCache Key, Servi ceVersionC acheValue> (); | |
502 | pr ivate stat ic final l ong servic eCacheMaxA ge = DateU til.MILLIS ECONDS_IN_ DAY; | |
503 | ||
504 | pr ivate Prov iderServic e getCache dProviderS ervice( | |
505 | Reso lvedArtifa ctSource r esolvedArt ifactSourc e, | |
506 | Stri ng protoco l) | |
507 | { | |
508 | Serv iceCacheKe y key = ne w ServiceC acheKey(re solvedArti factSource , protocol ); | |
509 | sync hronized ( urlService VersionCac he) | |
510 | { | |
511 | Servic eVersionCa cheValue c acheElemen t = urlSer viceVersio nCache.get (key); | |
512 | if (ca cheElement == null) | |
513 | return n ull; | |
514 | ||
515 | // exp ire the ca che elemen t if it is too old | |
516 | if (Sy stem.curre ntTimeMill is() - cac heElement. getPutTime () > servi ceCacheMax Age) | |
517 | { | |
518 | urlServi ceVersionC ache.remov e(key); | |
519 | return n ull; | |
520 | } | |
521 | return cacheElem ent.getSer vice(); | |
522 | } | |
523 | } | |
524 | ||
525 | pr ivate void putProvid erServiceT oCache( | |
526 | Reso lvedArtifa ctSource r esolvedArt ifactSourc e, | |
527 | Stri ng protoco l, | |
528 | Prov iderServic e service) | |
529 | { | |
530 | Serv iceCacheKe y key = ne w ServiceC acheKey(re solvedArti factSource , protocol ); | |
531 | ||
532 | sync hronized ( urlService VersionCac he) | |
533 | { | |
534 | urlSer viceVersio nCache.put (key, new ServiceVer sionCacheV alue(servi ce)); | |
535 | } | |
536 | } | |
537 | ||
538 | /* * | |
539 | * | |
540 | * / | |
541 | pu blic void clearProvi derService Cache() | |
542 | { | |
543 | sync hronized(u rlServiceV ersionCach e) | |
544 | { | |
545 | urlSer viceVersio nCache.cle ar(); | |
546 | } | |
547 | } | |
548 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.