Streams
如果看过之前的文章,我相信大家对Stream应该很了解了。
Stream分为两大类:readStream 和 writeStream。
ReadStream
实现的子类:HttpClientResponse, DatagramSocket, HttpClientRequest, HttpServerFileUpload, HttpServerRequest, HttpServerRequestStream, MessageConsumer, NetSocket, NetSocketStream, WebSocket, WebSocketStream, TimeoutStream, AsyncFile
功能:
- handler: set a handler which will receive items from the ReadStream.
- pause: pause the handler. When paused no items will be received in the handler.
- resume: resume the handler. The handler will be called if any item arrives.
- exceptionHandler: Will be called if an exception occurs on the ReadStream.
- endHandler: Will be called when end of stream is reached. This might be when EOF is reached if the ReadStream represents a file, or when end of request is reached if it’s an HTTP request, or when the connection is closed if it’s a TCP socket.
WriteStream
实现的子类:HttpClientRequest, HttpServerResponse WebSocket, NetSocket, AsyncFile, PacketWritestream and MessageProducer
功能:
write: write an object to the WriteStream. This method will never block. Writes are queued internally and asynchronously written to the underlying resource.
setWriteQueueMaxSize: set the number of object at which the write queue is considered full, and the method writeQueueFull returns true. Note that, when the write queue is considered full, if write is called the data will still be accepted and queued. The actual number depends on the stream implementation, for Buffer the size represents the actual number of bytes written and not the number of buffers.
writeQueueFull: returns true if the write queue is considered full.
exceptionHandler: Will be called if an exception occurs on the WriteStream.
drainHandler: The handler will be called if the WriteStream is considered no longer full.
Pump
泵
有如下方法:
start: Start the pump.
stop: Stops the pump. When the pump starts it is in stopped mode.
setWriteQueueMaxSize: This has the same meaning as setWriteQueueMaxSize on the WriteStream.
A pump can be started and stopped multiple times.
泵可以被开始和停止很多次。
When a pump is first created it is not started. You need to call the start() method to start it.
当一个泵第一次被创建时,它还没有开始工作,直到你调用start()。