Allow customization of LocalChannel instances that are being created by LocalServerChannel.

Motivation

It's possible to extend LocalChannel as well as LocalServerChannel but the LocalServerChannel's serve(peer) method is hardcoded to create only instances of LocalChannel.

Modifications

Add a protected factory method that returns by default new LocalChannel(...) but users may override it to customize it.

Result

It's possible to customize the LocalChannel instance on either end of the virtual connection.
This commit is contained in:
Roger Kapsi 2016-10-14 10:21:01 -04:00 committed by Norman Maurer
parent 50a11d964d
commit 40a6b045b4
2 changed files with 10 additions and 2 deletions

View File

@ -104,7 +104,7 @@ public class LocalChannel extends AbstractChannel {
super(null);
}
LocalChannel(LocalServerChannel parent, LocalChannel peer) {
protected LocalChannel(LocalServerChannel parent, LocalChannel peer) {
super(parent);
this.peer = peer;
localAddress = parent.localAddress();

View File

@ -133,7 +133,7 @@ public class LocalServerChannel extends AbstractServerChannel {
}
LocalChannel serve(final LocalChannel peer) {
final LocalChannel child = new LocalChannel(this, peer);
final LocalChannel child = newLocalChannel(peer);
if (eventLoop().inEventLoop()) {
serve0(child);
} else {
@ -147,6 +147,14 @@ public class LocalServerChannel extends AbstractServerChannel {
return child;
}
/**
* A factory method for {@link LocalChannel}s. Users may override it
* to create custom instances of {@link LocalChannel}s.
*/
protected LocalChannel newLocalChannel(LocalChannel peer) {
return new LocalChannel(this, peer);
}
private void serve0(final LocalChannel child) {
inboundBuffer.add(child);
if (acceptInProgress) {