类org.apache.hadoop.fs.BatchedRemoteIterator源码实例Demo

下面列出了怎么用org.apache.hadoop.fs.BatchedRemoteIterator的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: nnproxy   文件: CacheRegistry.java
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;
}
 
源代码2 项目: nnproxy   文件: CacheRegistry.java
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;
}
 
源代码3 项目: nnproxy   文件: CacheRegistry.java
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);
}
 
源代码4 项目: nnproxy   文件: CacheRegistry.java
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);
}
 
 类所在包
 类方法
 同包方法