2 Replies Latest reply on Feb 10, 2014 6:47 AM by Serge Moers

    Persistent SingleFileStore problem

    Serge Moers Newbie

      Dear All,

      It's the first time that I use "Infinispan". I must use a simple persistent cache.

      I have realized a simple test (see hereafter) , the cache functionnality running correctly, but it's not persistent.  The data are lost after each run.

      Can you tell where I have does a error in my code ?

       

      Infinispan version: Infinispan 'Infinium' 6.0.0.Final

       

      import java.util.Iterator;

      import java.util.Map.Entry;

      import java.util.Set;

      import java.util.UUID;

       

      import org.infinispan.Cache;

      import org.infinispan.configuration.cache.Configuration;

      import org.infinispan.configuration.cache.ConfigurationBuilder;

      import org.infinispan.manager.DefaultCacheManager;

      import org.infinispan.manager.EmbeddedCacheManager;

       

       

      public class Inf_1 {

       

          public static void main(String[] args) throws InterruptedException {

              // TODO Auto-generated method stub

             

              EmbeddedCacheManager manager = new DefaultCacheManager();

              ConfigurationBuilder cb = new ConfigurationBuilder();

             

              Configuration c = cb

                  .persistence()

                  .passivation(false)

                  .addSingleFileStore()

                  .preload(true)

                  .shared(false)

                  .fetchPersistentState(true)

                  .ignoreModifications(false)

                  .purgeOnStartup(false)

                  .location("D:/infinispan")

                  .singleton()

                      .enabled(true)

                      .pushStateWhenCoordinator(true)

                      .pushStateTimeout(20)

                  .build();

             

              manager.defineConfiguration("Test", c);

             

              Cache<UUID, Object> cache = manager.getCache("Test");

       

              System.out.println(cache.size());

             

              for(int i=1 ; i<10; i++){

                  Author author = new Author(i);

                  author.setFirstname("FirstName"+i);

                  author.setLastname("LastName"+i);

                  cache.put(UUID.randomUUID(), author);

              }

             

              System.out.println(cache.size());

              Thread.sleep(2000);

              Set<Entry<UUID, Object>> set = cache.getAdvancedCache().entrySet();

              Iterator it = set.iterator();

              while(it.hasNext()){

                  Entry entry = (Entry<UUID, Object>) it.next();

                  System.out.println(entry.getKey() + " // " + entry.getValue().toString());

              }

                     

             

             

              cache.stop();

              manager.stop();

          }

       

      }


      Result :

      févr. 03, 2014 12:59:21 PM org.infinispan.factories.GlobalComponentRegistry start

      INFO: ISPN000128: Infinispan version: Infinispan 'Infinium' 6.0.0.Final

      févr. 03, 2014 12:59:24 PM org.infinispan.jmx.CacheJmxRegistration start

      INFO: ISPN000031: MBeans were successfully registered to the platform MBean server.

      0

      9

      3a1f8260-cd83-4c35-8233-86d9599686c3 // Author [id=2.0, lastname=LastName2, firstname=FirstName2]

      1fdce9b1-8c5c-4690-bd8c-c31e7b00f09a // Author [id=4.0, lastname=LastName4, firstname=FirstName4]

      b07d8ac5-8bec-4f22-8e6b-885983d4ae9e // Author [id=5.0, lastname=LastName5, firstname=FirstName5]

      6219732d-def6-4c11-9889-df6cb14f8a5b // Author [id=9.0, lastname=LastName9, firstname=FirstName9]

      5443e2e6-0ece-4650-bd1a-60d6f4698bca // Author [id=3.0, lastname=LastName3, firstname=FirstName3]

      57478a4e-c05a-46cf-a74f-bac7d17b4260 // Author [id=6.0, lastname=LastName6, firstname=FirstName6]

      dfde6a15-b863-4450-a165-be06040dbfa4 // Author [id=8.0, lastname=LastName8, firstname=FirstName8]

      e80fcd74-24bb-4370-b13b-eb5bba5950c6 // Author [id=7.0, lastname=LastName7, firstname=FirstName7]

      da85538e-6dc2-4576-8a49-4caa27d60e07 // Author [id=1.0, lastname=LastName1, firstname=FirstName1]


      Many thanks !!

      Serge