当前位置:网站首页>Es network layer
Es network layer
2022-07-04 03:32:00 【m0_ thirty-seven million two hundred and ninety-four thousand f】
1 es be based on jdk, nio sdk build rpc The network layer
nio Multiplexing :
SelectableChannel
Selector
libs/nio :
NioSelectorGroup
NioSelector
ChannelFactory
ChannelContext
plugins/transport-nio :
NioGropuFactory
NioTranport

2 NioSelector Handle rpc news
Every nio selector Single threaded processing ready state channel
void singleLoop() {
try {
closePendingChannels();
preSelect();
long nanosUntilNextTask = taskScheduler.nanosUntilNextTask(System.nanoTime());
int ready;
if (nanosUntilNextTask == 0) {
ready = selector.selectNow();
} else {
long millisUntilNextTask = TimeUnit.NANOSECONDS.toMillis(nanosUntilNextTask);
// Only select until the next task needs to be run. Do not select with a value of 0 because
// that blocks without a timeout.
ready = selector.select(Math.min(300, Math.max(millisUntilNextTask, 1)));
}
if (ready > 0) {
Set<SelectionKey> selectionKeys = selector.selectedKeys();
Iterator<SelectionKey> keyIterator = selectionKeys.iterator();
while (keyIterator.hasNext()) {
SelectionKey sk = keyIterator.next();
keyIterator.remove();
if (sk.isValid()) {
try {
processKey(sk);
} catch (CancelledKeyException cke) {
eventHandler.genericChannelException((ChannelContext<?>) sk.attachment(), cke);
}
} else {
eventHandler.genericChannelException((ChannelContext<?>) sk.attachment(), new CancelledKeyException());
}
}
}
handleScheduledTasks(System.nanoTime());
} catch (ClosedSelectorException e) {
if (isOpen()) {
throw e;
}
} catch (IOException e) {
eventHandler.selectorException(e);
} catch (Exception e) {
eventHandler.uncaughtException(e);
}
}
Dealing with monitoring , Read write request
void processKey(SelectionKey selectionKey) {
ChannelContext<?> context = (ChannelContext<?>) selectionKey.attachment();
if (selectionKey.isAcceptable()) {
assert context instanceof ServerChannelContext : "Only server channels can receive accept events";
ServerChannelContext serverChannelContext = (ServerChannelContext) context;
int ops = selectionKey.readyOps();
if ((ops & SelectionKey.OP_ACCEPT) != 0) {
try {
eventHandler.acceptChannel(serverChannelContext);
} catch (IOException e) {
eventHandler.acceptException(serverChannelContext, e);
}
}
} else {
assert context instanceof SocketChannelContext : "Only sockets channels can receive non-accept events";
SocketChannelContext channelContext = (SocketChannelContext) context;
int ops = selectionKey.readyOps();
if ((ops & SelectionKey.OP_CONNECT) != 0) {
attemptConnect(channelContext, true);
}
if (channelContext.isConnectComplete()) {
if (channelContext.selectorShouldClose() == false) {
if ((ops & SelectionKey.OP_WRITE) != 0) {
handleWrite(channelContext);
}
if (channelContext.selectorShouldClose() == false && (ops & SelectionKey.OP_READ) != 0) {
handleRead(channelContext);
}
}
}
eventHandler.postHandling(channelContext);
}
}
边栏推荐
- 2022 attached lifting scaffold worker (special type of construction work) free test questions and attached lifting scaffold worker (special type of construction work) examination papers 2022 attached
- I stepped on a foundation pit today
- Rhcsa day 3
- Which product is better if you want to go abroad to insure Xinguan?
- Is online futures account opening safe and reliable? Which domestic futures company is better?
- 150 ppt! The most complete "fair perception machine learning and data mining" tutorial, Dr. AIST Toshihiro kamishima, Japan
- [untitled]
- Explain AI accelerator in detail: why is this the golden age of AI accelerator?
- Teach you how to optimize SQL
- Day05 錶格
猜你喜欢
![Stm32bug [stlink forced update prompt appears in keilmdk, but it cannot be updated]](/img/ad/b675364fcaf5d874397fd0cbfec11b.jpg)
Stm32bug [stlink forced update prompt appears in keilmdk, but it cannot be updated]

Nbear introduction and use diagram

Don't disagree, this is the most powerful "language" of the Internet

Unity knapsack system (code to center and exchange items)

Teach you how to optimize SQL

基于PHP的轻量企业销售管理系统

Hospital network planning and design document based on GLBP protocol + application form + task statement + opening report + interim examination + literature review + PPT + weekly progress + network to

Package details_ Four access control characters_ Two details of protected

Lichuang EDA learning notes 14: PCB board canvas settings

Consul of distributed service registration discovery and unified configuration management
随机推荐
Command Execution Vulnerability - command execution - vulnerability sites - code injection - vulnerability exploitation - joint execution - bypass (spaces, keyword filtering, variable bypass) - two ex
Www 2022 | taxoenrich: self supervised taxonomy complemented by Structural Semantics
National standard gb28181 protocol platform easygbs fails to start after replacing MySQL database. How to deal with it?
JS object definition
CSP drawing
The difference between MCU serial communication and parallel communication and the understanding of UART
选择排序与冒泡排序模板
Consul of distributed service registration discovery and unified configuration management
1day vulnerability pushback skills practice (3)
Contest3145 - the 37th game of 2021 freshman individual training match_ F: Smallest ball
How to use websocket to realize simple chat function in C #
Stm32bug [the project references devices, files or libraries that are not installed appear in keilmdk]
Tsinghua University product: penalty gradient norm improves generalization of deep learning model
Add token validation in swagger
[database I] database overview, common commands, view the table structure of 'demo data', simple query, condition query, sorting data, data processing function (single row processing function), groupi
Learning video website
Lichuang EDA learning notes 14: PCB board canvas settings
Is it really so difficult to learn redis? Today, a fan will share his personal learning materials!
Fudan released its first review paper on the construction and application of multimodal knowledge atlas, comprehensively describing the existing mmkg technology system and progress
Contest3145 - the 37th game of 2021 freshman individual training match_ J: Eat radish