Skip to content

Fix init order in AbstractPortUnificationServer #14892

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public abstract class AbstractPortUnificationServer extends AbstractServer {
/**
* extension name -> activate WireProtocol
*/
private final Map<String, WireProtocol> protocols;
private volatile Map<String, WireProtocol> protocols;

/*
protocol name --> URL object
Expand All @@ -50,16 +50,24 @@ public abstract class AbstractPortUnificationServer extends AbstractServer {

public AbstractPortUnificationServer(URL url, ChannelHandler handler) throws RemotingException {
super(url, handler);
ExtensionLoader<WireProtocol> extensionLoader =
url.getOrDefaultFrameworkModel().getExtensionLoader(WireProtocol.class);
this.protocols = extensionLoader.getActivateExtension(url, new String[0]).stream()
.collect(Collectors.toConcurrentMap(extensionLoader::getExtensionName, Function.identity()));
}

public Map<String, WireProtocol> getProtocols() {
return protocols;
}

@Override
protected final void doOpen() {
ExtensionLoader<WireProtocol> extensionLoader =
getUrl().getOrDefaultFrameworkModel().getExtensionLoader(WireProtocol.class);
this.protocols = extensionLoader.getActivateExtension(getUrl(), new String[0]).stream()
.collect(Collectors.toConcurrentMap(extensionLoader::getExtensionName, Function.identity()));

doOpen0();
}

protected abstract void doOpen0();

/*
This method registers URL object and corresponding channel handler to pu server.
In PuServerExchanger.bind, this method is called with ConcurrentHashMap.computeIfPresent to register messages to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void bind() {
}

@Override
protected void doOpen() {
protected void doOpen0() {
NettyHelper.setNettyLoggerFactory();
ExecutorService boss = Executors.newCachedThreadPool(new NamedThreadFactory(EVENT_LOOP_BOSS_POOL_NAME, true));
ExecutorService worker =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void bind() throws Throwable {
}

@Override
public void doOpen() throws Throwable {
public void doOpen0() {
bootstrap = new ServerBootstrap();

bossGroup = NettyEventLoopFactory.eventLoopGroup(1, EVENT_LOOP_BOSS_POOL_NAME);
Expand Down
Loading