Search in sources :

Example 1 with MortalCacheEntry

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());
    }
}
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 MortalCacheEntry

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());
    }
}
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 MortalCacheEntry

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

Example 4 with MortalCacheEntry

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;
}
Also used : MortalCacheEntry(org.infinispan.container.entries.MortalCacheEntry) TransientMortalCacheEntry(org.infinispan.container.entries.TransientMortalCacheEntry) InternalCacheEntry(org.infinispan.container.entries.InternalCacheEntry) Cache(org.infinispan.Cache)

Example 5 with MortalCacheEntry

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);
            }
        }
    }
}
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)

Aggregations

MortalCacheEntry (org.infinispan.container.entries.MortalCacheEntry)5 TransientMortalCacheEntry (org.infinispan.container.entries.TransientMortalCacheEntry)5 ImmortalCacheEntry (org.infinispan.container.entries.ImmortalCacheEntry)4 TransientCacheEntry (org.infinispan.container.entries.TransientCacheEntry)4 MetadataImmortalCacheEntry (org.infinispan.container.entries.metadata.MetadataImmortalCacheEntry)3 MetadataMortalCacheEntry (org.infinispan.container.entries.metadata.MetadataMortalCacheEntry)3 MetadataTransientCacheEntry (org.infinispan.container.entries.metadata.MetadataTransientCacheEntry)3 MetadataTransientMortalCacheEntry (org.infinispan.container.entries.metadata.MetadataTransientMortalCacheEntry)3 Cache (org.infinispan.Cache)1 InternalCacheEntry (org.infinispan.container.entries.InternalCacheEntry)1