private Store.ValueHolder<String> createValueHolder(String value) { if(value == null) { return null; } return new BasicOffHeapValueHolder<>(1, value, Long.MAX_VALUE, System.currentTimeMillis() - 1); }
public BasicOffHeapValueHolder(long id, V value, long creationTime, long expireTime, long lastAccessTime) { super(id, creationTime, expireTime); setLastAccessTime(lastAccessTime); this.value = value; }
@Test(expected = UnsupportedOperationException.class) public void testDoesNotSupportDelayedDeserialization() { valueHolder.detach(); }
@Test(expected = UnsupportedOperationException.class) public void testDoesNotSupportUpdateMetadata() { valueHolder.updateMetadata(valueHolder); } }
@Test(expected = UnsupportedOperationException.class) public void testDoesNotSupportForceDeserialization() { valueHolder.forceDeserialization(); }
@Test(expected = UnsupportedOperationException.class) public void testDoesNotSupportWriteBack() { valueHolder.writeBack(); }
@Test public void testCanAccessValue() { assertThat(valueHolder.get(), is(value)); }
@Before public void setUp() { value = "aValue"; valueHolder = new BasicOffHeapValueHolder<>(-1, value, 0, 0); }
public BasicOffHeapValueHolder(long id, V value, long creationTime, long expireTime, long lastAccessTime) { super(id, creationTime, expireTime); setLastAccessTime(lastAccessTime, TIME_UNIT); this.value = value; }
@Override public Store.ValueHolder<String> newValueHolder(String value) { return new BasicOffHeapValueHolder<>(-1, value, SystemTimeSource.INSTANCE.getTimeMillis(), OffHeapValueHolder.NO_EXPIRE); }
@Override public Store.ValueHolder<String> newValueHolder(String value) { return new BasicOffHeapValueHolder<>(-1, value, SystemTimeSource.INSTANCE.getTimeMillis(), OffHeapValueHolder.NO_EXPIRE); }
private OffHeapValueHolder<V> newCreateValueHolder(K key, V value, long now, StoreEventSink<K, V> eventSink) { Objects.requireNonNull(value); Duration duration = ExpiryUtils.getExpiryForCreation(key, value, expiry); if(duration.isZero()) { return null; } eventSink.created(key, value); long expirationTime = isExpiryDurationInfinite(duration) ? ValueHolder.NO_EXPIRE : ExpiryUtils.getExpirationMillis(now, duration); return new BasicOffHeapValueHolder<>(backingMap().nextIdFor(key), value, now, expirationTime); }
private OffHeapValueHolder<V> newUpdatedValueHolder(K key, V value, OffHeapValueHolder<V> existing, long now, StoreEventSink<K, V> eventSink) { eventSink.updated(key, existing, value); Duration duration = Duration.ZERO; try { duration = expiry.getExpiryForUpdate(key, existing, value); if (duration != null && duration.isNegative()) { duration = Duration.ZERO; } } catch (RuntimeException re) { LOG.error("Expiry computation caused an exception - Expiry duration will be 0 ", re); } if (Duration.ZERO.equals(duration)) { eventSink.expired(key, () -> value); return null; } if (duration == null) { return new BasicOffHeapValueHolder<>(backingMap().nextIdFor(key), value, now, existing.expirationTime()); } else if (isExpiryDurationInfinite(duration)) { return new BasicOffHeapValueHolder<>(backingMap().nextIdFor(key), value, now, OffHeapValueHolder.NO_EXPIRE); } else { return new BasicOffHeapValueHolder<>(backingMap().nextIdFor(key), value, now, ExpiryUtils.getExpirationMillis(now, duration)); } }
OffHeapValueHolder<V> valueHolder = newUpdatedValueHolder(key, computedValue, mappedValue, now, eventSink); if (valueHolder == null) { valueHeld.set(new BasicOffHeapValueHolder<>(mappedValue.getId(), computedValue, now, now));
@Before public void setup() throws UnsupportedTypeException { SerializationProvider provider = new DefaultSerializationProvider(null); provider.start(providerContaining()); valueHolderPortability = new OffHeapValueHolderPortability<>(provider .createValueSerializer(String.class, getClass().getClassLoader())); originalValue = new BasicOffHeapValueHolder<>(-1, "aValue", 1L, 2L, 3L); }
OffHeapValueHolder<V> valueHolder = newUpdatedValueHolder(key, computedValue, mappedValue, now, eventSink); if (valueHolder == null) { valueHeld.set(new BasicOffHeapValueHolder<>(mappedValue.getId(), computedValue, now, now));
private OffHeapValueHolder<V> newTransferValueHolder(ValueHolder<V> valueHolder) { if (valueHolder instanceof BinaryValueHolder && ((BinaryValueHolder) valueHolder).isBinaryValueAvailable()) { return new BinaryOffHeapValueHolder<>(valueHolder.getId(), valueHolder.get(), ((BinaryValueHolder) valueHolder).getBinaryValue(), valueHolder.creationTime(), valueHolder.expirationTime(), valueHolder.lastAccessTime()); } else { return new BasicOffHeapValueHolder<>(valueHolder.getId(), valueHolder.get(), valueHolder.creationTime(), valueHolder.expirationTime(), valueHolder.lastAccessTime()); } }
private OffHeapValueHolder<V> newCreateValueHolder(K key, V value, long now, StoreEventSink<K, V> eventSink) { Objects.requireNonNull(value); Duration duration = ExpiryUtils.getExpiryForCreation(key, value, expiry); if(duration.isZero()) { return null; } eventSink.created(key, value); long expirationTime = isExpiryDurationInfinite(duration) ? ValueHolder.NO_EXPIRE : ExpiryUtils.getExpirationMillis(now, duration); return new BasicOffHeapValueHolder<>(backingMap().nextIdFor(key), value, now, expirationTime); }
private OffHeapValueHolder<V> newUpdatedValueHolder(K key, V value, OffHeapValueHolder<V> existing, long now, StoreEventSink<K, V> eventSink) { eventSink.updated(key, existing, value); Duration duration = Duration.ZERO; try { duration = expiry.getExpiryForUpdate(key, existing, value); if (duration != null && duration.isNegative()) { duration = Duration.ZERO; } } catch (RuntimeException re) { LOG.error("Expiry computation caused an exception - Expiry duration will be 0 ", re); } if (Duration.ZERO.equals(duration)) { eventSink.expired(key, () -> value); return null; } if (duration == null) { return new BasicOffHeapValueHolder<>(backingMap().nextIdFor(key), value, now, existing.expirationTime(OffHeapValueHolder.TIME_UNIT)); } else if (isExpiryDurationInfinite(duration)) { return new BasicOffHeapValueHolder<>(backingMap().nextIdFor(key), value, now, OffHeapValueHolder.NO_EXPIRE); } else { return new BasicOffHeapValueHolder<>(backingMap().nextIdFor(key), value, now, ExpiryUtils.getExpirationMillis(now, duration)); } }
OffHeapValueHolder<V> valueHolder = newUpdatedValueHolder(key, computedValue, mappedValue, now, eventSink); if (valueHolder == null) { valueHeld.set(new BasicOffHeapValueHolder<>(mappedValue.getId(), computedValue, now, now));