Changeset 30532 in osm for applications/editors/josm/plugins/imagerycache/src/org/mapdb/EngineWrapper.java
- Timestamp:
- 2014-07-14T04:18:06+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imagerycache/src/org/mapdb/EngineWrapper.java
r29484 r30532 14 14 * limitations under the License. 15 15 */ 16 17 16 package org.mapdb; 18 19 17 20 18 import java.io.IOError; … … 26 24 import java.util.concurrent.ConcurrentLinkedQueue; 27 25 28 29 26 /** 30 27 * EngineWrapper adapter. It implements all methods on Engine interface. … … 293 290 } 294 291 295 296 292 /** 297 293 * check if Record Instances were not modified while in cache. 298 294 * Usuful to diagnose strange problems with Instance Cache. 299 295 */ 300 public static class ImmutabilityCheckEngine extends EngineWrapper {301 302 protected static class Item {303 final Serializer serializer;304 final Objectitem;296 public static class ImmutabilityCheckEngine extends EngineWrapper { 297 298 protected static class Item<E> { 299 final Serializer<E> serializer; 300 final E item; 305 301 final int oldChecksum; 306 302 307 public Item(Serializer serializer, Objectitem) {303 public Item(Serializer<E> serializer, E item) { 308 304 if(item==null || serializer==null) throw new AssertionError("null"); 309 305 this.serializer = serializer; … … 313 309 } 314 310 315 private int checksum() {311 private int checksum() { 316 312 try { 317 313 DataOutput2 out = new DataOutput2(); … … 324 320 } 325 321 326 void check() {322 void check() { 327 323 int newChecksum = checksum(); 328 324 if(oldChecksum!=newChecksum) throw new AssertionError("Record instance was modified: \n "+item+"\n "+serializer); … … 330 326 } 331 327 332 protected LongConcurrentHashMap<Item > items = new LongConcurrentHashMap<Item>();328 protected LongConcurrentHashMap<Item<?>> items = new LongConcurrentHashMap<>(); 333 329 334 330 protected ImmutabilityCheckEngine(Engine engine) { … … 338 334 @Override 339 335 public <A> A get(long recid, Serializer<A> serializer) { 340 Item item = items.get(recid);336 Item<?> item = items.get(recid); 341 337 if(item!=null) item.check(); 342 338 A ret = super.get(recid, serializer); 343 if(ret!=null) items.put(recid, new Item (serializer,ret));339 if(ret!=null) items.put(recid, new Item<A>(serializer,ret)); 344 340 return ret; 345 341 } … … 348 344 public <A> long put(A value, Serializer<A> serializer) { 349 345 long ret = super.put(value, serializer); 350 if(value!=null) items.put(ret, new Item (serializer,value));346 if(value!=null) items.put(ret, new Item<A>(serializer,value)); 351 347 return ret; 352 348 } … … 354 350 @Override 355 351 public <A> void update(long recid, A value, Serializer<A> serializer) { 356 Item item = items.get(recid);352 Item<?> item = items.get(recid); 357 353 if(item!=null) item.check(); 358 354 super.update(recid, value, serializer); 359 if(value!=null) items.put(recid, new Item(serializer,value)); 360 } 361 355 if(value!=null) items.put(recid, new Item<A>(serializer,value)); 356 } 357 358 @SuppressWarnings({ "unchecked", "rawtypes" }) 362 359 @Override 363 360 public <A> boolean compareAndSwap(long recid, A expectedOldValue, A newValue, Serializer<A> serializer) { 364 Item item = items.get(recid);361 Item<?> item = items.get(recid); 365 362 if(item!=null) item.check(); 366 363 boolean ret = super.compareAndSwap(recid, expectedOldValue, newValue, serializer); … … 372 369 public void close() { 373 370 super.close(); 374 for(Iterator<Item > iter = items.valuesIterator(); iter.hasNext();){371 for(Iterator<Item<?>> iter = items.valuesIterator(); iter.hasNext();){ 375 372 iter.next().check(); 376 373 } … … 378 375 } 379 376 } 380 381 377 382 378 /** Engine wrapper with all methods synchronized on global lock, useful to diagnose concurrency issues.*/ … … 442 438 } 443 439 } 444 445 440 }
Note:
See TracChangeset
for help on using the changeset viewer.