public void produceContent(ContentEncoder encoder, IOControl ioctrl) throws IOException { if (out == null) { synchronized (mutex) { out = new SharedOutputBuffer(8192, ioctrl, new HeapByteBufferAllocator()); mutex.notify(); } } while (!encoder.isCompleted()) out.produceContent(encoder); }
public void produceContent(ContentEncoder encoder, IOControl ioctrl) throws IOException { if (out == null) { synchronized (mutex) { out = new SharedOutputBuffer(8192, ioctrl, new HeapByteBufferAllocator()); mutex.notify(); } } while (!encoder.isCompleted()) out.produceContent(encoder); }
public void produceContent(ContentEncoder encoder, IOControl ioctrl) throws IOException { final SharedOutputBuffer ob = new SharedOutputBuffer(8192, ioctrl, new HeapByteBufferAllocator()); new Thread() { public void run() { try { FileInputStream fis = new FileInputStream("/Users/marc/Music/enjoytheride_feat.judytzuke_.mp3"); int nRead; byte[] bytes = new byte[4096]; while ((nRead = fis.read(bytes)) != -1) { synchronized (this) { try { wait(1); } catch (InterruptedException ie) { } } ob.write(bytes, 0, nRead); } ob.writeCompleted(); } catch (IOException e) { e.printStackTrace(); } } }.start(); while (!encoder.isCompleted()) ob.produceContent(encoder); }
public void produceContent(ContentEncoder encoder, IOControl ioctrl) throws IOException { final SharedOutputBuffer ob = new SharedOutputBuffer(8192, ioctrl, new HeapByteBufferAllocator()); new Thread() { public void run() { try { FileInputStream fis = new FileInputStream("/Users/marc/Music/enjoytheride_feat.judytzuke_.mp3"); int nRead; byte[] bytes = new byte[4096]; while ((nRead = fis.read(bytes)) != -1) { synchronized (this) { try { wait(1); } catch (InterruptedException ie) { } } ob.write(bytes, 0, nRead); } ob.writeCompleted(); } catch (IOException e) { e.printStackTrace(); } } }.start(); while (!encoder.isCompleted()) ob.produceContent(encoder); }
@Override public void produceContent( final ContentEncoder encoder, final IOControl ioctrl) throws IOException { if (this.producer != null) { this.producer.produceContent(encoder, ioctrl); if (encoder.isCompleted()) { this.producer.close(); } } }
@Override public void produceContent( final ContentEncoder encoder, final IOControl ioctrl) throws IOException { if (this.producer != null) { this.producer.produceContent(encoder, ioctrl); if (encoder.isCompleted()) { this.producer.close(); } } }
@Override public void produceContent( final ContentEncoder encoder, final IOControl ioctrl) throws IOException { if (this.producer != null) { this.producer.produceContent(encoder, ioctrl); if (encoder.isCompleted()) { this.producer.close(); } } }
@Override public void produceContent( final ContentEncoder encoder, final IOControl ioctrl) throws IOException { if (this.producer != null) { this.producer.produceContent(encoder, ioctrl); if (encoder.isCompleted()) { this.producer.close(); } } }
public void produceContent(ContentEncoder encoder, IOControl ioctrl) throws IOException { if (out == null) { synchronized (mutex) { out = new SharedOutputBuffer(8192, ioctrl, new HeapByteBufferAllocator()); mutex.notify(); } } while (!encoder.isCompleted()) out.produceContent(encoder); }
bytesWritten = encoder.write(this.buffer); if (encoder.isCompleted()) { this.endOfStream = true; if (this.endOfStream && !encoder.isCompleted()) { encoder.complete();
public void produceContent(ContentEncoder encoder, IOControl ioctrl) throws IOException { final SharedOutputBuffer ob = new SharedOutputBuffer(8192, ioctrl, new HeapByteBufferAllocator()); new Thread() { public void run() { try { FileInputStream fis = new FileInputStream("/Users/marc/Music/enjoytheride_feat.judytzuke_.mp3"); int nRead; byte[] bytes = new byte[4096]; while ((nRead = fis.read(bytes)) != -1) { synchronized (this) { try { wait(1); } catch (InterruptedException ie) { } } ob.write(bytes, 0, nRead); } ob.writeCompleted(); } catch (IOException e) { e.printStackTrace(); } } }.start(); while (!encoder.isCompleted()) ob.produceContent(encoder); }
/** * Consume the data from the pipe and write it to the wire. * * @param conn the connection to the target * @param encoder encoder for writing the message through * @throws java.io.IOException if an error occurs * @return number of bytes written */ public int write(NHttpClientConnection conn, ContentEncoder encoder) throws IOException { int bytes = 0; if (pipe != null) { bytes = pipe.consume(encoder); } if (encoder.isCompleted()) { conn.getContext().setAttribute(PassThroughConstants.REQ_DEPARTURE_TIME, System.currentTimeMillis()); conn.getContext().setAttribute(PassThroughConstants.REQ_TO_BACKEND_WRITE_END_TIME,System.currentTimeMillis()); targetConfiguration.getMetrics(). notifySentMessageSize(conn.getMetrics().getSentBytesCount()); TargetContext.updateState(conn, ProtocolState.REQUEST_DONE); } return bytes; }
@Override public void outputReady( final NHttpClientConnection conn, final ContentEncoder encoder) throws IOException, HttpException { final State state = getState(conn); Asserts.notNull(state, "Connection state"); Asserts.check(state.getRequestState() == MessageState.BODY_STREAM || state.getRequestState() == MessageState.ACK_EXPECTED, "Unexpected request state %s", state.getRequestState()); final HttpAsyncClientExchangeHandler handler = getHandler(conn); Asserts.notNull(handler, "Client exchange handler"); if (state.getRequestState() == MessageState.ACK_EXPECTED) { conn.suspendOutput(); return; } handler.produceContent(encoder, conn); if (encoder.isCompleted()) { handler.requestCompleted(); final boolean pipelined = handler.getClass().getAnnotation(Pipelined.class) != null; state.setRequestState(pipelined ? MessageState.READY : MessageState.COMPLETED); } }
@Override public void outputReady( final NHttpClientConnection conn, final ContentEncoder encoder) throws IOException, HttpException { final State state = getState(conn); Asserts.notNull(state, "Connection state"); Asserts.check(state.getRequestState() == MessageState.BODY_STREAM || state.getRequestState() == MessageState.ACK_EXPECTED, "Unexpected request state %s", state.getRequestState()); final HttpAsyncClientExchangeHandler handler = getHandler(conn); Asserts.notNull(handler, "Client exchange handler"); if (state.getRequestState() == MessageState.ACK_EXPECTED) { conn.suspendOutput(); return; } handler.produceContent(encoder, conn); if (encoder.isCompleted()) { handler.requestCompleted(); final boolean pipelined = handler.getClass().getAnnotation(Pipelined.class) != null; state.setRequestState(pipelined ? MessageState.READY : MessageState.COMPLETED); } }
public void outputReady(final NHttpServerConnection conn, final ContentEncoder encoder) { HttpContext context = conn.getContext(); HttpResponse response = conn.getHttpResponse(); ServerConnState connState = (ServerConnState) context.getAttribute(CONN_STATE); ContentOutputBuffer buffer = connState.getOutbuffer(); // Update connection state connState.setOutputState(ServerConnState.RESPONSE_BODY_STREAM); try { buffer.produceContent(encoder); if (encoder.isCompleted()) { connState.setOutputState(ServerConnState.RESPONSE_BODY_DONE); connState.resetOutput(); if (!this.connStrategy.keepAlive(response, context)) { conn.close(); } else { conn.requestInput(); } } } catch (IOException ex) { shutdownConnection(conn, ex); if (this.eventListener != null) { this.eventListener.fatalIOException(ex, conn); } } }
@Override public void outputReady( final NHttpServerConnection conn, final ContentEncoder encoder) throws HttpException, IOException { final State state = getState(conn); Asserts.notNull(state, "Connection state"); Asserts.check(state.getResponseState() == MessageState.BODY_STREAM, "Unexpected response state %s", state.getResponseState()); final Outgoing outgoing = state.getOutgoing(); Asserts.notNull(outgoing, "Outgoing response"); final HttpAsyncResponseProducer responseProducer = outgoing.getProducer(); responseProducer.produceContent(encoder, conn); if (encoder.isCompleted()) { completeResponse(outgoing, conn, state); } }
@Override public void outputReady( final NHttpServerConnection conn, final ContentEncoder encoder) throws HttpException, IOException { final State state = getState(conn); Asserts.notNull(state, "Connection state"); Asserts.check(state.getResponseState() == MessageState.BODY_STREAM, "Unexpected response state %s", state.getResponseState()); final Outgoing outgoing = state.getOutgoing(); Asserts.notNull(outgoing, "Outgoing response"); final HttpAsyncResponseProducer responseProducer = outgoing.getProducer(); responseProducer.produceContent(encoder, conn); if (encoder.isCompleted()) { completeResponse(outgoing, conn, state); } }
if (this.contentEncoder.isCompleted()) { resetOutput();
if (this.contentEncoder.isCompleted()) { resetOutput();
if (encoder.isCompleted()) { SourceContext.updateState(conn, ProtocolState.RESPONSE_DONE);