Last active
June 12, 2019 06:25
-
-
Save yangl/a9b54fe41fc66a323661e801de6b059d to your computer and use it in GitHub Desktop.
Netty Epoll的LT、ET模式使用场景,详见注释。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Set the {@link EpollMode} used. Default is | |
* {@link EpollMode#EDGE_TRIGGERED}. If you want to use {@link #isAutoRead()} {@code false} or | |
* {@link #getMaxMessagesPerRead()} and have an accurate behaviour you should use | |
* {@link EpollMode#LEVEL_TRIGGERED}. | |
* | |
* <strong>Be aware this config setting can only be adjusted before the channel was registered.</strong> | |
*/ | |
public EpollChannelConfig setEpollMode(EpollMode mode) { | |
if (mode == null) { | |
throw new NullPointerException("mode"); | |
} | |
try { | |
switch (mode) { | |
case EDGE_TRIGGERED: | |
checkChannelNotRegistered(); | |
((AbstractEpollChannel) channel).setFlag(Native.EPOLLET); | |
break; | |
case LEVEL_TRIGGERED: | |
checkChannelNotRegistered(); | |
((AbstractEpollChannel) channel).clearFlag(Native.EPOLLET); | |
break; | |
default: | |
throw new Error(); | |
} | |
} catch (IOException e) { | |
throw new ChannelException(e); | |
} | |
return this; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// pulsar ServerCnx | |
public void startSendOperation() { | |
if (++pendingSendRequest == MaxPendingSendRequests) { | |
// When the quota of pending send requests is reached, stop reading from socket to cause backpressure on | |
// client connection, possibly shared between multiple producers | |
ctx.channel().config().setAutoRead(false); | |
} | |
} | |
public void completedSendOperation(boolean isNonPersistentTopic) { | |
if (--pendingSendRequest == ResumeReadsThreshold) { | |
// Resume reading from socket | |
ctx.channel().config().setAutoRead(true); | |
} | |
if (isNonPersistentTopic) { | |
nonPersistentPendingMessages--; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment