Refine search
private void readInbound() { RecvByteBufAllocator.Handle handle = unsafe().recvBufAllocHandle(); handle.reset(config()); ChannelPipeline pipeline = pipeline(); do { Object received = inboundBuffer.poll(); if (received == null) { break; } pipeline.fireChannelRead(received); } while (handle.continueReading()); pipeline.fireChannelReadComplete(); }
/** * A factory method for {@link LocalChannel}s. Users may override it * to create custom instances of {@link LocalChannel}s. */ protected LocalChannel newLocalChannel(LocalChannel peer) { return new LocalChannel(this, peer); }
@Override protected void doBeginRead() throws Exception { if (readInProgress) { return; } Queue<Object> inboundBuffer = this.inboundBuffer; if (inboundBuffer.isEmpty()) { readInProgress = true; return; } final InternalThreadLocalMap threadLocals = InternalThreadLocalMap.get(); final Integer stackDepth = threadLocals.localChannelReaderStackDepth(); if (stackDepth < MAX_READER_STACK_DEPTH) { threadLocals.setLocalChannelReaderStackDepth(stackDepth + 1); try { readInbound(); } finally { threadLocals.setLocalChannelReaderStackDepth(stackDepth); } } else { try { eventLoop().execute(readTask); } catch (Throwable cause) { logger.warn("Closing Local channels {}-{} because exception occurred!", this, peer, cause); close(); peer.close(); PlatformDependent.throwException(cause); } } }
private void finishPeerRead(final LocalChannel peer) { // If the peer is also writing, then we must schedule the event on the event loop to preserve read order. if (peer.eventLoop() == eventLoop() && !peer.writeInProgress) { finishPeerRead0(peer); } else { runFinishPeerReadTask(peer); } }
private void runFinishPeerReadTask(final LocalChannel peer) { // If the peer is writing, we must wait until after reads are completed for that peer before we can read. So // we keep track of the task, and coordinate later that our read can't happen until the peer is done. final Runnable finishPeerReadTask = new Runnable() { @Override public void run() { finishPeerRead0(peer); } }; try { if (peer.writeInProgress) { peer.finishReadFuture = peer.eventLoop().submit(finishPeerReadTask); } else { peer.eventLoop().execute(finishPeerReadTask); } } catch (Throwable cause) { logger.warn("Closing Local channels {}-{} because exception occurred!", this, peer, cause); close(); peer.close(); PlatformDependent.throwException(cause); } }
peer.inboundBuffer.add(ReferenceCountUtil.retain(msg)); in.remove(); } else { finishPeerRead(peer);
private void releaseInboundBuffers() { assert eventLoop() == null || eventLoop().inEventLoop(); readInProgress = false; Queue<Object> inboundBuffer = this.inboundBuffer; Object msg; while ((msg = inboundBuffer.poll()) != null) { ReferenceCountUtil.release(msg); } }
ChannelPipeline pipeline = pipeline(); Queue<Object> inboundBuffer = this.inboundBuffer; if (inboundBuffer.isEmpty()) { readInProgress = true; return; try { for (;;) { Object received = inboundBuffer.poll(); if (received == null) { break; pipeline.fireChannelRead(received); pipeline.fireChannelReadComplete(); } finally { threadLocals.setLocalChannelReaderStackDepth(stackDepth); eventLoop().execute(readTask); } catch (Throwable cause) { logger.warn("Closing Local channels {}-{} because exception occurred!", this, peer, cause); close(); peer.close(); PlatformDependent.throwException(cause);
@Override public void run() { ChannelPipeline pipeline = pipeline(); for (;;) { Object m = inboundBuffer.poll(); if (m == null) { break; } pipeline.fireChannelRead(m); } pipeline.fireChannelReadComplete(); } };
@Test public void failOutstandingStreamCallbackOnException() throws Exception { Channel c = new LocalChannel(); c.pipeline().addLast(TransportFrameDecoder.HANDLER_NAME, new TransportFrameDecoder()); TransportResponseHandler handler = new TransportResponseHandler(c); StreamCallback cb = mock(StreamCallback.class); handler.addStreamCallback("stream-1", cb); handler.exceptionCaught(new IOException("Oops!")); verify(cb).onFailure(eq("stream-1"), isA(IOException.class)); } }
if (parent() == null) { LocalChannelRegistry.unregister(localAddress); finishPeerRead(peer); EventLoop peerEventLoop = peer.eventLoop(); final boolean peerIsActive = peer.isActive(); try { peerEventLoop.execute(new Runnable() { @Override public void run() { logger.warn("Releasing Inbound Queues for channels {}-{} because exception occurred!", this, peer, cause); if (peerEventLoop.inEventLoop()) { peer.releaseInboundBuffers(); } else { peer.close(); releaseInboundBuffers();
if (peer != null && parent() != null) { state = State.CONNECTED; peer.remoteAddress = parent() == null ? null : parent().localAddress(); peer.state = State.CONNECTED; peer.eventLoop().execute(new Runnable() { @Override public void run() { ((SingleThreadEventExecutor) eventLoop()).addShutdownHook(shutdownHook);
Exception cause = new AlreadyConnectedException(); safeSetFailure(promise, cause); pipeline().fireExceptionCaught(cause); return; doBind(localAddress); } catch (Throwable t) { safeSetFailure(promise, t);
@Override public void run() { ChannelPromise promise = peer.connectPromise; // Only trigger fireChannelActive() if the promise was not null and was not completed yet. // connectPromise may be set to null if doClose() was called in the meantime. if (promise != null && promise.trySuccess()) { peer.pipeline().fireChannelActive(); } } });
protected LocalChannel(LocalServerChannel parent, LocalChannel peer) { super(parent); config().setAllocator(new PreferHeapByteBufAllocator(config.getAllocator())); this.peer = peer; localAddress = parent.localAddress(); remoteAddress = peer.localAddress(); }
public LocalChannel() { super(null); config().setAllocator(new PreferHeapByteBufAllocator(config.getAllocator())); }
@Override protected void doDisconnect() throws Exception { doClose(); }
@Override protected void doDeregister() throws Exception { // Just remove the shutdownHook as this Channel may be closed later or registered to another EventLoop ((SingleThreadEventExecutor) eventLoop()).removeShutdownHook(shutdownHook); }
/** * remove remote channel related all local sessions * * @param remoteChannel * remote channel identifier */ public void removeAll(UscRemoteChannelIdentifier remoteChannel) { UscRouteIdentifier routeId = null; for (Entry<UscRouteIdentifier, LocalChannel> entry : sessionMap.entrySet()) { routeId = entry.getKey(); if (remoteChannel.equals(routeId)) { entry.getValue().close(); sessionMap.remove(routeId); } } } }