SPCoast
Railroading on the Southern Pacific Coast

NBD Netty

From SPCoast

Jump to: navigation, search

Full maven project source code: NBD implemented with Netty (gzip'd tar file) Apache Open Source License.

(See also: NBD implemented with Apache Mina)

Starting at the top, the Server simply parses command line arguments, instantiates the protocol stack and binds it to a port. I used the params Map to pass the command line arguments to the session handler.


Next comes the business logic in the Handler - get READ and WRITE commands from the Linux Kernel via a TCP/IP socket and actually read and write blocks from a file. The "file" could be a real disk drive or it could be a file created just for that reason: % dd if=/dev/zero of=somefile bs=1M count=1000


The Request and Response objects are POJOs - plain old Java Objects that mimic the Linux "C" structs...


and



After all this, the actual encoder and decoder are pretty simple:


and