Produced by Araxis Merge on 7/10/2017 1:01:42 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 | C:\AraxisMergeCompare\Pri_un\IV-ehmp_cif\CoreRouter\main\src\java\gov\va\med\imaging\core | AsynchronousRouterImpl.java | Thu Jun 29 17:22:43 2017 UTC |
| 2 | C:\AraxisMergeCompare\Pri_re\IV-ehmp_cif\CoreRouter\main\src\java\gov\va\med\imaging\core | AsynchronousRouterImpl.java | Fri Jul 7 16:36:52 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 4 | 556 |
| Changed | 3 | 6 |
| 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 | * Package : MAG - Vi stA Imagin g | |
| 3 | * WARNING : Per VHA Directive 2004-038, this routi ne should not be mod ified. | |
| 4 | * Date Cr eated: Oct 3, 2008 | |
| 5 | * Site Na me: Washi ngton OI F ield Offic e, Silver Spring, MD | |
| 6 | * @author R E DA C T E D | |
| 7 | * @versio n 1.0 | |
| 8 | * | |
| 9 | * ------- ---------- ---------- ---------- ---------- ---------- ------- | |
| 10 | * Propert y of the U S Governme nt. | |
| 11 | * No perm ission to copy or re distribute this soft ware is gi ven. | |
| 12 | * Use of unreleased versions of this so ftware req uires the user | |
| 13 | * to exec ute a writ ten test a greement w ith the Vi stA Imagin g | |
| 14 | * Develop ment Offic e of the D epartment of Veteran s Affairs, | |
| 15 | * telepho ne (301) 7 34-0100. | |
| 16 | * | |
| 17 | * The Foo d and Drug Administr ation clas sifies thi s software as | |
| 18 | * a Class II medica l device. As such, it may not be change d | |
| 19 | * in any way. Modi fications to this so ftware may result in an | |
| 20 | * adulter ated medic al device under 21CF R820, the use of whi ch | |
| 21 | * is cons idered to be a viola tion of US Federal S tatutes. | |
| 22 | * ------- ---------- ---------- ---------- ---------- ---------- ------- | |
| 23 | */ | |
| 24 | package go v.va.med.i maging.cor e; | |
| 25 | ||
| 26 | import gov .va.med.im aging.core .interface s.Asynchro nousRouter ; | |
| 27 | import gov .va.med.im aging.core .interface s.Router; | |
| 28 | import gov .va.med.im aging.core .interface s.exceptio ns.MethodE xception; | |
| 29 | import gov .va.med.im aging.core .interface s.router.A synchronou sCommandRe sult; | |
| 30 | import gov .va.med.im aging.core .interface s.router.A synchronou sCommandRe sultListen er; | |
| 31 | import gov .va.med.im aging.core .interface s.router.C ommand; | |
| 32 | import gov .va.med.im aging.core .interface s.router.C ommandStat us; | |
| 33 | import gov .va.med.im aging.core .router.Ab stractComm andImpl; | |
| 34 | import gov .va.med.im aging.core .router.Ab stractRetr yableComma ndImpl; | |
| 35 | import gov .va.med.im aging.core .router.As ynchronous CommandExe cutor; | |
| 36 | import gov .va.med.im aging.core .router.Pe riodicComm andList; | |
| 37 | import gov .va.med.im aging.tran sactioncon text.Inval idTransact ionContext MementoExc eption; | |
| 38 | import gov .va.med.im aging.tran sactioncon text.Trans actionCont extFactory ; | |
| 39 | ||
| 40 | import jav a.util.Gre gorianCale ndar; | |
| 41 | import jav a.util.Lis t; | |
| 42 | import jav a.util.con current.*; | |
| 43 | ||
| 44 | import org .apache.lo g4j.Logger ; | |
| 45 | ||
| 46 | /** | |
| 47 | * This cl ass implem ents all o f the asyn chronous m ethods of the Router | |
| 48 | * interfa ce. The R outer impl ementation may deleg ate work t o this cla ss | |
| 49 | * and vic e versa. | |
| 50 | * | |
| 51 | * @author R E DA C T E D | |
| 52 | * | |
| 53 | */ | |
| 54 | public cla ss Asynchr onousRoute rImpl | |
| 55 | implements Asynchron ousRouter | |
| 56 | { | |
| 57 | pr ivate fina l static i nt asynchC ommandComp letionNoti ficationSe rviceThrea ds = 25; | |
| 58 | ||
| 59 | fi nal Logger logger = Logger.get Logger(Rou ter.class) ; | |
| 60 | // priv ate final IImageConv ersion ima geConversi on; | |
| 61 | ||
| 62 | // A Queue w here the a synch exec utor shoul d put resu lts when t he tasks a re complet e | |
| 63 | pr ivate fina l Blocking Queue<Asyn chronousCo mmandResul t<?>> resu ltsQueue; | |
| 64 | ||
| 65 | // the async hronous co mmand proc essing exe cutor | |
| 66 | // this is s imilar in function t o an Execu tor but is specializ ed for | |
| 67 | // asynchron ous router processes and does not derive from any java.util. concurrent .* classes | |
| 68 | pr ivate Asyn chronousCo mmandExecu tor asynch CommandCom pletionSer vice; | |
| 69 | ||
| 70 | // A thread pool that takes comp leted asyn chronous t asks and n otifies th e client l istener | |
| 71 | pr ivate Exec utorServic e asynchCo mmandCompl etionNotif icationSer vice; | |
| 72 | ||
| 73 | pr ivate fina l RouterIm pl router; | |
| 74 | ||
| 75 | As ynchronous RouterImpl (RouterImp l router) | |
| 76 | { | |
| 77 | super(); | |
| 78 | this.rou ter = rout er; | |
| 79 | ||
| 80 | this .resultsQu eue = new LinkedBloc kingQueue< Asynchrono usCommandR esult<?>>( ); | |
| 81 | this .asynchCom mandComple tionServic e = new As ynchronous CommandExe cutor(resu ltsQueue); | |
| 82 | ||
| 83 | this .asynchCom mandComple tionNotifi cationServ ice = Exec utors.newF ixedThread Pool( | |
| 84 | asynch CommandCom pletionNot ificationS erviceThre ads, | |
| 85 | new Th readFactor y() | |
| 86 | { | |
| 87 | private int serial Number = 0 ; | |
| 88 | private ThreadGrou p group = new Thread Group("Com mandComple tionNotifi cationServ ice"); | |
| 89 | @Overrid e | |
| 90 | publ ic Thread newThread( Runnable r ) | |
| 91 | { | |
| 92 | Thread thr ead = new Thread(gro up, r, "Co mmandCompl etionNotif icationSer vice" + "- " + serial Number++); | |
| 93 | thread.set Daemon(tru e); | |
| 94 | return thr ead; | |
| 95 | } | |
| 96 | } | |
| 97 | ); | |
| 98 | // t he complet ion servic e completi on threads takes the results f rom the co mpletion s ervice | |
| 99 | // a nd calls t he Asynchr onousComma ndResultLi stener fro m the orig inal clien t call (if one was p rovided) | |
| 100 | for( int i=0; i <asynchCom mandComple tionNotifi cationServ iceThreads ; ++i) | |
| 101 | this.a synchComma ndCompleti onNotifica tionServic e.execute( new Comma ndCompleti onNotifica tionThread () ); | |
| 102 | } | |
| 103 | ||
| 104 | /* * | |
| 105 | * | |
| 106 | * @return | |
| 107 | * / | |
| 108 | pr ivate Asyn chronousCo mmandExecu tor getAsy nchCommand Completion Service() | |
| 109 | { | |
| 110 | retu rn asynchC ommandComp letionServ ice; | |
| 111 | } | |
| 112 | ||
| 113 | pr ivate Bloc kingQueue< Asynchrono usCommandR esult<?>> getResults Queue() | |
| 114 | { | |
| 115 | re turn resul tsQueue; | |
| 116 | } | |
| 117 | ||
| 118 | Ro uterImpl g etRouter() | |
| 119 | { | |
| 120 | re turn route r; | |
| 121 | } | |
| 122 | ||
| 123 | /* (non-Java doc) | |
| 124 | * @see gov. va.med.ima ging.core. Asynchrono usRouter#g etCommandS tatus(gov. va.med.ima ging.core. interfaces .router.Co mmand) | |
| 125 | * / | |
| 126 | pu blic Comma ndStatus g etCommandS tatus(Comm and<?> com mand) | |
| 127 | { | |
| 128 | retu rn getAsyn chCommandC ompletionS ervice().g etCommandS tatus(comm and); | |
| 129 | } | |
| 130 | ||
| 131 | /* (non-Java doc) | |
| 132 | * @see gov. va.med.ima ging.core. Asynchrono usRouter#d oAsynchron ously(gov. va.med.ima ging.core. router.Abs tractComma ndImpl) | |
| 133 | * / | |
| 134 | public void doAs ynchronous ly(Command <?> comman d) | |
| 135 | { | |
| 136 | if (command = = null) | |
| 137 | retu rn; | |
| 138 | ||
| 139 | if (command i nstanceof AbstractCo mmandImpl< ?>) | |
| 140 | { | |
| 141 | logg er.info("S ubmitting asynchrono us command '" + comm and.toStri ng() + "' for asynch ronous pro cessing us ing '" + c ommand.get Class().ge tSimpleNam e() + "'." ); | |
| 142 | // J MW 12/7/20 12 P130 - initially when the c ommand is scheduled it might n ot immedia tely execu te (there can be a d elay). Add it | |
| 143 | // t o the list of schedu led comman ds so it c an be canc elled befo re running if desire d. | |
| 144 | if(c ommand.isP eriodic()) | |
| 145 | Period icCommandL ist.get(). addIfNotAl readySched uled(comma nd); | |
| 146 | getA synchComma ndCompleti onService( ).execute( (AbstractC ommandImpl <?>)comman d); | |
| 147 | } | |
| 148 | el se | |
| 149 | logg er.error(" Error subm itting asy nchronous command '" + command .toString( ) + "' for asynchron ous proces sing. Com mand class is incomp atible wit h the asyn chronous r outer impl ementation ."); | |
| 150 | ||
| 151 | } | |
| 152 | ||
| 153 | /* * | |
| 154 | * | |
| 155 | * @author R E DA C T E D | |
| 156 | * | |
| 157 | * / | |
| 158 | cl ass Comman dCompletio nNotificat ionThread | |
| 159 | im plements R unnable | |
| 160 | { | |
| 161 | pr ivate bool ean runnin g = true; | |
| 162 | pr ivate Thre ad notific ationThrea d = null; | |
| 163 | ||
| 164 | pu blic void kill() | |
| 165 | { | |
| 166 | running = false; | |
| 167 | if(notif icationThr ead != nul l) | |
| 168 | not ificationT hread.inte rrupt(); | |
| 169 | } | |
| 170 | ||
| 171 | @O verride | |
| 172 | pu blic void run() | |
| 173 | { | |
| 174 | notifica tionThread = Thread. currentThr ead(); | |
| 175 | while(ru nning) | |
| 176 | { | |
| 177 | boolea n transact ionContext Set = fals e; | |
| 178 | try | |
| 179 | { | |
| 180 | Asynch ronousComm andResult< ?> result = getResul tsQueue(). take(); | |
| 181 | // the result al ways wraps the comma nd process or | |
| 182 | Abstract CommandImp l<?> comma nd = (Abst ractComman dImpl<?>)r esult.getC ommand(); | |
| 183 | ||
| 184 | // Push the transa ction cont ext onto t his notifi cation thr ead so tha t the | |
| 185 | // liste ners are o perating i n the corr ect transa ction cont ext | |
| 186 | ||
| 187 | try | |
| 188 | { | |
| 189 | // push th e transact ion contex t of the c lient, mak ing it the current T C | |
| 190 | Transactio nContextFa ctory.push Transactio nContext(c ommand.get Transactio nContextMe mento()); | |
| 191 | transactio nContextSe t = true; | |
| 192 | } | |
| 193 | catch (I nvalidTran sactionCon textMement oException itcmX) | |
| 194 | { | |
| 195 | logger.err or("Unable to push t ransaction context ( make it th e current context). Completio n listener s cannot b e safely n otified.", itcmX); | |
| 196 | } | |
| 197 | ||
| 198 | // Norma lly, liste ners are n otified re gardless o f result. | |
| 199 | // Retry able comma nds may ch oose not t o notify t heir liste ners until | |
| 200 | // all r etries hav e been exh austed. | |
| 201 | if( co mmand inst anceof Abs tractRetry ableComman dImpl<?> & & | |
| 202 | result.i sRetryRequ ested() && | |
| 203 | ((Abstra ctRetryabl eCommandIm pl<?>)comm and).getRe mainingRet ries() > 0 ) | |
| 204 | { | |
| 205 | logger.i nfo("Async hronous co mmand [" + result.ge tCommand() .toString( ) + "] com pleted wit h retry re quested.") ; | |
| 206 | Abstract RetryableC ommandImpl <?> retrya bleCommand = (Abstra ctRetryabl eCommandIm pl<?>)resu lt.getComm and(); | |
| 207 | retryabl eCommand.u pdateAcces sibilityDa teForRetry (); | |
| 208 | logger.i nfo("Async hronous co mmand [" + command.t oString() + "] retry ing."); | |
| 209 | doAsynchro nously(com mand); | |
| 210 | } | |
| 211 | else i f(transact ionContext Set) | |
| 212 | { | |
| 213 | logger.i nfo("Async hronous co mmand [" + result.ge tCommand() .toString( ) + "] com pleted."); | |
| 214 | fo r( Asynchr onousComma ndResultLi stener lis tener : co mmand.getL isteners() ) | |
| 215 | list ener.comma ndComplete (result); | |
| 216 | ||
| 217 | // If the co mmand is p eriodic, u pdate the accessibil ity date a nd throw i t back | |
| 218 | // on the qu eue | |
| 219 | if (command.i sPeriodic( )) | |
| 220 | { | |
| 221 | // make sure no lo nger in th e list of executing periodic c ommands | |
| 222 | Periodic CommandLis t.get().re moveSchedu ledCommand (command); | |
| 223 | boolean fatalExcep tion = fal se; | |
| 224 | if(resul t.getThrow able() != null) | |
| 225 | { | |
| 226 | List<Class <? extends MethodExc eption>> f atalExcept ionClasses = command .getFatalP eriodicExc eptionClas ses(); | |
| 227 | if(fatalEx ceptionCla sses != nu ll) | |
| 228 | { | |
| 229 | fo r(Class<? extends Th rowable> t : fatalEx ceptionCla sses) | |
| 230 | { | |
| 231 | if(r esult.getT hrowable() .getClass( ).equals(t )) | |
| 232 | { | |
| 233 | fatalE xception = true; | |
| 234 | logger .warn("Per iodic comm and [" + r esult.getC ommand().t oString() + "] compl eted with a fatal ex ception of type [" + result.ge tThrowable ().getClas s().getNam e() + "], will not b e reschedu led."); | |
| 235 | // don 't resched ule the pe riodic com mand | |
| 236 | comman d.handleFa talPeriodi cException (result.ge tThrowable ()); | |
| 237 | break; | |
| 238 | } | |
| 239 | } | |
| 240 | } | |
| 241 | } | |
| 242 | if(!fata lException ) | |
| 243 | { | |
| 244 | // check i f the now completed command wa s set to t erminate | |
| 245 | if(command .isPeriodi cProcessin gTerminate d()) | |
| 246 | { | |
| 247 | lo gger.info( "Periodic command [" + result. getCommand ().toStrin g() + "] c ompleted b ut has bee n set to t erminate - will not be added b ack to the asynch qu eue."); | |
| 248 | } | |
| 249 | else | |
| 250 | { | |
| 251 | lo gger.info( "Periodic command [" + result. getCommand ().toStrin g() + "] c ompleted a nd is bein g added ba ck to the asynch que ue."); | |
| 252 | Co mmand<?> n ewCommand = command. getNewPeri odicInstan ce(); | |
| 253 | Gr egorianCal endar acce ssibilityD ate = new GregorianC alendar(); | |
| 254 | ac cessibilit yDate.add( GregorianC alendar.MI LLISECOND, command.g etPeriodic ExecutionD elay()); | |
| 255 | ne wCommand.s etAccessib ilityDate( accessibil ityDate.ge tTime()); | |
| 256 | Pe riodicComm andList.ge t().addSch eduledPeri odicComman d(newComma nd); | |
| 257 | doAs ynchronous ly(newComm and); | |
| 258 | } | |
| 259 | } | |
| 260 | } | |
| 261 | } | |
| 262 | } | |
| 263 | catch (I nterrupted Exception e) | |
| 264 | { | |
| 265 | logger.war n("Command Completion ServiceCom pletion in terrupted waiting fo r results, ignoring. .."); | |
| 266 | } | |
| 267 | catch(Th rowable t) | |
| 268 | { | |
| 269 | logger.err or("Comman dCompletio nServiceCo mpletion r eceived ex ception wh en calling Asynchron ousCommand ResultList ener.", t) ; | |
| 270 | } | |
| 271 | finally | |
| 272 | { | |
| 273 | // restore the trans action con text, this is mostly so that t he thread no longer has access to the | |
| 274 | // securit y context which coul d lead to a security hole | |
| 275 | if(transac tionContex tSet) | |
| 276 | Tr ansactionC ontextFact ory.popTra nsactionCo ntext(); | |
| 277 | } | |
| 278 | } | |
| 279 | } | |
| 280 | } | |
| 281 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.