@SuppressWarnings("deprecation") @Override public void finishBlobUpload(String session) throws AuthorizationException, TException { try { OutputStream os = blobUploaders.get(session); if (os == null) { throw new RuntimeException("Blob for session " + session + " does not exist (or timed out)"); } os.close(); LOG.info("Finished uploading blob for session {}. Closing session.", session); blobUploaders.remove(session); } catch (Exception e) { LOG.warn("finish blob upload exception.", e); if (e instanceof TException) { throw (TException) e; } throw new RuntimeException(e); } }
@SuppressWarnings("deprecation") @Override public void cancelBlobUpload(String session) throws AuthorizationException, TException { try { AtomicOutputStream os = (AtomicOutputStream) blobUploaders.get(session); if (os == null) { throw new RuntimeException("Blob for session " + session + " does not exist (or timed out)"); } os.cancel(); LOG.info("Canceled uploading blob for session {}. Closing session.", session); blobUploaders.remove(session); } catch (Exception e) { LOG.warn("finish blob upload exception.", e); if (e instanceof TException) { throw (TException) e; } throw new RuntimeException(e); } }
@SuppressWarnings("deprecation") @Override public void finishFileUpload(String location) throws AuthorizationException, TException { try { finishFileUploadCalls.mark(); checkAuthorization(null, null, "fileUpload"); WritableByteChannel channel = uploaders.get(location); if (channel == null) { throw new RuntimeException("File for that location does not exist (or timed out)"); } channel.close(); LOG.info("Finished uploading file from client: {}", location); uploaders.remove(location); } catch (Exception e) { LOG.warn("finish file upload exception.", e); if (e instanceof TException) { throw (TException) e; } throw new RuntimeException(e); } }
@SuppressWarnings("deprecation") @Override public ByteBuffer downloadChunk(String id) throws AuthorizationException, TException { try { downloadChunkCalls.mark(); checkAuthorization(null, null, "fileDownload"); BufferInputStream is = downloaders.get(id); if (is == null) { throw new RuntimeException("Could not find input stream for id " + id); } byte[] ret = is.read(); if (ret.length == 0) { is.close(); downloaders.remove(id); } return ByteBuffer.wrap(ret); } catch (Exception e) { LOG.warn("download chunk exception.", e); if (e instanceof TException) { throw (TException) e; } throw new RuntimeException(e); } }
@SuppressWarnings("deprecation") @Override public ByteBuffer downloadBlobChunk(String session) throws AuthorizationException, TException { try { BufferInputStream is = blobDownloaders.get(session); if (is == null) { throw new RuntimeException("Blob for session " + session + " does not exist (or timed out)"); } byte[] ret = is.read(); if (ret.length == 0) { is.close(); blobDownloaders.remove(session); } else { blobDownloaders.put(session, is); } LOG.debug("Sending {} bytes", ret.length); return ByteBuffer.wrap(ret); } catch (Exception e) { LOG.warn("download blob chunk exception.", e); if (e instanceof TException) { throw (TException) e; } throw new RuntimeException(e); } }
blobListers.remove(session); LOG.info("No more blobs to list for session {}", session);
@Override public void execute(Tuple tuple) { List<Object> id = tuple.select(_idFields); GlobalStreamId streamId = new GlobalStreamId(tuple.getSourceComponent(), tuple.getSourceStreamId()); if (!_pending.containsKey(id)) { _pending.put(id, new HashMap<GlobalStreamId, Tuple>()); } Map<GlobalStreamId, Tuple> parts = _pending.get(id); if (parts.containsKey(streamId)) { throw new RuntimeException("Received same side of single join twice"); } parts.put(streamId, tuple); if (parts.size() == _numSources) { _pending.remove(id); List<Object> joinResult = new ArrayList<Object>(); for (String outField : _outFields) { GlobalStreamId loc = _fieldLocations.get(outField); joinResult.add(parts.get(loc).getValueByField(outField)); } _collector.emit(new ArrayList<Tuple>(parts.values()), joinResult); for (Tuple part : parts.values()) { _collector.ack(part); } } }
@Override public void execute(Tuple tuple) { List<Object> id = tuple.select(_idFields); GlobalStreamId streamId = new GlobalStreamId(tuple.getSourceComponent(), tuple.getSourceStreamId()); if (!_pending.containsKey(id)) { _pending.put(id, new HashMap<GlobalStreamId, Tuple>()); } Map<GlobalStreamId, Tuple> parts = _pending.get(id); if (parts.containsKey(streamId)) throw new RuntimeException("Received same side of single join twice"); parts.put(streamId, tuple); if (parts.size() == _numSources) { _pending.remove(id); List<Object> joinResult = new ArrayList<Object>(); for (String outField : _outFields) { GlobalStreamId loc = _fieldLocations.get(outField); joinResult.add(parts.get(loc).getValueByField(outField)); } _collector.emit(new ArrayList<Tuple>(parts.values()), joinResult); for (Tuple part : parts.values()) { _collector.ack(part); } } }