@Override public ExpirationAttributes getExpiry(Entry entry) { Object key = entry.getKey(); synchronized (CountExpiry.class) { Integer count = (Integer) invokeCounts.get(key); if (count == null) { invokeCounts.put(key, new Integer(1)); } else { invokeCounts.put(key, new Integer(count.intValue() + 1)); } } // synchronized if (key.equals(special)) { return specialAtt; } return null; }
@Override public void visit(Integer bid, Entry re) { buf.append(re.getKey()).append(" => ").append(re.getValue()).append("\n"); }
/** * Generates XML for a region entry */ private void generate(Region.Entry entry) throws SAXException { if ((entry == null)) { return; } handler.startElement("", ENTRY, ENTRY, EMPTY); handler.startElement("", KEY, KEY, EMPTY); generate(entry.getKey()); handler.endElement("", KEY, KEY); handler.startElement("", VALUE, VALUE, EMPTY); generate(entry.getValue()); handler.endElement("", VALUE, VALUE); handler.endElement("", ENTRY, ENTRY); }
while (iterator.hasNext()) { entry = (Region.Entry) iterator.next(); key = entry.getKey(); if (isDebugEnabled) { logger.debug("{} processing queue key {} and value {}", this.regionName, key,
for (int i = 0; i < 3; i++) { assertTrue(iter.hasNext()); assertTrue(keys.remove(((Region.Entry) iter.next()).getKey())); for (int i = 0; i < 3; i++) { assertTrue(iter.hasNext()); assertTrue(keys.remove(((Region.Entry) iter.next()).getKey())); region.destroy(entry.getKey()); if (entry.isLocal()) { assertTrue(entry.isDestroyed());
entry.getKey(); fail("Should have thrown an EntryDestroyedException"); } catch (EntryDestroyedException ex) {
assertTrue("!hasNext, i=" + i, iter.hasNext()); assertTrue("remove returned false, i=" + i, keys.remove(((Region.Entry) iter.next()).getKey())); assertTrue("!hasNext, i=" + i, iter.hasNext()); assertTrue("remove returned false, i=" + i, keys.remove(((Region.Entry) iter.next()).getKey())); Object ekey = entry.getKey(); region.destroy(ekey); assertEquals(false, region.containsKey(ekey));
Entry entry = (Entry) entryObject; try { Object key = entry.getKey(); Object value = entry.getValue(); if (value == Token.TOMBSTONE) {
Entry entry = (Entry) entryObject; try { Object entryKey = entry.getKey(); if (!(entryKey instanceof String)) { continue;
/** * Tests that creating an entry in a region actually creates it * * @see Region#containsKey * @see Region#containsValueForKey */ @Test public void testContainsKey() throws CacheException { String name = this.getUniqueName(); Region region = createRegion(name); Object key = name; Object value = new Integer(42); assertFalse(region.containsKey(key)); region.create(key, null); assertFalse(region.containsValueForKey(key)); Region.Entry entry = region.getEntry(key); assertNotNull(entry); assertEquals(entry.getKey(), key); assertNull(entry.getValue()); region.put(key, value); assertTrue(region.containsValueForKey(key)); assertEquals(entry, region.getEntry(key)); if (entry.isLocal()) { assertEquals(value, entry.getValue()); } else { assertEquals(value, region.getEntry(key).getValue()); } }
/** * do a localDestroy on all matching keys * * @param key the regular expression to match on * @see #registerInterestRegex(String) */ private void clearViaRegEx(String key) { // TODO: if (key.equals(".*)) then cmnClearRegionNoCallbacks Pattern keyPattern = Pattern.compile(key); for (Iterator it = this.entrySet(false).iterator(); it.hasNext();) { Region.Entry entry = (Region.Entry) it.next(); try { Object entryKey = entry.getKey(); if (!(entryKey instanceof String)) { continue; } if (!keyPattern.matcher((String) entryKey).matches()) { // key does not match the regex, this entry should not be returned. continue; } localDestroyNoCallbacks(entryKey); } catch (EntryDestroyedException ignore) { // ignore to fix bug 35534 } } }
Region.Entry otherEntry = other.getEntry(myEntry.getKey()); if (otherEntry == null) { return false;
/** * Tests that {@link Region#put} on a previously non-existent region entry creates it. */ @Test public void testPutNonExistentEntry() throws CacheException { String name = this.getUniqueName(); Region region = createRegion(name); Object key = name; assertNull(region.getEntry(key)); Object value = new Integer(42); region.put(key, value); Region.Entry entry = region.getEntry(key); assertNotNull(entry); assertEquals(key, entry.getKey()); assertEquals(value, entry.getValue()); assertEquals(value, region.get(key)); try { Collection values = region.values(); assertEquals(1, values.size()); assertEquals(value, values.iterator().next()); } catch (UnsupportedOperationException uoe) { org.apache.geode.test.dunit.LogWriterUtils.getLogWriter() .info("Region.values() reported UnsupportedOperation"); } }
/** * Do localDestroy on a list of keys, if they exist * * @param keys the list of arrays of keys to invalidate * @see #registerInterest(Object) */ private void clearViaList(List keys) { for (Object entryObject : entrySet(false)) { Entry entry = (Entry) entryObject; try { Object entryKey = entry.getKey(); boolean match = false; for (Object key : keys) { if (entryKey.equals(key)) { match = true; break; } } // for if (!match) { continue; } localDestroyNoCallbacks(entryKey); } catch (EntryDestroyedException ignore) { // ignore to fix bug 35534 } } }
public RemoteEntrySnapshot(Region.Entry entry, boolean statsEnabled) throws CacheException { Object entryName = entry.getKey(); if (entryName instanceof String || entryName instanceof Number) { name = entryName; } else { name = new RemoteObjectName(entryName); } Object val = entry.getValue(); if (val != null) { this.value = val.getClass().getName() + "\"" + val.toString() + "\""; } else { this.value = null; } Object attr = entry.getUserAttribute(); if (attr != null) { this.userAttribute = attr.getClass().getName() + "\"" + attr.toString() + "\""; } else { this.userAttribute = null; } if (statsEnabled) { this.stats = new RemoteCacheStatistics(entry.getStatistics()); } else { this.stats = new RemoteCacheStatistics(); } }
@Override public ExpirationAttributes getExpiry(Region.Entry entry) { // Use key to determine expiration. Object key = entry.getKey(); if (key instanceof ThreadIdentifier) { // TODO: inject subclass of ThreadIdentifierCustomExpiry and move next block to test class if (expTime != 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; } }
/** * Create one of these in the local case so that we have a snapshot of the state and can allow the * bucket to move out from under us. */ public NonLocalRegionEntry(Region.Entry re, InternalRegion br) { this.key = re.getKey(); this.value = re.getValue(); if (this.value instanceof CachedDeserializable) { // We make a copy of the CachedDeserializable. // That way the NonLocalRegionEntry will be disconnected // from the CachedDeserializable that is in our cache and // will not modify its state. this.value = CachedDeserializableFactory.create((CachedDeserializable) this.value); } Assert.assertTrue(this.value != Token.NOT_AVAILABLE, "getEntry did not fault value in from disk"); this.lastModified = 0l;// re.getStatistics().getLastModifiedTime(); this.isRemoved = Token.isRemoved(value); if (re instanceof EntrySnapshot) { this.versionTag = ((EntrySnapshot) re).getVersionTag(); } else { // TODO need to get version information from transaction entries } }
private Object fetchEntryValue(Region.Entry re) { if (re.isLocal()) { return re.getValue(); } else { Region r = re.getRegion(); Object key = re.getKey(); Region.Entry freshRE = r.getEntry(key); if (freshRE == null) { return null; // or should we throw an exception? } return freshRE.getValue(); } }
@Override public ExpirationAttributes getExpiry(Entry entry) { // getCache().getLogger().fine("Calculating expiry for " + entry.getKey() // , new Exception("here") // ); if (entry.getKey().equals(special)) { return specialAtt; } return null; }
private boolean isEntryDestroyed(Region.Entry re) { if (re.isLocal()) { return re.isDestroyed(); } else { Region r = re.getRegion(); Object key = re.getKey(); Region.Entry freshRE = r.getEntry(key); if (freshRE == null) { return true; } return freshRE.isDestroyed(); } }