Hi,

We are using JClouds on a server-side application.
That is, it is supposed to be long-lived, compared to a end-user application 
that could be closed after several minutes/hours of use.

    public byte[] getFile(String basePath, String containerName, String 
blobPath) {
        log.debug("load File in basePath: {}, containerName: {}, blobPath:{}", 
basePath, containerName, basePath);

        Properties properties = new java.util.Properties();
properties.setProperty(FilesystemConstants.PROPERTY_BASEDIR, basePath);

        BlobStoreContext context = 
ContextBuilder.newBuilder("filesystem").overrides(properties)
            .buildView(BlobStoreContext.class);

        BlobStore blobStore = context.getBlobStore();

        byte[] bFile = new byte[0];
        Blob blob = blobStore.getBlob(containerName, blobPath);

        if (null != blob) {
            log.debug("Blob headers : {}", blob.getAllHeaders());
            log.debug("Blob metadata : {}", blob.getMetadata());

            try {
                bFile = IOUtils.toByteArray(blob.getPayload().openStream());
            } catch (IOException e) {
                log.warn("Error reading file to input stream.", e);
            }
        } else {
            log.warn("Blob at {}/{} does not exist.", containerName, blobPath);
        }

        context.close();

        return bFile;
    }


The base directory is global for the whole application.
I wonder if the context and the blobstore should then be stored in a singleton a retrieved when needed, instead of being instantiated every time ?
(thus saving few milliseconds of works).

How long a context should remain open ?
How often should it be closed ?

Also, when using putBlob(), is the payload flushed directly or when the context 
is closed ?

Thanks,
Ionel
--
TECH'advantage SA - 1 rue Isabey 92500 RUEIL MALMAISON
Capital  EUR 219 300,00 - RCS Nanterre B 408 832 301 - TVA FR 09 408 832 301 
00027

Reply via email to