Search in sources :

Example 1 with TransientMortalCacheEntry

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

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

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

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)));
    }
}
Also used : CacheEventConverter(org.infinispan.notifications.cachelistener.filter.CacheEventConverter) CacheEventFilter(org.infinispan.notifications.cachelistener.filter.CacheEventFilter) ArrayList(java.util.ArrayList) Metadata(org.infinispan.metadata.Metadata) TransientMortalCacheEntry(org.infinispan.container.entries.TransientMortalCacheEntry) TransientMortalCacheEntry(org.infinispan.container.entries.TransientMortalCacheEntry) ImmortalCacheEntry(org.infinispan.container.entries.ImmortalCacheEntry) CacheEntry(org.infinispan.container.entries.CacheEntry)

Example 5 with TransientMortalCacheEntry

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

Aggregations

TransientMortalCacheEntry (org.infinispan.container.entries.TransientMortalCacheEntry)7 ImmortalCacheEntry (org.infinispan.container.entries.ImmortalCacheEntry)5 MortalCacheEntry (org.infinispan.container.entries.MortalCacheEntry)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 CacheEntry (org.infinispan.container.entries.CacheEntry)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 TimeUnit (java.util.concurrent.TimeUnit)1 Cache (org.infinispan.Cache)1 InternalCacheEntry (org.infinispan.container.entries.InternalCacheEntry)1 Metadata (org.infinispan.metadata.Metadata)1 CacheEventConverter (org.infinispan.notifications.cachelistener.filter.CacheEventConverter)1 CacheEventFilter (org.infinispan.notifications.cachelistener.filter.CacheEventFilter)1 Test (org.testng.annotations.Test)1