public V newValueOf(K key) { Command<V> command = commands.get(key); XAValueHolder<V> valueHolder = command == null ? null : command.getNewValueHolder(); return valueHolder == null ? null : valueHolder.get(); }
private Object writeReplace() { return new SerializedXAValueHolder<>(getId(), creationTime(), lastAccessTime(), expirationTime(), get(), valueSerialized); }
.getNewValueHolder().get(); Duration duration; try {
@Test public void testSerialization() throws Exception { long now = System.currentTimeMillis(); XAValueHolder<String> valueHolder = new XAValueHolder<>("value", now - 1000); valueHolder.accessed(now, Duration.ofSeconds(100)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream outputStream = new ObjectOutputStream(baos); outputStream.writeObject(valueHolder); outputStream.close(); @SuppressWarnings("unchecked") XAValueHolder<String> result = (XAValueHolder<String>) new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())).readObject(); assertThat(result.getId(), is(valueHolder.getId())); assertThat(result.creationTime(), is(valueHolder.creationTime())); assertThat(result.lastAccessTime(), is(valueHolder.lastAccessTime())); assertThat(result.expirationTime(), is(valueHolder.expirationTime())); assertThat(result.get(), is(valueHolder.get())); } }
@Override public SoftLock<T> copyForWrite(SoftLock<T> obj) { T oldValue = valueCopier.copyForWrite(obj.getOldValue()); XAValueHolder<T> valueHolder = obj.getNewValueHolder(); XAValueHolder<T> newValueHolder = valueHolder == null ? null : new XAValueHolder<>(valueHolder, valueCopier.copyForWrite(valueHolder .get())); return new SoftLock<>(obj.getTransactionId(), oldValue, newValueHolder); }
private Object writeReplace() { return new SerializedXAValueHolder<>(getId(), creationTime(NATIVE_TIME_UNIT), lastAccessTime(NATIVE_TIME_UNIT), expirationTime(NATIVE_TIME_UNIT), get(), valueSerialized); }
@Override public SoftLock<T> copyForRead(SoftLock<T> obj) { T oldValue = valueCopier.copyForRead(obj.getOldValue()); XAValueHolder<T> valueHolder = obj.getNewValueHolder(); XAValueHolder<T> newValueHolder = valueHolder == null ? null : new XAValueHolder<>(valueHolder, valueCopier.copyForRead(valueHolder .get())); return new SoftLock<>(obj.getTransactionId(), oldValue, newValueHolder); }
SoftLock<V> preparedSoftLock = getFromUnderlyingStore(key); XAValueHolder<V> newValueHolder = preparedSoftLock == null ? null : preparedSoftLock.getNewValueHolder(); SoftLock<V> definitiveSoftLock = newValueHolder == null ? null : new SoftLock<>(null, newValueHolder.get(), null);
assertThat(xaTransactionContext.updated(1L), is(true)); assertThat(xaTransactionContext.evicted(1L), is(false)); assertThat(xaTransactionContext.newValueHolderOf(1L).get(), equalTo("new")); assertThat(xaTransactionContext.oldValueOf(1L), equalTo("old")); assertThat(xaTransactionContext.newValueOf(1L), equalTo("new"));
@Test public void testEvictCommandCannotBeOverridden() { XATransactionContext<Long, String> xaTransactionContext = getXaTransactionContext(); xaTransactionContext.addCommand(1L, new StorePutCommand<>("old", new XAValueHolder<>("new", timeSource.getTimeMillis()))); assertThat(xaTransactionContext.touched(1L), is(true)); assertThat(xaTransactionContext.removed(1L), is(false)); assertThat(xaTransactionContext.updated(1L), is(true)); assertThat(xaTransactionContext.evicted(1L), is(false)); assertThat(xaTransactionContext.newValueHolderOf(1L).get(), equalTo("new")); assertThat(xaTransactionContext.oldValueOf(1L), equalTo("old")); assertThat(xaTransactionContext.newValueOf(1L), equalTo("new")); xaTransactionContext.addCommand(1L, new StoreEvictCommand<>("old")); assertThat(xaTransactionContext.touched(1L), is(true)); assertThat(xaTransactionContext.removed(1L), is(false)); assertThat(xaTransactionContext.updated(1L), is(false)); assertThat(xaTransactionContext.evicted(1L), is(true)); assertThat(xaTransactionContext.newValueHolderOf(1L), is(nullValue())); assertThat(xaTransactionContext.oldValueOf(1L), equalTo("old")); assertThat(xaTransactionContext.newValueOf(1L), is(nullValue())); xaTransactionContext.addCommand(1L, new StorePutCommand<>("old2", new XAValueHolder<>("new2", timeSource.getTimeMillis()))); assertThat(xaTransactionContext.touched(1L), is(true)); assertThat(xaTransactionContext.removed(1L), is(false)); assertThat(xaTransactionContext.updated(1L), is(false)); assertThat(xaTransactionContext.evicted(1L), is(true)); assertThat(xaTransactionContext.newValueHolderOf(1L), is(nullValue())); assertThat(xaTransactionContext.oldValueOf(1L), equalTo("old")); assertThat(xaTransactionContext.newValueOf(1L), is(nullValue())); }
assertThat(xaTransactionContext.updated(1L), is(true)); assertThat(xaTransactionContext.evicted(1L), is(false)); assertThat(xaTransactionContext.newValueHolderOf(1L).get(), equalTo("new")); assertThat(xaTransactionContext.oldValueOf(1L), equalTo("old")); assertThat(xaTransactionContext.newValueOf(1L), equalTo("new")); assertThat(xaTransactionContext.updated(1L), is(true)); assertThat(xaTransactionContext.evicted(1L), is(false)); assertThat(xaTransactionContext.newValueHolderOf(1L).get(), equalTo("new2")); assertThat(xaTransactionContext.oldValueOf(1L), equalTo("old2")); assertThat(xaTransactionContext.newValueOf(1L), equalTo("new2"));
xaValueHolder = new XAValueHolder<>(softLockValueHolder, softLockValueHolder.get().getNewValueHolder().get()); } else { if (updated) {
public V newValueOf(K key) { Command<V> command = commands.get(key); XAValueHolder<V> valueHolder = command == null ? null : command.getNewValueHolder(); return valueHolder == null ? null : valueHolder.get(); }
.getNewValueHolder().get(); Duration duration; try {
@Override public SoftLock<T> copyForWrite(SoftLock<T> obj) { T oldValue = valueCopier.copyForWrite(obj.getOldValue()); XAValueHolder<T> valueHolder = obj.getNewValueHolder(); XAValueHolder<T> newValueHolder = valueHolder == null ? null : new XAValueHolder<>(valueHolder, valueCopier.copyForWrite(valueHolder .get())); return new SoftLock<>(obj.getTransactionId(), oldValue, newValueHolder); }
@Override public SoftLock<T> copyForRead(SoftLock<T> obj) { T oldValue = valueCopier.copyForRead(obj.getOldValue()); XAValueHolder<T> valueHolder = obj.getNewValueHolder(); XAValueHolder<T> newValueHolder = valueHolder == null ? null : new XAValueHolder<>(valueHolder, valueCopier.copyForRead(valueHolder .get())); return new SoftLock<>(obj.getTransactionId(), oldValue, newValueHolder); }
SoftLock<V> preparedSoftLock = getFromUnderlyingStore(key); XAValueHolder<V> newValueHolder = preparedSoftLock == null ? null : preparedSoftLock.getNewValueHolder(); SoftLock<V> definitiveSoftLock = newValueHolder == null ? null : new SoftLock<>(null, newValueHolder.get(), null);
xaValueHolder = new XAValueHolder<>(softLockValueHolder, softLockValueHolder.get().getNewValueHolder().get()); } else { if (updated) {