Package org.jboss.cache

Examples of org.jboss.cache.Node


      try
      {
         Set children = null;
         for (int i = 0; i < hashBuckets.length; i++)
         {
            Node node = cache.getRoot().getChild(new Fqn(cacheNode, hashBuckets[i]));
            if (node != null)
            {
               children = node.getChildrenNames();
               count += (children == null ? 0 : children.size());
            }
         }
         count = count - passivatedCount;
      }
View Full Code Here


            // The rest only matters for optimistic locking, where we
            // need to establish the proper data version on the region root
           
            // Don't hold a transactional lock for this
            Transaction tx = suspend();
            Node newRoot = null;
            try {
                 // Make sure the root node for the region exists and
                 // has a DataVersion that never complains
                 newRoot = jbcCache.getRoot().getChild( regionFqn );
                 if (newRoot == null || !newRoot.isValid()) {               
                     // Establish the region root node with a non-locking data version
                     DataVersion version = optimistic ? NonLockingDataVersion.INSTANCE : null;
                     newRoot = CacheHelper.addNode(jbcCache, regionFqn, true, true, version);   
                 }
                 else if (newRoot instanceof NodeSPI) {
                     // FIXME Hacky workaround to JBCACHE-1202
                     if ( !( ( ( NodeSPI ) newRoot ).getVersion() instanceof NonLockingDataVersion ) ) {
                          ((NodeSPI) newRoot).setVersion(NonLockingDataVersion.INSTANCE);
                     }
                 }
                 // Never evict this node
                 newRoot.setResident(true);
            }
            finally {
                resume(tx);
                regionRoot = newRoot;
            }
View Full Code Here

    public static boolean isSynchronous(Configuration.CacheMode cacheMode) {
        return cacheMode == Configuration.CacheMode.REPL_SYNC || cacheMode == Configuration.CacheMode.INVALIDATION_SYNC;
    }
   
    public static Set getChildrenNames(Cache cache, Fqn fqn) {
        Node node = cache.getRoot().getChild(fqn);
        return (node != null) ? node.getChildrenNames() : Collections.emptySet();
    }
View Full Code Here

                option = new Option();
                option.setCacheModeLocal(localOnly);
                option.setDataVersion(version);
            }
           
            Node root = cache.getRoot();
            setInvocationOption(cache, option);
            // FIXME hack to work around fact that calling
            // Node added = root.addChild( fqn ); doesn't
            // properly set the version on the node
            Node added = null;
            if (version == null) {
                added = root.addChild( fqn );
            }
            else {
                cache.put(fqn, DUMMY, DUMMY);
                added = root.getChild(fqn);
            }
            if (resident)
                added.setResident(true);
            return added;
        }
        catch (Exception e) {
            throw new CacheException(e);
        }
View Full Code Here

      Fqn targetFqn = target.getFqn();
      for (Fqn internalFqn : internalFqns)
      {
         if (internalFqn.isChildOf(targetFqn))
         {
            Node internalNode = getInternalNode(target, internalFqn);
            if (internalNode != null)
            {
               result.add(internalNode);
            }
         }
View Full Code Here

   private Node getInternalNode(Node parent, Fqn internalFqn)
   {
      Object name = internalFqn.get(parent.getFqn().size());
      cache.getInvocationContext().getOptionOverrides().setSkipCacheStatusCheck(true);
      Node result = parent.getChild(name);
      if (result != null && internalFqn.size() < result.getFqn().size())
      {
         // need to recursively walk down the tree
         result = getInternalNode(result, internalFqn);
      }
View Full Code Here

            // The rest only matters for optimistic locking, where we
            // need to establish the proper data version on the region root
           
            // Don't hold a transactional lock for this
            Transaction tx = suspend();
            Node newRoot = null;
            try {
                 // Make sure the root node for the region exists and
                 // has a DataVersion that never complains
                 newRoot = jbcCache.getRoot().getChild( regionFqn );
                 if (newRoot == null || !newRoot.isValid()) {               
                     // Establish the region root node with a non-locking data version
                     DataVersion version = optimistic ? NonLockingDataVersion.INSTANCE : null;
                     newRoot = CacheHelper.addNode(jbcCache, regionFqn, true, true, version);   
                 }
                 else if (newRoot instanceof NodeSPI) {
                     // FIXME Hacky workaround to JBCACHE-1202
                     if ( !( ( ( NodeSPI ) newRoot ).getVersion() instanceof NonLockingDataVersion ) ) {
                          ((NodeSPI) newRoot).setVersion(NonLockingDataVersion.INSTANCE);
                     }
                 }
                 // Never evict this node
                 newRoot.setResident(true);
                 establishInternalNodes();
            }
            finally {
                resume(tx);
                regionRoot = newRoot;
View Full Code Here

        assertEquals("Cache is REPL_SYNC", "REPL_SYNC", localCache.getConfiguration().getCacheModeString());
       
        // Region creation should not have affected remoteCache

        assertNull("No region node", remoteCache.getRoot().getChild( regionFqn ));
        Node regionRoot = localCache.getRoot().getChild( regionFqn );
        assertTrue("Has a node at " + regionFqn, regionRoot != null );
        assertTrue(regionFqn + " is resident", regionRoot.isResident() );
       
        // Confirm region destroy does not affect remote cache
       
        Option option = new Option();
        option.setCacheModeLocal(true);
View Full Code Here

        avoidConcurrentFlush();
   
        GeneralDataRegion remoteRegion = (GeneralDataRegion) createRegion(regionFactory, getStandardRegionName(REGION_PREFIX), cfg.getProperties(), null);
        Fqn regionFqn = getRegionFqn(getStandardRegionName(REGION_PREFIX), REGION_PREFIX);
       
        Node regionRoot = localCache.getRoot().getChild(regionFqn);
        assertFalse(regionRoot == null);
        assertEquals("No children in " + regionRoot, 0, getValidChildrenCount(regionRoot));
        assertTrue(regionRoot.isResident());
       
        if (optimistic) {
            assertEquals(NonLockingDataVersion.class, ((NodeSPI) regionRoot).getVersion().getClass());
        }
   
        regionRoot = remoteCache.getRoot().getChild(regionFqn);
        assertFalse(regionRoot == null);
        assertEquals(0, getValidChildrenCount(regionRoot));
        assertTrue(regionRoot.isResident());
       
        if (optimistic) {
            assertEquals(NonLockingDataVersion.class, ((NodeSPI) regionRoot).getVersion().getClass());
        }
       
        assertNull("local is clean", localRegion.get(KEY));
        assertNull("remote is clean", remoteRegion.get(KEY));
       
        localRegion.put(KEY, VALUE1);
        assertEquals(VALUE1, localRegion.get(KEY));    
       
        // Allow async propagation
        sleep(250);
       
        remoteRegion.put(KEY, VALUE1);
        assertEquals(VALUE1, remoteRegion.get(KEY));    
       
        // Allow async propagation
        sleep(250);
       
        if (optimistic) {
            regionRoot = localCache.getRoot().getChild(regionFqn);
            assertEquals(NonLockingDataVersion.class, ((NodeSPI) regionRoot).getVersion().getClass());
            regionRoot = remoteCache.getRoot().getChild(regionFqn);
            assertEquals(NonLockingDataVersion.class, ((NodeSPI) regionRoot).getVersion().getClass());
        }
       
        localRegion.evictAll();
       
        // This should re-establish the region root node
        assertNull(localRegion.get(KEY));
       
        regionRoot = localCache.getRoot().getChild(regionFqn);
        assertFalse(regionRoot == null);
        assertEquals(0, getValidChildrenCount(regionRoot));
        assertTrue(regionRoot.isValid());
        assertTrue(regionRoot.isResident());

        // Re-establishing the region root on the local node doesn't
        // propagate it to other nodes. Do a get on the remote node to re-establish
        assertEquals(null, remoteRegion.get(KEY));
       
        regionRoot = remoteCache.getRoot().getChild(regionFqn);
        assertFalse(regionRoot == null);
        assertEquals(0, getValidChildrenCount(regionRoot));
        assertTrue(regionRoot.isValid());
        assertTrue(regionRoot.isResident());
       
        assertEquals("local is clean", null, localRegion.get(KEY));
        assertEquals("remote is clean", null, remoteRegion.get(KEY));
    }
View Full Code Here

      
        final String KEY = KEY_BASE + testCount++;
       
        Fqn regionFqn = getRegionFqn(REGION_NAME, REGION_PREFIX);
       
        Node regionRoot = localCache.getRoot().getChild(regionFqn);
        assertFalse(regionRoot == null);
        assertEquals(0, getValidChildrenCount(regionRoot));
        assertTrue(regionRoot.isResident());
       
        if (isUsingOptimisticLocking()) {
            assertEquals(NonLockingDataVersion.class, ((NodeSPI) regionRoot).getVersion().getClass());
        }

        regionRoot = remoteCache.getRoot().getChild(regionFqn);
        assertFalse(regionRoot == null);
        assertEquals(0, getValidChildrenCount(regionRoot));
        assertTrue(regionRoot.isResident());
       
        if (isUsingOptimisticLocking()) {
            assertEquals(NonLockingDataVersion.class, ((NodeSPI) regionRoot).getVersion().getClass());
        }
       
        assertNull("local is clean", localAccessStrategy.get(KEY, System.currentTimeMillis()));
        assertNull("remote is clean", remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
       
        localAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1));
        assertEquals(VALUE1, localAccessStrategy.get(KEY, System.currentTimeMillis()));
        remoteAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1));
        assertEquals(VALUE1, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
       
        // Wait for async propagation
        sleep(250);
       
        if (isUsingOptimisticLocking()) {
            regionRoot = localCache.getRoot().getChild(regionFqn);
            assertEquals(NonLockingDataVersion.class, ((NodeSPI) regionRoot).getVersion().getClass());
            regionRoot = remoteCache.getRoot().getChild(regionFqn);
            assertEquals(NonLockingDataVersion.class, ((NodeSPI) regionRoot).getVersion().getClass());
        }
       
        if (evict)
            localAccessStrategy.evictAll();
        else
            localAccessStrategy.removeAll();

        // This should re-establish the region root node
        assertNull(localAccessStrategy.get(KEY, System.currentTimeMillis()));
       
        regionRoot = localCache.getRoot().getChild(regionFqn);
         assertFalse(regionRoot == null);
         assertEquals(0, getValidChildrenCount(regionRoot));
         assertTrue(regionRoot.isValid());
         assertTrue(regionRoot.isResident());

        // Re-establishing the region root on the local node doesn't
        // propagate it to other nodes. Do a get on the remote node to re-establish
        assertEquals(null, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));

        regionRoot = remoteCache.getRoot().getChild(regionFqn);
        assertFalse(regionRoot == null);
        assertTrue(regionRoot.isValid());
        assertTrue(regionRoot.isResident());
        // Not invalidation, so we didn't insert a child above
        assertEquals(0, getValidChildrenCount(regionRoot));

        // Test whether the get above messes up the optimistic version
        remoteAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1));
        assertEquals(VALUE1, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
       
        // Revalidate the region root
        regionRoot = remoteCache.getRoot().getChild(regionFqn);
        assertFalse(regionRoot == null);
        assertTrue(regionRoot.isValid());
        assertTrue(regionRoot.isResident());
        // Region root should have 1 child -- the one we added above
        assertEquals(1, getValidChildrenCount(regionRoot));
       
        // Wait for async propagation of the putFromLoad
        sleep(250);
View Full Code Here

TOP

Related Classes of org.jboss.cache.Node

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.