use of org.infinispan.container.entries.TransientMortalCacheEntry in project infinispan by infinispan.
the class InternalEntryFactoryImpl method create.
@Override
public InternalCacheEntry create(Object key, Object value, Metadata metadata) {
long lifespan = metadata != null ? metadata.lifespan() : -1;
long maxIdle = metadata != null ? metadata.maxIdle() : -1;
if (!isStoreMetadata(metadata, null)) {
if (lifespan < 0 && maxIdle < 0)
return new ImmortalCacheEntry(key, value);
if (lifespan > -1 && maxIdle < 0)
return new MortalCacheEntry(key, value, lifespan, timeService.wallClockTime());
if (lifespan < 0 && maxIdle > -1)
return new TransientCacheEntry(key, value, maxIdle, timeService.wallClockTime());
return new TransientMortalCacheEntry(key, value, maxIdle, lifespan, timeService.wallClockTime());
} else {
if (lifespan < 0 && maxIdle < 0)
return new MetadataImmortalCacheEntry(key, value, metadata);
if (lifespan > -1 && maxIdle < 0)
return new MetadataMortalCacheEntry(key, value, metadata, timeService.wallClockTime());
if (lifespan < 0 && maxIdle > -1)
return new MetadataTransientCacheEntry(key, value, metadata, timeService.wallClockTime());
return new MetadataTransientMortalCacheEntry(key, value, metadata, timeService.wallClockTime());
}
}
use of org.infinispan.container.entries.TransientMortalCacheEntry in project infinispan by infinispan.
the class InternalEntryFactoryImpl method create.
@Override
public // TODO: Do we need this???
InternalCacheEntry create(Object key, Object value, Metadata metadata, long lifespan, long maxIdle) {
if (!isStoreMetadata(metadata, null)) {
if (lifespan < 0 && maxIdle < 0)
return new ImmortalCacheEntry(key, value);
if (lifespan > -1 && maxIdle < 0)
return new MortalCacheEntry(key, value, lifespan, timeService.wallClockTime());
if (lifespan < 0 && maxIdle > -1)
return new TransientCacheEntry(key, value, maxIdle, timeService.wallClockTime());
return new TransientMortalCacheEntry(key, value, maxIdle, lifespan, timeService.wallClockTime());
} else {
// Metadata to store, take lifespan and maxIdle settings from it
long metaLifespan = metadata.lifespan();
long metaMaxIdle = metadata.maxIdle();
if (metaLifespan < 0 && metaMaxIdle < 0)
return new MetadataImmortalCacheEntry(key, value, metadata);
if (metaLifespan > -1 && metaMaxIdle < 0)
return new MetadataMortalCacheEntry(key, value, metadata, timeService.wallClockTime());
if (metaLifespan < 0 && metaMaxIdle > -1)
return new MetadataTransientCacheEntry(key, value, metadata, timeService.wallClockTime());
return new MetadataTransientMortalCacheEntry(key, value, metadata, timeService.wallClockTime());
}
}
use of org.infinispan.container.entries.TransientMortalCacheEntry in project infinispan by infinispan.
the class VersionAwareMarshallerTest method testInternalCacheEntryMarshalling.
public void testInternalCacheEntryMarshalling() throws Exception {
ImmortalCacheEntry entry1 = (ImmortalCacheEntry) TestInternalCacheEntryFactory.create("key", "value", System.currentTimeMillis() - 1000, -1, System.currentTimeMillis(), -1);
marshallAndAssertEquality(entry1);
MortalCacheEntry entry2 = (MortalCacheEntry) TestInternalCacheEntryFactory.create("key", "value", System.currentTimeMillis() - 1000, 200000, System.currentTimeMillis(), -1);
marshallAndAssertEquality(entry2);
TransientCacheEntry entry3 = (TransientCacheEntry) TestInternalCacheEntryFactory.create("key", "value", System.currentTimeMillis() - 1000, -1, System.currentTimeMillis(), 4000000);
marshallAndAssertEquality(entry3);
TransientMortalCacheEntry entry4 = (TransientMortalCacheEntry) TestInternalCacheEntryFactory.create("key", "value", System.currentTimeMillis() - 1000, 200000, System.currentTimeMillis(), 4000000);
marshallAndAssertEquality(entry4);
}
use of org.infinispan.container.entries.TransientMortalCacheEntry in project infinispan by infinispan.
the class BaseCacheNotifierImplInitialTransferTest method testMetadataAvailable.
public void testMetadataAvailable() {
final List<CacheEntry<String, String>> initialValues = new ArrayList<>(10);
for (int i = 0; i < 10; i++) {
String key = "key-" + i;
String value = "value-" + i;
initialValues.add(new TransientMortalCacheEntry(key, value, i, -1, System.currentTimeMillis()));
}
// Note we don't actually use the filter/converter to retrieve values since it is being mocked, thus we can assert
// the filter/converter are not used by us
when(mockPublisherManager.entryPublisher(any(), any(), any(), anyLong(), any(), anyInt(), any())).thenReturn(wrapCompletionPublisher(Flowable.fromIterable(initialValues)));
CacheEventFilter filter = mock(CacheEventFilter.class, withSettings().serializable());
CacheEventConverter converter = mock(CacheEventConverter.class, withSettings().serializable());
StateListener<String, String> listener = new StateListenerClustered();
n.addListener(listener, filter, converter);
verifyEvents(isClustered(listener), listener, initialValues);
for (CacheEntryEvent<String, String> event : listener.events) {
String key = event.getKey();
Metadata metadata = event.getMetadata();
assertNotNull(metadata);
assertEquals(metadata.lifespan(), -1);
assertEquals(metadata.maxIdle(), Long.parseLong(key.substring(4)));
}
}
use of org.infinispan.container.entries.TransientMortalCacheEntry in project infinispan by infinispan.
the class ReplicatedExpiryTest method testBothExpiryReplicates.
public void testBothExpiryReplicates() {
Cache c1 = cache(0, "cache");
Cache c2 = cache(1, "cache");
long lifespan = 10000;
long idle = 3000;
c1.put("k", "v", lifespan, MILLISECONDS, idle, MILLISECONDS);
InternalCacheEntry ice = c2.getAdvancedCache().getDataContainer().get("k");
assert ice instanceof TransientMortalCacheEntry;
assert ice.getLifespan() == lifespan : "Expected " + lifespan + " but was " + ice.getLifespan();
assert ice.getMaxIdle() == idle : "Expected " + idle + " but was " + ice.getMaxIdle();
}
Aggregations