Search in sources :

Example 1 with CacheEntry

use of org.infinispan.container.entries.CacheEntry in project indy by Commonjava.

the class ScheduleManager method getNextExpireTime.

private Date getNextExpireTime(final ScheduleKey cacheKey) {
    return scheduleCache.execute(cache -> {
        final CacheEntry entry = cache.getAdvancedCache().getCacheEntry(cacheKey);
        if (entry != null) {
            final Metadata metadata = entry.getMetadata();
            long expire = metadata.lifespan();
            final long startTimeInMillis = (Long) scheduleCache.get(cacheKey).get(SCHEDULE_TIME);
            return calculateNextExpireTime(expire, startTimeInMillis);
        }
        return null;
    });
}
Also used : Metadata(org.infinispan.metadata.Metadata) CacheEntry(org.infinispan.container.entries.CacheEntry)

Example 2 with CacheEntry

use of org.infinispan.container.entries.CacheEntry in project hibernate-orm by hibernate.

the class TombstoneCallInterceptor method visitSizeCommand.

@Override
public Object visitSizeCommand(InvocationContext ctx, SizeCommand command) throws Throwable {
    Set<Flag> flags = command.getFlags();
    int size = 0;
    AdvancedCache decoratedCache = cache.getAdvancedCache();
    if (flags != null) {
        decoratedCache = decoratedCache.withFlags(flags.toArray(new Flag[flags.size()]));
    }
    // In non-transactional caches we don't care about context
    CloseableIterable<CacheEntry<Object, Object>> iterable = decoratedCache.filterEntries(Tombstone.EXCLUDE_TOMBSTONES).converter(NullValueConverter.getInstance());
    try {
        for (CacheEntry<Object, Object> entry : iterable) {
            if (size++ == Integer.MAX_VALUE) {
                return Integer.MAX_VALUE;
            }
        }
    } finally {
        iterable.close();
    }
    return size;
}
Also used : AdvancedCache(org.infinispan.AdvancedCache) CacheEntry(org.infinispan.container.entries.CacheEntry) Flag(org.infinispan.context.Flag)

Example 3 with CacheEntry

use of org.infinispan.container.entries.CacheEntry in project hibernate-orm by hibernate.

the class VersionedCallInterceptor method visitSizeCommand.

@Override
public Object visitSizeCommand(InvocationContext ctx, SizeCommand command) throws Throwable {
    Set<Flag> flags = command.getFlags();
    int size = 0;
    AdvancedCache decoratedCache = cache.getAdvancedCache();
    if (flags != null) {
        decoratedCache = decoratedCache.withFlags(flags.toArray(new Flag[flags.size()]));
    }
    // In non-transactional caches we don't care about context
    CloseableIterable<CacheEntry<Object, Void>> iterable = decoratedCache.filterEntries(VersionedEntry.EXCLUDE_EMPTY_EXTRACT_VALUE).converter(NullValueConverter.getInstance());
    try {
        for (CacheEntry<Object, Void> entry : iterable) {
            if (size++ == Integer.MAX_VALUE) {
                return Integer.MAX_VALUE;
            }
        }
    } finally {
        iterable.close();
    }
    return size;
}
Also used : AdvancedCache(org.infinispan.AdvancedCache) CacheEntry(org.infinispan.container.entries.CacheEntry) Flag(org.infinispan.context.Flag)

Example 4 with CacheEntry

use of org.infinispan.container.entries.CacheEntry in project hibernate-orm by hibernate.

the class BaseTransactionalDataRegion method removeEntries.

private void removeEntries(boolean inTransaction, KeyValueFilter filter) {
    // If the transaction is required, we simply need it -> will create our own
    boolean startedTx = false;
    if (!inTransaction && requiresTransaction) {
        try {
            tm.begin();
            startedTx = true;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    // We can never use cache.clear() since tombstones must be kept.
    try {
        AdvancedCache localCache = Caches.localCache(cache);
        CloseableIterator<CacheEntry> it = Caches.entrySet(localCache, Tombstone.EXCLUDE_TOMBSTONES).iterator();
        long now = nextTimestamp();
        try {
            while (it.hasNext()) {
                // Cannot use it.next(); it.remove() due to ISPN-5653
                CacheEntry entry = it.next();
                switch(strategy) {
                    case TOMBSTONES:
                        localCache.remove(entry.getKey(), entry.getValue());
                        break;
                    case VERSIONED_ENTRIES:
                        localCache.put(entry.getKey(), new VersionedEntry(null, null, now), tombstoneExpiration, TimeUnit.MILLISECONDS);
                        break;
                }
            }
        } finally {
            it.close();
        }
    } finally {
        if (startedTx) {
            try {
                tm.commit();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }
}
Also used : VersionedEntry(org.hibernate.cache.infinispan.util.VersionedEntry) AdvancedCache(org.infinispan.AdvancedCache) CacheEntry(org.infinispan.container.entries.CacheEntry)

Aggregations

CacheEntry (org.infinispan.container.entries.CacheEntry)4 AdvancedCache (org.infinispan.AdvancedCache)3 Flag (org.infinispan.context.Flag)2 VersionedEntry (org.hibernate.cache.infinispan.util.VersionedEntry)1 Metadata (org.infinispan.metadata.Metadata)1