GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Decouple AbstractChannel from DefaultChannelPipeline requirement · netty/netty@bdcfeb8

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • transport/src/main/java/io/netty/channel
    • AbstractChannel.java
    • DefaultChannelPipeline.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎transport/src/main/java/io/netty/channel/AbstractChannel.java‎

Copy file name to clipboardExpand all lines: transport/src/main/java/io/netty/channel/AbstractChannel.java
+13-15Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
4747
private final Channel parent;
4848
private final ChannelId id;
4949
private final Unsafe unsafe;
50-
private final DefaultChannelPipeline pipeline;
50+
private final ChannelPipeline pipeline;
5151
private final CloseFuture closeFuture = new CloseFuture(this);
5252
private final EventLoop eventLoop;
5353

@@ -123,9 +123,9 @@ public final ChannelId id() {
123123
}
124124

125125
/**
126-
* Returns a new {@link DefaultChannelPipeline} instance.
126+
* Returns a new {@link ChannelPipeline} instance.
127127
*/
128-
protected DefaultChannelPipeline newChannelPipeline() {
128+
protected ChannelPipeline newChannelPipeline() {
129129
return new DefaultChannelPipeline(this);
130130
}
131131

@@ -295,6 +295,8 @@ protected abstract class AbstractUnsafe implements Unsafe {
295295

296296
private volatile ChannelOutboundBuffer outboundBuffer = new ChannelOutboundBuffer(AbstractChannel.this);
297297
private RecvByteBufAllocator.Handle recvHandle;
298+
private MessageSizeEstimator.Handle estimatorHandle;
299+
298300
private boolean inFlush0;
299301
/** true if the channel has never been registered, false otherwise */
300302
private boolean neverRegistered = true;
@@ -303,6 +305,13 @@ private void assertEventLoop() {
303305
assert !registered || eventLoop.inEventLoop();
304306
}
305307

308+
MessageSizeEstimator.Handle estimatorHandle() {
309+
if (estimatorHandle == null) {
310+
estimatorHandle = config().getMessageSizeEstimator().newHandle();
311+
}
312+
return estimatorHandle;
313+
}
314+
306315
@Override
307316
public RecvByteBufAllocator.Handle recvBufAllocHandle() {
308317
if (recvHandle == null) {
@@ -333,13 +342,6 @@ public final void register(final ChannelPromise promise) {
333342
return;
334343
}
335344

336-
// Clear any cached executors from prior event loop registrations.
337-
AbstractChannelHandlerContext context = pipeline.tail;
338-
do {
339-
context.contextExecutor = null;
340-
context = context.prev;
341-
} while (context != null);
342-
343345
if (eventLoop.inEventLoop()) {
344346
register0(promise);
345347
} else {
@@ -376,10 +378,6 @@ public void operationComplete(ChannelFuture future) throws Exception {
376378
neverRegistered = false;
377379
registered = true;
378380

379-
// Ensure we call handlerAdded(...) before we actually notify the promise. This is needed as the
380-
// user may already fire events through the pipeline in the ChannelFutureListener.
381-
pipeline.invokeHandlerAddedIfNeeded();
382-
383381
safeSetSuccess(promise);
384382
pipeline.fireChannelRegistered();
385383
// Only fire a channelActive if the channel has never been registered. This prevents firing
@@ -735,7 +733,7 @@ public final void write(Object msg, ChannelPromise promise) {
735733
int size;
736734
try {
737735
msg = filterOutboundMessage(msg);
738-
size = pipeline.estimatorHandle().size(msg);
736+
size = estimatorHandle().size(msg);
739737
if (size < 0) {
740738
size = 0;
741739
}
Collapse file

‎transport/src/main/java/io/netty/channel/DefaultChannelPipeline.java‎

Copy file name to clipboardExpand all lines: transport/src/main/java/io/netty/channel/DefaultChannelPipeline.java
+20-1Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,26 @@ public void handlerRemoved(ChannelHandlerContext ctx) {
13001300

13011301
@Override
13021302
public void register(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
1303-
unsafe.register(promise);
1303+
ChannelPromise registerPromise = newPromise();
1304+
registerPromise.addListener(f -> {
1305+
if (f.isSuccess()) {
1306+
// Clear any cached executors from prior event loop registrations.
1307+
AbstractChannelHandlerContext context = tail;
1308+
do {
1309+
context.contextExecutor = null;
1310+
context = context.prev;
1311+
} while (context != null);
1312+
1313+
// Ensure we call handlerAdded(...) before we actually notify the promise. This is needed as the
1314+
// user may already fire events through the pipeline in the ChannelFutureListener that the user
1315+
// attached the the original promise.
1316+
invokeHandlerAddedIfNeeded();
1317+
promise.setSuccess();
1318+
} else {
1319+
promise.setFailure(f.cause());
1320+
}
1321+
});
1322+
unsafe.register(registerPromise);
13041323
}
13051324

13061325
@Override

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.