0 Replies Latest reply on Aug 15, 2009 1:32 AM by shms

    about eviction and other stuff

      Hi everybody ,

      I am trying to integrate the Jboss cache with a big stand alone environment the main problem with this program we need a huge data to process with amount reach to 7 GB so the idea is to use a cache system to evict some of the data and retrieve it when we want any way
      i will get in the problem right away my question is the Jboss cache sensitive to memory ?
      and any one have some suggestion .
      I tried to create a test before integrate the jboss cache with the system but i could not make it run so anybody can figure the problem

      --------------------------------
      i make the ram for the virtual , the idea behind the test frame work is to create dummy data and add it to the cache tree and check if it evict it but it did not worked .
      sorry i post this code but i want to show all the evolution process on it i used to debug and check and come up with ideas and test them on the same code

      import java.util.HashMap;
      import java.util.Map;
      import java.util.Scanner;
      
      import org.jboss.cache.Cache;
      import org.jboss.cache.CacheFactory;
      import org.jboss.cache.DefaultCacheFactory;
      import org.jboss.cache.Fqn;
      import org.jboss.cache.Node;
      import org.jboss.cache.Region;
      import org.jboss.cache.RegionManagerImpl;
      import org.jboss.cache.config.Configuration;
      import org.jboss.cache.config.EvictionAlgorithmConfig;
      import org.jboss.cache.config.EvictionConfig;
      import org.jboss.cache.config.EvictionRegionConfig;
      import org.jboss.cache.config.Configuration.CacheMode;
      import org.jboss.cache.eviction.EvictionEvent;
      import org.jboss.cache.eviction.EvictionQueueList;
      import org.jboss.cache.eviction.LRUAlgorithm;
      import org.jboss.cache.eviction.LRUAlgorithmConfig;
      import org.jboss.cache.interceptors.EvictionInterceptor;
      import org.jboss.cache.transaction.GenericTransactionManagerLookup;
      import org.jboss.util.LRUCachePolicy;
      import org.jgroups.tests.PullPushTestMux.MyListener;
      
      
      public class JBossTest {
      
      
       private static Node<Object, Object> newNode;
       private Node<Object, Object> lastNode ;
      // private Object watcher = new myListener();
       Object watcher = new myListener();
      
      
      
       /**
       * @param args
       */
       public static void getMemorySize()
       {
       long size = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
       System.out.println("The size of the memory at the current time is : " + size);
       }
       public static double[] getDummyData()
       {
       return new double[(int)(1000*Math.random()) + 1];
       }
      
      // private void orderChildren(Node node)
      // {
      // if (node == null) return;
      //
      // if (node instanceof root)
      // {
      // FqnTreeNode node = (FqnTreeNode) parent;
      // ArrayList children = Collections.list(node.children());
      // Collections.sort(children);
      // node.removeAllChildren();
      // Iterator childrenIterator = children.iterator();
      // while (childrenIterator.hasNext()) node.add((FqnTreeNode) childrenIterator.next());
      // }
      // }
       @SuppressWarnings("null")
      public void startUpTest()
       {
       /*
       * the configuration for the cache object
       */
      
       CacheFactory<Object, Object> factory = new DefaultCacheFactory<Object, Object>();
      
      
      // Cache cache = factory.createCache("/home/ecc_8/shamah0s/Desktop/SerialDemo/config.xml", false);
       Cache<Object, Object> cache = factory.createCache();
      
       Configuration config = new Configuration();
      
      // config.setTransactionManagerLookupClass(GenericTransactionManagerLookup.class.getName());
      // config.setIsolationLevel(IsolationLevel.READ_COMMITTED);
       config.setCacheMode(CacheMode.LOCAL);
      // config.setCacheMode(CacheMode.INVALIDATION_SYNC);
       config.setLockAcquisitionTimeout(15000);
      
      
       Node<Object, Object> root = cache.getRoot();
       Fqn<String> fqnNode = Fqn.fromString("root/arrayPath");
      
       // newNode = root.addChild(fqnNode);
       // newNode.setResident(true);
      
       Fqn<String> fqnNode1 = Fqn.fromString("root/hi");
       Fqn<String> fqnNode2 = Fqn.fromString("root/meToo");
       Fqn<String> fqnNode3 = Fqn.fromString("root/arrayPath/what");
       Fqn<String> fqnNode4 = Fqn.fromString("root/arrayPath/what/is");
       Fqn<String> fqnNode5 = Fqn.fromString("root/arrayPath/what/is/he");
       setNode(root);
      
      
       root.addChild(fqnNode2);
       root.addChild(fqnNode3);
       root.addChild(fqnNode4);
       root.addChild(fqnNode5);
      
      
      
       LRUAlgorithmConfig lru = new LRUAlgorithmConfig();
      
       lru.setMaxNodes(1000);
       lru.setMaxAge(15000);
       lru.setMinTimeToLive(2000);
       lru.setMinTimeToLive(1000);
      
      // EvictionRegionConfig ring = new EvictionRegionConfig(fqnNode5,lru);
       EvictionRegionConfig ring = new EvictionRegionConfig();
       ring.setRegionFqn(RegionManagerImpl.DEFAULT_REGION);
      
       EvictionAlgorithmConfig algoCon = new LRUAlgorithmConfig();
      
      // algoCon.validate();
      
       ring.setEvictionActionPolicyClassName(LRUAlgorithm.class.getName());
       // ring.setRegionFqn(fqnNode);
       ring.passCacheToChildConfig(config);
       ring.setEvictionAlgorithmConfig(lru);
       config.setUseLazyDeserialization(true);
      
       Region region = cache.getRegion(fqnNode5, true);
       // region.setEvictionRegionConfig(ring);
      
       // region.setActive(true);
       EvictionConfig evict = new EvictionConfig();
       ring.setRegionFqn(RegionManagerImpl.DEFAULT_REGION);
       // evict.applyDefaults(ring);
       evict.addEvictionRegionConfig(ring);
       // cache.evict(fqnNode, true);
      
       cache.evict(fqnNode5);
       System.out.println(evict.isValidConfig());
       // evict.createDefaultEvictionRegionConfig();
       config.setEvictionConfig(evict);
       // config.setReplQueueMaxElements(15000);
      // evict.setDefaultEvictionPolicyClass(LRUPolicy.class.getName());
      
      
      // start the cache
      
       System.out.println("start the cache before enter the while loop ");
      
       getMemorySize();
      
      // adding a listener
       cache.addCacheListener( watcher);
       // region.getCacheConfiguration();
      // region.processEvictionQueues();
      // region.setEvictionPolicy( LRUCachePolicy.class.);
      // region.setActive(true);
       //evict.
      // EvictionInterceptor interapter =new EvictionInterceptor();
       // EvictionEvent evictEvent = new EvictionEvent();
       // evictEvent.copy(fqnNode);
       // evictEvent.
       //cache.evict(fqnNode);
      
      // EvictionQueueList evictQeue = new EvictionQueueList();
      
       //System.out.println(region.getEvictionPolicyConfig().toString());
      
      
       Scanner scanner = new Scanner(System.in);
       // double[] dummyData = new double[(int)(1000*Math.random()) + 1];
       boolean abort = true;
       int i = 0;
      
       Map< Object, Object> data = new HashMap<Object, Object>();
      
      
      
       cache.create();
       cache.start();
      
       while(abort)
       {
      
       i++;
       if (i == 10000 || i == 100000 || i == 1000000)
       {
       getMemorySize();
       cache.toString();
       // cache.evict(
       System.out.println(cache.getChildrenNames(fqnNode5));
      // cache.evict(fqnNode5);
      // cache.evict(fqnNode1);
       System.out.println(cache.getData(fqnNode));
       cache.evict(fqnNode);
       System.out.println(cache.getData(fqnNode));
       System.out.println(cache.getChildrenNames("***************************************************"));
       System.out.println(fqnNode1.toString());
       System.out.println(fqnNode5.toString());
       System.out.println(cache.getChildrenNames(fqnNode5));
       System.out.println(cache.toString());
       System.out.println(fqnNode1.toString());
       System.out.println(fqnNode5.toString());
       System.out.println(fqnNode1.toString());
       System.out.println(fqnNode5.peekElements().toString());
       System.out.println("we reach 1000 do you want to exist type (y/n): ");
       String checkName = scanner.next();
       if (checkName.equalsIgnoreCase("y"))
       {
       //System.exit(0);
       abort = false;
       }
      
       }
      
       String dummyKey =(Integer.toString(i));
       // newNode.put(dummyKey, getDummyData());
      // data.put(dummyKey, getDummyData());
       //fqnNode.
       // Node <Object, Object> filledNode= getNode().addChild(getNode().getFqn());
       // filledNode.put(dummyKey, getDummyData());
      
      // Node<Object, Object> updated = getNode();
      // Fqn<String> newFqn = getNode().getFqn();
      // getNode().addChild(fqnNode2);
       // cache.getNode(fqn)
      // setNode(updated);
      
      
       // cache.put(getNode().getFqn());
       cache.put(fqnNode, dummyKey, getDummyData());
       // getNode().addChild(dummyKey, getDummyData());
      // cache.put(fqnNode, data);
       cache.toString();
       // cache.evict(fqnNode);
      
      
       }
      
       System.out.println(cache.getConfiguration().toString());
      // System.out.println(cache.getKeys(fqnNode));
       System.out.println(cache.getData(fqnNode));
      // System.out.println(cache.getKeys(fqnNode5));
       System.out.println(cache.getData(fqnNode5));
      // System.out.println(cache.getCacheListeners());
       // System.out.println(cache.getChildrenNames(fqnNode));
       System.out.println(cache.getChildrenNames(fqnNode5));
       System.out.println(cache.toString());
      // System.out.println(newNode.toString());
       }
      
       private Node<Object, Object> getNode()
       {
       return lastNode;
       }
       private void setNode(Node<Object, Object> node)
       {
       lastNode = node ;
       }
      
       public static void main(String[] args) {
       JBossTest test = new JBossTest();
       test.startUpTest();
      
       }
      
      }
      
      
      
      



      please some one help me
      import org.jboss.cache.notifications.annotation.CacheListener;
      import org.jboss.cache.notifications.annotation.CacheStarted;
      import org.jboss.cache.notifications.annotation.NodeEvicted;
      import org.jboss.cache.notifications.event.Event;
      
      @CacheListener
      public class myListener
      {
       private int i = 0;
       @CacheStarted
       @NodeEvicted
       public void cacheNodeEvict(Event e)
       {
       switch(e.getType())
       {
       case NODE_EVICTED:
       System.out.println("node evicted");
       case CACHE_STARTED:
       System.out.println("--------------------------------------------------------------------");
       case TRANSACTION_COMPLETED:
       System.out.println("node transection");
       case NODE_VISITED:
       // System.out.print(i++);
       System.out.println("");
       System.out.println("node visited "+ i++);
       case NODE_MODIFIED:
       System.out.println("node modified");
       }
       }
      }