Search in sources :

Example 1 with ListContainerOptions

use of org.jclouds.blobstore.options.ListContainerOptions in project camel by apache.

the class JcloudsBlobStoreConsumer method poll.

@Override
protected int poll() throws Exception {
    shutdownRunningTask = null;
    pendingExchanges = 0;
    Queue<Exchange> queue = new LinkedList<Exchange>();
    String directory = endpoint.getDirectory();
    ListContainerOptions opt = new ListContainerOptions();
    if (!Strings.isNullOrEmpty(directory)) {
        opt = opt.inDirectory(directory);
    }
    for (StorageMetadata md : blobStore.list(container, opt.maxResults(maxMessagesPerPoll).recursive())) {
        String blobName = md.getName();
        if (md.getType().equals(StorageType.BLOB)) {
            if (!Strings.isNullOrEmpty(blobName)) {
                InputStream body = JcloudsBlobStoreHelper.readBlob(blobStore, container, blobName);
                if (body != null) {
                    Exchange exchange = endpoint.createExchange();
                    CachedOutputStream cos = new CachedOutputStream(exchange);
                    IOHelper.copy(body, cos);
                    exchange.getIn().setBody(cos.newStreamCache());
                    exchange.setProperty(JcloudsConstants.BLOB_NAME, blobName);
                    queue.add(exchange);
                }
            }
        }
    }
    return queue.isEmpty() ? 0 : processBatch(CastUtils.cast(queue));
}
Also used : Exchange(org.apache.camel.Exchange) ListContainerOptions(org.jclouds.blobstore.options.ListContainerOptions) StorageMetadata(org.jclouds.blobstore.domain.StorageMetadata) InputStream(java.io.InputStream) LinkedList(java.util.LinkedList) CachedOutputStream(org.apache.camel.converter.stream.CachedOutputStream)

Aggregations

InputStream (java.io.InputStream)1 LinkedList (java.util.LinkedList)1 Exchange (org.apache.camel.Exchange)1 CachedOutputStream (org.apache.camel.converter.stream.CachedOutputStream)1 StorageMetadata (org.jclouds.blobstore.domain.StorageMetadata)1 ListContainerOptions (org.jclouds.blobstore.options.ListContainerOptions)1