0 Replies Latest reply on Jun 5, 2008 4:40 AM by Yair Zaslavsky

    Newbie question about pojo cache

    Yair Zaslavsky Newbie

      Hi all,
      I used abit JBoss cache core edition (version 1.4.1), and then I realized I might have the classic scenario of object graph problem that requires me to use jboss pojo cache (i'm now using pojo cache version 1.4.1)
      I wrote a cache wrapper class:


      public class PersonCache
       private PojoCache mCache;
      
      
       public PersonCache()
       {
       initCache();
       }
      
       private void initCache()
       {
       try
       {
      
       mCache = new PojoCache();
      
      
      
       PropertyConfigurator config = new PropertyConfigurator();
      
      
       InputStream is = this.getClass().getClassLoader().getResourceAsStream("treecache.xml");
      
      
       //InputStream is = new FileInputStream("conf/test/cache.xml");
       config.configure(mCache, is);
       CacheLoaderManager loaderManager = new CacheLoaderManager();
       loaderManager.setConfig(mCache.getCacheLoaderConfiguration(),mCache);
       mCache.setCacheLoaderManager(loaderManager);
      
       CallInterceptor callInterceptor = new CallInterceptor();
       callInterceptor.setCache(mCache);
      
       mCache.setInterceptorChain(callInterceptor);
      
      
       }
       catch (Exception ex)
       {
       ex.printStackTrace();
       }
       }
      
       public Person getPerson(int aID)
       {
       try
       {
       Person p = (Person)mCache.get("/persons/",aID);
       return p;
       }
       catch (Exception e)
       {
       e.printStackTrace();
       return null;
       }
       }
      
       public Book getBook(int aID)
       {
       try
       {
       Book b = (Book)mCache.get("/books/",aID);
       return b;
       }
       catch (Exception e)
       {
       return null;
       }
      
       }
      
       public void putPerson(Person p)
       {
       try
       {
       mCache.put("/persons/",p.getID(),p);
       }
       catch (Exception e)
       {
       sLogger.error("Error in putting person " + p.getID(),e);
       e.printStackTrace();
       }
       }
      
       public void putBook(Book b)
       {
       try
       {
       mCache.put("/books/",b.getID(),b);
       }
       catch (Exception e)
       {
       sLogger.error("Error in putting person " + b.getID(),e);
       }
      
       }
      
      
      }




      When I try putting a person I get an exception that the node "/Persons" does not exist


      org.jboss.cache.NodeNotExistsException: node /persons not found (gtx=null, caller=WorkerThread#0[192.168.10.58:57536])
       at org.jboss.cache.TreeCache._put(TreeCache.java:4692)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jgroups.blocks.MethodCall.invoke(MethodCall.java:330)
       at org.jboss.cache.interceptors.CallInterceptor.invoke(CallInterceptor.java:52)
       at org.jboss.cache.TreeCache.invokeMethod(TreeCache.java:5899)
       at org.jboss.cache.TreeCache.put(TreeCache.java:3847)
       at org.jboss.cache.TreeCache.put(TreeCache.java:3788)
       at com.cellerium.logicsrv.logic.test.PersonCache.putPerson(PersonCache.java:113)



      A similar code in jboss cache core edition worked for me.
      I did not instrument the classes (I read at the docs that they should be either instrumented or implement Serializable, and they do implement Serializable)


      Here are my Person and Book classes:


      public class Person implements Serializable
      {
       /**
       *
       */
       private static final long serialVersionUID = -7050290411284487094L;
       private int ID;
       private String name;
       private List<Book> books;
      
      
       public void setID(int iD)
       {
       ID = iD;
       }
      
      
      
      
       public void addBook(Book aBook)
       {
       if (books == null)
       books = new ArrayList<Book>();
      
      
       books.add(aBook);
       aBook.setPerson(this);
       }
      
       public void removeBook(Book aBook)
       {
       books.remove(aBook);
       if (books.size() == 0)
       books = null;
       aBook.setPerson(null);
       }
      
      
       public int getID()
       {
       return ID;
       }
      
      
       public void setName(String name)
       {
       this.name = name;
       }
      
      
       public String getName()
       {
       return name;
       }
      
      
       public void setBooks(List<Book> books)
       {
       this.books = books;
       }
      
      
       public List<Book> getBooks()
       {
       return books;
       }
      
      }



      public class Book implements Serializable
      {
       /**
       *
       */
      
      
       private List<Car> cars;
       private Person person;
       private int version;
       private String name;
       private static final long serialVersionUID = 2435701335133371769L;
       private int ID;
      
       public void setID(int iD)
       {
       ID = iD;
       }
      
       public int getID()
       {
       return ID;
       }
      
       public void setPerson(Person person)
       {
       this.person = person;
       }
      
      
       public Person getPerson()
       {
       return person;
       }
      
       public void setVersion(int version)
       {
       this.version = version;
       }
      
      
       public int getVersion()
       {
       return version;
       }
      
       public void setName(String name)
       {
       this.name = name;
       }
      
       public String getName()
       {
       return name;
       }
      
      
       public void setCars(List<Car> cars)
       {
       this.cars = cars;
       }
      
      
       public void addCar(Car aCar)
       {
       if (getCars() == null)
       setCars(new ArrayList<Car>());
      
       aCar.setBook(this);
       }
      
      
       public void removeCar(Car aCar)
       {
       if (getCars().size() == 0)
       setCars(null);
      
       aCar.setBook(null);
       }
      
       public List<Car> getCars()
       {
       return cars;
       }
      }
      


      This is my treecache.xml file:

      <?xml version="1.0" encoding="UTF-8"?>
      
      <!-- ===================================================================== -->
      <!-- -->
      <!-- Sample TreeCache Service Configuration -->
      <!-- -->
      <!-- ===================================================================== -->
      
      <server>
      
       <classpath codebase="./lib" archives="jboss-cache.jar, jgroups.jar"/>
      
      
       <!-- ==================================================================== -->
       <!-- Defines TreeCache configuration -->
       <!-- ==================================================================== -->
      
       <mbean code="org.jboss.cache.TreeCache"
       name="jboss.cache:service=TreeCache">
      
       <depends>jboss:service=Naming</depends>
       <depends>jboss:service=TransactionManager</depends>
      
       <!--
       Configure the TransactionManager
       -->
       <attribute name="TransactionManagerLookupClass">org.jboss.cache.JBossTransactionManagerLookup</attribute>
      
      
       <!--
       Node locking level : SERIALIZABLE
       REPEATABLE_READ (default)
       READ_COMMITTED
       READ_UNCOMMITTED
       NONE
       -->
       <attribute name="IsolationLevel">REPEATABLE_READ</attribute>
      
       <!--
       Valid modes are LOCAL
       REPL_ASYNC
       REPL_SYNC
       -->
       <attribute name="CacheMode">LOCAL</attribute>
      
       <!-- Name of cluster. Needs to be the same for all clusters, in order
       to find each other
       -->
       <attribute name="ClusterName">TreeCache-Cluster</attribute>
      
       <!-- JGroups protocol stack properties. Can also be a URL,
       e.g. file:/home/bela/default.xml
       <attribute name="ClusterProperties"></attribute>
       -->
      
       <attribute name="ClusterConfig">
       <config>
       <!-- UDP: if you have a multihomed machine,
       set the bind_addr attribute to the appropriate NIC IP address -->
       <!-- UDP: On Windows machines, because of the media sense feature
       being broken with multicast (even after disabling media sense)
       set the loopback attribute to true -->
       <UDP mcast_addr="228.1.2.3" mcast_port="48866"
       ip_ttl="64" ip_mcast="true"
       mcast_send_buf_size="150000" mcast_recv_buf_size="80000"
       ucast_send_buf_size="150000" ucast_recv_buf_size="80000"
       loopback="false"/>
       <PING timeout="2000" num_initial_members="3"
       up_thread="false" down_thread="false"/>
       <MERGE2 min_interval="10000" max_interval="20000"/>
       <FD shun="true" up_thread="true" down_thread="true"/>
       <VERIFY_SUSPECT timeout="1500"
       up_thread="false" down_thread="false"/>
       <pbcast.NAKACK gc_lag="50" retransmit_timeout="600,1200,2400,4800"
       max_xmit_size="8192" up_thread="false" down_thread="false"/>
       <UNICAST timeout="600,1200,2400" window_size="100" min_threshold="10"
       down_thread="false"/>
       <pbcast.STABLE desired_avg_gossip="20000"
       up_thread="false" down_thread="false"/>
       <FRAG frag_size="8192"
       down_thread="false" up_thread="false"/>
       <pbcast.GMS join_timeout="5000" join_retry_timeout="2000"
       shun="true" print_local_addr="true"/>
       <pbcast.STATE_TRANSFER up_thread="false" down_thread="false"/>
       </config>
       </attribute>
      
      
       <!--
       The max amount of time (in milliseconds) we wait until the
       initial state (ie. the contents of the cache) are retrieved from
       existing members in a clustered environment
       -->
       <attribute name="InitialStateRetrievalTimeout">20000</attribute>
      
       <!--
       Number of milliseconds to wait until all responses for a
       synchronous call have been received.
       -->
       <attribute name="SyncReplTimeout">20000</attribute>
      
       <!-- Max number of milliseconds to wait for a lock acquisition -->
       <attribute name="LockAcquisitionTimeout">15000</attribute>
      
      
       <!-- Name of the eviction policy class. -->
       <attribute name="EvictionPolicyClass">org.jboss.cache.aop.eviction.AopLRUPolicy</attribute>
       <!-- Specific eviction policy configurations. This is LRU -->
       <attribute name="EvictionPolicyConfig">
       <config>
       <attribute name="wakeUpIntervalSeconds">5</attribute>
       <!-- Cache wide default -->
       <region name="/_default_">
       <attribute name="maxNodes">5000</attribute>
       <attribute name="timeToLiveSeconds">1000</attribute>
       </region>
       <region name="/org/jboss/data">
       <attribute name="maxNodes">5000</attribute>
       <attribute name="timeToLiveSeconds">1000</attribute>
       </region>
       <region name="/persons">
       <attribute name="maxNodes">5000</attribute>
       <attribute name="timeToLiveSeconds">1000</attribute>
       </region>
       <region name="/books">
       <attribute name="maxNodes">5000</attribute>
       <attribute name="timeToLiveSeconds">1000</attribute>
       </region>
      
      
       <region name="/org/jboss/test/data">
       <attribute name="maxNodes">5</attribute>
       <attribute name="timeToLiveSeconds">4</attribute>
       </region>
       <region name="/test">
       <attribute name="maxNodes">10000</attribute>
       <attribute name="timeToLiveSeconds">4</attribute>
       </region>
       <region name="/maxAgeTest">
       <attribute name="maxNodes">10000</attribute>
       <attribute name="timeToLiveSeconds">8</attribute>
       <attribute name="maxAgeSeconds">10</attribute>
       </region>
       </config>
       </attribute>
      
       <!-- New 1.3.x cache loader config block -->
       <attribute name="CacheLoaderConfiguration">
       <config>
       <!-- if passivation is true, only the first cache loader is used; the rest are ignored -->
       <passivation>false</passivation>
       <preload>/</preload>
       <shared>false</shared>
      
       <!-- we can now have multiple cache loaders, which get chained -->
       <cacheloader>
       <class>org.jboss.cache.loader.FileCacheLoader</class>
       <!-- same as the old CacheLoaderConfig attribute -->
       <properties>
       location=/tmp/
       </properties>
       <!-- whether the cache loader writes are asynchronous -->
       <async>false</async>
       <!-- only one cache loader in the chain may set fetchPersistentState to true.
       An exception is thrown if more than one cache loader sets this to true. -->
       <fetchPersistentState>true</fetchPersistentState>
       <!-- determines whether this cache loader ignores writes - defaults to false. -->
       <ignoreModifications>false</ignoreModifications>
       </cacheloader>
      
       </config>
       </attribute>
       </mbean>
      
      
      </server>



      Thanks for any help,
      Yair