Java Code Examples for com.gemstone.gemfire.cache.Region#Entry

The following examples show how to use com.gemstone.gemfire.cache.Region#Entry . 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: HARegionQueue.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public ExpirationAttributes getExpiry(Region.Entry entry) {
  // Use key to determine expiration.
  Object key = entry.getKey();
  if (key instanceof ThreadIdentifier) {
    final int expTime = HARegionQueue.threadIdExpiryTime;
    if (expTime != HARegionQueue.DEFAULT_THREAD_ID_EXPIRY_TIME) {
      // This should only happen in unit test code
      ExpirationAttributes result = testExpAtts;
      if (result == null || result.getTimeout() != expTime) {
        result = new ExpirationAttributes(expTime, ExpirationAction.LOCAL_INVALIDATE);
        // save the expiration attributes in a static to prevent tests from creating lots of instances.
        testExpAtts = result;
      }
      return result;
    } else {
      return DEFAULT_THREAD_ID_EXP_ATTS;
    }
  } else {
    return null;
  }
}
 
Example 2
Source File: PartitionedRegionSingleNodeOperationsJUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public void test022GetEntry() throws Exception {
  Region pr = null;
  try {
    pr = PartitionedRegionTestHelper.createPartitionedRegion("testGetEntry", String.valueOf(200), 0);
    final Integer one = new Integer(1);
    pr.put(one, "one" );
    final Region.Entry re = pr.getEntry(one);
    assertFalse(re.isDestroyed());
    assertFalse(re.isLocal());
    assertTrue(((EntrySnapshot)re).wasInitiallyLocal());

    assertEquals("one", re.getValue());
    assertEquals(one, re.getKey());
    // TODO: Finish out the entry operations
    assertNull(pr.getEntry("nuthin"));
  }
  finally {
    if (pr!=null) {
      pr.destroyRegion();
    }      
  }
}
 
Example 3
Source File: Transactions.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private static void printRegionData(Region<String, String> exampleRegion) {
  Set<String> keySet = new TreeSet<String>(exampleRegion.keySet());
  for (String entryKey: keySet) {
    Region.Entry<String, String> entry = exampleRegion.getEntry(entryKey);
    String entryValue = entry.getValue();
    System.out.println("        entry: " + entryKey + ", " + entryValue);
  }
}
 
Example 4
Source File: DummyQRegion.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public Region.Entry getEntry(Object key) {
  LocalRegion.NonTXEntry e =(LocalRegion.NonTXEntry)super.getEntry(key);
  Region.Entry retVal = null;
  if(e != null &&  this.entry == e.getRegionEntry()) {
      retVal = e;
   } 
  return retVal;
}
 
Example 5
Source File: NewWANConcurrencyCheckForDestroyDUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static void verifyTimestampAfterOp(long timestamp, int memberid) {
  Region region = cache.getRegion("repRegion");
  assertEquals(0, region.size());

  Region.Entry entry = ((LocalRegion)region).getEntry("testKey", null, true);
  RegionEntry re = ((EntrySnapshot)entry).getRegionEntry();
  assertTrue(re.getValueInVM((LocalRegion) region) instanceof Tombstone);
  
  VersionTag tag = re.getVersionStamp().asVersionTag();
  assertEquals(timestamp, tag.getVersionTimeStamp());
  assertEquals(memberid, tag.getDistributedSystemId());
}
 
Example 6
Source File: NewWANConcurrencyCheckForDestroyDUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static void verifyTimestampAfterOp(long timestamp, int memberid) {
  Region region = cache.getRegion("repRegion");
  assertEquals(0, region.size());

  Region.Entry entry = ((LocalRegion)region).getEntry("testKey", null, true);
  RegionEntry re = ((EntrySnapshot)entry).getRegionEntry();
  assertTrue(re.getValueInVM((LocalRegion) region) instanceof Tombstone);
  
  VersionTag tag = re.getVersionStamp().asVersionTag();
  assertEquals(timestamp, tag.getVersionTimeStamp());
  assertEquals(memberid, tag.getDistributedSystemId());
}
 
Example 7
Source File: TXState.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * @see InternalDataView#accessEntry(Object, Object, LocalRegion)
 */
public Region.Entry<?, ?> accessEntry(final Object key,
    final Object callbackArg, final LocalRegion localRegion) {
  // creating a KeyInfo here to avoid possible multiple resolver calls
  // to get the bucketId
  final KeyInfo keyInfo = localRegion.getKeyInfo(key, callbackArg);
  return getEntry(keyInfo, localRegion, true, false);
}
 
Example 8
Source File: GetEntry70.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public Get70.Entry getValueAndIsObject(Region region, Object key,
    Object callbackArg, LogWriterI18n log,
    ServerConnection servConn) {
  LocalRegion lregion = (LocalRegion)region;
  Object data = null;
  Region.Entry entry = region.getEntry(key);
  if (logger.fineEnabled()) {
    logger.fine("GetEntryCommand: for key:"+key+" returning entry:"+entry);
  }
  VersionTag tag = null;
  if (entry != null) {
    EntrySnapshot snap;
    if (entry instanceof EntrySnapshot) {
      snap = (EntrySnapshot)entry;
      tag = snap.getVersionTag();
    }
    else {
      snap = new EntrySnapshot();
    }
    NonLocalRegionEntry re = NonLocalRegionEntry.newEntry(key,
        entry.getValue(), lregion, tag);
    snap.setRegionEntry(re);
    snap.setRegion(lregion);
    data = snap;
  }
  Get70.Entry result = new Get70.Entry();
  result.value = data;
  result.isObject = true;
  result.keyNotPresent = false;
  result.versionTag = tag;
  return result;
}
 
Example 9
Source File: WANClient.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Validating Reader Wan Sites
 */
public static void validateReaderWanSiteEntriesTask() {
  Log.getLogWriter().info("Sleeping for some time ..");
  hydra.MasterController.sleepForMs(100000);
  Region region = RegionHelper.getRegion(REGION_NAME);
  if (region.isEmpty()) {
    throw new TestException(" Region has no entries to validate ");
  }
  long requiredSize = WANBlackboard.getInstance().getSharedCounters().read(
      WANBlackboard.currentEntry_writer);
  checkKeyRegionEntries("writer_", requiredSize);

  Iterator iterator = region.entrySet(false).iterator();
  Region.Entry entry = null;
  Object key = null;
  Object value = null;
  while (iterator.hasNext()) {
    entry = (Region.Entry)iterator.next();
    key = entry.getKey();
    value = entry.getValue();

    if (((String)key).startsWith("reader_")) {
      if (!keyList.contains(key)) {
        throw new TestException(
            "Found reader key that is not present in the keyList");
      }
      else if (((Integer)value).intValue() != ITERATIONS) {
        String s = "Wrong value in cache at " + key + ", expected "
            + ITERATIONS + " but got " + ((Integer)value).intValue();
        throw new TestException(s);
      }

    }

  }
}
 
Example 10
Source File: TXState.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
final Region.Entry<?, ?> getEntry(final KeyInfo keyInfo,
    final LocalRegion localRegion, final boolean access,
    final boolean allowTombstones) {
  final LocalRegion dataRegion = localRegion.getDataRegionForRead(keyInfo,
      Operation.GET_ENTRY);
  final TXRegionState txr = readRegion(dataRegion);
  if (txr != null) {
    final Object key = keyInfo.getKey();
    txr.lock();
    try {
      final Object txEntry = txr.readEntry(key);
      if (txEntry != null) {
        if (txEntry instanceof TXEntryState) {
          final TXEntryState txes = (TXEntryState)txEntry;
          if (txes.existsLocally()) {
            if (txes.isDirty()) {
              return new TXEntry(localRegion, dataRegion, key, txes, this);
            }
            return localRegion.new NonTXEntry(txes.getUnderlyingRegionEntry());
          }
          // It was destroyed by the transaction so skip
          // this key and try the next one
          return null; // fix for bug 34583
        }
        else {
          // for read locked entries, no need to take the read lock again
          final AbstractRegionEntry entry = (AbstractRegionEntry)txEntry;
          if (!entry.isDestroyedOrRemoved()) {
            return localRegion.new NonTXEntry(entry);
          }
          return null;
        }
      }
    } finally {
      txr.unlock();
    }
  }
  return localRegion.txGetEntry(keyInfo, access, this, allowTombstones);
}
 
Example 11
Source File: HAContainerRegion.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public Object getEntry(Object key) {
  Region.Entry entry = ((Region)map).getEntry(key);
  if(entry != null) {
    ClientUpdateMessageImpl cum = (ClientUpdateMessageImpl)entry.getValue();
    cum.setEventIdentifier(((HAEventWrapper)key).getEventId());
    if(cum.hasCqs()) {
      cum.setClientCqs(((HAEventWrapper)key).getClientCqs());
    }      
  }
  return entry;
}
 
Example 12
Source File: HARQueueNewImplDUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static void verifyNullValuesInCMR(final Integer numOfEntries, 
    final Integer port,
    String[] keys) {
  final Region msgsRegion = cache.getRegion(BridgeServerImpl
      .generateNameForClientMsgsRegion(port.intValue()));
  WaitCriterion wc = new WaitCriterion() {
    String excuse;
    public boolean done() {
      int sz = msgsRegion.size();
      return sz == numOfEntries.intValue();
    }
    public String description() {
      return excuse;
    }
  };
  DistributedTestCase.waitForCriterion(wc, 60 * 1000, 1000, true);

  Set entries = msgsRegion.entrySet();
  Iterator iter = entries.iterator();
  for (; iter.hasNext();) {
    Region.Entry entry = (Region.Entry)iter.next();
    ClientUpdateMessage cum = (ClientUpdateMessage)entry.getValue();
    for (int i = 0; i < keys.length; i++) {
      logger.fine("cum.key: " + cum.getKeyToConflate());
      // assert that the keys are not present in entries set
      assertTrue(!keys[i].equals(cum.getKeyToConflate()));
    }
  }
}
 
Example 13
Source File: HARegionQueue.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Repopulates the HARegion after the GII is over so as to reset the counters
 * and populate the DACE objects for the thread identifiers . This method
 * should be invoked as the last method in the constructor . Thus while
 * creating BlockingQueue this method should be invoked lastly in the derived
 * class contructor , after the HARegionQueue contructor is complete.
 * Otherwise, the ReentrantLock will be null.
 * 
 * @throws CacheException
 * @throws InterruptedException
 */
void putGIIDataInRegion() throws CacheException, InterruptedException
{
  Set entrySet = this.region.entries(false);
  // check if the region is not empty. if there is
  //data, then the relevant data structures have to
  //be populated
  if (!entrySet.isEmpty()) {
    this.puttingGIIDataInQueue = true;
    try {
      Region.Entry entry = null;
      Map orderedMap = new TreeMap();
      Iterator iterator = entrySet.iterator();
      Object key = null;
      while (iterator.hasNext()) {
        entry = (Region.Entry)iterator.next();
        key = entry.getKey();
        if (logger.fineEnabled()) {
          logger.fine("processing queue key " + key + " and value " + entry.getValue());
        }
        if (key instanceof Long) {
          if ( !(entry.getValue() instanceof ClientMarkerMessageImpl) ) {
            orderedMap.put(key, entry.getValue());
          }
        }
        this.region.localDestroy(key);
      }
      long max = 0;
      long counterInRegion = 0;
      entrySet = orderedMap.entrySet();
      if (!entrySet.isEmpty()) {
        Map.Entry mapEntry = null;
        iterator = entrySet.iterator();
        while (iterator.hasNext()) {
          mapEntry = (Map.Entry)iterator.next();
          Conflatable val = (Conflatable)mapEntry.getValue();
          if (val.getEventId() != null) { // bug #44959 null event ID caused NPE
            counterInRegion = ((Long)mapEntry.getKey()).intValue();
            // TODO: remove this assertion
            Assert.assertTrue(counterInRegion > max);
            max = counterInRegion;
            //putInQueue(val);
//            this.logger.info(LocalizedStrings.DEBUG, this + " putting GII entry #" + counterInRegion
//                + " into queue: " + val);
            this.put(val);
          } else if (this.logger.fineEnabled()) {
            this.logger.fine("bug 44959 encountered: HARegion.putGIIDataInRegion found null eventId in " + val);
          }
        }
      }
      this.tailKey.set(max);
    } finally {
      this.puttingGIIDataInQueue = false;
      if (this.logger.fineEnabled()) {
        this.logger.fine(this + " done putting GII data into queue");
      }
    }
  }
  //TODO:Asif: Avoid invocation of this method
  startHAServices(this.region.getCache());
}
 
Example 14
Source File: TXState.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public Region.Entry<?, ?> getEntryForIterator(final KeyInfo keyInfo,
    final LocalRegion region, boolean allowTombstones) {
  // for local/distributed regions, the key is the RegionEntry itself
  // getDataRegion will work correctly neverthless
  final InternalDataView sharedView = region.getSharedDataView();
  final Object re = keyInfo.getKey();
  final Object key = sharedView.getKeyForIterator(re, region);
  if (key != null) {
    final LocalRegion dataRegion = region.getDataRegionForRead(keyInfo,
        Operation.GET_ENTRY);
    final TXRegionState txr = readRegion(dataRegion);
    if (txr != null) {
      txr.lock();
      try {
        final Object txEntry = txr.readEntry(key);
        if (txEntry != null) {
          if (txEntry instanceof TXEntryState) {
            final TXEntryState txes = (TXEntryState)txEntry;
            if (txes.existsLocally()) {
              if (txes.isDirty()) {
                return new TXEntry(region, dataRegion, key, txes, this);
              }
              return region.new NonTXEntry(txes.getUnderlyingRegionEntry());
            }
            // It was destroyed by the transaction so skip
            // this key and try the next one
            return null; // fix for bug 34583
          }
          else {
            // for read locked entries, no need to take the read lock again
            final AbstractRegionEntry entry = (AbstractRegionEntry)txEntry;
            if (!entry.isDestroyedOrRemoved()) {
              return region.new NonTXEntry(entry);
            }
            return null;
          }
        }
      } finally {
        txr.unlock();
      }
    }
    return region
        .txGetEntryForIterator(keyInfo, false, this, allowTombstones);
  }
  return null;
}
 
Example 15
Source File: TXState.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public Region.Entry<?, ?> getEntryForIterator(final KeyInfo keyInfo,
    final LocalRegion region, boolean allowTombstones) {
  // for local/distributed regions, the key is the RegionEntry itself
  // getDataRegion will work correctly neverthless
  final InternalDataView sharedView = region.getSharedDataView();
  final Object re = keyInfo.getKey();
  final Object key = sharedView.getKeyForIterator(re, region);
  if (key != null) {
    final LocalRegion dataRegion = region.getDataRegionForRead(keyInfo,
        Operation.GET_ENTRY);
    final TXRegionState txr = readRegion(dataRegion);
    if (txr != null) {
      txr.lock();
      try {
        final Object txEntry = txr.readEntry(key);
        if (txEntry != null) {
          if (txEntry instanceof TXEntryState) {
            final TXEntryState txes = (TXEntryState)txEntry;
            if (txes.existsLocally()) {
              if (txes.isDirty()) {
                return new TXEntry(region, dataRegion, key, txes, this);
              }
              return region.new NonTXEntry(txes.getUnderlyingRegionEntry());
            }
            // It was destroyed by the transaction so skip
            // this key and try the next one
            return null; // fix for bug 34583
          }
          else {
            // for read locked entries, no need to take the read lock again
            final AbstractRegionEntry entry = (AbstractRegionEntry)txEntry;
            if (!entry.isDestroyedOrRemoved()) {
              return region.new NonTXEntry(entry);
            }
            return null;
          }
        }
      } finally {
        txr.unlock();
      }
    }
    return region
        .txGetEntryForIterator(keyInfo, false, this, allowTombstones);
  }
  return null;
}
 
Example 16
Source File: PartitionedRegionDataView.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
@Override
public Region.Entry<?, ?> getEntryForIterator(final KeyInfo keyInfo,
    final LocalRegion currRgn, boolean allowTombstones) {
  return currRgn.txGetEntry(keyInfo, false, null, allowTombstones);
}
 
Example 17
Source File: TXStateProxy.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public final Region.Entry<?, ?> getEntryForIterator(final KeyInfo keyInfo,
    final LocalRegion currRgn, final boolean allowTombstones) {
  return getEntry(keyInfo, null, null, currRgn, false, true, allowTombstones);
}
 
Example 18
Source File: EntryExpiryTask.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
private Object getValueForCallback(LocalRegion r, Object k) {
  Region.Entry<?,?> e = r.getEntry(k);
  return (e != null) ? e.getValue() : null;
}
 
Example 19
Source File: EntryExpiryTask.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
private Object getValueForCallback(LocalRegion r, Object k) {
  Region.Entry<?,?> e = r.getEntry(k);
  return (e != null) ? e.getValue() : null;
}
 
Example 20
Source File: InternalDataView.java    From gemfirexd-oss with Apache License 2.0 2 votes vote down vote up
/**
 * 
 * @param key
 * @param currRgn
 * @param allowTombstones
 * @return an Entry for the key
 */
Region.Entry<?, ?> getEntryForIterator(KeyInfo key, LocalRegion currRgn,
    boolean allowTombstones);