-
Netty Core InterfaceNetty 2019. 1. 7. 20:54Channel, ChannelFuture, ChannelHandler, ChannelHandlerContext, ChannelPipeline, EventLoop순서대로 보자- Channel
대충 중요해보이는게 eventLoop(), pipeline(), read() 정도 보인다. ChannelOutboundInvoker는 뭐하는 녀석일까
대충 이런게 있다치고 넘어가자.- ChannelFuture
줄줄이 설명이 잘 되있다; channelFuture는 비동기 I/O 동작의 결과물이라고 한다.
netty는 모든 동작이 비동기이며, 그것은 모든 I/O call이 즉시 이녀석을 리턴한다고 볼 수 있다.(물론 요청의 완료 여부는 보장하지 않는다)
이녀석은 요청이 어떻게 동작하는지 그 상태정보와 결과를 갖고있다. 자세한 내용을 아래에 그림으로 잘 그려놨다--;
- ChannelHandler
I/O 이벤트를 Handle 하거나, I/O Operation을 Intercept 해서 ChannelPipeline에 있는 다음 channelHandler에게 전달한다.
* Handles an I/O event or intercepts an I/O operation, and forwards it to its next handler in
* its {@link ChannelPipeline}.- ChannelHandlerContext
ChannelHandlerContext는 ChannelHandler가 연결되있는 ChannelPipeline과 다른 ChannelHandler와 상호작용 할수있게 해준다.
ChannelPipeline에 연결되어있는 다음 ChannelHandler 에게 notify를 할 수있고, 갖고있는 ChannelPipeline을 동적으로 변경할 수 있다.
* Enables a {@link ChannelHandler} to interact with its {@link ChannelPipeline}
* and other handlers. Among other things a handler can notify the next {@link ChannelHandler} in the
* {@link ChannelPipeline} as well as modify the {@link ChannelPipeline} it belongs to dynamically.Channel이 ChannelOutboundInvoker를 extends 하고있었는데 그녀석이 보인다. ChannelInbountInvoker 라는것도 있나보다
EventLoop가 어쩌고 하는데 일단 패스..
- ChannelPipeline
Channel의 inbound events와 outbound operation을 handle, intercept하는 ChannelHandler들의 리스트이다.
사용자가 event가 어떻게 handle되는지, 어떻게 pipeline안에서 ChannelHandler들이 어떻게 상호작용하는지 제어할수 있도록 하기위해 Intercepting Filter 패턴을 사용했다.
* A list of {@link ChannelHandler}s which handles or intercepts inbound events and outbound operations of a
* {@link Channel}. {@link ChannelPipeline} implements an advanced form of the
* <a href="http://www.oracle.com/technetwork/java/interceptingfilter-142169.html">Intercepting Filter</a> pattern
* to give a user full control over how an event is handled and how the {@link ChannelHandler}s in a pipeline
* interact with each other.참고 : https://www.oracle.com/technetwork/java/interceptingfilter-142169.html
채널마다 고유한 pipeline을 가지고있고, pipeline은 새로운 채널이 만들어 질 때 자동으로 생성된다.
아래 그림은 ChannelPipeline안에서 ChannelHandler들이 I/O event를 어떻게 처리하는지 나타낸다.
I/O event는 ChannelInbountHandler/ChannelOutboundHandler에 의해 핸들되고, ChannelHandlerContext의 이벤트 전파 메서드 (fireChannelRead나 write함수) 호출로 가장 가까운 ChannelHandler로 보내진다.
그림으로 보아 Outbound는 write를, Inbound는 read를 담당한다.
- EventLoop
등록된 채널의 모든 I/O operation들을 핸들한다.
하나의 eventLoop 인스턴스는 하나 이상의 채널로부터 이벤트를 핸들할 수 있는데 내부 구현에 따라 다르다.
이벤트 루프 종류도 많은듯 하다. 구현체는 NioEventLoopGroup을 주로 사용한다고 한다.
http://hatemogi.github.io/netty-startup/#34
참고 : https://netty.io/4.1/api/index.html
주로 사용한다고 한 녀석, MultithreadEventLoopGroup을 기억하자.
EventLoop, EventLoopGroup 어느쪽이든 EventExecutorGroup을 상속하고있는데 뭐하는 녀석인지 보자.
EventExecutor를 제공하는 녀석이다. 추가로 EventExecutor들의 like-cycle과 종료를 담당한다.
/**
* The {@link EventExecutorGroup} is responsible for providing the {@link EventExecutor}'s to use
* via its {@link #next()} method. Besides this, it is also responsible for handling their
* life-cycle and allows shutting them down in a global fashion.
*
*/public interface EventExecutorGroup extends ScheduledExecutorService, Iterable<EventExecutor> {
...
}
일단 피곤해서 이까지
'Netty' 카테고리의 다른 글
ccc (0) 2019.01.13 Netty Bootstrap (0) 2019.01.09