Netty in action study notes (prequel)

Asynchronous design

CallBack

Futures

 

NINE JDK1.4

NIO2 JDK1.7

 

Standard IO: characters and byte-stream oriented data

NIO: based channel (Channel) and buffer (Buffer), facing the buffer

Read operation: channel - Data -> Buffer

Write: Buffer - Data -> Channel

NIO core:

Buffer 

Channel

Selector

 

Buffer memory fragments essentially, Buffer has three attributes: capacity, position, limit

capacity is the capacity in both the write mode, the write mode position and capacity meaning related Buffer

Buffer Write mode :

When default initialization position = 0, position Maximum = capacity-1

The maximum amount of data that can be written to limit capacity = buffer capacity

Buffer read mode :

position = 0, each reading, position rearward movement

limit = position when writing mode

 

Buffer's member variables :

capacity:int

limit:int

mark:int

position:int

Buffer's method:

clear():Buffer

flip():Buffer

Buffer's implementation class :

ByteBuffer,CharBuffer等

 

IO Model:

blocking IO

nonBlocking IO

IO multiplexing

asynchronous IO 

Two objects associated with the network IO: process (OR thread) and kernel

Selector scheduler whether a plurality of nonblocking IO, examine one or more NIO Channel state in the readable, writable.

Selector achieve threaded manage multiple Channels, i.e. managing multiple network connections.

Selector belong case of IO multiplexing

Selector.select () polling Find

 

Channels of four states:

Connect

Accept

Read

Write

SelectionKey corresponding to the four states:

SelectionKey.OP_CONNECT

SelectionKey.OP_ACCEPT

SelectionKey.OP_READ

SelectionKey.OP_WRITE

 

Java IO

Essence character streams: byte stream read + check code table (code table according to the character mapping)

And the node relationship process flow stream: flow packaging process flow nodes, using the decorative design pattern, to eliminate the difference node stream.

 

Encoding and decoding

Coding: plaintext character sequence ----> binary sequence of bytes

Decoding: a binary sequence of bytes ----> plaintext character sequence

 

Netty in:

Encoding: Java objects ----> byte

Decoding: Byte ----> Java Objects

 

A series of bytes of data network. 

 

Common strings and application / x-www-form-urlencoded MIME string

URLDecoder

URLEncoder

Guess you like

Origin www.cnblogs.com/mrray1105/p/10810009.html