Produced by Araxis Merge on 7/10/2017 1:01:43 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\ImagingCacheImpl\main\src\java\gov\va\med\imaging\storage\cache\impl\memory | MemoryInstanceByteChannelFactory.java | Thu Jun 29 17:22:11 2017 UTC |
| 2 | C:\AraxisMergeCompare\Pri_re\IV-ehmp_cif\ImagingCacheImpl\main\src\java\gov\va\med\imaging\storage\cache\impl\memory | MemoryInstanceByteChannelFactory.java | Thu Jul 6 15:02:20 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 4 | 696 |
| 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 | * | |
| 3 | */ | |
| 4 | package go v.va.med.i maging.sto rage.cache .impl.memo ry; | |
| 5 | ||
| 6 | import gov .va.med.im aging.stor age.cache. InstanceBy teChannelF actory; | |
| 7 | import gov .va.med.im aging.stor age.cache. InstanceBy teChannelL istener; | |
| 8 | import gov .va.med.im aging.stor age.cache. InstanceRe adableByte Channel; | |
| 9 | import gov .va.med.im aging.stor age.cache. InstanceWr itableByte Channel; | |
| 10 | import gov .va.med.im aging.stor age.cache. exceptions .CacheExce ption; | |
| 11 | import gov .va.med.im aging.stor age.cache. exceptions .Persisten ceIOExcept ion; | |
| 12 | import gov .va.med.im aging.stor age.cache. impl.memor y.data.Mem oryInstanc eData; | |
| 13 | import gov .va.med.im aging.stor age.cache. impl.memor y.data.Mem oryInstanc eDataFacto ry; | |
| 14 | import gov .va.med.im aging.stor age.cache. memento.By teChannelF actoryMeme nto; | |
| 15 | ||
| 16 | import jav a.io.File; | |
| 17 | import jav a.io.IOExc eption; | |
| 18 | import jav a.nio.Byte Buffer; | |
| 19 | import jav a.util.Has hSet; | |
| 20 | import jav a.util.Set ; | |
| 21 | import jav a.util.zip .Checksum; | |
| 22 | ||
| 23 | /** | |
| 24 | * @author
|
|
| 25 | * | |
| 26 | */ | |
| 27 | public cla ss MemoryI nstanceByt eChannelFa ctory | |
| 28 | implements InstanceB yteChannel Factory<In teger>, In stanceByte ChannelLis tener | |
| 29 | { | |
| 30 | pu blic final static in t maxInsta nceSize = 4096; | |
| 31 | pr ivate long sweepTime = 1000; | |
| 32 | pr ivate long maxChanne lOpenDurat ion = 1000 0; | |
| 33 | pr ivate bool ean traceC hannelInst antiation; | |
| 34 | pr ivate int currentlyO penReadabl eByteChann els = 0; | |
| 35 | pr ivate int currentlyO penWritabl eByteChann els = 0; | |
| 36 | pr ivate Memo ryInstance DataFactor y instance Factory; | |
| 37 | ||
| 38 | pu blic Memor yInstanceB yteChannel Factory(Me moryInstan ceDataFact ory instan ceFactory) | |
| 39 | { | |
| 40 | this .instanceF actory = i nstanceFac tory; | |
| 41 | } | |
| 42 | ||
| 43 | pu blic Memor yInstanceD ataFactory getInstan ceFactory( ) | |
| 44 | { | |
| 45 | retu rn instanc eFactory; | |
| 46 | } | |
| 47 | ||
| 48 | pu blic int g etCurrentl yOpenReada bleByteCha nnels() | |
| 49 | { | |
| 50 | retu rn current lyOpenRead ableByteCh annels; | |
| 51 | } | |
| 52 | ||
| 53 | pu blic int g etCurrentl yOpenWrita bleByteCha nnels() | |
| 54 | { | |
| 55 | retu rn current lyOpenWrit ableByteCh annels; | |
| 56 | } | |
| 57 | ||
| 58 | /* (non-Java doc) | |
| 59 | * @see gov. va.med.ima ging.stora ge.cache.I nstanceByt eChannelFa ctory#getI nstanceRea dableByteC hannel(jav a.lang.Obj ect, gov.v a.med.imag ing.storag e.cache.In stanceByte ChannelLis tener) | |
| 60 | * / | |
| 61 | pu blic Insta nceReadabl eByteChann el getInst anceReadab leByteChan nel(Intege r instance Id, Instan ceByteChan nelListene r timeoutL istener) | |
| 62 | th rows Persi stenceIOEx ception, C acheExcept ion | |
| 63 | { | |
| 64 | Memo ryInstance Data insta nce = getI nstanceFac tory().get (instanceI d); | |
| 65 | if(i nstance != null) | |
| 66 | { | |
| 67 | Instan ceReadable ByteChanne l readable = new Moc kInstanceR eadableByt eChannel(i nstance); | |
| 68 | ++curr entlyOpenR eadableByt eChannels; | |
| 69 | return readable; | |
| 70 | } | |
| 71 | ||
| 72 | retu rn null; | |
| 73 | } | |
| 74 | ||
| 75 | /* (non-Java doc) | |
| 76 | * @see gov. va.med.ima ging.stora ge.cache.I nstanceByt eChannelFa ctory#getI nstanceWri tableByteC hannel(jav a.lang.Obj ect, gov.v a.med.imag ing.storag e.cache.In stanceByte ChannelLis tener) | |
| 77 | * / | |
| 78 | pu blic Insta nceWritabl eByteChann el getInst anceWritab leByteChan nel(Intege r instance Id, Instan ceByteChan nelListene r timeoutL istener) | |
| 79 | th rows Persi stenceIOEx ception, C acheExcept ion | |
| 80 | { | |
| 81 | Memo ryInstance Data insta nceData = getInstanc eFactory() .getOrCrea te(instanc eId, maxIn stanceSize ); | |
| 82 | Inst anceWritab leByteChan nel writab le = new M ockInstanc eWritableB yteChannel (instanceD ata); | |
| 83 | ++cu rrentlyOpe nReadableB yteChannel s; | |
| 84 | retu rn writabl e; | |
| 85 | } | |
| 86 | ||
| 87 | /* * | |
| 88 | * @param id | |
| 89 | * / | |
| 90 | pu blic void remove(Int eger insta nceId) | |
| 91 | { | |
| 92 | getI nstanceFac tory().ins tanceRemov ed(instanc eId); | |
| 93 | } | |
| 94 | ||
| 95 | /* (non-Java doc) | |
| 96 | * @see gov. va.med.ima ging.stora ge.cache.I nstanceByt eChannelFa ctory#getM axChannelO penDuratio n() | |
| 97 | * / | |
| 98 | pu blic long getMaxChan nelOpenDur ation() | |
| 99 | { | |
| 100 | retu rn maxChan nelOpenDur ation; | |
| 101 | } | |
| 102 | ||
| 103 | pu blic void setMaxChan nelOpenDur ation(long max) | |
| 104 | { | |
| 105 | this .maxChanne lOpenDurat ion = max; | |
| 106 | } | |
| 107 | ||
| 108 | pu blic long getSweepTi me() | |
| 109 | { | |
| 110 | retu rn sweepTi me; | |
| 111 | } | |
| 112 | ||
| 113 | pu blic void setSweepTi me(long sw eep) | |
| 114 | { | |
| 115 | this .sweepTime = sweep; | |
| 116 | } | |
| 117 | ||
| 118 | /* (non-Java doc) | |
| 119 | * @see gov. va.med.ima ging.stora ge.cache.I nstanceByt eChannelFa ctory#isTr aceChannel Instantiat ion() | |
| 120 | * / | |
| 121 | pu blic boole an isTrace ChannelIns tantiation () | |
| 122 | { | |
| 123 | retu rn traceCh annelInsta ntiation; | |
| 124 | } | |
| 125 | ||
| 126 | pu blic void setTraceCh annelInsta ntiation(b oolean tra ceChannelI nstantiati on) | |
| 127 | { | |
| 128 | this .traceChan nelInstant iation = t raceChanne lInstantia tion; | |
| 129 | } | |
| 130 | ||
| 131 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ======= | |
| 132 | // InstanceB yteChannel Listener | |
| 133 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ======= | |
| 134 | pu blic void readChanne lClose(Ins tanceReada bleByteCha nnel reada ble) | |
| 135 | { | |
| 136 | --cu rrentlyOpe nReadableB yteChannel s; | |
| 137 | } | |
| 138 | ||
| 139 | pu blic void readChanne lIdleTimeo ut(Instanc eReadableB yteChannel readable) | |
| 140 | { | |
| 141 | --cu rrentlyOpe nReadableB yteChannel s; | |
| 142 | } | |
| 143 | ||
| 144 | pu blic void writeChann elClose(In stanceWrit ableByteCh annel writ able) | |
| 145 | { | |
| 146 | --cu rrentlyOpe nWritableB yteChannel s; | |
| 147 | } | |
| 148 | ||
| 149 | pu blic void writeChann elIdleTime out(Instan ceWritable ByteChanne l writable ) | |
| 150 | { | |
| 151 | --cu rrentlyOpe nWritableB yteChannel s; | |
| 152 | } | |
| 153 | ||
| 154 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ======= | |
| 155 | // State Ser ialization | |
| 156 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ======= | |
| 157 | pu blic ByteC hannelFact oryMemento createMem ento() | |
| 158 | { | |
| 159 | retu rn null; | |
| 160 | } | |
| 161 | ||
| 162 | pu blic void restoreMem ento(ByteC hannelFact oryMemento memento) | |
| 163 | { | |
| 164 | } | |
| 165 | ||
| 166 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ======= | |
| 167 | // ByteChann el Realiza tions | |
| 168 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ======= | |
| 169 | /* * | |
| 170 | * | |
| 171 | * @author
|
|
| 172 | * | |
| 173 | * / | |
| 174 | cl ass MockIn stanceRead ableByteCh annel | |
| 175 | im plements I nstanceRea dableByteC hannel | |
| 176 | { | |
| 177 | priv ate Memory InstanceDa ta instanc eData; | |
| 178 | int position = 0; | |
| 179 | priv ate boolea n open = t rue; // t he channel is open w hen it is created | |
| 180 | ||
| 181 | publ ic MockIns tanceReada bleByteCha nnel(Memor yInstanceD ata instan ceData) | |
| 182 | { | |
| 183 | this.i nstanceDat a = instan ceData; | |
| 184 | } | |
| 185 | ||
| 186 | publ ic Checksu m getCheck sum() | |
| 187 | { | |
| 188 | return null; | |
| 189 | } | |
| 190 | ||
| 191 | publ ic int rea d(ByteBuff er dst) | |
| 192 | thro ws IOExcep tion | |
| 193 | { | |
| 194 | if( !o pen ) | |
| 195 | throw ne w IOExcept ion("Inval id state, channel is already c losed."); | |
| 196 | ||
| 197 | int by tesRead = Math.min(i nstanceDat a.getLimit () - posit ion, dst.r emaining() ); | |
| 198 | if(byt esRead > 0 ) | |
| 199 | dst.put( instanceDa ta.read(po sition, by tesRead)); | |
| 200 | ||
| 201 | positi on += byte sRead; | |
| 202 | ||
| 203 | return bytesRead ; | |
| 204 | } | |
| 205 | ||
| 206 | publ ic void cl ose() | |
| 207 | thro ws IOExcep tion | |
| 208 | { | |
| 209 | open = false; | |
| 210 | notify Listeners( false); | |
| 211 | } | |
| 212 | ||
| 213 | publ ic void er ror() | |
| 214 | thro ws IOExcep tion | |
| 215 | { | |
| 216 | open = false; | |
| 217 | notify Listeners( true); | |
| 218 | } | |
| 219 | ||
| 220 | publ ic boolean isOpen() | |
| 221 | { | |
| 222 | return open; | |
| 223 | } | |
| 224 | ||
| 225 | priv ate Set<In stanceByte ChannelLis tener> lis teners = n ew HashSet <InstanceB yteChannel Listener>( ); | |
| 226 | publ ic void ad dListener( InstanceBy teChannelL istener li stener) | |
| 227 | { | |
| 228 | listen ers.add(li stener); | |
| 229 | } | |
| 230 | publ ic void re moveListen er(Instanc eByteChann elListener listener) | |
| 231 | { | |
| 232 | listen ers.remove (listener) ; | |
| 233 | } | |
| 234 | priv ate void n otifyListe ners(boole an errorCl ose) | |
| 235 | { | |
| 236 | for(In stanceByte ChannelLis tener list ener : lis teners) | |
| 237 | if( erro rClose ) | |
| 238 | listener.r eadChannel IdleTimeou t(this); | |
| 239 | else | |
| 240 | listener.r eadChannel Close(this ); | |
| 241 | } | |
| 242 | ||
| 243 | /* ( non-Javado c) | |
| 244 | * @ see gov.va .med.imagi ng.storage .cache.Ins tanceReada bleByteCha nnel#getLa stAccessed Time() | |
| 245 | */ | |
| 246 | @Ove rride | |
| 247 | publ ic long ge tLastAcces sedTime() | |
| 248 | { | |
| 249 | return System.cu rrentTimeM illis(); | |
| 250 | } | |
| 251 | ||
| 252 | @Ove rride | |
| 253 | publ ic File ge tCacheFile () { | |
| 254 | // TOD O Auto-gen erated met hod stub | |
| 255 | return null; | |
| 256 | } | |
| 257 | } | |
| 258 | ||
| 259 | /* * | |
| 260 | * | |
| 261 | * @author
|
|
| 262 | * | |
| 263 | * / | |
| 264 | cl ass MockIn stanceWrit ableByteCh annel | |
| 265 | im plements I nstanceWri tableByteC hannel | |
| 266 | { | |
| 267 | priv ate Memory InstanceDa ta instanc eData; | |
| 268 | int position = 0; | |
| 269 | priv ate boolea n open = t rue; // t he channel is open w hen it is created | |
| 270 | priv ate Checks um checksu m = new ja va.util.zi p.Adler32( ); | |
| 271 | ||
| 272 | publ ic MockIns tanceWrita bleByteCha nnel(Memor yInstanceD ata instan ceData) | |
| 273 | { | |
| 274 | this.i nstanceDat a = instan ceData; | |
| 275 | } | |
| 276 | ||
| 277 | publ ic boolean isOpen() | |
| 278 | { | |
| 279 | return open; | |
| 280 | } | |
| 281 | ||
| 282 | publ ic Checksu m getCheck sum() | |
| 283 | { | |
| 284 | return checksum; | |
| 285 | } | |
| 286 | ||
| 287 | publ ic int wri te(ByteBuf fer src) | |
| 288 | thro ws IOExcep tion | |
| 289 | { | |
| 290 | if( ! isOpen() ) | |
| 291 | throw ne w IOExcept ion("Inval id state, channel is already c losed."); | |
| 292 | ||
| 293 | // ass ure that w e do not o verwrite t he buffer | |
| 294 | if( sr c.remainin g() > (ins tanceData. getCapacit y() - posi tion) ) | |
| 295 | throw ne w IOExcept ion("Error writing t o channel, storage o verflow"); | |
| 296 | int by tesWritten = Math.mi n(instance Data.getCa pacity() - position, src.remai ning() ); | |
| 297 | if(byt esWritten > 0) | |
| 298 | { | |
| 299 | byte[] t mp = new b yte[src.re maining()] ; | |
| 300 | src.get( tmp); | |
| 301 | checksum .update(tm p, 0, tmp. length); | |
| 302 | instance Data.write (position, tmp); | |
| 303 | } | |
| 304 | ||
| 305 | positi on += byte sWritten; | |
| 306 | ||
| 307 | return bytesWrit ten; | |
| 308 | } | |
| 309 | ||
| 310 | publ ic void er ror() | |
| 311 | thro ws IOExcep tion | |
| 312 | { | |
| 313 | open = false; | |
| 314 | notify Listeners( true); | |
| 315 | } | |
| 316 | ||
| 317 | publ ic void cl ose() | |
| 318 | thro ws IOExcep tion | |
| 319 | { | |
| 320 | open = false; | |
| 321 | notify Listeners( false); | |
| 322 | } | |
| 323 | ||
| 324 | priv ate Set<In stanceByte ChannelLis tener> lis teners = n ew HashSet <InstanceB yteChannel Listener>( ); | |
| 325 | publ ic void ad dListener( InstanceBy teChannelL istener li stener) | |
| 326 | { | |
| 327 | listen ers.add(li stener); | |
| 328 | } | |
| 329 | publ ic void re moveListen er(Instanc eByteChann elListener listener) | |
| 330 | { | |
| 331 | listen ers.remove (listener) ; | |
| 332 | } | |
| 333 | priv ate void n otifyListe ners(boole an errorCl ose) | |
| 334 | { | |
| 335 | for(In stanceByte ChannelLis tener list ener : lis teners) | |
| 336 | if( erro rClose ) | |
| 337 | listener.w riteChanne lIdleTimeo ut(this); | |
| 338 | else | |
| 339 | listener.w riteChanne lClose(thi s); | |
| 340 | } | |
| 341 | /* ( non-Javado c) | |
| 342 | * @ see gov.va .med.imagi ng.storage .cache.Ins tanceReada bleByteCha nnel#getLa stAccessed Time() | |
| 343 | */ | |
| 344 | @Ove rride | |
| 345 | publ ic long ge tLastAcces sedTime() | |
| 346 | { | |
| 347 | return System.cu rrentTimeM illis(); | |
| 348 | } | |
| 349 | } | |
| 350 | ||
| 351 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.