Search in sources :

Example 1 with DataConversion

use of org.infinispan.encoding.DataConversion in project infinispan by infinispan.

the class ClusteredStatsTest method primaryKeysCount.

@Override
protected long primaryKeysCount(Cache<?, ?> cache) {
    DistributionManager dm = TestingUtil.extractComponent(cache, DistributionManager.class);
    long count = 0;
    for (int i = 0; i < TOTAL_ENTRIES; i++) {
        DataConversion keyDataConversion = cache.getAdvancedCache().getKeyDataConversion();
        if (dm.getCacheTopology().getDistribution(keyDataConversion.toStorage("key" + i)).isPrimary()) {
            count++;
        }
    }
    return count;
}
Also used : DataConversion(org.infinispan.encoding.DataConversion) DistributionManager(org.infinispan.distribution.DistributionManager)

Example 2 with DataConversion

use of org.infinispan.encoding.DataConversion in project infinispan by infinispan.

the class EncoderCache method withEncoding.

@Override
public AdvancedCache<K, V> withEncoding(Class<? extends Encoder> keyEncoderClass, Class<? extends Encoder> valueEncoderClass) {
    checkSubclass(keyEncoderClass, Encoder.class);
    checkSubclass(valueEncoderClass, Encoder.class);
    DataConversion newKeyDataConversion = keyDataConversion.withEncoding(keyEncoderClass);
    DataConversion newValueDataConversion = valueDataConversion.withEncoding(valueEncoderClass);
    EncoderCache<K, V> encoderCache = new EncoderCache<>(cache, entryFactory, componentRegistry, newKeyDataConversion, newValueDataConversion);
    encoderCache.lookupEncoderWrapper();
    return encoderCache;
}
Also used : DataConversion(org.infinispan.encoding.DataConversion)

Example 3 with DataConversion

use of org.infinispan.encoding.DataConversion in project infinispan by infinispan.

the class EncoderCache method withMediaType.

@Override
public AdvancedCache<K, V> withMediaType(MediaType kType, MediaType vType) {
    DataConversion newKeyDataConversion = keyDataConversion.withRequestMediaType(kType);
    DataConversion newValueDataConversion = valueDataConversion.withRequestMediaType(vType);
    EncoderCache<K, V> encoderCache = new EncoderCache<>(cache, entryFactory, componentRegistry, newKeyDataConversion, newValueDataConversion);
    encoderCache.lookupEncoderWrapper();
    return encoderCache;
}
Also used : DataConversion(org.infinispan.encoding.DataConversion)

Example 4 with DataConversion

use of org.infinispan.encoding.DataConversion in project infinispan by infinispan.

the class EncoderCache method withWrapping.

@Override
public AdvancedCache<K, V> withWrapping(Class<? extends Wrapper> keyWrapperClass, Class<? extends Wrapper> valueWrapperClass) {
    checkSubclass(keyWrapperClass, Wrapper.class);
    checkSubclass(valueWrapperClass, Wrapper.class);
    DataConversion newKeyDataConversion = keyDataConversion.withWrapping(keyWrapperClass);
    DataConversion newValueDataConversion = valueDataConversion.withWrapping(valueWrapperClass);
    EncoderCache<K, V> encoderCache = new EncoderCache<>(cache, entryFactory, componentRegistry, newKeyDataConversion, newValueDataConversion);
    encoderCache.lookupEncoderWrapper();
    return encoderCache;
}
Also used : DataConversion(org.infinispan.encoding.DataConversion)

Example 5 with DataConversion

use of org.infinispan.encoding.DataConversion in project infinispan by infinispan.

the class OffHeapSingleNodeExpirationEvictionTest method testEnsureCorrectStorage.

public void testEnsureCorrectStorage() {
    Cache<String, String> cache = cache(0);
    long beforeInsert = timeService.wallClockTime();
    cache.put("k", "v");
    timeService.advance(10);
    DataConversion dataConversion = cache.getAdvancedCache().getKeyDataConversion();
    Object convertedKey = dataConversion.toStorage("k");
    assertNotNull(cache.getAdvancedCache().getDataContainer().get(convertedKey));
    CacheEntry<String, String> entry = cache.getAdvancedCache().getDataContainer().peek(convertedKey);
    assertNotNull(entry);
    long storedTime = TimeUnit.MINUTES.toMillis(10);
    switch(expirationType) {
        case MORTAL:
            assertEquals(storedTime, entry.getLifespan());
            assertEquals(-1, entry.getMaxIdle());
            assertEquals(beforeInsert, entry.getCreated());
            assertEquals(-1, entry.getLastUsed());
            break;
        case TRANSIENT:
            assertEquals(-1, entry.getLifespan());
            assertEquals(storedTime, entry.getMaxIdle());
            assertEquals(-1, entry.getCreated());
            assertEquals(beforeInsert, entry.getLastUsed());
            break;
        case TRANSIENT_MORTAL:
            assertEquals(storedTime, entry.getLifespan());
            assertEquals(storedTime, entry.getMaxIdle());
            assertEquals(beforeInsert, entry.getCreated());
            assertEquals(beforeInsert, entry.getLastUsed());
            break;
    }
}
Also used : DataConversion(org.infinispan.encoding.DataConversion)

Aggregations

DataConversion (org.infinispan.encoding.DataConversion)41 MVCCEntry (org.infinispan.container.entries.MVCCEntry)9 KeyPartitioner (org.infinispan.distribution.ch.KeyPartitioner)9 ArrayList (java.util.ArrayList)8 AdvancedCache (org.infinispan.AdvancedCache)8 Util (org.infinispan.commons.util.Util)8 EnumUtil (org.infinispan.commons.util.EnumUtil)7 InvocationContext (org.infinispan.context.InvocationContext)7 Completable (io.reactivex.rxjava3.core.Completable)6 Flowable (io.reactivex.rxjava3.core.Flowable)6 Set (java.util.Set)6 CompletionStage (java.util.concurrent.CompletionStage)6 Function (java.util.function.Function)6 Transaction (javax.transaction.Transaction)6 TransactionManager (javax.transaction.TransactionManager)6 MediaType (org.infinispan.commons.dataconversion.MediaType)6 TimeService (org.infinispan.commons.time.TimeService)6 Configuration (org.infinispan.configuration.cache.Configuration)6 CacheEntry (org.infinispan.container.entries.CacheEntry)6 FlagBitSets (org.infinispan.context.impl.FlagBitSets)6