List of Listings

Chapter 1. Netty—asynchronous and event-driven

Listing 1.1. Blocking I/O example

Listing 1.2. ChannelHandler triggered by a callback

Listing 1.3. Asynchronous connect

Listing 1.4. Callback in action

Chapter 2. Your first Netty application

Listing 2.1. EchoServerHandler

Listing 2.2. EchoServer class

Listing 2.3. ChannelHandler for the client

Listing 2.4. Main class for the client

Listing 2.5. Building the Echo client and server

Listing 2.6. Build artifacts

Listing 2.7. Exception handling in the Echo client

Chapter 4. Transports

Listing 4.1. Blocking networking without Netty

Listing 4.2. Asynchronous networking without Netty

Listing 4.3. Blocking networking with Netty

Listing 4.4. Asynchronous networking with Netty

Listing 4.5. Writing to a Channel

Listing 4.6. Using a Channel from many threads

Chapter 5. ByteBuf

Listing 5.1. Backing array

Listing 5.2. Direct buffer data access

Listing 5.3. Composite buffer pattern using ByteBuffer

Listing 5.4. Composite buffer pattern using CompositeByteBuf

Listing 5.5. Accessing the data in a CompositeByteBuf

Listing 5.6. Access data

Listing 5.7. Read all data

Listing 5.8. Write data

Listing 5.9. Using ByteBufProcessor to find

Listing 5.10. Slice a ByteBuf

Listing 5.11. Copying a ByteBuf

Listing 5.12. get() and set() usage

Listing 5.13. read() and write() operations on the ByteBuf

Listing 5.14. Obtaining a ByteBufAllocator reference

Listing 5.15. Reference counting

Listing 5.16. Release reference-counted object

Chapter 6. ChannelHandler and ChannelPipeline

Listing 6.1. Releasing message resources

Listing 6.2. Using SimpleChannelInboundHandler

Listing 6.3. Consuming and releasing an inbound message

Listing 6.4. Discarding and releasing outbound data

Listing 6.5. Modify the ChannelPipeline

Listing 6.6. Accessing the Channel from a ChannelHandlerContext

Listing 6.7. Accessing the ChannelPipeline from a ChannelHandlerContext

Listing 6.8. Calling ChannelHandlerContext write()

Listing 6.9. Caching a ChannelHandlerContext

Listing 6.10. A sharable ChannelHandler

Listing 6.11. Invalid usage of @Sharable

Listing 6.12. Basic inbound exception handling

Listing 6.13. Adding a ChannelFutureListener to a ChannelFuture

Listing 6.14. Adding a ChannelFutureListener to a ChannelPromise

Chapter 7. EventLoop and threading model

Listing 7.1. Executing tasks in an event loop

Listing 7.2. Scheduling a task with a ScheduledExecutorService

Listing 7.3. Scheduling a task with EventLoop

Listing 7.4. Scheduling a recurring task with EventLoop

Listing 7.5. Canceling a task using ScheduledFuture

Chapter 8. Bootstrapping

Listing 8.1. Bootstrapping a client

Listing 8.2. Compatible EventLoopGroups and Channels

Listing 8.3. Incompatible Channel and EventLoopGroup

Listing 8.4. Bootstrapping a server

Listing 8.5. Bootstrapping a server

Listing 8.6. Bootstrapping and using ChannelInitializer

Listing 8.7. Using attributes

Listing 8.8. Using Bootstrap with DatagramChannel

Listing 8.9. Graceful shutdown

Chapter 9. Unit testing

Listing 9.1. FixedLengthFrameDecoder

Listing 9.2. Testing the FixedLengthFrameDecoder

Listing 9.3. AbsIntegerEncoder

Listing 9.4. Testing the AbsIntegerEncoder

Listing 9.5. FrameChunkDecoder

Listing 9.6. Testing FrameChunkDecoder

Chapter 10. The codec framework

Listing 10.1. Class ToIntegerDecoder extends ByteToMessageDecoder

Listing 10.2. Class ToIntegerDecoder2 extends ReplayingDecoder

Listing 10.3. Class IntegerToStringDecoder

Listing 10.4. TooLongFrameException

Listing 10.5. Class ShortToByteEncoder

Listing 10.6. Class IntegerToStringEncoder

Listing 10.7. Using MessageToMessageCodec

Listing 10.8. Class ByteToCharDecoder

Listing 10.9. Class CharToByteEncoder

Listing 10.10. CombinedChannelDuplexHandler<I,O>

Chapter 11. Provided ChannelHandlers and codecs

Listing 11.1. Adding SSL/TLS support

Listing 11.2. Adding support for HTTP

Listing 11.3. Automatically aggregating HTTP message fragments

Listing 11.4. Automatically compressing HTTP messages

Listing 11.5. Using HTTPS

Listing 11.6. Supporting WebSocket on the server

Listing 11.7. Sending heartbeats

Listing 11.8. Handling line-delimited frames

Listing 11.9. Using a ChannelInitializer as a decoder installer

Listing 11.10. Decoder for the command and the handler

Listing 11.11. Transferring file contents with FileRegion

Listing 11.12. Transferring file contents with ChunkedStream

Listing 11.13. Using JBoss Marshalling

Listing 11.14. Using protobuf

Chapter 12. WebSocket

Listing 12.1. HTTPRequestHandler

Listing 12.2. Handling text frames

Listing 12.3. Initializing the ChannelPipeline

Listing 12.4. Bootstrapping the server

Listing 12.5. Compile and start the ChatServer

Listing 12.6. Adding encryption to the ChannelPipeline

Listing 12.7. Adding encryption to the ChatServer

Listing 12.8. Starting the SecureChatServer

Chapter 13. Broadcasting events with UDP

Listing 13.1. LogEvent message

Listing 13.2. LogEventEncoder

Listing 13.3. LogEventBroadcaster

Listing 13.4. Compile and start the LogEventBroadcaster

Listing 13.5. Compile and start the LogEventBroadcaster

Listing 13.6. LogEventDecoder

Listing 13.7. LogEventHandler

Listing 13.8. LogEventMonitor

Listing 13.9. Compiling and starting the LogEventBroadcaster

Listing 13.10. LogEventMonitor output

Chapter 14. Case studies, part 1

Listing 14.1. Setting up the ChannelPipeline

Listing 14.2. The RequestController

Listing 14.3. Setting up the ChannelPipeline

Listing 14.4. ApnsMessage implementation

Listing 14.5. Setting up the ChannelPipeline

Chapter 15. Case studies, part 2

Listing 15.1. Setting up the ChannelFactory

Listing 15.2. Connecting to a remote host

Listing 15.3. Netty3-based transport

Listing 15.4. Netty-based Listener

Listing 15.5. Bridging Netty and Finagle

Listing 15.6. Composing services via Finagle

Appendix Introduction to Maven

Listing A.1. POM outline

Listing A.2. PluginManagement

Listing A.3. Plugin inheritance

Listing A.4. Standalone pom.xml

Listing A.5. chapter2 directory tree

Listing A.6. Parent and aggregator POM: echo-parent

Listing A.7. Echo-server POM

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset