Produced by Araxis Merge on 12/5/2017 12:06:38 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\CoreValueObjects\main\src\java\gov\va\med\imaging\exchange\storage | ByteBufferPool.java | Mon Dec 4 21:35:00 2017 UTC |
| 2 | IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\CoreValueObjects\main\src\java\gov\va\med\imaging\exchange\storage | ByteBufferPool.java | Mon Dec 4 21:58:56 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 3 | 646 |
| 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 | Package: MAG - Vis tA Imaging | |
| 4 | WARNING: Per VHA D irective 2 004-038, t his routin e should n ot be modi fied. | |
| 5 | Date Cre ated: Sep 30, 2008 | |
| 6 | Site Nam e: Washin gton OI Fi eld Office , Silver S pring, MD | |
| 7 | Developer:
|
|
| 8 | Descript ion: | |
| 9 | ||
| 10 | ;; +-------- ---------- ---------- ---------- ---------- ---------- ---------- + | |
| 11 | ;; Property of the US Government . | |
| 12 | ;; No permis sion to co py or redi stribute t his softwa re is give n. | |
| 13 | ;; Use of un released v ersions of this soft ware requi res the us er | |
| 14 | ;; to execu te a writt en test ag reement wi th the Vis tA Imaging | |
| 15 | ;; Developm ent Office of the De partment o f Veterans Affairs, | |
| 16 | ;; telephon e (301) 73 4-0100. | |
| 17 | ;; | |
| 18 | ;; The Food and Drug A dministrat ion classi fies this software a s | |
| 19 | ;; a Class I I medical device. A s such, it may not b e changed | |
| 20 | ;; in any wa y. Modifi cations to this soft ware may r esult in a n | |
| 21 | ;; adulterat ed medical device un der 21CFR8 20, the us e of which | |
| 22 | ;; is consid ered to be a violati on of US F ederal Sta tutes. | |
| 23 | ;; +-------- ---------- ---------- ---------- ---------- ---------- ---------- + | |
| 24 | ||
| 25 | */ | |
| 26 | package go v.va.med.i maging.exc hange.stor age; | |
| 27 | ||
| 28 | import gov .va.med.im aging.exch ange.TaskS cheduler; | |
| 29 | ||
| 30 | import jav a.nio.Byte Buffer; | |
| 31 | import jav a.util.Arr ayList; | |
| 32 | import jav a.util.Lis t; | |
| 33 | import jav a.util.Tim erTask; | |
| 34 | ||
| 35 | import org .apache.lo gging.log4 j.LogManag er; | |
| 36 | import org .apache.lo gging.log4 j.Logger; | |
| 37 | ||
| 38 | /** | |
| 39 | * Extensi on of Arra yList that contains ByteBuffer s. This li st holds t he ByteBuf fers and k nows how | |
| 40 | * large o f buffers it creates and holds on to. | |
| 41 | * | |
| 42 | * @author
|
|
| 43 | * | |
| 44 | */ | |
| 45 | public cla ss ByteBuf ferPool | |
| 46 | extends Ti merTask | |
| 47 | implements Comparabl e<ByteBuff erPool>, | |
| 48 | ByteBuffer PoolMBean | |
| 49 | { | |
| 50 | pr ivate stat ic final l ong serial VersionUID = -287130 4395412112 847L; | |
| 51 | pr ivate fina l static L ogger logg er = LogMa nager.getL ogger(Byte BufferPool .class); | |
| 52 | ||
| 53 | pr ivate fina l static l ong BYTE_B UFFER_POOL _TIMER_REF RESH = 100 0 * 60 * 1 5; // 15 m inutes | |
| 54 | ||
| 55 | pr ivate List <ByteBuffe r> byteBuf fers = nul l; | |
| 56 | ||
| 57 | pr ivate fina l int maxB ufferSizeI nBytes; | |
| 58 | pr ivate fina l String n ame; | |
| 59 | ||
| 60 | // the prefe rred max n umber of b uffers in this pool (when a cl eanup occu rs, bring down to th is amount) | |
| 61 | pr ivate fina l int pref erredBuffe rMaxCount; | |
| 62 | // the maxim um number of buffers in the po ol allowed (should n ever excee d this val ue) | |
| 63 | pr ivate fina l int maxB ufferCount ; | |
| 64 | ||
| 65 | // Counters for JMX MB eans | |
| 66 | in t requestB ufferCount = 0; | |
| 67 | in t returnBu fferCount = 0; | |
| 68 | in t createNe wBufferCou nt = 0; | |
| 69 | lo ng bufferS izeUsage = 0; | |
| 70 | ||
| 71 | /* * | |
| 72 | * Create an empty buf fer list o f the spec ified size | |
| 73 | * @param na me | |
| 74 | * @param ma xBufferSiz eInbytes | |
| 75 | * @return | |
| 76 | * / | |
| 77 | pu blic stati c ByteBuff erPool cre ateByteBuf ferList(St ring name, int maxBu fferSizeIn bytes, int preferred PoolSize) | |
| 78 | { | |
| 79 | logg er.info("C reating By teBufferMi nimumSizeL ist of [" + maxBuffe rSizeInbyt es + " buf fer sizes named [" + name + "] "); | |
| 80 | Byte BufferPool list = ne w ByteBuff erPool(nam e, maxBuff erSizeInby tes, prefe rredPoolSi ze); | |
| 81 | retu rn list; | |
| 82 | } | |
| 83 | ||
| 84 | /* * | |
| 85 | * Create a buffer lis t of the s pecified s ize with t he specifi ed number of buffers in it ini tially. | |
| 86 | * @param na me | |
| 87 | * @param ma xBufferSiz eInbytes | |
| 88 | * @param in itialBuffe rs | |
| 89 | * @return | |
| 90 | * / | |
| 91 | pu blic stati c ByteBuff erPool cre ateByteBuf ferList(St ring name, int maxBu fferSizeIn bytes, | |
| 92 | int preferredP oolSize, i nt initial Buffers) | |
| 93 | { | |
| 94 | Byte BufferPool list = cr eateByteBu fferList(n ame, maxBu fferSizeIn bytes, pre ferredPool Size); | |
| 95 | for( int i = 0; i < initi alBuffers; i++) | |
| 96 | { | |
| 97 | ByteBu ffer b = l ist.create NewBuffer( 0); | |
| 98 | list.r eturnBuffe rToList(b) ; | |
| 99 | } | |
| 100 | // reset the counters s o adding t he buffers doesn't i ncrement t he counts | |
| 101 | list .resetCoun ters(); | |
| 102 | retu rn list; | |
| 103 | } | |
| 104 | ||
| 105 | /* * | |
| 106 | * Internal constructo r | |
| 107 | * @param na me | |
| 108 | * @param ma xBufferSiz e | |
| 109 | * / | |
| 110 | pr ivate Byte BufferPool (String na me, int ma xBufferSiz e, int pre ferredPool Size) | |
| 111 | { | |
| 112 | byte Buffers = new ArrayL ist<ByteBu ffer>(); | |
| 113 | this .name = na me; | |
| 114 | this .maxBuffer SizeInByte s = maxBuf ferSize; | |
| 115 | // s et these t o better d efaults, a llow input parameter s for thes e | |
| 116 | this .maxBuffer Count = 10 0; | |
| 117 | this .preferred BufferMaxC ount = pre ferredPool Size; | |
| 118 | ||
| 119 | logg er.info("S cheduling byte buffe r pool '" + name + " ' every [" + BYTE_BU FFER_POOL_ TIMER_REFR ESH + "] m s"); | |
| 120 | Task Scheduler. getTaskSch eduler().s chedule(th is, BYTE_B UFFER_POOL _TIMER_REF RESH, BYTE _BUFFER_PO OL_TIMER_R EFRESH); | |
| 121 | } | |
| 122 | ||
| 123 | ||
| 124 | /* (non-Java doc) | |
| 125 | * @see java .util.Time rTask#run( ) | |
| 126 | * / | |
| 127 | @O verride | |
| 128 | pu blic void run() | |
| 129 | { | |
| 130 | sync hronized ( byteBuffer s) | |
| 131 | { | |
| 132 | if(byt eBuffers.s ize() > pr eferredBuf ferMaxCoun t) | |
| 133 | { | |
| 134 | logger.i nfo("ByteB uffer Pool '" + name + "' has [" + byteB uffers.siz e() + "] b uffers, mo re than pr eferred am ount [" + preferredB ufferMaxCo unt + "]") ; | |
| 135 | int buff ersToRemov e = byteBu ffers.size () - prefe rredBuffer MaxCount; | |
| 136 | logger.i nfo("Remov ing [" + b uffersToRe move + "] buffers fr om buffer pool '" + name + "'" ); | |
| 137 | // Want to start f rom the hi ghest numb er because it is mor e efficien t to remov e | |
| 138 | // from the end of the list so pointer s do not n eed to be reorganize d. | |
| 139 | for(int i = byteBu ffers.size () - 1; i >= preferr edBufferMa xCount; i- -) | |
| 140 | { | |
| 141 | logger.deb ug("Removi ng buffer at index [ " + i + "] from buff er pool '" + name + "'"); | |
| 142 | byteBuffer s.remove(i ); | |
| 143 | } | |
| 144 | } | |
| 145 | else | |
| 146 | { | |
| 147 | logger.d ebug("Byte Buffer poo l '" + nam e + "' con tains [" + byteBuffe rs.size() + "] buffe rs, less t han [" + p referredBu fferMaxCou nt + "] pr eferred bu ffers, not cleaning up"); | |
| 148 | } | |
| 149 | } | |
| 150 | } | |
| 151 | ||
| 152 | /* * | |
| 153 | * Create a new buffer of the si ze this bu ffer list contains | |
| 154 | * @return | |
| 155 | * / | |
| 156 | pu blic ByteB uffer crea teNewBuffe r(int buff erUseSize) | |
| 157 | { | |
| 158 | logg er.info("C reating ne w ByteBuff er in '" + this + "' "); | |
| 159 | if(t his.maxBuf ferSizeInB ytes <= 0) | |
| 160 | { | |
| 161 | return null; | |
| 162 | } | |
| 163 | crea teNewBuffe rCount++; | |
| 164 | this .bufferSiz eUsage += bufferUseS ize; | |
| 165 | Byte Buffer buf fer = Byte Buffer.all ocate(this .maxBuffer SizeInByte s); | |
| 166 | retu rn buffer; | |
| 167 | } | |
| 168 | ||
| 169 | /* * | |
| 170 | * @return t he maxBuff erSize | |
| 171 | * / | |
| 172 | pu blic int g etMaxBuffe rSizeInByt es() { | |
| 173 | retu rn maxBuff erSizeInBy tes; | |
| 174 | } | |
| 175 | ||
| 176 | pu blic ByteB uffer remo veBufferFr omList(int bufferUse Size) | |
| 177 | { | |
| 178 | sync hronized ( byteBuffer s) | |
| 179 | { | |
| 180 | if(byt eBuffers.s ize() > 0) | |
| 181 | { | |
| 182 | this.buf ferSizeUsa ge += buff erUseSize; | |
| 183 | requestB ufferCount ++; | |
| 184 | return b yteBuffers .remove(0) ; | |
| 185 | } | |
| 186 | return null; | |
| 187 | } | |
| 188 | } | |
| 189 | ||
| 190 | pu blic boole an returnB ufferToLis t(ByteBuff er buff) | |
| 191 | { | |
| 192 | sync hronized ( byteBuffer s) | |
| 193 | { | |
| 194 | return BufferCoun t++; | |
| 195 | return byteBuffe rs.add(buf f); | |
| 196 | } | |
| 197 | } | |
| 198 | ||
| 199 | /* (non-Java doc) | |
| 200 | * @see java .util.Abst ractCollec tion#toStr ing() | |
| 201 | * / | |
| 202 | @O verride | |
| 203 | pu blic Strin g toString () | |
| 204 | { | |
| 205 | retu rn "ByteBu fferPool n amed [" + this.name + "] curre ntly holdi ng [" + by teBuffers. size() + " ] buffers" ; | |
| 206 | } | |
| 207 | ||
| 208 | /* (non-Java doc) | |
| 209 | * @see java .lang.Comp arable#com pareTo(jav a.lang.Obj ect) | |
| 210 | * / | |
| 211 | @O verride | |
| 212 | pu blic int c ompareTo(B yteBufferP ool that) | |
| 213 | { | |
| 214 | if(t his.maxBuf ferSizeInB ytes < tha t.maxBuffe rSizeInByt es) | |
| 215 | return -1; | |
| 216 | if(t his.maxBuf ferSizeInB ytes > tha t.maxBuffe rSizeInByt es) | |
| 217 | return 1; | |
| 218 | retu rn 0; | |
| 219 | } | |
| 220 | ||
| 221 | /* * | |
| 222 | * @return t he name | |
| 223 | * / | |
| 224 | pu blic Strin g getName( ) { | |
| 225 | retu rn name; | |
| 226 | } | |
| 227 | ||
| 228 | /* (non-Java doc) | |
| 229 | * @see gov. va.med.ima ging.excha nge.storag e.ByteBuff erMinimumS izeListMBe an#getBuff erListSize () | |
| 230 | * / | |
| 231 | @O verride | |
| 232 | pu blic int g etBufferLi stSize() | |
| 233 | { | |
| 234 | retu rn this.by teBuffers. size(); | |
| 235 | } | |
| 236 | ||
| 237 | /* (non-Java doc) | |
| 238 | * @see gov. va.med.ima ging.excha nge.storag e.ByteBuff erMinimumS izeListMBe an#getBuff erMaxFileS ize() | |
| 239 | * / | |
| 240 | @O verride | |
| 241 | pu blic int g etBufferMa xFileSize( ) | |
| 242 | { | |
| 243 | retu rn maxBuff erSizeInBy tes; | |
| 244 | } | |
| 245 | ||
| 246 | /* (non-Java doc) | |
| 247 | * @see gov. va.med.ima ging.excha nge.storag e.ByteBuff erMinimumS izeListMBe an#getCrea teNewBuffe rCount() | |
| 248 | * / | |
| 249 | @O verride | |
| 250 | pu blic int g etCreateNe wBufferCou nt() | |
| 251 | { | |
| 252 | retu rn createN ewBufferCo unt; | |
| 253 | } | |
| 254 | ||
| 255 | /* (non-Java doc) | |
| 256 | * @see gov. va.med.ima ging.excha nge.storag e.ByteBuff erMinimumS izeListMBe an#getRequ estBufferC ount() | |
| 257 | * / | |
| 258 | @O verride | |
| 259 | pu blic int g etRequestB ufferCount () | |
| 260 | { | |
| 261 | retu rn request BufferCoun t; | |
| 262 | } | |
| 263 | ||
| 264 | /* (non-Java doc) | |
| 265 | * @see gov. va.med.ima ging.excha nge.storag e.ByteBuff erMinimumS izeListMBe an#getRetu rnBufferCo unt() | |
| 266 | * / | |
| 267 | @O verride | |
| 268 | pu blic int g etReturnBu fferCount( ) | |
| 269 | { | |
| 270 | retu rn returnB ufferCount ; | |
| 271 | } | |
| 272 | ||
| 273 | /* (non-Java doc) | |
| 274 | * @see gov. va.med.ima ging.excha nge.storag e.ByteBuff erMinimumS izeListMBe an#resetCo unters() | |
| 275 | * / | |
| 276 | @O verride | |
| 277 | pu blic void resetCount ers() | |
| 278 | { | |
| 279 | this .requestBu fferCount = 0; | |
| 280 | this .returnBuf ferCount = 0; | |
| 281 | this .createNew BufferCoun t = 0; | |
| 282 | this .bufferSiz eUsage = 0 ; | |
| 283 | } | |
| 284 | ||
| 285 | /* (non-Java doc) | |
| 286 | * @see gov. va.med.ima ging.excha nge.storag e.ByteBuff erMinimumS izeListMBe an#getMaxi mumBufferC ount() | |
| 287 | * / | |
| 288 | @O verride | |
| 289 | pu blic int g etMaximumB ufferCount () | |
| 290 | { | |
| 291 | retu rn maxBuff erCount; | |
| 292 | } | |
| 293 | ||
| 294 | /* (non-Java doc) | |
| 295 | * @see gov. va.med.ima ging.excha nge.storag e.ByteBuff erMinimumS izeListMBe an#getPref erredBuffe rCount() | |
| 296 | * / | |
| 297 | @O verride | |
| 298 | pu blic int g etPreferre dBufferCou nt() | |
| 299 | { | |
| 300 | retu rn preferr edBufferMa xCount; | |
| 301 | } | |
| 302 | ||
| 303 | /* (non-Java doc) | |
| 304 | * @see gov. va.med.ima ging.excha nge.storag e.ByteBuff erPoolMBea n#getAvera geBufferSi zeUse() | |
| 305 | * / | |
| 306 | @O verride | |
| 307 | pu blic doubl e getAvera geBufferSi zeUse() | |
| 308 | { | |
| 309 | int count = re questBuffe rCount + c reateNewBu fferCount; | |
| 310 | if(c ount > 0) | |
| 311 | { | |
| 312 | return (double)b ufferSizeU sage / cou nt; | |
| 313 | } | |
| 314 | retu rn 0.0f; | |
| 315 | } | |
| 316 | ||
| 317 | /* (non-Java doc) | |
| 318 | * @see gov. va.med.ima ging.excha nge.storag e.ByteBuff erPoolMBea n#getBuffe rSizeUse() | |
| 319 | * / | |
| 320 | @O verride | |
| 321 | pu blic long getBufferS izeUse() | |
| 322 | { | |
| 323 | retu rn bufferS izeUsage; | |
| 324 | } | |
| 325 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.