如何在Openstack4j中列出超过10000个swift对象?

时间:2018-01-15 15:25:00

标签: java openstack object-storage

official tutorial code是:

List<? extends SwiftObject> objs = os.objectStorage().objects().list(containerName);

但这有10000个文件的明确限制。是否有更多或更少的常用方法来列出更大的容器?

1 个答案:

答案 0 :(得分:0)

好吧,自己动手,按照测试结果似乎正确。适当的API按名称排序结果(这是记录的)和帐户名称标记&#39;表示用。开始列表的点。

final List<String> result = new ArrayList<>();

final ObjectStorageObjectService oservice = os.objectStorage().objects();
final ObjectListOptions listOptions = ObjectListOptions.create().limit(LIST_PAGE_LIMIT);
List<? extends SwiftObject> objects;
do {
    // Get next list page.
    objects = oservice.list(CONTAINER_NAME, listOptions);

    // If we have some result setup next page.
    if (!objects.isEmpty()) {
        listOptions.marker(objects.get(objects.size() - 1).getName());
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("SWIFT OS: listed page of {} file(s).", objects.size());
    }

    // Add current results page to the end.
    for (final SwiftObject swiftObject : objects) {
        fileList.add(swiftObject.getName());
    }
    // Process will be repeated unless we have incomplete page.

} while (objects.size() >= LIST_PAGE_LIMIT);