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