Netty in Action
Norman Maurer and Marvin Allen Wolfthal
  • MEAP began March 2013
  • Publication in August 2015 (estimated)
  • ISBN 9781617291470
  • 300 pages (estimated)
  • printed in black & white

Netty in Action introduces the Netty framework and shows you how to incorporate it into your Java network applications. You'll learn to write highly-scalable applications without the need to dive into the low-level non-blocking APIs at the core of Java. You'll learn how to think in an asynchronous way as you work through numerous hands-on examples. You'll follow numerous examples that show you how to use Netty while you master the best practices of large-scale network apps.

Table of Contents show full

Part 1 NETTY CONCEPTS AND ARCHITECTURE

1. Netty—Asynchronous and Event-Driven

1.1. Networking in Java

1.2. Introducing Netty

1.2.1. Who Uses Netty?

1.2.2. Asynchronous and Event-Driven

1.3. Core Components

1.3.1. Channels

1.3.2. Callbacks

1.3.3. Futures

1.3.4. Events and Handlers

1.3.5. Putting it All Together

1.4. Summary

2. Your first Netty application

2.1. Setting up the development environment

2.2. Netty client / server overview

2.3. Writing the echo server

2.3.1. ChannelHandlers and business logic

2.3.2. Bootstrapping the server

2.4. Writing an echo client

2.4.1. Implementing the client logic with ChannelHandlers

2.4.2. Bootstrapping the client

2.5. Building and running the Echo Server and Client

2.5.1. Running the build

2.5.2. Running the Echo Server and Client

2.6. Summary

3. Netty Components and Design

3.1. Channel, EventLoop and ChannelFuture

3.1.1. interface EventLoop

3.1.2. interface ChannelFuture

3.2. ChannelHandler and ChannelPipeline

3.2.1. interface ChannelHandler

3.2.2. interface ChannelPipeline

3.2.3. A Closer Look at ChannelHandlers

3.2.4. Encoders and Decoders

3.2.5. abstract class SimpleChannelInboundHandler

3.3. Bootstrapping

3.4. Summary

4. Transports

4.1. Case study: transport migration

4.1.1. Using I/O and NIO without Netty

4.1.2. Using I/O and NIO with Netty

4.1.3. Non-blocking Netty version

4.2. Transport API

4.3. Included transports

4.3.1. NIO - Nonblocking I/O

4.3.2. Epoll - Native Non-blocking Transport for Linux

4.3.3. OIO - Old blocking I/O

4.3.4. Local Transport for Communication within a JVM

4.3.5. Embedded Transport

4.4. Transport Use Cases

4.5. Summary

5. ByteBuf

5.1. Buffer API

5.2. class ByteBuf - Netty’s data container

5.2.1. How it works

5.2.2. ByteBuf Usage Patterns

5.3. Byte-level Operations

5.3.1. Random access indexing

5.3.2. Sequential access indexing

5.3.3. Discardable bytes

5.3.4. Readable bytes

5.3.5. Writable bytes

5.3.6. Index management

5.3.7. Search operations

5.3.8. Derived buffers

5.3.9. Read/write operations

5.3.10. More operations

5.4. interface ByteBufHolder

5.5. ByteBuf allocation

5.5.1. On-demand: interface ByteBufAllocator

5.5.2. Unpooled buffers

5.5.3. class ByteBufUtil

5.6. Reference counting

5.7. Summary

6. ChannelHandler and ChannelPipeline

6.1. The ChannelHandler Family

6.1.1. The Channel Lifecycle

6.1.2. The ChannelHandler Lifecycle

6.1.3. ChannelHandler Subinterfaces

6.1.4. interface ChannelInboundHandler

6.1.5. interface ChannelOutboundHandler

6.1.6. Resource Management

6.2. interface ChannelPipeline

6.2.1. Modifying a ChannelPipeline

6.2.2. Firing events

6.3. interface ChannelHandlerContext

6.3.1. Using ChannelHandler

6.3.2. Advanced usages of ChannelHandler and ChannelHandlerContext

6.4. Exception Handling

6.4.1. Handling Inbound Exceptions

6.4.2. Handling Outbound Exceptions

6.5. Summary

7. EventLoop and Threading Model

7.1. Threading Model

7.2. The EventLoop

7.2.1. I/O and Event Handling in Netty 4

7.2.2. I/O Operations in Netty 3

7.3. Task Scheduling

7.3.1. JDK Scheduling API

7.3.2. Scheduling Tasks using EventLoop

7.4. Implementation Details

7.4.1. Thread Management

7.4.2. EventLoop / Thread Allocation

7.5. Summary

8. Bootstrapping

8.1. Bootstrap classes

8.2. Bootstrapping clients and connectionless protocols

8.2.1. Bootstrapping a client

8.2.2. Channel and EventLoopGroup Compatibility

8.3. Bootstrapping servers

8.3.1. class ServerBootstrap

8.3.2. Bootstrapping a server

8.4. Bootstrapping clients from a Channel

8.5. Adding multiple ChannelHandlers during a bootstrap

8.6. Using Netty ChannelOptions and Attributes

8.7. Bootstrapping DatagramChannels

8.8. Shutdown

8.9. Summary

9. Unit Testing

9.1. Overview

9.2. Testing ChannelHandler

9.2.1. Testing inbound messages

9.2.2. Testing outbound messages

9.3. Testing exception handling

9.4. Summary

Part 2 CODECS

10. The Codec Framework

10.1. What is a Codec?

10.2. Decoders

10.2.1. abstract class ByteToMessageDecoder

10.2.2. class ReplayingDecoder<S>

10.2.3. abstract class MessageToMessageDecoder<I>

10.2.4. class TooLongFrameException

10.3. Encoders

10.3.1. abstract class MessageToByteEncoder<I>

10.3.2. abstract class MessageToMessageEncoder<I>

10.4. Abstract Codec classes

10.4.1. abstract class ByteToMessageCodec<I>

10.4.2. abstract MessageToMessageCodec<INBOUND,OUTBOUND>

10.4.3. class CombinedChannelDuplexHandler<I,O>

10.5. Summary

11. Provided ChannelHandlers and Codecs

11.1. Securing Netty applications with SSL/TLS

11.2. Building Netty HTTP/HTTPS applications

11.2.1. HTTP Decoder, Encoder, and Codec

11.2.2. HTTP message aggregation

11.2.3. HTTP compression

11.2.4. Using HTTPS

11.2.5. WebSocket

11.2.6. SPDY

11.3. Idle Connections and Timeouts

11.4. Decoding delimited and length-based protocols

11.4.1. Delimited protocols

11.4.2. Length-based protocols

11.5. Writing big data

11.6. Serializing data

11.6.1. JDK Serialization

11.6.2. Serialization with JBoss Marshalling

11.6.3. Serialization via ProtoBuf

11.7. Summary

Part 3 NETWORK PROTOCOLS

12. Web Sockets

12.1. The example WebSockets application

12.2. Adding WebSockets support

12.2.1. Handling HTTP requests

12.2.2. Handling WebSocket frames

12.2.3. Initializing the ChannelPipeline

12.2.4. Bootstrapping

12.3. Testing the Application

12.3.1. What about Encryption?

12.4. Summary

13. SPDY

13.1. Background

13.2. A sample SPDY application

13.3. Implementation

13.3.1. Integration with Next Protocol Negotiation

13.3.2. ChannelHandler implementations

13.3.3. Setting up the ChannelPipeline

13.3.4. Wiring things together

13.4. Testing the SpdyServer

13.5. Summary

14. Broadcasting Events with UDP

14.1. UDP Basics

14.2. UDP Broadcast

14.3. The UDP Sample Application

14.4. EventLog POJOs

14.5. Writing the broadcaster

14.6. Writing the monitor

14.7. Running the LogEventBroadcaster and LogEventMonitor

14.8. Summary

Part 4 CASE STUDIES

15. Case Studies, Part 1

15.1. Droplr - Building Mobile Services

15.1.1. How it all started

15.1.2. How Droplr works

15.1.3. Creating a faster upload experience

15.1.4. The Technology Stack

15.1.5. Performance

15.1.6. Summary - Standing on the shoulders of Giants

15.2. Firebase - A Real-Time Data Synchronization Service

15.2.1. The Firebase Architecture

15.2.2. Long Polling

15.2.3. HTTP 1.1 Keep-Alive and Pipelining

15.2.4. Control of SSL handler

15.2.5. Summary

15.3. Urban Airship - Building Mobile Services

15.3.1. Basics of Mobile Messaging

15.3.2. Third-Party Delivery

15.3.3. Binary Protocol Example

15.3.4. Direct to Device Delivery

15.3.5. Netty excels at managing large numbers of concurrent connections

15.3.6. Summary - Beyond the Perimiter of the Firewall

15.4. Summary

16. Case Studies, Part 2

16.1. Netty at Facebook: Nifty and Swift

16.1.1. What is Thrift?

16.1.2. Improving the State of Java Thrift using Netty

16.1.3. Nifty Server Design

16.1.4. Nifty Asynchronous Client Design

16.1.5. Swift: A faster way to build Java Thrift service

16.1.6. Results

16.1.7. Summary

16.2. Netty at Twitter: Finagle

16.2.1. Twitter’s Growing Pains

16.2.2. The birth of Finagle

16.2.3. How Finagle works

16.3. Finagle’s Abstraction

16.3.1. Failure Management

16.3.2. Composing Services

16.4. The Future: Netty

16.4.1. Conclusion

16.5. Summary

Appendix A: Introduction to Maven

A.1. What is Maven?

A.1.1. Installing and Configuring Maven

A.1.2. Basic Maven Concepts

A.2. POM Examples

A.2.1. A Project POM

A.2.2. POM Inheritance and Aggregation

A.3. Maven command-line arguments

A.4. Summary

About the Technology

Network applications must handle events intelligently and efficiently, establishing priorities, resolving conflicts, and managing resources to avoid blocks, dropouts, and the other jams that occur in high-traffic environments. Netty is a Java-based networking framework designed to handle asynchronous network events smoothly so your applications are easy to write and maintain. The framework hides all the boilerplate and low-level code from you, making it possible to keep your business-logic separate and reusable, even in different network transports and protocols. Netty has built-in support for many protocols i.e. HTTP, SPDY, and WebSockets.

What's inside

  • Netty from the ground up
  • Covers Netty 4.x
  • Asynchronous, event-driven programming
  • Implement Services that use WebSockets or SPDY

About the reader

Readers should be comfortable with Java and basic network architecture. No exposure to Netty or asynchronous network programming required.

About the authors

Norman Maurer is one of the core developers of Netty, a member of the Apache Software Foundation and a contributor to many OpenSource Projects over the past years. He's a Senior Software Engineer for Apple, where he works on Netty and other network related things as part of the iCloud Team. Marvin Wolfthal has used Netty for several years, and has employed it most recently in high-performance claims processing applications he has implemented in his role as a Dell Services consultant.


Manning Early Access Program (MEAP) Read chapters as they are written, get the finished eBook as soon as it’s ready, and receive the pBook long before it's in bookstores.
MEAP combo $54.99 pBook + eBook
MEAP eBook $43.99 pdf + ePub + kindle

FREE domestic shipping on three or more pBooks