Search in sources :

Example 1 with InvocationHelper

use of org.infinispan.cache.impl.InvocationHelper in project infinispan by infinispan.

the class MigrationTask method apply.

@Override
public Integer apply(EmbeddedCacheManager embeddedCacheManager) {
    AtomicInteger counter = new AtomicInteger(0);
    DefaultThreadFactory threadFactory = new BlockingThreadFactory(null, 1, THREAD_NAME + "-%t", null, null);
    ExecutorService executorService = Executors.newFixedThreadPool(threads, threadFactory);
    RemoveListener listener = null;
    AdvancedCache<Object, Object> advancedCache = embeddedCacheManager.getCache(cacheName).getAdvancedCache();
    Cache cache = advancedCache.withStorageMediaType();
    try {
        ComponentRegistry cr = cache.getAdvancedCache().getComponentRegistry();
        invocationHelper = cr.getComponent(InvocationHelper.class);
        commandsFactory = cr.getCommandsFactory();
        keyPartitioner = cr.getComponent(KeyPartitioner.class);
        PersistenceManager loaderManager = cr.getComponent(PersistenceManager.class);
        Set<RemoteStore<Object, Object>> stores = (Set) loaderManager.getStores(RemoteStore.class);
        listener = new RemoveListener();
        cache.addFilteredListener(listener, new RemovedFilter<>(), null, Util.asSet(CacheEntryRemoved.class));
        Iterator<RemoteStore<Object, Object>> storeIterator = stores.iterator();
        if (storeIterator.hasNext()) {
            RemoteStore<Object, Object> store = storeIterator.next();
            RemoteCache<Object, Object> storeCache = store.getRemoteCache();
            migrateEntriesWithMetadata(storeCache, counter, executorService, cache);
        }
    } finally {
        if (listener != null) {
            cache.removeListener(listener);
        }
        executorService.shutdown();
    }
    return counter.get();
}
Also used : Set(java.util.Set) BitSet(java.util.BitSet) PersistenceManager(org.infinispan.persistence.manager.PersistenceManager) RemoteStore(org.infinispan.persistence.remote.RemoteStore) DefaultThreadFactory(org.infinispan.factories.threads.DefaultThreadFactory) BlockingThreadFactory(org.infinispan.factories.threads.BlockingThreadFactory) CacheEntryRemoved(org.infinispan.notifications.cachelistener.annotation.CacheEntryRemoved) InvocationHelper(org.infinispan.cache.impl.InvocationHelper) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ComponentRegistry(org.infinispan.factories.ComponentRegistry) ExecutorService(java.util.concurrent.ExecutorService) Cache(org.infinispan.Cache) RemoteCache(org.infinispan.client.hotrod.RemoteCache) AdvancedCache(org.infinispan.AdvancedCache)

Aggregations

BitSet (java.util.BitSet)1 Set (java.util.Set)1 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AdvancedCache (org.infinispan.AdvancedCache)1 Cache (org.infinispan.Cache)1 InvocationHelper (org.infinispan.cache.impl.InvocationHelper)1 RemoteCache (org.infinispan.client.hotrod.RemoteCache)1 KeyPartitioner (org.infinispan.distribution.ch.KeyPartitioner)1 ComponentRegistry (org.infinispan.factories.ComponentRegistry)1 BlockingThreadFactory (org.infinispan.factories.threads.BlockingThreadFactory)1 DefaultThreadFactory (org.infinispan.factories.threads.DefaultThreadFactory)1 CacheEntryRemoved (org.infinispan.notifications.cachelistener.annotation.CacheEntryRemoved)1 PersistenceManager (org.infinispan.persistence.manager.PersistenceManager)1 RemoteStore (org.infinispan.persistence.remote.RemoteStore)1