Package org.radargun.service

Source Code of org.radargun.service.Infinispan70CacheInfo$Cache

package org.radargun.service;

import java.util.Iterator;

import org.infinispan.AdvancedCache;
import org.infinispan.commons.util.CloseableIterable;
import org.infinispan.iteration.EntryIterable;
import org.radargun.filters.AllFilter;
import org.radargun.filters.NullConverter;
import org.radargun.logging.Log;
import org.radargun.logging.LogFactory;
import org.radargun.traits.CacheInformation;

/**
* @author Radim Vansa <rvansa@redhat.com>
* @author Alan Field <afield@redhat.com>
*/
public class Infinispan70CacheInfo extends Infinispan53CacheInfo {
   private final Log log = LogFactory.getLog(Infinispan70CacheInfo.class);

   public Infinispan70CacheInfo(InfinispanEmbeddedService service) {
      super(service);
   }

   @Override
   public CacheInformation.Cache getCache(String cacheName) {
      return new Cache(service.getCache(cacheName).getAdvancedCache());
   }

   protected class Cache extends Infinispan53CacheInfo.Cache {
      public Cache(AdvancedCache cache) {
         super(cache);
      }

      @Override
      public long getTotalSize() {
         long totalSize = 0;
         EntryIterable entryIterator = null;
         try {
            entryIterator = cache.filterEntries(AllFilter.INSTANCE);
            CloseableIterable ci = entryIterator.converter(NullConverter.INSTANCE);
            Iterator iter = ci.iterator();
            while (iter.hasNext()) {
               iter.next();
               totalSize++;
            }
            return totalSize;
         } finally {
            if (entryIterator != null) {
               try {
                  entryIterator.close();
               } catch (Exception e) {
                  log.error("Failed to close EntryIterable", e);
               }
            }
         }
      }

   }

}
TOP

Related Classes of org.radargun.service.Infinispan70CacheInfo$Cache

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.