这个就是通过selector把之前注册的事件取出来,从而完成了调用。
- //9.类: NioEndPoint内部类 Poller implements Runnable
- protected void processKey(SelectionKey sk, NioSocketWrapper socketWrapper) {
- //省略大部分代码
- processSocket(socketWrapper, SocketEvent.OPEN_WRITE, true)
-
- }
-
- //10.类:AbstractEndPoint
- public boolean processSocket(SocketWrapperBase<S> socketWrapper,
- SocketEvent event, boolean dispatch) {
- //省略部分代码
- Executor executor = getExecutor();
- if (dispatch && executor != null) {
- executor.execute(sc);
- } else {
- sc.run();
- }
-
- return true;
- }
- //11.类:SocketProcessorBase implements Runnable
- public final void run() {
- synchronized (socketWrapper) {
- // It is possible that processing may be triggered for read and
- // write at the same time. The sync above makes sure that processing
- // does not occur in parallel. The test below ensures that if the
- // first event to be processed results in the socket being closed,
- // the subsequent events are not processed.
- if (socketWrapper.isClosed()) {
- return;
- }
- doRun();
- }
- }
-
- //类:12.NioEndPoint extends AbstractJsseEndpoint<NioChannel,SocketChannel>
- protected void doRun() {
- //省略部分代码
- if (handshake == 0) {
- SocketState state = SocketState.OPEN;
- // Process the request from this socket
- if (event == null) {
- state = getHandler().process(socketWrapper, SocketEvent.OPEN_READ);
- } else {
- state = getHandler().process(socketWrapper, event);
- }
- if (state == SocketState.CLOSED) {
- poller.cancelledKey(key, socketWrapper);
- }
- }
- }
-
(编辑:西安站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|