/** * Append an interest response * * @param region the region (for debugging) * @param riKey the registerInterest "key" (what the client is interested in) * @param entryKey key we're responding to * @param list list to append to */ private static void appendInterestResponseKey(LocalRegion region, Object riKey, Object entryKey, List list, ServerConnection servConn) throws IOException { list.add(entryKey); if (logger.isDebugEnabled()) { logger.debug("{}: appendInterestResponseKey <{}>; list size was {}; region: {}", servConn.getName(), entryKey, list.size(), region.getFullPath()); } if (list.size() == MAXIMUM_CHUNK_SIZE) { // Send the chunk and clear the list sendRegisterInterestResponseChunk(region, riKey, list, false, servConn); list.clear(); } }
/** * Process an interest request of type {@link InterestType#REGULAR_EXPRESSION} */ private static void handleRegExPR(final PartitionedRegion region, final String regex, final InterestResultPolicy policy, final ServerConnection servConn) throws IOException { final List keyList = new ArrayList(MAXIMUM_CHUNK_SIZE); region.getKeysWithRegEx(regex, sendTombstonesInRIResults(servConn, policy), new PartitionedRegion.SetCollector() { @Override public void receiveSet(Set theSet) throws IOException { appendInterestResponseKeys(region, regex, theSet, keyList, servConn); } }); // Send the last chunk (the only chunk for individual and list keys) // always send it back, even if the list is of zero size. sendRegisterInterestResponseChunk(region, regex, keyList, true, servConn); }
/** * Process an interest request involving a list of keys */ private static void handleListPR(final PartitionedRegion region, final List keyList, final InterestResultPolicy policy, final ServerConnection servConn) throws IOException { final List newKeyList = new ArrayList(MAXIMUM_CHUNK_SIZE); region.getKeysWithList(keyList, sendTombstonesInRIResults(servConn, policy), new PartitionedRegion.SetCollector() { @Override public void receiveSet(Set theSet) throws IOException { appendInterestResponseKeys(region, keyList, theSet, newKeyList, servConn); } }); // Send the last chunk (the only chunk for individual and list keys) // always send it back, even if the list is of zero size. sendRegisterInterestResponseChunk(region, keyList, newKeyList, true, servConn); }
/** * Process an interest request of type ALL_KEYS * * @param region the region * @param policy the policy */ private static void handleAllKeys(LocalRegion region, InterestResultPolicy policy, ServerConnection servConn) throws IOException { List keyList = new ArrayList(MAXIMUM_CHUNK_SIZE); if (region != null) { for (Object entryKey : region.keySet(sendTombstonesInRIResults(servConn, policy))) { appendInterestResponseKey(region, "ALL_KEYS", entryKey, keyList, servConn); } } // Send the last chunk (the only chunk for individual and list keys) // always send it back, even if the list is of zero size. sendRegisterInterestResponseChunk(region, "ALL_KEYS", keyList, true, servConn); }
/** * Process an interest request of type {@link InterestType#REGULAR_EXPRESSION} */ private static void handleRegEx(LocalRegion region, String regex, InterestResultPolicy policy, ServerConnection servConn) throws IOException { if (region instanceof PartitionedRegion) { // too bad java doesn't provide another way to do this... handleRegExPR((PartitionedRegion) region, regex, policy, servConn); return; } List keyList = new ArrayList(MAXIMUM_CHUNK_SIZE); // Handle the regex pattern if (region != null) { Pattern keyPattern = Pattern.compile(regex); for (Object entryKey : region.keySet(sendTombstonesInRIResults(servConn, policy))) { if (!(entryKey instanceof String)) { // key is not a String, cannot apply regex to this entry continue; } if (!keyPattern.matcher((String) entryKey).matches()) { // key does not match the regex, this entry should not be returned. continue; } appendInterestResponseKey(region, regex, entryKey, keyList, servConn); } } // Send the last chunk (the only chunk for individual and list keys) // always send it back, even if the list is of zero size. sendRegisterInterestResponseChunk(region, regex, keyList, true, servConn); }
/** * Process an interest request consisting of a single key * * @param region the region * @param entryKey the key * @param policy the policy */ private static void handleSingleton(LocalRegion region, Object entryKey, InterestResultPolicy policy, ServerConnection servConn) throws IOException { List keyList = new ArrayList(1); if (region != null) { if (region.containsKey(entryKey) || sendTombstonesInRIResults(servConn, policy) && region.containsTombstone(entryKey)) { appendInterestResponseKey(region, entryKey, entryKey, keyList, servConn); } } // Send the last chunk (the only chunk for individual and list keys) // always send it back, even if the list is of zero size. sendRegisterInterestResponseChunk(region, entryKey, keyList, true, servConn); }
/** * Process an interest request involving a list of keys * * @param region the region * @param keyList the list of keys * @param policy the policy */ private static void handleList(LocalRegion region, List keyList, InterestResultPolicy policy, ServerConnection servConn) throws IOException { if (region instanceof PartitionedRegion) { // too bad java doesn't provide another way to do this... handleListPR((PartitionedRegion) region, keyList, policy, servConn); return; } List newKeyList = new ArrayList(MAXIMUM_CHUNK_SIZE); // Handle list of keys if (region != null) { for (Object entryKey : keyList) { if (region.containsKey(entryKey) || sendTombstonesInRIResults(servConn, policy) && region.containsTombstone(entryKey)) { appendInterestResponseKey(region, keyList, entryKey, newKeyList, servConn); } } } // Send the last chunk (the only chunk for individual and list keys) // always send it back, even if the list is of zero size. sendRegisterInterestResponseChunk(region, keyList, newKeyList, true, servConn); }
sendRegisterInterestResponseChunk(region, riKey, new ArrayList(), true, servConn); return;