Produced by Araxis Merge on 12/13/2018 10:35:30 AM Eastern Standard 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 | v12.5_iter_7_build 51.zip\TRM_Upgrade\src\main\java\gov\va\med\fw\scheduling | StatelessScheduledService.java | Fri Dec 7 17:36:20 2018 UTC |
| 2 | v12.5_iter_7_build 51.zip\TRM_Upgrade\src\main\java\gov\va\med\fw\scheduling | StatelessScheduledService.java | Wed Dec 12 19:46:45 2018 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 836 |
| 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 | * Copyrii ght 2006 V HA. All ri ghts reser ved | |
| 3 | ********* ********** ********** ********** ********** ********** *********/ | |
| 4 | // Package | |
| 5 | package go v.va.med.f w.scheduli ng; | |
| 6 | ||
| 7 | // Java cl asses | |
| 8 | import jav a.io.Seria lizable; | |
| 9 | import jav a.lang.ref lect.Invoc ationTarge tException ; | |
| 10 | import jav a.util.Lis t; | |
| 11 | ||
| 12 | import org .apache.co mmons.lang .ArrayUtil s; | |
| 13 | import org .apache.co mmons.lang .ClassUtil s; | |
| 14 | import org .apache.co mmons.lang .StringUti ls; | |
| 15 | import org .quartz.In terruptabl eJob; | |
| 16 | import org .quartz.Jo bExecution Context; | |
| 17 | import org .quartz.Jo bExecution Exception; | |
| 18 | import org .quartz.Un ableToInte rruptJobEx ception; | |
| 19 | import org .springfra mework.bea ns.BeansEx ception; | |
| 20 | import org .springfra mework.con text.Appli cationCont ext; | |
| 21 | import org .springfra mework.con text.Confi gurableApp licationCo ntext; | |
| 22 | import org .springfra mework.sch eduling.qu artz.Quart zJobBean; | |
| 23 | ||
| 24 | import gov .va.med.fw .batchproc ess.BatchP rocessDeta il; | |
| 25 | import gov .va.med.fw .batchproc ess.BatchP rocessInvo ker; | |
| 26 | import gov .va.med.fw .batchproc ess.BatchP rocessServ ice; | |
| 27 | import gov .va.med.fw .security. LoginManag er; | |
| 28 | import gov .va.med.fw .util.Refl ectionExce ption; | |
| 29 | import gov .va.med.fw .util.Refl ector; | |
| 30 | ||
| 31 | /** | |
| 32 | * Base cl ass for al l Quartz b ased jobs. This allo ws for con sistent pr e- and | |
| 33 | * post- o perations to the exe cution of the jobs. The jobs t hemselves are tied | |
| 34 | * to the serviceNam e and meth odName. | |
| 35 | * | |
| 36 | * If a Ba tchProcess Invoker is "detected ", its cus tom implem entation w ill create | |
| 37 | * a JMS M essage to indicate a job needs to be exe cuted imme diately. T his allows | |
| 38 | * for tar geting job execution to dedica ted server s (ie, phy sical JMS queue is | |
| 39 | * located on subset of nodes in cluster ) without worrying a bout | |
| 40 | * inclusi on/exclusi on of Quar tz schedul er. | |
| 41 | * | |
| 42 | * @author DN S
|
|
| 43 | */ | |
| 44 | public cla ss Statele ssSchedule dService e xtends Qua rtzJobBean implement s Serializ able, | |
| 45 | Inte rruptableJ ob { | |
| 46 | ||
| 47 | pu blic stati c final St ring ARGUM ENTS_METHO D = "metho dArguments "; | |
| 48 | pr ivate stat ic final S tring INVO KE_METHOD = "invoke" ; | |
| 49 | pr ivate stat ic final S tring INTE RRUPT_METH OD = "inte rrupt"; | |
| 50 | pr ivate stat ic final i nt MAX_USE R_ID_LENGT H = 30; | |
| 51 | ||
| 52 | /* * | |
| 53 | * An instan ce of seri alVersionU ID | |
| 54 | * / | |
| 55 | pr ivate stat ic final l ong serial VersionUID = -561159 3072858343 064L; | |
| 56 | ||
| 57 | /* * | |
| 58 | * An instan ce of serv iceName | |
| 59 | * / | |
| 60 | pr ivate Stri ng service Name = nul l; | |
| 61 | ||
| 62 | /* * | |
| 63 | * An instan ce of meth odName - d efault is invoke. | |
| 64 | * / | |
| 65 | pr ivate Stri ng methodN ame = INVO KE_METHOD; | |
| 66 | ||
| 67 | /* * | |
| 68 | * An instan ce of appl icationCon text | |
| 69 | * / | |
| 70 | pr ivate Appl icationCon text appli cationCont ext = null ; | |
| 71 | ||
| 72 | /* * | |
| 73 | * An instan ce of meth odArgument s | |
| 74 | * / | |
| 75 | pr ivate Obje ct[] metho dArguments = null; | |
| 76 | ||
| 77 | /* * | |
| 78 | * An instan ce of inte rruptMetho d, default value is interrupt | |
| 79 | * / | |
| 80 | pr ivate Stri ng interru ptMethod = INTERRUPT _METHOD; | |
| 81 | ||
| 82 | pr ivate Batc hProcessIn voker batc hProcessIn voker; | |
| 83 | pr ivate Batc hProcessSe rvice batc hProcessSe rvice; | |
| 84 | pr ivate Logi nManager l oginManage r; | |
| 85 | ||
| 86 | /* * | |
| 87 | * A default construct or | |
| 88 | * / | |
| 89 | pu blic State lessSchedu ledService () { | |
| 90 | supe r(); | |
| 91 | } | |
| 92 | ||
| 93 | /* * | |
| 94 | * @param ap plicationC ontext | |
| 95 | * @throws B eansExcept ion | |
| 96 | * / | |
| 97 | pu blic void setApplica tionContex t(Applicat ionContext applicati onContext) throws Be ansExcepti on { | |
| 98 | this .applicati onContext = applicat ionContext ; | |
| 99 | } | |
| 100 | ||
| 101 | /* * | |
| 102 | * @return R eturns the applicati onContext. | |
| 103 | * / | |
| 104 | pu blic Appli cationCont ext getApp licationCo ntext() { | |
| 105 | retu rn applica tionContex t; | |
| 106 | } | |
| 107 | ||
| 108 | /* * | |
| 109 | * @param me thodName | |
| 110 | * The meth odName to set. | |
| 111 | * / | |
| 112 | pu blic void setMethodN ame(String methodNam e) { | |
| 113 | this .methodNam e = method Name; | |
| 114 | } | |
| 115 | ||
| 116 | /* * | |
| 117 | * @param me thodArgume nts | |
| 118 | * The meth odArgument s to set. | |
| 119 | * / | |
| 120 | pu blic void setMethodA rguments(O bject[] me thodArgume nts) { | |
| 121 | this .methodArg uments = m ethodArgum ents; | |
| 122 | } | |
| 123 | ||
| 124 | /* * | |
| 125 | * @param se rviceName | |
| 126 | * The serv iceName to set. | |
| 127 | * / | |
| 128 | pu blic void setService Name(Strin g serviceN ame) { | |
| 129 | this .serviceNa me = servi ceName; | |
| 130 | } | |
| 131 | ||
| 132 | /* * | |
| 133 | * @return R eturns the serviceNa me. | |
| 134 | * / | |
| 135 | pu blic Strin g getServi ceName() { | |
| 136 | retu rn service Name; | |
| 137 | } | |
| 138 | ||
| 139 | /* * | |
| 140 | * @return R eturns the interrupt Method. | |
| 141 | * / | |
| 142 | pu blic Strin g getInter ruptMethod () { | |
| 143 | retu rn interru ptMethod; | |
| 144 | } | |
| 145 | ||
| 146 | /* * | |
| 147 | * @param in terruptMet hod | |
| 148 | * The inte rruptMetho d to set. | |
| 149 | * / | |
| 150 | pu blic void setInterru ptMethod(S tring inte rruptMetho d) { | |
| 151 | this .interrupt Method = i nterruptMe thod; | |
| 152 | } | |
| 153 | ||
| 154 | /* * | |
| 155 | * @see org. quartz.Int erruptable Job#interr upt() | |
| 156 | * / | |
| 157 | pu blic void interrupt( ) throws U nableToInt erruptJobE xception { | |
| 158 | ||
| 159 | try { | |
| 160 | Object service = getApplic ationConte xt().getBe an(getServ iceName()) ; | |
| 161 | Reflec tor.invoke (service, interruptM ethod, nul l); | |
| 162 | } ca tch (NoSuc hMethodExc eption e) { | |
| 163 | Unable ToInterrup tJobExcept ion ex = n ew UnableT oInterrupt JobExcepti on( | |
| 164 | "A interru pt method to run is missing"); | |
| 165 | ex.ini tCause(e); | |
| 166 | throw ex; | |
| 167 | } ca tch (Refle ctionExcep tion e) { | |
| 168 | Unable ToInterrup tJobExcept ion ex = n ew UnableT oInterrupt JobExcepti on( | |
| 169 | "A interru pt method to run is in accessi ble"); | |
| 170 | ex.ini tCause(e); | |
| 171 | throw ex; | |
| 172 | } ca tch (Invoc ationTarge tException e) { | |
| 173 | Unable ToInterrup tJobExcept ion ex = n ew UnableT oInterrupt JobExcepti on( | |
| 174 | "Exception thrown in a interru pt method " + interr uptMethod) ; | |
| 175 | ex.ini tCause(e); | |
| 176 | throw ex; | |
| 177 | } ca tch (Excep tion e) { | |
| 178 | // Any runtime e xception s uch as Tra nsactionTi meoutExcep tion | |
| 179 | Unable ToInterrup tJobExcept ion ex = n ew UnableT oInterrupt JobExcepti on( | |
| 180 | "Exception thrown in a interru pt method " + interr uptMethod) ; | |
| 181 | ex.ini tCause(e); | |
| 182 | throw ex; | |
| 183 | } ca tch (Error e) { | |
| 184 | // Any error suc h as OutOf MemoryErro r | |
| 185 | Unable ToInterrup tJobExcept ion ex = n ew UnableT oInterrupt JobExcepti on( | |
| 186 | "Exception thrown in a interru pt method " + interr uptMethod) ; | |
| 187 | ex.ini tCause(e); | |
| 188 | throw ex; | |
| 189 | } | |
| 190 | } | |
| 191 | ||
| 192 | /* * | |
| 193 | * @see org. springfram ework.sche duling.qua rtz.Quartz JobBean#ex ecuteInter nal(org.qu artz.JobEx ecutionCon text) | |
| 194 | * / | |
| 195 | pr otected vo id execute Internal(J obExecutio nContext c ontext) th rows JobEx ecutionExc eption { | |
| 196 | ||
| 197 | // A n applicat ion contex t is set a utomatical ly by a Sp ring manag ed | |
| 198 | // S chedulerFa ctoryBean | |
| 199 | // i nto a Schd ulerContex t, which i s a map. A QuartzJob Bean, in t urn, | |
| 200 | // l ooks for p roperties | |
| 201 | // i n this Job class who se names a re the sam e as keys in a | |
| 202 | // S cheduleCon text then set the | |
| 203 | // a ppropriate values. R efer to Qu artzJobBea n for more info | |
| 204 | ||
| 205 | // F irst check if all re quired pro perties ar e set | |
| 206 | if ( this.appli cationCont ext == nul l || this. methodName == null | | this.ser viceName = = null) { | |
| 207 | ||
| 208 | throw new JobExe cutionExce ption("Mis sing requi red proper ties to ru n a job"); | |
| 209 | } | |
| 210 | ||
| 211 | // e xecution c ontext cou ld come fr om either trigger or job.....t herefore | |
| 212 | // c heck conte xt | |
| 213 | Obje ct[] curre ntArgument s = method Arguments; | |
| 214 | Obje ct[] conte xtArgument s = null; | |
| 215 | if ( context.ge tMergedJob DataMap(). containsKe y( | |
| 216 | Schedule dProcessIn vocationCo ntext.INVO CATION_ARG UMENTS)) { | |
| 217 | // cli ent can ei ther have these as t yped or on e generic | |
| 218 | // Obj ect.....tr y typed fi rst | |
| 219 | if (co ntext.getM ergedJobDa taMap().ge t( | |
| 220 | ScheduledP rocessInvo cationCont ext.INVOCA TION_ARGUM ENTS) inst anceof Lis t) | |
| 221 | contextA rguments = ((List) c ontext.get MergedJobD ataMap().g et( | |
| 222 | Sc heduledPro cessInvoca tionContex t.INVOCATI ON_ARGUMEN TS)).toArr ay(); | |
| 223 | else | |
| 224 | contextA rguments = (Object[] ) context. getMergedJ obDataMap( ).get( | |
| 225 | Sc heduledPro cessInvoca tionContex t.INVOCATI ON_ARGUMEN TS); | |
| 226 | if (me thodArgume nts == nul l) { | |
| 227 | currentA rguments = contextAr guments; | |
| 228 | } else if (isNot JobData(co ntextArgum ents)) { | |
| 229 | // some usages may pass dyna mic data i n on the J ob's JobDa taMap | |
| 230 | // (whic h would ge t copied o nto method Arguments already) | |
| 231 | currentA rguments = ArrayUtil s.addAll(m ethodArgum ents, cont extArgumen ts); | |
| 232 | } | |
| 233 | } | |
| 234 | ||
| 235 | try { | |
| 236 | // wra p current arguments in a Sched uledProces sInvocatio nContext | |
| 237 | Schedu ledProcess Invocation Context in vContext = new Sched uledProces sInvocatio nContext() ; | |
| 238 | ||
| 239 | if (cu rrentArgum ents != nu ll) | |
| 240 | invConte xt | |
| 241 | .s etInvocati onArgument s(currentA rguments.l ength == 1 ? current Arguments[ 0] | |
| 242 | : curr entArgumen ts); | |
| 243 | String execution Context = (String) c ontext.get MergedJobD ataMap().g et( | |
| 244 | ScheduledP rocessInvo cationCont ext.EXECUT ION_CONTEX T); | |
| 245 | if (St ringUtils. isNotBlank (execution Context)) | |
| 246 | invConte xt.setExec utionConte xt(executi onContext) ; | |
| 247 | ||
| 248 | /* | |
| 249 | * not ice we do not set th e JobDetai lBeanName on invCont ext, this is | |
| 250 | * bec ause it ma y not exis t (logical name that is not an actual | |
| 251 | * Spr ing bean) | |
| 252 | */ | |
| 253 | invCon text.setSe rviceName( this.servi ceName); | |
| 254 | invCon text.setMe thodName(t his.method Name); | |
| 255 | ||
| 256 | invCon text.setJo bName(cont ext.getJob Detail().g etKey().ge tName()); | |
| 257 | invCon text.setJo bGroup(con text.getJo bDetail(). getKey().g etGroup()) ; | |
| 258 | ||
| 259 | doExec uteJob(inv Context); | |
| 260 | } ca tch (NoSuc hMethodExc eption e) { | |
| 261 | throw new JobExe cutionExce ption("A s ervice met hod to run is missin g", e, fal se); | |
| 262 | } ca tch (Refle ctionExcep tion e) { | |
| 263 | throw new JobExe cutionExce ption("A s ervice met hod to run is in acc essible", e, false); | |
| 264 | } ca tch (Invoc ationTarge tException e) { | |
| 265 | throw new JobExe cutionExce ption("Fai led to run a job in: " + metho dName, e, false); | |
| 266 | } ca tch (Excep tion e) { | |
| 267 | // Any runtime e xception s uch as Tra nsactionTi meoutExcep tion | |
| 268 | throw new JobExe cutionExce ption("Fai led to run a job in: " + metho dName, e, false); | |
| 269 | } ca tch (Error e) { | |
| 270 | // Any error suc h as OutOf MemoryErro r | |
| 271 | JobExe cutionExce ption je = new JobEx ecutionExc eption("Fa iled to ru n a job in : " | |
| 272 | + methodNa me, null, false); | |
| 273 | je.ini tCause(e); | |
| 274 | throw je; | |
| 275 | } | |
| 276 | } | |
| 277 | ||
| 278 | /* * Subclass es can ove rride */ | |
| 279 | pr otected vo id doExecu teJob(Sche duledProce ssInvocati onContext invContext ) throws E xception { | |
| 280 | if ( !containsB atchProces sInvoker() ) { | |
| 281 | if (!t his.contai nsBatchPro cessServic e()) | |
| 282 | throw ne w IllegalS tateExcept ion("Missi ng BatchPr ocessServi ce to exec ute job"); | |
| 283 | this.g etBatchPro cessServic e().execut eJob(invCo ntext); | |
| 284 | } el se { | |
| 285 | String jobName = invContex t.getJobNa me(); | |
| 286 | BatchP rocessDeta il detail = getBatch ProcessInv oker().get BatchProce ssDetail(j obName); | |
| 287 | if (de tail == nu ll) { | |
| 288 | // could be for dy namically scheduled job | |
| 289 | detail = new Batch ProcessDet ail(); | |
| 290 | detail.s etJobName( invContext .getJobNam e()); | |
| 291 | detail.s etGroupNam e(invConte xt.getJobG roup()); | |
| 292 | } | |
| 293 | ||
| 294 | try { | |
| 295 | String l ogicalUser Name = det ail.getJob Name(); | |
| 296 | if (logi calUserNam e.length() > MAX_USE R_ID_LENGT H) { | |
| 297 | logicalUse rName = lo gicalUserN ame.substr ing(0, MAX _USER_ID_L ENGTH); | |
| 298 | } | |
| 299 | // this. getLoginMa nager().lo ginAnonymo us(Thread. currentThr ead().getN ame()); | |
| 300 | this.get LoginManag er().login Anonymous( logicalUse rName); | |
| 301 | getBatch ProcessInv oker().inv okeBatchPr ocessWithE vent(detai l, invCont ext); | |
| 302 | } fina lly { | |
| 303 | this.get LoginManag er().logou t(); | |
| 304 | } | |
| 305 | } | |
| 306 | } | |
| 307 | ||
| 308 | /* * | |
| 309 | * @param ar gs | |
| 310 | * @return | |
| 311 | * / | |
| 312 | pr ivate bool ean isNotJ obData(Obj ect[] args ) { | |
| 313 | if ( methodArgu ments.leng th != args .length) | |
| 314 | return true; | |
| 315 | for (int i = 0 ; i < args .length; i ++) | |
| 316 | if (!a rgs[i].equ als(method Arguments[ i])) | |
| 317 | return t rue; | |
| 318 | retu rn false; | |
| 319 | } | |
| 320 | ||
| 321 | pr ivate bool ean contai nsBatchPro cessInvoke r() { | |
| 322 | try { | |
| 323 | getBat chProcessI nvoker(); | |
| 324 | return true; | |
| 325 | } ca tch (Excep tion e) { | |
| 326 | return false; | |
| 327 | } | |
| 328 | } | |
| 329 | ||
| 330 | pr ivate bool ean contai nsBatchPro cessServic e() { | |
| 331 | try { | |
| 332 | this.g etBatchPro cessServic e(); | |
| 333 | return true; | |
| 334 | } ca tch (Excep tion e) { | |
| 335 | return false; | |
| 336 | } | |
| 337 | } | |
| 338 | ||
| 339 | /* | |
| 340 | * below are needed si nce this b ean's life cycle is n ot managed by Spring (is | |
| 341 | * created b y Quartz) | |
| 342 | * / | |
| 343 | ||
| 344 | pr ivate Batc hProcessIn voker getB atchProces sInvoker() { | |
| 345 | if ( batchProce ssInvoker == null) { | |
| 346 | try { | |
| 347 | batchPro cessInvoke r = (Batch ProcessInv oker) getA pplication Context(). getBean( | |
| 348 | Cl assUtils.g etShortCla ssName(Bat chProcessI nvoker.cla ss), | |
| 349 | Ba tchProcess Invoker.cl ass); | |
| 350 | } catc h (Illegal StateExcep tion e) { | |
| 351 | /* | |
| 352 | * Ensur e it is re freshed if get Illeg alStateExc eption and try | |
| 353 | * one m ore time.. .(seen thi s exceptio n in clust ered | |
| 354 | * envir onment). S ee Spring | |
| 355 | * Abstr actRefresh ableApplic ationConte xt.getBean Factory() method | |
| 356 | * that is called from this chain | |
| 357 | */ | |
| 358 | if (getA pplication Context() instanceof Configura bleApplica tionContex t) { | |
| 359 | ((Configur ableApplic ationConte xt) getApp licationCo ntext()).r efresh(); | |
| 360 | batchProce ssInvoker = (BatchPr ocessInvok er) getApp licationCo ntext().ge tBean( | |
| 361 | Clas sUtils.get ShortClass Name(Batch ProcessInv oker.class ), | |
| 362 | Batc hProcessIn voker.clas s); | |
| 363 | } else | |
| 364 | throw e; | |
| 365 | } | |
| 366 | } | |
| 367 | retu rn batchPr ocessInvok er; | |
| 368 | } | |
| 369 | ||
| 370 | pr ivate Batc hProcessSe rvice getB atchProces sService() { | |
| 371 | if ( batchProce ssService == null) { | |
| 372 | try { | |
| 373 | batchPro cessServic e = (Batch ProcessSer vice) getA pplication Context(). getBean( | |
| 374 | Cl assUtils.g etShortCla ssName(Bat chProcessS ervice.cla ss), | |
| 375 | Ba tchProcess Service.cl ass); | |
| 376 | } catc h (Illegal StateExcep tion e) { | |
| 377 | /* | |
| 378 | * Ensur e it is re freshed if get Illeg alStateExc eption and try | |
| 379 | * one m ore time.. .(seen thi s exceptio n in clust ered | |
| 380 | * envir onment). S ee Spring | |
| 381 | * Abstr actRefresh ableApplic ationConte xt.getBean Factory() method | |
| 382 | * that is called from this chain | |
| 383 | */ | |
| 384 | if (getA pplication Context() instanceof Configura bleApplica tionContex t) { | |
| 385 | ((Configur ableApplic ationConte xt) getApp licationCo ntext()).r efresh(); | |
| 386 | batchProce ssService = (BatchPr ocessServi ce) getApp licationCo ntext().ge tBean( | |
| 387 | Clas sUtils.get ShortClass Name(Batch ProcessSer vice.class ), | |
| 388 | Batc hProcessSe rvice.clas s); | |
| 389 | } else | |
| 390 | throw e; | |
| 391 | } | |
| 392 | } | |
| 393 | retu rn batchPr ocessServi ce; | |
| 394 | } | |
| 395 | ||
| 396 | pr ivate Logi nManager g etLoginMan ager() { | |
| 397 | if ( loginManag er == null ) { | |
| 398 | try { | |
| 399 | loginMan ager = (Lo ginManager ) getAppli cationCont ext().getB ean( | |
| 400 | Cl assUtils.g etShortCla ssName(Log inManager. class), Lo ginManager .class); | |
| 401 | } catc h (Illegal StateExcep tion e) { | |
| 402 | /* | |
| 403 | * Ensur e it is re freshed if get Illeg alStateExc eption and try | |
| 404 | * one m ore time.. .(seen thi s exceptio n in clust ered | |
| 405 | * envir onment). S ee Spring | |
| 406 | * Abstr actRefresh ableApplic ationConte xt.getBean Factory() method | |
| 407 | * that is called from this chain | |
| 408 | */ | |
| 409 | if (getA pplication Context() instanceof Configura bleApplica tionContex t) { | |
| 410 | ((Configur ableApplic ationConte xt) getApp licationCo ntext()).r efresh(); | |
| 411 | loginManag er = (Logi nManager) getApplica tionContex t().getBea n( | |
| 412 | Clas sUtils.get ShortClass Name(Login Manager.cl ass), Logi nManager.c lass); | |
| 413 | } else | |
| 414 | throw e; | |
| 415 | } | |
| 416 | } | |
| 417 | retu rn loginMa nager; | |
| 418 | } | |
| 419 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.