@Override public Void onCompleted() throws Exception { entityStream.closeQueue(); return null; }
@Override public Void onCompleted() throws Exception { entityStream.closeQueue(); return null; }
@Override public void close() throws IOException { if (closed.compareAndSet(false, true)) { closeQueue(); // we can now safely clear the queue - any blocking read waiting for a buffer // has been resumed by the EOF buffer buffers.clear(); } checkThrowable(); }
@Override public void onFailure(final Response response, final Throwable t) { entityStream.closeQueue(t); // try to complete the future with an exception responseFuture.completeExceptionally(t); if (callbackInvoked.compareAndSet(false, true)) { callback.failure(t); } } });
@Override public void onComplete(final Result result) { entityStream.closeQueue(); callback.response(jerseyResponse.get()); responseFuture.complete(jerseyResponse.get()); }
@Override public void onThrowable(Throwable t) { entityStream.closeQueue(t); if (futureSet.compareAndSet(false, true)) { t = t instanceof IOException ? new ProcessingException(t.getMessage(), t) : t; responseFuture.completeExceptionally(t); } } });
@Override public void close() throws IOException { if (closed.compareAndSet(false, true)) { closeQueue(); // we can now safely clear the queue - any blocking read waiting for a buffer // has been resumed by the EOF buffer buffers.clear(); } checkThrowable(); }
private synchronized void commitToMode() { // return if the mode has already been committed if (mode != Mode.UNDECIDED) { return; } // go asynchronous, if the user has made any move suggesting asynchronous mode if (readListener != null || listenerExecutor != null) { mode = Mode.ASYNCHRONOUS; return; } // go synchronous, if the user has not made any move suggesting asynchronous mode mode = Mode.SYNCHRONOUS; synchronousStream = new ByteBufferInputStream(); // move all buffered data to synchronous stream for (ByteBuffer b : data) { if (b == EOF) { synchronousStream.closeQueue(); } else if (b == ERROR) { synchronousStream.closeQueue(t); } else { try { synchronousStream.put(b); } catch (InterruptedException e) { synchronousStream.closeQueue(e); } } } }
@Override public void onThrowable(Throwable t) { entityStream.closeQueue(t); if (callbackInvoked.compareAndSet(false, true)) { t = t instanceof IOException ? new ProcessingException(t.getMessage(), t) : t; callback.failure(t); } } });
@Override public void onContent(final Response jettyResponse, final ByteBuffer content) { try { // content must be consumed before returning from this method. if (content.hasArray()) { byte[] array = content.array(); byte[] buff = new byte[content.remaining()]; System.arraycopy(array, content.arrayOffset(), buff, 0, content.remaining()); entityStream.put(ByteBuffer.wrap(buff)); } else { byte[] buff = new byte[content.remaining()]; content.get(buff); entityStream.put(ByteBuffer.wrap(buff)); } } catch (final InterruptedException ex) { final ProcessingException pe = new ProcessingException(ex); entityStream.closeQueue(pe); // try to complete the future with an exception responseFuture.completeExceptionally(pe); Thread.currentThread().interrupt(); } }
synchronized void notifyDataAvailable(ByteBuffer availableData) { assertClosedForInput(); if (!availableData.hasRemaining()) { return; } if (mode == Mode.SYNCHRONOUS) { try { synchronousStream.put(availableData); } catch (InterruptedException e) { synchronousStream.closeQueue(e); } return; } data.add(availableData); if (readListener != null && callReadListener) { callDataAvailable(); } }
synchronized void notifyAllDataRead() { assertClosedForInput(); if (stateChangeLister != null) { stateChangeLister.onAllDataRead(); } if (mode == Mode.SYNCHRONOUS) { synchronousStream.closeQueue(); return; } data.add(EOF); if (mode == Mode.ASYNCHRONOUS && callReadListener) { callOnAllDataRead(); } }
synchronized void notifyError(Throwable t) { assertClosedForInput(); if (stateChangeLister != null) { stateChangeLister.onError(t); } closedForInput = true; if (mode == Mode.SYNCHRONOUS) { synchronousStream.closeQueue(t); return; } // we store the error and put a marker in the stream, so that the user can read all data that // were successfully received up to the error. this.t = t; data.add(ERROR); if (mode == Mode.ASYNCHRONOUS && callReadListener) { callOnError(t); } }
@Override public Void onCompleted() throws Exception { entityStream.closeQueue(); return null; }
@Override public Void onCompleted() throws Exception { entityStream.closeQueue(); return null; }
@Override public void close() throws IOException { if (closed.compareAndSet(false, true)) { closeQueue(); // we can now safely clear the queue - any blocking read waiting for a buffer // has been resumed by the EOF buffer buffers.clear(); } checkThrowable(); }
@Override public void onThrowable(Throwable t) { entityStream.closeQueue(t); if (futureSet.compareAndSet(false, true)) { t = t instanceof IOException ? new ProcessingException(t.getMessage(), t) : t; responseFuture.completeExceptionally(t); } } });
@Override public void close() throws IOException { if (closed.compareAndSet(false, true)) { closeQueue(); // we can now safely clear the queue - any blocking read waiting for a buffer // has been resumed by the EOF buffer buffers.clear(); } checkThrowable(); }
@Override public void onFailure(final Response response, final Throwable t) { entityStream.closeQueue(t); // try to complete the future with an exception responseFuture.completeExceptionally(t); if (callbackInvoked.compareAndSet(false, true)) { callback.failure(t); } } });
@Override public void onThrowable(Throwable t) { entityStream.closeQueue(t); if (callbackInvoked.compareAndSet(false, true)) { t = t instanceof IOException ? new ProcessingException(t.getMessage(), t) : t; callback.failure(t); } } });