@Override public void add(BufferOrEvent boe) { bytesBlocked += pageSize; currentBuffers.add(boe); }
/** * Add a buffer to the end of the queue and associate a listener with it that should be completed when * all the buffers bytes have been consumed from the queue and written. * @param buf to add to the tail of the queue * @param listener to notify when all the bytes have been consumed and written, can be {@code null}. */ public final void add(ByteBuf buf, ChannelFutureListener listener) { // buffers are added before promises so that we naturally 'consume' the entire buffer during removal // before we complete it's promise. bufAndListenerPairs.add(buf); if (listener != null) { bufAndListenerPairs.add(listener); } incrementReadableBytes(buf.readableBytes()); }
synchronized boolean pong(ByteString payload) { // Don't send pongs after we've failed or sent the close frame. if (failed || (enqueuedClose && messageAndCloseQueue.isEmpty())) return false; pongQueue.add(payload); runWriter(); return true; }
@Override public synchronized void onReadPing(ByteString payload) { // Don't respond to pings after we've failed or sent the close frame. if (failed || (enqueuedClose && messageAndCloseQueue.isEmpty())) return; pongQueue.add(payload); runWriter(); receivedPingCount++; }
public DefaultBlockingPool( Supplier<T> generator, int limit ) { this.objects = new ArrayDeque<>(limit); this.maxSize = limit; for (int i = 0; i < limit; i++) { objects.add(generator.get()); } this.lock = new ReentrantLock(); this.notEnough = lock.newCondition(); }
/** * Add a buffer to the end of the queue and associate a listener with it that should be completed when * all the buffers bytes have been consumed from the queue and written. * @param buf to add to the tail of the queue * @param listener to notify when all the bytes have been consumed and written, can be {@code null}. */ public final void add(ByteBuf buf, ChannelFutureListener listener) { // buffers are added before promises so that we naturally 'consume' the entire buffer during removal // before we complete it's promise. bufAndListenerPairs.add(buf); if (listener != null) { bufAndListenerPairs.add(listener); } incrementReadableBytes(buf.readableBytes()); }
@Override public void put(Bitmap bitmap) { numPuts++; bitmaps.add(bitmap); }
synchronized boolean pong(ByteString payload) { // Don't send pongs after we've failed or sent the close frame. if (failed || (enqueuedClose && messageAndCloseQueue.isEmpty())) return false; pongQueue.add(payload); runWriter(); return true; }
@Override public synchronized void onReadPing(ByteString payload) { // Don't respond to pings after we've failed or sent the close frame. if (failed || (enqueuedClose && messageAndCloseQueue.isEmpty())) return; pongQueue.add(payload); runWriter(); pingCount++; }
public CeaDecoder() { availableInputBuffers = new ArrayDeque<>(); for (int i = 0; i < NUM_INPUT_BUFFERS; i++) { availableInputBuffers.add(new CeaInputBuffer()); } availableOutputBuffers = new ArrayDeque<>(); for (int i = 0; i < NUM_OUTPUT_BUFFERS; i++) { availableOutputBuffers.add(new CeaOutputBuffer()); } queuedInputBuffers = new PriorityQueue<>(); }
private void releaseInputBuffer(CeaInputBuffer inputBuffer) { inputBuffer.clear(); availableInputBuffers.add(inputBuffer); }
protected void releaseOutputBuffer(SubtitleOutputBuffer outputBuffer) { outputBuffer.clear(); availableOutputBuffers.add(outputBuffer); }
@Override public synchronized void onReadPing(ByteString payload) { // Don't respond to pings after we've failed or sent the close frame. if (failed || (enqueuedClose && messageAndCloseQueue.isEmpty())) return; pongQueue.add(payload); runWriter(); receivedPingCount++; }
synchronized boolean pong(ByteString payload) { // Don't send pongs after we've failed or sent the close frame. if (failed || (enqueuedClose && messageAndCloseQueue.isEmpty())) return false; pongQueue.add(payload); runWriter(); return true; }
@Override public HttpConnection ping(Buffer data, Handler<AsyncResult<Buffer>> pongHandler) { if (data.length() != 8) { throw new IllegalArgumentException("Ping data must be exactly 8 bytes"); } handler.writePing(data.getLong(0)).addListener(fut -> { if (fut.isSuccess()) { synchronized (Http2ConnectionBase.this) { pongHandlers.add(pongHandler); } } else { pongHandler.handle(Future.failedFuture(fut.cause())); } }); return this; }
synchronized boolean close(int code, String reason, long cancelAfterCloseMillis) { validateCloseCode(code); ByteString reasonBytes = null; if (reason != null) { reasonBytes = ByteString.encodeUtf8(reason); if (reasonBytes.size() > CLOSE_MESSAGE_MAX) { throw new IllegalArgumentException("reason.size() > " + CLOSE_MESSAGE_MAX + ": " + reason); } } if (failed || enqueuedClose) return false; // Immediately prevent further frames from being enqueued. enqueuedClose = true; // Enqueue the close frame. messageAndCloseQueue.add(new Close(code, reasonBytes, cancelAfterCloseMillis)); runWriter(); return true; }
private synchronized boolean send(ByteString data, int formatOpcode) { // Don't send new frames after we've failed or enqueued a close frame. if (failed || enqueuedClose) return false; // If this frame overflows the buffer, reject it and close the web socket. if (queueSize + data.size() > MAX_QUEUE_SIZE) { close(CLOSE_CLIENT_GOING_AWAY, null); return false; } // Enqueue the message frame. queueSize += data.size(); messageAndCloseQueue.add(new Message(formatOpcode, data)); runWriter(); return true; }
synchronized boolean close(int code, String reason, long cancelAfterCloseMillis) { validateCloseCode(code); ByteString reasonBytes = null; if (reason != null) { reasonBytes = ByteString.encodeUtf8(reason); if (reasonBytes.size() > CLOSE_MESSAGE_MAX) { throw new IllegalArgumentException("reason.size() > " + CLOSE_MESSAGE_MAX + ": " + reason); } } if (failed || enqueuedClose) return false; // Immediately prevent further frames from being enqueued. enqueuedClose = true; // Enqueue the close frame. messageAndCloseQueue.add(new Close(code, reasonBytes, cancelAfterCloseMillis)); runWriter(); return true; }
@Override public void startSequence() throws ASN1Exception { readTag(SEQUENCE_TYPE); int length = readLength(); states.add(new DecoderState(SEQUENCE_TYPE, bi.getIndex() + length)); }
private synchronized boolean send(ByteString data, int formatOpcode) { // Don't send new frames after we've failed or enqueued a close frame. if (failed || enqueuedClose) return false; // If this frame overflows the buffer, reject it and close the web socket. if (queueSize + data.size() > MAX_QUEUE_SIZE) { close(CLOSE_CLIENT_GOING_AWAY, null); return false; } // Enqueue the message frame. queueSize += data.size(); messageAndCloseQueue.add(new Message(formatOpcode, data)); runWriter(); return true; }