Java Code Examples for com.gemstone.gemfire.cache.Region#localDestroy()

The following examples show how to use com.gemstone.gemfire.cache.Region#localDestroy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DestroyEntryMessage.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
@Override
public void process(DistributionManager dm) {
  Region r = getRegion(dm.getSystem());
  if (r != null) {
    try {
      if (action == ExpirationAction.LOCAL_DESTROY) {
        r.localDestroy(key);
      } else if (action == ExpirationAction.DESTROY) {
        r.destroy(key);
      } else if (action == ExpirationAction.INVALIDATE) {
        r.invalidate(key);
      } else if (action == ExpirationAction.LOCAL_INVALIDATE) {
        r.localInvalidate(key);
      }
    } catch (Exception e) {
      dm.getLoggerI18n().warning(
          LocalizedStrings.DestroEntryMessage_FAILED_ATTEMPT_TO_DESTROY_OR_INVALIDATE_ENTRY_0_1_FROM_CONSOLE_AT_2,
          new Object[] {r.getFullPath(), key, this.getSender()});
    }
  }
}
 
Example 2
Source File: DestroyEntryMessage.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
@Override
public void process(DistributionManager dm) {
  Region r = getRegion(dm.getSystem());
  if (r != null) {
    try {
      if (action == ExpirationAction.LOCAL_DESTROY) {
        r.localDestroy(key);
      } else if (action == ExpirationAction.DESTROY) {
        r.destroy(key);
      } else if (action == ExpirationAction.INVALIDATE) {
        r.invalidate(key);
      } else if (action == ExpirationAction.LOCAL_INVALIDATE) {
        r.localInvalidate(key);
      }
    } catch (Exception e) {
      dm.getLoggerI18n().warning(
          LocalizedStrings.DestroEntryMessage_FAILED_ATTEMPT_TO_DESTROY_OR_INVALIDATE_ENTRY_0_1_FROM_CONSOLE_AT_2,
          new Object[] {r.getFullPath(), key, this.getSender()});
    }
  }
}
 
Example 3
Source File: RegionUtil.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Locally clears the specified region. 
 * @param region The region to be cleared.
 * @throws CacheException Thrown if it encounters a cache error.
 */
public final static void clearLocalRegion(Region region) throws CacheException
{
	if (region == null) {
		return;
	}
    for (Iterator iterator = region.keySet().iterator(); iterator.hasNext();) {
        try {
        	region.localDestroy(iterator.next());
        } catch (EntryNotFoundException ex) {
        	// ignore all exceptions, especially, EntryNotFoundException
        }
    }
}
 
Example 4
Source File: HARegionJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * test no exception being thrown while doing a localDestroy on a HARegion
 *  
 */
public void testLocalDestroy()
{
  try {
    Region region = createHARegion();
    region.put("key1", "value1");
    region.localDestroy("key1");
    Assert.assertEquals(region.get("key1"), null);
  }
  catch (Exception e) {
    e.printStackTrace();
    fail("put failed due to " + e);
  }
}
 
Example 5
Source File: HARegionDUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * destroy key-1
 * 
 */
public static void destroy()
{
  try {
    Region region1 = cache.getRegion(Region.SEPARATOR + REGION_NAME);
    region1.localDestroy("key-1");
  }
  catch (Exception e) {
    e.printStackTrace();
    fail("test failed due to exception in destroy ");
  }
}
 
Example 6
Source File: HARegionQueueDUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * destroy key-1
 *
 */
public static void destroy()
{
  try {
    Region region1 = cache.getRegion("/HARegionQueueDUnitTest_region");
    region1.localDestroy("key-1");
  }
  catch (Exception e) {
    e.printStackTrace();
    fail("test failed due to exception in destroy ");
  }
}
 
Example 7
Source File: RegionUtil.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Locally clears the specified region. 
 * @param region The region to be cleared.
 * @throws CacheException Thrown if it encounters a cache error.
 */
public final static void clearLocalRegion(Region region) throws CacheException
{
	if (region == null) {
		return;
	}
    for (Iterator iterator = region.keySet().iterator(); iterator.hasNext();) {
        try {
        	region.localDestroy(iterator.next());
        } catch (EntryNotFoundException ex) {
        	// ignore all exceptions, especially, EntryNotFoundException
        }
    }
}
 
Example 8
Source File: BridgeWriterMiscDUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Test for bug 43407, where LRU in the client caused an entry to be
 * evicted with DESTROY(), then the client invalidated the entry and
 * did a get().  After the get() the entry was not seen to be in the
 * client's cache.  This turned out to be expected behavior, but we
 * now have this test to guarantee that the product behaves as expected.
 */
public void testBug43407()
    throws Exception
{
  // start server first
  PORT1 = initServerCache(false);
  createClientCache(getServerHostName(Host.getHost(0)), PORT1);
  registerInterestForInvalidatesInBothTheRegions();
  Region region = static_cache.getRegion(REGION_NAME1);
  populateCache();
  region.put("invalidationKey", "invalidationValue");
  region.localDestroy("invalidationKey");
  if (region.containsKey("invalidationKey")) {
    fail("region still contains invalidationKey");
  }
  region.invalidate("invalidationKey");
  if (region.containsKey("invalidationKey")) {
    fail("this test expects the entry is not created on invalidate() if not there before the operation");
  }
  Object value = region.get("invalidationKey");
  if (value != null) {
    fail("this test expected a null response to get('invalidationKey')");
  }
  if (!region.containsKeyOnServer("invalidationKey")) {
    fail("expected an entry on the server after invalidation");
  }
  // bug 43407 asserts that there should be an entry, but the product does not
  // do this.  This verifies that the product does not behave as asserted in that bug
  if (region.containsKey("invalidationKey")) {
    fail("expected no entry after invalidation when entry was not in client but was on server");
  }
}
 
Example 9
Source File: HARegionJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * test no exception being thrown while doing a localDestroy on a HARegion
 *  
 */
public void testLocalDestroy()
{
  try {
    Region region = createHARegion();
    region.put("key1", "value1");
    region.localDestroy("key1");
    Assert.assertEquals(region.get("key1"), null);
  }
  catch (Exception e) {
    e.printStackTrace();
    fail("put failed due to " + e);
  }
}
 
Example 10
Source File: HARegionDUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * destroy key-1
 * 
 */
public static void destroy()
{
  try {
    Region region1 = cache.getRegion(Region.SEPARATOR + REGION_NAME);
    region1.localDestroy("key-1");
  }
  catch (Exception e) {
    e.printStackTrace();
    fail("test failed due to exception in destroy ");
  }
}
 
Example 11
Source File: DeltaPropagationDUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static void doLocalOp(String op, String rName, String key) {
  try {
    Region r = cache.getRegion("/" + rName);
    assertNotNull(r);
    if (INVALIDATE.equals(op)) {
      r.localInvalidate(key);
    }
    else if (DESTROY.equals(op)) {
      r.localDestroy(key);
    }
  }
  catch (Exception e) {
    fail("failed in doLocalOp()", e);
  }
}
 
Example 12
Source File: P2PDeltaPropagationDUnitTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public static void destroy() throws Exception
{
  Region r1 = cache.getRegion(Region.SEPARATOR + REGION_NAME);
  r1.localDestroy("KEY");
}
 
Example 13
Source File: WANOperationsClient.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Destroy an entry in the given region.
 * 
 * @param aRegion
 *          The region to use for destroying an entry.
 * @param isLocalDestroy
 *          True if the destroy should be local, false otherwise.
 */
protected void destroyEntry(Region aRegion, boolean isLocalDestroy) {
  Object key = getExistingKey(aRegion);
  if (key == null) {
    int size = aRegion.size();
    return;
  }
  try {
    String callback = destroyCallbackPrefix + ProcessMgr.getProcessId();
    if (isLocalDestroy) { // do a local destroy
      if (TestConfig.tab().getRandGen().nextBoolean()) { // local destroy with
        // callback
        Log.getLogWriter().info(
            "destroyEntry: local destroy for " + key + " callback is "
                + callback);
        aRegion.localDestroy(key, callback);
        Log.getLogWriter().info(
            "destroyEntry: done with local destroy for " + key);
      }
      else { // local destroy without callback
        Log.getLogWriter().info("destroyEntry: local destroy for " + key);
        aRegion.localDestroy(key);
        Log.getLogWriter().info(
            "destroyEntry: done with local destroy for " + key);
      }
    }
    else { // do a distributed destroy
      if (TestConfig.tab().getRandGen().nextBoolean()) { // destroy with
        // callback
        Log.getLogWriter().info(
            "destroyEntry: destroying key " + key + " callback is "
                + callback);
        aRegion.destroy(key, callback);
        Log.getLogWriter().info("destroyEntry: done destroying key " + key);
      }
      else { // destroy without callback
        Log.getLogWriter().info("destroyEntry: destroying key " + key);
        aRegion.destroy(key);
        Log.getLogWriter().info("destroyEntry: done destroying key " + key);
      }
      // unique key validation does not support local destroy
      if (useUniqueKeyPerThread) {
        updateBlackboardSnapshot(aRegion, key, null, true);
      }
    }
  }
  catch (com.gemstone.gemfire.cache.EntryNotFoundException e) {
    Log.getLogWriter().info(
        "Caught " + e
            + " (expected with concurrent execution); continuing with test");
    return;
  }
}
 
Example 14
Source File: WANOperationsClient.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Destroy an entry in the given region.
 * 
 * @param aRegion
 *          The region to use for destroying an entry.
 * @param isLocalDestroy
 *          True if the destroy should be local, false otherwise.
 */
protected void destroyEntry(Region aRegion, boolean isLocalDestroy) {
  Object key = getExistingKey(aRegion);
  if (key == null) {
    int size = aRegion.size();
    return;
  }
  try {
    String callback = destroyCallbackPrefix + ProcessMgr.getProcessId();
    if (isLocalDestroy) { // do a local destroy
      if (TestConfig.tab().getRandGen().nextBoolean()) { // local destroy with
        // callback
        Log.getLogWriter().info(
            "destroyEntry: local destroy for " + key + " callback is "
                + callback);
        aRegion.localDestroy(key, callback);
        Log.getLogWriter().info(
            "destroyEntry: done with local destroy for " + key);
      }
      else { // local destroy without callback
        Log.getLogWriter().info("destroyEntry: local destroy for " + key);
        aRegion.localDestroy(key);
        Log.getLogWriter().info(
            "destroyEntry: done with local destroy for " + key);
      }
    }
    else { // do a distributed destroy
      if (TestConfig.tab().getRandGen().nextBoolean()) { // destroy with
        // callback
        Log.getLogWriter().info(
            "destroyEntry: destroying key " + key + " callback is "
                + callback);
        aRegion.destroy(key, callback);
        Log.getLogWriter().info("destroyEntry: done destroying key " + key);
      }
      else { // destroy without callback
        Log.getLogWriter().info("destroyEntry: destroying key " + key);
        aRegion.destroy(key);
        Log.getLogWriter().info("destroyEntry: done destroying key " + key);
      }
      // unique key validation does not support local destroy
      if (useUniqueKeyPerThread) {
        updateBlackboardSnapshot(aRegion, key, null, true);
      }
    }
  }
  catch (com.gemstone.gemfire.cache.EntryNotFoundException e) {
    Log.getLogWriter().info(
        "Caught " + e
            + " (expected with concurrent execution); continuing with test");
    return;
  }
}
 
Example 15
Source File: ParRegColocation.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void localDestroy(Region aRegion, Object key) {
  Log.getLogWriter().info("Locally destroying " + key);
  checkContainsValueForKey(aRegion, key, true, "before local destroy");
  aRegion.localDestroy(key);
}
 
Example 16
Source File: KeyCallbackResolverTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void localDestroy(Region aRegion, Object keyName) {
  Object key = getKeyWrapper(keyName);
  Object callbackArg = getCallBackWrapper(keyName);
  aRegion.localDestroy(key, callbackArg);
}
 
Example 17
Source File: DeltaTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/** Destroy an entry in the given region.
 *
 *  @param aRegion The region to use for destroying an entry.
 *  @param isLocalDestroy True if the destroy should be local, false otherwise.
 */
protected void destroyEntry(Region aReg, boolean isLocalDestroy) {
   Object key = getExistingKey(aReg, uniqueKeys, numThreadsInClients);
   if (key == null) {
      int size = aReg.size();
      if (isSerialExecution && (size != 0))
         throw new TestException("getExistingKey returned " + key + ", but region size is " + size);
      Log.getLogWriter().info("destroyEntry: No keys in region");
      return;
   }
   try {
      String callback = destroyCallbackPrefix + ProcessMgr.getProcessId();
      if (isLocalDestroy) { // do a local destroy
         if (TestConfig.tab().getRandGen().nextBoolean()) { // local destroy with callback
            Log.getLogWriter().info("operation for " + key + ", destroyEntry: local destroy for " + key + " callback is " + callback);
            aReg.localDestroy(key, callback);
            Log.getLogWriter().info("operation for " + key + ", destroyEntry: done with local destroy for " + key);
         } else { // local destroy without callback
            Log.getLogWriter().info("operation for " + key + ", destroyEntry: local destroy for " + key);
            aReg.localDestroy(key);
            Log.getLogWriter().info("operation for " + key + ", destroyEntry: done with local destroy for " + key);
         }
      } else { // do a distributed destroy
         if (TestConfig.tab().getRandGen().nextBoolean()) { // destroy with callback
            Log.getLogWriter().info("operation for " + key + ", destroyEntry: destroying key " + key + " callback is " + callback);
            aReg.destroy(key, callback);
            Log.getLogWriter().info("operation for " + key + ", destroyEntry: done destroying key " + key);
         } else { // destroy without callback
            Log.getLogWriter().info("operation for " + key + ", destroyEntry: destroying key " + key);
            aReg.destroy(key);
            Log.getLogWriter().info("operation for " + key + ", destroyEntry: done destroying key " + key);
         }
      }

      // validation
      if (isSerialExecution || uniqueKeys) {
         // record the current state
         regionSnapshot.remove(key);
      }
   } catch (com.gemstone.gemfire.cache.EntryNotFoundException e) {
      if (isSerialExecution || uniqueKeys)
         throw new TestException(TestHelper.getStackTrace(e));
      else {
         Log.getLogWriter().info("Caught " + e + " (expected with concurrent execution); continuing with test");
         return;
      }
   }
}
 
Example 18
Source File: KeyCallbackResolverTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void localDestroy(Region aRegion, Object keyName) {
  Object key = getKeyWrapper(keyName);
  Object callbackArg = getCallBackWrapper(keyName);
  aRegion.localDestroy(key, callbackArg);
}
 
Example 19
Source File: P2PDeltaPropagationDUnitTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public static void destroy() throws Exception
{
  Region r1 = cache.getRegion(Region.SEPARATOR + REGION_NAME);
  r1.localDestroy("KEY");
}
 
Example 20
Source File: DeltaTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/** Destroy an entry in the given region.
 *
 *  @param aRegion The region to use for destroying an entry.
 *  @param isLocalDestroy True if the destroy should be local, false otherwise.
 */
protected void destroyEntry(Region aReg, boolean isLocalDestroy) {
   Object key = getExistingKey(aReg, uniqueKeys, numThreadsInClients);
   if (key == null) {
      int size = aReg.size();
      if (isSerialExecution && (size != 0))
         throw new TestException("getExistingKey returned " + key + ", but region size is " + size);
      Log.getLogWriter().info("destroyEntry: No keys in region");
      return;
   }
   try {
      String callback = destroyCallbackPrefix + ProcessMgr.getProcessId();
      if (isLocalDestroy) { // do a local destroy
         if (TestConfig.tab().getRandGen().nextBoolean()) { // local destroy with callback
            Log.getLogWriter().info("operation for " + key + ", destroyEntry: local destroy for " + key + " callback is " + callback);
            aReg.localDestroy(key, callback);
            Log.getLogWriter().info("operation for " + key + ", destroyEntry: done with local destroy for " + key);
         } else { // local destroy without callback
            Log.getLogWriter().info("operation for " + key + ", destroyEntry: local destroy for " + key);
            aReg.localDestroy(key);
            Log.getLogWriter().info("operation for " + key + ", destroyEntry: done with local destroy for " + key);
         }
      } else { // do a distributed destroy
         if (TestConfig.tab().getRandGen().nextBoolean()) { // destroy with callback
            Log.getLogWriter().info("operation for " + key + ", destroyEntry: destroying key " + key + " callback is " + callback);
            aReg.destroy(key, callback);
            Log.getLogWriter().info("operation for " + key + ", destroyEntry: done destroying key " + key);
         } else { // destroy without callback
            Log.getLogWriter().info("operation for " + key + ", destroyEntry: destroying key " + key);
            aReg.destroy(key);
            Log.getLogWriter().info("operation for " + key + ", destroyEntry: done destroying key " + key);
         }
      }

      // validation
      if (isSerialExecution || uniqueKeys) {
         // record the current state
         regionSnapshot.remove(key);
      }
   } catch (com.gemstone.gemfire.cache.EntryNotFoundException e) {
      if (isSerialExecution || uniqueKeys)
         throw new TestException(TestHelper.getStackTrace(e));
      else {
         Log.getLogWriter().info("Caught " + e + " (expected with concurrent execution); continuing with test");
         return;
      }
   }
}