当前位置: 首页>>代码示例>>Java>>正文


Java TaskContextImpl类代码示例

本文整理汇总了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());
   }

}
 
开发者ID:infinispan,项目名称:infinispan-cachestore-mongodb,代码行数:41,代码来源:MongoDBStore.java

示例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);
   }
}
 
开发者ID:saturnism,项目名称:infinispan-cachestore-mapdb,代码行数:31,代码来源:MapDBStore.java

示例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);
}
 
开发者ID:infinispan,项目名称:infinispan-cachestore-cloud,代码行数:43,代码来源:CloudStore.java


注:本文中的org.infinispan.persistence.TaskContextImpl类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。