@Test public void compareAndSwap(){ long recid = e.put(111, Serializer.INTEGER_SERIALIZER); Engine snapshot = e.snapshot(); e.compareAndSwap(recid, 111, 222, Serializer.INTEGER_SERIALIZER); assertEquals(Integer.valueOf(111), snapshot.get(recid, Serializer.INTEGER_SERIALIZER)); }
@Override public <A> boolean compareAndSwap(long recid, A expectedOldValue, A newValue, Serializer<A> serializer) { locks.lock(recid); try{ boolean ret = super.compareAndSwap(recid, expectedOldValue, newValue, serializer); if(ret==true){ for(Snapshot s:snapshots.keySet()){ s.oldValues.putIfAbsent(recid, expectedOldValue); } } return ret; }finally{ locks.unlock(recid); } }
SnapshotEngine extends EngineWrapper { @Override public <A> boolean compareAndSwap(long recid, A expectedOldValue, A newValue, Serializer<A> serializer) { locks.lock(recid); try{ boolean ret = super.compareAndSwap(recid, expectedOldValue, newValue, serializer); if(ret==true){ for(Snapshot s:snapshots.keySet()){ s.oldValues.putIfAbsent(recid, expectedOldValue); } } return ret; }finally{ locks.unlock(recid); } } }
SnapshotEngine extends EngineWrapper { @Override public <A> boolean compareAndSwap(long recid, A expectedOldValue, A newValue, Serializer<A> serializer) { locks.lock(recid); try{ boolean ret = super.compareAndSwap(recid, expectedOldValue, newValue, serializer); if(ret==true){ for(Snapshot s:snapshots.keySet()){ s.oldValues.putIfAbsent(recid, expectedOldValue); } } return ret; }finally{ locks.unlock(recid); } } protected  SnapshotEngine(Engine engine); }
SnapshotEngine extends EngineWrapper { @Override public <A> boolean compareAndSwap(long recid, A expectedOldValue, A newValue, Serializer<A> serializer) { locks.lock(recid); try{ boolean ret = super.compareAndSwap(recid, expectedOldValue, newValue, serializer); if(ret==true){ for(Snapshot s:snapshots.keySet()){ s.oldValues.putIfAbsent(recid, expectedOldValue); } } return ret; }finally{ locks.unlock(recid); } } protected  SnapshotEngine(Engine engine); Engine snapshot(); @Override long put(A value, Serializer<A> serializer); @Override boolean compareAndSwap(long recid, A expectedOldValue, A newValue, Serializer<A> serializer); @Override void update(long recid, A value, Serializer<A> serializer); @Override void delete(long recid, Serializer<A> serializer); static Engine createSnapshotFor(Engine engine); }
SnapshotEngine extends EngineWrapper { @Override public <A> boolean compareAndSwap(long recid, A expectedOldValue, A newValue, Serializer<A> serializer) { locks.lock(recid); try{ boolean ret = super.compareAndSwap(recid, expectedOldValue, newValue, serializer); if(ret==true){ for(Snapshot s:snapshots.keySet()){ s.oldValues.putIfAbsent(recid, expectedOldValue); } } return ret; }finally{ locks.unlock(recid); } } protected  SnapshotEngine(Engine engine); Engine snapshot(); @Override long put(A value, Serializer<A> serializer); @Override boolean compareAndSwap(long recid, A expectedOldValue, A newValue, Serializer<A> serializer); @Override void update(long recid, A value, Serializer<A> serializer); @Override void delete(long recid, Serializer<A> serializer); static Engine createSnapshotFor(Engine engine);  }