use of org.infinispan.container.entries.metadata.MetadataImmortalCacheEntry 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.metadata.MetadataImmortalCacheEntry 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.metadata.MetadataImmortalCacheEntry in project infinispan by infinispan.
the class CacheEntrySizeCalculator method calculateSize.
@Override
public long calculateSize(K key, InternalCacheEntry<K, V> ice) {
// This will be non zero when use expiration, but don't want to store the metadata
long noMetadataSize = 0;
boolean metadataAware;
// ImmortalCacheEntry so it has to come before
if (ice instanceof MetadataImmortalCacheEntry) {
metadataAware = true;
} else if (ice instanceof ImmortalCacheEntry) {
metadataAware = false;
} else if (ice instanceof MortalCacheEntry) {
noMetadataSize += 16;
metadataAware = false;
} else if (ice instanceof TransientCacheEntry) {
noMetadataSize += 16;
metadataAware = false;
} else if (ice instanceof TransientMortalCacheEntry) {
noMetadataSize += 32;
metadataAware = false;
} else if (ice instanceof MetadataMortalCacheEntry) {
metadataAware = true;
} else if (ice instanceof MetadataTransientCacheEntry) {
metadataAware = true;
} else {
metadataAware = ice instanceof MetadataTransientMortalCacheEntry;
}
Metadata metadata;
if (metadataAware) {
metadata = ice.getMetadata();
// We don't support other metadata types currently
if (!(metadata instanceof EmbeddedMetadata)) {
metadata = null;
}
} else {
metadata = null;
}
long keyValueMetadataSize = calculateSize(key, ice.getValue(), metadata, ice.getInternalMetadata());
return keyValueMetadataSize + noMetadataSize;
}
use of org.infinispan.container.entries.metadata.MetadataImmortalCacheEntry 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);
}
}
}
}
use of org.infinispan.container.entries.metadata.MetadataImmortalCacheEntry in project infinispan by infinispan.
the class MetadataImmortalCacheEntryExternalizer method readObject.
@Override
public MetadataImmortalCacheEntry readObject(ObjectInput input) throws IOException, ClassNotFoundException {
Object key = input.readObject();
Object value = input.readObject();
Metadata metadata = (Metadata) input.readObject();
return new MetadataImmortalCacheEntry(key, value, metadata);
}
Aggregations