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);
}
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;
}
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);
}
}
Aggregations