use of org.infinispan.factories.threads.BlockingThreadFactory 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();
}
Aggregations