Package org.infinispan.persistence.spi

Examples of org.infinispan.persistence.spi.AdvancedCacheLoader


      waitForClusterToForm();
   }

   @Override
   protected void assertNumberOfEntries(int cacheIndex) throws Exception {
      AdvancedCacheLoader cacheStore = (AdvancedCacheLoader) TestingUtil.getCacheLoader(cache(cacheIndex));
      Assert.assertEquals(1, PersistenceUtil.count(cacheStore, null)); // one entry in store

      DataContainer dataContainer = cache(cacheIndex).getAdvancedCache().getDataContainer();
      Assert.assertEquals(1, dataContainer.size());        // only one entry in memory (the other one was evicted)
   }
View Full Code Here


      for(int i = 0; i < 4; i++){
         cache.put(cacheManagers.get(0).getAddress().toString()+"-"+i, "42");
      }

      // lets check if all elements arrived
      AdvancedCacheLoader cs1 = (AdvancedCacheLoader) TestingUtil.getCacheLoader(cache);
      Set<Object> keys = PersistenceUtil.toKeySet(cs1, null);

      Assert.assertEquals(keys.size(), 4);

      // now start 2nd node
      addClusterEnabledCacheManager(getCB());
      waitForClusterToForm("P006");

      cache = cacheManagers.get(1).getCache("P006");

      // add next 4 elements
      for(int i = 0; i < 4; i++){
         cache.put(cacheManagers.get(1).getAddress().toString()+"-"+i, "42");
      }

      Set mergedKeys = new HashSet();
      // add keys from all cache stores
      AdvancedCacheLoader cs2 = (AdvancedCacheLoader) TestingUtil.getCacheLoader(cache);
      log.debugf("Load from cache store via cache 1");
      mergedKeys.addAll(PersistenceUtil.toKeySet(cs1, null));
      log.debugf("Load from cache store via cache 2");
      mergedKeys.addAll(PersistenceUtil.toKeySet(cs2, null));
View Full Code Here

      addClusterEnabledCacheManager(configBuilder);
   }

   @Override
   protected void assertNumberOfEntries(int cacheIndex) throws Exception {
      AdvancedCacheLoader cacheStore = (AdvancedCacheLoader) TestingUtil.getCacheLoader(cache(cacheIndex));
      assertEquals(1, PersistenceUtil.count(cacheStore, null)); // one entry in store

      DataContainer dataContainer = cache(cacheIndex).getAdvancedCache().getDataContainer();
      assertEquals(1, dataContainer.size());        // only one entry in memory (the other one was evicted)
   }
View Full Code Here

      purgingCfg.read(cfg.build());
      purgingCfg.persistence().clearStores().addStore(DummyInMemoryStoreConfigurationBuilder.class)
         .storeName("purgingCache").purgeOnStartup(true);
      cm.defineConfiguration("purgingCache", purgingCfg.build());
      Cache<String, String> purgingCache = cm.getCache("purgingCache");
      AdvancedCacheLoader purgingLoader = (AdvancedCacheLoader) TestingUtil.getCacheLoader(purgingCache);

      assertNotInCacheAndStore(purgingCache, purgingLoader, "k1", "k2", "k3", "k4");

      purgingCache.put("k1", "v1");
      purgingCache.put("k2", "v2", lifespan, MILLISECONDS);
View Full Code Here

   protected void doPreloadingTest(Configuration preloadingCfg, String cacheName) throws Exception {
      assertTrue("Preload not enabled for preload test", preloadingCfg.persistence().preload());
      cm.defineConfiguration(cacheName, preloadingCfg);
      Cache<String, String> preloadingCache = cm.getCache(cacheName);
      AdvancedCacheLoader preloadingCacheLoader = (AdvancedCacheLoader) TestingUtil.getCacheLoader(preloadingCache);

      assert preloadingCache.getCacheConfiguration().persistence().preload();

      assertNotInCacheAndStore(preloadingCache, preloadingCacheLoader, "k1", "k2", "k3", "k4");
View Full Code Here

      cm.defineConfiguration(cacheName, preloadingCfg);

      final Cache<String, String> preloadingCache = cm.getCache(cacheName);
      final int expectedEntriesInContainer = Math.min(4, preloadingCfg.eviction().maxEntries());
      AdvancedCacheLoader preloadingCacheLoader = (AdvancedCacheLoader) TestingUtil.getCacheLoader(preloadingCache);

      assertTrue("Preload not enabled in cache configuration",
                 preloadingCache.getCacheConfiguration().persistence().preload());
      assertNotInCacheAndStore(preloadingCache, preloadingCacheLoader, "k1", "k2", "k3", "k4");

      preloadingCache.getAdvancedCache().getTransactionManager().begin();
      preloadingCache.put("k1", "v1");
      preloadingCache.put("k2", "v2", lifespan, MILLISECONDS);
      preloadingCache.put("k3", "v3");
      preloadingCache.put("k4", "v4", lifespan, MILLISECONDS);
      preloadingCache.getAdvancedCache().getTransactionManager().commit();

      DataContainer c = preloadingCache.getAdvancedCache().getDataContainer();
      assertEquals("Wrong number of entries in data container", expectedEntriesInContainer, c.size());

      for (int i = 1; i < 5; i++) {
         final Object key = "k" + i;
         final Object value = "v" + i;
         final long lifespan = i % 2 == 1 ? -1 : this.lifespan;
         boolean found = false;
         InternalCacheEntry se = preloadingCache.getAdvancedCache().getDataContainer().get(key);
         MarshalledEntry load = preloadingCacheLoader.load(key);
         if (se != null) {
            testStoredEntry(se.getValue(), value, se.getLifespan(), lifespan, "Cache", key);
            found = true;
         }
         if (load != null) {
            testStoredEntry(load.getValue(), value, load.getMetadata().lifespan(), lifespan, "Store", key);
            found = true;
         }
         assertTrue("Key not found.", found);
      }

      preloadingCache.stop();
      assertEquals("DataContainer still has entries after stop", 0, c.size());

      preloadingCache.start();
      // The old store's marshaller is not working any more
      preloadingCacheLoader = (AdvancedCacheLoader) TestingUtil.getCacheLoader(preloadingCache);

      assertTrue("Preload not enabled in cache configuration",
                 preloadingCache.getCacheConfiguration().persistence().preload());

      c = preloadingCache.getAdvancedCache().getDataContainer();
      assertEquals("Wrong number of entries in data container", expectedEntriesInContainer, c.size());

      for (int i = 1; i < 5; i++) {
         final Object key = "k" + i;
         final Object value = "v" + i;
         final long lifespan = i % 2 == 1 ? -1 : this.lifespan;
         boolean found = false;
         InternalCacheEntry se = preloadingCache.getAdvancedCache().getDataContainer().get(key);
         MarshalledEntry load = preloadingCacheLoader.load(key);
         if (se != null) {
            testStoredEntry(se.getValue(), value, se.getLifespan(), lifespan, "Cache", key);
            found = true;
         }
         if (load != null) {
View Full Code Here

         return c.call();
      }
   }

   protected void assertNumberOfEntries(int cacheIndex) throws Exception {
      AdvancedCacheLoader loader = (AdvancedCacheLoader) TestingUtil.getCacheLoader(cache(cacheIndex));
      assertEquals(2, PersistenceUtil.count(loader, null)); // two entries in store

      DataContainer dataContainer = cache(cacheIndex).getAdvancedCache().getDataContainer();
      assertEquals(1, dataContainer.size());        // only one entry in memory (the other one was evicted)
   }
View Full Code Here

            if (segments.contains(segmentId)) {
               sendEntry(ice, segmentId);
            }
         }

         AdvancedCacheLoader stProvider = persistenceManager.getStateTransferProvider();
         if (stProvider != null) {
            try {
               CollectionKeyFilter filter = new CollectionKeyFilter(new ReadOnlyDataContainerBackedKeySet(dataContainer));
               AdvancedCacheLoader.CacheLoaderTask task = new AdvancedCacheLoader.CacheLoaderTask() {
                  @Override
                  public void processEntry(MarshalledEntry me, AdvancedCacheLoader.TaskContext taskContext) throws InterruptedException {
                        int segmentId = readCh.getSegment(me.getKey());
                        if (segments.contains(segmentId)) {
                           try {
                              InternalCacheEntry icv = entryFactory.create(me.getKey(), me.getValue(), me.getMetadata());
                              sendEntry(icv, segmentId);
                           } catch (CacheException e) {
                              log.failedLoadingValueFromCacheStore(me.getKey(), e);
                           }
                        }
                     }
                  };
               stProvider.process(filter, task, new WithinThreadExecutor(), true, true);
            } catch (CacheException e) {
               log.failedLoadingKeysFromCacheStore(e);
            }
         }
View Full Code Here

   @Override
   @Start(priority = 56)
   public void preload() {
      if (!enabled)
         return;
      AdvancedCacheLoader preloadCl = null;

      for (CacheLoader l : loaders) {
         if (configMap.get(l).preload()) {
            if (!(l instanceof AdvancedCacheLoader)) {
               throw new PersistenceException("Cannot preload from cache loader '" + l.getClass().getName()
                                                    + "' as it doesn't implement '" + AdvancedCacheLoader.class.getName() + "'");
            }
            preloadCl = (AdvancedCacheLoader) l;
            if (preloadCl instanceof AdvancedAsyncCacheLoader)
               preloadCl = (AdvancedCacheLoader) ((AdvancedAsyncCacheLoader) preloadCl).undelegate();
            break;
         }
      }
      if (preloadCl == null)
         return;

      long start = timeService.time();


      final int maxEntries = getMaxEntries();
      final AtomicInteger loadedEntries = new AtomicInteger(0);
      final AdvancedCache<Object, Object> flaggedCache = getCacheForStateInsertion();
      preloadCl.process(null, new AdvancedCacheLoader.CacheLoaderTask() {
         @Override
         public void processEntry(MarshalledEntry me, AdvancedCacheLoader.TaskContext taskContext) throws InterruptedException {
            if (loadedEntries.getAndIncrement() >= maxEntries) {
               taskContext.stop();
               return;
View Full Code Here

   @Override
   @Start(priority = 56)
   public void preload() {
      if (!enabled)
         return;
      AdvancedCacheLoader preloadCl = null;

      for (CacheLoader l : loaders) {
         if (configMap.get(l).preload()) {
            if (!(l instanceof AdvancedCacheLoader)) {
               throw new PersistenceException("Cannot preload from cache loader '" + l.getClass().getName()
                                                    + "' as it doesn't implement '" + AdvancedCacheLoader.class.getName() + "'");
            }
            preloadCl = (AdvancedCacheLoader) l;
            if (preloadCl instanceof AdvancedAsyncCacheLoader)
               preloadCl = (AdvancedCacheLoader) ((AdvancedAsyncCacheLoader) preloadCl).undelegate();
            break;
         }
      }
      if (preloadCl == null)
         return;

      long start = timeService.time();


      final int maxEntries = getMaxEntries();
      final AtomicInteger loadedEntries = new AtomicInteger(0);
      final AdvancedCache<Object, Object> flaggedCache = getCacheForStateInsertion();
      preloadCl.process(null, new AdvancedCacheLoader.CacheLoaderTask() {
         @Override
         public void processEntry(MarshalledEntry me, AdvancedCacheLoader.TaskContext taskContext) throws InterruptedException {
            if (loadedEntries.getAndIncrement() >= maxEntries) {
               taskContext.stop();
               return;
View Full Code Here

TOP

Related Classes of org.infinispan.persistence.spi.AdvancedCacheLoader

Copyright © 2018 www.massapicom. 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.