/** * The maximum size, in bytes, of all data waiting to be written to the associated {@link Connection}. * If the value is zero or less, then no resource enforcement will take place. * * @param maxPendingBytes the maximum size, in bytes, of all data waiting to be written to the associated {@link * Connection}. */ public void setMaxPendingBytes(int maxPendingBytes) { this.maxPendingBytes = maxPendingBytes; transport.getAsyncQueueIO().getWriter().setMaxPendingBytesPerConnection(maxPendingBytes); }
@Override public Object call() throws Exception { byte[] originalMessage = new byte[packetSize]; Arrays.fill(originalMessage, b); Buffer buffer = Buffers.wrap(mm, originalMessage); asyncQueueWriter.write(con, buffer, completionHandler); return null; } });
@Override protected void closeConnection(final Connection connection) throws IOException { final SelectableChannel nioChannel = ((NIOConnection) connection).getChannel(); if (nioChannel != null) { try { nioChannel.close(); } catch (IOException e) { LOGGER.log(Level.FINE, "TCPNIOTransport.closeChannel exception", e); } } if (asyncQueueIO != null) { final AsyncQueueReader reader = asyncQueueIO.getReader(); if (reader != null) { reader.onClose(connection); } final AsyncQueueWriter writer = asyncQueueIO.getWriter(); if (writer != null) { writer.onClose(connection); } } }
asyncQueueWriter.setMaxPendingBytesPerConnection(256000 * 10); System.out.println( "Max Space: " + asyncQueueWriter.getMaxPendingBytesPerConnection()); Buffer buffer = Buffers.wrap(mm, originalMessage); try { if (asyncQueueWriter.canWrite(con)) { asyncQueueWriter.write(con, buffer); } while (asyncQueueWriter.canWrite(con)); // fill the buffer System.out.println("Notified in " + result + "ms"); assertTrue(tqueue.spaceInBytes() < asyncQueueWriter.getMaxPendingBytesPerConnection()); System.out.println("Queue Space: " + tqueue.spaceInBytes());
protected final void resetProperties() { if (channel != null) { setReadBufferSize(transport.getReadBufferSize()); setWriteBufferSize(transport.getWriteBufferSize()); final int transportMaxAsyncWriteQueueSize = transport.getAsyncQueueIO() .getWriter().getMaxPendingBytesPerConnection(); setMaxAsyncWriteQueueSize( transportMaxAsyncWriteQueueSize == AsyncQueueWriter.AUTO_SIZE ? getWriteBufferSize() * 4 : transportMaxAsyncWriteQueueSize); localSocketAddressHolder = Holder.lazyHolder( new NullaryFunction<SocketAddress>() { @Override public SocketAddress evaluate() { return ((DatagramChannel) channel).socket().getLocalSocketAddress(); } }); peerSocketAddressHolder = Holder.lazyHolder( new NullaryFunction<SocketAddress>() { @Override public SocketAddress evaluate() { return ((DatagramChannel) channel).socket().getRemoteSocketAddress(); } }); } }
/** * This method should never be called, because * {@link StandaloneProcessor#isInterested(IOEvent)} returns false for any * {@link IOEvent}. */ @Override public ProcessorResult process(final Context context) { final IOEvent iOEvent = context.getIoEvent(); if (iOEvent == IOEvent.READ) { final Connection connection = context.getConnection(); final AsyncQueueReader reader = ((AsyncQueueEnabledTransport) connection.getTransport()). getAsyncQueueIO().getReader(); return reader.processAsync(context).toProcessorResult(); } else if (iOEvent == IOEvent.WRITE) { final Connection connection = context.getConnection(); final AsyncQueueWriter writer = ((AsyncQueueEnabledTransport) connection.getTransport()). getAsyncQueueIO().getWriter(); return writer.processAsync(context).toProcessorResult(); } throw new IllegalStateException("Unexpected IOEvent=" + iOEvent); }
/** * Configures <tt>NIOTransport</tt> to be optimized for specific for the * connection multiplexing usecase, when different threads will try to * write data simultaneously. */ public void setOptimizedForMultiplexing(final boolean optimizedForMultiplexing) { this.optimizedForMultiplexing = optimizedForMultiplexing; getAsyncQueueIO().getWriter().setAllowDirectWrite(!optimizedForMultiplexing); }
protected final void resetProperties() { if (channel != null) { setReadBufferSize(transport.getReadBufferSize()); setWriteBufferSize(transport.getWriteBufferSize()); final int transportMaxAsyncWriteQueueSize = transport.getAsyncQueueIO() .getWriter().getMaxPendingBytesPerConnection(); setMaxAsyncWriteQueueSize( transportMaxAsyncWriteQueueSize == AsyncQueueWriter.AUTO_SIZE ? getWriteBufferSize() * 4 : transportMaxAsyncWriteQueueSize); localSocketAddressHolder = Holder.lazyHolder( new NullaryFunction<SocketAddress>() { @Override public SocketAddress evaluate() { return ((DatagramChannel) channel).socket().getLocalSocketAddress(); } }); peerSocketAddressHolder = Holder.lazyHolder( new NullaryFunction<SocketAddress>() { @Override public SocketAddress evaluate() { return ((DatagramChannel) channel).socket().getRemoteSocketAddress(); } }); } }
/** * This method should never be called, because * {@link StandaloneProcessor#isInterested(IOEvent)} returns false for any * {@link IOEvent}. */ @Override public ProcessorResult process(final Context context) { final IOEvent iOEvent = context.getIoEvent(); if (iOEvent == IOEvent.READ) { final Connection connection = context.getConnection(); final AsyncQueueReader reader = ((AsyncQueueEnabledTransport) connection.getTransport()). getAsyncQueueIO().getReader(); return reader.processAsync(context).toProcessorResult(); } else if (iOEvent == IOEvent.WRITE) { final Connection connection = context.getConnection(); final AsyncQueueWriter writer = ((AsyncQueueEnabledTransport) connection.getTransport()). getAsyncQueueIO().getWriter(); return writer.processAsync(context).toProcessorResult(); } throw new IllegalStateException("Unexpected IOEvent=" + iOEvent); }
/** * Configures <tt>NIOTransport</tt> to be optimized for specific for the * connection multiplexing usecase, when different threads will try to * write data simultaneously. */ public void setOptimizedForMultiplexing(final boolean optimizedForMultiplexing) { this.optimizedForMultiplexing = optimizedForMultiplexing; getAsyncQueueIO().getWriter().setAllowDirectWrite(!optimizedForMultiplexing); }
/** * The maximum size, in bytes, of all data waiting to be written to the associated {@link Connection}. * If the value is zero or less, then no resource enforcement will take place. * * @param maxPendingBytes the maximum size, in bytes, of all data waiting to be written to the associated {@link * Connection}. */ public void setMaxPendingBytes(int maxPendingBytes) { this.maxPendingBytes = maxPendingBytes; transport.getAsyncQueueIO().getWriter().setMaxPendingBytesPerConnection(maxPendingBytes); }
protected final void resetProperties() { if (channel != null) { setReadBufferSize(transport.getReadBufferSize()); setWriteBufferSize(transport.getWriteBufferSize()); final int transportMaxAsyncWriteQueueSize = transport.getAsyncQueueIO() .getWriter().getMaxPendingBytesPerConnection(); setMaxAsyncWriteQueueSize( transportMaxAsyncWriteQueueSize == AsyncQueueWriter.AUTO_SIZE ? getWriteBufferSize() * 4 : transportMaxAsyncWriteQueueSize); localSocketAddressHolder = Holder.lazyHolder( new NullaryFunction<SocketAddress>() { @Override public SocketAddress evaluate() { return ((DatagramChannel) channel).socket().getLocalSocketAddress(); } }); peerSocketAddressHolder = Holder.lazyHolder( new NullaryFunction<SocketAddress>() { @Override public SocketAddress evaluate() { return ((DatagramChannel) channel).socket().getRemoteSocketAddress(); } }); } }
@Override public void completed( WriteResult<WritableMessage, SocketAddress> result) { final int packetNum = packetCounter.incrementAndGet(); if (packetNum <= reentrantsToTest) { final int reentrantNum = reentrantsCounter.get() + 1; try { reentrantsCounter.set(reentrantNum); if (reentrantNum > maxReentrantsNoticed.get()) { maxReentrantsNoticed.set(reentrantNum); } Buffer bufferInner = Buffers.wrap(mm, "" + ((char) ('A' + packetNum))); asyncQueueWriter.write(con, bufferInner, this); } finally { reentrantsCounter.set(reentrantNum - 1); } } else { resultFuture.result(Boolean.TRUE); } }
@Override protected void closeConnection(final Connection connection) throws IOException { final SelectableChannel nioChannel = ((NIOConnection) connection).getChannel(); if (nioChannel != null) { try { nioChannel.close(); } catch (IOException e) { LOGGER.log(Level.FINE, "TCPNIOTransport.closeChannel exception", e); } } if (asyncQueueIO != null) { final AsyncQueueReader reader = asyncQueueIO.getReader(); if (reader != null) { reader.onClose(connection); } final AsyncQueueWriter writer = asyncQueueIO.getWriter(); if (writer != null) { writer.onClose(connection); } } }
/** * This method should never be called, because * {@link StandaloneProcessor#isInterested(IOEvent)} returns false for any * {@link IOEvent}. */ @Override public ProcessorResult process(final Context context) { final IOEvent iOEvent = context.getIoEvent(); if (iOEvent == IOEvent.READ) { final Connection connection = context.getConnection(); final AsyncQueueReader reader = ((AsyncQueueEnabledTransport) connection.getTransport()). getAsyncQueueIO().getReader(); return reader.processAsync(context).toProcessorResult(); } else if (iOEvent == IOEvent.WRITE) { final Connection connection = context.getConnection(); final AsyncQueueWriter writer = ((AsyncQueueEnabledTransport) connection.getTransport()). getAsyncQueueIO().getWriter(); return writer.processAsync(context).toProcessorResult(); } throw new IllegalStateException("Unexpected IOEvent=" + iOEvent); }
/** * Configures <tt>NIOTransport</tt> to be optimized for specific for the * connection multiplexing usecase, when different threads will try to * write data simultaneously. */ public void setOptimizedForMultiplexing(final boolean optimizedForMultiplexing) { this.optimizedForMultiplexing = optimizedForMultiplexing; getAsyncQueueIO().getWriter().setAllowDirectWrite(!optimizedForMultiplexing); }
/** * The maximum size, in bytes, of all data waiting to be written to the associated {@link Connection}. * If the value is zero or less, then no resource enforcement will take place. * * @param maxPendingBytes the maximum size, in bytes, of all data waiting to be written to the associated {@link * Connection}. */ public void setMaxPendingBytes(int maxPendingBytes) { this.maxPendingBytes = maxPendingBytes; transport.getAsyncQueueIO().getWriter().setMaxPendingBytesPerConnection(maxPendingBytes); }
protected void resetProperties() { if (channel != null) { setReadBufferSize(transport.getReadBufferSize()); setWriteBufferSize(transport.getWriteBufferSize()); final int transportMaxAsyncWriteQueueSize = ((TCPNIOTransport) transport).getAsyncQueueIO() .getWriter().getMaxPendingBytesPerConnection(); setMaxAsyncWriteQueueSize( transportMaxAsyncWriteQueueSize == AsyncQueueWriter.AUTO_SIZE ? getWriteBufferSize() * 4 : transportMaxAsyncWriteQueueSize); localSocketAddressHolder = Holder.lazyHolder( new NullaryFunction<SocketAddress>() { @Override public SocketAddress evaluate() { return ((SocketChannel) channel).socket().getLocalSocketAddress(); } }); peerSocketAddressHolder = Holder.lazyHolder( new NullaryFunction<SocketAddress>() { @Override public SocketAddress evaluate() { return ((SocketChannel) channel).socket().getRemoteSocketAddress(); } }); } }
@Override @SuppressWarnings("unchecked") public NextAction handleWrite(final FilterChainContext ctx) throws IOException { final WritableMessage message = ctx.getMessage(); if (message != null) { ctx.setMessage(null); final Connection connection = ctx.getConnection(); final FilterChainContext.TransportContext transportContext = ctx.getTransportContext(); final CompletionHandler completionHandler = transportContext.getCompletionHandler(); final MessageCloner cloner = transportContext.getMessageCloner(); transportContext.setCompletionHandler(null); transportContext.setMessageCloner(null); if (!transportContext.isBlocking()) { transport.getAsyncQueueIO().getWriter().write(connection, null, message, completionHandler, cloner); } else { transport.getTemporarySelectorIO().getWriter().write(connection, null, message, completionHandler); } } return ctx.getInvokeAction(); }
@Override protected void closeConnection(final Connection connection) throws IOException { final SelectableChannel nioChannel = ((NIOConnection) connection).getChannel(); if (nioChannel != null) { try { nioChannel.close(); } catch (IOException e) { LOGGER.log(Level.FINE, "TCPNIOTransport.closeChannel exception", e); } } if (asyncQueueIO != null) { final AsyncQueueReader reader = asyncQueueIO.getReader(); if (reader != null) { reader.onClose(connection); } final AsyncQueueWriter writer = asyncQueueIO.getWriter(); if (writer != null) { writer.onClose(connection); } } }