Produced by Araxis Merge on 8/1/2019 1:42:43 PM Eastern 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 | JLV_2_8_0_0_0_July_2019.zip\JLV_2_8_0_0_0_July_2019\jMeadows\src\main\java\gov\va\med\jmeadows\dao\util | MultiLocationQuery.java | Mon Jul 8 19:18:52 2019 UTC |
2 | JLV_2_8_0_0_0_July_2019.zip\JLV_2_8_0_0_0_July_2019\jMeadows\src\main\java\gov\va\med\jmeadows\dao\util | MultiLocationQuery.java | Wed Jul 31 18:41:36 2019 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 2 | 714 |
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 | * Janus 4 .0 (c) | |
3 | * Copyrig ht (c) 201 1 Hawaii R esource Gr oup LLC. A ll Rights Reserved. | |
4 | * Develop ed for the Pacific T elehealth & Technolo gy Hui and the Pacif ic Joint I nformation Technolog y Center | |
5 | * Contrib utors: | |
6 | * Hon orable Sen ator Danie l K. Inouy e | |
7 | * VA Pacific Is lands Heal th Care Sy stem | |
8 | * Tri pler Army Medical Ce nter | |
9 | */ | |
10 | ||
11 | ||
12 | package go v.va.med.j meadows.da o.util; | |
13 | ||
14 | import gov .va.med.jm eadows.com mon.AppCon fig; | |
15 | import gov .va.med.jm eadows.com mon.JMeado wsExceptio n; | |
16 | import gov .va.med.jm eadows.dao .beans.JMe adowsQuery ; | |
17 | import gov .va.med.jm eadows.dao .beans.JMe dResultCol lection; | |
18 | import gov .va.med.jm eadows.dao .beans.Lab QueryRespo nse; | |
19 | import gov .va.med.jm eadows.sma rtbeans.pa tient.Smar tBean; | |
20 | import gov .va.med.vd s.webservi ce.Interfa ceStatus; | |
21 | import org .slf4j.Log ger; | |
22 | import org .slf4j.Log gerFactory ; | |
23 | ||
24 | import jav a.util.*; | |
25 | import jav a.util.con current.Ex ecutionExc eption; | |
26 | import jav a.util.con current.Ex ecutorServ ice; | |
27 | import jav a.util.con current.Fu ture; | |
28 | import jav a.util.con current.Ti meUnit; | |
29 | ||
30 | /** | |
31 | * | |
32 | * @author DNS | |
33 | */ | |
34 | public cla ss MultiLo cationQuer y { | |
35 | privat e final st atic int M AX_THREAD_ POOL_SIZE = 7; | |
36 | ||
37 | privat e final st atic AppCo nfig APP_C ONFIG = Ap pConfig.ge tInstance( ); | |
38 | // priv ate static final Str ing AGENCY _VA = APP_ CONFIG.get AgencyVA() ; | |
39 | // priv ate static final Str ing AGENCY _DOD = APP _CONFIG.ge tAgencyDOD (); | |
40 | privat e static f inal long THREAD_TIM EOUT_MS = APP_CONFIG .getThread TimeoutMS( ); | |
41 | // priv ate static final Str ing SITE_U NKNOWN = " Unknown"; | |
42 | ||
43 | privat e final st atic Logge r LOGGER = LoggerFac tory.getLo gger(Multi LocationQu ery.class) ; | |
44 | ||
45 | ||
46 | /** | |
47 | * Exe cutes mult i-location data quer ies. | |
48 | * @pa ram queryL ocCfgs Lis t of locat ion query configurat ions. | |
49 | * @pa ram smartB ean SmartB ean shared by the qu ery config urations. | |
50 | * @pa ram queryB ean Webser vice query bean | |
51 | * @re turn A lis t of datab ean result s. | |
52 | */ | |
53 | public static Ob ject[] exe cute(List< MultiLocat ionQueryCo nfig> quer yLocCfgs, | |
54 | SmartBea n smartBea n, JMeadow sQuery que ryBean) th rows JMead owsExcepti on { | |
55 | Ob ject[] rtc ; | |
56 | if (queryLoc Cfgs == nu ll || quer yLocCfgs.i sEmpty()) { | |
57 | LOGGER.d ebug("List of query configs if null or e mpty"); | |
58 | ||
59 | //bail i f query lo cations co nfigs is n ull or emp ty | |
60 | rtc = nu ll; | |
61 | } else { | |
62 | ||
63 | if (LOGG ER.isDebug Enabled()) { | |
64 | LOGG ER.debug(" queryLocCf gs ({})", queryLocCf gs.size()) ; | |
65 | } | |
66 | ||
67 | //setup thread and thread ex ecution ar rays | |
68 | List<Mul tiLocation QueryThrea d> dataQue ryThreads = new Arra yList<Mult iLocationQ ueryThread >(); | |
69 | ||
70 | //genera te query t hreads for each loca tion | |
71 | for (Mul tiLocation QueryConfi g config : queryLocC fgs) { | |
72 | data QueryThrea ds.add(new MultiLoca tionQueryT hread(conf ig, smartB ean)); | |
73 | } | |
74 | ||
75 | LinkedHa shMap<Loca tion, Obje ct> dataBe ansMap = n ew LinkedH ashMap<Loc ation, Obj ect>(); | |
76 | ||
77 | ||
78 | Executor Service ex ecutorServ ice = Thre adPoolMana ger.getIns tance().ge tThreadPoo l(); | |
79 | ||
80 | try { | |
81 | List <Future<Ob ject>> fut ures = exe cutorServi ce.invokeA ll(dataQue ryThreads, THREAD_TI MEOUT_MS, TimeUnit.M ILLISECOND S); | |
82 | ||
83 | //fu tures are returned i n the same sequentia l order as produced by the ite rator for the given task list. | |
84 | Iter ator<Multi LocationQu eryThread> queryThre adItr = da taQueryThr eads.itera tor(); | |
85 | Iter ator<Futur e<Object>> futuresIt r = future s.iterator (); | |
86 | ||
87 | whil e (queryTh readItr.ha sNext() && futuresIt r.hasNext( )) { | |
88 | MultiLocat ionQueryTh read query Thread = q ueryThread Itr.next() ; | |
89 | Future<Obj ect> futur e = future sItr.next( ); | |
90 | handleQuer y(queryThr ead, futur e, dataBea nsMap, sma rtBean); | |
91 | } | |
92 | ||
93 | //in it return object arr ay | |
94 | Obje ct[] retur nVal = nul l; | |
95 | ||
96 | //us e smart be an to comb ine data f rom each l ocation | |
97 | for (Object en try : data BeansMap.e ntrySet()) { | |
98 | Object[] d ataBeanLis t = (Objec t[]) ((Map .Entry) en try).getVa lue(); | |
99 | returnVal = smartBea n.combineD ata(return Val, dataB eanList, q ueryBean.g etSortBy() ); | |
100 | } | |
101 | ||
102 | //Li mit return Val by max , if max i s set | |
103 | if ( returnVal == null || queryBean .getMax() == null) { | |
104 | rtc = retu rnVal; | |
105 | } el se { | |
106 | if (return Val.length <= queryB ean.getMax ()) { | |
107 | rtc = returnVal; | |
108 | } else { | |
109 | Object [] maxRetV al = new O bject[quer yBean.getM ax()]; | |
110 | System .arraycopy (returnVal , 0, maxRe tVal, 0, q ueryBean.g etMax()); | |
111 | rtc = maxRetVal; | |
112 | } | |
113 | } | |
114 | ||
115 | } catch (Interrupt edExceptio n e) { | |
116 | thro w new JMea dowsExcept ion(e); | |
117 | } | |
118 | } | |
119 | re turn rtc; | |
120 | } | |
121 | ||
122 | privat e static v oid handle Query(Mult iLocationQ ueryThread queryThre ad, Future <Object> f uture, Lin kedHashMap <Location, Object> d ataBeansMa p, SmartBe an smartBe an) throws Interrupt edExceptio n { | |
123 | Ob ject[] res ult = null ; | |
124 | ||
125 | tr y { | |
126 | if (futu re.isCance lled()) { | |
127 | Mult iLocationQ ueryConfig queryConf ig = query Thread.get QueryConfi g(); | |
128 | resu lt = smart Bean.gener ateConnect ionUnavail ableBean( | |
129 | queryC onfig.getL ocation(), | |
130 | queryC onfig.getC onnectionE rrorMsg()) ; | |
131 | ||
132 | //lo g connecti on timeout | |
133 | Stri ngBuilder errorMsg = new Strin gBuilder() ; | |
134 | erro rMsg.appen d("MultiLo cationQuer yThread ti meout. Thr ead wait t ime exceed ed "); | |
135 | erro rMsg.appen d(THREAD_T IMEOUT_MS) ; | |
136 | erro rMsg.appen d("ms"); | |
137 | LOGG ER.error(e rrorMsg.to String(), new JMeado wsExceptio n(errorMsg .toString( ))); | |
138 | } else { | |
139 | resu lt = (Obje ct[]) futu re.get(); | |
140 | } | |
141 | ||
142 | MultiLoc ationQuery Config con fig = quer yThread.ge tQueryConf ig(); | |
143 | ||
144 | //add re sult to da tabean loc ation map | |
145 | if (resu lt != null ) { | |
146 | Obje ct[] newRe sult; | |
147 | //if previous result exi sts for lo cation, co mbine it w ith return ing result set | |
148 | ||
149 | Loca tion locat ionKey; | |
150 | ||
151 | loca tionKey = config.get Location() ; | |
152 | ||
153 | Obje ct[] prevR esult = (O bject[]) d ataBeansMa p.get(loca tionKey); | |
154 | ||
155 | if ( prevResult == null) { | |
156 | newResult = result; | |
157 | } el se { | |
158 | ArrayList< Object> re sultList = new Array List<Objec t>(); | |
159 | resultList .addAll(Ar rays.asLis t(prevResu lt)); | |
160 | resultList .addAll(Ar rays.asLis t(result)) ; | |
161 | newResult = resultLi st.toArray (new Objec t[resultLi st.size()] ); | |
162 | } | |
163 | data BeansMap.p ut(locatio nKey, newR esult); | |
164 | } | |
165 | } catch (Exe cutionExce ption ex) { | |
166 | MultiLoc ationQuery Config con fig = quer yThread.ge tQueryConf ig(); | |
167 | ||
168 | result = smartBean .generateC onnectionU navailable Bean( | |
169 | config.get Location() , | |
170 | config.get Connection ErrorMsg() ); | |
171 | ||
172 | Location locationK ey; | |
173 | location Key = conf ig.getLoca tion(); | |
174 | ||
175 | dataBean sMap.put(l ocationKey , result); | |
176 | ||
177 | LOGGER.e rror(ex.ge tMessage() , ex); | |
178 | } | |
179 | } | |
180 | ||
181 | /** | |
182 | * Exe cutes mult i-location data quer ies. | |
183 | * @pa ram queryL ocCfgs Lis t of locat ion query configurat ions. | |
184 | * @pa ram smartB ean SmartB ean shared by the qu ery config urations. | |
185 | * @pa ram queryB ean Webser vice query bean | |
186 | * @re turn A lis t of datab ean result s. | |
187 | */ | |
188 | public static JM edResultCo llection e xecute2(Li st<MultiLo cationQuer yConfig> q ueryLocCfg s, | |
189 | Sm artBean sm artBean, J MeadowsQue ry queryBe an) throws JMeadowsE xception { | |
190 | // init retur n object a rray | |
191 | JM edResultCo llection r eturnVal = new JMedR esultColle ction(); | |
192 | ||
193 | if (queryLoc Cfgs == nu ll || quer yLocCfgs.i sEmpty()) { | |
194 | LOGGER.d ebug("List of query configs if null or e mpty"); | |
195 | ||
196 | //bail i f query lo cations co nfigs is n ull or emp ty | |
197 | returnVa l = null; | |
198 | } else { | |
199 | ||
200 | if (LOGG ER.isDebug Enabled()) { | |
201 | LOGG ER.debug(" queryLocCf gs ({})", queryLocCf gs.size()) ; | |
202 | } | |
203 | ||
204 | //setup thread and thread ex ecution ar rays | |
205 | List<Mul tiLocation QueryThrea d> dataQue ryThreads = new Arra yList<Mult iLocationQ ueryThread >(); | |
206 | ||
207 | //genera te query t hreads for each loca tion | |
208 | for (Mul tiLocation QueryConfi g config : queryLocC fgs) { | |
209 | data QueryThrea ds.add(new MultiLoca tionQueryT hread(conf ig, smartB ean)); | |
210 | } | |
211 | ||
212 | LinkedHa shMap<Loca tion, Obje ct> dataBe ansMap = n ew LinkedH ashMap<Loc ation, Obj ect>(); | |
213 | ||
214 | ||
215 | Executor Service ex ecutorServ ice = Thre adPoolMana ger.getIns tance().ge tThreadPoo l(); | |
216 | ||
217 | try { | |
218 | List <Future<Ob ject>> fut ures = exe cutorServi ce.invokeA ll(dataQue ryThreads, THREAD_TI MEOUT_MS, TimeUnit.M ILLISECOND S); | |
219 | ||
220 | //fu tures are returned i n the same sequentia l order as produced by the ite rator for the given task list. | |
221 | Iter ator<Multi LocationQu eryThread> queryThre adItr = da taQueryThr eads.itera tor(); | |
222 | Iter ator<Futur e<Object>> futuresIt r = future s.iterator (); | |
223 | ||
224 | whil e (queryTh readItr.ha sNext() && futuresIt r.hasNext( )) { | |
225 | MultiLocat ionQueryTh read query Thread = q ueryThread Itr.next() ; | |
226 | Future<Obj ect> futur e = future sItr.next( ); | |
227 | handleQuer y2(queryTh read, futu re, dataBe ansMap, sm artBean); | |
228 | } | |
229 | //us e smart be an to comb ine data f rom each l ocation | |
230 | for (Map.Entry <Location, Object> en try : data BeansMap.e ntrySet()) { | |
231 | if(entry.g etValue() != null && entry.get Value() in stanceof J MedResultC ollection) { | |
232 | return Val = smar tBean.comb ineData(re turnVal, ( JMedResult Collection ) entry.ge tValue(), queryBean. getSortBy( )); | |
233 | } | |
234 | // else if( entry.getV alue() != null && en try.getVal ue() insta nceof JlvR esultColle ction) { | |
235 | // retu rnVal = sm artBean.co mbineData( returnVal, (JlvResul tCollectio n) entry.g etValue(), queryBean .getSortBy ()); | |
236 | // } | |
237 | else { | |
238 | if(ent ry.getValu e() instan ceof Array List) { | |
239 | fo r (JMedRes ultCollect ion collec tion : (Ar rayList<JM edResultCo llection>) entry.get Value()) { | |
240 | returnVa l = smartB ean.combin eData(retu rnVal, col lection, q ueryBean.g etSortBy() ); | |
241 | } | |
242 | } | |
243 | } | |
244 | } | |
245 | ||
246 | } catch (Interrupt edExceptio n e) { | |
247 | thro w new JMea dowsExcept ion(e); | |
248 | } | |
249 | } | |
250 | re turn retur nVal; | |
251 | } | |
252 | ||
253 | public static Li st<LabQuer yResponse> executeLa bQuery(Lis t<MultiLoc ationQuery Config> do dLabOrderC onfigs, | |
254 | List<Mult iLocationQ ueryConfig > vaLabRes ultConfigs , | |
255 | JMeadowsQ uery query Bean) thro ws JMeadow sException { | |
256 | ||
257 | Ex ecutorServ ice execut orService = ThreadPo olManager. getInstanc e().getThr eadPool(); | |
258 | ||
259 | Li st<LabQuer yThread> l abQueryThr eads = new ArrayList <>(); | |
260 | la bQueryThre ads.add(ne w LabQuery Thread(dod LabOrderCo nfigs, Lab QueryThrea d.AGENCY_D OD, queryB ean)); | |
261 | la bQueryThre ads.add(ne w LabQuery Thread(vaL abResultCo nfigs, Lab QueryThrea d.AGENCY_V A, queryBe an)); | |
262 | ||
263 | tr y { | |
264 | List<Fut ure<LabQue ryResponse >> futures = executo rService.i nvokeAll(l abQueryThr eads, THRE AD_TIMEOUT _MS, TimeU nit.MILLIS ECONDS); | |
265 | ||
266 | List<Lab QueryRespo nse> respo nseList = new ArrayL ist<>(); | |
267 | ||
268 | for(Futu re<LabQuer yResponse> future : futures) { | |
269 | resp onseList.a dd(future. get()); | |
270 | } | |
271 | ||
272 | return r esponseLis t; | |
273 | ||
274 | } catch (Int erruptedEx ception | ExecutionE xception e ) { | |
275 | throw ne w JMeadows Exception( e); | |
276 | } | |
277 | } | |
278 | ||
279 | privat e static v oid handle Query2(Mul tiLocation QueryThrea d queryThr ead, Futur e<Object> future, Li nkedHashMa p<Location , Object> dataBeansM ap, SmartB ean smartB ean) throw s Interrup tedExcepti on { | |
280 | Ob ject resul t = null; | |
281 | ||
282 | tr y { | |
283 | if (futu re.isCance lled()) { | |
284 | Mult iLocationQ ueryConfig queryConf ig = query Thread.get QueryConfi g(); | |
285 | ||
286 | if(q ueryConfig .returnsRe sultCollec tion) { | |
287 | result = s martBean.g enerateCon nectionUna vailableSt atus( | |
288 | qu eryConfig. getLocatio n(), | |
289 | qu eryConfig. getConnect ionErrorMs g(), ""); | |
290 | } el se { | |
291 | result = s martBean.g enerateCon nectionUna vailableBe an( | |
292 | qu eryConfig. getLocatio n(), | |
293 | qu eryConfig. getConnect ionErrorMs g()); | |
294 | } | |
295 | ||
296 | //lo g connecti on timeout | |
297 | Stri ngBuilder errorMsg = new Strin gBuilder() ; | |
298 | erro rMsg.appen d("MultiLo cationQuer yThread ti meout. Thr ead wait t ime exceed ed "); | |
299 | erro rMsg.appen d(THREAD_T IMEOUT_MS) ; | |
300 | erro rMsg.appen d("ms"); | |
301 | LOGG ER.error(e rrorMsg.to String(), new JMeado wsExceptio n(errorMsg .toString( ))); | |
302 | } else { | |
303 | resu lt = (Obje ct) future .get(); | |
304 | } | |
305 | ||
306 | MultiLoc ationQuery Config con fig = quer yThread.ge tQueryConf ig(); | |
307 | ||
308 | //add re sult to da tabean loc ation map | |
309 | if (resu lt != null ) { | |
310 | Obje ct newResu lt; | |
311 | //if previous result exi sts for lo cation, co mbine it w ith return ing result set | |
312 | ||
313 | Loca tion locat ionKey; | |
314 | ||
315 | loca tionKey = config.get Location() ; | |
316 | ||
317 | Obje ct prevRes ult = (Obj ect) dataB eansMap.ge t(location Key); | |
318 | ||
319 | if ( prevResult == null) { | |
320 | newResult = result; | |
321 | } el se { | |
322 | ArrayList< Object> re sultList = new Array List<Objec t>(); | |
323 | if(prevRes ult instan ceof Array List){ | |
324 | result List.addAl l((ArrayLi st<JMedRes ultCollect ion>)prevR esult); | |
325 | } else { | |
326 | result List.add(p revResult) ; | |
327 | } | |
328 | resultList .add(resul t); | |
329 | // newResul t = result List.toArr ay(new Obj ect[result List.size( )]); | |
330 | newResult = resultLi st; | |
331 | } | |
332 | data BeansMap.p ut(locatio nKey, newR esult); | |
333 | } | |
334 | } catch (Exe cutionExce ption ex) { | |
335 | MultiLoc ationQuery Config con fig = quer yThread.ge tQueryConf ig(); | |
336 | ||
337 | if(confi g.returnsR esultColle ction) { | |
338 | resu lt = smart Bean.gener ateConnect ionUnavail ableStatus ( | |
339 | config .getLocati on(), | |
340 | config .getConnec tionErrorM sg(), ""); | |
341 | } else { | |
342 | resu lt = smart Bean.gener ateConnect ionUnavail ableBean( | |
343 | config .getLocati on(), | |
344 | config .getConnec tionErrorM sg()); | |
345 | } | |
346 | ||
347 | JMedResu ltCollecti on collect ion = new JMedResult Collection (); | |
348 | collecti on.getInte rfaceStatu sList().ad dAll(Array s.asList(( InterfaceS tatus[])re sult)); | |
349 | ||
350 | Location locationK ey; | |
351 | location Key = conf ig.getLoca tion(); | |
352 | ||
353 | dataBean sMap.put(l ocationKey , collecti on); | |
354 | ||
355 | LOGGER.e rror(ex.ge tMessage() , ex); | |
356 | } | |
357 | } | |
358 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.