use of org.infinispan.container.entries.MortalCacheEntry 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.MortalCacheEntry 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.MortalCacheEntry 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.MortalCacheEntry in project infinispan by infinispan.
the class ReplicatedExpiryTest method testLifespanExpiryReplicates.
public void testLifespanExpiryReplicates() {
Cache c1 = cache(0, "cache");
Cache c2 = cache(1, "cache");
long lifespan = 3000;
c1.put("k", "v", lifespan, MILLISECONDS);
InternalCacheEntry ice = c2.getAdvancedCache().getDataContainer().get("k");
assert ice instanceof MortalCacheEntry;
assert ice.getLifespan() == lifespan;
assert ice.getMaxIdle() == -1;
}
use of org.infinispan.container.entries.MortalCacheEntry in project infinispan by infinispan.
the class InternalEntryFactoryImpl method updateMetadataUnawareEntry.
private InternalCacheEntry updateMetadataUnawareEntry(InternalCacheEntry ice, long lifespan, long maxIdle) {
if (lifespan < 0) {
if (maxIdle < 0) {
// Need extra check because MetadataImmortalCacheEntry extends ImmortalCacheEntry
if (ice instanceof ImmortalCacheEntry && !(ice instanceof MetadataImmortalCacheEntry)) {
return ice;
} else {
return new ImmortalCacheEntry(ice.getKey(), ice.getValue());
}
} else {
if (ice instanceof TransientCacheEntry) {
((TransientCacheEntry) ice).setMaxIdle(maxIdle);
return ice;
} else {
return new TransientCacheEntry(ice.getKey(), ice.getValue(), maxIdle, timeService.wallClockTime());
}
}
} else {
if (maxIdle < 0) {
if (ice instanceof MortalCacheEntry) {
((MortalCacheEntry) ice).setLifespan(lifespan);
return ice;
} else {
return new MortalCacheEntry(ice.getKey(), ice.getValue(), lifespan, timeService.wallClockTime());
}
} else {
if (ice instanceof TransientMortalCacheEntry) {
TransientMortalCacheEntry transientMortalEntry = (TransientMortalCacheEntry) ice;
transientMortalEntry.setLifespan(lifespan);
transientMortalEntry.setMaxIdle(maxIdle);
return ice;
} else {
long ctm = timeService.wallClockTime();
return new TransientMortalCacheEntry(ice.getKey(), ice.getValue(), maxIdle, lifespan, ctm, ctm);
}
}
}
}
Aggregations