Search in sources :

Example 1 with MetadataImmortalCacheEntry

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());
    }
}
Also used : TransientMortalCacheEntry(org.infinispan.container.entries.TransientMortalCacheEntry) MetadataMortalCacheEntry(org.infinispan.container.entries.metadata.MetadataMortalCacheEntry) MortalCacheEntry(org.infinispan.container.entries.MortalCacheEntry) MetadataTransientMortalCacheEntry(org.infinispan.container.entries.metadata.MetadataTransientMortalCacheEntry) ImmortalCacheEntry(org.infinispan.container.entries.ImmortalCacheEntry) MetadataImmortalCacheEntry(org.infinispan.container.entries.metadata.MetadataImmortalCacheEntry) MetadataTransientCacheEntry(org.infinispan.container.entries.metadata.MetadataTransientCacheEntry) MetadataTransientMortalCacheEntry(org.infinispan.container.entries.metadata.MetadataTransientMortalCacheEntry) TransientMortalCacheEntry(org.infinispan.container.entries.TransientMortalCacheEntry) MetadataTransientMortalCacheEntry(org.infinispan.container.entries.metadata.MetadataTransientMortalCacheEntry) MetadataImmortalCacheEntry(org.infinispan.container.entries.metadata.MetadataImmortalCacheEntry) MetadataMortalCacheEntry(org.infinispan.container.entries.metadata.MetadataMortalCacheEntry) TransientCacheEntry(org.infinispan.container.entries.TransientCacheEntry) MetadataTransientCacheEntry(org.infinispan.container.entries.metadata.MetadataTransientCacheEntry)

Example 2 with MetadataImmortalCacheEntry

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());
    }
}
Also used : TransientMortalCacheEntry(org.infinispan.container.entries.TransientMortalCacheEntry) MetadataMortalCacheEntry(org.infinispan.container.entries.metadata.MetadataMortalCacheEntry) MortalCacheEntry(org.infinispan.container.entries.MortalCacheEntry) MetadataTransientMortalCacheEntry(org.infinispan.container.entries.metadata.MetadataTransientMortalCacheEntry) ImmortalCacheEntry(org.infinispan.container.entries.ImmortalCacheEntry) MetadataImmortalCacheEntry(org.infinispan.container.entries.metadata.MetadataImmortalCacheEntry) MetadataTransientCacheEntry(org.infinispan.container.entries.metadata.MetadataTransientCacheEntry) MetadataTransientMortalCacheEntry(org.infinispan.container.entries.metadata.MetadataTransientMortalCacheEntry) TransientMortalCacheEntry(org.infinispan.container.entries.TransientMortalCacheEntry) MetadataTransientMortalCacheEntry(org.infinispan.container.entries.metadata.MetadataTransientMortalCacheEntry) MetadataImmortalCacheEntry(org.infinispan.container.entries.metadata.MetadataImmortalCacheEntry) MetadataMortalCacheEntry(org.infinispan.container.entries.metadata.MetadataMortalCacheEntry) TransientCacheEntry(org.infinispan.container.entries.TransientCacheEntry) MetadataTransientCacheEntry(org.infinispan.container.entries.metadata.MetadataTransientCacheEntry)

Example 3 with MetadataImmortalCacheEntry

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;
}
Also used : MetadataTransientMortalCacheEntry(org.infinispan.container.entries.metadata.MetadataTransientMortalCacheEntry) MetadataMortalCacheEntry(org.infinispan.container.entries.metadata.MetadataMortalCacheEntry) EmbeddedMetadata(org.infinispan.metadata.EmbeddedMetadata) MetadataImmortalCacheEntry(org.infinispan.container.entries.metadata.MetadataImmortalCacheEntry) MetadataTransientCacheEntry(org.infinispan.container.entries.metadata.MetadataTransientCacheEntry) MetadataTransientMortalCacheEntry(org.infinispan.container.entries.metadata.MetadataTransientMortalCacheEntry) EmbeddedMetadata(org.infinispan.metadata.EmbeddedMetadata) PrivateMetadata(org.infinispan.metadata.impl.PrivateMetadata) Metadata(org.infinispan.metadata.Metadata) MetadataTransientMortalCacheEntry(org.infinispan.container.entries.metadata.MetadataTransientMortalCacheEntry) MetadataImmortalCacheEntry(org.infinispan.container.entries.metadata.MetadataImmortalCacheEntry) MetadataMortalCacheEntry(org.infinispan.container.entries.metadata.MetadataMortalCacheEntry) MetadataTransientCacheEntry(org.infinispan.container.entries.metadata.MetadataTransientCacheEntry)

Example 4 with MetadataImmortalCacheEntry

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);
            }
        }
    }
}
Also used : TransientMortalCacheEntry(org.infinispan.container.entries.TransientMortalCacheEntry) MetadataMortalCacheEntry(org.infinispan.container.entries.metadata.MetadataMortalCacheEntry) MortalCacheEntry(org.infinispan.container.entries.MortalCacheEntry) MetadataTransientMortalCacheEntry(org.infinispan.container.entries.metadata.MetadataTransientMortalCacheEntry) ImmortalCacheEntry(org.infinispan.container.entries.ImmortalCacheEntry) MetadataImmortalCacheEntry(org.infinispan.container.entries.metadata.MetadataImmortalCacheEntry) TransientMortalCacheEntry(org.infinispan.container.entries.TransientMortalCacheEntry) MetadataTransientMortalCacheEntry(org.infinispan.container.entries.metadata.MetadataTransientMortalCacheEntry) MetadataImmortalCacheEntry(org.infinispan.container.entries.metadata.MetadataImmortalCacheEntry) TransientCacheEntry(org.infinispan.container.entries.TransientCacheEntry) MetadataTransientCacheEntry(org.infinispan.container.entries.metadata.MetadataTransientCacheEntry)

Example 5 with MetadataImmortalCacheEntry

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);
}
Also used : Metadata(org.infinispan.metadata.Metadata) MetadataImmortalCacheEntry(org.infinispan.container.entries.metadata.MetadataImmortalCacheEntry)

Aggregations

MetadataImmortalCacheEntry (org.infinispan.container.entries.metadata.MetadataImmortalCacheEntry)5 MetadataMortalCacheEntry (org.infinispan.container.entries.metadata.MetadataMortalCacheEntry)4 MetadataTransientCacheEntry (org.infinispan.container.entries.metadata.MetadataTransientCacheEntry)4 MetadataTransientMortalCacheEntry (org.infinispan.container.entries.metadata.MetadataTransientMortalCacheEntry)4 ImmortalCacheEntry (org.infinispan.container.entries.ImmortalCacheEntry)3 MortalCacheEntry (org.infinispan.container.entries.MortalCacheEntry)3 TransientCacheEntry (org.infinispan.container.entries.TransientCacheEntry)3 TransientMortalCacheEntry (org.infinispan.container.entries.TransientMortalCacheEntry)3 Metadata (org.infinispan.metadata.Metadata)2 EmbeddedMetadata (org.infinispan.metadata.EmbeddedMetadata)1 PrivateMetadata (org.infinispan.metadata.impl.PrivateMetadata)1