本文整理汇总了Java中org.infinispan.persistence.TaskContextImpl类的典型用法代码示例。如果您正苦于以下问题:Java TaskContextImpl类的具体用法?Java TaskContextImpl怎么用?Java TaskContextImpl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TaskContextImpl类属于org.infinispan.persistence包,在下文中一共展示了TaskContextImpl类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import org.infinispan.persistence.TaskContextImpl; //导入依赖的package包/类
@Override
public void process(final KeyFilter<? super K> filter, final CacheLoaderTask<K, V> task, Executor executor, boolean fetchValue, boolean fetchMetadata) {
ExecutorAllCompletionService eacs = new ExecutorAllCompletionService(executor);
final TaskContextImpl taskContext = new TaskContextImpl();
//A while loop since we have to hit the db again for paging.
boolean shouldContinue = true;
byte[] id = null;
while (shouldContinue) {
final List<MongoDBEntry<K, V>> entries = cache.getPagedEntries(id);
shouldContinue = !entries.isEmpty();
if (taskContext.isStopped()) {
break;
}
if (shouldContinue) {
eacs.submit(() -> {
for (final MongoDBEntry<K, V> entry : entries) {
if (taskContext.isStopped()) {
break;
}
final K marshalledKey = (K) toObject(entry.getKeyBytes());
if (filter == null || filter.accept(marshalledKey)) {
final MarshalledEntry<K, V> marshalledEntry = getMarshalledEntry(entry);
if (marshalledEntry != null) {
task.processEntry(marshalledEntry, taskContext);
}
}
}
return null;
});
//get last key so we can get more entries.
id = entries.get(entries.size() - 1).getKeyBytes();
}
}
eacs.waitUntilAllCompleted();
if (eacs.isExceptionThrown()) {
throw new PersistenceException("Execution exception!", eacs.getFirstException());
}
}
示例2: process
import org.infinispan.persistence.TaskContextImpl; //导入依赖的package包/类
@Override
public void process(KeyFilter filter, CacheLoaderTask task, Executor executor, boolean fetchValue,
boolean fetchMetadata) {
int batchSize = 100;
ExecutorCompletionService ecs = new ExecutorCompletionService(executor);
int tasks = 0;
final TaskContext taskContext = new TaskContextImpl();
List<Map.Entry<Object, byte[]>> entries = new ArrayList<Map.Entry<Object, byte[]>>(batchSize);
try {
for (Map.Entry<Object, byte[]> entry : store.entrySet()) {
entries.add(entry);
if (entries.size() == batchSize) {
final List<Map.Entry<Object, byte[]>> batch = entries;
entries = new ArrayList<Map.Entry<Object, byte[]>>(batchSize);
submitProcessTask(task, filter, ecs, taskContext, batch);
tasks++;
}
}
if (!entries.isEmpty()) {
submitProcessTask(task, filter,ecs, taskContext, entries);
tasks++;
}
PersistenceUtil.waitForAllTasksToComplete(ecs, tasks);
} catch (Exception e) {
throw new CacheLoaderException(e);
}
}
示例3: process
import org.infinispan.persistence.TaskContextImpl; //导入依赖的package包/类
@Override
public void process(KeyFilter<? super K> keyFilter, final CacheLoaderTask<K, V> cacheLoaderTask, Executor executor,
boolean loadValue, boolean loadMetadata) {
String nextMarker = null;
PageSet<? extends StorageMetadata> pageSet;
do {
ListContainerOptions listOptions = nextMarker == null ? ListContainerOptions.NONE
: ListContainerOptions.Builder.afterMarker(nextMarker);
pageSet = blobStore.list(containerName, listOptions);
ExecutorAllCompletionService eacs = new ExecutorAllCompletionService(executor);
final TaskContext taskContext = new TaskContextImpl();
Set<Object> entries = new HashSet<Object>(BATCH_SIZE);
Iterator<? extends StorageMetadata> storageMetadataIterator = pageSet.iterator();
while (storageMetadataIterator.hasNext()) {
StorageMetadata blobMetadata = storageMetadataIterator.next();
K key = (K) key2StringMapper.getKeyMapping(blobMetadata.getName());
if (keyFilter == null || keyFilter.accept(key)) {
entries.add(key);
}
if (entries.size() == BATCH_SIZE) {
final Set<Object> batch = entries;
entries = new HashSet<Object>(BATCH_SIZE);
submitProcessTask(cacheLoaderTask, eacs, taskContext, batch, loadValue, loadMetadata);
}
}
if (!entries.isEmpty()) {
submitProcessTask(cacheLoaderTask, eacs, taskContext, entries, loadValue, loadMetadata);
}
eacs.waitUntilAllCompleted();
if (eacs.isExceptionThrown()) {
throw new PersistenceException("Process execution exception!", eacs.getFirstException());
}
nextMarker = pageSet.getNextMarker();
} while (nextMarker != null);
}