public MessageOutputStream(OutgoingFrames outgoing, int bufferSize, ByteBufferPool bufferPool) { this.outgoing = outgoing; this.bufferPool = bufferPool; this.blocker = new BlockingWriteCallback(); this.buffer = bufferPool.acquire(bufferSize, true); BufferUtil.flipToFill(buffer); this.frame = new BinaryFrame(); }
public WriteBlocker acquireWriteBlocker() throws IOException { return new WriteBlocker(acquire()); }
private void blockingWrite(WebSocketFrame frame) throws IOException { try(WriteBlocker b=blocker.acquireWriteBlocker()) { uncheckedSendFrame(frame, b); b.block(); } }
@Override public void flush() throws IOException { lockMsg(MsgType.ASYNC); try (WriteBlocker b = blocker.acquireWriteBlocker()) { uncheckedSendFrame(FrameFlusher.FLUSH_FRAME, b); b.block(); } finally { unlockMsg(MsgType.ASYNC); } }
public MessageWriter(OutgoingFrames outgoing, int bufferSize, ByteBufferPool bufferPool) { this.outgoing = outgoing; this.bufferPool = bufferPool; this.blocker = new BlockingWriteCallback(); this.buffer = bufferPool.acquire(bufferSize, true); BufferUtil.flipToFill(buffer); this.frame = new TextFrame(); this.utf = Utf8CharBuffer.wrap(buffer); }
private void flush(boolean fin) throws IOException { synchronized (this) { if (closed) throw new IOException("Stream is closed"); closed = fin; BufferUtil.flipToFlush(buffer, 0); frame.setPayload(buffer); frame.setFin(fin); try(WriteBlocker b=blocker.acquireWriteBlocker()) { outgoing.outgoingFrame(frame, b, BatchMode.OFF); b.block(); } ++frameCount; // Any flush after the first will be a CONTINUATION frame. frame.setIsContinuation(); BufferUtil.flipToFill(buffer); } }
private void flush(boolean fin) throws IOException { synchronized (this) { if (closed) throw new IOException("Stream is closed"); closed = fin; ByteBuffer data = utf.getByteBuffer(); if (LOG.isDebugEnabled()) LOG.debug("flush({}): {}", fin, BufferUtil.toDetailString(buffer)); frame.setPayload(data); frame.setFin(fin); try (WriteBlocker b = blocker.acquireWriteBlocker()) { outgoing.outgoingFrame(frame, b, BatchMode.OFF); b.block(); } ++frameCount; // Any flush after the first will be a CONTINUATION frame. frame.setIsContinuation(); utf.clear(); } }