org.apache.geode.cache.Region.entrySet()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(11.0k)|赞(0)|评价(0)|浏览(81)

本文整理了Java中org.apache.geode.cache.Region.entrySet方法的一些代码示例,展示了Region.entrySet的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Region.entrySet方法的具体详情如下:
包路径:org.apache.geode.cache.Region
类名称:Region
方法名:entrySet

Region.entrySet介绍

[英]Returns the Set of Region.Entry objects in this region.

This Set is unmodifiable. It is backed by this region. Synchronization is not necessary to access or iterate over this set. No ConcurrentModificationExceptions will be thrown, but entries may be added or removed to this set while a thread is iterating. Iterators are intended to be used by one thread at a time. If a stable "snapshot" view of the set is required, then call one of the toArray methods on the set and iterate over the array. If you need to lock down the region so this set is not modified while it is being accessed, use global scope with a distributed lock. A remove called on an entry via the iterator will result in an UnsupportedOperationException The Region.Entry obtained via the iterator is backed by the region. If a setValue on that entry is called, it will be similar in effect as calling a put on that key.
[中]返回此区域中Region.Entry个对象的Set
这个Set是不可修改的。它得到了这个地区的支持。访问或迭代此集合不需要同步。不会抛出ConcurrentModificationExceptions,但在线程迭代时,可以向该集合添加或删除条目。迭代器一次只能由一个线程使用。如果需要一个稳定的集合“快照”视图,那么调用集合上的一个toArray方法并迭代数组。如果需要锁定该区域,以便在访问该区域时不修改该集合,请使用带有分布式锁的全局作用域。通过迭代器对条目调用remove将导致该区域出现UnsupportedOperationException。通过迭代器获得的条目由区域支持。如果调用了该项上的setValue,则其效果类似于调用该键上的put。

代码示例

代码示例来源:origin: apache/geode

@Override
public Set<Entry<K, V>> entrySet() {
 return region.entrySet();
}

代码示例来源:origin: apache/geode

public Set entrySet(boolean recursive) {
 return this.region.entrySet(recursive);
}

代码示例来源:origin: apache/geode

@Override
public Set entrySet() {
 return map.entrySet();
}

代码示例来源:origin: apache/geode

public Set<Map.Entry<String, RedisDataType>> metaEntrySet() {
 return this.redisMetaRegion.entrySet();
}

代码示例来源:origin: apache/geode

@Override
public Map<Integer, PdxType> types() {
 // ugh, I don't think we can rely on the local map to contain all types
 Map<Integer, PdxType> types = new HashMap<>();
 for (Entry<Object, Object> type : getIdToType().entrySet()) {
  Object id = type.getKey();
  if (type.getValue() instanceof PdxType) {
   types.put((Integer) id, (PdxType) type.getValue());
  }
 }
 return types;
}

代码示例来源:origin: apache/geode

@Override
public Map<Integer, EnumInfo> enums() {
 // ugh, I don't think we can rely on the local map to contain all types
 Map<Integer, EnumInfo> enums = new HashMap<Integer, EnumInfo>();
 for (Entry<Object, Object> type : getIdToType().entrySet()) {
  Object id = type.getKey();
  if (type.getValue() instanceof EnumInfo) {
   enums.put(((EnumId) id).intValue(), (EnumInfo) type.getValue());
  }
 }
 return enums;
}

代码示例来源:origin: apache/geode

@Override
 public void visit(Integer bucketId, Region buk) {
  try {
   ((LocalRegion) buk).waitForData();
   for (Iterator ei = buk.entrySet().iterator(); ei.hasNext();) {
    knock.visit(bucketId, (Region.Entry) ei.next());
   }
  } catch (CacheRuntimeException ignore) {
  }
  knock.finishedVisiting();
 }
});

代码示例来源:origin: apache/geode

@Override
public Set entrySet(boolean recursive) {
 try {
  preOp();
  return this.realRegion.entrySet(recursive);
 } finally {
  postOp();
 }
}

代码示例来源:origin: apache/geode

@Override
public Set entrySet() {
 try {
  preOp();
  return this.realRegion.entrySet();
 } finally {
  postOp();
 }
}

代码示例来源:origin: apache/geode

@Override
 public void run2() throws CacheException {
  Region<Object, Object> region = getRootRegion().getSubregion(name);
  // expected entry count (subtract entries destroyed)
  int entryCount = NB1_NUM_ENTRIES + 200 - NB1_NUM_ENTRIES / 6;
  assertThat(region.entrySet(false).size()).isEqualTo(entryCount);
  // determine how many entries were updated before getInitialImage
  // was complete
  int numConcurrent = 0;
  numConcurrent = verifyEntryUpdateCounts(region, numConcurrent, values, iiComplete);
  logger.info(name + ": " + numConcurrent
    + " entries out of " + entryCount + " were updated concurrently with getInitialImage");
  // make sure at least some of them were concurrent
  {
   int min = 30;
   String description =
     "Not enough updates concurrent with getInitialImage occurred to my liking. "
       + numConcurrent + " entries out of " + entryCount
       + " were updated concurrently with getInitialImage, and I'd expect at least "
       + min
       + " or so";
   assertThat(numConcurrent >= min).describedAs(description).isTrue();
  }
 }
});

代码示例来源:origin: apache/geode

/**
 * This creates Dynamic Regions that already exist in other publishing processes
 */
private void createDefinedDynamicRegions() throws CacheException {
 // TODO: perhaps add some logic here to avoid the possibility of synchronization issues
 Set set = this.dynamicRegionList.entrySet(false);
 Iterator iterator = set.iterator();
 SortedMap sorted = new TreeMap();
 // sort by region name before creating (bug 35528)
 while (iterator.hasNext()) {
  Region.Entry e = (Region.Entry) iterator.next();
  DynamicRegionAttributes dda = (DynamicRegionAttributes) e.getValue();
  sorted.put(dda.rootRegionName + '/' + dda.name, dda);
 }
 iterator = sorted.values().iterator();
 while (iterator.hasNext()) {
  DynamicRegionAttributes dda = (DynamicRegionAttributes) iterator.next();
  doBeforeRegionCreated(dda.rootRegionName, dda.name);
  Region region = createDynamicRegionImpl(dda.rootRegionName, dda.name, false);
  doAfterRegionCreated(region, false, false, null);
 }
}

代码示例来源:origin: apache/geode

public SelectResults entrySet() {
 ResultsCollectionWrapper res = new ResultsCollectionWrapper(new ObjectTypeImpl(Map.Entry.class),
   this.region.entrySet(false));
 res.setModifiable(false);
 return res;
}

代码示例来源:origin: apache/geode

void removeInvalidXmlConfigurations(Region<String, Configuration> configRegion)
  throws IOException, SAXException, ParserConfigurationException, TransformerException {
 for (Map.Entry<String, Configuration> entry : configRegion.entrySet()) {
  String group = entry.getKey();
  Configuration configuration = entry.getValue();
  String configurationXml = configuration.getCacheXmlContent();
  if (configurationXml != null && !configurationXml.isEmpty()) {
   Document document = XmlUtils.createDocumentFromXml(configurationXml);
   boolean removedInvalidReceivers = removeInvalidGatewayReceivers(document);
   boolean removedDuplicateReceivers = removeDuplicateGatewayReceivers(document);
   if (removedInvalidReceivers || removedDuplicateReceivers) {
    configuration.setCacheXmlContent(XmlUtils.prettyXml(document));
    configRegion.put(group, configuration);
   }
  }
 }
}

代码示例来源:origin: apache/geode

@Test
 public void removeAllProxiesEntryNotFoundLogged() {
  MBeanProxyFactory mBeanProxyFactory =
    spy(new MBeanProxyFactory(mock(MBeanJMXAdapter.class),
      mock(SystemManagementService.class)));
  Region mockRegion = mock(Region.class);
  Set entrySet = new HashSet<Map.Entry<String, Object>>();

  Map.Entry mockEntry = mock(Map.Entry.class);
  doThrow(new EntryNotFoundException("Test EntryNotFoundException")).when(mockEntry).getKey();

  entrySet.add(mockEntry);

  doReturn(entrySet).when(mockRegion).entrySet();
  mBeanProxyFactory.removeAllProxies(mock(DistributedMember.class), mockRegion);

  // EntryNotFoundException should just result in a warning as it implies
  // the proxy has already been removed and the entry has already been destroyed
  verify(mBeanProxyFactory, times(1)).logProxyAlreadyRemoved(any(), any());
 }
}

代码示例来源:origin: apache/geode

public RegionSubRegionSnapshot(Region reg) {
 this();
 this.name = reg.getName();
 if (reg instanceof PartitionedRegion) {
  PartitionedRegion p_reg = (PartitionedRegion) reg;
  this.entryCount = p_reg.entryCount(true);
 } else {
  this.entryCount = reg.entrySet().size();
 }
 final LogWriter logger = reg.getCache().getLogger();
 if ((logger != null) && logger.fineEnabled()) {
  logger.fine("RegionSubRegionSnapshot Region entry count =" + this.entryCount + " for region ="
    + this.name);
 }
}

代码示例来源:origin: apache/geode

@Test
@Parameters(method = "getXmlAndExpectedElements")
public void removeInvalidXmlConfiguration(String xml, int expectedInitialElements,
  int expectFinalElements) throws Exception {
 Region<String, Configuration> configurationRegion = mock(Region.class);
 configuration.setCacheXmlContent(xml);
 System.out.println("Initial xml content:\n" + configuration.getCacheXmlContent());
 Document document = XmlUtils.createDocumentFromXml(configuration.getCacheXmlContent());
 assertThat(document.getElementsByTagName("gateway-receiver").getLength())
   .isEqualTo(expectedInitialElements);
 Set<Map.Entry<String, Configuration>> configurationEntries = new HashSet<>();
 configurationEntries.add(new AbstractMap.SimpleEntry<>("cluster", configuration));
 doReturn(configurationEntries).when(configurationRegion).entrySet();
 service.removeInvalidXmlConfigurations(configurationRegion);
 System.out.println("Processed xml content:\n" + configuration.getCacheXmlContent());
 document = XmlUtils.createDocumentFromXml(configuration.getCacheXmlContent());
 assertThat(document.getElementsByTagName("gateway-receiver").getLength())
   .isEqualTo(expectFinalElements);
}

代码示例来源:origin: apache/geode

@Override
 public long export(Region<K, V> region, ExportSink sink, SnapshotOptions<K, V> options)
   throws IOException {
  LocalRegion local = RegionSnapshotServiceImpl.getLocalRegion(region);

  long count = 0;
  for (Entry<K, V> entry : region.entrySet()) {
   try {
    if (options.getFilter() == null || options.getFilter().accept(entry)) {
     sink.write(new SnapshotRecord(local, entry));
     count++;
    }
   } catch (EntryDestroyedException e) {
    // continue to next entry
   }
  }
  return count;
 }
}

代码示例来源:origin: apache/geode

/**
 * Returns the entries as an unmodifiable SelectResults. This is the preferred method that is
 * invoked when accessing the attribute "entries".
 */
public SelectResults getEntries() {
 ResultsCollectionWrapper res;
 if (this.region instanceof LocalDataSet) {
  LocalDataSet localData = (LocalDataSet) this.region;
  res = new ResultsCollectionWrapper(TypeUtils.getRegionEntryType(this.region),
    localData.localEntrySet());
 } else {
  res = new ResultsCollectionWrapper(TypeUtils.getRegionEntryType(this.region),
    this.region.entrySet(false));
 }
 res.setModifiable(false);
 return res;
}

代码示例来源:origin: apache/geode

/** Creates a new instance of QRegion */
public QRegion(Region region, boolean includeKeys) {
 if (region == null)
  throw new IllegalArgumentException(
    "Region can not be NULL");
 this.region = region;
 Class constraint = this.region.getAttributes().getValueConstraint();
 if (constraint == null)
  constraint = Object.class;
 ResultsCollectionWrapper res = null;
 if (includeKeys) {
  res =
    new ResultsCollectionWrapper(TypeUtils.getObjectType(constraint), this.region.entrySet());
 } else {
  res = new ResultsCollectionWrapper(TypeUtils.getObjectType(constraint), this.region.values());
 }
 res.setModifiable(false);
 if (!DefaultQueryService.COPY_ON_READ_AT_ENTRY_LEVEL) {
  res.setIgnoreCopyOnReadForQuery(true);
 }
 this.values = res;
}

代码示例来源:origin: apache/geode

@Override
public void executeCommand(Command command, ExecutionHandlerContext context) {
 List<byte[]> commandElems = command.getProcessedCommand();
 if (commandElems.size() < 2) {
  command.setResponse(Coder.getErrorResponse(context.getByteBufAllocator(), ArityDef.HGETALL));
  return;
 }
 ByteArrayWrapper key = command.getKey();
 checkDataType(key, RedisDataType.REDIS_HASH, context);
 Region<ByteArrayWrapper, ByteArrayWrapper> keyRegion = getRegion(context, key);
 if (keyRegion == null) {
  command.setResponse(Coder.getEmptyArrayResponse(context.getByteBufAllocator()));
  return;
 }
 Collection<Map.Entry<ByteArrayWrapper, ByteArrayWrapper>> entries =
   new ArrayList(keyRegion.entrySet()); // This creates a CopyOnRead behavior
 if (entries.isEmpty()) {
  command.setResponse(Coder.getEmptyArrayResponse(context.getByteBufAllocator()));
  return;
 }
 command.setResponse(Coder.getKeyValArrayResponse(context.getByteBufAllocator(), entries));
}

相关文章

微信公众号

最新文章

更多