Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Its look like, you are trying to implement a new asynchronous transport, so it will be worth to have a look on <a href="https://github.com/netty/netty/tree/4.1/transport/src/main/java/io/netty/channel/socket/nio" rel="nofollow noreferrer">NIO TCP transport</a> (other than <em>Datagram</em> classes).</p> <p>I am not sure how relevant it is, but it will help to understand how to write a new transport service for Netty (since you have asked about Server, Client Channels, Factories, and all) </p> <p>It will be easier If you can understand the Netty event model and how goes through the pipeline. This is my understanding about how it works.</p> <ul> <li><p>Upstream events (event from network) starts from <code>Channel</code>/<code>ServerChannel</code>, Boss/NioWorker and send through the pipeline until it reaches the last handler.</p></li> <li><p>Downstream events starts from last downstream handler and send through the pipeline and sinks at <code>ChannelSink</code>, channel sink process the events and take action or put the messages on channel's queues.</p></li> </ul> <p>In more details, (I assume, some one is looking on Nio TCP transport classes to write their custom transport for Netty).</p> <p><strong>NioWorker</strong> - On selector events for the channels (all NioClientSocketChannel, NioAcceptedSocketChannel), runs the nio loop - Data received from network: fire message received - Poll write queue and does non blocking write - Poll task queue for interested op events and take suspend/resume the channel?.</p> <p><strong>Boss</strong></p> <ul> <li>Runs Server NIO event loop.</li> <li>Accept client socket, creates a <code>NioAcceptedSocketChannel</code>, and register selectors for NioWorker </li> </ul> <p><strong>NioClientSocketPipelineSink</strong></p> <ul> <li>Has a worker thread pool executor.</li> <li>Submit NioWorker runnables to worker thread pool at constructor.</li> <li>Client channel downstream events sinks here and put to channels write queue/task queue, intercept some upstream state events and manages the state of the channel.</li> </ul> <p><strong>NioServerSocketPipelineSink</strong></p> <ul> <li>Has boss thread pool.</li> <li>Submit Nio worker runnables to executor at creation.</li> <li>Submit boss runnable with ServerSocketChannel to executor on bind event.</li> <li>Server channel downstream events sinks here, intercept some upstream state events and manages ServerSocketChannel state.</li> </ul> <blockquote> <p>How should my implementation respond to "InterestOps"-type stuff?</p> </blockquote> <p>It depends on the nature of the channel (blocking/non blocking) and constrains.</p> <blockquote> <p>Is ServerChannel.write what is called for messages that come all the way down the stack? What's up with the two different overloads?</p> </blockquote> <p>Server channel has no need to support those method calls, I think you are referring to Channel's</p> <pre><code>ChannelFuture write(Object message); ChannelFuture write(Object message, SocketAddress remoteAddress); </code></pre> <p>These methods are there for connectionless transport. For TCP, both are actually doing the same thing. </p> <blockquote> <p>How do I need to implement ServerChannel.(dis)connect?</p> </blockquote> <p>Server channel doesn't need to support those method calls, but you should implement, <code>bind</code> and <code>unbind</code> here.</p> <blockquote> <p>Should I still do all of this stuff through <code>ServerBootstrap</code>, or is that too high-level for this stuff?</p> </blockquote> <p>Server/client bootstraps are just helper classes to manage pipeline resources and provide a facade to bind, connect &amp; disconnect. You have to implement most of the logic in</p> <p>Client, Server Channel Impls<br> Client, Server Pipeline sinks<br> Boss, Worker classes,</p> <p>Then you have to implement client &amp; server channel factories using above classes, if these things are done, you can simply setup you server &amp; client using Bootstrap classes.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload