Produced by Araxis Merge on 12/5/2017 12:06:35 PM Central 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 | IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\CacheImpl\main\src\java\gov\va\med\imaging\storage\cache\impl | AbstractByteChannelFactory.java | Mon Dec 4 21:35:18 2017 UTC |
| 2 | IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\CacheImpl\main\src\java\gov\va\med\imaging\storage\cache\impl | AbstractByteChannelFactory.java | Mon Dec 4 21:57:31 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 3 | 1274 |
| Changed | 2 | 4 |
| 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.sto rage.cache .impl; | |
| 5 | ||
| 6 | ||
| 7 | import gov .va.med.im aging.Stac kTraceAnal yzer; | |
| 8 | import gov .va.med.im aging.chan nels.Check sumFactory ; | |
| 9 | import gov .va.med.im aging.stor age.cache. *; | |
| 10 | import gov .va.med.im aging.stor age.cache. exceptions .CacheStat eException ; | |
| 11 | import gov .va.med.im aging.stor age.cache. memento.By teChannelF actoryMeme nto; | |
| 12 | ||
| 13 | import jav a.io.IOExc eption; | |
| 14 | import jav a.text.Dat eFormat; | |
| 15 | import jav a.text.Sim pleDateFor mat; | |
| 16 | import jav a.util.*; | |
| 17 | ||
| 18 | import jav ax.managem ent.*; | |
| 19 | import jav ax.managem ent.openmb ean.*; | |
| 20 | ||
| 21 | import org .apache.lo gging.log4 j.LogManag er; | |
| 22 | import org .apache.lo gging.log4 j.Logger; | |
| 23 | ||
| 24 | /** | |
| 25 | * @author
|
|
| 26 | * | |
| 27 | * A facto ry class t hat provid es some ma nagement o f instance file chan nels. | |
| 28 | * | |
| 29 | */ | |
| 30 | public abs tract clas s Abstract ByteChanne lFactory<T > | |
| 31 | implements DynamicMB ean, Cache LifecycleL istener | |
| 32 | { | |
| 33 | pu blic stati c final lo ng default MaxChannel OpenDurati on = 30000 0L; // default to 5 minu tes (for r emote juke boxes) | |
| 34 | pu blic stati c final lo ng default SweepTime = 10000L; | |
| 35 | pu blic stati c final bo olean defa ultTraceCh annelInsta ntiation = true; | |
| 36 | pu blic stati c final St ring defau ltChecksum AlgorithmN ame = "Adl er32"; | |
| 37 | ||
| 38 | pr ivate Date Format df = new Simp leDateForm at("ddMMMy yyy hh:mm: ss"); | |
| 39 | ||
| 40 | pr ivate long maxChanne lOpenDurat ion = defa ultMaxChan nelOpenDur ation; | |
| 41 | pr ivate long sweepTime = default SweepTime; | |
| 42 | pr ivate bool ean traceC hannelInst antiation = defaultT raceChanne lInstantia tion; | |
| 43 | pr ivate Stri ng checksu mClassName ; | |
| 44 | ||
| 45 | pr ivate fina l Logger l og = LogMa nager.getL ogger(this .getClass( )); | |
| 46 | pr ivate Chan nelCleanup Thread cle anupThread ; | |
| 47 | ||
| 48 | /* * | |
| 49 | * | |
| 50 | * @param me mento | |
| 51 | * / | |
| 52 | pr otected Ab stractByte ChannelFac tory(ByteC hannelFact oryMemento memento) | |
| 53 | { | |
| 54 | this ( | |
| 55 | mement o == null ? defaultM axChannelO penDuratio n : mement o.getMaxCh annelOpenD uration(), | |
| 56 | mement o == null ? defaultS weepTime : memento.g etSweepTim e(), | |
| 57 | mement o == null ? null : m emento.get ChecksumAl gorithmNam e() | |
| 58 | ); | |
| 59 | } | |
| 60 | ||
| 61 | /* * | |
| 62 | * | |
| 63 | * @param ma xChannelOp enDuration - the max imum time a channel is allowed to be ope n | |
| 64 | * @param sw eepTime - the delay in the bac kground th read that looks for open chann els | |
| 65 | * / | |
| 66 | pr otected Ab stractByte ChannelFac tory(Long maxChannel OpenDurati on, Long s weepTime, String che cksumClass name) | |
| 67 | { | |
| 68 | setM axChannelO penDuratio n(maxChann elOpenDura tion == nu ll ? defau ltMaxChann elOpenDura tion : max ChannelOpe nDuration. longValue( )); | |
| 69 | setS weepTime(s weepTime = = null ? d efaultSwee pTime : sw eepTime.lo ngValue()) ; | |
| 70 | setC hecksumCla ssname(che cksumClass name); | |
| 71 | } | |
| 72 | ||
| 73 | /* * | |
| 74 | * @return t he log | |
| 75 | * / | |
| 76 | pu blic Logge r getLogge r() | |
| 77 | { | |
| 78 | retu rn this.lo g; | |
| 79 | } | |
| 80 | ||
| 81 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========= | |
| 82 | // InstanceB yteChannel Factory Im plementati on | |
| 83 | // Behaviora l Modifica tion Metho ds | |
| 84 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========= | |
| 85 | ||
| 86 | /* (non-Java doc) | |
| 87 | * @see gov. va.med.ima ging.stora ge.cache.i mpl.filesy stem.Insta nceByteCha nnelFactor yImplMBean #getMaxCha nnelOpenDu ration() | |
| 88 | * / | |
| 89 | pu blic long getMaxChan nelOpenDur ation() | |
| 90 | { | |
| 91 | retu rn maxChan nelOpenDur ation; | |
| 92 | } | |
| 93 | pu blic void setMaxChan nelOpenDur ation(long maxChanne lOpenDurat ion) | |
| 94 | { | |
| 95 | if(m axChannelO penDuratio n > 0L) | |
| 96 | this.m axChannelO penDuratio n = maxCha nnelOpenDu ration; | |
| 97 | } | |
| 98 | ||
| 99 | /* (non-Java doc) | |
| 100 | * @see gov. va.med.ima ging.stora ge.cache.i mpl.filesy stem.Insta nceByteCha nnelFactor yImplMBean #getSweepT ime() | |
| 101 | * / | |
| 102 | pu blic long getSweepTi me() | |
| 103 | { | |
| 104 | retu rn sweepTi me; | |
| 105 | } | |
| 106 | pu blic void setSweepTi me(long sw eepTime) | |
| 107 | { | |
| 108 | if(s weepTime > 0L) | |
| 109 | this.s weepTime = sweepTime ; | |
| 110 | } | |
| 111 | ||
| 112 | pu blic void setChecksu mClassname (String ch ecksumClas sName) | |
| 113 | { | |
| 114 | try | |
| 115 | { | |
| 116 | if( ch ecksumClas sName == n ull || Che cksumFacto ry.getFact ory().get( checksumCl assName) ! = null ) | |
| 117 | this.che cksumClass Name = che cksumClass Name; | |
| 118 | else | |
| 119 | log.erro r("Specifi ed checksu m '" + che cksumClass Name + "' is not a k nown algor ithm and i s not a cl ass name f ound on th e classpat h."); | |
| 120 | } | |
| 121 | catc h (Excepti on x) | |
| 122 | { | |
| 123 | log.er ror("Unabl e to use s pecified c hecksum '" + checksu mClassName + "'."); | |
| 124 | } | |
| 125 | } | |
| 126 | ||
| 127 | pu blic Strin g getCheck sumClassna me() | |
| 128 | { | |
| 129 | retu rn checksu mClassName ; | |
| 130 | } | |
| 131 | ||
| 132 | /* (non-Java doc) | |
| 133 | * @see gov. va.med.ima ging.stora ge.cache.i mpl.filesy stem.Insta nceByteCha nnelFactor yImplMBean #getCurren tlyOpenRea dableByteC hannels() | |
| 134 | * / | |
| 135 | pu blic int g etCurrentl yOpenReada bleByteCha nnels() | |
| 136 | { | |
| 137 | retu rn openRea dChannels. size(); | |
| 138 | } | |
| 139 | ||
| 140 | /* (non-Java doc) | |
| 141 | * @see gov. va.med.ima ging.stora ge.cache.i mpl.filesy stem.Insta nceByteCha nnelFactor yImplMBean #getCurren tlyOpenWri tableByteC hannels() | |
| 142 | * / | |
| 143 | pu blic int g etCurrentl yOpenWrita bleByteCha nnels() | |
| 144 | { | |
| 145 | retu rn openWri teChannels .size(); | |
| 146 | } | |
| 147 | ||
| 148 | /* * | |
| 149 | * If traceC hannelInst antiation is set the n the fact ory will r ecord | |
| 150 | * the stack trace whe n a channe l is insta ntiated an d report t he stack | |
| 151 | * trace whe n the chan nel is clo sed due to a timeout . | |
| 152 | * | |
| 153 | * @return | |
| 154 | * / | |
| 155 | pu blic boole an isTrace ChannelIns tantiation () | |
| 156 | { | |
| 157 | retu rn this.tr aceChannel Instantiat ion; | |
| 158 | } | |
| 159 | ||
| 160 | pu blic void setTraceCh annelInsta ntiation(b oolean tra ceChannelI nstantiati on) | |
| 161 | { | |
| 162 | this .traceChan nelInstant iation = t raceChanne lInstantia tion; | |
| 163 | } | |
| 164 | ||
| 165 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ====== | |
| 166 | // Open Read /Write Cha nnels list managemen t. | |
| 167 | // All acces s to these maps shou ld go thro ugh the ca lls provid ed below s o that cor rect | |
| 168 | // synchroni zation may be provid ed. | |
| 169 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ====== | |
| 170 | pr ivate Map< InstanceWr itableByte Channel, I nstanceByt eChannelLi stener> op enWriteCha nnels = | |
| 171 | Coll ections.sy nchronized Map( new H ashMap<Ins tanceWrita bleByteCha nnel, Inst anceByteCh annelListe ner>() ); | |
| 172 | pr ivate Map< InstanceRe adableByte Channel, I nstanceByt eChannelLi stener> op enReadChan nels = | |
| 173 | Coll ections.sy nchronized Map( new H ashMap<Ins tanceReada bleByteCha nnel, Inst anceByteCh annelListe ner>() ); | |
| 174 | ||
| 175 | /* * | |
| 176 | * @return t he openWri teChannels | |
| 177 | * / | |
| 178 | pr otected Ma p<Instance WritableBy teChannel, InstanceB yteChannel Listener> getOpenWri teChannels () | |
| 179 | { | |
| 180 | retu rn this.op enWriteCha nnels; | |
| 181 | } | |
| 182 | ||
| 183 | /* * | |
| 184 | * @return t he openRea dChannels | |
| 185 | * / | |
| 186 | pr otected Ma p<Instance ReadableBy teChannel, InstanceB yteChannel Listener> getOpenRea dChannels( ) | |
| 187 | { | |
| 188 | retu rn this.op enReadChan nels; | |
| 189 | } | |
| 190 | ||
| 191 | pr otected vo id putWrit ableChanne l(Instance WritableBy teChannel writable, InstanceBy teChannelL istener li stener) | |
| 192 | { | |
| 193 | open WriteChann els.put(wr itable, li stener); | |
| 194 | } | |
| 195 | ||
| 196 | pr otected vo id putRead ableChanne l(Instance ReadableBy teChannel readable, InstanceBy teChannelL istener li stener) | |
| 197 | { | |
| 198 | open ReadChanne ls.put(rea dable, lis tener); | |
| 199 | } | |
| 200 | ||
| 201 | /* * | |
| 202 | * Look thro ugh our in ternal lis t of open writable c hannels an d return a | |
| 203 | * reference to the by te channel that is o pen on the given fil e, | |
| 204 | * or return null if n ot open. | |
| 205 | * | |
| 206 | * @param in stanceFile | |
| 207 | * @return | |
| 208 | * / | |
| 209 | ab stract pro tected Ins tanceWrita bleByteCha nnel getOp enWritable ByteChanne l(T instan ceFile); | |
| 210 | ||
| 211 | /* * | |
| 212 | * Look thro ugh our in ternal lis t of open readable c hannels an d return a | |
| 213 | * reference to the by te channel that is o pen on the given fil e, | |
| 214 | * or return null if n ot open. | |
| 215 | * | |
| 216 | * @param in stanceFile | |
| 217 | * @return | |
| 218 | * / | |
| 219 | ab stract pro tected Ins tanceReada bleByteCha nnel getOp enReadable ByteChanne l(T instan ceFile); | |
| 220 | ||
| 221 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========= | |
| 222 | // InstanceB yteChannel Factory Im plementati on | |
| 223 | // Statistic s Gatherin g Methods | |
| 224 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========= | |
| 225 | /* * | |
| 226 | * This is N OT an idem potent met hod, it RE MOVES the writable m ap entry. | |
| 227 | * | |
| 228 | * @param wr itable | |
| 229 | * / | |
| 230 | pr ivate void notifyTim eoutWritab leChannelL isteners(I nstanceWri tableByteC hannel wri table) | |
| 231 | { | |
| 232 | writ ableByteCh annelClose d(writable , true); | |
| 233 | } | |
| 234 | ||
| 235 | /* * | |
| 236 | * This is N OT an idem potent met hod, it RE MOVES the readable m ap entry. | |
| 237 | * | |
| 238 | * @param re adable | |
| 239 | * / | |
| 240 | pr ivate void notifyTim eoutReadab leChannelL isteners(I nstanceRea dableByteC hannel rea dable) | |
| 241 | { | |
| 242 | read ableByteCh annelClose d(readable , true); | |
| 243 | } | |
| 244 | ||
| 245 | ||
| 246 | /* * | |
| 247 | * Any shoul d call thi s to remov e the writ able byte channel, | |
| 248 | * else the listeners will get t imeout sig nals. | |
| 249 | * | |
| 250 | * NOTE: it would be b etter if t his method were prot ected and the bytes channels | |
| 251 | * were "fri end" class es but thi s isn't C+ +, so we d eclare the m public. | |
| 252 | * | |
| 253 | * @param wr itable | |
| 254 | * / | |
| 255 | pu blic void writableBy teChannelC losed(Inst anceWritab leByteChan nel writab le, boolea n errorClo se) | |
| 256 | { | |
| 257 | Inst anceByteCh annelListe ner listen er = openW riteChanne ls.get(wri table); | |
| 258 | open WriteChann els.remove (writable) ; | |
| 259 | ||
| 260 | if(l istener != null) | |
| 261 | { | |
| 262 | if(err orClose) | |
| 263 | listener .writeChan nelIdleTim eout(writa ble); | |
| 264 | else | |
| 265 | listener .writeChan nelClose(w ritable); | |
| 266 | } | |
| 267 | } | |
| 268 | /* * | |
| 269 | * A 'normal ' close sh ould call this to re move the r eadable by te channel , | |
| 270 | * else the listeners will get t imeout sig nals. | |
| 271 | * | |
| 272 | * NOTE: it would be b etter if t his method were prot ected and the bytes channels | |
| 273 | * were "fri end" class es but thi s isn't C+ +, so we d eclare the m public. | |
| 274 | * | |
| 275 | * @param re adable | |
| 276 | * / | |
| 277 | pu blic void readableBy teChannelC losed(Inst anceReadab leByteChan nel readab le, boolea n errorClo se) | |
| 278 | { | |
| 279 | Inst anceByteCh annelListe ner listen er = openR eadChannel s.get(read able); | |
| 280 | open ReadChanne ls.remove( readable); | |
| 281 | ||
| 282 | if(l istener != null) | |
| 283 | { | |
| 284 | if(err orClose) | |
| 285 | listener .readChann elIdleTime out(readab le); | |
| 286 | else | |
| 287 | listener .readChann elClose(re adable); | |
| 288 | } | |
| 289 | } | |
| 290 | ||
| 291 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== = | |
| 292 | // State per sistence i mplementat ion | |
| 293 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== = | |
| 294 | /* * | |
| 295 | * Create a Serializab le represe ntation of our state that may be | |
| 296 | * used late r to recre ate our st ate. | |
| 297 | * | |
| 298 | * @return | |
| 299 | * / | |
| 300 | pu blic ByteC hannelFact oryMemento createMem ento() | |
| 301 | { | |
| 302 | Byte ChannelFac toryMement o memento = new Byte ChannelFac toryMement o(); | |
| 303 | ||
| 304 | meme nto.setMax ChannelOpe nDuration( getMaxChan nelOpenDur ation()); | |
| 305 | meme nto.setSwe epTime(get SweepTime( )); | |
| 306 | meme nto.setChe cksumAlgor ithmName(g etChecksum Classname( )); | |
| 307 | ||
| 308 | retu rn memento ; | |
| 309 | } | |
| 310 | ||
| 311 | pu blic void restoreMem ento(ByteC hannelFact oryMemento memento) | |
| 312 | { | |
| 313 | setM axChannelO penDuratio n( memento .getMaxCha nnelOpenDu ration() ) ; | |
| 314 | setS weepTime( memento.ge tSweepTime () ); | |
| 315 | setC hecksumCla ssname(mem ento.getCh ecksumAlgo rithmName( )); | |
| 316 | } | |
| 317 | ||
| 318 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ====== | |
| 319 | // CacheLife cycleListe ner | |
| 320 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ====== | |
| 321 | pu blic void cacheLifec ycleEvent( CacheLifec ycleEvent event) thr ows CacheS tateExcept ion | |
| 322 | { | |
| 323 | if(e vent == Ca cheLifecyc leEvent.ST ART) | |
| 324 | { | |
| 325 | if(thi s.sweepTim e > 0L && this.maxCh annelOpenD uration > 0L) | |
| 326 | { | |
| 327 | cleanupT hread = ne w ChannelC leanupThre ad(); | |
| 328 | cleanupT hread.star t(); | |
| 329 | } | |
| 330 | } | |
| 331 | else if (event == CacheL ifecycleEv ent.STOP) | |
| 332 | { | |
| 333 | if(cle anupThread != null) | |
| 334 | cleanupT hread.kill (); | |
| 335 | } | |
| 336 | } | |
| 337 | ||
| 338 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ====== | |
| 339 | // JMX (mana gement) re lated meth ods (Dynam icMBean im plementati on) | |
| 340 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ====== | |
| 341 | ||
| 342 | /* * | |
| 343 | * @see java x.manageme nt.Dynamic MBean#getM BeanInfo() | |
| 344 | * / | |
| 345 | pr ivate MBea nInfo open MBeanInfo; | |
| 346 | pu blic synch ronized MB eanInfo ge tMBeanInfo () | |
| 347 | { | |
| 348 | if(o penMBeanIn fo == null ) | |
| 349 | { | |
| 350 | openMB eanInfo = new OpenMB eanInfoSup port( | |
| 351 | getClass() .getName() , | |
| 352 | "Byte chan nel factor y for file system ba sed cache implementa tions.", | |
| 353 | new OpenMB eanAttribu teInfo[] | |
| 354 | { | |
| 355 | ne w OpenMBea nAttribute InfoSuppor t("maxChan nelOpenDur ation", "M aximum tim e in milli seconds be tween chan nel usage" , SimpleTy pe.LONG, t rue, true, false), | |
| 356 | ne w OpenMBea nAttribute InfoSuppor t("sweepTi me", "Time to delay between sw eeping ope n channels ", SimpleT ype.LONG, true, true , false), | |
| 357 | ne w OpenMBea nAttribute InfoSuppor t("traceCh annelInsta ntiation", "Trace th e code tha t opened c hannels", SimpleType .BOOLEAN, true, true , true), | |
| 358 | ne w OpenMBea nAttribute InfoSuppor t("checksu mClassName ", "The cl ass or alg orithm nam e for chec ksum calcu lation", S impleType. STRING, tr ue, true, false), | |
| 359 | ne w OpenMBea nAttribute InfoSuppor t("openRea dableByteC hannels", "Number of read chan nels curre ntly open" , SimpleTy pe.INTEGER , true, fa lse, false ), | |
| 360 | ne w OpenMBea nAttribute InfoSuppor t("openWri tableByteC hannels", "Number of write cha nnels curr ently open ", SimpleT ype.INTEGE R, true, f alse, fals e) | |
| 361 | }, | |
| 362 | new OpenMB eanConstru ctorInfo[] {}, | |
| 363 | new OpenMB eanOperati onInfo[]{} , | |
| 364 | new MBeanN otificatio nInfo[]{} | |
| 365 | ); | |
| 366 | } | |
| 367 | ||
| 368 | retu rn openMBe anInfo; | |
| 369 | } | |
| 370 | ||
| 371 | /* * | |
| 372 | * @see java x.manageme nt.Dynamic MBean#getA ttribute(j ava.lang.S tring) | |
| 373 | * / | |
| 374 | pu blic Objec t getAttri bute(Strin g attribut e) | |
| 375 | th rows Attri buteNotFou ndExceptio n, MBeanEx ception, R eflectionE xception | |
| 376 | { | |
| 377 | if( "maxChanne lOpenDurat ion".equal s(attribut e) ) | |
| 378 | return new Long( getMaxChan nelOpenDur ation()); | |
| 379 | else if( "swee pTime".equ als(attrib ute) ) | |
| 380 | return new Long( getSweepTi me()); | |
| 381 | else if( "trac eChannelIn stantiatio n".equals( attribute) ) | |
| 382 | return new Boole an(isTrace ChannelIns tantiation ()); | |
| 383 | else if( "chec ksumClassN ame".equal s(attribut e) ) | |
| 384 | return getChecks umClassnam e(); | |
| 385 | else if( "open ReadableBy teChannels ".equals(a ttribute) ) | |
| 386 | return new Integ er(getCurr entlyOpenR eadableByt eChannels( )); | |
| 387 | else if( "open WritableBy teChannels ".equals(a ttribute) ) | |
| 388 | return new Integ er(getCurr entlyOpenW ritableByt eChannels( )); | |
| 389 | else | |
| 390 | throw new Attrib uteNotFoun dException ("Attribut e '" + att ribute + " ' not foun d"); | |
| 391 | } | |
| 392 | ||
| 393 | /* * | |
| 394 | * @see java x.manageme nt.Dynamic MBean#getA ttributes( java.lang. String[]) | |
| 395 | * / | |
| 396 | pu blic Attri buteList g etAttribut es(String[ ] attribut es) | |
| 397 | { | |
| 398 | Attr ibuteList list = new Attribute List(); | |
| 399 | for( String att ribute:att ributes) | |
| 400 | try | |
| 401 | { | |
| 402 | list.add ( new Attr ibute(attr ibute, get Attribute( attribute) ) ); | |
| 403 | } | |
| 404 | catch (Attribute NotFoundEx ception x) | |
| 405 | { | |
| 406 | x.printS tackTrace( ); | |
| 407 | } | |
| 408 | catch (MBeanExce ption x) | |
| 409 | { | |
| 410 | x.printS tackTrace( ); | |
| 411 | } | |
| 412 | catch (Reflectio nException x) | |
| 413 | { | |
| 414 | x.printS tackTrace( ); | |
| 415 | } | |
| 416 | retu rn list; | |
| 417 | } | |
| 418 | ||
| 419 | /* * | |
| 420 | * @see java x.manageme nt.Dynamic MBean#setA ttribute(j avax.manag ement.Attr ibute) | |
| 421 | * / | |
| 422 | pu blic void setAttribu te(Attribu te attribu te) | |
| 423 | th rows Attri buteNotFou ndExceptio n, Invalid AttributeV alueExcept ion, MBean Exception, Reflectio nException | |
| 424 | { | |
| 425 | try | |
| 426 | { | |
| 427 | if( "m axChannelO penDuratio n".equals( attribute. getName()) ) | |
| 428 | setMaxCh annelOpenD uration( ( Long)attri bute.getVa lue() ); | |
| 429 | else i f( "sweepT ime".equal s(attribut e.getName( )) ) | |
| 430 | setSweep Time( (Lon g)attribut e.getValue () ); | |
| 431 | else i f( "traceC hannelInst antiation" .equals(at tribute.ge tName()) ) | |
| 432 | setTrace ChannelIns tantiation ( (Boolean )attribute .getValue( ) ); | |
| 433 | else i f( "checks umClassNam e".equals( attribute. getName()) ) | |
| 434 | setCheck sumClassna me((String )attribute .getValue( ) ); | |
| 435 | else | |
| 436 | throw ne w Attribut eNotFoundE xception(" Attribute '" + attri bute + "' not found. "); | |
| 437 | } | |
| 438 | catc h (ClassCa stExceptio n x) | |
| 439 | { | |
| 440 | throw new Invali dAttribute ValueExcep tion("Attr ibute '" + attribute + "' valu es was of incorrect type."); | |
| 441 | } | |
| 442 | } | |
| 443 | ||
| 444 | /* * | |
| 445 | * @see java x.manageme nt.Dynamic MBean#setA ttributes( javax.mana gement.Att ributeList ) | |
| 446 | * / | |
| 447 | pu blic Attri buteList s etAttribut es(Attribu teList att ributes) | |
| 448 | { | |
| 449 | for( int index= 0; index < attribute s.size(); ++index) | |
| 450 | { | |
| 451 | Attrib ute attrib ute = (Att ribute)att ributes.ge t(index); | |
| 452 | ||
| 453 | try | |
| 454 | { | |
| 455 | setAttri bute(attri bute); | |
| 456 | } | |
| 457 | catch (Attribute NotFoundEx ception x) | |
| 458 | { | |
| 459 | x.printS tackTrace( ); | |
| 460 | } | |
| 461 | catch (InvalidAt tributeVal ueExceptio n x) | |
| 462 | { | |
| 463 | x.printS tackTrace( ); | |
| 464 | } | |
| 465 | catch (MBeanExce ption x) | |
| 466 | { | |
| 467 | x.printS tackTrace( ); | |
| 468 | } | |
| 469 | catch (Reflectio nException x) | |
| 470 | { | |
| 471 | x.printS tackTrace( ); | |
| 472 | } | |
| 473 | } | |
| 474 | ||
| 475 | retu rn attribu tes; | |
| 476 | } | |
| 477 | ||
| 478 | /* * | |
| 479 | * @see java x.manageme nt.Dynamic MBean#invo ke(java.la ng.String, java.lang .Object[], java.lang .String[]) | |
| 480 | * / | |
| 481 | pu blic Objec t invoke(S tring acti onName, Ob ject[] par ams, Strin g[] signat ure) | |
| 482 | th rows MBean Exception, Reflectio nException | |
| 483 | { | |
| 484 | retu rn null; | |
| 485 | } | |
| 486 | ||
| 487 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ====== | |
| 488 | // The threa d that mon itors and cleans up channels t hat have b een left h anging | |
| 489 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ====== | |
| 490 | /* * | |
| 491 | * | |
| 492 | * @author
|
|
| 493 | * | |
| 494 | * / | |
| 495 | cl ass Channe lCleanupTh read | |
| 496 | ex tends Thre ad | |
| 497 | { | |
| 498 | priv ate boolea n running = true; | |
| 499 | ||
| 500 | Chan nelCleanup Thread() | |
| 501 | { | |
| 502 | this.s etDaemon(t rue); | |
| 503 | } | |
| 504 | ||
| 505 | publ ic void ki ll() | |
| 506 | { | |
| 507 | this.r unning = f alse; | |
| 508 | this.i nterrupt() ; | |
| 509 | } | |
| 510 | ||
| 511 | @Ove rride | |
| 512 | publ ic void ru n() | |
| 513 | { | |
| 514 | while( running) | |
| 515 | { | |
| 516 | long min OpenTime = System.cu rrentTimeM illis() - getMaxChan nelOpenDur ation(); | |
| 517 | ||
| 518 | log.info ("Sweeping write cha nnels open before " + df.forma t(minOpenT ime)); | |
| 519 | try | |
| 520 | { | |
| 521 | List<Insta nceWritabl eByteChann el> writeC hannelKill List = new ArrayList <InstanceW ritableByt eChannel>( ); | |
| 522 | try | |
| 523 | { | |
| 524 | // do the ki ll/close i n two loop s to avoid concurren t modifica tion excep tions | |
| 525 | fo r( Instanc eWritableB yteChannel writeChan nel:openWr iteChannel s.keySet() ) | |
| 526 | { | |
| 527 | if( writeChann el.getLast AccessedTi me() < min OpenTime ) | |
| 528 | { | |
| 529 | log.wa rn("Writab le Byte Ch annel " + writeChann el.toStrin g() + " ha s remained open past the maxim um allowab le, forcin g close!" ); | |
| 530 | writeC hannelKill List.add(w riteChanne l); | |
| 531 | ||
| 532 | if(isT raceChanne lInstantia tion() && writeChann el instanc eof Tracab leComponen t) | |
| 533 | { | |
| 534 | StackTra ceElement[ ] instanti atingStack Trace = | |
| 535 | ((Tracable Component) writeChann el).getIns tantiating StackTrace (); | |
| 536 | warnInst antiatingS tackTrace( instantiat ingStackTr ace); | |
| 537 | } | |
| 538 | } | |
| 539 | } | |
| 540 | } | |
| 541 | catch(Conc urrentModi ficationEx ception cm X) | |
| 542 | { | |
| 543 | // note that if we get a concurr ent modifi cation (i. e. another thread is opening o r closing readable c hannels) | |
| 544 | // then log it but don 't fail 'c ause we ca n always c lose the c hannel lat er | |
| 545 | lo g.info("Co ncurrent m odificatio n exceptio n while it erating op en write c hannels, s ome overdu e channels may not b e closed i mmediately ."); | |
| 546 | } | |
| 547 | ||
| 548 | log.info(" Closing " + writeCha nnelKillLi st.size() + " write channels d ue to inac tivity tim eout"); | |
| 549 | for(Instan ceWritable ByteChanne l deadChan nel:writeC hannelKill List) | |
| 550 | { | |
| 551 | tr y | |
| 552 | { | |
| 553 | dead Channel.er ror(); | |
| 554 | } | |
| 555 | ca tch (IOExc eption e) | |
| 556 | { | |
| 557 | log. error(e); | |
| 558 | } | |
| 559 | no tifyTimeou tWritableC hannelList eners(dead Channel); | |
| 560 | op enWriteCha nnels.remo ve(deadCha nnel); | |
| 561 | } | |
| 562 | ||
| 563 | log.info(" Sweeping r ead channe ls open be fore " + d f.format(m inOpenTime )); | |
| 564 | List<Insta nceReadabl eByteChann el> readCh annelKillL ist = new ArrayList< InstanceRe adableByte Channel>() ; | |
| 565 | ||
| 566 | // do the kill/close in two lo ops to avo id concurr ent modifi cation exc eptions | |
| 567 | try | |
| 568 | { | |
| 569 | fo r( Instanc eReadableB yteChannel readChann el:openRea dChannels. keySet() ) | |
| 570 | { | |
| 571 | if( readChanne l.getLastA ccessedTim e() < minO penTime ) | |
| 572 | { | |
| 573 | log.wa rn("Readab le Byte Ch annel " + readChanne l.toString () + " has remained open past the maximu m allowabl e, notifyi ng listene rs" ); | |
| 574 | readCh annelKillL ist.add(re adChannel) ; | |
| 575 | ||
| 576 | if(isT raceChanne lInstantia tion() && readChanne l instance of Tracabl eComponent ) | |
| 577 | { | |
| 578 | StackTra ceElement[ ] instanti atingStack Trace = | |
| 579 | ((Tracable Component) readChanne l).getInst antiatingS tackTrace( ); | |
| 580 | warnInst antiatingS tackTrace( instantiat ingStackTr ace); | |
| 581 | } | |
| 582 | } | |
| 583 | } | |
| 584 | } | |
| 585 | catch(Conc urrentModi ficationEx ception cm X) | |
| 586 | { | |
| 587 | // note that if we get a concurr ent modifi cation (i. e. another thread is opening o r closing readable c hannels) | |
| 588 | // then log it but don 't fail 'c ause we ca n always c lose the c hannel lat er | |
| 589 | lo g.info("Co ncurrent m odificatio n exceptio n while it erating op en read ch annels, so me overdue channels may not be closed im mediately. "); | |
| 590 | } | |
| 591 | ||
| 592 | log.info(" Closing " + readChan nelKillLis t.size() + " read ch annels due to inacti vity timeo ut"); | |
| 593 | for(Instan ceReadable ByteChanne l deadChan nel:readCh annelKillL ist) | |
| 594 | { | |
| 595 | tr y | |
| 596 | { | |
| 597 | dead Channel.cl ose(); | |
| 598 | } | |
| 599 | ca tch (IOExc eption e) | |
| 600 | { | |
| 601 | log. error(e); | |
| 602 | } | |
| 603 | no tifyTimeou tReadableC hannelList eners(dead Channel); | |
| 604 | op enReadChan nels.remov e(deadChan nel); | |
| 605 | } | |
| 606 | ||
| 607 | sleep(getS weepTime() ); | |
| 608 | } | |
| 609 | catch (I nterrupted Exception e) | |
| 610 | { | |
| 611 | // if some one interr upts us th en run the thread ou t, we're d one | |
| 612 | break; | |
| 613 | } | |
| 614 | } | |
| 615 | } | |
| 616 | ||
| 617 | /* | |
| 618 | * L og warning about who is leavin g channels open, if the info i s availabl e, else | |
| 619 | * j ujst log m essages th at a chann el was lef t open. | |
| 620 | */ | |
| 621 | priv ate void w arnInstant iatingStac kTrace(Sta ckTraceEle ment[] ins tantiating StackTrace ) | |
| 622 | { | |
| 623 | if(ins tantiating StackTrace != null) | |
| 624 | { | |
| 625 | StackTra ceAnalyzer stAnalyze r = new St ackTraceAn alyzer(ins tantiating StackTrace ); | |
| 626 | StackTra ceElement element = stAnalyzer .getFirstE lementNotI nPackageHi erarchy("g ov.va.med. imaging.st orage.cach e"); | |
| 627 | if(eleme nt != null ) | |
| 628 | log.warn(" Method '" + element. getClassNa me() + "." + element .getMethod Name() + " ' (or some thing it c alls) is o pening cha nnels that are not b eing close d." + | |
| 629 | "Ent ire call s tack is:\n " + stAnal yzer.toStr ing()); | |
| 630 | else | |
| 631 | log.warn(" Some metho d in this stack trac e is openi ng channel s that are not being closed:\n " + stAnal yzer.toStr ing()); | |
| 632 | } | |
| 633 | else | |
| 634 | log.warn ("Stack Tr ace analys is of chan nel instan tiating me thod is no t availabl e. Turn T raceChanne lInstantia tion on to find the offending code."); | |
| 635 | ||
| 636 | } | |
| 637 | } // end ChannelCl eanup | |
| 638 | ||
| 639 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.