org.apache.hadoop.fs.BatchedRemoteIterator Java Examples
The following examples show how to use
org.apache.hadoop.fs.BatchedRemoteIterator.
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: CacheRegistry.java From nnproxy with Apache License 2.0 | 6 votes |
List<CacheDirectiveEntry> getAllCacheDirectives(UpstreamManager.Upstream upstream) throws IOException { CacheDirectiveInfo filter = new CacheDirectiveInfo.Builder().build(); List<CacheDirectiveEntry> directives = new ArrayList<>(); long prevId = -1; while (true) { BatchedRemoteIterator.BatchedEntries<CacheDirectiveEntry> it = upstream.protocol.listCacheDirectives(prevId, filter); if (it.size() == 0) { break; } for (int i = 0; i < it.size(); i++) { CacheDirectiveEntry entry = it.get(i); prevId = entry.getInfo().getId(); directives.add(entry); } } return directives; }
Example #2
Source File: CacheRegistry.java From nnproxy with Apache License 2.0 | 6 votes |
List<CachePoolEntry> getAllCachePools(UpstreamManager.Upstream upstream) throws IOException { String prevPool = ""; List<CachePoolEntry> pools = new ArrayList<>(); while (true) { BatchedRemoteIterator.BatchedEntries<CachePoolEntry> it = upstream.protocol.listCachePools(prevPool); if (it.size() == 0) { break; } for (int i = 0; i < it.size(); i++) { CachePoolEntry entry = it.get(i); prevPool = entry.getInfo().getPoolName(); pools.add(entry); } } return pools; }
Example #3
Source File: CacheRegistry.java From nnproxy with Apache License 2.0 | 5 votes |
public BatchedRemoteIterator.BatchedListEntries<CachePoolEntry> listCachePools(String prevKey) { final int NUM_PRE_ALLOCATED_ENTRIES = 16; ArrayList<CachePoolEntry> results = new ArrayList<CachePoolEntry>(NUM_PRE_ALLOCATED_ENTRIES); SortedMap<String, CachePoolEntry> tailMap = cachePools.tailMap(prevKey, false); int numListed = 0; for (Map.Entry<String, CachePoolEntry> cur : tailMap.entrySet()) { if (numListed++ >= maxListCachePoolsResponses) { return new BatchedRemoteIterator.BatchedListEntries<>(results, true); } results.add(cur.getValue()); } return new BatchedRemoteIterator.BatchedListEntries<>(results, false); }
Example #4
Source File: CacheRegistry.java From nnproxy with Apache License 2.0 | 4 votes |
public BatchedRemoteIterator.BatchedListEntries<CacheDirectiveEntry> listCacheDirectives(long prevId, CacheDirectiveInfo filter) throws InvalidRequestException { final int NUM_PRE_ALLOCATED_ENTRIES = 16; String filterPath = null; if (filter.getPath() != null) { filterPath = validatePath(filter); } if (filter.getReplication() != null) { throw new InvalidRequestException( "Filtering by replication is unsupported."); } // Querying for a single ID final Long id = filter.getId(); if (id != null) { if (!directivesById.containsKey(id)) { throw new InvalidRequestException("Did not find requested id " + id); } // Since we use a tailMap on directivesById, setting prev to id-1 gets // us the directive with the id (if present) prevId = id - 1; } ArrayList<CacheDirectiveEntry> replies = new ArrayList<CacheDirectiveEntry>(NUM_PRE_ALLOCATED_ENTRIES); int numReplies = 0; SortedMap<Long, CacheDirectiveEntry> tailMap = directivesById.tailMap(prevId + 1); for (Map.Entry<Long, CacheDirectiveEntry> cur : tailMap.entrySet()) { if (numReplies >= maxListCacheDirectivesNumResponses) { return new BatchedRemoteIterator.BatchedListEntries<>(replies, true); } CacheDirectiveInfo info = cur.getValue().getInfo(); // If the requested ID is present, it should be the first item. // Hitting this case means the ID is not present, or we're on the second // item and should break out. if (id != null && !(info.getId().equals(id))) { break; } if (filter.getPool() != null && !info.getPool().equals(filter.getPool())) { continue; } if (filterPath != null && !info.getPath().toUri().getPath().equals(filterPath)) { continue; } replies.add(cur.getValue()); numReplies++; } return new BatchedRemoteIterator.BatchedListEntries<>(replies, false); }