Search in sources :

Example 1 with BufferInputStream

use of backtype.storm.utils.BufferInputStream in project jstorm by alibaba.

the class NimbusData method mkBlobCacheMap.

public void mkBlobCacheMap() {
    ExpiredCallback<Object, Object> expiredCallback = new ExpiredCallback<Object, Object>() {

        @Override
        public void expire(Object key, Object val) {
            try {
                LOG.debug("Close blob file " + String.valueOf(key));
                if (val != null) {
                    if (val instanceof AtomicOutputStream) {
                        AtomicOutputStream stream = (AtomicOutputStream) val;
                        stream.cancel();
                        stream.close();
                    } else if (val instanceof BufferInputStream) {
                        BufferInputStream is = (BufferInputStream) val;
                        is.close();
                    }
                }
            } catch (IOException e) {
                LOG.error(e.getMessage(), e);
            }
        }
    };
    int expiration_secs = JStormUtils.parseInt(conf.get(Config.NIMBUS_FILE_COPY_EXPIRATION_SECS), 30);
    blobUploaders = new TimeCacheMap<Object, Object>(expiration_secs, expiredCallback);
    blobDownloaders = new TimeCacheMap<Object, Object>(expiration_secs, expiredCallback);
    blobListers = new TimeCacheMap<Object, Object>(expiration_secs, null);
}
Also used : BufferInputStream(backtype.storm.utils.BufferInputStream) ExpiredCallback(com.alibaba.jstorm.utils.ExpiredCallback) AtomicOutputStream(com.alibaba.jstorm.blobstore.AtomicOutputStream) IOException(java.io.IOException)

Example 2 with BufferInputStream

use of backtype.storm.utils.BufferInputStream in project jstorm by alibaba.

the class ServiceHandler method beginBlobDownload.

@Override
public BeginDownloadResult beginBlobDownload(String key) throws TException {
    InputStreamWithMeta is = data.getBlobStore().getBlob(key);
    String sessionId = UUID.randomUUID().toString();
    BeginDownloadResult result = null;
    try {
        result = new BeginDownloadResult(is.getVersion(), sessionId);
        result.set_data_size(is.getFileLength());
        int bufferSize = JStormUtils.parseInt(data.getConf().get(Config.STORM_BLOBSTORE_INPUTSTREAM_BUFFER_SIZE_BYTES), 65536);
        BufferInputStream bufferedIS = new BufferInputStream(is, bufferSize);
        data.getBlobDownloaders().put(sessionId, bufferedIS);
    } catch (IOException e) {
        LOG.error("beginBlobDownload error", e);
        throw new TException(e);
    }
    return result;
}
Also used : BufferInputStream(backtype.storm.utils.BufferInputStream) TException(org.apache.thrift.TException) InputStreamWithMeta(com.alibaba.jstorm.blobstore.InputStreamWithMeta) BeginDownloadResult(backtype.storm.generated.BeginDownloadResult) IOException(java.io.IOException)

Example 3 with BufferInputStream

use of backtype.storm.utils.BufferInputStream in project jstorm by alibaba.

the class ServiceHandler method downloadBlobChunk.

@Override
public ByteBuffer downloadBlobChunk(String session) throws TException {
    BufferInputStream is = (BufferInputStream) data.getBlobDownloaders().get(session);
    if (is == null) {
        throw new TException("Could not find input stream for session " + session);
    }
    try {
        byte[] ret = is.read();
        data.getBlobDownloaders().put(session, is);
        if (ret.length == 0) {
            is.close();
            data.getBlobDownloaders().remove(session);
        }
        LOG.debug("Sending {} bytes", ret.length);
        return ByteBuffer.wrap(ret);
    } catch (IOException e) {
        LOG.error("BufferInputStream read failed when downloadBlobChunk ", e);
        throw new TException(e);
    }
}
Also used : BufferInputStream(backtype.storm.utils.BufferInputStream) TException(org.apache.thrift.TException) IOException(java.io.IOException)

Aggregations

BufferInputStream (backtype.storm.utils.BufferInputStream)3 IOException (java.io.IOException)3 TException (org.apache.thrift.TException)2 BeginDownloadResult (backtype.storm.generated.BeginDownloadResult)1 AtomicOutputStream (com.alibaba.jstorm.blobstore.AtomicOutputStream)1 InputStreamWithMeta (com.alibaba.jstorm.blobstore.InputStreamWithMeta)1 ExpiredCallback (com.alibaba.jstorm.utils.ExpiredCallback)1