RecyclableArrayList futures = RecyclableArrayList.newInstance(msgs.length); try { for (Object m: msgs) { break; futures.add(write(m)); int size = futures.size(); for (int i = 0; i < size; i++) { ChannelFuture future = (ChannelFuture) futures.get(i); if (future.isDone()) { recordException(future); return isNotEmpty(outboundMessages); } finally { futures.recycle();
@Override protected RecyclableArrayList newObject(Handle<RecyclableArrayList> handle) { return new RecyclableArrayList(handle); } };
@Override public boolean addAll(int index, Collection<?> c) { checkNullElements(c); if (super.addAll(index, c)) { insertSinceRecycled = true; return true; } return false; }
@Override public void handlerRemoved(ChannelHandlerContext ctx) throws Exception { /*On shut down, all the handlers are removed from the pipeline, so we don't need to explicitly remove the additional handlers added in handlerAdded()*/ currentState = State.Stopped; if (null != buffer) { if (!buffer.isEmpty()) { for (Object item : buffer) { ReferenceCountUtil.release(item); } } buffer.recycle(); buffer = null; } }
RecyclableArrayList array = RecyclableArrayList.newInstance(buffers.length); try { Component c = findComponent(index); throw new UnsupportedOperationException(); case 1: array.add(s.nioBuffer(index - adjustment, localLength)); break; default: return array.toArray(new ByteBuffer[0]); } finally { array.recycle();
public void sendMessages(ChannelHandlerContext ctx, RecyclableArrayList messages) { Channel channel = ctx.channel(); channel.eventLoop().execute(() -> { int i = 0; while (channel.isActive() && channel.isWritable() && i < messages.size()) { for (int j = 0; j < 5 && i < messages.size(); j++, i++) { ctx.write(messages.get(i), ctx.voidPromise()); } ctx.flush(); } if (i < messages.size()) { messages.subList(0, i).clear(); storeMessages(ctx.name(), messages); } else { messages.recycle(); } }); }
/** * Create a new empty {@link RecyclableArrayList} instance */ public static RecyclableArrayList newInstance() { return newInstance(DEFAULT_INITIAL_CAPACITY); }
final ZMTPWireFormat wireFormat = ZMTPWireFormats.wireFormat(version); final ZMTPWireFormat.Header header = wireFormat.header(); final RecyclableArrayList frames = RecyclableArrayList.newInstance(); while (true) { final boolean read = header.read(in); if (!read) { frames.recycle(); in.readerIndex(mark); return null; frames.recycle(); in.readerIndex(mark); return null; frames.add(frame); if (!header.more()) { @SuppressWarnings("unchecked") final ZMTPMessage message = ZMTPMessage.from((List<ByteBuf>) (Object) frames); frames.recycle(); return message;
@SuppressWarnings("fallthrough") @Override public final void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (State.Stopped != currentState && !shouldReadMore(ctx)) { currentState = State.Buffering; } switch (currentState) { case ReadRequested: currentState = State.Reading; case Reading: newMessage(ctx, msg); break; case Buffering: case DrainingBuffer: if (null == buffer) { buffer = RecyclableArrayList.newInstance(); } buffer.add(msg); break; case Stopped: logger.warn("Message read after handler removed, discarding the same. Message class: " + msg.getClass().getName()); ReferenceCountUtil.release(msg); break; } }
private void recycleBuffer() { buffer.recycle(); currentBufferIndex = 0; buffer = null; }
/** * Clear and recycle this instance. */ public boolean recycle() { clear(); insertSinceRecycled = false; handle.recycle(this); return true; } }
/** * Create a new empty {@link RecyclableArrayList} instance with the given capacity. */ public static RecyclableArrayList newInstance(int minCapacity) { RecyclableArrayList ret = RECYCLER.get(); ret.ensureCapacity(minCapacity); return ret; }
RecyclableArrayList buffers = RecyclableArrayList.newInstance(componentCount); try { int i = toComponentIndex0(index); throw new UnsupportedOperationException(); case 1: buffers.add(s.nioBuffer(c.idx(index), localLength)); break; default: return buffers.toArray(new ByteBuffer[0]); } finally { buffers.recycle();
/** * Create a new empty {@link RecyclableArrayList} instance */ public static RecyclableArrayList newInstance() { return newInstance(DEFAULT_INITIAL_CAPACITY); }
/** * Clear and recycle this instance. */ public boolean recycle() { clear(); insertSinceRecycled = false; handle.recycle(this); return true; } }
/** * Create a new empty {@link RecyclableArrayList} instance with the given capacity. */ public static RecyclableArrayList newInstance(int minCapacity) { RecyclableArrayList ret = RECYCLER.get(); ret.ensureCapacity(minCapacity); return ret; }
RecyclableArrayList futures = RecyclableArrayList.newInstance(msgs.length); try { for (Object m: msgs) { break; futures.add(write(m)); int size = futures.size(); for (int i = 0; i < size; i++) { ChannelFuture future = (ChannelFuture) futures.get(i); if (future.isDone()) { recordException(future); return isNotEmpty(outboundMessages); } finally { futures.recycle();
RecyclableArrayList array = RecyclableArrayList.newInstance(buffers.length); try { Component c = findComponent(index); throw new UnsupportedOperationException(); case 1: array.add(s.nioBuffer(index - adjustment, localLength)); break; default: return array.toArray(new ByteBuffer[0]); } finally { array.recycle();
/** * Create a new empty {@link RecyclableArrayList} instance */ public static RecyclableArrayList newInstance() { return newInstance(DEFAULT_INITIAL_CAPACITY); }