/** * Enables OP_READ if it has never been enabled before. * * @throws IOException */ protected void enableInitialOpRead() throws IOException { if (isInitialReadRequired) { // isInitialReadRequired will be disabled inside enableIOEvent(IOEvent.READ); } }
@Override public boolean canWrite(final Connection<SocketAddress> connection) { final NIOConnection nioConnection = (NIOConnection) connection; final int connectionMaxPendingBytes = nioConnection.getMaxAsyncWriteQueueSize(); if (connectionMaxPendingBytes < 0) { return true; } final TaskQueue<AsyncWriteQueueRecord> connectionQueue = (nioConnection).getAsyncWriteQueue(); final int size = connectionQueue.spaceInBytes(); return size == 0 || size < connectionMaxPendingBytes; }
@Override public void addCloseListener(CloseListener closeListener) { addCloseListener((org.glassfish.grizzly.CloseListener) closeListener); }
protected void configureNIOConnection(NIOConnection connection) { connection.configureBlocking(isBlocking); connection.configureStandalone(isStandalone); connection.setProcessor(processor); connection.setProcessorSelector(processorSelector); connection.setReadTimeout(readTimeout, TimeUnit.MILLISECONDS); connection.setWriteTimeout(writeTimeout, TimeUnit.MILLISECONDS); if (connectionMonitoringConfig.hasProbes()) { connection.setMonitoringProbes(connectionMonitoringConfig.getProbes()); } }
private static int getLastSelectedKeysCount(final Connection c) { return ((NIOConnection) c).getSelectorRunner().getLastSelectedKeysCount(); }
@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); } } }
/** * {@inheritDoc} */ @Override public void onClose(final Connection connection) { final NIOConnection nioConnection = (NIOConnection) connection; final TaskQueue<AsyncWriteQueueRecord> writeQueue = nioConnection.getAsyncWriteQueue(); writeQueue.onClose(nioConnection.getCloseReason().getCause()); }
protected final void checkEmptyRead(final int size) { if (WIN32) { if (size == 0) { final short count = ++zeroByteReadCount; if (count >= MAX_ZERO_READ_COUNT) { closeSilently(); } } else { zeroByteReadCount = 0; } } }
/** * {@inheritDoc} * @deprecated please use {@link #close()} with the following {@link * GrizzlyFuture#addCompletionHandler(org.glassfish.grizzly.CompletionHandler)} call */ @Override public void close(final CompletionHandler<Closeable> completionHandler) { closeGracefully0(completionHandler, CloseReason.LOCALLY_CLOSED_REASON); }
public void attachToSelectorRunner(final SelectorRunner selectorRunner) throws IOException { detachSelectorRunner(); final SelectorHandler selectorHandler = transport.getSelectorHandler(); final FutureImpl<RegisterChannelResult> future = Futures.createSafeFuture(); selectorHandler.registerChannelAsync( selectorRunner, channel, 0, this, Futures.toCompletionHandler(future)); try { final RegisterChannelResult result = future.get(readTimeoutMillis, TimeUnit.MILLISECONDS); this.selectorRunner = selectorRunner; this.selectionKey = result.getSelectionKey(); } catch (InterruptedException | TimeoutException e) { throw new IOException("", e); } catch (ExecutionException e) { throw new IOException("", e.getCause()); } }
@Override public void notifyWritePossible(final Connection<SocketAddress> connection, final WriteHandler writeHandler) { ((NIOConnection) connection).getAsyncWriteQueue() .notifyWritePossible(writeHandler); }
@Override public NextAction handleAccept(final FilterChainContext ctx) throws IOException { final NIOConnection connection = (NIOConnection) ctx.getConnection(); connection.attachToSelectorRunner(distributor.getSelectorRunner()); connection.enableIOEvent(IOEvent.READ); return ctx.getInvokeAction(); } });
protected void configureNIOConnection(NIOConnection connection) { connection.configureBlocking(isBlocking); connection.configureStandalone(isStandalone); connection.setProcessor(processor); connection.setProcessorSelector(processorSelector); connection.setReadTimeout(readTimeout, TimeUnit.MILLISECONDS); connection.setWriteTimeout(writeTimeout, TimeUnit.MILLISECONDS); if (connectionMonitoringConfig.hasProbes()) { connection.setMonitoringProbes(connectionMonitoringConfig.getProbes()); } }
private static int getLastSelectedKeysCount(final Connection c) { return ((NIOConnection) c).getSelectorRunner().getLastSelectedKeysCount(); }
@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); } } }
/** * {@inheritDoc} */ @Override public void onClose(final Connection connection) { final NIOConnection nioConnection = (NIOConnection) connection; final TaskQueue<AsyncWriteQueueRecord> writeQueue = nioConnection.getAsyncWriteQueue(); writeQueue.onClose(nioConnection.getCloseReason().getCause()); }
protected final void checkEmptyRead(final int size) { if (WIN32) { if (size == 0) { final short count = ++zeroByteReadCount; if (count >= MAX_ZERO_READ_COUNT) { closeSilently(); } } else { zeroByteReadCount = 0; } } }
/** * {@inheritDoc} * @deprecated please use {@link #close()} with the following {@link * GrizzlyFuture#addCompletionHandler(org.glassfish.grizzly.CompletionHandler)} call */ @Override public void close(final CompletionHandler<Closeable> completionHandler) { closeGracefully0(completionHandler, CloseReason.LOCALLY_CLOSED_REASON); }
public void attachToSelectorRunner(final SelectorRunner selectorRunner) throws IOException { detachSelectorRunner(); final SelectorHandler selectorHandler = transport.getSelectorHandler(); final FutureImpl<RegisterChannelResult> future = Futures.createSafeFuture(); selectorHandler.registerChannelAsync( selectorRunner, channel, 0, this, Futures.toCompletionHandler(future)); try { final RegisterChannelResult result = future.get(readTimeoutMillis, TimeUnit.MILLISECONDS); this.selectorRunner = selectorRunner; this.selectionKey = result.getSelectionKey(); } catch (InterruptedException | TimeoutException e) { throw new IOException("", e); } catch (ExecutionException e) { throw new IOException("", e.getCause()); } }
/** * {@inheritDoc} */ @Override public final boolean isReady(final Connection connection) { final TaskQueue connectionQueue = ((NIOConnection) connection).getAsyncWriteQueue(); return connectionQueue != null && !connectionQueue.isEmpty(); }